blob: 5147a9070707ba44ce22d3d2d4b2723f186e6809 [file] [log] [blame]
Chris Lattnerafade922002-11-20 22:28:10 +00001//===- TestPasses.cpp - "buggy" passes used to test bugpoint --------------===//
Misha Brukman3da94ae2005-04-22 00:00:37 +00002//
John Criswell7c0e0222003-10-20 17:47:21 +00003// 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.
Misha Brukman3da94ae2005-04-22 00:00:37 +00007//
John Criswell7c0e0222003-10-20 17:47:21 +00008//===----------------------------------------------------------------------===//
Chris Lattnerafade922002-11-20 22:28:10 +00009//
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
Chris Lattnerafade922002-11-20 22:28:10 +000015#include "llvm/BasicBlock.h"
Misha Brukmane49603d2003-08-07 21:19:30 +000016#include "llvm/Constant.h"
Misha Brukman47b14a42004-07-29 17:30:56 +000017#include "llvm/Instructions.h"
Misha Brukmane49603d2003-08-07 21:19:30 +000018#include "llvm/Pass.h"
Chris Lattner5b3a4552005-03-17 15:38:16 +000019#include "llvm/Type.h"
Misha Brukmane49603d2003-08-07 21:19:30 +000020#include "llvm/Support/InstVisitor.h"
Chris Lattnerafade922002-11-20 22:28:10 +000021
Brian Gaeked0fde302003-11-11 22:41:34 +000022using namespace llvm;
23
Chris Lattnerafade922002-11-20 22:28:10 +000024namespace {
25 /// CrashOnCalls - This pass is used to test bugpoint. It intentionally
26 /// crashes on any call instructions.
27 class CrashOnCalls : public BasicBlockPass {
28 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
29 AU.setPreservesAll();
30 }
31
32 bool runOnBasicBlock(BasicBlock &BB) {
33 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
34 if (isa<CallInst>(*I))
35 abort();
36
37 return false;
38 }
39 };
40
41 RegisterPass<CrashOnCalls>
42 X("bugpoint-crashcalls",
43 "BugPoint Test Pass - Intentionally crash on CallInsts");
44}
45
46namespace {
47 /// DeleteCalls - This pass is used to test bugpoint. It intentionally
Chris Lattner9d5968d2004-03-17 17:29:08 +000048 /// deletes some call instructions, "misoptimizing" the program.
Chris Lattnerafade922002-11-20 22:28:10 +000049 class DeleteCalls : public BasicBlockPass {
50 bool runOnBasicBlock(BasicBlock &BB) {
51 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
Chris Lattner6e96a99c2003-04-23 16:38:00 +000052 if (CallInst *CI = dyn_cast<CallInst>(I)) {
Chris Lattnerafade922002-11-20 22:28:10 +000053 if (!CI->use_empty())
54 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
55 CI->getParent()->getInstList().erase(CI);
Chris Lattner9d5968d2004-03-17 17:29:08 +000056 break;
Chris Lattnerafade922002-11-20 22:28:10 +000057 }
58 return false;
59 }
60 };
61
62 RegisterPass<DeleteCalls>
63 Y("bugpoint-deletecalls",
64 "BugPoint Test Pass - Intentionally 'misoptimize' CallInsts");
65}