@@ -64,16 +64,15 @@ class SwiftARCContractImpl {
64
64
bool Changed;
65
65
66
66
// / Swift RC Identity.
67
- SwiftRCIdentity * RC;
67
+ SwiftRCIdentity RC;
68
68
69
69
// / The function that we are processing.
70
70
Function &F;
71
71
72
72
// / The entry point builder that is used to construct ARC entry points.
73
73
ARCEntryPointBuilder B;
74
74
public:
75
- SwiftARCContractImpl (Function &InF, SwiftRCIdentity *InRC)
76
- : Changed(false ), RC(InRC), F(InF), B(F) {}
75
+ SwiftARCContractImpl (Function &InF) : Changed(false ), F(InF), B(F) {}
77
76
78
77
// The top level run routine of the pass.
79
78
bool run ();
@@ -109,7 +108,7 @@ performRRNOptimization(DenseMap<Value *, LocalState> &PtrToLocalStateMap) {
109
108
break ;
110
109
}
111
110
}
112
- B.createRetainN (RC-> getSwiftRCIdentityRoot (O), RetainList.size (), RI);
111
+ B.createRetainN (RC. getSwiftRCIdentityRoot (O), RetainList.size (), RI);
113
112
114
113
// Replace all uses of the retain instructions with our new retainN and
115
114
// then delete them.
@@ -135,7 +134,7 @@ performRRNOptimization(DenseMap<Value *, LocalState> &PtrToLocalStateMap) {
135
134
break ;
136
135
}
137
136
}
138
- B.createReleaseN (RC-> getSwiftRCIdentityRoot (O), ReleaseList.size (), RI);
137
+ B.createReleaseN (RC. getSwiftRCIdentityRoot (O), ReleaseList.size (), RI);
139
138
140
139
// Remove all old release instructions.
141
140
for (auto *Inst : ReleaseList) {
@@ -159,7 +158,7 @@ performRRNOptimization(DenseMap<Value *, LocalState> &PtrToLocalStateMap) {
159
158
break ;
160
159
}
161
160
}
162
- B.createUnknownObjectRetainN (RC-> getSwiftRCIdentityRoot (O),
161
+ B.createUnknownObjectRetainN (RC. getSwiftRCIdentityRoot (O),
163
162
UnknownObjectRetainList.size (), RI);
164
163
165
164
// Replace all uses of the retain instructions with our new retainN and
@@ -187,7 +186,7 @@ performRRNOptimization(DenseMap<Value *, LocalState> &PtrToLocalStateMap) {
187
186
break ;
188
187
}
189
188
}
190
- B.createUnknownObjectReleaseN (RC-> getSwiftRCIdentityRoot (O),
189
+ B.createUnknownObjectReleaseN (RC. getSwiftRCIdentityRoot (O),
191
190
UnknownObjectReleaseList.size (), RI);
192
191
193
192
// Remove all old release instructions.
@@ -214,7 +213,7 @@ performRRNOptimization(DenseMap<Value *, LocalState> &PtrToLocalStateMap) {
214
213
}
215
214
}
216
215
// Bridge retain may modify the input reference before forwarding it.
217
- auto *I = B.createBridgeRetainN (RC-> getSwiftRCIdentityRoot (O),
216
+ auto *I = B.createBridgeRetainN (RC. getSwiftRCIdentityRoot (O),
218
217
BridgeRetainList.size (), RI);
219
218
220
219
// Remove all old retain instructions.
@@ -246,8 +245,8 @@ performRRNOptimization(DenseMap<Value *, LocalState> &PtrToLocalStateMap) {
246
245
break ;
247
246
}
248
247
}
249
- B.createBridgeReleaseN (RC-> getSwiftRCIdentityRoot (O),
250
- BridgeReleaseList.size (), RI);
248
+ B.createBridgeReleaseN (RC. getSwiftRCIdentityRoot (O),
249
+ BridgeReleaseList.size (), RI);
251
250
252
251
// Remove all old release instructions.
253
252
for (auto *Inst : BridgeReleaseList) {
@@ -290,15 +289,15 @@ bool SwiftARCContractImpl::run() {
290
289
continue ;
291
290
case RT_Retain: {
292
291
auto *CI = cast<CallInst>(&Inst);
293
- auto *ArgVal = RC-> getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
292
+ auto *ArgVal = RC. getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
294
293
295
294
LocalState &LocalEntry = PtrToLocalStateMap[ArgVal];
296
295
LocalEntry.RetainList .push_back (CI);
297
296
continue ;
298
297
}
299
298
case RT_UnknownObjectRetain: {
300
299
auto *CI = cast<CallInst>(&Inst);
301
- auto *ArgVal = RC-> getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
300
+ auto *ArgVal = RC. getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
302
301
303
302
LocalState &LocalEntry = PtrToLocalStateMap[ArgVal];
304
303
LocalEntry.UnknownObjectRetainList .push_back (CI);
@@ -307,7 +306,7 @@ bool SwiftARCContractImpl::run() {
307
306
case RT_Release: {
308
307
// Stash any releases that we see.
309
308
auto *CI = cast<CallInst>(&Inst);
310
- auto *ArgVal = RC-> getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
309
+ auto *ArgVal = RC. getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
311
310
312
311
LocalState &LocalEntry = PtrToLocalStateMap[ArgVal];
313
312
LocalEntry.ReleaseList .push_back (CI);
@@ -316,23 +315,23 @@ bool SwiftARCContractImpl::run() {
316
315
case RT_UnknownObjectRelease: {
317
316
// Stash any releases that we see.
318
317
auto *CI = cast<CallInst>(&Inst);
319
- auto *ArgVal = RC-> getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
318
+ auto *ArgVal = RC. getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
320
319
321
320
LocalState &LocalEntry = PtrToLocalStateMap[ArgVal];
322
321
LocalEntry.UnknownObjectReleaseList .push_back (CI);
323
322
continue ;
324
323
}
325
324
case RT_BridgeRetain: {
326
325
auto *CI = cast<CallInst>(&Inst);
327
- auto *ArgVal = RC-> getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
326
+ auto *ArgVal = RC. getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
328
327
329
328
LocalState &LocalEntry = PtrToLocalStateMap[ArgVal];
330
329
LocalEntry.BridgeRetainList .push_back (CI);
331
330
continue ;
332
331
}
333
332
case RT_BridgeRelease: {
334
333
auto *CI = cast<CallInst>(&Inst);
335
- auto *ArgVal = RC-> getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
334
+ auto *ArgVal = RC. getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
336
335
337
336
LocalState &LocalEntry = PtrToLocalStateMap[ArgVal];
338
337
LocalEntry.BridgeReleaseList .push_back (CI);
@@ -382,15 +381,12 @@ bool SwiftARCContractImpl::run() {
382
381
}
383
382
384
383
bool SwiftARCContract::runOnFunction (Function &F) {
385
- RC = &getAnalysis<SwiftRCIdentity>();
386
- return SwiftARCContractImpl (F, RC).run ();
384
+ return SwiftARCContractImpl (F).run ();
387
385
}
388
386
389
387
char SwiftARCContract::ID = 0 ;
390
- INITIALIZE_PASS_BEGIN (SwiftARCContract,
391
- " swift-arc-contract" , " Swift ARC contraction" ,
392
- false , false )
393
- INITIALIZE_PASS_DEPENDENCY(SwiftRCIdentity)
388
+ INITIALIZE_PASS_BEGIN (SwiftARCContract, " swift-arc-contract" ,
389
+ " Swift ARC contraction" , false , false )
394
390
INITIALIZE_PASS_END(SwiftARCContract,
395
391
" swift-arc-contract" , " Swift ARC contraction" ,
396
392
false , false )
@@ -401,6 +397,17 @@ llvm::FunctionPass *swift::createSwiftARCContractPass() {
401
397
}
402
398
403
399
void SwiftARCContract::getAnalysisUsage (llvm::AnalysisUsage &AU) const {
404
- AU.addRequired <SwiftRCIdentity>();
405
400
AU.setPreservesCFG ();
406
401
}
402
+
403
+ llvm::PreservedAnalyses
404
+ SwiftARCContractPass::run (llvm::Function &F,
405
+ llvm::FunctionAnalysisManager &AM) {
406
+ bool changed = SwiftARCContractImpl (F).run ();
407
+ if (!changed)
408
+ return PreservedAnalyses::all ();
409
+
410
+ PreservedAnalyses PA;
411
+ PA.preserveSet <CFGAnalyses>();
412
+ return PA;
413
+ }
0 commit comments