[llvm] 3dd1c72 - Port -objc-arc-expand to NPM
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 26 20:07:16 PDT 2020
Author: Arthur Eubanks
Date: 2020-10-26T20:05:10-07:00
New Revision: 3dd1c724581ab7aab8bae7bb6e0566c52b1f9a9d
URL: https://github.com/llvm/llvm-project/commit/3dd1c724581ab7aab8bae7bb6e0566c52b1f9a9d
DIFF: https://github.com/llvm/llvm-project/commit/3dd1c724581ab7aab8bae7bb6e0566c52b1f9a9d.diff
LOG: Port -objc-arc-expand to NPM
Reviewed By: asbirlea
Differential Revision: https://reviews.llvm.org/D90182
Added:
Modified:
llvm/include/llvm/Transforms/ObjCARC.h
llvm/lib/Passes/PassRegistry.def
llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp
llvm/test/Transforms/ObjCARC/expand.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/ObjCARC.h b/llvm/include/llvm/Transforms/ObjCARC.h
index f033a7b16420..18df98937461 100644
--- a/llvm/include/llvm/Transforms/ObjCARC.h
+++ b/llvm/include/llvm/Transforms/ObjCARC.h
@@ -56,6 +56,10 @@ struct ObjCARCAPElimPass : public PassInfoMixin<ObjCARCAPElimPass> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};
+struct ObjCARCExpandPass : public PassInfoMixin<ObjCARCExpandPass> {
+ 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 01a04da3a72a..538913c001e1 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<assumptions>", AssumptionPrinterPass(dbgs()))
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCExpand.cpp
index f8d872a7c995..d2121dcebe91 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<CFGAnalyses>();
+ return PA;
+}
diff --git a/llvm/test/Transforms/ObjCARC/expand.ll b/llvm/test/Transforms/ObjCARC/expand.ll
index b89c5d524e1f..07b412fa37be 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"
More information about the llvm-commits
mailing list