1 | // Copyright (C) 2022 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef QQMLJSBASICBLOCKS_P_H |
5 | #define QQMLJSBASICBLOCKS_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | |
17 | |
18 | #include <private/qqmljscompilepass_p.h> |
19 | #include <private/qflatmap_p.h> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | class Q_QMLCOMPILER_PRIVATE_EXPORT QQmlJSBasicBlocks : public QQmlJSCompilePass |
24 | { |
25 | public: |
26 | struct BasicBlock { |
27 | QList<int> jumpOrigins; |
28 | QList<int> readRegisters; |
29 | QList<QQmlJSScope::ConstPtr> readTypes; |
30 | int jumpTarget = -1; |
31 | bool jumpIsUnconditional = false; |
32 | }; |
33 | |
34 | QQmlJSBasicBlocks(const QV4::Compiler::JSUnitGenerator *unitGenerator, |
35 | const QQmlJSTypeResolver *typeResolver, QQmlJSLogger *logger) |
36 | : QQmlJSCompilePass(unitGenerator, typeResolver, logger) |
37 | { |
38 | } |
39 | |
40 | ~QQmlJSBasicBlocks() = default; |
41 | |
42 | InstructionAnnotations run( |
43 | const Function *function, const InstructionAnnotations &annotations, |
44 | QQmlJS::DiagnosticMessage *error); |
45 | |
46 | private: |
47 | struct RegisterAccess |
48 | { |
49 | QList<QQmlJSScope::ConstPtr> trackedTypes; |
50 | QHash<int, QQmlJSScope::ConstPtr> typeReaders; |
51 | QHash<int, QList<int>> registerReadersAndConversions; |
52 | int trackedRegister; |
53 | }; |
54 | |
55 | QV4::Moth::ByteCodeHandler::Verdict startInstruction(QV4::Moth::Instr::Type type) override; |
56 | void endInstruction(QV4::Moth::Instr::Type type) override; |
57 | |
58 | void generate_Jump(int offset) override; |
59 | void generate_JumpTrue(int offset) override; |
60 | void generate_JumpFalse(int offset) override; |
61 | void generate_JumpNoException(int offset) override; |
62 | void generate_JumpNotUndefined(int offset) override; |
63 | |
64 | void generate_Ret() override; |
65 | void generate_ThrowException() override; |
66 | |
67 | void generate_DefineArray(int argc, int argv) override; |
68 | |
69 | enum JumpMode { Unconditional, Conditional }; |
70 | void processJump(int offset, JumpMode mode); |
71 | void populateBasicBlocks(); |
72 | void populateReaderLocations(); |
73 | void adjustTypes(); |
74 | bool canMove(int instructionOffset, const RegisterAccess &access) const; |
75 | |
76 | InstructionAnnotations m_annotations; |
77 | QFlatMap<int, BasicBlock> m_basicBlocks; |
78 | QHash<int, RegisterAccess> m_readerLocations; |
79 | QList<int> m_arrayDefinitions; |
80 | bool m_skipUntilNextLabel = false; |
81 | bool m_hadBackJumps = false; |
82 | }; |
83 | |
84 | QT_END_NAMESPACE |
85 | |
86 | #endif // QQMLJSBASICBLOCKS_P_H |
87 | |