aboutsummaryrefslogtreecommitdiff
path: root/polly/lib/Transform/CodePreparation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'polly/lib/Transform/CodePreparation.cpp')
-rw-r--r--polly/lib/Transform/CodePreparation.cpp96
1 files changed, 18 insertions, 78 deletions
diff --git a/polly/lib/Transform/CodePreparation.cpp b/polly/lib/Transform/CodePreparation.cpp
index 7c8579eb..5b96c86 100644
--- a/polly/lib/Transform/CodePreparation.cpp
+++ b/polly/lib/Transform/CodePreparation.cpp
@@ -16,49 +16,17 @@
//===----------------------------------------------------------------------===//
#include "polly/CodePreparation.h"
-#include "polly/LinkAllPasses.h"
#include "polly/Support/ScopHelper.h"
#include "llvm/Analysis/DominanceFrontier.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/RegionInfo.h"
#include "llvm/Analysis/ScalarEvolution.h"
-#include "llvm/InitializePasses.h"
using namespace llvm;
using namespace polly;
-namespace {
-
-/// Prepare the IR for the scop detection.
-///
-class CodePreparation final : public FunctionPass {
- CodePreparation(const CodePreparation &) = delete;
- const CodePreparation &operator=(const CodePreparation &) = delete;
-
- LoopInfo *LI;
- ScalarEvolution *SE;
-
- void clear();
-
-public:
- static char ID;
-
- explicit CodePreparation() : FunctionPass(ID) {}
- ~CodePreparation();
-
- /// @name FunctionPass interface.
- //@{
- void getAnalysisUsage(AnalysisUsage &AU) const override;
- void releaseMemory() override;
- bool runOnFunction(Function &F) override;
- void print(raw_ostream &OS, const Module *) const override;
- //@}
-};
-} // namespace
-
-PreservedAnalyses CodePreparationPass::run(Function &F,
- FunctionAnalysisManager &FAM) {
-
+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();
@@ -66,55 +34,27 @@ PreservedAnalyses CodePreparationPass::run(Function &F,
while (isa<AllocaInst>(I))
++I;
- auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
- auto &LI = FAM.getResult<LoopAnalysis>(F);
+ // 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, nullptr);
+ splitEntryBlockForAlloca(&EntryBlock, DT, LI, RI);
+
+ return true;
+}
+
+PreservedAnalyses CodePreparationPass::run(Function &F,
+ FunctionAnalysisManager &FAM) {
+ auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
+ auto &LI = FAM.getResult<LoopAnalysis>(F);
+ bool Changed = runCodePreprationImpl(F, &DT, &LI, nullptr);
+ if (!Changed)
+ return PreservedAnalyses::all();
PreservedAnalyses PA;
PA.preserve<DominatorTreeAnalysis>();
PA.preserve<LoopAnalysis>();
return PA;
}
-
-void CodePreparation::clear() {}
-
-CodePreparation::~CodePreparation() { clear(); }
-
-void CodePreparation::getAnalysisUsage(AnalysisUsage &AU) const {
- AU.addRequired<LoopInfoWrapperPass>();
- AU.addRequired<ScalarEvolutionWrapperPass>();
-
- AU.addPreserved<LoopInfoWrapperPass>();
- AU.addPreserved<RegionInfoPass>();
- AU.addPreserved<DominatorTreeWrapperPass>();
- AU.addPreserved<DominanceFrontierWrapperPass>();
-}
-
-bool CodePreparation::runOnFunction(Function &F) {
- if (skipFunction(F))
- return false;
-
- LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
- SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
-
- splitEntryBlockForAlloca(&F.getEntryBlock(), this);
-
- return true;
-}
-
-void CodePreparation::releaseMemory() { clear(); }
-
-void CodePreparation::print(raw_ostream &OS, const Module *) const {}
-
-char CodePreparation::ID = 0;
-char &polly::CodePreparationID = CodePreparation::ID;
-
-Pass *polly::createCodePreparationPass() { return new CodePreparation(); }
-
-INITIALIZE_PASS_BEGIN(CodePreparation, "polly-prepare",
- "Polly - Prepare code for polly", false, false)
-INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
-INITIALIZE_PASS_END(CodePreparation, "polly-prepare",
- "Polly - Prepare code for polly", false, false)