diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2018-05-07 15:08:12 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2018-05-25 09:46:39 +0000 |
commit | f783aa97c3d8d9df74212b4350203182d2d167f1 (patch) | |
tree | ea9ec96e80e2028542678a8db89e49acd713c7d1 /src/qml/compiler/qv4bytecodegenerator_p.h | |
parent | 8390b610401f42d239eee3390052cf685f47335d (diff) |
V4: Peephole optimize LoadReg/MoveReg
The following sequence:
StoreReg rX
LoadReg rX
Can be optimized by dropping the LoadReg, as the value is still in the
accumulator. Also, the sequence:
StoreReg rX
MoveReg rY, rX
Can be optimized to:
StoreReg rX
StoreReg rY
This last optimization prevents one load from the JS stack (reading rX).
Both cases are only valid if there is no label on the second
instruction.
Change-Id: Ibd4543459e1eab4da55e92248eba544c707c5456
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4bytecodegenerator_p.h')
-rw-r--r-- | src/qml/compiler/qv4bytecodegenerator_p.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/qml/compiler/qv4bytecodegenerator_p.h b/src/qml/compiler/qv4bytecodegenerator_p.h index 0033acf3c7..98951b610c 100644 --- a/src/qml/compiler/qv4bytecodegenerator_p.h +++ b/src/qml/compiler/qv4bytecodegenerator_p.h @@ -77,7 +77,9 @@ public: Label(BytecodeGenerator *generator, LinkMode mode = LinkNow) : generator(generator), index(generator->labels.size()) { - generator->labels.append(mode == LinkNow ? generator->instructions.size() : -1); + generator->labels.append(-1); + if (mode == LinkNow) + link(); } static Label returnLabel() { Label l; @@ -92,6 +94,7 @@ public: Q_ASSERT(index >= 0); Q_ASSERT(generator->labels[index] == -1); generator->labels[index] = generator->instructions.size(); + generator->clearLastInstruction(); } BytecodeGenerator *generator = nullptr; @@ -261,6 +264,11 @@ public: addJumpInstruction(Instruction::JumpTrue()).link(*trueLabel); } + void clearLastInstruction() + { + lastInstrType = -1; + } + private: friend struct Jump; friend struct Label; @@ -292,6 +300,9 @@ private: int startLine = 0; int currentLine = 0; bool debugMode = false; + + int lastInstrType = -1; + Moth::Instr lastInstr; }; } |