27
27
using namespace llvm ;
28
28
using namespace polly ;
29
29
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
+
30
50
namespace {
31
51
32
52
// / Prepare the IR for the scop detection.
@@ -35,9 +55,6 @@ class CodePreparation final : public FunctionPass {
35
55
CodePreparation (const CodePreparation &) = delete ;
36
56
const CodePreparation &operator =(const CodePreparation &) = delete ;
37
57
38
- LoopInfo *LI;
39
- ScalarEvolution *SE;
40
-
41
58
void clear ();
42
59
43
60
public:
@@ -58,19 +75,11 @@ class CodePreparation final : public FunctionPass {
58
75
59
76
PreservedAnalyses CodePreparationPass::run (Function &F,
60
77
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
-
69
78
auto &DT = FAM.getResult <DominatorTreeAnalysis>(F);
70
79
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 ( );
74
83
75
84
PreservedAnalyses PA;
76
85
PA.preserve <DominatorTreeAnalysis>();
@@ -84,7 +93,6 @@ CodePreparation::~CodePreparation() { clear(); }
84
93
85
94
void CodePreparation::getAnalysisUsage (AnalysisUsage &AU) const {
86
95
AU.addRequired <LoopInfoWrapperPass>();
87
- AU.addRequired <ScalarEvolutionWrapperPass>();
88
96
89
97
AU.addPreserved <LoopInfoWrapperPass>();
90
98
AU.addPreserved <RegionInfoPass>();
@@ -96,10 +104,11 @@ bool CodePreparation::runOnFunction(Function &F) {
96
104
if (skipFunction (F))
97
105
return false ;
98
106
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 ();
101
110
102
- splitEntryBlockForAlloca (&F. getEntryBlock (), this );
111
+ runCodePreprationImpl (F, DT, LI, RI );
103
112
104
113
return true ;
105
114
}
0 commit comments