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