[llvm-commits] CVS: llvm/lib/Transforms/IPO/LoopExtractor.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Aug 12 20:05:28 PDT 2004
Changes in directory llvm/lib/Transforms/IPO:
LoopExtractor.cpp updated: 1.12 -> 1.13
---
Log message:
"extract" the block extractor pass from bugpoint (haha)
---
Diffs of the changes: (+53 -0)
Index: llvm/lib/Transforms/IPO/LoopExtractor.cpp
diff -u llvm/lib/Transforms/IPO/LoopExtractor.cpp:1.12 llvm/lib/Transforms/IPO/LoopExtractor.cpp:1.13
--- llvm/lib/Transforms/IPO/LoopExtractor.cpp:1.12 Thu Jul 29 12:28:42 2004
+++ llvm/lib/Transforms/IPO/LoopExtractor.cpp Thu Aug 12 22:05:17 2004
@@ -129,3 +129,56 @@
Pass *llvm::createSingleLoopExtractorPass() {
return new SingleLoopExtractor();
}
+
+
+namespace {
+ /// BlockExtractorPass - This pass is used by bugpoint to extract all blocks
+ /// from the module into their own functions except for those specified by the
+ /// BlocksToNotExtract list.
+ class BlockExtractorPass : public Pass {
+ std::vector<BasicBlock*> BlocksToNotExtract;
+ public:
+ BlockExtractorPass(std::vector<BasicBlock*> &B) : BlocksToNotExtract(B) {}
+ BlockExtractorPass() {}
+
+ bool run(Module &M);
+ };
+ RegisterOpt<BlockExtractorPass>
+ XX("extract-blocks", "Extract Basic Blocks From Module (for bugpoint use)");
+}
+
+// createBlockExtractorPass - This pass extracts all blocks (except those
+// specified in the argument list) from the functions in the module.
+//
+Pass *llvm::createBlockExtractorPass(std::vector<BasicBlock*> &BTNE) {
+ return new BlockExtractorPass(BTNE);
+}
+
+bool BlockExtractorPass::run(Module &M) {
+ std::set<BasicBlock*> TranslatedBlocksToNotExtract;
+ for (unsigned i = 0, e = BlocksToNotExtract.size(); i != e; ++i) {
+ BasicBlock *BB = BlocksToNotExtract[i];
+ Function *F = BB->getParent();
+
+ // Map the corresponding function in this module.
+ Function *MF = M.getFunction(F->getName(), F->getFunctionType());
+
+ // Figure out which index the basic block is in its function.
+ Function::iterator BBI = MF->begin();
+ std::advance(BBI, std::distance(F->begin(), Function::iterator(BB)));
+ TranslatedBlocksToNotExtract.insert(BBI);
+ }
+
+ // Now that we know which blocks to not extract, figure out which ones we WANT
+ // to extract.
+ std::vector<BasicBlock*> BlocksToExtract;
+ for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
+ for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
+ if (!TranslatedBlocksToNotExtract.count(BB))
+ BlocksToExtract.push_back(BB);
+
+ for (unsigned i = 0, e = BlocksToExtract.size(); i != e; ++i)
+ ExtractBasicBlock(BlocksToExtract[i]);
+
+ return !BlocksToExtract.empty();
+}
More information about the llvm-commits
mailing list