js/src/jit/ValueNumbering.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=8 sts=4 et sw=4 tw=99:
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef jit_ValueNumbering_h
michael@0 8 #define jit_ValueNumbering_h
michael@0 9
michael@0 10 #include "jit/MIR.h"
michael@0 11
michael@0 12 namespace js {
michael@0 13 namespace jit {
michael@0 14
michael@0 15 class ValueNumberer
michael@0 16 {
michael@0 17 protected:
michael@0 18 struct ValueHasher
michael@0 19 {
michael@0 20 typedef MDefinition * Lookup;
michael@0 21 typedef MDefinition * Key;
michael@0 22 static HashNumber hash(const Lookup &ins) {
michael@0 23 return ins->valueHash();
michael@0 24 }
michael@0 25
michael@0 26 static bool match(const Key &k, const Lookup &l) {
michael@0 27 // If one of the instructions depends on a store, and the
michael@0 28 // other instruction does not depend on the same store,
michael@0 29 // the instructions are not congruent.
michael@0 30 if (k->dependency() != l->dependency())
michael@0 31 return false;
michael@0 32 return k->congruentTo(l);
michael@0 33 }
michael@0 34 };
michael@0 35
michael@0 36 typedef HashMap<MDefinition *,
michael@0 37 uint32_t,
michael@0 38 ValueHasher,
michael@0 39 IonAllocPolicy> ValueMap;
michael@0 40
michael@0 41 struct DominatingValue
michael@0 42 {
michael@0 43 MDefinition *def;
michael@0 44 uint32_t validUntil;
michael@0 45 };
michael@0 46
michael@0 47 typedef HashMap<uint32_t,
michael@0 48 DominatingValue,
michael@0 49 DefaultHasher<uint32_t>,
michael@0 50 IonAllocPolicy> InstructionMap;
michael@0 51
michael@0 52 protected:
michael@0 53 TempAllocator &alloc() const;
michael@0 54 uint32_t lookupValue(MDefinition *ins);
michael@0 55 MDefinition *findDominatingDef(InstructionMap &defs, MDefinition *ins, size_t index);
michael@0 56
michael@0 57 MDefinition *simplify(MDefinition *def, bool useValueNumbers);
michael@0 58 MControlInstruction *simplifyControlInstruction(MControlInstruction *def);
michael@0 59 bool eliminateRedundancies();
michael@0 60
michael@0 61 bool computeValueNumbers();
michael@0 62
michael@0 63 inline bool isMarked(MDefinition *def) {
michael@0 64 return pessimisticPass_ || def->isInWorklist();
michael@0 65 }
michael@0 66
michael@0 67 void markDefinition(MDefinition *def);
michael@0 68 void unmarkDefinition(MDefinition *def);
michael@0 69
michael@0 70 void markConsumers(MDefinition *def);
michael@0 71 void markBlock(MBasicBlock *block);
michael@0 72 void setClass(MDefinition *toSet, MDefinition *representative);
michael@0 73
michael@0 74 public:
michael@0 75 static MDefinition *findSplit(MDefinition *);
michael@0 76 void breakClass(MDefinition*);
michael@0 77
michael@0 78 protected:
michael@0 79 MIRGenerator *mir;
michael@0 80 MIRGraph &graph_;
michael@0 81 ValueMap values;
michael@0 82 bool pessimisticPass_;
michael@0 83 size_t count_;
michael@0 84
michael@0 85 public:
michael@0 86 ValueNumberer(MIRGenerator *mir, MIRGraph &graph, bool optimistic);
michael@0 87 bool analyze();
michael@0 88 bool clear();
michael@0 89 };
michael@0 90
michael@0 91 class ValueNumberData : public TempObject {
michael@0 92
michael@0 93 friend void ValueNumberer::breakClass(MDefinition*);
michael@0 94 friend MDefinition *ValueNumberer::findSplit(MDefinition*);
michael@0 95 uint32_t number;
michael@0 96 MDefinition *classNext;
michael@0 97 MDefinition *classPrev;
michael@0 98
michael@0 99 public:
michael@0 100 ValueNumberData() : number(0), classNext(nullptr), classPrev(nullptr) {}
michael@0 101
michael@0 102 void setValueNumber(uint32_t number_) {
michael@0 103 number = number_;
michael@0 104 }
michael@0 105
michael@0 106 uint32_t valueNumber() {
michael@0 107 return number;
michael@0 108 }
michael@0 109 // Set the class of this to the given representative value.
michael@0 110 void setClass(MDefinition *thisDef, MDefinition *rep) {
michael@0 111 JS_ASSERT(thisDef->valueNumberData() == this);
michael@0 112 // If we are attempting to insert ourself, then nothing needs to be done.
michael@0 113 // However, if the definition to be inserted already has the correct value number,
michael@0 114 // it still needs to be inserted, since the value number needs to be updated lazily.
michael@0 115 // this updating tactic can leave the world in a state where thisDef is not in the
michael@0 116 // equivalence class of rep, but it has the same value number. Defs in this state
michael@0 117 // need to be re-processed.
michael@0 118 if (this == rep->valueNumberData())
michael@0 119 return;
michael@0 120
michael@0 121 if (classNext)
michael@0 122 classNext->valueNumberData()->classPrev = classPrev;
michael@0 123 if (classPrev)
michael@0 124 classPrev->valueNumberData()->classNext = classNext;
michael@0 125
michael@0 126
michael@0 127 classPrev = rep;
michael@0 128 classNext = rep->valueNumberData()->classNext;
michael@0 129
michael@0 130 if (rep->valueNumberData()->classNext)
michael@0 131 rep->valueNumberData()->classNext->valueNumberData()->classPrev = thisDef;
michael@0 132 rep->valueNumberData()->classNext = thisDef;
michael@0 133 }
michael@0 134 };
michael@0 135 } // namespace jit
michael@0 136 } // namespace js
michael@0 137
michael@0 138 #endif /* jit_ValueNumbering_h */

mercurial