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 | #include "jit/x86/Lowering-x86.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "jit/MIR.h" |
michael@0 | 10 | #include "jit/x86/Assembler-x86.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "jit/shared/Lowering-shared-inl.h" |
michael@0 | 13 | |
michael@0 | 14 | using namespace js; |
michael@0 | 15 | using namespace js::jit; |
michael@0 | 16 | |
michael@0 | 17 | LDefinition |
michael@0 | 18 | LIRGeneratorX86::tempForDispatchCache(MIRType outputType) |
michael@0 | 19 | { |
michael@0 | 20 | // x86 doesn't have a scratch register and we need one for the |
michael@0 | 21 | // indirect jump for dispatch-style ICs. |
michael@0 | 22 | // |
michael@0 | 23 | // Note that currently we only install dispatch-style ICs for parallel |
michael@0 | 24 | // execution. If this assumption changes, please change it here. |
michael@0 | 25 | if (gen->info().executionMode() != ParallelExecution) |
michael@0 | 26 | return LDefinition::BogusTemp(); |
michael@0 | 27 | |
michael@0 | 28 | // If we don't have an output register, we need a temp. |
michael@0 | 29 | if (outputType == MIRType_None) |
michael@0 | 30 | return temp(); |
michael@0 | 31 | |
michael@0 | 32 | // If we have a double output register, we need a temp. |
michael@0 | 33 | if (outputType == MIRType_Double) |
michael@0 | 34 | return temp(); |
michael@0 | 35 | |
michael@0 | 36 | // Otherwise we have a non-double output register and we can reuse it. |
michael@0 | 37 | return LDefinition::BogusTemp(); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | bool |
michael@0 | 41 | LIRGeneratorX86::useBox(LInstruction *lir, size_t n, MDefinition *mir, |
michael@0 | 42 | LUse::Policy policy, bool useAtStart) |
michael@0 | 43 | { |
michael@0 | 44 | JS_ASSERT(mir->type() == MIRType_Value); |
michael@0 | 45 | |
michael@0 | 46 | if (!ensureDefined(mir)) |
michael@0 | 47 | return false; |
michael@0 | 48 | lir->setOperand(n, LUse(mir->virtualRegister(), policy, useAtStart)); |
michael@0 | 49 | lir->setOperand(n + 1, LUse(VirtualRegisterOfPayload(mir), policy, useAtStart)); |
michael@0 | 50 | return true; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | bool |
michael@0 | 54 | LIRGeneratorX86::useBoxFixed(LInstruction *lir, size_t n, MDefinition *mir, Register reg1, |
michael@0 | 55 | Register reg2) |
michael@0 | 56 | { |
michael@0 | 57 | JS_ASSERT(mir->type() == MIRType_Value); |
michael@0 | 58 | JS_ASSERT(reg1 != reg2); |
michael@0 | 59 | |
michael@0 | 60 | if (!ensureDefined(mir)) |
michael@0 | 61 | return false; |
michael@0 | 62 | lir->setOperand(n, LUse(reg1, mir->virtualRegister())); |
michael@0 | 63 | lir->setOperand(n + 1, LUse(reg2, VirtualRegisterOfPayload(mir))); |
michael@0 | 64 | return true; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | LAllocation |
michael@0 | 68 | LIRGeneratorX86::useByteOpRegister(MDefinition *mir) |
michael@0 | 69 | { |
michael@0 | 70 | return useFixed(mir, eax); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | LAllocation |
michael@0 | 74 | LIRGeneratorX86::useByteOpRegisterOrNonDoubleConstant(MDefinition *mir) |
michael@0 | 75 | { |
michael@0 | 76 | return useFixed(mir, eax); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | bool |
michael@0 | 80 | LIRGeneratorX86::visitBox(MBox *box) |
michael@0 | 81 | { |
michael@0 | 82 | MDefinition *inner = box->getOperand(0); |
michael@0 | 83 | |
michael@0 | 84 | // If the box wrapped a double, it needs a new register. |
michael@0 | 85 | if (IsFloatingPointType(inner->type())) |
michael@0 | 86 | return defineBox(new(alloc()) LBoxFloatingPoint(useRegisterAtStart(inner), tempCopy(inner, 0), |
michael@0 | 87 | inner->type()), box); |
michael@0 | 88 | |
michael@0 | 89 | if (box->canEmitAtUses()) |
michael@0 | 90 | return emitAtUses(box); |
michael@0 | 91 | |
michael@0 | 92 | if (inner->isConstant()) |
michael@0 | 93 | return defineBox(new(alloc()) LValue(inner->toConstant()->value()), box); |
michael@0 | 94 | |
michael@0 | 95 | LBox *lir = new(alloc()) LBox(use(inner), inner->type()); |
michael@0 | 96 | |
michael@0 | 97 | // Otherwise, we should not define a new register for the payload portion |
michael@0 | 98 | // of the output, so bypass defineBox(). |
michael@0 | 99 | uint32_t vreg = getVirtualRegister(); |
michael@0 | 100 | if (vreg >= MAX_VIRTUAL_REGISTERS) |
michael@0 | 101 | return false; |
michael@0 | 102 | |
michael@0 | 103 | // Note that because we're using PASSTHROUGH, we do not change the type of |
michael@0 | 104 | // the definition. We also do not define the first output as "TYPE", |
michael@0 | 105 | // because it has no corresponding payload at (vreg + 1). Also note that |
michael@0 | 106 | // although we copy the input's original type for the payload half of the |
michael@0 | 107 | // definition, this is only for clarity. PASSTHROUGH definitions are |
michael@0 | 108 | // ignored. |
michael@0 | 109 | lir->setDef(0, LDefinition(vreg, LDefinition::GENERAL)); |
michael@0 | 110 | lir->setDef(1, LDefinition(inner->virtualRegister(), LDefinition::TypeFrom(inner->type()), |
michael@0 | 111 | LDefinition::PASSTHROUGH)); |
michael@0 | 112 | box->setVirtualRegister(vreg); |
michael@0 | 113 | return add(lir); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | bool |
michael@0 | 117 | LIRGeneratorX86::visitUnbox(MUnbox *unbox) |
michael@0 | 118 | { |
michael@0 | 119 | // An unbox on x86 reads in a type tag (either in memory or a register) and |
michael@0 | 120 | // a payload. Unlike most instructions conusming a box, we ask for the type |
michael@0 | 121 | // second, so that the result can re-use the first input. |
michael@0 | 122 | MDefinition *inner = unbox->getOperand(0); |
michael@0 | 123 | |
michael@0 | 124 | if (!ensureDefined(inner)) |
michael@0 | 125 | return false; |
michael@0 | 126 | |
michael@0 | 127 | if (IsFloatingPointType(unbox->type())) { |
michael@0 | 128 | LUnboxFloatingPoint *lir = new(alloc()) LUnboxFloatingPoint(unbox->type()); |
michael@0 | 129 | if (unbox->fallible() && !assignSnapshot(lir, unbox->bailoutKind())) |
michael@0 | 130 | return false; |
michael@0 | 131 | if (!useBox(lir, LUnboxFloatingPoint::Input, inner)) |
michael@0 | 132 | return false; |
michael@0 | 133 | return define(lir, unbox); |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | // Swap the order we use the box pieces so we can re-use the payload register. |
michael@0 | 137 | LUnbox *lir = new(alloc()) LUnbox; |
michael@0 | 138 | lir->setOperand(0, usePayloadInRegisterAtStart(inner)); |
michael@0 | 139 | lir->setOperand(1, useType(inner, LUse::ANY)); |
michael@0 | 140 | |
michael@0 | 141 | if (unbox->fallible() && !assignSnapshot(lir, unbox->bailoutKind())) |
michael@0 | 142 | return false; |
michael@0 | 143 | |
michael@0 | 144 | // Note that PASSTHROUGH here is illegal, since types and payloads form two |
michael@0 | 145 | // separate intervals. If the type becomes dead before the payload, it |
michael@0 | 146 | // could be used as a Value without the type being recoverable. Unbox's |
michael@0 | 147 | // purpose is to eagerly kill the definition of a type tag, so keeping both |
michael@0 | 148 | // alive (for the purpose of gcmaps) is unappealing. Instead, we create a |
michael@0 | 149 | // new virtual register. |
michael@0 | 150 | return defineReuseInput(lir, unbox, 0); |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | bool |
michael@0 | 154 | LIRGeneratorX86::visitReturn(MReturn *ret) |
michael@0 | 155 | { |
michael@0 | 156 | MDefinition *opd = ret->getOperand(0); |
michael@0 | 157 | JS_ASSERT(opd->type() == MIRType_Value); |
michael@0 | 158 | |
michael@0 | 159 | LReturn *ins = new(alloc()) LReturn; |
michael@0 | 160 | ins->setOperand(0, LUse(JSReturnReg_Type)); |
michael@0 | 161 | ins->setOperand(1, LUse(JSReturnReg_Data)); |
michael@0 | 162 | return fillBoxUses(ins, 0, opd) && add(ins); |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | bool |
michael@0 | 166 | LIRGeneratorX86::defineUntypedPhi(MPhi *phi, size_t lirIndex) |
michael@0 | 167 | { |
michael@0 | 168 | LPhi *type = current->getPhi(lirIndex + VREG_TYPE_OFFSET); |
michael@0 | 169 | LPhi *payload = current->getPhi(lirIndex + VREG_DATA_OFFSET); |
michael@0 | 170 | |
michael@0 | 171 | uint32_t typeVreg = getVirtualRegister(); |
michael@0 | 172 | if (typeVreg >= MAX_VIRTUAL_REGISTERS) |
michael@0 | 173 | return false; |
michael@0 | 174 | |
michael@0 | 175 | phi->setVirtualRegister(typeVreg); |
michael@0 | 176 | |
michael@0 | 177 | uint32_t payloadVreg = getVirtualRegister(); |
michael@0 | 178 | if (payloadVreg >= MAX_VIRTUAL_REGISTERS) |
michael@0 | 179 | return false; |
michael@0 | 180 | JS_ASSERT(typeVreg + 1 == payloadVreg); |
michael@0 | 181 | |
michael@0 | 182 | type->setDef(0, LDefinition(typeVreg, LDefinition::TYPE)); |
michael@0 | 183 | payload->setDef(0, LDefinition(payloadVreg, LDefinition::PAYLOAD)); |
michael@0 | 184 | annotate(type); |
michael@0 | 185 | annotate(payload); |
michael@0 | 186 | return true; |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | void |
michael@0 | 190 | LIRGeneratorX86::lowerUntypedPhiInput(MPhi *phi, uint32_t inputPosition, LBlock *block, size_t lirIndex) |
michael@0 | 191 | { |
michael@0 | 192 | MDefinition *operand = phi->getOperand(inputPosition); |
michael@0 | 193 | LPhi *type = block->getPhi(lirIndex + VREG_TYPE_OFFSET); |
michael@0 | 194 | LPhi *payload = block->getPhi(lirIndex + VREG_DATA_OFFSET); |
michael@0 | 195 | type->setOperand(inputPosition, LUse(operand->virtualRegister() + VREG_TYPE_OFFSET, LUse::ANY)); |
michael@0 | 196 | payload->setOperand(inputPosition, LUse(VirtualRegisterOfPayload(operand), LUse::ANY)); |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | bool |
michael@0 | 200 | LIRGeneratorX86::visitAsmJSUnsignedToDouble(MAsmJSUnsignedToDouble *ins) |
michael@0 | 201 | { |
michael@0 | 202 | JS_ASSERT(ins->input()->type() == MIRType_Int32); |
michael@0 | 203 | LAsmJSUInt32ToDouble *lir = new(alloc()) LAsmJSUInt32ToDouble(useRegisterAtStart(ins->input()), temp()); |
michael@0 | 204 | return define(lir, ins); |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | bool |
michael@0 | 208 | LIRGeneratorX86::visitAsmJSUnsignedToFloat32(MAsmJSUnsignedToFloat32 *ins) |
michael@0 | 209 | { |
michael@0 | 210 | JS_ASSERT(ins->input()->type() == MIRType_Int32); |
michael@0 | 211 | LAsmJSUInt32ToFloat32 *lir = new(alloc()) LAsmJSUInt32ToFloat32(useRegisterAtStart(ins->input()), temp()); |
michael@0 | 212 | return define(lir, ins); |
michael@0 | 213 | } |
michael@0 | 214 | |
michael@0 | 215 | bool |
michael@0 | 216 | LIRGeneratorX86::visitAsmJSLoadHeap(MAsmJSLoadHeap *ins) |
michael@0 | 217 | { |
michael@0 | 218 | MDefinition *ptr = ins->ptr(); |
michael@0 | 219 | LAllocation ptrAlloc; |
michael@0 | 220 | JS_ASSERT(ptr->type() == MIRType_Int32); |
michael@0 | 221 | |
michael@0 | 222 | // For the x86 it is best to keep the 'ptr' in a register if a bounds check is needed. |
michael@0 | 223 | if (ptr->isConstant() && ins->skipBoundsCheck()) { |
michael@0 | 224 | int32_t ptrValue = ptr->toConstant()->value().toInt32(); |
michael@0 | 225 | // A bounds check is only skipped for a positive index. |
michael@0 | 226 | JS_ASSERT(ptrValue >= 0); |
michael@0 | 227 | ptrAlloc = LAllocation(ptr->toConstant()->vp()); |
michael@0 | 228 | } else { |
michael@0 | 229 | ptrAlloc = useRegisterAtStart(ptr); |
michael@0 | 230 | } |
michael@0 | 231 | LAsmJSLoadHeap *lir = new(alloc()) LAsmJSLoadHeap(ptrAlloc); |
michael@0 | 232 | return define(lir, ins); |
michael@0 | 233 | } |
michael@0 | 234 | |
michael@0 | 235 | bool |
michael@0 | 236 | LIRGeneratorX86::visitAsmJSStoreHeap(MAsmJSStoreHeap *ins) |
michael@0 | 237 | { |
michael@0 | 238 | MDefinition *ptr = ins->ptr(); |
michael@0 | 239 | LAsmJSStoreHeap *lir; |
michael@0 | 240 | JS_ASSERT(ptr->type() == MIRType_Int32); |
michael@0 | 241 | |
michael@0 | 242 | if (ptr->isConstant() && ins->skipBoundsCheck()) { |
michael@0 | 243 | int32_t ptrValue = ptr->toConstant()->value().toInt32(); |
michael@0 | 244 | JS_ASSERT(ptrValue >= 0); |
michael@0 | 245 | LAllocation ptrAlloc = LAllocation(ptr->toConstant()->vp()); |
michael@0 | 246 | switch (ins->viewType()) { |
michael@0 | 247 | case ArrayBufferView::TYPE_INT8: case ArrayBufferView::TYPE_UINT8: |
michael@0 | 248 | // See comment below. |
michael@0 | 249 | lir = new(alloc()) LAsmJSStoreHeap(ptrAlloc, useFixed(ins->value(), eax)); |
michael@0 | 250 | break; |
michael@0 | 251 | case ArrayBufferView::TYPE_INT16: case ArrayBufferView::TYPE_UINT16: |
michael@0 | 252 | case ArrayBufferView::TYPE_INT32: case ArrayBufferView::TYPE_UINT32: |
michael@0 | 253 | case ArrayBufferView::TYPE_FLOAT32: case ArrayBufferView::TYPE_FLOAT64: |
michael@0 | 254 | // See comment below. |
michael@0 | 255 | lir = new(alloc()) LAsmJSStoreHeap(ptrAlloc, useRegisterAtStart(ins->value())); |
michael@0 | 256 | break; |
michael@0 | 257 | default: MOZ_ASSUME_UNREACHABLE("unexpected array type"); |
michael@0 | 258 | } |
michael@0 | 259 | return add(lir, ins); |
michael@0 | 260 | } |
michael@0 | 261 | |
michael@0 | 262 | switch (ins->viewType()) { |
michael@0 | 263 | case ArrayBufferView::TYPE_INT8: case ArrayBufferView::TYPE_UINT8: |
michael@0 | 264 | // See comment for LIRGeneratorX86::useByteOpRegister. |
michael@0 | 265 | lir = new(alloc()) LAsmJSStoreHeap(useRegister(ins->ptr()), useFixed(ins->value(), eax)); |
michael@0 | 266 | break; |
michael@0 | 267 | case ArrayBufferView::TYPE_INT16: case ArrayBufferView::TYPE_UINT16: |
michael@0 | 268 | case ArrayBufferView::TYPE_INT32: case ArrayBufferView::TYPE_UINT32: |
michael@0 | 269 | case ArrayBufferView::TYPE_FLOAT32: case ArrayBufferView::TYPE_FLOAT64: |
michael@0 | 270 | // For now, don't allow constant values. The immediate operand |
michael@0 | 271 | // affects instruction layout which affects patching. |
michael@0 | 272 | lir = new(alloc()) LAsmJSStoreHeap(useRegisterAtStart(ptr), useRegisterAtStart(ins->value())); |
michael@0 | 273 | break; |
michael@0 | 274 | default: MOZ_ASSUME_UNREACHABLE("unexpected array type"); |
michael@0 | 275 | } |
michael@0 | 276 | |
michael@0 | 277 | return add(lir, ins); |
michael@0 | 278 | } |
michael@0 | 279 | |
michael@0 | 280 | bool |
michael@0 | 281 | LIRGeneratorX86::visitStoreTypedArrayElementStatic(MStoreTypedArrayElementStatic *ins) |
michael@0 | 282 | { |
michael@0 | 283 | // The code generated for StoreTypedArrayElementStatic is identical to that |
michael@0 | 284 | // for AsmJSStoreHeap, and the same concerns apply. |
michael@0 | 285 | LStoreTypedArrayElementStatic *lir; |
michael@0 | 286 | switch (ins->viewType()) { |
michael@0 | 287 | case ArrayBufferView::TYPE_INT8: case ArrayBufferView::TYPE_UINT8: |
michael@0 | 288 | case ArrayBufferView::TYPE_UINT8_CLAMPED: |
michael@0 | 289 | lir = new(alloc()) LStoreTypedArrayElementStatic(useRegister(ins->ptr()), |
michael@0 | 290 | useFixed(ins->value(), eax)); |
michael@0 | 291 | break; |
michael@0 | 292 | case ArrayBufferView::TYPE_INT16: case ArrayBufferView::TYPE_UINT16: |
michael@0 | 293 | case ArrayBufferView::TYPE_INT32: case ArrayBufferView::TYPE_UINT32: |
michael@0 | 294 | case ArrayBufferView::TYPE_FLOAT32: case ArrayBufferView::TYPE_FLOAT64: |
michael@0 | 295 | lir = new(alloc()) LStoreTypedArrayElementStatic(useRegisterAtStart(ins->ptr()), |
michael@0 | 296 | useRegisterAtStart(ins->value())); |
michael@0 | 297 | break; |
michael@0 | 298 | default: MOZ_ASSUME_UNREACHABLE("unexpected array type"); |
michael@0 | 299 | } |
michael@0 | 300 | |
michael@0 | 301 | return add(lir, ins); |
michael@0 | 302 | } |
michael@0 | 303 | |
michael@0 | 304 | bool |
michael@0 | 305 | LIRGeneratorX86::visitAsmJSLoadFuncPtr(MAsmJSLoadFuncPtr *ins) |
michael@0 | 306 | { |
michael@0 | 307 | return define(new(alloc()) LAsmJSLoadFuncPtr(useRegisterAtStart(ins->index())), ins); |
michael@0 | 308 | } |