Fixes for PR214. Use the SHLIBEXT variable instead of hardcoding .so into
[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/iOther.h"
18 #include "llvm/Pass.h"
19 #include "llvm/Support/InstVisitor.h"
20
21 using namespace llvm;
22
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
47   /// deletes all call instructions, "misoptimizing" the program.
48   class DeleteCalls : public BasicBlockPass {
49     bool runOnBasicBlock(BasicBlock &BB) {
50       for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
51         if (CallInst *CI = dyn_cast<CallInst>(I)) {
52           if (!CI->use_empty())
53             CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
54           CI->getParent()->getInstList().erase(CI);
55         }
56       return false;
57     }
58   };
59
60   RegisterPass<DeleteCalls>
61   Y("bugpoint-deletecalls",
62     "BugPoint Test Pass - Intentionally 'misoptimize' CallInsts");
63 }