aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-03-14 20:01:36 +0000
committerChris Lattner <sabre@nondot.org>2004-03-14 20:01:36 +0000
commit41bc0b069c74afa05e92a97ff2c5d3cfa7426505 (patch)
treecbf70ce354e884057b697b668fbd946c5eccdb87
parent7bc91c62f01e14e0cd1ee32755a10d2abb878933 (diff)
Split into two passes. Now there is the general loop extractor, usable on
the command line, and the single loop extractor, usable by bugpoint git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12390 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/IPO/LoopExtractor.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/lib/Transforms/IPO/LoopExtractor.cpp b/lib/Transforms/IPO/LoopExtractor.cpp
index f0d79e1a06..ce4d0f7e32 100644
--- a/lib/Transforms/IPO/LoopExtractor.cpp
+++ b/lib/Transforms/IPO/LoopExtractor.cpp
@@ -23,8 +23,14 @@
using namespace llvm;
namespace {
- // FIXME: PassManager should allow Module passes to require FunctionPasses
+ // FIXME: This is not a function pass, but the PassManager doesn't allow
+ // Module passes to require FunctionPasses, so we can't get loop info if we're
+ // not a function pass.
struct LoopExtractor : public FunctionPass {
+ unsigned NumLoops;
+
+ LoopExtractor(unsigned numLoops = ~0) : NumLoops(numLoops) {}
+
virtual bool runOnFunction(Function &F);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
@@ -35,6 +41,14 @@ namespace {
RegisterOpt<LoopExtractor>
X("loop-extract", "Extract loops into new functions");
+
+ /// SingleLoopExtractor - For bugpoint.
+ struct SingleLoopExtractor : public LoopExtractor {
+ SingleLoopExtractor() : LoopExtractor(1) {}
+ };
+
+ RegisterOpt<SingleLoopExtractor>
+ Y("loop-extract-single", "Extract at most one loop into a new function");
} // End anonymous namespace
bool LoopExtractor::runOnFunction(Function &F) {
@@ -47,14 +61,18 @@ bool LoopExtractor::runOnFunction(Function &F) {
bool Changed = false;
// Try to move each loop out of the code into separate function
- for (LoopInfo::iterator i = LI.begin(), e = LI.end(); i != e; ++i)
+ for (LoopInfo::iterator i = LI.begin(), e = LI.end(); i != e; ++i) {
+ if (NumLoops == 0) return Changed;
+ --NumLoops;
Changed |= (ExtractLoop(*i) != 0);
+ }
return Changed;
}
-/// createLoopExtractorPass
-///
-Pass* llvm::createLoopExtractorPass() {
- return new LoopExtractor();
+// createSingleLoopExtractorPass - This pass extracts one natural loop from the
+// program into a function if it can. This is used by bugpoint.
+//
+Pass *llvm::createSingleLoopExtractorPass() {
+ return new SingleLoopExtractor();
}