1 //===---- Canonicalization.cpp - Run canonicalization passes --------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Run the set of default canonicalization passes. 10 // 11 // This pass is mainly used for debugging. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include "polly/Canonicalization.h" 16 #include "polly/LinkAllPasses.h" 17 #include "polly/Options.h" 18 #include "llvm/IR/LegacyPassManager.h" 19 #include "llvm/Transforms/IPO.h" 20 #include "llvm/Transforms/InstCombine/InstCombine.h" 21 #include "llvm/Transforms/Scalar.h" 22 #include "llvm/Transforms/Utils.h" 23 24 using namespace llvm; 25 using namespace polly; 26 27 static cl::opt<bool> 28 PollyInliner("polly-run-inliner", 29 cl::desc("Run an early inliner pass before Polly"), cl::Hidden, 30 cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory)); 31 32 void polly::registerCanonicalicationPasses(llvm::legacy::PassManagerBase &PM) { 33 bool UseMemSSA = true; 34 PM.add(polly::createRewriteByrefParamsPass()); 35 PM.add(llvm::createPromoteMemoryToRegisterPass()); 36 PM.add(llvm::createEarlyCSEPass(UseMemSSA)); 37 PM.add(llvm::createInstructionCombiningPass()); 38 PM.add(llvm::createCFGSimplificationPass()); 39 PM.add(llvm::createTailCallEliminationPass()); 40 PM.add(llvm::createCFGSimplificationPass()); 41 PM.add(llvm::createReassociatePass()); 42 PM.add(llvm::createLoopRotatePass()); 43 if (PollyInliner) { 44 PM.add(llvm::createFunctionInliningPass(200)); 45 PM.add(llvm::createPromoteMemoryToRegisterPass()); 46 PM.add(llvm::createCFGSimplificationPass()); 47 PM.add(llvm::createInstructionCombiningPass()); 48 PM.add(createBarrierNoopPass()); 49 } 50 PM.add(llvm::createInstructionCombiningPass()); 51 PM.add(llvm::createIndVarSimplifyPass()); 52 PM.add(polly::createCodePreparationPass()); 53 } 54 55 namespace { 56 class PollyCanonicalize : public ModulePass { 57 PollyCanonicalize(const PollyCanonicalize &) = delete; 58 const PollyCanonicalize &operator=(const PollyCanonicalize &) = delete; 59 60 public: 61 static char ID; 62 63 explicit PollyCanonicalize() : ModulePass(ID) {} 64 ~PollyCanonicalize(); 65 66 /// @name FunctionPass interface. 67 //@{ 68 void getAnalysisUsage(AnalysisUsage &AU) const override; 69 void releaseMemory() override; 70 bool runOnModule(Module &M) override; 71 void print(raw_ostream &OS, const Module *) const override; 72 //@} 73 }; 74 } // namespace 75 76 PollyCanonicalize::~PollyCanonicalize() {} 77 78 void PollyCanonicalize::getAnalysisUsage(AnalysisUsage &AU) const {} 79 80 void PollyCanonicalize::releaseMemory() {} 81 82 bool PollyCanonicalize::runOnModule(Module &M) { 83 legacy::PassManager PM; 84 registerCanonicalicationPasses(PM); 85 PM.run(M); 86 87 return true; 88 } 89 90 void PollyCanonicalize::print(raw_ostream &OS, const Module *) const {} 91 92 char PollyCanonicalize::ID = 0; 93 94 Pass *polly::createPollyCanonicalizePass() { return new PollyCanonicalize(); } 95 96 INITIALIZE_PASS_BEGIN(PollyCanonicalize, "polly-canonicalize", 97 "Polly - Run canonicalization passes", false, false) 98 INITIALIZE_PASS_END(PollyCanonicalize, "polly-canonicalize", 99 "Polly - Run canonicalization passes", false, false) 100