Chris Lattner | 73a6bdd | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 1 | //===- TestPasses.cpp - "buggy" passes used to test bugpoint --------------===// |
| 2 | // |
| 3 | // This file contains "buggy" passes that are used to test bugpoint, to check |
| 4 | // that it is narrowing down testcases correctly. |
| 5 | // |
| 6 | //===----------------------------------------------------------------------===// |
| 7 | |
Chris Lattner | 73a6bdd | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 8 | #include "llvm/BasicBlock.h" |
Misha Brukman | 0c2305b | 2003-08-07 21:19:30 +0000 | [diff] [blame^] | 9 | #include "llvm/Constant.h" |
| 10 | #include "llvm/iOther.h" |
| 11 | #include "llvm/Pass.h" |
| 12 | #include "llvm/Support/InstVisitor.h" |
Chris Lattner | 73a6bdd | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 13 | |
| 14 | namespace { |
| 15 | /// CrashOnCalls - This pass is used to test bugpoint. It intentionally |
| 16 | /// crashes on any call instructions. |
| 17 | class CrashOnCalls : public BasicBlockPass { |
| 18 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 19 | AU.setPreservesAll(); |
| 20 | } |
| 21 | |
| 22 | bool runOnBasicBlock(BasicBlock &BB) { |
| 23 | for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) |
| 24 | if (isa<CallInst>(*I)) |
| 25 | abort(); |
| 26 | |
| 27 | return false; |
| 28 | } |
| 29 | }; |
| 30 | |
| 31 | RegisterPass<CrashOnCalls> |
| 32 | X("bugpoint-crashcalls", |
| 33 | "BugPoint Test Pass - Intentionally crash on CallInsts"); |
| 34 | } |
| 35 | |
| 36 | namespace { |
| 37 | /// DeleteCalls - This pass is used to test bugpoint. It intentionally |
| 38 | /// deletes all call instructions, "misoptimizing" the program. |
| 39 | class DeleteCalls : public BasicBlockPass { |
| 40 | bool runOnBasicBlock(BasicBlock &BB) { |
| 41 | for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) |
Chris Lattner | e695da3 | 2003-04-23 16:38:00 +0000 | [diff] [blame] | 42 | if (CallInst *CI = dyn_cast<CallInst>(I)) { |
Chris Lattner | 73a6bdd | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 43 | if (!CI->use_empty()) |
| 44 | CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); |
| 45 | CI->getParent()->getInstList().erase(CI); |
| 46 | } |
| 47 | return false; |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | RegisterPass<DeleteCalls> |
| 52 | Y("bugpoint-deletecalls", |
| 53 | "BugPoint Test Pass - Intentionally 'misoptimize' CallInsts"); |
| 54 | } |