Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 1 | //===- TestPasses.cpp - "buggy" passes used to test bugpoint --------------===// |
John Criswell | 7c0e022 | 2003-10-20 17:47:21 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 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" |
| 19 | #include "llvm/Support/InstVisitor.h" |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 20 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 21 | using namespace llvm; |
| 22 | |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 23 | namespace { |
| 24 | /// CrashOnCalls - This pass is used to test bugpoint. It intentionally |
| 25 | /// crashes on any call instructions. |
| 26 | class CrashOnCalls : public BasicBlockPass { |
| 27 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 28 | AU.setPreservesAll(); |
| 29 | } |
| 30 | |
| 31 | bool runOnBasicBlock(BasicBlock &BB) { |
| 32 | for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) |
| 33 | if (isa<CallInst>(*I)) |
| 34 | abort(); |
| 35 | |
| 36 | return false; |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | RegisterPass<CrashOnCalls> |
| 41 | X("bugpoint-crashcalls", |
| 42 | "BugPoint Test Pass - Intentionally crash on CallInsts"); |
| 43 | } |
| 44 | |
| 45 | namespace { |
| 46 | /// DeleteCalls - This pass is used to test bugpoint. It intentionally |
Chris Lattner | 9d5968d | 2004-03-17 17:29:08 +0000 | [diff] [blame] | 47 | /// deletes some call instructions, "misoptimizing" the program. |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 48 | class DeleteCalls : public BasicBlockPass { |
| 49 | bool runOnBasicBlock(BasicBlock &BB) { |
| 50 | for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) |
Chris Lattner | 6e96a99c | 2003-04-23 16:38:00 +0000 | [diff] [blame] | 51 | if (CallInst *CI = dyn_cast<CallInst>(I)) { |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 52 | if (!CI->use_empty()) |
| 53 | CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); |
| 54 | CI->getParent()->getInstList().erase(CI); |
Chris Lattner | 9d5968d | 2004-03-17 17:29:08 +0000 | [diff] [blame] | 55 | break; |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 56 | } |
| 57 | return false; |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | RegisterPass<DeleteCalls> |
| 62 | Y("bugpoint-deletecalls", |
| 63 | "BugPoint Test Pass - Intentionally 'misoptimize' CallInsts"); |
| 64 | } |