@@ -64,16 +64,15 @@ class SwiftARCContractImpl {
6464 bool Changed;
6565
6666 // / Swift RC Identity.
67- SwiftRCIdentity * RC;
67+ SwiftRCIdentity RC;
6868
6969 // / The function that we are processing.
7070 Function &F;
7171
7272 // / The entry point builder that is used to construct ARC entry points.
7373 ARCEntryPointBuilder B;
7474public:
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) {}
7776
7877 // The top level run routine of the pass.
7978 bool run ();
@@ -109,7 +108,7 @@ performRRNOptimization(DenseMap<Value *, LocalState> &PtrToLocalStateMap) {
109108 break ;
110109 }
111110 }
112- B.createRetainN (RC-> getSwiftRCIdentityRoot (O), RetainList.size (), RI);
111+ B.createRetainN (RC. getSwiftRCIdentityRoot (O), RetainList.size (), RI);
113112
114113 // Replace all uses of the retain instructions with our new retainN and
115114 // then delete them.
@@ -135,7 +134,7 @@ performRRNOptimization(DenseMap<Value *, LocalState> &PtrToLocalStateMap) {
135134 break ;
136135 }
137136 }
138- B.createReleaseN (RC-> getSwiftRCIdentityRoot (O), ReleaseList.size (), RI);
137+ B.createReleaseN (RC. getSwiftRCIdentityRoot (O), ReleaseList.size (), RI);
139138
140139 // Remove all old release instructions.
141140 for (auto *Inst : ReleaseList) {
@@ -159,7 +158,7 @@ performRRNOptimization(DenseMap<Value *, LocalState> &PtrToLocalStateMap) {
159158 break ;
160159 }
161160 }
162- B.createUnknownObjectRetainN (RC-> getSwiftRCIdentityRoot (O),
161+ B.createUnknownObjectRetainN (RC. getSwiftRCIdentityRoot (O),
163162 UnknownObjectRetainList.size (), RI);
164163
165164 // Replace all uses of the retain instructions with our new retainN and
@@ -187,7 +186,7 @@ performRRNOptimization(DenseMap<Value *, LocalState> &PtrToLocalStateMap) {
187186 break ;
188187 }
189188 }
190- B.createUnknownObjectReleaseN (RC-> getSwiftRCIdentityRoot (O),
189+ B.createUnknownObjectReleaseN (RC. getSwiftRCIdentityRoot (O),
191190 UnknownObjectReleaseList.size (), RI);
192191
193192 // Remove all old release instructions.
@@ -214,7 +213,7 @@ performRRNOptimization(DenseMap<Value *, LocalState> &PtrToLocalStateMap) {
214213 }
215214 }
216215 // 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),
218217 BridgeRetainList.size (), RI);
219218
220219 // Remove all old retain instructions.
@@ -246,8 +245,8 @@ performRRNOptimization(DenseMap<Value *, LocalState> &PtrToLocalStateMap) {
246245 break ;
247246 }
248247 }
249- B.createBridgeReleaseN (RC-> getSwiftRCIdentityRoot (O),
250- BridgeReleaseList.size (), RI);
248+ B.createBridgeReleaseN (RC. getSwiftRCIdentityRoot (O),
249+ BridgeReleaseList.size (), RI);
251250
252251 // Remove all old release instructions.
253252 for (auto *Inst : BridgeReleaseList) {
@@ -290,15 +289,15 @@ bool SwiftARCContractImpl::run() {
290289 continue ;
291290 case RT_Retain: {
292291 auto *CI = cast<CallInst>(&Inst);
293- auto *ArgVal = RC-> getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
292+ auto *ArgVal = RC. getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
294293
295294 LocalState &LocalEntry = PtrToLocalStateMap[ArgVal];
296295 LocalEntry.RetainList .push_back (CI);
297296 continue ;
298297 }
299298 case RT_UnknownObjectRetain: {
300299 auto *CI = cast<CallInst>(&Inst);
301- auto *ArgVal = RC-> getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
300+ auto *ArgVal = RC. getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
302301
303302 LocalState &LocalEntry = PtrToLocalStateMap[ArgVal];
304303 LocalEntry.UnknownObjectRetainList .push_back (CI);
@@ -307,7 +306,7 @@ bool SwiftARCContractImpl::run() {
307306 case RT_Release: {
308307 // Stash any releases that we see.
309308 auto *CI = cast<CallInst>(&Inst);
310- auto *ArgVal = RC-> getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
309+ auto *ArgVal = RC. getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
311310
312311 LocalState &LocalEntry = PtrToLocalStateMap[ArgVal];
313312 LocalEntry.ReleaseList .push_back (CI);
@@ -316,23 +315,23 @@ bool SwiftARCContractImpl::run() {
316315 case RT_UnknownObjectRelease: {
317316 // Stash any releases that we see.
318317 auto *CI = cast<CallInst>(&Inst);
319- auto *ArgVal = RC-> getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
318+ auto *ArgVal = RC. getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
320319
321320 LocalState &LocalEntry = PtrToLocalStateMap[ArgVal];
322321 LocalEntry.UnknownObjectReleaseList .push_back (CI);
323322 continue ;
324323 }
325324 case RT_BridgeRetain: {
326325 auto *CI = cast<CallInst>(&Inst);
327- auto *ArgVal = RC-> getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
326+ auto *ArgVal = RC. getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
328327
329328 LocalState &LocalEntry = PtrToLocalStateMap[ArgVal];
330329 LocalEntry.BridgeRetainList .push_back (CI);
331330 continue ;
332331 }
333332 case RT_BridgeRelease: {
334333 auto *CI = cast<CallInst>(&Inst);
335- auto *ArgVal = RC-> getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
334+ auto *ArgVal = RC. getSwiftRCIdentityRoot (CI->getArgOperand (0 ));
336335
337336 LocalState &LocalEntry = PtrToLocalStateMap[ArgVal];
338337 LocalEntry.BridgeReleaseList .push_back (CI);
@@ -382,15 +381,12 @@ bool SwiftARCContractImpl::run() {
382381}
383382
384383bool SwiftARCContract::runOnFunction (Function &F) {
385- RC = &getAnalysis<SwiftRCIdentity>();
386- return SwiftARCContractImpl (F, RC).run ();
384+ return SwiftARCContractImpl (F).run ();
387385}
388386
389387char 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 )
394390INITIALIZE_PASS_END(SwiftARCContract,
395391 " swift-arc-contract" , " Swift ARC contraction" ,
396392 false , false )
@@ -401,6 +397,17 @@ llvm::FunctionPass *swift::createSwiftARCContractPass() {
401397}
402398
403399void SwiftARCContract::getAnalysisUsage (llvm::AnalysisUsage &AU) const {
404- AU.addRequired <SwiftRCIdentity>();
405400 AU.setPreservesCFG ();
406401}
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