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 //===----------------------------------------------------------------------===//
11 // This file contains "buggy" passes that are used to test bugpoint, to check
12 // that it is narrowing down testcases correctly.
14 //===----------------------------------------------------------------------===//
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"
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 {
30 bool runOnBasicBlock(BasicBlock &BB) {
31 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
32 if (isa<CallInst>(*I))
39 RegisterPass<CrashOnCalls>
40 X("bugpoint-crashcalls",
41 "BugPoint Test Pass - Intentionally crash on CallInsts");
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)) {
52 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
53 CI->getParent()->getInstList().erase(CI);
59 RegisterPass<DeleteCalls>
60 Y("bugpoint-deletecalls",
61 "BugPoint Test Pass - Intentionally 'misoptimize' CallInsts");