From: Chris Lattner Date: Sun, 14 Mar 2004 02:32:27 +0000 (+0000) Subject: Move to the IPO library. Utils shouldn't contain passes. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=c3c8703c3bf0d4fff3420ee3ce00caea992a354c;p=oota-llvm.git Move to the IPO library. Utils shouldn't contain passes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12372 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/LoopExtractor.cpp b/lib/Transforms/IPO/LoopExtractor.cpp new file mode 100644 index 00000000000..3eda45265d2 --- /dev/null +++ b/lib/Transforms/IPO/LoopExtractor.cpp @@ -0,0 +1,68 @@ +//===- LoopExtractor.cpp - Extract each loop into a new function ----------===// +// +// A pass wrapper around the ExtractLoop() scalar transformation to extract each +// top-level loop into its own new function. If the loop is the ONLY loop in a +// given function, it is not touched. This is a pass most useful for debugging +// via bugpoint. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Module.h" +#include "llvm/Pass.h" +#include "llvm/Analysis/LoopInfo.h" +#include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/Utils/FunctionUtils.h" +#include +using namespace llvm; + +namespace { + +// FIXME: PassManager should allow Module passes to require FunctionPasses +struct LoopExtractor : public FunctionPass { + +public: + LoopExtractor() {} + virtual bool run(Module &M); + virtual bool runOnFunction(Function &F); + + virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AU.addRequired(); + } + +}; + +RegisterOpt +X("loop-extract", "Extract loops into new functions"); + +bool LoopExtractor::run(Module &M) { + bool Changed = false; + for (Module::iterator i = M.begin(), e = M.end(); i != e; ++i) + Changed |= runOnFunction(*i); + return Changed; +} + +bool LoopExtractor::runOnFunction(Function &F) { + std::cerr << F.getName() << "\n"; + + LoopInfo &LI = getAnalysis(); + + // We don't want to keep extracting the only loop of a function into a new one + if (LI.begin() == LI.end() || LI.begin() + 1 == LI.end()) + return false; + + 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) + Changed |= (ExtractLoop(*i) != 0); + + return Changed; +} + +} // End anonymous namespace + +/// createLoopExtractorPass +/// +FunctionPass* llvm::createLoopExtractorPass() { + return new LoopExtractor(); +} diff --git a/lib/Transforms/Utils/LoopExtractor.cpp b/lib/Transforms/Utils/LoopExtractor.cpp deleted file mode 100644 index 3eda45265d2..00000000000 --- a/lib/Transforms/Utils/LoopExtractor.cpp +++ /dev/null @@ -1,68 +0,0 @@ -//===- LoopExtractor.cpp - Extract each loop into a new function ----------===// -// -// A pass wrapper around the ExtractLoop() scalar transformation to extract each -// top-level loop into its own new function. If the loop is the ONLY loop in a -// given function, it is not touched. This is a pass most useful for debugging -// via bugpoint. -// -//===----------------------------------------------------------------------===// - -#include "llvm/Module.h" -#include "llvm/Pass.h" -#include "llvm/Analysis/LoopInfo.h" -#include "llvm/Transforms/Scalar.h" -#include "llvm/Transforms/Utils/FunctionUtils.h" -#include -using namespace llvm; - -namespace { - -// FIXME: PassManager should allow Module passes to require FunctionPasses -struct LoopExtractor : public FunctionPass { - -public: - LoopExtractor() {} - virtual bool run(Module &M); - virtual bool runOnFunction(Function &F); - - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.addRequired(); - } - -}; - -RegisterOpt -X("loop-extract", "Extract loops into new functions"); - -bool LoopExtractor::run(Module &M) { - bool Changed = false; - for (Module::iterator i = M.begin(), e = M.end(); i != e; ++i) - Changed |= runOnFunction(*i); - return Changed; -} - -bool LoopExtractor::runOnFunction(Function &F) { - std::cerr << F.getName() << "\n"; - - LoopInfo &LI = getAnalysis(); - - // We don't want to keep extracting the only loop of a function into a new one - if (LI.begin() == LI.end() || LI.begin() + 1 == LI.end()) - return false; - - 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) - Changed |= (ExtractLoop(*i) != 0); - - return Changed; -} - -} // End anonymous namespace - -/// createLoopExtractorPass -/// -FunctionPass* llvm::createLoopExtractorPass() { - return new LoopExtractor(); -}