Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 1 | //===- TestPasses.cpp - "buggy" passes used to test bugpoint --------------===// |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | 7c0e022 | 2003-10-20 17:47:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 21c62da | 2007-12-29 20:44:31 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | 7c0e022 | 2003-10-20 17:47:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file contains "buggy" passes that are used to test bugpoint, to check |
| 11 | // that it is narrowing down testcases correctly. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 15 | #include "llvm/BasicBlock.h" |
Misha Brukman | e49603d | 2003-08-07 21:19:30 +0000 | [diff] [blame] | 16 | #include "llvm/Constant.h" |
Misha Brukman | 47b14a4 | 2004-07-29 17:30:56 +0000 | [diff] [blame] | 17 | #include "llvm/Instructions.h" |
Misha Brukman | e49603d | 2003-08-07 21:19:30 +0000 | [diff] [blame] | 18 | #include "llvm/Pass.h" |
Chris Lattner | 5b3a455 | 2005-03-17 15:38:16 +0000 | [diff] [blame] | 19 | #include "llvm/Type.h" |
Misha Brukman | e49603d | 2003-08-07 21:19:30 +0000 | [diff] [blame] | 20 | #include "llvm/Support/InstVisitor.h" |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 21 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 22 | using namespace llvm; |
| 23 | |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 24 | namespace { |
| 25 | /// CrashOnCalls - This pass is used to test bugpoint. It intentionally |
| 26 | /// crashes on any call instructions. |
| 27 | class CrashOnCalls : public BasicBlockPass { |
Devang Patel | 794fd75 | 2007-05-01 21:15:47 +0000 | [diff] [blame] | 28 | public: |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 29 | static char ID; // Pass ID, replacement for typeid |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 30 | CrashOnCalls() : BasicBlockPass(ID) {} |
Devang Patel | 794fd75 | 2007-05-01 21:15:47 +0000 | [diff] [blame] | 31 | private: |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 32 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 33 | AU.setPreservesAll(); |
| 34 | } |
| 35 | |
| 36 | bool runOnBasicBlock(BasicBlock &BB) { |
| 37 | for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) |
| 38 | if (isa<CallInst>(*I)) |
| 39 | abort(); |
| 40 | |
| 41 | return false; |
| 42 | } |
| 43 | }; |
Dan Gohman | a2a3bbc | 2010-08-20 00:56:16 +0000 | [diff] [blame] | 44 | } |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 45 | |
Dan Gohman | a2a3bbc | 2010-08-20 00:56:16 +0000 | [diff] [blame] | 46 | char CrashOnCalls::ID = 0; |
| 47 | static RegisterPass<CrashOnCalls> |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 48 | X("bugpoint-crashcalls", |
| 49 | "BugPoint Test Pass - Intentionally crash on CallInsts"); |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 50 | |
| 51 | namespace { |
| 52 | /// DeleteCalls - This pass is used to test bugpoint. It intentionally |
Chris Lattner | 9d5968d | 2004-03-17 17:29:08 +0000 | [diff] [blame] | 53 | /// deletes some call instructions, "misoptimizing" the program. |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 54 | class DeleteCalls : public BasicBlockPass { |
Devang Patel | 794fd75 | 2007-05-01 21:15:47 +0000 | [diff] [blame] | 55 | public: |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 56 | static char ID; // Pass ID, replacement for typeid |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 57 | DeleteCalls() : BasicBlockPass(ID) {} |
Devang Patel | 794fd75 | 2007-05-01 21:15:47 +0000 | [diff] [blame] | 58 | private: |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 59 | bool runOnBasicBlock(BasicBlock &BB) { |
| 60 | for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) |
Chris Lattner | 6e96a99c | 2003-04-23 16:38:00 +0000 | [diff] [blame] | 61 | if (CallInst *CI = dyn_cast<CallInst>(I)) { |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 62 | if (!CI->use_empty()) |
Owen Anderson | a7235ea | 2009-07-31 20:28:14 +0000 | [diff] [blame] | 63 | CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 64 | CI->getParent()->getInstList().erase(CI); |
Chris Lattner | 9d5968d | 2004-03-17 17:29:08 +0000 | [diff] [blame] | 65 | break; |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 66 | } |
| 67 | return false; |
| 68 | } |
| 69 | }; |
Dan Gohman | a2a3bbc | 2010-08-20 00:56:16 +0000 | [diff] [blame] | 70 | } |
Devang Patel | 794fd75 | 2007-05-01 21:15:47 +0000 | [diff] [blame] | 71 | |
Dan Gohman | a2a3bbc | 2010-08-20 00:56:16 +0000 | [diff] [blame] | 72 | char DeleteCalls::ID = 0; |
| 73 | static RegisterPass<DeleteCalls> |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 74 | Y("bugpoint-deletecalls", |
| 75 | "BugPoint Test Pass - Intentionally 'misoptimize' CallInsts"); |