Skip to content

Commit

Permalink
Bug 1279312 - Handle call-preserved registers in register allocator. …
Browse files Browse the repository at this point in the history
…r=bhackett

- Add a virtual isCallPreserved() method to LNode which allows a call
  instruction to indicate that it preserves the values of some registers. Use
  this hook in BacktrackingAllocator when processing a call instruction.

- Add a preservesTlsReg() property to MAsmJSCall and use this to implement the
  LAsmJSCall::isCallPreserved() method.

- Mark intra-module WebAssembly calls as preserving the TLS pointer register.

This change allows the backtracking register allocator to leave the TLS pointer
register alone in small functions that don't need it for something else. There
are probably more improvements to be done if we need to split the live range of
the TLS pointer register. For example, BacktrackingAllocator::splitAcrossCalls()
will still split that live range at all calls.
  • Loading branch information
Jakob Stoklund Olesen committed Jul 25, 2016
1 parent 7e6ef39 commit b3eb4d4
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
13 changes: 9 additions & 4 deletions js/src/asmjs/WasmIonCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ class FunctionCompiler
MAsmJSCall::Args regArgs_;
Vector<MAsmJSPassStackArg*, 0, SystemAllocPolicy> stackArgs_;
bool childClobbers_;
bool preservesTlsReg_;

friend class FunctionCompiler;

Expand All @@ -798,7 +799,8 @@ class FunctionCompiler
: lineOrBytecode_(lineOrBytecode),
maxChildStackBytes_(0),
spIncrement_(0),
childClobbers_(false)
childClobbers_(false),
preservesTlsReg_(false)
{ }
};

Expand All @@ -823,11 +825,13 @@ class FunctionCompiler
return args->stackArgs_.append(mir);
}

// Add the hidden TLS pointer argument to CallArgs.
// Add the hidden TLS pointer argument to CallArgs, and assume that it will
// be preserved by the call.
bool passTlsPointer(CallArgs* args)
{
if (inDeadCode())
return true;
args->preservesTlsReg_ = true;
return args->regArgs_.append(MAsmJSCall::Arg(AnyRegister(WasmTlsReg), tlsPointer_));
}

Expand Down Expand Up @@ -885,8 +889,9 @@ class FunctionCompiler
case MAsmJSCall::Callee::Builtin: kind = CallSiteDesc::Register; break;
}

MAsmJSCall* ins = MAsmJSCall::New(alloc(), CallSiteDesc(args.lineOrBytecode_, kind),
callee, args.regArgs_, ToMIRType(ret), args.spIncrement_);
MAsmJSCall* ins =
MAsmJSCall::New(alloc(), CallSiteDesc(args.lineOrBytecode_, kind), callee, args.regArgs_,
ToMIRType(ret), args.spIncrement_, args.preservesTlsReg_);
if (!ins)
return false;

Expand Down
5 changes: 4 additions & 1 deletion js/src/jit/BacktrackingAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,10 @@ BacktrackingAllocator::buildLivenessInfo()
break;
}
}
if (!found) {
// If this register doesn't have an explicit def above, mark
// it as clobbered by the call unless it is actually
// call-preserved.
if (!found && !ins->isCallPreserved(*iter)) {
if (!addInitialFixedRange(*iter, outputOf(*ins), outputOf(*ins).next()))
return false;
}
Expand Down
7 changes: 7 additions & 0 deletions js/src/jit/LIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,13 @@ class LNode
virtual bool isCall() const {
return false;
}

// Does this call preserve the given register?
// By default, it is assumed that all registers are clobbered by a call.
virtual bool isCallPreserved(AnyRegister reg) const {
return false;
}

uint32_t id() const {
return id_;
}
Expand Down
5 changes: 3 additions & 2 deletions js/src/jit/MIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5360,9 +5360,10 @@ MAsmJSUnsignedToFloat32::foldsTo(TempAllocator& alloc)

MAsmJSCall*
MAsmJSCall::New(TempAllocator& alloc, const wasm::CallSiteDesc& desc, Callee callee,
const Args& args, MIRType resultType, size_t spIncrement)
const Args& args, MIRType resultType, size_t spIncrement,
bool preservesTlsReg)
{
MAsmJSCall* call = new(alloc) MAsmJSCall(desc, callee, spIncrement);
MAsmJSCall* call = new(alloc) MAsmJSCall(desc, callee, spIncrement, preservesTlsReg);
call->setResultType(resultType);

if (!call->argRegs_.init(alloc, args.length()))
Expand Down
19 changes: 15 additions & 4 deletions js/src/jit/MIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -13531,9 +13531,14 @@ class MAsmJSCall final
Callee callee_;
FixedList<AnyRegister> argRegs_;
size_t spIncrement_;

MAsmJSCall(const wasm::CallSiteDesc& desc, Callee callee, size_t spIncrement)
: desc_(desc), callee_(callee), spIncrement_(spIncrement)
bool preservesTlsReg_;

MAsmJSCall(const wasm::CallSiteDesc& desc, Callee callee, size_t spIncrement,
bool preservesTlsReg)
: desc_(desc)
, callee_(callee)
, spIncrement_(spIncrement)
, preservesTlsReg_(preservesTlsReg)
{ }

public:
Expand All @@ -13547,7 +13552,8 @@ class MAsmJSCall final
typedef Vector<Arg, 8, SystemAllocPolicy> Args;

static MAsmJSCall* New(TempAllocator& alloc, const wasm::CallSiteDesc& desc, Callee callee,
const Args& args, MIRType resultType, size_t spIncrement);
const Args& args, MIRType resultType, size_t spIncrement,
bool preservesTlsReg);

size_t numArgs() const {
return argRegs_.length();
Expand All @@ -13571,6 +13577,11 @@ class MAsmJSCall final
return spIncrement_;
}

// Does this call preserve the value of the TLS pointer register?
bool preservesTlsReg() const {
return preservesTlsReg_;
}

bool possiblyCalls() const override {
return true;
}
Expand Down
7 changes: 7 additions & 0 deletions js/src/jit/shared/LIR-shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -8157,6 +8157,13 @@ class LAsmJSCall final : public LInstruction
return true;
}

bool isCallPreserved(AnyRegister reg) const {
// WebAssembly functions preserve the TLS pointer register.
if (reg.isFloat() || reg.gpr() != WasmTlsReg)
return false;
return mir()->preservesTlsReg();
}

// LInstruction interface
size_t numDefs() const {
return def_.isBogusTemp() ? 0 : 1;
Expand Down

0 comments on commit b3eb4d4

Please sign in to comment.