aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4bytecodegenerator.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Restore offset/length in QQmlJS::DiagnosticMessageSimon Hausmann2020-03-021-1/+1
| | | | | | | | | | | | This is needed in a few places outside of declarative, so this change restores the loc member in DiagnosticMessage and moves QQmlJS::AST::SourceLocation into common's QQmlJS namespace/directory. QQmlError is unaffected and retains only line/column. Amends d4d197d06279f9257647628f7e1ccc9ec763a6bb Change-Id: Ifb9d344228e3c6e9e26fc4fe112686f9336ea2b2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Allow generating debug instructions even if !qml_debugUlf Hermann2019-07-101-4/+0
| | | | | | | | | | qml_debug is about the runtime debug support. Even if it's not running in debug mode itself, the compiler should still be able to generate debug instructions to be interpreted later by a potentially debugging runtime. Change-Id: Ided5ff8ef9ce820de204e8a967ddeddad3fea5d5 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* V4: Generate labels for backward jumpsErik Verbruggen2019-01-311-0/+4
| | | | | | | | | | | | | | | | | | | | | | | 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>
* Trim some #includesErik Verbruggen2018-10-071-1/+0
| | | | | Change-Id: I5346fc36c89b7969c2bef3069f256f33bd4d9eb9 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix compression of jump instructions with an type >= 256Lars Knoll2018-09-081-2/+2
| | | | | | | | | Those instructions are encoded with a two byte instruction id that needs to be read correctly to figure out whether it's a wide or narrow instruction. Change-Id: I769d1a2d121f9f372105fa94771785d517694855 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Allow for more than 128 bytecode instructionsLars Knoll2018-07-031-9/+7
| | | | | | | | | | | | | | | | | | | | | | Instructions always occupy two numbers, an even and the following odd one, for the single byte and four byte encoding. An instruction of 0x0 is now a NOP, but 0x1 implies that the instruction type is using two bytes, and the following byte needs to be read as well to get the correct instruction type. Encoding and decoding of those two byte instructions is fully transparent, and adding more instructions now doesn't require any special handling. The first 127 instructions in the FOR_EACH_MOTH_INSTR macro will get a single byte encoding, the remaining ones will use two bytes. When adding new instructions, make sure to put often used and fast instructions into the first 127 instructions, while adding rarely used (or slow) instructions to the end (before Debug though). Change-Id: Id772a109641ab68feb228c3abd05f41ae7075e94 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Change the instruction encoding for the bytecodeLars Knoll2018-07-031-11/+10
| | | | | | | | | | | | Change the encoding, so that even instructions are short ones, odd instructions long. This implies that the lowest bit encodes whether an instruction is short or long (1 vs 4 byte encoded). This prepares for allowing us to extend the totoal number of instructions beyond 128. Change-Id: I4732e7241d3593b24ad25cd69555edc25f38d2f6 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* V4: Peephole optimize LoadReg/MoveRegErik Verbruggen2018-05-251-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Fix build with GCC 7: possibly uninitialized array warningThiago Macieira2018-02-211-1/+1
| | | | | | | qv4bytecodegenerator.cpp:99:19: error: ‘instructionsAsInts[3]’ may be used uninitialized in this function [-Werror=maybe-uninitialized] Change-Id: I940917d6763842499b18fffd1513ff143fc502bb Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix clang 5 warningsAllan Sandfeld Jensen2018-02-071-0/+2
| | | | | | | Fixes clang develop-builds Change-Id: If262d7038fc36bcec281be4c218b3cf3d4ae4deb Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix build without QML debuggingUlf Hermann2018-01-161-0/+2
| | | | | Change-Id: Ie1b18dd00705b1913572b87c6968a63438e7a90c Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Prospective fix for big endian and AOTSimon Hausmann2018-01-071-4/+12
| | | | | | | | Ensure that the integer arguments for widely encoded instructions are always encoded as little endian. Change-Id: Iccd45aefb20b20d76fe1618d6706435142b202b9 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Minor cleanup in byte code instruction compressionSimon Hausmann2018-01-071-1/+3
| | | | | | | | Once we have identified that an instruction needs to be encoded in wide format, we do not inspect the remaining arguments any further. Change-Id: I0164acedc68b28bd95f9aab0c0fd1702a59de90d Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix decoding of bytecode instructions on ARM generated on x86-64Simon Hausmann2018-01-051-4/+4
| | | | | | | | | | | | | | | | | | | | | | | Due to the difference of sign of the char type, byte code is encoded differently on x86-64 than if it was on ARM and it also is decoded differently. The problem at hand here was that negative jumps were encoded as two-byte instructions (opcode and negative offset as byte) on x86-64 when qmlcachegen is run. At run-time the negative offset was read into a char type and consequently interpreted as a positive jump, leading to crashes. The explicit use of qint8 as signed byte type in encoding/decoding sensitive parts avoids the decoding issue and should also result in consistent encoding. The added auto-test is (among other configurations) run in the CI under qemu, which means the x86-64 host-built qmlcachegen will generate byte code and the tst_qmlcachegen ARM binary will run under qemu and reproduce this scenario. Task-number: QTBUG-65521 Change-Id: I615628f53475dad38a41095c6e7ffea0c34d58ac Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Re-enable Debug instructions and locations for QML functionsUlf Hermann2017-11-061-1/+15
| | | | | | | | | | | | | | | | | | | | | | Debug instructions are used to trigger break points and are added for every source line. We also need to insert Debug instructions before Ret, so that we can step out. We also need to assign line numbers to the entry and return points of "abbreviated" QML functions (by simulating lbrace and rbrace) so that we can set break points on them. The line numbers on Ret need to be negative, so that you cannot (accidentally) set break points on them. A typical signal handler or binding in QML consists of only one line and if you set a break point on that line, you want it to hit only once, when entering the function. If the line numbers on Ret were positive, it would be hit again on exit. Some of the tests in tst_qqmldebugjs implicitly check for that. Also the new interpreter does something on the left brace, so a function actually starts there, not on the first statement. Change-Id: Id9dfb20e35696b420d0950deab988f7cc5197bfc Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix building for QNX with buggy GCCErik Verbruggen2017-09-131-2/+2
| | | | | | | | The complaint from GCC was that a static array InstrInfo::argumentCount) cannot be in a union. Change-Id: Ibd8dad478dc95853004fb2a871d5883d4dc73dcc Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix line number mapping to work with non increasing line numbersLars Knoll2017-08-291-7/+9
| | | | | | | | | The old map assumed that line numbers are always increasing, something that isn't always true. So move to a format where we map blocks of bytecode to a line number instead. Change-Id: I1cd9dd1329d415122cd3d560294ef53007f879f8 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Remove the distinction between wide and xwide instructionsLars Knoll2017-08-281-31/+15
| | | | | | | | | | | | | | Only keep 1 byte and 4 byte wide instructions. As this gives less than 256 distinct instructions, those can now again be encoded in 1 byte, dropping the Wide and XWide prefix instructions. This gives us 95% of the size savings that we had before, by being able to encode the full instruction in one byte, while bringing back pretty much all of the speed lost through the compression. Change-Id: I9ec978d43314ed304ca0ee5546035d2b581b6dc3 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Compress jump instructions as wellLars Knoll2017-08-281-38/+73
| | | | | Change-Id: If95a5733594a1beaa41063249a364988190844c5 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Compress all non jump instructionsLars Knoll2017-08-281-6/+57
| | | | | Change-Id: I90daee5388f5aba5a5c1cd643379adc9a8e05039 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Introduce the wide/xwide instruction prefixesLars Knoll2017-08-281-4/+5
| | | | | | | | | | | And add proper decoding for the prefixed instructions to the VME and bytecode dumper. We still only generate XWide instructions, that will get fixed in the next change. Change-Id: I6d2dc6a0a4f706044038274ca79e019a6c9bb7d9 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Start compressing the byte codeLars Knoll2017-08-281-1/+15
| | | | | | | As a first step, use only one byte for the instruction type. Change-Id: I762a05233c277a7144472793bc71e41d9e8e82cb Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Get rid of the separate vector of JumpsLars Knoll2017-08-281-5/+8
| | | | | | | Instead add it to the unencoded instruction vector Change-Id: I7e88d808bb94f75aecdf9d3ed9bace2055c1da5d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Decode instructions into registersLars Knoll2017-08-281-1/+1
| | | | | | | | Don't use the old instruction structures in the VME anymore, instead directly decode into scoped registers. Change-Id: Ie03ebad98050ebfd9eb9cc7e9273e5db92884a89 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Change offsets to be integer basedLars Knoll2017-08-281-2/+2
| | | | | | | | | This is big enough for generated bytecode, and gives more uniform sizing in our instructions (everything's an int), that will simplify moving over to a compressed instruction stream. Change-Id: Ieb13c5db84348f11c3297c08dca640bb9ec5f224 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Move line number information into a side tableLars Knoll2017-08-251-7/+13
| | | | | | | | | Don't emit any Line instructions anymore, and instead store the info in a side table in the compiled data, where it can be looked up on demand. Change-Id: Idcaf3bf4ee4129fd62f9e717bf1277dc6a34fe19 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Store arguments in the stack frame before the locals/tempsErik Verbruggen2017-08-031-5/+0
| | | | | | | | | | All escaping arguments will still be loaded/stored from/to the CallData, but this is not the common case. In a subsequent patch we can make the caller prepare the stack frame, and for the common case we don't even need to copy arguments around. Change-Id: I3fbb6fe575a564d05a9fd5dcc0c8f4129eac3bc2 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Where applicable, rename Temp* to Register*Erik Verbruggen2017-08-031-10/+10
| | | | | Change-Id: Ib7839ac09f520aaff3fadfdb37ea63d85a257bfd Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix various signed/unsigned warningsErik Verbruggen2017-08-021-3/+3
| | | | | Change-Id: I9f4a5a8470c1abc6b07a28c71fdad0d208e1fea1 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Remove now unused filesLars Knoll2017-06-301-1/+0
| | | | | | | | | Remove all files from the old compiler pipeline that are now unused. This includes the whole IR, JIT code generation, and the old Moth Isel. Change-Id: I50d06abfbcf0e9755a54ed94638f8bb74f9512b1 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Don't use IR::Function for temp allocation anymoreLars Knoll2017-06-301-8/+8
| | | | | Change-Id: Id9ab6f3e9f5ae1c1bedb0b34bf1fac6abfe0bbfc Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Quick fix for line numbers to make tests passErik Verbruggen2017-06-291-1/+1
| | | | | | | | It'd be way better to store line numbers in a IP->line table, instead of putting Line instructions into the bytecode. Change-Id: Ie20abf356612a0692507a7e079ba87d711707eb9 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Switch over to new JS call setupLars Knoll2017-06-291-0/+9
| | | | | | | | | | | | | | | | Differences: - push parameters on the stack, including space for CallData members - call instructions calculate the argument start - use temp space above the calldata to evaluate arguments - fewer temporaries are needed when a call is done while generating the arguments of another call - when calling the function, the js stack space above the callData is not used, allowing for optimizations in the future - Array and ObjectLiteral use the same mechanism Change-Id: Id100fa06f12cc9d941b0f90b0b81b8270a8e4f5d Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Rename push instruction to InitStackFrameErik Verbruggen2017-06-291-4/+4
| | | | | Change-Id: I67f8397686a439cede37b52863d32dc194bee23f Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Re-enable lookupsLars Knoll2017-06-221-1/+1
| | | | | Change-Id: I02d57d2cbb4ae56c0c4626d96cbdf9935b366579 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Get back some line number informationLars Knoll2017-06-201-0/+11
| | | | | Change-Id: I7d7845a9d8d147bd363c0f60df41066fab355272 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Allow defining Labels as destinations for JumpsLars Knoll2017-06-201-4/+6
| | | | | | | | Those Labels can be linked to a code location further ahead. Change-Id: I82f1a719654162db0e0abb46df602ee2e01154da Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Implement support for conditional expressionsLars Knoll2017-06-201-2/+5
| | | | | | Change-Id: Ifcd57713e1cfa9514d3955e26f739a359cdaa8e5 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Rework and implement Jump handling in the bytecode generatorLars Knoll2017-06-191-0/+12
| | | | | | | | Add Label and Jump classes to facilitate the handling, and resolve them to proper offsets at finalize() time. Change-Id: Ic140a3ceb848fb29657a1b156c97b806db6dc434 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Add the push instruction required to set up the tempsLars Knoll2017-06-191-3/+7
| | | | | | | And a commented out finalize() call to the bytecodegenerator Change-Id: Iaaf8981ee658e19b6816589d4340a8e5744764b7 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* Add a BytecodeGenerator classLars Knoll2017-06-191-0/+66
Use the generator to store the list of instructions, labels and patches. The finalize() method can then create the final bytecode out of that list. Change-Id: If2ea3118ed6e8744545bb918ecc4bbc87d6a3ff1 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>