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
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
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> {
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())
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()))
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>();
/// @}
///
-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>();