diff --git a/include/llvm/Transforms/ObjCARC.h b/include/llvm/Transforms/ObjCARC.h index f033a7b1642..18df9893746 100644 --- a/include/llvm/Transforms/ObjCARC.h +++ b/include/llvm/Transforms/ObjCARC.h @@ -56,6 +56,10 @@ struct ObjCARCAPElimPass : public PassInfoMixin { PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); }; +struct ObjCARCExpandPass : public PassInfoMixin { + PreservedAnalyses run(Function &M, FunctionAnalysisManager &AM); +}; + } // End llvm namespace #endif diff --git a/lib/Passes/PassRegistry.def b/lib/Passes/PassRegistry.def index 01a04da3a72..538913c001e 100644 --- a/lib/Passes/PassRegistry.def +++ b/lib/Passes/PassRegistry.def @@ -254,6 +254,7 @@ FUNCTION_PASS("loop-load-elim", LoopLoadEliminationPass()) FUNCTION_PASS("loop-fusion", LoopFusePass()) FUNCTION_PASS("loop-distribute", LoopDistributePass()) FUNCTION_PASS("loop-versioning", LoopVersioningPass()) +FUNCTION_PASS("objc-arc-expand", ObjCARCExpandPass()) FUNCTION_PASS("pgo-memop-opt", PGOMemOPSizeOpt()) FUNCTION_PASS("print", PrintFunctionPass(dbgs())) FUNCTION_PASS("print", AssumptionPrinterPass(dbgs())) diff --git a/lib/Transforms/ObjCARC/ObjCARCExpand.cpp b/lib/Transforms/ObjCARC/ObjCARCExpand.cpp index f8d872a7c99..d2121dcebe9 100644 --- a/lib/Transforms/ObjCARC/ObjCARCExpand.cpp +++ b/lib/Transforms/ObjCARC/ObjCARCExpand.cpp @@ -27,6 +27,7 @@ #include "llvm/IR/InstIterator.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" +#include "llvm/IR/PassManager.h" #include "llvm/IR/Value.h" #include "llvm/InitializePasses.h" #include "llvm/Pass.h" @@ -34,57 +35,20 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Transforms/ObjCARC.h" #define DEBUG_TYPE "objc-arc-expand" -namespace llvm { - class Module; -} - using namespace llvm; using namespace llvm::objcarc; namespace { - /// Early ARC transformations. - class ObjCARCExpand : public FunctionPass { - void getAnalysisUsage(AnalysisUsage &AU) const override; - bool doInitialization(Module &M) override; - bool runOnFunction(Function &F) override; - - /// A flag indicating whether this optimization pass should run. - bool Run; - - public: - static char ID; - ObjCARCExpand() : FunctionPass(ID) { - initializeObjCARCExpandPass(*PassRegistry::getPassRegistry()); - } - }; -} - -char ObjCARCExpand::ID = 0; -INITIALIZE_PASS(ObjCARCExpand, - "objc-arc-expand", "ObjC ARC expansion", false, false) - -Pass *llvm::createObjCARCExpandPass() { - return new ObjCARCExpand(); -} - -void ObjCARCExpand::getAnalysisUsage(AnalysisUsage &AU) const { - AU.setPreservesCFG(); -} - -bool ObjCARCExpand::doInitialization(Module &M) { - Run = ModuleHasARC(M); - return false; -} - -bool ObjCARCExpand::runOnFunction(Function &F) { +static bool runImpl(Function &F) { if (!EnableARCOpts) return false; // If nothing in the Module uses ARC, don't do anything. - if (!Run) + if (!ModuleHasARC(*F.getParent())) return false; bool Changed = false; @@ -126,3 +90,37 @@ bool ObjCARCExpand::runOnFunction(Function &F) { return Changed; } + +/// Early ARC transformations. +class ObjCARCExpand : public FunctionPass { + void getAnalysisUsage(AnalysisUsage &AU) const override; + bool runOnFunction(Function &F) override; + +public: + static char ID; + ObjCARCExpand() : FunctionPass(ID) { + initializeObjCARCExpandPass(*PassRegistry::getPassRegistry()); + } +}; +} // namespace + +char ObjCARCExpand::ID = 0; +INITIALIZE_PASS(ObjCARCExpand, "objc-arc-expand", "ObjC ARC expansion", false, + false) + +Pass *llvm::createObjCARCExpandPass() { return new ObjCARCExpand(); } + +void ObjCARCExpand::getAnalysisUsage(AnalysisUsage &AU) const { + AU.setPreservesCFG(); +} + +bool ObjCARCExpand::runOnFunction(Function &F) { return runImpl(F); } + +PreservedAnalyses ObjCARCExpandPass::run(Function &F, + FunctionAnalysisManager &AM) { + if (!runImpl(F)) + return PreservedAnalyses::all(); + PreservedAnalyses PA; + PA.preserveSet(); + return PA; +} diff --git a/test/Transforms/ObjCARC/expand.ll b/test/Transforms/ObjCARC/expand.ll index b89c5d524e1..07b412fa37b 100644 --- a/test/Transforms/ObjCARC/expand.ll +++ b/test/Transforms/ObjCARC/expand.ll @@ -1,4 +1,5 @@ ; RUN: opt -objc-arc-expand -S < %s | FileCheck %s +; RUN: opt -passes=objc-arc-expand -S < %s | FileCheck %s target datalayout = "e-p:64:64:64"