llvm.org GIT mirror llvm / 4e1be6d
Deleting redundant copy of block extractor pass. See also PR1775. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43694 91177308-0d34-0410-b5e6-96231b3b80d8 Gordon Henriksen 11 years ago
3 changed file(s) with 6 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
152152 /// createBlockExtractorPass - This pass extracts all blocks (except those
153153 /// specified in the argument list) from the functions in the module.
154154 ///
155 ModulePass *createBlockExtractorPass(std::vector &BTNE);
155 ModulePass *createBlockExtractorPass(const std::vector &BTNE);
156156
157157 /// createOptimizeWellKnownCallsPass - This pass optimizes specific calls to
158158 /// specific well-known (library) functions.
150150 std::vector BlocksToNotExtract;
151151 public:
152152 static char ID; // Pass identification, replacement for typeid
153 explicit BlockExtractorPass(std::vector &B)
153 explicit BlockExtractorPass(const std::vector &B)
154154 : ModulePass((intptr_t)&ID), BlocksToNotExtract(B) {}
155155 BlockExtractorPass() : ModulePass((intptr_t)&ID) {}
156156
165165 // createBlockExtractorPass - This pass extracts all blocks (except those
166166 // specified in the argument list) from the functions in the module.
167167 //
168 ModulePass *llvm::createBlockExtractorPass(std::vector &BTNE) {
168 ModulePass *llvm::createBlockExtractorPass(const std::vector &BTNE)
169 {
169170 return new BlockExtractorPass(BTNE);
170171 }
171172
296296 // Basic Block Extraction Code
297297 //===----------------------------------------------------------------------===//
298298
299 namespace {
300 std::vector BlocksToNotExtract;
301
302 /// BlockExtractorPass - This pass is used by bugpoint to extract all blocks
303 /// from the module into their own functions except for those specified by the
304 /// BlocksToNotExtract list.
305 class BlockExtractorPass : public ModulePass {
306 bool runOnModule(Module &M);
307 public:
308 static char ID; // Pass ID, replacement for typeid
309 BlockExtractorPass() : ModulePass((intptr_t)&ID) {}
310 };
311 char BlockExtractorPass::ID = 0;
312 RegisterPass
313 XX("extract-bbs", "Extract Basic Blocks From Module (for bugpoint use)");
314 }
315
316 bool BlockExtractorPass::runOnModule(Module &M) {
317 std::set TranslatedBlocksToNotExtract;
318 for (unsigned i = 0, e = BlocksToNotExtract.size(); i != e; ++i) {
319 BasicBlock *BB = BlocksToNotExtract[i];
320 Function *F = BB->getParent();
321
322 // Map the corresponding function in this module.
323 Function *MF = M.getFunction(F->getName());
324
325 // Figure out which index the basic block is in its function.
326 Function::iterator BBI = MF->begin();
327 std::advance(BBI, std::distance(F->begin(), Function::iterator(BB)));
328 TranslatedBlocksToNotExtract.insert(BBI);
329 }
330
331 // Now that we know which blocks to not extract, figure out which ones we WANT
332 // to extract.
333 std::vector BlocksToExtract;
334 for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
335 for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
336 if (!TranslatedBlocksToNotExtract.count(BB))
337 BlocksToExtract.push_back(BB);
338
339 for (unsigned i = 0, e = BlocksToExtract.size(); i != e; ++i)
340 ExtractBasicBlock(BlocksToExtract[i]);
341
342 return !BlocksToExtract.empty();
343 }
344
345299 /// ExtractMappedBlocksFromModule - Extract all but the specified basic blocks
346300 /// into their own functions. The only detail is that M is actually a module
347301 /// cloned from the one the BBs are in, so some mapping needs to be performed.
350304 Module *BugDriver::ExtractMappedBlocksFromModule(const
351305 std::vector &BBs,
352306 Module *M) {
353 // Set the global list so that pass will be able to access it.
354 BlocksToNotExtract = BBs;
355
356307 std::vector PI;
357 PI.push_back(getPI(new BlockExtractorPass()));
308 // FIXME: BBs is actually ignored. See http://llvm.org/PR1775
309 PI.push_back(getPI(createBlockExtractorPass(BBs)));
358310 Module *Ret = runPassesOn(M, PI);
359 BlocksToNotExtract.clear();
360311 if (Ret == 0) {
361312 std::cout << "*** Basic Block extraction failed, please report a bug!\n";
362313 M = swapProgramIn(M);