Run dead arg elimination, and tell it that it's ok to hack up non-internal functions
[oota-llvm.git] / tools / bugpoint / TestPasses.cpp
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
8 #include "llvm/Pass.h"
9 #include "llvm/iOther.h"
10 #include "llvm/Support/InstVisitor.h"
11 #include "llvm/Constant.h"
12 #include "llvm/BasicBlock.h"
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)
42         if (CallInst *CI = dyn_cast<CallInst>(I)) {
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 }