blob: 900bf632a83bb1552d527469c1b3cb27bf8d6d39 [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//
Chris Lattner21c62da2007-12-29 20:44:31 +00005// This file is distributed under the University of Illinois Open Source
6// 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 {
Devang Patel794fd752007-05-01 21:15:47 +000028 public:
Devang Patel19974732007-05-03 01:11:54 +000029 static char ID; // Pass ID, replacement for typeid
Dan Gohman865f0062009-02-18 05:09:16 +000030 CrashOnCalls() : BasicBlockPass(&ID) {}
Devang Patel794fd752007-05-01 21:15:47 +000031 private:
Chris Lattnerafade922002-11-20 22:28:10 +000032 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
Devang Patel19974732007-05-03 01:11:54 +000045 char CrashOnCalls::ID = 0;
Chris Lattnerafade922002-11-20 22:28:10 +000046 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
Chris Lattner9d5968d2004-03-17 17:29:08 +000053 /// deletes some call instructions, "misoptimizing" the program.
Chris Lattnerafade922002-11-20 22:28:10 +000054 class DeleteCalls : public BasicBlockPass {
Devang Patel794fd752007-05-01 21:15:47 +000055 public:
Devang Patel19974732007-05-03 01:11:54 +000056 static char ID; // Pass ID, replacement for typeid
Dan Gohman865f0062009-02-18 05:09:16 +000057 DeleteCalls() : BasicBlockPass(&ID) {}
Devang Patel794fd752007-05-01 21:15:47 +000058 private:
Chris Lattnerafade922002-11-20 22:28:10 +000059 bool runOnBasicBlock(BasicBlock &BB) {
60 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
Chris Lattner6e96a99c2003-04-23 16:38:00 +000061 if (CallInst *CI = dyn_cast<CallInst>(I)) {
Chris Lattnerafade922002-11-20 22:28:10 +000062 if (!CI->use_empty())
63 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
64 CI->getParent()->getInstList().erase(CI);
Chris Lattner9d5968d2004-03-17 17:29:08 +000065 break;
Chris Lattnerafade922002-11-20 22:28:10 +000066 }
67 return false;
68 }
69 };
Devang Patel794fd752007-05-01 21:15:47 +000070
Devang Patel19974732007-05-03 01:11:54 +000071 char DeleteCalls::ID = 0;
Chris Lattnerafade922002-11-20 22:28:10 +000072 RegisterPass<DeleteCalls>
73 Y("bugpoint-deletecalls",
74 "BugPoint Test Pass - Intentionally 'misoptimize' CallInsts");
75}