BugDriver.h revision 9686ae7f4ea5f19ce77e31e64e0916db41a82662
1afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner//===- BugDriver.h - Top-Level BugPoint class -------------------*- C++ -*-===// 23da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman// 37c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell// The LLVM Compiler Infrastructure 47c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell// 57c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell// This file was developed by the LLVM research group and is distributed under 67c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell// the University of Illinois Open Source License. See LICENSE.TXT for details. 73da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman// 87c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell//===----------------------------------------------------------------------===// 9afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner// 10afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner// This class contains all of the shared state and information that is used by 11afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner// the BugPoint tool to track down errors in optimizations. This class is the 12afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner// main driver class that invokes all sub-functionality. 13afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner// 14afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner//===----------------------------------------------------------------------===// 15afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 16afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#ifndef BUGDRIVER_H 17afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#define BUGDRIVER_H 18afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 19afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#include <vector> 20afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#include <string> 215073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman 22d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 23d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 24afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerclass PassInfo; 25afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerclass Module; 26afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerclass Function; 275e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattnerclass BasicBlock; 28218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattnerclass AbstractInterpreter; 296520785dcd22012535934098942d57c07c7631c2Chris Lattnerclass Instruction; 30afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 31aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattnerclass DebugCrashes; 32640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 33a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukmanclass CBE; 34a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukmanclass GCC; 35a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman 3647ae4a1cee5eec5767a11403c0fac7c91ec45461Chris Lattnerextern bool DisableSimplifyCFG; 3747ae4a1cee5eec5767a11403c0fac7c91ec45461Chris Lattner 38f9aaae06cd2109082cda2b09ef3f23e0e1cff47bChris Lattner/// BugpointIsInterrupted - Set to true when the user presses ctrl-c. 39f9aaae06cd2109082cda2b09ef3f23e0e1cff47bChris Lattner/// 40f9aaae06cd2109082cda2b09ef3f23e0e1cff47bChris Lattnerextern bool BugpointIsInterrupted; 41f9aaae06cd2109082cda2b09ef3f23e0e1cff47bChris Lattner 42afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerclass BugDriver { 43afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner const std::string ToolName; // Name of bugpoint 44a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman std::string ReferenceOutputFile; // Name of `good' output file 45afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner Module *Program; // The raw program, linked together 46afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner std::vector<const PassInfo*> PassesToRun; 47218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner AbstractInterpreter *Interpreter; // How to run the program 48a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman CBE *cbe; 49a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman GCC *gcc; 50c4bb052ecccfafa0ffa928d0b061db35734ee2eeReid Spencer bool run_as_child; 519686ae7f4ea5f19ce77e31e64e0916db41a82662Chris Lattner unsigned Timeout; 52640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 53aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner // FIXME: sort out public/private distinctions... 5406905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner friend class ReducePassList; 555073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman friend class ReduceMisCodegenFunctions; 565073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman 57afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerpublic: 589686ae7f4ea5f19ce77e31e64e0916db41a82662Chris Lattner BugDriver(const char *toolname, bool as_child, unsigned timeout); 59218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner 60218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner const std::string &getToolName() const { return ToolName; } 61afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 62afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner // Set up methods... these methods are used to copy information about the 63afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner // command line arguments into instance variables of BugDriver. 64afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner // 65afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner bool addSources(const std::vector<std::string> &FileNames); 66afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner template<class It> 67afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner void addPasses(It I, It E) { PassesToRun.insert(PassesToRun.end(), I, E); } 689c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner void setPassesToRun(const std::vector<const PassInfo*> &PTR) { 699c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner PassesToRun = PTR; 709c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner } 71efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner const std::vector<const PassInfo*> &getPassesToRun() const { 72efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner return PassesToRun; 73efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner } 74afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 75afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// run - The top level method that is invoked after all of the instance 76c4bb052ecccfafa0ffa928d0b061db35734ee2eeReid Spencer /// variables are set up from command line arguments. The \p as_child argument 77c4bb052ecccfafa0ffa928d0b061db35734ee2eeReid Spencer /// indicates whether the driver is to run in parent mode or child mode. 78afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// 79afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner bool run(); 80afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 81025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// debugOptimizerCrash - This method is called when some optimizer pass 82025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// crashes on input. It attempts to prune down the testcase to something 83025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// reasonable, and figure out exactly which pass is crashing. 84afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// 85025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner bool debugOptimizerCrash(); 863da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman 87025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// debugCodeGeneratorCrash - This method is called when the code generator 88025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// crashes on an input. It attempts to reduce the input as much as possible 89025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// while still causing the code generator to crash. 90025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner bool debugCodeGeneratorCrash(); 91afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 92afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// debugMiscompilation - This method is used when the passes selected are not 93afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// crashing, but the generated output is semantically different from the 94afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// input. 95afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner bool debugMiscompilation(); 96afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 97218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// debugPassMiscompilation - This method is called when the specified pass 98218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// miscompiles Program as input. It tries to reduce the testcase to 99218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// something that smaller that still miscompiles the program. 100218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// ReferenceOutput contains the filename of the file containing the output we 101218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// are to match. 102218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// 103218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner bool debugPassMiscompilation(const PassInfo *ThePass, 104ea3e5e56fdc56e5c2ddafb36eab26676e137dfa0Jeff Cohen const std::string &ReferenceOutput); 105218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner 1065073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman /// compileSharedObject - This method creates a SharedObject from a given 1075073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman /// BytecodeFile for debugging a code generator. 108a0f5b15e1eb8642d92b3141a6b88a5729ea979dcChris Lattner /// 109a0f5b15e1eb8642d92b3141a6b88a5729ea979dcChris Lattner std::string compileSharedObject(const std::string &BytecodeFile); 1105073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman 1115073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman /// debugCodeGenerator - This method narrows down a module to a function or 1125073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman /// set of functions, using the CBE as a ``safe'' code generator for other 1135073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman /// functions that are not under consideration. 1145073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman bool debugCodeGenerator(); 1155073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman 116fe04db890b87d9ac4c4a607e6bd0035e8cc2ad6cMisha Brukman /// isExecutingJIT - Returns true if bugpoint is currently testing the JIT 117fe04db890b87d9ac4c4a607e6bd0035e8cc2ad6cMisha Brukman /// 11891eabc13d3a456cc4b387d3d7fdb041d976732c7Misha Brukman bool isExecutingJIT(); 11991eabc13d3a456cc4b387d3d7fdb041d976732c7Misha Brukman 12006905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner /// runPasses - Run all of the passes in the "PassesToRun" list, discard the 12106905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner /// output, and return true if any of the passes crashed. 12206905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner bool runPasses(Module *M = 0) { 12306905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner if (M == 0) M = Program; 12406905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner std::swap(M, Program); 12506905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner bool Result = runPasses(PassesToRun); 12606905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner std::swap(M, Program); 12706905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner return Result; 12806905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner } 12906905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner 130efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *getProgram() const { return Program; } 131efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 132efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner /// swapProgramIn - Set the current module to the specified module, returning 133efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner /// the old one. 134efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *swapProgramIn(Module *M) { 135efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *OldProgram = Program; 136efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Program = M; 137efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner return OldProgram; 138efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner } 13906905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner 140a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner AbstractInterpreter *switchToCBE() { 141a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner AbstractInterpreter *Old = Interpreter; 142a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner Interpreter = (AbstractInterpreter*)cbe; 143a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner return Old; 144a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 145a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 146a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner void switchToInterpreter(AbstractInterpreter *AI) { 147a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner Interpreter = AI; 148a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 1493da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman 15006905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner /// setNewProgram - If we reduce or update the program somehow, call this 15106905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner /// method to update bugdriver with it. This deletes the old module and sets 15206905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner /// the specified one as the current program. 15306905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner void setNewProgram(Module *M); 15406905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner 155ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner /// compileProgram - Try to compile the specified module, throwing an 156ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner /// exception if an error occurs, or returning normally if not. This is used 157ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner /// for code generation crash testing. 158ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner /// 159ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner void compileProgram(Module *M); 160ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner 161a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// executeProgram - This method runs "Program", capturing the output of the 162a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// program to a file, returning the filename of the file. A recommended 163a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// filename may be optionally specified. If there is a problem with the code 164a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// generator (e.g., llc crashes), this will throw an exception. 165a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// 166a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner std::string executeProgram(std::string RequestedOutputFilename = "", 167a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner std::string Bytecode = "", 168a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner const std::string &SharedObjects = "", 169a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner AbstractInterpreter *AI = 0, 170a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner bool *ProgramExitedNonzero = 0); 171a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner 172a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// executeProgramWithCBE - Used to create reference output with the C 173a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// backend, if reference output is not provided. If there is a problem with 174a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// the code generator (e.g., llc crashes), this will throw an exception. 175a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// 176a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner std::string executeProgramWithCBE(std::string OutputFile = ""); 177a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner 178a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// diffProgram - This method executes the specified module and diffs the 179a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// output against the file specified by ReferenceOutputFile. If the output 180a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// is different, true is returned. If there is a problem with the code 181a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// generator (e.g., llc crashes), this will throw an exception. 182a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// 183a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner bool diffProgram(const std::string &BytecodeFile = "", 184a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner const std::string &SharedObj = "", 185a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner bool RemoveBytecode = false); 1860cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// EmitProgressBytecode - This function is used to output the current Program 1870cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// to a file named "bugpoint-ID.bc". 1880cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// 1890cc8807029f577996a442b96d24c3346ed6de091Chris Lattner void EmitProgressBytecode(const std::string &ID, bool NoFlyer = false); 1900cc8807029f577996a442b96d24c3346ed6de091Chris Lattner 1910cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// deleteInstructionFromProgram - This method clones the current Program and 1920cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// deletes the specified instruction from the cloned module. It then runs a 1930cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code 1940cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// which depends on the value. The modified module is then returned. 1950cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// 1960cc8807029f577996a442b96d24c3346ed6de091Chris Lattner Module *deleteInstructionFromProgram(const Instruction *I, unsigned Simp) 1970cc8807029f577996a442b96d24c3346ed6de091Chris Lattner const; 1980cc8807029f577996a442b96d24c3346ed6de091Chris Lattner 1990cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// performFinalCleanups - This method clones the current Program and performs 2000cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// a series of cleanups intended to get rid of extra cruft on the module. If 2010cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// the MayModifySemantics argument is true, then the cleanups is allowed to 2020cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// modify how the code behaves. 2030cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// 2040cc8807029f577996a442b96d24c3346ed6de091Chris Lattner Module *performFinalCleanups(Module *M, bool MayModifySemantics = false); 2050cc8807029f577996a442b96d24c3346ed6de091Chris Lattner 2067546c3884a400b72d10fc19f120c6798b294a39dChris Lattner /// ExtractLoop - Given a module, extract up to one loop from it into a new 2077546c3884a400b72d10fc19f120c6798b294a39dChris Lattner /// function. This returns null if there are no extractable loops in the 2087546c3884a400b72d10fc19f120c6798b294a39dChris Lattner /// program or if the loop extractor crashes. 2097546c3884a400b72d10fc19f120c6798b294a39dChris Lattner Module *ExtractLoop(Module *M); 2107546c3884a400b72d10fc19f120c6798b294a39dChris Lattner 2115e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner /// ExtractMappedBlocksFromModule - Extract all but the specified basic blocks 2125e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner /// into their own functions. The only detail is that M is actually a module 2135e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner /// cloned from the one the BBs are in, so some mapping needs to be performed. 2145e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner /// If this operation fails for some reason (ie the implementation is buggy), 2155e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner /// this function should return null, otherwise it returns a new Module. 2165e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner Module *ExtractMappedBlocksFromModule(const std::vector<BasicBlock*> &BBs, 2175e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner Module *M); 2185e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 2193b6441e1050a9a2a55c79f58513191b3195fdaf7Chris Lattner /// runPassesOn - Carefully run the specified set of pass on the specified 2203b6441e1050a9a2a55c79f58513191b3195fdaf7Chris Lattner /// module, returning the transformed module on success, or a null pointer on 2210a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner /// failure. If AutoDebugCrashes is set to true, then bugpoint will 2220a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner /// automatically attempt to track down a crashing pass if one exists, and 2230a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner /// this method will never return null. 2240a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner Module *runPassesOn(Module *M, const std::vector<const PassInfo*> &Passes, 2250a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner bool AutoDebugCrashes = false); 2263b6441e1050a9a2a55c79f58513191b3195fdaf7Chris Lattner 227afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// runPasses - Run the specified passes on Program, outputting a bytecode 228afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// file and writting the filename into OutputFile if successful. If the 229afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// optimizations fail for some reason (optimizer crashes), return true, 230afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// otherwise return false. If DeleteOutput is set to true, the bytecode is 231afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// deleted on success, and the filename string is undefined. This prints to 232afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// cout a single line message indicating whether compilation was successful 233218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// or failed, unless Quiet is set. 234afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// 235afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner bool runPasses(const std::vector<const PassInfo*> &PassesToRun, 236218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner std::string &OutputFilename, bool DeleteOutput = false, 237ea3e5e56fdc56e5c2ddafb36eab26676e137dfa0Jeff Cohen bool Quiet = false) const; 23811b8cd197a740bc9af2f27cb88d535c4be2cdd0eChris Lattner 239efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner /// writeProgramToFile - This writes the current "Program" to the named 240efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner /// bytecode file. If an error occurs, true is returned. 241efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner /// 242efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner bool writeProgramToFile(const std::string &Filename, Module *M = 0) const; 243afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 24411b8cd197a740bc9af2f27cb88d535c4be2cdd0eChris Lattnerprivate: 245afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// runPasses - Just like the method above, but this just returns true or 246afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// false indicating whether or not the optimizer crashed on the specified 247afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// input (true = crashed). 248afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// 249afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner bool runPasses(const std::vector<const PassInfo*> &PassesToRun, 250afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner bool DeleteOutput = true) const { 251afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner std::string Filename; 252afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner return runPasses(PassesToRun, Filename, DeleteOutput); 253afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner } 254afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 255c4bb052ecccfafa0ffa928d0b061db35734ee2eeReid Spencer /// runAsChild - The actual "runPasses" guts that runs in a child process. 256c4bb052ecccfafa0ffa928d0b061db35734ee2eeReid Spencer int runPassesAsChild(const std::vector<const PassInfo*> &PassesToRun); 257c4bb052ecccfafa0ffa928d0b061db35734ee2eeReid Spencer 258218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// initializeExecutionEnvironment - This method is used to set up the 259218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// environment for executing LLVM programs. 260218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// 261218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner bool initializeExecutionEnvironment(); 262afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner}; 263afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 264efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// ParseInputFile - Given a bytecode or assembly input filename, parse and 265efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// return it, or return null if not possible. 266efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// 267efdc0b505712d1ca4460def27e51c430f033d58dChris LattnerModule *ParseInputFile(const std::string &InputFilename); 268efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 269efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 270640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner/// getPassesString - Turn a list of passes into a string which indicates the 271640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner/// command line options that must be passed to add the passes. 272640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner/// 273640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattnerstd::string getPassesString(const std::vector<const PassInfo*> &Passes); 274640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 275efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// PrintFunctionList - prints out list of problematic functions 276efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// 277efdc0b505712d1ca4460def27e51c430f033d58dChris Lattnervoid PrintFunctionList(const std::vector<Function*> &Funcs); 278efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 279aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner// DeleteFunctionBody - "Remove" the function by deleting all of it's basic 280aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner// blocks, making it external. 281aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner// 282aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattnervoid DeleteFunctionBody(Function *F); 283aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner 284be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// SplitFunctionsOutOfModule - Given a module and a list of functions in the 285be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// module, split the functions OUT of the specified module, and place them in 286be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// the new module. 287be21ca54e08339ede5dd4bbb882182d22e274988Chris LattnerModule *SplitFunctionsOutOfModule(Module *M, const std::vector<Function*> &F); 288be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner 289d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 290d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 291afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#endif 292