Wed, 31 Dec 2014 06:09:35 +0100
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_shared_Lowering_shared_h |
michael@0 | 8 | #define jit_shared_Lowering_shared_h |
michael@0 | 9 | |
michael@0 | 10 | // This file declares the structures that are used for attaching LIR to a |
michael@0 | 11 | // MIRGraph. |
michael@0 | 12 | |
michael@0 | 13 | #include "jit/LIR.h" |
michael@0 | 14 | |
michael@0 | 15 | namespace js { |
michael@0 | 16 | namespace jit { |
michael@0 | 17 | |
michael@0 | 18 | class MBasicBlock; |
michael@0 | 19 | class MTableSwitch; |
michael@0 | 20 | class MIRGenerator; |
michael@0 | 21 | class MIRGraph; |
michael@0 | 22 | class MDefinition; |
michael@0 | 23 | class MInstruction; |
michael@0 | 24 | class LOsiPoint; |
michael@0 | 25 | |
michael@0 | 26 | class LIRGeneratorShared : public MInstructionVisitorWithDefaults |
michael@0 | 27 | { |
michael@0 | 28 | protected: |
michael@0 | 29 | MIRGenerator *gen; |
michael@0 | 30 | MIRGraph &graph; |
michael@0 | 31 | LIRGraph &lirGraph_; |
michael@0 | 32 | LBlock *current; |
michael@0 | 33 | MResumePoint *lastResumePoint_; |
michael@0 | 34 | LRecoverInfo *cachedRecoverInfo_; |
michael@0 | 35 | LOsiPoint *osiPoint_; |
michael@0 | 36 | |
michael@0 | 37 | public: |
michael@0 | 38 | LIRGeneratorShared(MIRGenerator *gen, MIRGraph &graph, LIRGraph &lirGraph) |
michael@0 | 39 | : gen(gen), |
michael@0 | 40 | graph(graph), |
michael@0 | 41 | lirGraph_(lirGraph), |
michael@0 | 42 | lastResumePoint_(nullptr), |
michael@0 | 43 | cachedRecoverInfo_(nullptr), |
michael@0 | 44 | osiPoint_(nullptr) |
michael@0 | 45 | { } |
michael@0 | 46 | |
michael@0 | 47 | MIRGenerator *mir() { |
michael@0 | 48 | return gen; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | protected: |
michael@0 | 52 | // A backend can decide that an instruction should be emitted at its uses, |
michael@0 | 53 | // rather than at its definition. To communicate this, set the |
michael@0 | 54 | // instruction's virtual register set to 0. When using the instruction, |
michael@0 | 55 | // its virtual register is temporarily reassigned. To know to clear it |
michael@0 | 56 | // after constructing the use information, the worklist bit is temporarily |
michael@0 | 57 | // unset. |
michael@0 | 58 | // |
michael@0 | 59 | // The backend can use the worklist bit to determine whether or not a |
michael@0 | 60 | // definition should be created. |
michael@0 | 61 | inline bool emitAtUses(MInstruction *mir); |
michael@0 | 62 | |
michael@0 | 63 | // The lowest-level calls to use, those that do not wrap another call to |
michael@0 | 64 | // use(), must prefix grabbing virtual register IDs by these calls. |
michael@0 | 65 | inline bool ensureDefined(MDefinition *mir); |
michael@0 | 66 | |
michael@0 | 67 | // These all create a use of a virtual register, with an optional |
michael@0 | 68 | // allocation policy. |
michael@0 | 69 | inline LUse use(MDefinition *mir, LUse policy); |
michael@0 | 70 | inline LUse use(MDefinition *mir); |
michael@0 | 71 | inline LUse useAtStart(MDefinition *mir); |
michael@0 | 72 | inline LUse useRegister(MDefinition *mir); |
michael@0 | 73 | inline LUse useRegisterAtStart(MDefinition *mir); |
michael@0 | 74 | inline LUse useFixed(MDefinition *mir, Register reg); |
michael@0 | 75 | inline LUse useFixed(MDefinition *mir, FloatRegister reg); |
michael@0 | 76 | inline LUse useFixed(MDefinition *mir, AnyRegister reg); |
michael@0 | 77 | inline LUse useFixedAtStart(MDefinition *mir, Register reg); |
michael@0 | 78 | inline LAllocation useOrConstant(MDefinition *mir); |
michael@0 | 79 | // "Any" is architecture dependent, and will include registers and stack slots on X86, |
michael@0 | 80 | // and only registers on ARM. |
michael@0 | 81 | inline LAllocation useAny(MDefinition *mir); |
michael@0 | 82 | inline LAllocation useAnyOrConstant(MDefinition *mir); |
michael@0 | 83 | // "Storable" is architecture dependend, and will include registers and constants on X86 |
michael@0 | 84 | // and only registers on ARM. |
michael@0 | 85 | // this is a generic "things we can expect to write into memory in 1 instruction" |
michael@0 | 86 | inline LAllocation useStorable(MDefinition *mir); |
michael@0 | 87 | inline LAllocation useStorableAtStart(MDefinition *mir); |
michael@0 | 88 | inline LAllocation useKeepaliveOrConstant(MDefinition *mir); |
michael@0 | 89 | inline LAllocation useRegisterOrConstant(MDefinition *mir); |
michael@0 | 90 | inline LAllocation useRegisterOrConstantAtStart(MDefinition *mir); |
michael@0 | 91 | inline LAllocation useRegisterOrNonNegativeConstantAtStart(MDefinition *mir); |
michael@0 | 92 | inline LAllocation useRegisterOrNonDoubleConstant(MDefinition *mir); |
michael@0 | 93 | |
michael@0 | 94 | #ifdef JS_NUNBOX32 |
michael@0 | 95 | inline LUse useType(MDefinition *mir, LUse::Policy policy); |
michael@0 | 96 | inline LUse usePayload(MDefinition *mir, LUse::Policy policy); |
michael@0 | 97 | inline LUse usePayloadAtStart(MDefinition *mir, LUse::Policy policy); |
michael@0 | 98 | inline LUse usePayloadInRegisterAtStart(MDefinition *mir); |
michael@0 | 99 | |
michael@0 | 100 | // Adds a box input to an instruction, setting operand |n| to the type and |
michael@0 | 101 | // |n+1| to the payload. Does not modify the operands, instead expecting a |
michael@0 | 102 | // policy to already be set. |
michael@0 | 103 | inline bool fillBoxUses(LInstruction *lir, size_t n, MDefinition *mir); |
michael@0 | 104 | #endif |
michael@0 | 105 | |
michael@0 | 106 | // These create temporary register requests. |
michael@0 | 107 | inline LDefinition temp(LDefinition::Type type = LDefinition::GENERAL, |
michael@0 | 108 | LDefinition::Policy policy = LDefinition::DEFAULT); |
michael@0 | 109 | inline LDefinition tempFloat32(); |
michael@0 | 110 | inline LDefinition tempDouble(); |
michael@0 | 111 | inline LDefinition tempCopy(MDefinition *input, uint32_t reusedInput); |
michael@0 | 112 | |
michael@0 | 113 | // Note that the fixed register has a GENERAL type. |
michael@0 | 114 | inline LDefinition tempFixed(Register reg); |
michael@0 | 115 | |
michael@0 | 116 | template <size_t Ops, size_t Temps> |
michael@0 | 117 | inline bool defineFixed(LInstructionHelper<1, Ops, Temps> *lir, MDefinition *mir, |
michael@0 | 118 | const LAllocation &output); |
michael@0 | 119 | |
michael@0 | 120 | template <size_t Ops, size_t Temps> |
michael@0 | 121 | inline bool defineBox(LInstructionHelper<BOX_PIECES, Ops, Temps> *lir, MDefinition *mir, |
michael@0 | 122 | LDefinition::Policy policy = LDefinition::DEFAULT); |
michael@0 | 123 | |
michael@0 | 124 | inline bool defineReturn(LInstruction *lir, MDefinition *mir); |
michael@0 | 125 | |
michael@0 | 126 | template <size_t Ops, size_t Temps> |
michael@0 | 127 | inline bool define(LInstructionHelper<1, Ops, Temps> *lir, MDefinition *mir, |
michael@0 | 128 | const LDefinition &def); |
michael@0 | 129 | |
michael@0 | 130 | template <size_t Ops, size_t Temps> |
michael@0 | 131 | inline bool define(LInstructionHelper<1, Ops, Temps> *lir, MDefinition *mir, |
michael@0 | 132 | LDefinition::Policy policy = LDefinition::DEFAULT); |
michael@0 | 133 | |
michael@0 | 134 | template <size_t Ops, size_t Temps> |
michael@0 | 135 | inline bool defineReuseInput(LInstructionHelper<1, Ops, Temps> *lir, MDefinition *mir, uint32_t operand); |
michael@0 | 136 | |
michael@0 | 137 | // Rather than defining a new virtual register, sets |ins| to have the same |
michael@0 | 138 | // virtual register as |as|. |
michael@0 | 139 | inline bool redefine(MDefinition *ins, MDefinition *as); |
michael@0 | 140 | |
michael@0 | 141 | // Defines an IR's output as the same as another IR. This is similar to |
michael@0 | 142 | // redefine(), but used when creating new LIR. |
michael@0 | 143 | inline bool defineAs(LInstruction *outLir, MDefinition *outMir, MDefinition *inMir); |
michael@0 | 144 | |
michael@0 | 145 | TempAllocator &alloc() const { |
michael@0 | 146 | return graph.alloc(); |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | uint32_t getVirtualRegister() { |
michael@0 | 150 | return lirGraph_.getVirtualRegister(); |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | template <typename T> void annotate(T *ins); |
michael@0 | 154 | template <typename T> bool add(T *ins, MInstruction *mir = nullptr); |
michael@0 | 155 | |
michael@0 | 156 | void lowerTypedPhiInput(MPhi *phi, uint32_t inputPosition, LBlock *block, size_t lirIndex); |
michael@0 | 157 | bool defineTypedPhi(MPhi *phi, size_t lirIndex); |
michael@0 | 158 | |
michael@0 | 159 | LOsiPoint *popOsiPoint() { |
michael@0 | 160 | LOsiPoint *tmp = osiPoint_; |
michael@0 | 161 | osiPoint_ = nullptr; |
michael@0 | 162 | return tmp; |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | LRecoverInfo *getRecoverInfo(MResumePoint *rp); |
michael@0 | 166 | LSnapshot *buildSnapshot(LInstruction *ins, MResumePoint *rp, BailoutKind kind); |
michael@0 | 167 | bool assignPostSnapshot(MInstruction *mir, LInstruction *ins); |
michael@0 | 168 | |
michael@0 | 169 | // Marks this instruction as fallible, meaning that before it performs |
michael@0 | 170 | // effects (if any), it may check pre-conditions and bailout if they do not |
michael@0 | 171 | // hold. This function informs the register allocator that it will need to |
michael@0 | 172 | // capture appropriate state. |
michael@0 | 173 | bool assignSnapshot(LInstruction *ins, BailoutKind kind = Bailout_Normal); |
michael@0 | 174 | |
michael@0 | 175 | // Marks this instruction as needing to call into either the VM or GC. This |
michael@0 | 176 | // function may build a snapshot that captures the result of its own |
michael@0 | 177 | // instruction, and as such, should generally be called after define*(). |
michael@0 | 178 | bool assignSafepoint(LInstruction *ins, MInstruction *mir); |
michael@0 | 179 | |
michael@0 | 180 | public: |
michael@0 | 181 | bool visitConstant(MConstant *ins); |
michael@0 | 182 | |
michael@0 | 183 | // Whether to generate typed reads for element accesses with hole checks. |
michael@0 | 184 | static bool allowTypedElementHoleCheck() { |
michael@0 | 185 | return false; |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | // Whether to generate typed array accesses on statically known objects. |
michael@0 | 189 | static bool allowStaticTypedArrayAccesses() { |
michael@0 | 190 | return false; |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | // Whether we can emit Float32 specific optimizations. |
michael@0 | 194 | static bool allowFloat32Optimizations() { |
michael@0 | 195 | return false; |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | // Whether we can inline ForkJoinGetSlice. |
michael@0 | 199 | static bool allowInlineForkJoinGetSlice() { |
michael@0 | 200 | return false; |
michael@0 | 201 | } |
michael@0 | 202 | }; |
michael@0 | 203 | |
michael@0 | 204 | } // namespace jit |
michael@0 | 205 | } // namespace js |
michael@0 | 206 | |
michael@0 | 207 | #endif /* jit_shared_Lowering_shared_h */ |