19#include "llvm/Analysis/CallGraph.h"
20#include "llvm/Analysis/CallGraphSCCPass.h"
21#include "llvm/Analysis/OptimizationRemarkEmitter.h"
22#include "llvm/Analysis/RegionInfo.h"
23#include "llvm/IR/Dominators.h"
24#include "llvm/Passes/PassBuilder.h"
25#include "llvm/Transforms/IPO/AlwaysInliner.h"
28#define DEBUG_TYPE "polly-scop-inliner"
37template <
typename SCC_t>
bool runScopInlinerImpl(Function *F, SCC_t &SCC) {
42 assert(SCC.size() == 1 &&
"found empty SCC");
47 if (F->isDeclaration()) {
49 <<
"because it is a declaration.\n");
55 LoopAnalysisManager LAM;
56 FunctionAnalysisManager FAM;
57 CGSCCAnalysisManager CGAM;
58 ModuleAnalysisManager MAM;
59 PB.registerModuleAnalyses(MAM);
60 PB.registerCGSCCAnalyses(CGAM);
61 PB.registerFunctionAnalyses(FAM);
62 PB.registerLoopAnalyses(LAM);
63 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
65 auto &DT = FAM.getResult<DominatorTreeAnalysis>(*F);
66 auto &SE = FAM.getResult<ScalarEvolutionAnalysis>(*F);
67 auto &LI = FAM.getResult<LoopAnalysis>(*F);
68 auto &RI = FAM.getResult<RegionInfoAnalysis>(*F);
69 auto &AA = FAM.getResult<AAManager>(*F);
70 auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(*F);
74 const bool HasScopAsTopLevelRegion =
78 if (HasScopAsTopLevelRegion) {
80 <<
" has scop as top level region");
81 F->addFnAttr(llvm::Attribute::AlwaysInline);
83 ModulePassManager MPM;
84 MPM.addPass(AlwaysInlinerPass());
85 Module *M = F->getParent();
86 assert(M &&
"Function has illegal module");
87 PreservedAnalyses PA = MPM.run(*M, MAM);
88 if (!PA.areAllPreserved())
92 <<
" does NOT have scop as top level region\n");
102 "Aborting from ScopInliner because it only makes sense to run with "
103 "-polly-allow-full-function. "
104 "The heurtistic for ScopInliner checks that the full function is a "
105 "Scop, which happens if and only if polly-allow-full-function is "
107 " If not, the entry block is not included in the Scop");
112 llvm::CGSCCAnalysisManager &AM,
113 llvm::LazyCallGraph &CG,
114 llvm::CGSCCUpdateResult &UR) {
115 Function *F = &SCC.begin()->getFunction();
116 bool Changed = runScopInlinerImpl(F, SCC);
117 return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
Pass to detect the maximal static control parts (Scops) of a function.
llvm::PreservedAnalyses run(llvm::LazyCallGraph::SCC &C, llvm::CGSCCAnalysisManager &AM, llvm::LazyCallGraph &CG, llvm::CGSCCUpdateResult &UR)
bool PollyAllowFullFunction