blob: 1535b0388561364fa30e3a5873454ca80caa4a91 [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
Owen Anderson90c579d2010-08-06 18:33:48 +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 };
Dan Gohmana2a3bbc2010-08-20 00:56:16 +000044}
Chris Lattnerafade922002-11-20 22:28:10 +000045
Dan Gohmana2a3bbc2010-08-20 00:56:16 +000046char CrashOnCalls::ID = 0;
47static RegisterPass<CrashOnCalls>
Chris Lattnerafade922002-11-20 22:28:10 +000048 X("bugpoint-crashcalls",
49 "BugPoint Test Pass - Intentionally crash on CallInsts");
Chris Lattnerafade922002-11-20 22:28:10 +000050
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
Owen Anderson90c579d2010-08-06 18:33:48 +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())
Owen Andersona7235ea2009-07-31 20:28:14 +000063 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
Chris Lattnerafade922002-11-20 22:28:10 +000064 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 };
Dan Gohmana2a3bbc2010-08-20 00:56:16 +000070}
Devang Patel794fd752007-05-01 21:15:47 +000071
Dan Gohmana2a3bbc2010-08-20 00:56:16 +000072char DeleteCalls::ID = 0;
73static RegisterPass<DeleteCalls>
Chris Lattnerafade922002-11-20 22:28:10 +000074 Y("bugpoint-deletecalls",
75 "BugPoint Test Pass - Intentionally 'misoptimize' CallInsts");