js/src/jit/x64/Lowering-x64.cpp

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 #include "jit/x64/Lowering-x64.h"
michael@0 8
michael@0 9 #include "jit/MIR.h"
michael@0 10 #include "jit/x64/Assembler-x64.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 bool
michael@0 18 LIRGeneratorX64::useBox(LInstruction *lir, size_t n, MDefinition *mir,
michael@0 19 LUse::Policy policy, bool useAtStart)
michael@0 20 {
michael@0 21 JS_ASSERT(mir->type() == MIRType_Value);
michael@0 22
michael@0 23 if (!ensureDefined(mir))
michael@0 24 return false;
michael@0 25 lir->setOperand(n, LUse(mir->virtualRegister(), policy, useAtStart));
michael@0 26 return true;
michael@0 27 }
michael@0 28
michael@0 29 bool
michael@0 30 LIRGeneratorX64::useBoxFixed(LInstruction *lir, size_t n, MDefinition *mir, Register reg1, Register)
michael@0 31 {
michael@0 32 JS_ASSERT(mir->type() == MIRType_Value);
michael@0 33
michael@0 34 if (!ensureDefined(mir))
michael@0 35 return false;
michael@0 36 lir->setOperand(n, LUse(reg1, mir->virtualRegister()));
michael@0 37 return true;
michael@0 38 }
michael@0 39
michael@0 40 LAllocation
michael@0 41 LIRGeneratorX64::useByteOpRegister(MDefinition *mir)
michael@0 42 {
michael@0 43 return useRegister(mir);
michael@0 44 }
michael@0 45
michael@0 46 LAllocation
michael@0 47 LIRGeneratorX64::useByteOpRegisterOrNonDoubleConstant(MDefinition *mir)
michael@0 48 {
michael@0 49 return useRegisterOrNonDoubleConstant(mir);
michael@0 50 }
michael@0 51
michael@0 52 LDefinition
michael@0 53 LIRGeneratorX64::tempToUnbox()
michael@0 54 {
michael@0 55 return temp();
michael@0 56 }
michael@0 57
michael@0 58 bool
michael@0 59 LIRGeneratorX64::visitBox(MBox *box)
michael@0 60 {
michael@0 61 MDefinition *opd = box->getOperand(0);
michael@0 62
michael@0 63 // If the operand is a constant, emit near its uses.
michael@0 64 if (opd->isConstant() && box->canEmitAtUses())
michael@0 65 return emitAtUses(box);
michael@0 66
michael@0 67 if (opd->isConstant())
michael@0 68 return define(new(alloc()) LValue(opd->toConstant()->value()), box, LDefinition(LDefinition::BOX));
michael@0 69
michael@0 70 LBox *ins = new(alloc()) LBox(opd->type(), useRegister(opd));
michael@0 71 return define(ins, box, LDefinition(LDefinition::BOX));
michael@0 72 }
michael@0 73
michael@0 74 bool
michael@0 75 LIRGeneratorX64::visitUnbox(MUnbox *unbox)
michael@0 76 {
michael@0 77 MDefinition *box = unbox->getOperand(0);
michael@0 78 LUnboxBase *lir;
michael@0 79 if (IsFloatingPointType(unbox->type()))
michael@0 80 lir = new(alloc()) LUnboxFloatingPoint(useRegisterAtStart(box), unbox->type());
michael@0 81 else
michael@0 82 lir = new(alloc()) LUnbox(useRegisterAtStart(box));
michael@0 83
michael@0 84 if (unbox->fallible() && !assignSnapshot(lir, unbox->bailoutKind()))
michael@0 85 return false;
michael@0 86
michael@0 87 return define(lir, unbox);
michael@0 88 }
michael@0 89
michael@0 90 bool
michael@0 91 LIRGeneratorX64::visitReturn(MReturn *ret)
michael@0 92 {
michael@0 93 MDefinition *opd = ret->getOperand(0);
michael@0 94 JS_ASSERT(opd->type() == MIRType_Value);
michael@0 95
michael@0 96 LReturn *ins = new(alloc()) LReturn;
michael@0 97 ins->setOperand(0, useFixed(opd, JSReturnReg));
michael@0 98 return add(ins);
michael@0 99 }
michael@0 100
michael@0 101 bool
michael@0 102 LIRGeneratorX64::defineUntypedPhi(MPhi *phi, size_t lirIndex)
michael@0 103 {
michael@0 104 return defineTypedPhi(phi, lirIndex);
michael@0 105 }
michael@0 106
michael@0 107 void
michael@0 108 LIRGeneratorX64::lowerUntypedPhiInput(MPhi *phi, uint32_t inputPosition, LBlock *block, size_t lirIndex)
michael@0 109 {
michael@0 110 lowerTypedPhiInput(phi, inputPosition, block, lirIndex);
michael@0 111 }
michael@0 112
michael@0 113 bool
michael@0 114 LIRGeneratorX64::visitAsmJSUnsignedToDouble(MAsmJSUnsignedToDouble *ins)
michael@0 115 {
michael@0 116 JS_ASSERT(ins->input()->type() == MIRType_Int32);
michael@0 117 LAsmJSUInt32ToDouble *lir = new(alloc()) LAsmJSUInt32ToDouble(useRegisterAtStart(ins->input()));
michael@0 118 return define(lir, ins);
michael@0 119 }
michael@0 120
michael@0 121 bool
michael@0 122 LIRGeneratorX64::visitAsmJSUnsignedToFloat32(MAsmJSUnsignedToFloat32 *ins)
michael@0 123 {
michael@0 124 JS_ASSERT(ins->input()->type() == MIRType_Int32);
michael@0 125 LAsmJSUInt32ToFloat32 *lir = new(alloc()) LAsmJSUInt32ToFloat32(useRegisterAtStart(ins->input()));
michael@0 126 return define(lir, ins);
michael@0 127 }
michael@0 128
michael@0 129 bool
michael@0 130 LIRGeneratorX64::visitAsmJSLoadHeap(MAsmJSLoadHeap *ins)
michael@0 131 {
michael@0 132 MDefinition *ptr = ins->ptr();
michael@0 133 JS_ASSERT(ptr->type() == MIRType_Int32);
michael@0 134
michael@0 135 // The X64 does not inline an explicit bounds check so has no need to keep the
michael@0 136 // index in a register, however only a positive index is accepted because a
michael@0 137 // negative offset encoded as an offset in the addressing mode would not wrap
michael@0 138 // back into the protected area reserved for the heap.
michael@0 139 if (ptr->isConstant() && ptr->toConstant()->value().toInt32() >= 0) {
michael@0 140 LAsmJSLoadHeap *lir = new(alloc()) LAsmJSLoadHeap(LAllocation(ptr->toConstant()->vp()));
michael@0 141 return define(lir, ins);
michael@0 142 }
michael@0 143 return define(new(alloc()) LAsmJSLoadHeap(useRegisterAtStart(ptr)), ins);
michael@0 144 }
michael@0 145
michael@0 146 bool
michael@0 147 LIRGeneratorX64::visitAsmJSStoreHeap(MAsmJSStoreHeap *ins)
michael@0 148 {
michael@0 149 MDefinition *ptr = ins->ptr();
michael@0 150 JS_ASSERT(ptr->type() == MIRType_Int32);
michael@0 151 LAsmJSStoreHeap *lir;
michael@0 152
michael@0 153 // Note only a positive constant index is accepted because a negative offset
michael@0 154 // encoded as an offset in the addressing mode would not wrap back into the
michael@0 155 // protected area reserved for the heap.
michael@0 156 LAllocation ptrAlloc = useRegisterOrNonNegativeConstantAtStart(ptr);
michael@0 157 switch (ins->viewType()) {
michael@0 158 case ArrayBufferView::TYPE_INT8: case ArrayBufferView::TYPE_UINT8:
michael@0 159 case ArrayBufferView::TYPE_INT16: case ArrayBufferView::TYPE_UINT16:
michael@0 160 case ArrayBufferView::TYPE_INT32: case ArrayBufferView::TYPE_UINT32:
michael@0 161 lir = new(alloc()) LAsmJSStoreHeap(ptrAlloc, useRegisterOrConstantAtStart(ins->value()));
michael@0 162 break;
michael@0 163 case ArrayBufferView::TYPE_FLOAT32: case ArrayBufferView::TYPE_FLOAT64:
michael@0 164 lir = new(alloc()) LAsmJSStoreHeap(ptrAlloc, useRegisterAtStart(ins->value()));
michael@0 165 break;
michael@0 166 default: MOZ_ASSUME_UNREACHABLE("unexpected array type");
michael@0 167 }
michael@0 168
michael@0 169 return add(lir, ins);
michael@0 170 }
michael@0 171
michael@0 172 bool
michael@0 173 LIRGeneratorX64::visitAsmJSLoadFuncPtr(MAsmJSLoadFuncPtr *ins)
michael@0 174 {
michael@0 175 return define(new(alloc()) LAsmJSLoadFuncPtr(useRegister(ins->index()), temp()), ins);
michael@0 176 }
michael@0 177
michael@0 178 bool
michael@0 179 LIRGeneratorX64::visitStoreTypedArrayElementStatic(MStoreTypedArrayElementStatic *ins)
michael@0 180 {
michael@0 181 MOZ_ASSUME_UNREACHABLE("NYI");
michael@0 182 }

mercurial