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 QList<QQmlJSRegisterContent> trackedTypes;
44 QHash<int, QQmlJSRegisterContent> typeReaders;
45 QHash<int, Conversions> registerReadersAndConversions;
46 int trackedRegister;
47 };
48
49 QV4::Moth::ByteCodeHandler::Verdict startInstruction(QV4::Moth::Instr::Type) override
50 {
51 return ProcessInstruction;
52 }
53 void endInstruction(QV4::Moth::Instr::Type) override { }
54
55 void populateBasicBlocks();
56 void populateReaderLocations();
57 void adjustTypes();
58 bool canMove(int instructionOffset, const RegisterAccess &access) const;
59
60 void removeReadsFromErasedInstructions(const QFlatMap<int, InstructionAnnotation>::const_iterator &it);
61 void removeDeadStoresUntilStable();
62 bool eraseDeadStore(const InstructionAnnotations::iterator &it, bool &erasedReaders);
63
64 QHash<int, RegisterAccess> m_readerLocations;
65 QList<ObjectOrArrayDefinition> m_objectAndArrayDefinitions;
66};
67
68QT_END_NAMESPACE
69
70#endif // QQMLJSOPTIMIZATIONS_P_H
void appendOrdered(const typename OriginalFlatMap::iterator &i)
OriginalFlatMap take()
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)