Bug 1288222 - Baldr: factor out common global access code (r=bbouvier)

MozReview-Commit-ID: 5NOGyihk8s

--HG--
extra : rebase_source : 622fa7961d494a252ef2a7c5c04959904965ce96
This commit is contained in:
Luke Wagner 2016-07-20 12:56:53 -05:00
parent f58ed6912f
commit fc7d4e3d39
21 changed files with 51 additions and 178 deletions

View File

@ -2057,25 +2057,11 @@ class BaseCompiler
masm.move32(Imm32(sigIndex), WasmTableCallSigReg);
}
#if defined(JS_CODEGEN_X64)
// CodeGeneratorX64::visitAsmJSLoadFuncPtr()
{
ScratchI32 scratch(*this);
CodeOffset label = masm.loadRipRelativeInt64(scratch);
masm.append(GlobalAccess(label, globalDataOffset));
masm.loadPtr(Operand(scratch, ptrReg, ScalePointer, 0), ptrReg);
masm.loadWasmGlobalPtr(globalDataOffset, scratch);
masm.loadPtr(BaseIndex(scratch, ptrReg, ScalePointer, 0), ptrReg);
}
#elif defined(JS_CODEGEN_X86)
// CodeGeneratorX86::visitAsmJSLoadFuncPtr()
{
ScratchI32 scratch(*this);
CodeOffset label = masm.movlWithPatch(PatchedAbsoluteAddress(), scratch);
masm.append(GlobalAccess(label, globalDataOffset));
masm.loadPtr(Operand(scratch, ptrReg, ScalePointer), ptrReg);
}
#else
MOZ_CRASH("BaseCompiler platform hook: funcPtrCall");
#endif
callDynamic(ptrReg, call);
}
@ -2085,18 +2071,7 @@ class BaseCompiler
void ffiCall(unsigned globalDataOffset, const FunctionCall& call)
{
Register ptrReg = WasmTableCallPtrReg;
#if defined(JS_CODEGEN_X64)
// CodeGeneratorX64::visitAsmJSLoadFFIFunc()
CodeOffset label = masm.loadRipRelativeInt64(ptrReg);
masm.append(GlobalAccess(label, globalDataOffset));
#elif defined(JS_CODEGEN_X86)
// CodeGeneratorX86::visitAsmJSLoadFFIFunc()
CodeOffset label = masm.movlWithPatch(PatchedAbsoluteAddress(), ptrReg);
masm.append(GlobalAccess(label, globalDataOffset));
#else
MOZ_CRASH("BaseCompiler platform hook: ffiCall");
#endif
masm.loadWasmGlobalPtr(globalDataOffset, ptrReg);
callDynamic(ptrReg, call);
}

View File

@ -11228,6 +11228,29 @@ CodeGenerator::visitAsmJSVoidReturn(LAsmJSVoidReturn* lir)
masm.jump(&returnLabel_);
}
void
CodeGenerator::visitAsmJSLoadFuncPtr(LAsmJSLoadFuncPtr* ins)
{
const MAsmJSLoadFuncPtr* mir = ins->mir();
Register index = ToRegister(ins->index());
Register out = ToRegister(ins->output());
if (mir->hasLimit()) {
masm.branch32(Assembler::Condition::AboveOrEqual, index, Imm32(mir->limit()),
wasm::JumpTarget::OutOfBounds);
}
masm.loadWasmGlobalPtr(mir->globalDataOffset(), out);
masm.loadPtr(BaseIndex(out, index, ScalePointer), out);
}
void
CodeGenerator::visitAsmJSLoadFFIFunc(LAsmJSLoadFFIFunc* ins)
{
masm.loadWasmGlobalPtr(ins->mir()->globalDataOffset(), ToRegister(ins->output()));
}
void
CodeGenerator::emitAssertRangeI(const Range* r, Register input)
{

View File

@ -363,6 +363,8 @@ class CodeGenerator final : public CodeGeneratorSpecific
void visitAsmJSParameter(LAsmJSParameter* lir);
void visitAsmJSReturn(LAsmJSReturn* ret);
void visitAsmJSVoidReturn(LAsmJSVoidReturn* ret);
void visitAsmJSLoadFuncPtr(LAsmJSLoadFuncPtr* ins);
void visitAsmJSLoadFFIFunc(LAsmJSLoadFFIFunc* ins);
void visitLexicalCheck(LLexicalCheck* ins);
void visitThrowRuntimeLexicalError(LThrowRuntimeLexicalError* ins);
void visitGlobalNameConflictsCheck(LGlobalNameConflictsCheck* ins);

View File

@ -1266,6 +1266,9 @@ class MacroAssembler : public MacroAssemblerSpecific
void loadJitActivation(Register dest) {
loadPtr(AbsoluteAddress(GetJitContext()->runtime->addressOfActivation()), dest);
}
void loadWasmActivation(Register dest) {
loadWasmGlobalPtr(wasm::ActivationGlobalDataOffset, dest);
}
template<typename T>
void loadTypedOrValue(const T& src, TypedOrValueRegister dest) {

View File

@ -2752,32 +2752,6 @@ CodeGeneratorARM::visitWasmStoreGlobalVar(LWasmStoreGlobalVar* ins)
}
}
void
CodeGeneratorARM::visitAsmJSLoadFuncPtr(LAsmJSLoadFuncPtr* ins)
{
const MAsmJSLoadFuncPtr* mir = ins->mir();
Register index = ToRegister(ins->index());
Register out = ToRegister(ins->output());
if (mir->hasLimit()) {
masm.branch32(Assembler::Condition::AboveOrEqual, index, Imm32(mir->limit()),
wasm::JumpTarget::OutOfBounds);
}
masm.ma_ldr(Address(GlobalReg, mir->globalDataOffset() - AsmJSGlobalRegBias), out);
masm.ma_ldr(DTRAddr(out, DtrRegImmShift(index, LSL, 2)), out);
}
void
CodeGeneratorARM::visitAsmJSLoadFFIFunc(LAsmJSLoadFFIFunc* ins)
{
const MAsmJSLoadFFIFunc* mir = ins->mir();
masm.ma_ldr(Address(GlobalReg, mir->globalDataOffset() - AsmJSGlobalRegBias),
ToRegister(ins->output()));
}
void
CodeGeneratorARM::visitNegI(LNegI* ins)
{

View File

@ -217,8 +217,6 @@ class CodeGeneratorARM : public CodeGeneratorShared
void visitAsmJSAtomicBinopHeap(LAsmJSAtomicBinopHeap* ins);
void visitAsmJSAtomicBinopHeapForEffect(LAsmJSAtomicBinopHeapForEffect* ins);
void visitAsmJSAtomicBinopCallout(LAsmJSAtomicBinopCallout* ins);
void visitAsmJSLoadFuncPtr(LAsmJSLoadFuncPtr* ins);
void visitAsmJSLoadFFIFunc(LAsmJSLoadFFIFunc* ins);
void visitAsmJSPassStackArg(LAsmJSPassStackArg* ins);
void visitWasmTruncateToInt32(LWasmTruncateToInt32* ins);
void visitOutOfLineWasmTruncateCheck(OutOfLineWasmTruncateCheck* ool);

View File

@ -1438,12 +1438,13 @@ class MacroAssemblerARMCompat : public MacroAssemblerARM
as_vmov(VFPRegister(dest).singleOverlay(), VFPRegister(src).singleOverlay(), cc);
}
void loadWasmActivation(Register dest) {
loadPtr(Address(GlobalReg, wasm::ActivationGlobalDataOffset - AsmJSGlobalRegBias), dest);
void loadWasmGlobalPtr(uint32_t globalDataOffset, Register dest) {
loadPtr(Address(GlobalReg, globalDataOffset - AsmJSGlobalRegBias), dest);
}
void loadAsmJSHeapRegisterFromGlobalData() {
loadPtr(Address(GlobalReg, wasm::HeapGlobalDataOffset - AsmJSGlobalRegBias), HeapReg);
loadWasmGlobalPtr(wasm::HeapGlobalDataOffset, HeapReg);
}
// Instrumentation for entering and leaving the profiler.
void profilerEnterFrame(Register framePtr, Register scratch);
void profilerExitFrame();

View File

@ -703,18 +703,6 @@ CodeGeneratorARM64::visitWasmStoreGlobalVar(LWasmStoreGlobalVar* ins)
MOZ_CRASH("visitWasmStoreGlobalVar");
}
void
CodeGeneratorARM64::visitAsmJSLoadFuncPtr(LAsmJSLoadFuncPtr* ins)
{
MOZ_CRASH("visitAsmJSLoadFuncPtr");
}
void
CodeGeneratorARM64::visitAsmJSLoadFFIFunc(LAsmJSLoadFFIFunc* ins)
{
MOZ_CRASH("visitAsmJSLoadFFIFunc");
}
void
CodeGeneratorARM64::visitNegI(LNegI* ins)
{

View File

@ -203,8 +203,6 @@ class CodeGeneratorARM64 : public CodeGeneratorShared
void visitAsmJSStoreHeap(LAsmJSStoreHeap* ins);
void visitAsmJSCompareExchangeHeap(LAsmJSCompareExchangeHeap* ins);
void visitAsmJSAtomicBinopHeap(LAsmJSAtomicBinopHeap* ins);
void visitAsmJSLoadFuncPtr(LAsmJSLoadFuncPtr* ins);
void visitAsmJSLoadFFIFunc(LAsmJSLoadFFIFunc* ins);
void visitAsmJSPassStackArg(LAsmJSPassStackArg* ins);
void visitWasmLoadGlobalVar(LWasmLoadGlobalVar* ins);

View File

@ -2305,12 +2305,12 @@ class MacroAssemblerCompat : public vixl::MacroAssembler
#endif
}
void loadWasmActivation(Register dest) {
loadPtr(Address(GlobalReg, wasm::ActivationGlobalDataOffset - AsmJSGlobalRegBias), dest);
void loadWasmGlobalPtr(uint32_t globalDataOffset, Register dest) {
loadPtr(Address(GlobalReg, globalDataOffset - AsmJSGlobalRegBias), dest);
}
void loadAsmJSHeapRegisterFromGlobalData() {
loadPtr(Address(GlobalReg, wasm::HeapGlobalDataOffset - AsmJSGlobalRegBias), HeapReg);
loadPtr(Address(GlobalReg, wasm::HeapGlobalDataOffset - AsmJSGlobalRegBias + 8), HeapLenReg);
loadWasmGlobalPtr(wasm::HeapGlobalDataOffset, HeapReg);
loadWasmGlobalPtr(wasm::HeapGlobalDataOffset + 8, HeapLenReg);
}
// Overwrites the payload bits of a dest register containing a Value.

View File

@ -2262,32 +2262,6 @@ CodeGeneratorMIPSShared::visitWasmStoreGlobalVar(LWasmStoreGlobalVar* ins)
masm.storeDouble(ToFloatRegister(ins->value()), Address(GlobalReg, addr));
}
void
CodeGeneratorMIPSShared::visitAsmJSLoadFuncPtr(LAsmJSLoadFuncPtr* ins)
{
const MAsmJSLoadFuncPtr* mir = ins->mir();
Register index = ToRegister(ins->index());
Register out = ToRegister(ins->output());
unsigned addr = mir->globalDataOffset() - AsmJSGlobalRegBias;
if (mir->hasLimit()) {
masm.branch32(Assembler::Condition::AboveOrEqual, index, Imm32(mir->limit()),
wasm::JumpTarget::OutOfBounds);
}
BaseIndex source(GlobalReg, index, ScalePointer, addr);
masm.loadPtr(source, out);
}
void
CodeGeneratorMIPSShared::visitAsmJSLoadFFIFunc(LAsmJSLoadFFIFunc* ins)
{
const MAsmJSLoadFFIFunc* mir = ins->mir();
masm.loadPtr(Address(GlobalReg, mir->globalDataOffset() - AsmJSGlobalRegBias),
ToRegister(ins->output()));
}
void
CodeGeneratorMIPSShared::visitNegI(LNegI* ins)
{

View File

@ -204,8 +204,6 @@ class CodeGeneratorMIPSShared : public CodeGeneratorShared
void visitAsmJSAtomicExchangeHeap(LAsmJSAtomicExchangeHeap* ins);
void visitAsmJSAtomicBinopHeap(LAsmJSAtomicBinopHeap* ins);
void visitAsmJSAtomicBinopHeapForEffect(LAsmJSAtomicBinopHeapForEffect* ins);
void visitAsmJSLoadFuncPtr(LAsmJSLoadFuncPtr* ins);
void visitAsmJSLoadFFIFunc(LAsmJSLoadFFIFunc* ins);
void visitAsmJSPassStackArg(LAsmJSPassStackArg* ins);
void visitAsmSelect(LAsmSelect* ins);

View File

@ -998,12 +998,12 @@ class MacroAssemblerMIPSCompat : public MacroAssemblerMIPS
as_movs(dest, src);
}
void loadWasmActivation(Register dest) {
loadPtr(Address(GlobalReg, wasm::ActivationGlobalDataOffset - AsmJSGlobalRegBias), dest);
void loadWasmGlobalPtr(uint32_t globalDataOffset, Register dest) {
loadPtr(Address(GlobalReg, globalDataOffset - AsmJSGlobalRegBias), dest);
}
void loadAsmJSHeapRegisterFromGlobalData() {
MOZ_ASSERT(Imm16::IsInSignedRange(wasm::HeapGlobalDataOffset - AsmJSGlobalRegBias));
loadPtr(Address(GlobalReg, wasm::HeapGlobalDataOffset - AsmJSGlobalRegBias), HeapReg);
loadWasmGlobalPtr(wasm::HeapGlobalDataOffset, HeapReg);
}
// Instrumentation for entering and leaving the profiler.

View File

@ -1000,12 +1000,12 @@ class MacroAssemblerMIPS64Compat : public MacroAssemblerMIPS64
as_movs(dest, src);
}
void loadWasmActivation(Register dest) {
loadPtr(Address(GlobalReg, wasm::ActivationGlobalDataOffset - AsmJSGlobalRegBias), dest);
void loadWasmGlobalPtr(uint32_t globalDataOffset, Register dest) {
loadPtr(Address(GlobalReg, globalDataOffset - AsmJSGlobalRegBias), dest);
}
void loadAsmJSHeapRegisterFromGlobalData() {
MOZ_ASSERT(Imm16::IsInSignedRange(wasm::HeapGlobalDataOffset - AsmJSGlobalRegBias));
loadPtr(Address(GlobalReg, wasm::HeapGlobalDataOffset - AsmJSGlobalRegBias), HeapReg);
loadWasmGlobalPtr(wasm::HeapGlobalDataOffset, dest);
}
// Instrumentation for entering and leaving the profiler.

View File

@ -405,6 +405,7 @@ class MacroAssemblerNone : public Assembler
void buildFakeExitFrame(Register, uint32_t*) { MOZ_CRASH(); }
bool buildOOLFakeExitFrame(void*) { MOZ_CRASH(); }
void loadWasmGlobalPtr(uint32_t, Register) { MOZ_CRASH(); }
void loadWasmActivation(Register) { MOZ_CRASH(); }
void loadAsmJSHeapRegisterFromGlobalData() { MOZ_CRASH(); }

View File

@ -825,13 +825,12 @@ class Assembler : public AssemblerX86Shared
return CodeOffset(masm.leaq_rip(dest.encoding()).offset());
}
void loadWasmActivation(Register dest) {
void loadWasmGlobalPtr(uint32_t globalDataOffset, Register dest) {
CodeOffset label = loadRipRelativeInt64(dest);
append(wasm::GlobalAccess(label, wasm::ActivationGlobalDataOffset));
append(wasm::GlobalAccess(label, globalDataOffset));
}
void loadAsmJSHeapRegisterFromGlobalData() {
CodeOffset label = loadRipRelativeInt64(HeapReg);
append(wasm::GlobalAccess(label, wasm::HeapGlobalDataOffset));
loadWasmGlobalPtr(wasm::HeapGlobalDataOffset, HeapReg);
}
void cmpq(Register rhs, Register lhs) {

View File

@ -1246,34 +1246,6 @@ CodeGeneratorX64::visitWasmStoreGlobalVar(LWasmStoreGlobalVar* ins)
masm.append(wasm::GlobalAccess(label, mir->globalDataOffset()));
}
void
CodeGeneratorX64::visitAsmJSLoadFuncPtr(LAsmJSLoadFuncPtr* ins)
{
const MAsmJSLoadFuncPtr* mir = ins->mir();
Register index = ToRegister(ins->index());
Register out = ToRegister(ins->output());
if (mir->hasLimit()) {
masm.branch32(Assembler::Condition::AboveOrEqual, index, Imm32(mir->limit()),
wasm::JumpTarget::OutOfBounds);
}
CodeOffset label = masm.loadRipRelativeInt64(out);
masm.append(wasm::GlobalAccess(label, mir->globalDataOffset()));
masm.loadPtr(Operand(out, index, ScalePointer, 0), out);
}
void
CodeGeneratorX64::visitAsmJSLoadFFIFunc(LAsmJSLoadFFIFunc* ins)
{
MAsmJSLoadFFIFunc* mir = ins->mir();
CodeOffset label = masm.loadRipRelativeInt64(ToRegister(ins->output()));
masm.append(wasm::GlobalAccess(label, mir->globalDataOffset()));
}
void
CodeGeneratorX64::visitTruncateDToInt32(LTruncateDToInt32* ins)
{

View File

@ -85,8 +85,6 @@ class CodeGeneratorX64 : public CodeGeneratorX86Shared
void visitAsmJSAtomicExchangeHeap(LAsmJSAtomicExchangeHeap* ins);
void visitAsmJSAtomicBinopHeap(LAsmJSAtomicBinopHeap* ins);
void visitAsmJSAtomicBinopHeapForEffect(LAsmJSAtomicBinopHeapForEffect* ins);
void visitAsmJSLoadFuncPtr(LAsmJSLoadFuncPtr* ins);
void visitAsmJSLoadFFIFunc(LAsmJSLoadFFIFunc* ins);
void visitAsmJSUInt32ToDouble(LAsmJSUInt32ToDouble* lir);
void visitAsmJSUInt32ToFloat32(LAsmJSUInt32ToFloat32* lir);
void visitAsmReinterpretFromI64(LAsmReinterpretFromI64* lir);

View File

@ -920,9 +920,9 @@ class Assembler : public AssemblerX86Shared
return CodeOffset(masm.currentOffset());
}
void loadWasmActivation(Register dest) {
void loadWasmGlobalPtr(uint32_t globalDataOffset, Register dest) {
CodeOffset label = movlWithPatch(PatchedAbsoluteAddress(), dest);
append(wasm::GlobalAccess(label, wasm::ActivationGlobalDataOffset));
append(wasm::GlobalAccess(label, globalDataOffset));
}
void loadAsmJSHeapRegisterFromGlobalData() {
// x86 doesn't have a pinned heap register.

View File

@ -901,35 +901,6 @@ CodeGeneratorX86::visitWasmStoreGlobalVar(LWasmStoreGlobalVar* ins)
masm.append(wasm::GlobalAccess(label, mir->globalDataOffset()));
}
void
CodeGeneratorX86::visitAsmJSLoadFuncPtr(LAsmJSLoadFuncPtr* ins)
{
const MAsmJSLoadFuncPtr* mir = ins->mir();
Register index = ToRegister(ins->index());
Register out = ToRegister(ins->output());
if (mir->hasLimit()) {
masm.branch32(Assembler::Condition::AboveOrEqual, index, Imm32(mir->limit()),
wasm::JumpTarget::OutOfBounds);
}
CodeOffset label = masm.movlWithPatch(PatchedAbsoluteAddress(), out);
masm.append(wasm::GlobalAccess(label, mir->globalDataOffset()));
masm.loadPtr(Operand(out, index, ScalePointer), out);
}
void
CodeGeneratorX86::visitAsmJSLoadFFIFunc(LAsmJSLoadFFIFunc* ins)
{
MAsmJSLoadFFIFunc* mir = ins->mir();
Register out = ToRegister(ins->output());
CodeOffset label = masm.movlWithPatch(PatchedAbsoluteAddress(), out);
masm.append(wasm::GlobalAccess(label, mir->globalDataOffset()));
}
namespace js {
namespace jit {

View File

@ -68,8 +68,6 @@ class CodeGeneratorX86 : public CodeGeneratorX86Shared
void visitAsmJSAtomicExchangeHeap(LAsmJSAtomicExchangeHeap* ins);
void visitAsmJSAtomicBinopHeap(LAsmJSAtomicBinopHeap* ins);
void visitAsmJSAtomicBinopHeapForEffect(LAsmJSAtomicBinopHeapForEffect* ins);
void visitAsmJSLoadFuncPtr(LAsmJSLoadFuncPtr* ins);
void visitAsmJSLoadFFIFunc(LAsmJSLoadFFIFunc* ins);
void visitWasmTruncateToInt32(LWasmTruncateToInt32* ins);
void visitOutOfLineTruncate(OutOfLineTruncate* ool);