diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2018-11-23 12:34:48 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2019-01-31 09:19:13 +0000 |
commit | 3f2efbd1b904cdc9358ed328235502e338b020bf (patch) | |
tree | 38fe2d4e1d00d30fb6ce51944eae3f5d8bd662da /src/qml/jit/qv4baselineassembler.cpp | |
parent | 965f49bb4f83c9eedd56f9ec01f166a4634a05d3 (diff) |
V4: Generate labels for backward jumps
When analyzing the bytecode from top-to-bottom in a single pass, we
don't know when a jump back to previously seen code occurs. For example,
in the baseline JIT we would already have generated code for some
bytecode when we see a jump back (like at the end of a loop body), and
we can't go back and insert a label to jump to.
As JavaScript has no goto's, the only backward jumps are at the end of
loops, so there are very few cases where we need to actually generate
labels.
This was previously handled by analyzing the bytecode twice: once to
collect all jump targets, and then second pass over the bytecode to do
the actual JITting (which would use the jump targets to insert labels).
We can now do that with one single pass. So the trade-off is to store
4 bytes more per function plus 4 bytes for each loop, instead of having
to analyze all functions only to find where all jumps are each time that
function is JITted.
Change-Id: I3abfcb69f65851a397dbd4a9762ea5e9e57495f6
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/jit/qv4baselineassembler.cpp')
-rw-r--r-- | src/qml/jit/qv4baselineassembler.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/qml/jit/qv4baselineassembler.cpp b/src/qml/jit/qv4baselineassembler.cpp index 9663754cbf..987f366256 100644 --- a/src/qml/jit/qv4baselineassembler.cpp +++ b/src/qml/jit/qv4baselineassembler.cpp @@ -1382,28 +1382,31 @@ void BaselineAssembler::cmpStrictNotEqual(int lhs) pasm()->setAccumulatorTag(QV4::Value::ValueTypeInternal::Boolean); } -void BaselineAssembler::jump(int offset) +int BaselineAssembler::jump(int offset) { pasm()->addJumpToOffset(pasm()->jump(), offset); + return offset; } -void BaselineAssembler::jumpTrue(int offset) +int BaselineAssembler::jumpTrue(int offset) { pasm()->toBoolean([this, offset](PlatformAssembler::RegisterID resultReg) { auto jump = pasm()->branch32(PlatformAssembler::NotEqual, TrustedImm32(0), resultReg); pasm()->addJumpToOffset(jump, offset); }); + return offset; } -void BaselineAssembler::jumpFalse(int offset) +int BaselineAssembler::jumpFalse(int offset) { pasm()->toBoolean([this, offset](PlatformAssembler::RegisterID resultReg) { auto jump = pasm()->branch32(PlatformAssembler::Equal, TrustedImm32(0), resultReg); pasm()->addJumpToOffset(jump, offset); }); + return offset; } -void BaselineAssembler::jumpNoException(int offset) +int BaselineAssembler::jumpNoException(int offset) { auto jump = pasm()->branch32( PlatformAssembler::Equal, @@ -1411,11 +1414,13 @@ void BaselineAssembler::jumpNoException(int offset) offsetof(EngineBase, hasException)), TrustedImm32(0)); pasm()->addJumpToOffset(jump, offset); + return offset; } -void BaselineAssembler::jumpNotUndefined(int offset) +int BaselineAssembler::jumpNotUndefined(int offset) { pasm()->jumpNotUndefined(offset); + return offset; } void BaselineAssembler::prepareCallWithArgCount(int argc) @@ -1539,10 +1544,11 @@ void BaselineAssembler::setException() noException.link(pasm()); } -void BaselineAssembler::setUnwindHandler(int offset) +int BaselineAssembler::setUnwindHandler(int offset) { auto l = pasm()->storePtrWithPatch(TrustedImmPtr(nullptr), pasm()->exceptionHandlerAddress()); pasm()->addEHTarget(l, offset); + return offset; } @@ -1568,12 +1574,13 @@ void JIT::BaselineAssembler::unwindDispatch() noUnwind.link(pasm()); } -void JIT::BaselineAssembler::unwindToLabel(int level, int offset) +int JIT::BaselineAssembler::unwindToLabel(int level, int offset) { auto l = pasm()->storePtrWithPatch(TrustedImmPtr(nullptr), Address(PlatformAssembler::CppStackFrameRegister, offsetof(CppStackFrame, unwindLabel))); pasm()->addEHTarget(l, offset); pasm()->store32(TrustedImm32(level), Address(PlatformAssembler::CppStackFrameRegister, offsetof(CppStackFrame, unwindLevel))); gotoCatchException(); + return offset; } void BaselineAssembler::pushCatchContext(int index, int name) |