18
18
#include " llvm/iTerminators.h"
19
19
#include " llvm/Module.h"
20
20
#include " llvm/Pass.h"
21
+ #include " llvm/Analysis/Dominators.h"
21
22
#include " llvm/Analysis/LoopInfo.h"
22
23
#include " llvm/Transforms/Scalar.h"
23
24
#include " llvm/Transforms/Utils/FunctionUtils.h"
25
+ #include " Support/Statistic.h"
24
26
using namespace llvm ;
25
27
26
28
namespace {
29
+ Statistic<> NumExtracted (" loop-extract" , " Number of loops extracted" );
30
+
27
31
// FIXME: This is not a function pass, but the PassManager doesn't allow
28
32
// Module passes to require FunctionPasses, so we can't get loop info if we're
29
33
// not a function pass.
@@ -35,8 +39,10 @@ namespace {
35
39
virtual bool runOnFunction (Function &F);
36
40
37
41
virtual void getAnalysisUsage (AnalysisUsage &AU) const {
38
- AU.addRequired <LoopInfo>( );
42
+ AU.addRequiredID (BreakCriticalEdgesID );
39
43
AU.addRequiredID (LoopSimplifyID);
44
+ AU.addRequired <DominatorSet>();
45
+ AU.addRequired <LoopInfo>();
40
46
}
41
47
};
42
48
@@ -59,14 +65,17 @@ bool LoopExtractor::runOnFunction(Function &F) {
59
65
if (LI.begin () == LI.end ())
60
66
return false ;
61
67
68
+ DominatorSet &DS = getAnalysis<DominatorSet>();
69
+
62
70
// If there is more than one top-level loop in this function, extract all of
63
71
// the loops.
64
72
bool Changed = false ;
65
73
if (LI.end ()-LI.begin () > 1 ) {
66
74
for (LoopInfo::iterator i = LI.begin (), e = LI.end (); i != e; ++i) {
67
75
if (NumLoops == 0 ) return Changed;
68
76
--NumLoops;
69
- Changed |= (ExtractLoop (*i) != 0 );
77
+ Changed |= ExtractLoop (DS, *i) != 0 ;
78
+ ++NumExtracted;
70
79
}
71
80
} else {
72
81
// Otherwise there is exactly one top-level loop. If this function is more
@@ -93,7 +102,8 @@ bool LoopExtractor::runOnFunction(Function &F) {
93
102
if (ShouldExtractLoop) {
94
103
if (NumLoops == 0 ) return Changed;
95
104
--NumLoops;
96
- Changed |= (ExtractLoop (TLL) != 0 );
105
+ Changed |= ExtractLoop (DS, TLL) != 0 ;
106
+ ++NumExtracted;
97
107
} else {
98
108
// Okay, this function is a minimal container around the specified loop.
99
109
// If we extract the loop, we will continue to just keep extracting it
@@ -102,7 +112,8 @@ bool LoopExtractor::runOnFunction(Function &F) {
102
112
for (Loop::iterator i = TLL->begin (), e = TLL->end (); i != e; ++i) {
103
113
if (NumLoops == 0 ) return Changed;
104
114
--NumLoops;
105
- Changed |= (ExtractLoop (*i) != 0 );
115
+ Changed |= ExtractLoop (DS, *i) != 0 ;
116
+ ++NumExtracted;
106
117
}
107
118
}
108
119
}
0 commit comments