@@ -72,127 +72,127 @@ bool CaptureTracker::isDereferenceableOrNull(Value *O, const DataLayout &DL) {
72
72
}
73
73
74
74
namespace {
75
- struct SimpleCaptureTracker : public CaptureTracker {
76
- explicit SimpleCaptureTracker (bool ReturnCaptures)
77
- : ReturnCaptures(ReturnCaptures) {}
75
+ struct SimpleCaptureTracker : public CaptureTracker {
76
+ explicit SimpleCaptureTracker (bool ReturnCaptures)
77
+ : ReturnCaptures(ReturnCaptures) {}
78
78
79
- void tooManyUses () override {
80
- LLVM_DEBUG (dbgs () << " Captured due to too many uses\n " );
81
- Captured = true ;
82
- }
79
+ void tooManyUses () override {
80
+ LLVM_DEBUG (dbgs () << " Captured due to too many uses\n " );
81
+ Captured = true ;
82
+ }
83
83
84
- bool captured (const Use *U) override {
85
- if (isa<ReturnInst>(U->getUser ()) && !ReturnCaptures)
86
- return false ;
84
+ bool captured (const Use *U) override {
85
+ if (isa<ReturnInst>(U->getUser ()) && !ReturnCaptures)
86
+ return false ;
87
87
88
- LLVM_DEBUG (dbgs () << " Captured by: " << *U->getUser () << " \n " );
88
+ LLVM_DEBUG (dbgs () << " Captured by: " << *U->getUser () << " \n " );
89
89
90
- Captured = true ;
91
- return true ;
92
- }
90
+ Captured = true ;
91
+ return true ;
92
+ }
93
93
94
- bool ReturnCaptures;
94
+ bool ReturnCaptures;
95
95
96
- bool Captured = false ;
97
- };
96
+ bool Captured = false ;
97
+ };
98
98
99
- // / Only find pointer captures which happen before the given instruction. Uses
100
- // / the dominator tree to determine whether one instruction is before another.
101
- // / Only support the case where the Value is defined in the same basic block
102
- // / as the given instruction and the use.
103
- struct CapturesBefore : public CaptureTracker {
99
+ // / Only find pointer captures which happen before the given instruction. Uses
100
+ // / the dominator tree to determine whether one instruction is before another.
101
+ // / Only support the case where the Value is defined in the same basic block
102
+ // / as the given instruction and the use.
103
+ struct CapturesBefore : public CaptureTracker {
104
104
105
- CapturesBefore (bool ReturnCaptures, const Instruction *I,
106
- const DominatorTree *DT, bool IncludeI, const LoopInfo *LI)
107
- : BeforeHere(I), DT(DT), ReturnCaptures(ReturnCaptures),
108
- IncludeI (IncludeI), LI(LI) {}
105
+ CapturesBefore (bool ReturnCaptures, const Instruction *I,
106
+ const DominatorTree *DT, bool IncludeI, const LoopInfo *LI)
107
+ : BeforeHere(I), DT(DT), ReturnCaptures(ReturnCaptures),
108
+ IncludeI (IncludeI), LI(LI) {}
109
109
110
- void tooManyUses () override { Captured = true ; }
110
+ void tooManyUses () override { Captured = true ; }
111
111
112
- bool isSafeToPrune (Instruction *I) {
113
- if (BeforeHere == I)
114
- return !IncludeI;
112
+ bool isSafeToPrune (Instruction *I) {
113
+ if (BeforeHere == I)
114
+ return !IncludeI;
115
115
116
- // We explore this usage only if the usage can reach "BeforeHere".
117
- // If use is not reachable from entry, there is no need to explore.
118
- if (!DT->isReachableFromEntry (I->getParent ()))
119
- return true ;
116
+ // We explore this usage only if the usage can reach "BeforeHere".
117
+ // If use is not reachable from entry, there is no need to explore.
118
+ if (!DT->isReachableFromEntry (I->getParent ()))
119
+ return true ;
120
120
121
- // Check whether there is a path from I to BeforeHere.
122
- return !isPotentiallyReachable (I, BeforeHere, nullptr , DT, LI);
123
- }
121
+ // Check whether there is a path from I to BeforeHere.
122
+ return !isPotentiallyReachable (I, BeforeHere, nullptr , DT, LI);
123
+ }
124
124
125
- bool captured (const Use *U) override {
126
- Instruction *I = cast<Instruction>(U->getUser ());
127
- if (isa<ReturnInst>(I) && !ReturnCaptures)
128
- return false ;
125
+ bool captured (const Use *U) override {
126
+ Instruction *I = cast<Instruction>(U->getUser ());
127
+ if (isa<ReturnInst>(I) && !ReturnCaptures)
128
+ return false ;
129
129
130
- // Check isSafeToPrune() here rather than in shouldExplore() to avoid
131
- // an expensive reachability query for every instruction we look at.
132
- // Instead we only do one for actual capturing candidates.
133
- if (isSafeToPrune (I))
134
- return false ;
130
+ // Check isSafeToPrune() here rather than in shouldExplore() to avoid
131
+ // an expensive reachability query for every instruction we look at.
132
+ // Instead we only do one for actual capturing candidates.
133
+ if (isSafeToPrune (I))
134
+ return false ;
135
135
136
- Captured = true ;
137
- return true ;
138
- }
136
+ Captured = true ;
137
+ return true ;
138
+ }
139
139
140
- const Instruction *BeforeHere;
141
- const DominatorTree *DT;
140
+ const Instruction *BeforeHere;
141
+ const DominatorTree *DT;
142
142
143
- bool ReturnCaptures;
144
- bool IncludeI;
143
+ bool ReturnCaptures;
144
+ bool IncludeI;
145
145
146
- bool Captured = false ;
146
+ bool Captured = false ;
147
147
148
- const LoopInfo *LI;
149
- };
148
+ const LoopInfo *LI;
149
+ };
150
150
151
- // / Find the 'earliest' instruction before which the pointer is known not to
152
- // / be captured. Here an instruction A is considered earlier than instruction
153
- // / B, if A dominates B. If 2 escapes do not dominate each other, the
154
- // / terminator of the common dominator is chosen. If not all uses cannot be
155
- // / analyzed, the earliest escape is set to the first instruction in the
156
- // / function entry block.
157
- // NOTE: Users have to make sure instructions compared against the earliest
158
- // escape are not in a cycle.
159
- struct EarliestCaptures : public CaptureTracker {
160
-
161
- EarliestCaptures (bool ReturnCaptures, Function &F, const DominatorTree &DT)
162
- : DT(DT), ReturnCaptures(ReturnCaptures), F(F) {}
163
-
164
- void tooManyUses () override {
165
- Captured = true ;
166
- EarliestCapture = &*F.getEntryBlock ().begin ();
167
- }
151
+ // / Find the 'earliest' instruction before which the pointer is known not to
152
+ // / be captured. Here an instruction A is considered earlier than instruction
153
+ // / B, if A dominates B. If 2 escapes do not dominate each other, the
154
+ // / terminator of the common dominator is chosen. If not all uses cannot be
155
+ // / analyzed, the earliest escape is set to the first instruction in the
156
+ // / function entry block.
157
+ // NOTE: Users have to make sure instructions compared against the earliest
158
+ // escape are not in a cycle.
159
+ struct EarliestCaptures : public CaptureTracker {
168
160
169
- bool captured (const Use *U) override {
170
- Instruction *I = cast<Instruction>(U->getUser ());
171
- if (isa<ReturnInst>(I) && !ReturnCaptures)
172
- return false ;
161
+ EarliestCaptures (bool ReturnCaptures, Function &F, const DominatorTree &DT)
162
+ : DT(DT), ReturnCaptures(ReturnCaptures), F(F) {}
173
163
174
- if (!EarliestCapture)
175
- EarliestCapture = I;
176
- else
177
- EarliestCapture = DT.findNearestCommonDominator (EarliestCapture, I);
178
- Captured = true ;
164
+ void tooManyUses () override {
165
+ Captured = true ;
166
+ EarliestCapture = &*F.getEntryBlock ().begin ();
167
+ }
179
168
180
- // Return false to continue analysis; we need to see all potential
181
- // captures.
169
+ bool captured (const Use *U) override {
170
+ Instruction *I = cast<Instruction>(U->getUser ());
171
+ if (isa<ReturnInst>(I) && !ReturnCaptures)
182
172
return false ;
183
- }
184
173
185
- Instruction *EarliestCapture = nullptr ;
174
+ if (!EarliestCapture)
175
+ EarliestCapture = I;
176
+ else
177
+ EarliestCapture = DT.findNearestCommonDominator (EarliestCapture, I);
178
+ Captured = true ;
186
179
187
- const DominatorTree &DT;
180
+ // Return false to continue analysis; we need to see all potential
181
+ // captures.
182
+ return false ;
183
+ }
188
184
189
- bool ReturnCaptures ;
185
+ Instruction *EarliestCapture = nullptr ;
190
186
191
- bool Captured = false ;
187
+ const DominatorTree &DT ;
192
188
193
- Function &F;
194
- };
195
- }
189
+ bool ReturnCaptures;
190
+
191
+ bool Captured = false ;
192
+
193
+ Function &F;
194
+ };
195
+ } // namespace
196
196
197
197
// / PointerMayBeCaptured - Return true if this pointer value may be captured
198
198
// / by the enclosing function (which is required to exist). This routine can
0 commit comments