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>
38bool runScopInlinerImpl(Function *F, SCC_t &SCC,
39 IntrusiveRefCntPtr<vfs::FileSystem> FS) {
44 assert(SCC.size() == 1 &&
"found empty SCC");
49 if (F->isDeclaration()) {
51 <<
"because it is a declaration.\n");
59 nullptr, std::move(FS));
61 LoopAnalysisManager LAM;
62 FunctionAnalysisManager FAM;
63 CGSCCAnalysisManager CGAM;
64 ModuleAnalysisManager MAM;
65 PB.registerModuleAnalyses(MAM);
66 PB.registerCGSCCAnalyses(CGAM);
67 PB.registerFunctionAnalyses(FAM);
68 PB.registerLoopAnalyses(LAM);
69 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
71 auto &DT = FAM.getResult<DominatorTreeAnalysis>(*F);
72 auto &SE = FAM.getResult<ScalarEvolutionAnalysis>(*F);
73 auto &LI = FAM.getResult<LoopAnalysis>(*F);
74 auto &RI = FAM.getResult<RegionInfoAnalysis>(*F);
75 auto &AA = FAM.getResult<AAManager>(*F);
76 auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(*F);
80 const bool HasScopAsTopLevelRegion =
84 if (HasScopAsTopLevelRegion) {
86 <<
" has scop as top level region");
87 F->addFnAttr(llvm::Attribute::AlwaysInline);
89 ModulePassManager MPM;
90 MPM.addPass(AlwaysInlinerPass());
91 Module *M = F->getParent();
92 assert(M &&
"Function has illegal module");
93 PreservedAnalyses PA = MPM.run(*M, MAM);
94 if (!PA.areAllPreserved())
98 <<
" does NOT have scop as top level region\n");
106 :
FS(std::move(
FS)) {
109 "Aborting from ScopInliner because it only makes sense to run with "
110 "-polly-allow-full-function. "
111 "The heurtistic for ScopInliner checks that the full function is a "
112 "Scop, which happens if and only if polly-allow-full-function is "
114 " If not, the entry block is not included in the Scop");
119 llvm::CGSCCAnalysisManager &AM,
120 llvm::LazyCallGraph &CG,
121 llvm::CGSCCUpdateResult &UR) {
122 Function *F = &SCC.begin()->getFunction();
123 bool Changed = runScopInlinerImpl(F, SCC,
FS);
124 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)
ScopInlinerPass(llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS)
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS
bool PollyAllowFullFunction