From 3dd1c724581ab7aab8bae7bb6e0566c52b1f9a9d Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Mon, 26 Oct 2020 11:59:23 -0700 Subject: [PATCH] Port -objc-arc-expand to NPM Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D90182 --- llvm/include/llvm/Transforms/ObjCARC.h | 4 ++ llvm/lib/Passes/PassRegistry.def | 1 + llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp | 78 +++++++++++++-------------- llvm/test/Transforms/ObjCARC/expand.ll | 1 + 4 files changed, 44 insertions(+), 40 deletions(-) diff --git a/llvm/include/llvm/Transforms/ObjCARC.h b/llvm/include/llvm/Transforms/ObjCARC.h index f033a7b..18df989 100644 --- a/llvm/include/llvm/Transforms/ObjCARC.h +++ b/llvm/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/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index 01a04da..538913c 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/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/llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp index f8d872a..d2121dc 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp +++ b/llvm/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/llvm/test/Transforms/ObjCARC/expand.ll b/llvm/test/Transforms/ObjCARC/expand.ll index b89c5d5..07b412f 100644 --- a/llvm/test/Transforms/ObjCARC/expand.ll +++ b/llvm/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" -- 2.7.4