From d7c459070cf3382f30abaf0b258223f7c254a06c Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 19 Feb 2023 21:39:47 -0800 Subject: [PATCH] [LoopIdiomRecognize] Remove legacy pass Following recent changes to remove non-core legacy passes. --- .../scalar_opts/llvm_scalar_opts.ml | 3 - .../scalar_opts/llvm_scalar_opts.mli | 5 -- .../scalar_opts/scalar_opts_ocaml.c | 6 -- llvm/include/llvm-c/Transforms/Scalar.h | 3 - llvm/include/llvm/InitializePasses.h | 1 - llvm/include/llvm/LinkAllPasses.h | 1 - llvm/include/llvm/Transforms/Scalar.h | 6 -- .../lib/Transforms/IPO/PassManagerBuilder.cpp | 1 - .../Transforms/Scalar/LoopIdiomRecognize.cpp | 64 ------------------- llvm/lib/Transforms/Scalar/Scalar.cpp | 5 -- llvm/test/Bindings/OCaml/scalar_opts.ml | 1 - polly/lib/CodeGen/CodegenCleanup.cpp | 1 - 12 files changed, 97 deletions(-) diff --git a/llvm/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.ml b/llvm/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.ml index 30f4f8f6bf24..cf212b90f717 100644 --- a/llvm/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.ml +++ b/llvm/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.ml @@ -42,9 +42,6 @@ external add_jump_threading external add_licm : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit = "llvm_add_licm" -external add_loop_idiom - : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit - = "llvm_add_loop_idiom" external add_loop_rotation : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit = "llvm_add_loop_rotate" diff --git a/llvm/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.mli b/llvm/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.mli index 7ac557d204c1..57069c19133f 100644 --- a/llvm/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.mli +++ b/llvm/bindings/ocaml/transforms/scalar_opts/llvm_scalar_opts.mli @@ -71,11 +71,6 @@ external add_licm : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit = "llvm_add_licm" -(** See the [llvm::createLoopIdiomPass] function. *) -external add_loop_idiom - : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit - = "llvm_add_loop_idiom" - (** See the [llvm::createLoopRotatePass] function. *) external add_loop_rotation : [< Llvm.PassManager.any ] Llvm.PassManager.t -> unit diff --git a/llvm/bindings/ocaml/transforms/scalar_opts/scalar_opts_ocaml.c b/llvm/bindings/ocaml/transforms/scalar_opts/scalar_opts_ocaml.c index 12e0f88eae05..304e87a3f2f6 100644 --- a/llvm/bindings/ocaml/transforms/scalar_opts/scalar_opts_ocaml.c +++ b/llvm/bindings/ocaml/transforms/scalar_opts/scalar_opts_ocaml.c @@ -91,12 +91,6 @@ value llvm_add_licm(LLVMPassManagerRef PM) { return Val_unit; } -/* [ unit */ -value llvm_add_loop_idiom(LLVMPassManagerRef PM) { - LLVMAddLoopIdiomPass(PM); - return Val_unit; -} - /* [ unit */ value llvm_add_loop_rotate(LLVMPassManagerRef PM) { LLVMAddLoopRotatePass(PM); diff --git a/llvm/include/llvm-c/Transforms/Scalar.h b/llvm/include/llvm-c/Transforms/Scalar.h index 5aaeb9470168..020af80763d4 100644 --- a/llvm/include/llvm-c/Transforms/Scalar.h +++ b/llvm/include/llvm-c/Transforms/Scalar.h @@ -76,9 +76,6 @@ void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM); /** See llvm::createLICMPass function. */ void LLVMAddLICMPass(LLVMPassManagerRef PM); -/** See llvm::createLoopIdiomPass function */ -void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM); - /** See llvm::createLoopRotatePass function. */ void LLVMAddLoopRotatePass(LLVMPassManagerRef PM); diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index 01df2e063e7f..2924b02774bd 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -209,7 +209,6 @@ void initializeLoopAccessLegacyAnalysisPass(PassRegistry&); void initializeLoopDataPrefetchLegacyPassPass(PassRegistry&); void initializeLoopExtractorLegacyPassPass(PassRegistry &); void initializeLoopGuardWideningLegacyPassPass(PassRegistry&); -void initializeLoopIdiomRecognizeLegacyPassPass(PassRegistry&); void initializeLoopInfoWrapperPassPass(PassRegistry&); void initializeLoopInstSimplifyLegacyPassPass(PassRegistry&); void initializeLoopPassPass(PassRegistry&); diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h index 8d1d1883972a..66810828c0db 100644 --- a/llvm/include/llvm/LinkAllPasses.h +++ b/llvm/include/llvm/LinkAllPasses.h @@ -113,7 +113,6 @@ namespace { (void) llvm::createLoopSimplifyCFGPass(); (void) llvm::createLoopStrengthReducePass(); (void) llvm::createLoopUnrollPass(); - (void) llvm::createLoopIdiomPass(); (void) llvm::createLoopRotatePass(); (void) llvm::createLowerConstantIntrinsicsPass(); (void) llvm::createLowerExpectIntrinsicPass(); diff --git a/llvm/include/llvm/Transforms/Scalar.h b/llvm/include/llvm/Transforms/Scalar.h index 2dea75291d4c..8770eecceb7f 100644 --- a/llvm/include/llvm/Transforms/Scalar.h +++ b/llvm/include/llvm/Transforms/Scalar.h @@ -176,12 +176,6 @@ Pass *createSimpleLoopUnrollPass(int OptLevel = 2, bool OnlyWhenForced = false, // Pass *createLoopRotatePass(int MaxHeaderSize = -1, bool PrepareForLTO = false); -//===----------------------------------------------------------------------===// -// -// LoopIdiom - This pass recognizes and replaces idioms in loops. -// -Pass *createLoopIdiomPass(); - //===----------------------------------------------------------------------===// // // DemoteRegisterToMemoryPass - This pass is used to demote registers to memory diff --git a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp index 841e60807901..6312217840c1 100644 --- a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp +++ b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -152,7 +152,6 @@ void PassManagerBuilder::addFunctionSimplificationPasses( SimplifyCFGOptions().convertSwitchRangeToICmp(true))); MPM.add(createInstructionCombiningPass()); // We resume loop passes creating a second loop pipeline here. - MPM.add(createLoopIdiomPass()); // Recognize idioms like memset. MPM.add(createIndVarSimplifyPass()); // Canonicalize indvars // Unroll small loops and perform peeling. diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index 035cbdf595a8..6922ba3d7002 100644 --- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -254,62 +254,8 @@ private: /// @} }; - -class LoopIdiomRecognizeLegacyPass : public LoopPass { -public: - static char ID; - - explicit LoopIdiomRecognizeLegacyPass() : LoopPass(ID) { - initializeLoopIdiomRecognizeLegacyPassPass( - *PassRegistry::getPassRegistry()); - } - - bool runOnLoop(Loop *L, LPPassManager &LPM) override { - if (DisableLIRP::All) - return false; - - if (skipLoop(L)) - return false; - - AliasAnalysis *AA = &getAnalysis().getAAResults(); - DominatorTree *DT = &getAnalysis().getDomTree(); - LoopInfo *LI = &getAnalysis().getLoopInfo(); - ScalarEvolution *SE = &getAnalysis().getSE(); - TargetLibraryInfo *TLI = - &getAnalysis().getTLI( - *L->getHeader()->getParent()); - const TargetTransformInfo *TTI = - &getAnalysis().getTTI( - *L->getHeader()->getParent()); - const DataLayout *DL = &L->getHeader()->getModule()->getDataLayout(); - auto *MSSAAnalysis = getAnalysisIfAvailable(); - MemorySSA *MSSA = nullptr; - if (MSSAAnalysis) - MSSA = &MSSAAnalysis->getMSSA(); - - // For the old PM, we can't use OptimizationRemarkEmitter as an analysis - // pass. Function analyses need to be preserved across loop transformations - // but ORE cannot be preserved (see comment before the pass definition). - OptimizationRemarkEmitter ORE(L->getHeader()->getParent()); - - LoopIdiomRecognize LIR(AA, DT, LI, SE, TLI, TTI, MSSA, DL, ORE); - return LIR.runOnLoop(L); - } - - /// This transformation requires natural loop information & requires that - /// loop preheaders be inserted into the CFG. - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.addRequired(); - AU.addRequired(); - AU.addPreserved(); - getLoopAnalysisUsage(AU); - } -}; - } // end anonymous namespace -char LoopIdiomRecognizeLegacyPass::ID = 0; - PreservedAnalyses LoopIdiomRecognizePass::run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &) { @@ -334,16 +280,6 @@ PreservedAnalyses LoopIdiomRecognizePass::run(Loop &L, LoopAnalysisManager &AM, return PA; } -INITIALIZE_PASS_BEGIN(LoopIdiomRecognizeLegacyPass, "loop-idiom", - "Recognize loop idioms", false, false) -INITIALIZE_PASS_DEPENDENCY(LoopPass) -INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) -INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass) -INITIALIZE_PASS_END(LoopIdiomRecognizeLegacyPass, "loop-idiom", - "Recognize loop idioms", false, false) - -Pass *llvm::createLoopIdiomPass() { return new LoopIdiomRecognizeLegacyPass(); } - static void deleteDeadInstruction(Instruction *I) { I->replaceAllUsesWith(PoisonValue::get(I->getType())); I->eraseFromParent(); diff --git a/llvm/lib/Transforms/Scalar/Scalar.cpp b/llvm/lib/Transforms/Scalar/Scalar.cpp index e07471f75dae..38c2bffc66d0 100644 --- a/llvm/lib/Transforms/Scalar/Scalar.cpp +++ b/llvm/lib/Transforms/Scalar/Scalar.cpp @@ -65,7 +65,6 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) { initializeLoopRotateLegacyPassPass(Registry); initializeLoopStrengthReducePass(Registry); initializeLoopUnrollPass(Registry); - initializeLoopIdiomRecognizeLegacyPassPass(Registry); initializeLowerAtomicLegacyPassPass(Registry); initializeLowerConstantIntrinsicsPass(Registry); initializeLowerExpectIntrinsicPass(Registry); @@ -168,10 +167,6 @@ void LLVMAddLICMPass(LLVMPassManagerRef PM) { unwrap(PM)->add(createLICMPass()); } -void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM) { - unwrap(PM)->add(createLoopIdiomPass()); -} - void LLVMAddLoopRotatePass(LLVMPassManagerRef PM) { unwrap(PM)->add(createLoopRotatePass()); } diff --git a/llvm/test/Bindings/OCaml/scalar_opts.ml b/llvm/test/Bindings/OCaml/scalar_opts.ml index d63d63b9f056..861e38c4bf01 100644 --- a/llvm/test/Bindings/OCaml/scalar_opts.ml +++ b/llvm/test/Bindings/OCaml/scalar_opts.ml @@ -53,7 +53,6 @@ let test_transforms () = ++ add_instruction_combination ++ add_jump_threading ++ add_licm - ++ add_loop_idiom ++ add_loop_rotation ++ add_loop_unroll ++ add_memcpy_opt diff --git a/polly/lib/CodeGen/CodegenCleanup.cpp b/polly/lib/CodeGen/CodegenCleanup.cpp index 0f66d757c67b..e57475079788 100644 --- a/polly/lib/CodeGen/CodegenCleanup.cpp +++ b/polly/lib/CodeGen/CodegenCleanup.cpp @@ -84,7 +84,6 @@ public: FPM->add(createCFGSimplificationPass()); FPM->add(createInstructionCombiningPass(true)); FPM->add(createIndVarSimplifyPass()); - FPM->add(createLoopIdiomPass()); FPM->add(createCFGSimplificationPass()); FPM->add(createSimpleLoopUnrollPass(3)); FPM->add(createMergedLoadStoreMotionPass());