blob: 1535b0388561364fa30e3a5873454ca80caa4a91 [file] [log] [blame]
Chris Lattner73a6bdd2002-11-20 22:28:10 +00001//===- TestPasses.cpp - "buggy" passes used to test bugpoint --------------===//
Misha Brukman650ba8e2005-04-22 00:00:37 +00002//
John Criswell09344dc2003-10-20 17:47:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner345353d2007-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 Brukman650ba8e2005-04-22 00:00:37 +00007//
John Criswell09344dc2003-10-20 17:47:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner73a6bdd2002-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 Lattner73a6bdd2002-11-20 22:28:10 +000015#include "llvm/BasicBlock.h"
Misha Brukman0c2305b2003-08-07 21:19:30 +000016#include "llvm/Constant.h"
Misha Brukman63b38bd2004-07-29 17:30:56 +000017#include "llvm/Instructions.h"
Misha Brukman0c2305b2003-08-07 21:19:30 +000018#include "llvm/Pass.h"
Chris Lattner7b9020a2005-03-17 15:38:16 +000019#include "llvm/Type.h"
Misha Brukman0c2305b2003-08-07 21:19:30 +000020#include "llvm/Support/InstVisitor.h"
Chris Lattner73a6bdd2002-11-20 22:28:10 +000021
Brian Gaeke960707c2003-11-11 22:41:34 +000022using namespace llvm;
23
Chris Lattner73a6bdd2002-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 Patel09f162c2007-05-01 21:15:47 +000028 public:
Devang Patel8c78a0b2007-05-03 01:11:54 +000029 static char ID; // Pass ID, replacement for typeid
Owen Andersona7aed182010-08-06 18:33:48 +000030 CrashOnCalls() : BasicBlockPass(ID) {}
Devang Patel09f162c2007-05-01 21:15:47 +000031 private:
Chris Lattner73a6bdd2002-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 Gohman12bb5052010-08-20 00:56:16 +000044}
Chris Lattner73a6bdd2002-11-20 22:28:10 +000045
Dan Gohman12bb5052010-08-20 00:56:16 +000046char CrashOnCalls::ID = 0;
47static RegisterPass<CrashOnCalls>
Chris Lattner73a6bdd2002-11-20 22:28:10 +000048 X("bugpoint-crashcalls",
49 "BugPoint Test Pass - Intentionally crash on CallInsts");
Chris Lattner73a6bdd2002-11-20 22:28:10 +000050
51namespace {
52 /// DeleteCalls - This pass is used to test bugpoint. It intentionally
Chris Lattner425726d2004-03-17 17:29:08 +000053 /// deletes some call instructions, "misoptimizing" the program.
Chris Lattner73a6bdd2002-11-20 22:28:10 +000054 class DeleteCalls : public BasicBlockPass {
Devang Patel09f162c2007-05-01 21:15:47 +000055 public:
Devang Patel8c78a0b2007-05-03 01:11:54 +000056 static char ID; // Pass ID, replacement for typeid
Owen Andersona7aed182010-08-06 18:33:48 +000057 DeleteCalls() : BasicBlockPass(ID) {}
Devang Patel09f162c2007-05-01 21:15:47 +000058 private:
Chris Lattner73a6bdd2002-11-20 22:28:10 +000059 bool runOnBasicBlock(BasicBlock &BB) {
60 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
Chris Lattnere695da32003-04-23 16:38:00 +000061 if (CallInst *CI = dyn_cast<CallInst>(I)) {
Chris Lattner73a6bdd2002-11-20 22:28:10 +000062 if (!CI->use_empty())
Owen Anderson5a1acd92009-07-31 20:28:14 +000063 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
Chris Lattner73a6bdd2002-11-20 22:28:10 +000064 CI->getParent()->getInstList().erase(CI);
Chris Lattner425726d2004-03-17 17:29:08 +000065 break;
Chris Lattner73a6bdd2002-11-20 22:28:10 +000066 }
67 return false;
68 }
69 };
Dan Gohman12bb5052010-08-20 00:56:16 +000070}
Devang Patel09f162c2007-05-01 21:15:47 +000071
Dan Gohman12bb5052010-08-20 00:56:16 +000072char DeleteCalls::ID = 0;
73static RegisterPass<DeleteCalls>
Chris Lattner73a6bdd2002-11-20 22:28:10 +000074 Y("bugpoint-deletecalls",
75 "BugPoint Test Pass - Intentionally 'misoptimize' CallInsts");