Added copyright header to all C++ source files.
[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 //
11 // This file contains "buggy" passes that are used to test bugpoint, to check
12 // that it is narrowing down testcases correctly.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "llvm/BasicBlock.h"
17 #include "llvm/Constant.h"
18 #include "llvm/iOther.h"
19 #include "llvm/Pass.h"
20 #include "llvm/Support/InstVisitor.h"
21
22 namespace {
23   /// CrashOnCalls - This pass is used to test bugpoint.  It intentionally
24   /// crashes on any call instructions.
25   class CrashOnCalls : public BasicBlockPass {
26     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
27       AU.setPreservesAll();
28     }
29
30     bool runOnBasicBlock(BasicBlock &BB) {
31       for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
32         if (isa<CallInst>(*I))
33           abort();
34
35       return false;
36     }
37   };
38
39   RegisterPass<CrashOnCalls>
40   X("bugpoint-crashcalls",
41     "BugPoint Test Pass - Intentionally crash on CallInsts");
42 }
43
44 namespace {
45   /// DeleteCalls - This pass is used to test bugpoint.  It intentionally
46   /// deletes all call instructions, "misoptimizing" the program.
47   class DeleteCalls : public BasicBlockPass {
48     bool runOnBasicBlock(BasicBlock &BB) {
49       for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
50         if (CallInst *CI = dyn_cast<CallInst>(I)) {
51           if (!CI->use_empty())
52             CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
53           CI->getParent()->getInstList().erase(CI);
54         }
55       return false;
56     }
57   };
58
59   RegisterPass<DeleteCalls>
60   Y("bugpoint-deletecalls",
61     "BugPoint Test Pass - Intentionally 'misoptimize' CallInsts");
62 }