BugDriver.h revision 4434ed44c45c87a72b7a0bf2f91211f895022b91
1afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner//===- BugDriver.h - Top-Level BugPoint class -------------------*- C++ -*-===// 23da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman// 37c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell// The LLVM Compiler Infrastructure 47c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell// 521c62da287237d39d0d95004881ea4baae3be6daChris Lattner// This file is distributed under the University of Illinois Open Source 621c62da287237d39d0d95004881ea4baae3be6daChris Lattner// 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 19d50330cd02b00c8e3de40e8544c45701b9891d87Dan Gohman#include "llvm/ADT/DenseMap.h" 20afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#include <vector> 21afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#include <string> 225073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman 23d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 24d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 25d50330cd02b00c8e3de40e8544c45701b9891d87Dan Gohmanclass Value; 26afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerclass PassInfo; 27afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerclass Module; 284e3be89cb5cde6e2df294c64db3bc28133b67594Bill Wendlingclass GlobalVariable; 29afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerclass Function; 305e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattnerclass BasicBlock; 31218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattnerclass AbstractInterpreter; 326520785dcd22012535934098942d57c07c7631c2Chris Lattnerclass Instruction; 338b477ed579794ba6d76915d56b3f448a7dd20120Owen Andersonclass LLVMContext; 34afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 35aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattnerclass DebugCrashes; 36640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 37a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukmanclass GCC; 38a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman 3947ae4a1cee5eec5767a11403c0fac7c91ec45461Chris Lattnerextern bool DisableSimplifyCFG; 4047ae4a1cee5eec5767a11403c0fac7c91ec45461Chris Lattner 41f9aaae06cd2109082cda2b09ef3f23e0e1cff47bChris Lattner/// BugpointIsInterrupted - Set to true when the user presses ctrl-c. 42f9aaae06cd2109082cda2b09ef3f23e0e1cff47bChris Lattner/// 43f9aaae06cd2109082cda2b09ef3f23e0e1cff47bChris Lattnerextern bool BugpointIsInterrupted; 44f9aaae06cd2109082cda2b09ef3f23e0e1cff47bChris Lattner 45afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerclass BugDriver { 464434ed44c45c87a72b7a0bf2f91211f895022b91Owen Anderson LLVMContext& Context; 47afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner const std::string ToolName; // Name of bugpoint 48a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman std::string ReferenceOutputFile; // Name of `good' output file 49afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner Module *Program; // The raw program, linked together 50afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner std::vector<const PassInfo*> PassesToRun; 51218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner AbstractInterpreter *Interpreter; // How to run the program 5270ef449741da8b1ef035e04a55958652a0200ba1Dan Gohman AbstractInterpreter *SafeInterpreter; // To generate reference output, etc. 53a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman GCC *gcc; 54c4bb052ecccfafa0ffa928d0b061db35734ee2eeReid Spencer bool run_as_child; 556a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins bool run_find_bugs; 569686ae7f4ea5f19ce77e31e64e0916db41a82662Chris Lattner unsigned Timeout; 579ba8a76f8baaa1092d60ccfbc04e7efdc207c98fAnton Korobeynikov unsigned MemoryLimit; 58640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 59aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner // FIXME: sort out public/private distinctions... 6006905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner friend class ReducePassList; 615073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman friend class ReduceMisCodegenFunctions; 625073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman 63afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerpublic: 646a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins BugDriver(const char *toolname, bool as_child, bool find_bugs, 654434ed44c45c87a72b7a0bf2f91211f895022b91Owen Anderson unsigned timeout, unsigned memlimit, LLVMContext& ctxt); 66218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner 67218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner const std::string &getToolName() const { return ToolName; } 68afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 694434ed44c45c87a72b7a0bf2f91211f895022b91Owen Anderson LLVMContext& getContext() { return Context; } 708b477ed579794ba6d76915d56b3f448a7dd20120Owen Anderson 71afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner // Set up methods... these methods are used to copy information about the 72afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner // command line arguments into instance variables of BugDriver. 73afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner // 74afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner bool addSources(const std::vector<std::string> &FileNames); 75afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner template<class It> 76afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner void addPasses(It I, It E) { PassesToRun.insert(PassesToRun.end(), I, E); } 779c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner void setPassesToRun(const std::vector<const PassInfo*> &PTR) { 789c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner PassesToRun = PTR; 799c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner } 80efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner const std::vector<const PassInfo*> &getPassesToRun() const { 81efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner return PassesToRun; 82efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner } 83afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 84afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// run - The top level method that is invoked after all of the instance 85c4bb052ecccfafa0ffa928d0b061db35734ee2eeReid Spencer /// variables are set up from command line arguments. The \p as_child argument 86c4bb052ecccfafa0ffa928d0b061db35734ee2eeReid Spencer /// indicates whether the driver is to run in parent mode or child mode. 87afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// 88afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner bool run(); 89afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 90025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// debugOptimizerCrash - This method is called when some optimizer pass 91025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// crashes on input. It attempts to prune down the testcase to something 92025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// reasonable, and figure out exactly which pass is crashing. 93afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// 946a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins bool debugOptimizerCrash(const std::string &ID = "passes"); 953da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman 96025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// debugCodeGeneratorCrash - This method is called when the code generator 97025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// crashes on an input. It attempts to reduce the input as much as possible 98025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// while still causing the code generator to crash. 99025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner bool debugCodeGeneratorCrash(); 100afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 101afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// debugMiscompilation - This method is used when the passes selected are not 102afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// crashing, but the generated output is semantically different from the 103afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// input. 104afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner bool debugMiscompilation(); 105afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 106218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// debugPassMiscompilation - This method is called when the specified pass 107218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// miscompiles Program as input. It tries to reduce the testcase to 108218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// something that smaller that still miscompiles the program. 109218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// ReferenceOutput contains the filename of the file containing the output we 110218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// are to match. 111218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// 112218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner bool debugPassMiscompilation(const PassInfo *ThePass, 113ea3e5e56fdc56e5c2ddafb36eab26676e137dfa0Jeff Cohen const std::string &ReferenceOutput); 114218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner 1155073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman /// compileSharedObject - This method creates a SharedObject from a given 1168ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif /// BitcodeFile for debugging a code generator. 117a0f5b15e1eb8642d92b3141a6b88a5729ea979dcChris Lattner /// 1188ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif std::string compileSharedObject(const std::string &BitcodeFile); 1195073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman 1205073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman /// debugCodeGenerator - This method narrows down a module to a function or 1215073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman /// set of functions, using the CBE as a ``safe'' code generator for other 1225073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman /// functions that are not under consideration. 1235073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman bool debugCodeGenerator(); 1245073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman 125fe04db890b87d9ac4c4a607e6bd0035e8cc2ad6cMisha Brukman /// isExecutingJIT - Returns true if bugpoint is currently testing the JIT 126fe04db890b87d9ac4c4a607e6bd0035e8cc2ad6cMisha Brukman /// 12791eabc13d3a456cc4b387d3d7fdb041d976732c7Misha Brukman bool isExecutingJIT(); 12891eabc13d3a456cc4b387d3d7fdb041d976732c7Misha Brukman 12906905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner /// runPasses - Run all of the passes in the "PassesToRun" list, discard the 13006905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner /// output, and return true if any of the passes crashed. 13106905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner bool runPasses(Module *M = 0) { 13206905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner if (M == 0) M = Program; 13306905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner std::swap(M, Program); 13406905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner bool Result = runPasses(PassesToRun); 13506905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner std::swap(M, Program); 13606905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner return Result; 13706905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner } 13806905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner 139efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *getProgram() const { return Program; } 140efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 141efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner /// swapProgramIn - Set the current module to the specified module, returning 142efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner /// the old one. 143efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *swapProgramIn(Module *M) { 144efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *OldProgram = Program; 145efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Program = M; 146efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner return OldProgram; 147efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner } 14806905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner 14970ef449741da8b1ef035e04a55958652a0200ba1Dan Gohman AbstractInterpreter *switchToSafeInterpreter() { 150a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner AbstractInterpreter *Old = Interpreter; 15170ef449741da8b1ef035e04a55958652a0200ba1Dan Gohman Interpreter = (AbstractInterpreter*)SafeInterpreter; 152a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner return Old; 153a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 154a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 155a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner void switchToInterpreter(AbstractInterpreter *AI) { 156a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner Interpreter = AI; 157a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 1583da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman 15906905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner /// setNewProgram - If we reduce or update the program somehow, call this 16006905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner /// method to update bugdriver with it. This deletes the old module and sets 16106905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner /// the specified one as the current program. 16206905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner void setNewProgram(Module *M); 16306905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner 164ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner /// compileProgram - Try to compile the specified module, throwing an 165ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner /// exception if an error occurs, or returning normally if not. This is used 166ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner /// for code generation crash testing. 167ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner /// 168ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner void compileProgram(Module *M); 169ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner 170a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// executeProgram - This method runs "Program", capturing the output of the 171a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// program to a file, returning the filename of the file. A recommended 172a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// filename may be optionally specified. If there is a problem with the code 173a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// generator (e.g., llc crashes), this will throw an exception. 174a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// 175a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner std::string executeProgram(std::string RequestedOutputFilename = "", 1768ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif std::string Bitcode = "", 177a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner const std::string &SharedObjects = "", 178a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner AbstractInterpreter *AI = 0, 179a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner bool *ProgramExitedNonzero = 0); 180a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner 18170ef449741da8b1ef035e04a55958652a0200ba1Dan Gohman /// executeProgramSafely - Used to create reference output with the "safe" 182a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// backend, if reference output is not provided. If there is a problem with 183a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// the code generator (e.g., llc crashes), this will throw an exception. 184a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// 18570ef449741da8b1ef035e04a55958652a0200ba1Dan Gohman std::string executeProgramSafely(std::string OutputFile = ""); 186a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner 1876a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// createReferenceFile - calls compileProgram and then records the output 1886a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// into ReferenceOutputFile. Returns true if reference file created, false 1896a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// otherwise. Note: initializeExecutionEnvironment should be called BEFORE 1906a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// this function. 1916a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// 192c0431fe1ca52c5d159c604957f337aa3eb1ec3d3Chris Lattner bool createReferenceFile(Module *M, const std::string &Filename 193c0431fe1ca52c5d159c604957f337aa3eb1ec3d3Chris Lattner = "bugpoint.reference.out"); 1946a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins 195a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// diffProgram - This method executes the specified module and diffs the 196a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// output against the file specified by ReferenceOutputFile. If the output 197a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// is different, true is returned. If there is a problem with the code 198a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// generator (e.g., llc crashes), this will throw an exception. 199a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// 2008ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif bool diffProgram(const std::string &BitcodeFile = "", 201a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner const std::string &SharedObj = "", 2028ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif bool RemoveBitcode = false); 2036a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins 2048ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif /// EmitProgressBitcode - This function is used to output the current Program 2050cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// to a file named "bugpoint-ID.bc". 2060cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// 2078ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif void EmitProgressBitcode(const std::string &ID, bool NoFlyer = false); 2080cc8807029f577996a442b96d24c3346ed6de091Chris Lattner 2090cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// deleteInstructionFromProgram - This method clones the current Program and 2100cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// deletes the specified instruction from the cloned module. It then runs a 2110cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code 2120cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// which depends on the value. The modified module is then returned. 2130cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// 2140cc8807029f577996a442b96d24c3346ed6de091Chris Lattner Module *deleteInstructionFromProgram(const Instruction *I, unsigned Simp) 2150cc8807029f577996a442b96d24c3346ed6de091Chris Lattner const; 2160cc8807029f577996a442b96d24c3346ed6de091Chris Lattner 2170cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// performFinalCleanups - This method clones the current Program and performs 2180cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// a series of cleanups intended to get rid of extra cruft on the module. If 2190cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// the MayModifySemantics argument is true, then the cleanups is allowed to 2200cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// modify how the code behaves. 2210cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// 2220cc8807029f577996a442b96d24c3346ed6de091Chris Lattner Module *performFinalCleanups(Module *M, bool MayModifySemantics = false); 2230cc8807029f577996a442b96d24c3346ed6de091Chris Lattner 2247546c3884a400b72d10fc19f120c6798b294a39dChris Lattner /// ExtractLoop - Given a module, extract up to one loop from it into a new 2257546c3884a400b72d10fc19f120c6798b294a39dChris Lattner /// function. This returns null if there are no extractable loops in the 2267546c3884a400b72d10fc19f120c6798b294a39dChris Lattner /// program or if the loop extractor crashes. 2277546c3884a400b72d10fc19f120c6798b294a39dChris Lattner Module *ExtractLoop(Module *M); 2287546c3884a400b72d10fc19f120c6798b294a39dChris Lattner 2295e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner /// ExtractMappedBlocksFromModule - Extract all but the specified basic blocks 2305e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner /// into their own functions. The only detail is that M is actually a module 2315e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner /// cloned from the one the BBs are in, so some mapping needs to be performed. 2325e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner /// If this operation fails for some reason (ie the implementation is buggy), 2335e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner /// this function should return null, otherwise it returns a new Module. 2345e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner Module *ExtractMappedBlocksFromModule(const std::vector<BasicBlock*> &BBs, 2355e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner Module *M); 2365e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 2373b6441e1050a9a2a55c79f58513191b3195fdaf7Chris Lattner /// runPassesOn - Carefully run the specified set of pass on the specified 2383b6441e1050a9a2a55c79f58513191b3195fdaf7Chris Lattner /// module, returning the transformed module on success, or a null pointer on 2390a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner /// failure. If AutoDebugCrashes is set to true, then bugpoint will 2400a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner /// automatically attempt to track down a crashing pass if one exists, and 2410a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner /// this method will never return null. 2420a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner Module *runPassesOn(Module *M, const std::vector<const PassInfo*> &Passes, 2436fa98b13206583e6eb90b8304758b35548914944Nick Lewycky bool AutoDebugCrashes = false, unsigned NumExtraArgs = 0, 2446fa98b13206583e6eb90b8304758b35548914944Nick Lewycky const char * const *ExtraArgs = NULL); 2453b6441e1050a9a2a55c79f58513191b3195fdaf7Chris Lattner 2468ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif /// runPasses - Run the specified passes on Program, outputting a bitcode 247afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// file and writting the filename into OutputFile if successful. If the 248afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// optimizations fail for some reason (optimizer crashes), return true, 2498ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif /// otherwise return false. If DeleteOutput is set to true, the bitcode is 250afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// deleted on success, and the filename string is undefined. This prints to 251afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// cout a single line message indicating whether compilation was successful 2526fa98b13206583e6eb90b8304758b35548914944Nick Lewycky /// or failed, unless Quiet is set. ExtraArgs specifies additional arguments 2536fa98b13206583e6eb90b8304758b35548914944Nick Lewycky /// to pass to the child bugpoint instance. 254afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// 255afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner bool runPasses(const std::vector<const PassInfo*> &PassesToRun, 256218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner std::string &OutputFilename, bool DeleteOutput = false, 2576fa98b13206583e6eb90b8304758b35548914944Nick Lewycky bool Quiet = false, unsigned NumExtraArgs = 0, 2586fa98b13206583e6eb90b8304758b35548914944Nick Lewycky const char * const *ExtraArgs = NULL) const; 2596a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins 2606a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// runManyPasses - Take the specified pass list and create different 2616a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// combinations of passes to compile the program with. Compile the program with 2626a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// each set and mark test to see if it compiled correctly. If the passes 2636a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// compiled correctly output nothing and rearrange the passes into a new order. 2646a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// If the passes did not compile correctly, output the command required to 2656a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// recreate the failure. This returns true if a compiler error is found. 2666a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// 2676a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins bool runManyPasses(const std::vector<const PassInfo*> &AllPasses); 26811b8cd197a740bc9af2f27cb88d535c4be2cdd0eChris Lattner 269efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner /// writeProgramToFile - This writes the current "Program" to the named 2708ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif /// bitcode file. If an error occurs, true is returned. 271efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner /// 272efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner bool writeProgramToFile(const std::string &Filename, Module *M = 0) const; 273afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 27411b8cd197a740bc9af2f27cb88d535c4be2cdd0eChris Lattnerprivate: 275afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// runPasses - Just like the method above, but this just returns true or 276afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// false indicating whether or not the optimizer crashed on the specified 277afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// input (true = crashed). 278afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// 279afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner bool runPasses(const std::vector<const PassInfo*> &PassesToRun, 280afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner bool DeleteOutput = true) const { 281afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner std::string Filename; 282afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner return runPasses(PassesToRun, Filename, DeleteOutput); 283afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner } 284afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 285c4bb052ecccfafa0ffa928d0b061db35734ee2eeReid Spencer /// runAsChild - The actual "runPasses" guts that runs in a child process. 286c4bb052ecccfafa0ffa928d0b061db35734ee2eeReid Spencer int runPassesAsChild(const std::vector<const PassInfo*> &PassesToRun); 287c4bb052ecccfafa0ffa928d0b061db35734ee2eeReid Spencer 288218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// initializeExecutionEnvironment - This method is used to set up the 289218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// environment for executing LLVM programs. 290218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// 291218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner bool initializeExecutionEnvironment(); 292afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner}; 293afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 2948ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif/// ParseInputFile - Given a bitcode or assembly input filename, parse and 295efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// return it, or return null if not possible. 296efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// 29731895e73591d3c9ceae731a1274c8f56194b9616Owen AndersonModule *ParseInputFile(const std::string &InputFilename, 2984434ed44c45c87a72b7a0bf2f91211f895022b91Owen Anderson LLVMContext& ctxt); 299efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 300efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 301640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner/// getPassesString - Turn a list of passes into a string which indicates the 302640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner/// command line options that must be passed to add the passes. 303640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner/// 304640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattnerstd::string getPassesString(const std::vector<const PassInfo*> &Passes); 305640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 306efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// PrintFunctionList - prints out list of problematic functions 307efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// 308efdc0b505712d1ca4460def27e51c430f033d58dChris Lattnervoid PrintFunctionList(const std::vector<Function*> &Funcs); 309efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 3104e3be89cb5cde6e2df294c64db3bc28133b67594Bill Wendling/// PrintGlobalVariableList - prints out list of problematic global variables 3114e3be89cb5cde6e2df294c64db3bc28133b67594Bill Wendling/// 3124e3be89cb5cde6e2df294c64db3bc28133b67594Bill Wendlingvoid PrintGlobalVariableList(const std::vector<GlobalVariable*> &GVs); 3134e3be89cb5cde6e2df294c64db3bc28133b67594Bill Wendling 314aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner// DeleteFunctionBody - "Remove" the function by deleting all of it's basic 315aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner// blocks, making it external. 316aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner// 317aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattnervoid DeleteFunctionBody(Function *F); 318aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner 319be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// SplitFunctionsOutOfModule - Given a module and a list of functions in the 320be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// module, split the functions OUT of the specified module, and place them in 321be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// the new module. 322d50330cd02b00c8e3de40e8544c45701b9891d87Dan GohmanModule *SplitFunctionsOutOfModule(Module *M, const std::vector<Function*> &F, 323d50330cd02b00c8e3de40e8544c45701b9891d87Dan Gohman DenseMap<const Value*, Value*> &ValueMap); 324be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner 325d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 326d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 327afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#endif 328