2727using  namespace  llvm ; 
2828using  namespace  polly ; 
2929
30+ static  bool  runCodePreprationImpl (Function &F, DominatorTree *DT, LoopInfo *LI,
31+                                   RegionInfo *RI) {
32+   //  Find first non-alloca instruction. Every basic block has a non-alloca
33+   //  instruction, as every well formed basic block has a terminator.
34+   auto  &EntryBlock = F.getEntryBlock ();
35+   BasicBlock::iterator I = EntryBlock.begin ();
36+   while  (isa<AllocaInst>(I))
37+     ++I;
38+ 
39+   //  Abort if not necessary to split
40+   if  (I->isTerminator () && isa<BranchInst>(I) &&
41+       cast<BranchInst>(I)->isUnconditional ())
42+     return  false ;
43+ 
44+   //  splitBlock updates DT, LI and RI.
45+   splitEntryBlockForAlloca (&EntryBlock, DT, LI, RI);
46+ 
47+   return  true ;
48+ }
49+ 
3050namespace  {
3151
3252// / Prepare the IR for the scop detection.
@@ -35,9 +55,6 @@ class CodePreparation final : public FunctionPass {
3555  CodePreparation (const  CodePreparation &) = delete ;
3656  const  CodePreparation &operator =(const  CodePreparation &) = delete ;
3757
38-   LoopInfo *LI;
39-   ScalarEvolution *SE;
40- 
4158  void  clear ();
4259
4360public: 
@@ -58,19 +75,11 @@ class CodePreparation final : public FunctionPass {
5875
5976PreservedAnalyses CodePreparationPass::run (Function &F,
6077                                           FunctionAnalysisManager &FAM) {
61- 
62-   //  Find first non-alloca instruction. Every basic block has a non-alloca
63-   //  instruction, as every well formed basic block has a terminator.
64-   auto  &EntryBlock = F.getEntryBlock ();
65-   BasicBlock::iterator I = EntryBlock.begin ();
66-   while  (isa<AllocaInst>(I))
67-     ++I;
68- 
6978  auto  &DT = FAM.getResult <DominatorTreeAnalysis>(F);
7079  auto  &LI = FAM.getResult <LoopAnalysis>(F);
71- 
72-   //  splitBlock updates DT, LI and RI. 
73-   splitEntryBlockForAlloca (&EntryBlock, &DT, &LI,  nullptr );
80+    bool  Changed =  runCodePreprationImpl (F, &DT, &LI,  nullptr ); 
81+   if  (!Changed) 
82+      return   PreservedAnalyses::all ( );
7483
7584  PreservedAnalyses PA;
7685  PA.preserve <DominatorTreeAnalysis>();
@@ -84,7 +93,6 @@ CodePreparation::~CodePreparation() { clear(); }
8493
8594void  CodePreparation::getAnalysisUsage (AnalysisUsage &AU) const  {
8695  AU.addRequired <LoopInfoWrapperPass>();
87-   AU.addRequired <ScalarEvolutionWrapperPass>();
8896
8997  AU.addPreserved <LoopInfoWrapperPass>();
9098  AU.addPreserved <RegionInfoPass>();
@@ -96,10 +104,11 @@ bool CodePreparation::runOnFunction(Function &F) {
96104  if  (skipFunction (F))
97105    return  false ;
98106
99-   LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo ();
100-   SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE ();
107+   DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree ();
108+   LoopInfo *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo ();
109+   RegionInfo *RI = &getAnalysis<RegionInfoPass>().getRegionInfo ();
101110
102-   splitEntryBlockForAlloca (&F. getEntryBlock (),  this );
111+   runCodePreprationImpl (F, DT, LI, RI );
103112
104113  return  true ;
105114}
0 commit comments