[llvm-branch-commits] [clang] 756dd70 - [NewPM] Run ObjC ARC passes
Arthur Eubanks via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Jan 8 15:51:25 PST 2021
Author: Arthur Eubanks
Date: 2021-01-08T15:47:11-08:00
New Revision: 756dd707668ccc1ac22b88d5899984843a5a3262
URL: https://github.com/llvm/llvm-project/commit/756dd707668ccc1ac22b88d5899984843a5a3262
DIFF: https://github.com/llvm/llvm-project/commit/756dd707668ccc1ac22b88d5899984843a5a3262.diff
LOG: [NewPM] Run ObjC ARC passes
Match the legacy PM in running various ObjC ARC passes.
This requires making some module passes into function passes. These were
initially ported as module passes since they add function declarations
(e.g. https://reviews.llvm.org/D86178), but that's still up for debate
and other passes do so.
Reviewed By: ahatanak
Differential Revision: https://reviews.llvm.org/D93743
Added:
Modified:
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/Transforms/ObjCARC.h
llvm/lib/Passes/PassRegistry.def
llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 90cf5fc5df9a..2257be8d2887 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1199,6 +1199,25 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
bool IsThinLTO = CodeGenOpts.PrepareForThinLTO;
bool IsLTO = CodeGenOpts.PrepareForLTO;
+ if (LangOpts.ObjCAutoRefCount) {
+ PB.registerPipelineStartEPCallback(
+ [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
+ if (Level != PassBuilder::OptimizationLevel::O0)
+ MPM.addPass(
+ createModuleToFunctionPassAdaptor(ObjCARCExpandPass()));
+ });
+ PB.registerPipelineEarlySimplificationEPCallback(
+ [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
+ if (Level != PassBuilder::OptimizationLevel::O0)
+ MPM.addPass(ObjCARCAPElimPass());
+ });
+ PB.registerScalarOptimizerLateEPCallback(
+ [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
+ if (Level != PassBuilder::OptimizationLevel::O0)
+ FPM.addPass(ObjCARCOptPass());
+ });
+ }
+
// If we reached here with a non-empty index file name, then the index
// file was empty and we are not performing ThinLTO backend compilation
// (used in testing in a distributed build environment). Drop any the type
diff --git a/llvm/include/llvm/Transforms/ObjCARC.h b/llvm/include/llvm/Transforms/ObjCARC.h
index 18df98937461..a89df95385c8 100644
--- a/llvm/include/llvm/Transforms/ObjCARC.h
+++ b/llvm/include/llvm/Transforms/ObjCARC.h
@@ -45,11 +45,11 @@ Pass *createObjCARCContractPass();
Pass *createObjCARCOptPass();
struct ObjCARCOptPass : public PassInfoMixin<ObjCARCOptPass> {
- PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};
struct ObjCARCContractPass : public PassInfoMixin<ObjCARCContractPass> {
- PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+ PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
};
struct ObjCARCAPElimPass : public PassInfoMixin<ObjCARCAPElimPass> {
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 3db0cfffb059..1937d5af78a3 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -80,9 +80,7 @@ MODULE_PASS("metarenamer", MetaRenamerPass())
MODULE_PASS("mergefunc", MergeFunctionsPass())
MODULE_PASS("name-anon-globals", NameAnonGlobalPass())
MODULE_PASS("no-op-module", NoOpModulePass())
-MODULE_PASS("objc-arc", ObjCARCOptPass())
MODULE_PASS("objc-arc-apelim", ObjCARCAPElimPass())
-MODULE_PASS("objc-arc-contract", ObjCARCContractPass())
MODULE_PASS("partial-inliner", PartialInlinerPass())
MODULE_PASS("pgo-icall-prom", PGOIndirectCallPromotion())
MODULE_PASS("pgo-instr-gen", PGOInstrumentationGen())
@@ -268,6 +266,8 @@ 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", ObjCARCOptPass())
+FUNCTION_PASS("objc-arc-contract", ObjCARCContractPass())
FUNCTION_PASS("objc-arc-expand", ObjCARCExpandPass())
FUNCTION_PASS("pgo-memop-opt", PGOMemOPSizeOpt())
FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
index c2499fc85cf5..86d161116e8c 100644
--- a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
@@ -750,19 +750,13 @@ bool ObjCARCContractLegacyPass::runOnFunction(Function &F) {
return OCARCC.run(F, AA, DT);
}
-PreservedAnalyses ObjCARCContractPass::run(Module &M,
- ModuleAnalysisManager &AM) {
+PreservedAnalyses ObjCARCContractPass::run(Function &F,
+ FunctionAnalysisManager &AM) {
ObjCARCContract OCAC;
- OCAC.init(M);
+ OCAC.init(*F.getParent());
- auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
- bool Changed = false;
- for (Function &F : M) {
- if (F.isDeclaration())
- continue;
- Changed |= OCAC.run(F, &FAM.getResult<AAManager>(F),
- &FAM.getResult<DominatorTreeAnalysis>(F));
- }
+ bool Changed = OCAC.run(F, &AM.getResult<AAManager>(F),
+ &AM.getResult<DominatorTreeAnalysis>(F));
if (Changed) {
PreservedAnalyses PA;
PA.preserveSet<CFGAnalyses>();
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
index 443ff5b817f7..1c447499519c 100644
--- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
@@ -2462,17 +2462,12 @@ void ObjCARCOpt::releaseMemory() {
/// @}
///
-PreservedAnalyses ObjCARCOptPass::run(Module &M, ModuleAnalysisManager &AM) {
+PreservedAnalyses ObjCARCOptPass::run(Function &F,
+ FunctionAnalysisManager &AM) {
ObjCARCOpt OCAO;
- OCAO.init(M);
+ OCAO.init(*F.getParent());
- auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
- bool Changed = false;
- for (Function &F : M) {
- if (F.isDeclaration())
- continue;
- Changed |= OCAO.run(F, FAM.getResult<AAManager>(F));
- }
+ bool Changed = OCAO.run(F, AM.getResult<AAManager>(F));
if (Changed) {
PreservedAnalyses PA;
PA.preserveSet<CFGAnalyses>();
More information about the llvm-branch-commits
mailing list