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