1 //===- TestPasses.cpp - "buggy" passes used to test bugpoint --------------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file contains "buggy" passes that are used to test bugpoint, to check
11 // that it is narrowing down testcases correctly.
13 //===----------------------------------------------------------------------===//
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"
22 /// CrashOnCalls - This pass is used to test bugpoint. It intentionally
23 /// crashes on any call instructions.
24 class CrashOnCalls : public BasicBlockPass {
25 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
29 bool runOnBasicBlock(BasicBlock &BB) {
30 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
31 if (isa<CallInst>(*I))
38 RegisterPass<CrashOnCalls>
39 X("bugpoint-crashcalls",
40 "BugPoint Test Pass - Intentionally crash on CallInsts");
44 /// DeleteCalls - This pass is used to test bugpoint. It intentionally
45 /// deletes all call instructions, "misoptimizing" the program.
46 class DeleteCalls : public BasicBlockPass {
47 bool runOnBasicBlock(BasicBlock &BB) {
48 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
49 if (CallInst *CI = dyn_cast<CallInst>(I)) {
51 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
52 CI->getParent()->getInstList().erase(CI);
58 RegisterPass<DeleteCalls>
59 Y("bugpoint-deletecalls",
60 "BugPoint Test Pass - Intentionally 'misoptimize' CallInsts");