Remove trailing whitespace
[oota-llvm.git] / tools / bugpoint / TestPasses.cpp
1 //===- TestPasses.cpp - "buggy" passes used to test bugpoint --------------===//
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 //===----------------------------------------------------------------------===//
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
15 #include "llvm/BasicBlock.h"
16 #include "llvm/Constant.h"
17 #include "llvm/Instructions.h"
18 #include "llvm/Pass.h"
19 #include "llvm/Type.h"
20 #include "llvm/Support/InstVisitor.h"
21
22 using namespace llvm;
23
24 namespace {
25   /// CrashOnCalls - This pass is used to test bugpoint.  It intentionally
26   /// crashes on any call instructions.
27   class CrashOnCalls : public BasicBlockPass {
28     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
29       AU.setPreservesAll();
30     }
31
32     bool runOnBasicBlock(BasicBlock &BB) {
33       for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
34         if (isa<CallInst>(*I))
35           abort();
36
37       return false;
38     }
39   };
40
41   RegisterPass<CrashOnCalls>
42   X("bugpoint-crashcalls",
43     "BugPoint Test Pass - Intentionally crash on CallInsts");
44 }
45
46 namespace {
47   /// DeleteCalls - This pass is used to test bugpoint.  It intentionally
48   /// deletes some call instructions, "misoptimizing" the program.
49   class DeleteCalls : public BasicBlockPass {
50     bool runOnBasicBlock(BasicBlock &BB) {
51       for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
52         if (CallInst *CI = dyn_cast<CallInst>(I)) {
53           if (!CI->use_empty())
54             CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
55           CI->getParent()->getInstList().erase(CI);
56           break;
57         }
58       return false;
59     }
60   };
61
62   RegisterPass<DeleteCalls>
63   Y("bugpoint-deletecalls",
64     "BugPoint Test Pass - Intentionally 'misoptimize' CallInsts");
65 }