blob: 900bf632a83bb1552d527469c1b3cb27bf8d6d39 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- TestPasses.cpp - "buggy" passes used to test bugpoint --------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5f5a5732007-12-29 20:44:31 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
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/Instructions.h"
18#include "llvm/Pass.h"
19#include "llvm/Type.h"
20#include "llvm/Support/InstVisitor.h"
21
22using namespace llvm;
23
24namespace {
25 /// CrashOnCalls - This pass is used to test bugpoint. It intentionally
26 /// crashes on any call instructions.
27 class CrashOnCalls : public BasicBlockPass {
28 public:
29 static char ID; // Pass ID, replacement for typeid
Dan Gohmanc74a1972009-02-18 05:09:16 +000030 CrashOnCalls() : BasicBlockPass(&ID) {}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000031 private:
32 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
33 AU.setPreservesAll();
34 }
35
36 bool runOnBasicBlock(BasicBlock &BB) {
37 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
38 if (isa<CallInst>(*I))
39 abort();
40
41 return false;
42 }
43 };
44
45 char CrashOnCalls::ID = 0;
46 RegisterPass<CrashOnCalls>
47 X("bugpoint-crashcalls",
48 "BugPoint Test Pass - Intentionally crash on CallInsts");
49}
50
51namespace {
52 /// DeleteCalls - This pass is used to test bugpoint. It intentionally
53 /// deletes some call instructions, "misoptimizing" the program.
54 class DeleteCalls : public BasicBlockPass {
55 public:
56 static char ID; // Pass ID, replacement for typeid
Dan Gohmanc74a1972009-02-18 05:09:16 +000057 DeleteCalls() : BasicBlockPass(&ID) {}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000058 private:
59 bool runOnBasicBlock(BasicBlock &BB) {
60 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
61 if (CallInst *CI = dyn_cast<CallInst>(I)) {
62 if (!CI->use_empty())
Owen Andersonaac28372009-07-31 20:28:14 +000063 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064 CI->getParent()->getInstList().erase(CI);
65 break;
66 }
67 return false;
68 }
69 };
70
71 char DeleteCalls::ID = 0;
72 RegisterPass<DeleteCalls>
73 Y("bugpoint-deletecalls",
74 "BugPoint Test Pass - Intentionally 'misoptimize' CallInsts");
75}