1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef jit_IonAnalysis_h
#define jit_IonAnalysis_h
// This file declares various analysis passes that operate on MIR.
#include "jit/JitAllocPolicy.h"
#include "jit/MIR.h"
namespace js {
namespace jit {
class MIRGenerator;
class MIRGraph;
[[nodiscard]] bool
PruneUnusedBranches(MIRGenerator* mir, MIRGraph& graph);
[[nodiscard]] bool
FoldTests(MIRGraph& graph);
[[nodiscard]] bool
SplitCriticalEdges(MIRGraph& graph);
bool
IsUint32Type(const MDefinition* def);
enum Observability {
ConservativeObservability,
AggressiveObservability
};
[[nodiscard]] bool
EliminatePhis(MIRGenerator* mir, MIRGraph& graph, Observability observe);
size_t
MarkLoopBlocks(MIRGraph& graph, MBasicBlock* header, bool* canOsr);
void
UnmarkLoopBlocks(MIRGraph& graph, MBasicBlock* header);
[[nodiscard]] bool
MakeLoopsContiguous(MIRGraph& graph);
[[nodiscard]] bool
EliminateDeadResumePointOperands(MIRGenerator* mir, MIRGraph& graph);
[[nodiscard]] bool
EliminateDeadCode(MIRGenerator* mir, MIRGraph& graph);
[[nodiscard]] bool
ApplyTypeInformation(MIRGenerator* mir, MIRGraph& graph);
void
RenumberBlocks(MIRGraph& graph);
[[nodiscard]] bool
AccountForCFGChanges(MIRGenerator* mir, MIRGraph& graph, bool updateAliasAnalysis,
bool underValueNumberer = false);
[[nodiscard]] bool
RemoveUnmarkedBlocks(MIRGenerator* mir, MIRGraph& graph, uint32_t numMarkedBlocks);
[[nodiscard]] bool
CreateMIRRootList(IonBuilder& builder);
void
ClearDominatorTree(MIRGraph& graph);
[[nodiscard]] bool
BuildDominatorTree(MIRGraph& graph);
[[nodiscard]] bool
BuildPhiReverseMapping(MIRGraph& graph);
void
AssertBasicGraphCoherency(MIRGraph& graph);
void
AssertGraphCoherency(MIRGraph& graph);
void
AssertExtendedGraphCoherency(MIRGraph& graph, bool underValueNumberer = false);
[[nodiscard]] bool
EliminateRedundantChecks(MIRGraph& graph);
[[nodiscard]] bool
AddKeepAliveInstructions(MIRGraph& graph);
class MDefinition;
// Simple linear sum of the form 'n' or 'x + n'.
struct SimpleLinearSum
{
MDefinition* term;
int32_t constant;
SimpleLinearSum(MDefinition* term, int32_t constant)
: term(term), constant(constant)
{}
};
// Math done in a Linear sum can either be in a modulo space, in which case
// overflow are wrapped around, or they can be computed in the integer-space in
// which case we have to check that no overflow can happen when summing
// constants.
//
// When the caller ignores which space it is, the definition would be used to
// deduce it.
enum class MathSpace {
Modulo,
Infinite,
Unknown
};
SimpleLinearSum
ExtractLinearSum(MDefinition* ins, MathSpace space = MathSpace::Unknown);
[[nodiscard]] bool
ExtractLinearInequality(MTest* test, BranchDirection direction,
SimpleLinearSum* plhs, MDefinition** prhs, bool* plessEqual);
struct LinearTerm
{
MDefinition* term;
int32_t scale;
LinearTerm(MDefinition* term, int32_t scale)
: term(term), scale(scale)
{
}
};
// General linear sum of the form 'x1*n1 + x2*n2 + ... + n'
class LinearSum
{
public:
explicit LinearSum(TempAllocator& alloc)
: terms_(alloc),
constant_(0)
{
}
LinearSum(const LinearSum& other)
: terms_(other.terms_.allocPolicy()),
constant_(other.constant_)
{
AutoEnterOOMUnsafeRegion oomUnsafe;
if (!terms_.appendAll(other.terms_))
oomUnsafe.crash("LinearSum::LinearSum");
}
// These return false on an integer overflow, and afterwards the sum must
// not be used.
[[nodiscard]] bool multiply(int32_t scale);
[[nodiscard]] bool add(const LinearSum& other, int32_t scale = 1);
[[nodiscard]] bool add(SimpleLinearSum other, int32_t scale = 1);
[[nodiscard]] bool add(MDefinition* term, int32_t scale);
[[nodiscard]] bool add(int32_t constant);
// Unlike the above function, on failure this leaves the sum unchanged and
// it can still be used.
[[nodiscard]] bool divide(uint32_t scale);
int32_t constant() const { return constant_; }
size_t numTerms() const { return terms_.length(); }
LinearTerm term(size_t i) const { return terms_[i]; }
void replaceTerm(size_t i, MDefinition* def) { terms_[i].term = def; }
void dump(GenericPrinter& out) const;
void dump() const;
private:
Vector<LinearTerm, 2, JitAllocPolicy> terms_;
int32_t constant_;
};
// Convert all components of a linear sum (except, optionally, the constant)
// and add any new instructions to the end of block.
MDefinition*
ConvertLinearSum(TempAllocator& alloc, MBasicBlock* block, const LinearSum& sum,
bool convertConstant = false);
// Convert the test 'sum >= 0' to a comparison, adding any necessary
// instructions to the end of block.
MCompare*
ConvertLinearInequality(TempAllocator& alloc, MBasicBlock* block, const LinearSum& sum);
[[nodiscard]] bool
AnalyzeNewScriptDefiniteProperties(JSContext* cx,
DPAConstraintInfo& constraintInfo,
HandleFunction fun,
ObjectGroup* group,
HandlePlainObject baseobj,
Vector<TypeNewScript::Initializer>* initializerList);
[[nodiscard]] bool
AnalyzeArgumentsUsage(JSContext* cx, JSScript* script);
bool
DeadIfUnused(const MDefinition* def);
bool
IsDiscardable(const MDefinition* def);
void
DumpMIRExpressions(MIRGraph& graph);
} // namespace jit
} // namespace js
#endif /* jit_IonAnalysis_h */
|