Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmljsoptimizations_p.h
Go to the documentation of this file.
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// Qt-Security score:significant
4
5#ifndef QQMLJSOPTIMIZATIONS_P_H
6#define QQMLJSOPTIMIZATIONS_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17
18#include <private/qqmljscompilepass_p.h>
19
21
22class Q_QMLCOMPILER_EXPORT QQmlJSOptimizations : public QQmlJSCompilePass
23{
24public:
25 using Conversions = QSet<int>;
26
27 QQmlJSOptimizations(const QV4::Compiler::JSUnitGenerator *unitGenerator,
28 const QQmlJSTypeResolver *typeResolver, QQmlJSLogger *logger,
29 const BasicBlocks &basicBlocks, const InstructionAnnotations &annotations,
30 QList<ObjectOrArrayDefinition> objectAndArrayDefinitions)
31 : QQmlJSCompilePass(unitGenerator, typeResolver, logger, basicBlocks, annotations),
32 m_objectAndArrayDefinitions{ std::move(objectAndArrayDefinitions) }
33 {
34 }
35
36 ~QQmlJSOptimizations() = default;
37
38 BlocksAndAnnotations run(const Function *function);
39
40private:
41 struct RegisterAccess
42 {
43 // Content written by this instruction, or contents merged/converted into this register.
44 QList<QQmlJSRegisterContent> trackedTypes;
45
46 // Instructions that genuinely consume the *value* this write produced (never renames/copies
47 // of it), keyed by instruction offset, with the exact content each one reads it as.
48 // Tracked by content identity, so this follows the value across register renames rather
49 // than being tied to one register slot.
50 // Drives the write's required output type (see QQmlJSTypeResolver::adjustTrackedType) and
51 // whether it can be moved into its single use site (see canMove).
52 QHash<int, QQmlJSRegisterContent> typeReaders;
53
54 // Reads of this write's *specific register slot* while it's still the reaching definition
55 // (i.e. before any later write overwrites that register), keyed by instruction offset,
56 // together with the type-conversion instructions crossed between the write and each read.
57 // Drives which type conversions are actually needed in codegen (see liveConversions in
58 // adjustTypes) and, combined with typeReaders, whether a store is conversion-free enough to
59 // move.
60 QHash<int, Conversions> registerReadersAndConversions;
61
62 // Register slot written to by this instruction.
63 int trackedRegister;
64 };
65
66 QV4::Moth::ByteCodeHandler::Verdict startInstruction(QV4::Moth::Instr::Type) override
67 {
68 return ProcessInstruction;
69 }
70 void endInstruction(QV4::Moth::Instr::Type) override { }
71
72 void populateBasicBlocks();
73 void populateReaderLocationsTrackedTypes();
74 void populateReaderLocationsReadersAndConversions();
75 void adjustTypes();
76 bool canMove(int instructionOffset, const RegisterAccess &access) const;
77
78 void removeReadsFromErasedInstructions(const QFlatMap<int, InstructionAnnotation>::const_iterator &it);
79 void removeDeadStoresUntilStable();
80 bool eraseDeadStore(const InstructionAnnotations::iterator &it, bool &erasedReaders);
81
82 QHash<int, RegisterAccess> m_readerLocations;
83 QList<ObjectOrArrayDefinition> m_objectAndArrayDefinitions;
84};
85
86QT_END_NAMESPACE
87
88#endif // QQMLJSOPTIMIZATIONS_P_H
void appendOrdered(const typename OriginalFlatMap::iterator &i)
OriginalFlatMap take()
Combined button and popup list for selecting options.
static bool mergeBlockState(BlockState &to, const BlockState &from)
static QString adjustErrorMessage(QQmlJSRegisterContent origin, const QQmlJSScope::ConstPtr &conversion)
static bool containsAny(const ContainerA &container, const ContainerB &elements)
static QString adjustErrorMessage(QQmlJSRegisterContent origin, QQmlJSRegisterContent conversion)
QHash< int, RegisterState > registers