Skip to content

[Polly][CodePreparation] Extract common code of LPM and NPM #140419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: users/meinersbur/polly_NPM-ScopInliner
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions polly/lib/Transform/CodePreparation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -58,19 +75,11 @@ class CodePreparation final : public FunctionPass {

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>();
Expand All @@ -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>();
Expand All @@ -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;
}
Expand Down
Loading