diff options
| author | Michael Kruse <llvm-project@meinersbur.de> | 2025-10-31 19:23:49 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-31 19:23:49 +0100 |
| commit | 8c87f3eb35d5f5c12321b516265c732a7e2c31d1 (patch) | |
| tree | 0d0f43285c2187fe1df5de1cc6fe4e786d51342f | |
| parent | f9d715ab047469323f7d709cc92873b543a75ec8 (diff) | |
| download | llvm-8c87f3eb35d5f5c12321b516265c732a7e2c31d1.zip llvm-8c87f3eb35d5f5c12321b516265c732a7e2c31d1.tar.gz llvm-8c87f3eb35d5f5c12321b516265c732a7e2c31d1.tar.bz2 | |
[Polly][CodePreparation] Extract common code of LPM and NPM (#140419)
Use a common function for the non-boilerplate code shared between LPM
and NPM as done by most other passes already. ScalarEvolution is not
actually used.
Patch extracted out of #125442 requested by
https://github.com/llvm/llvm-project/pull/125442#discussion_r2034416019
| -rw-r--r-- | polly/lib/Transform/CodePreparation.cpp | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/polly/lib/Transform/CodePreparation.cpp b/polly/lib/Transform/CodePreparation.cpp index 7c8579eb..d045fb6 100644 --- a/polly/lib/Transform/CodePreparation.cpp +++ b/polly/lib/Transform/CodePreparation.cpp @@ -27,6 +27,26 @@ using namespace llvm; using namespace polly; +static bool runCodePreprationImpl(Function &F, DominatorTree *DT, LoopInfo *LI, + RegionInfo *RI) { + // Find first non-alloca instruction. Every basic block has a non-alloca + // instruction, as every well formed basic block has a terminator. + auto &EntryBlock = F.getEntryBlock(); + BasicBlock::iterator I = EntryBlock.begin(); + while (isa<AllocaInst>(I)) + ++I; + + // Abort if not necessary to split + if (I->isTerminator() && isa<BranchInst>(I) && + cast<BranchInst>(I)->isUnconditional()) + return false; + + // splitBlock updates DT, LI and RI. + splitEntryBlockForAlloca(&EntryBlock, DT, LI, RI); + + return true; +} + namespace { /// Prepare the IR for the scop detection. @@ -35,9 +55,6 @@ class CodePreparation final : public FunctionPass { CodePreparation(const CodePreparation &) = delete; const CodePreparation &operator=(const CodePreparation &) = delete; - LoopInfo *LI; - ScalarEvolution *SE; - void clear(); public: @@ -58,19 +75,11 @@ public: PreservedAnalyses CodePreparationPass::run(Function &F, FunctionAnalysisManager &FAM) { - - // Find first non-alloca instruction. Every basic block has a non-alloca - // instruction, as every well formed basic block has a terminator. - auto &EntryBlock = F.getEntryBlock(); - BasicBlock::iterator I = EntryBlock.begin(); - while (isa<AllocaInst>(I)) - ++I; - auto &DT = FAM.getResult<DominatorTreeAnalysis>(F); auto &LI = FAM.getResult<LoopAnalysis>(F); - - // splitBlock updates DT, LI and RI. - splitEntryBlockForAlloca(&EntryBlock, &DT, &LI, nullptr); + bool Changed = runCodePreprationImpl(F, &DT, &LI, nullptr); + if (!Changed) + return PreservedAnalyses::all(); PreservedAnalyses PA; PA.preserve<DominatorTreeAnalysis>(); @@ -84,7 +93,6 @@ CodePreparation::~CodePreparation() { clear(); } void CodePreparation::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired<LoopInfoWrapperPass>(); - AU.addRequired<ScalarEvolutionWrapperPass>(); AU.addPreserved<LoopInfoWrapperPass>(); AU.addPreserved<RegionInfoPass>(); @@ -96,10 +104,11 @@ bool CodePreparation::runOnFunction(Function &F) { if (skipFunction(F)) return false; - LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); - SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE(); + DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); + LoopInfo *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); + RegionInfo *RI = &getAnalysis<RegionInfoPass>().getRegionInfo(); - splitEntryBlockForAlloca(&F.getEntryBlock(), this); + runCodePreprationImpl(F, DT, LI, RI); return true; } |
