1 | // Copyright (C) 2024 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 QQMLJSOPTIMIZATIONS_P_H |
5 | #define QQMLJSOPTIMIZATIONS_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 | #include <private/qqmljscompilepass_p.h> |
18 | |
19 | QT_BEGIN_NAMESPACE |
20 | |
21 | class Q_QMLCOMPILER_EXPORT QQmlJSOptimizations : public QQmlJSCompilePass |
22 | { |
23 | public: |
24 | using Conversions = QSet<int>; |
25 | |
26 | QQmlJSOptimizations(const QV4::Compiler::JSUnitGenerator *unitGenerator, |
27 | const QQmlJSTypeResolver *typeResolver, QQmlJSLogger *logger, |
28 | BasicBlocks basicBlocks, InstructionAnnotations annotations, |
29 | QList<ObjectOrArrayDefinition> objectAndArrayDefinitions) |
30 | : QQmlJSCompilePass(unitGenerator, typeResolver, logger, basicBlocks, annotations), |
31 | m_objectAndArrayDefinitions{ objectAndArrayDefinitions } |
32 | { |
33 | } |
34 | |
35 | ~QQmlJSOptimizations() = default; |
36 | |
37 | BlocksAndAnnotations run(const Function *function, QQmlJS::DiagnosticMessage *error); |
38 | |
39 | private: |
40 | struct RegisterAccess |
41 | { |
42 | QList<QQmlJSScope::ConstPtr> trackedTypes; |
43 | QHash<int, QQmlJSScope::ConstPtr> typeReaders; |
44 | QHash<int, Conversions> registerReadersAndConversions; |
45 | int trackedRegister; |
46 | }; |
47 | |
48 | QV4::Moth::ByteCodeHandler::Verdict startInstruction(QV4::Moth::Instr::Type) override |
49 | { |
50 | return ProcessInstruction; |
51 | } |
52 | void endInstruction(QV4::Moth::Instr::Type) override { } |
53 | |
54 | void populateBasicBlocks(); |
55 | void populateReaderLocations(); |
56 | void adjustTypes(); |
57 | bool canMove(int instructionOffset, const RegisterAccess &access) const; |
58 | |
59 | QHash<int, RegisterAccess> m_readerLocations; |
60 | QList<ObjectOrArrayDefinition> m_objectAndArrayDefinitions; |
61 | }; |
62 | |
63 | QT_END_NAMESPACE |
64 | |
65 | #endif // QQMLJSOPTIMIZATIONS_P_H |
66 | |