blob: 32bca9555b6de874d35abea8a1954742222af85c [file] [log] [blame]
Chris Lattner73a6bdd2002-11-20 22:28:10 +00001//===- 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
Chris Lattner73a6bdd2002-11-20 22:28:10 +00008#include "llvm/BasicBlock.h"
Misha Brukman0c2305b2003-08-07 21:19:30 +00009#include "llvm/Constant.h"
10#include "llvm/iOther.h"
11#include "llvm/Pass.h"
12#include "llvm/Support/InstVisitor.h"
Chris Lattner73a6bdd2002-11-20 22:28:10 +000013
14namespace {
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
36namespace {
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)
Chris Lattnere695da32003-04-23 16:38:00 +000042 if (CallInst *CI = dyn_cast<CallInst>(I)) {
Chris Lattner73a6bdd2002-11-20 22:28:10 +000043 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}