BugDriver.h revision 88088f4067ae002aebf6e32079c446b06fab31f1
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 19e9916a302f1bacad234d7dafc1df3dc968a6ba0fDevang Patel#include "llvm/ADT/ValueMap.h" 201ed219a9d2279ce5a5bbcf16d9b7ccc05cce638cRafael Espindola#include "llvm/Transforms/Utils/ValueMapper.h" 21afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#include <string> 22f010c464a11444733ec67e31aace8bcebeaf2588Chandler Carruth#include <vector> 235073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman 24d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 25d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 26d50330cd02b00c8e3de40e8544c45701b9891d87Dan Gohmanclass Value; 278be3291f5942e3ae4a5d66c480e7aabe2f771031Owen Andersonclass PassInfo; 28afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerclass Module; 294e3be89cb5cde6e2df294c64db3bc28133b67594Bill Wendlingclass GlobalVariable; 30afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerclass Function; 315e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattnerclass BasicBlock; 32218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattnerclass AbstractInterpreter; 336520785dcd22012535934098942d57c07c7631c2Chris Lattnerclass Instruction; 3412ddd409535b52a7fa5157ded9a4cedd161fedb6Benjamin Kramerclass LLVMContext; 35afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 36aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattnerclass DebugCrashes; 37640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 38a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukmanclass GCC; 39a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman 4047ae4a1cee5eec5767a11403c0fac7c91ec45461Chris Lattnerextern bool DisableSimplifyCFG; 4147ae4a1cee5eec5767a11403c0fac7c91ec45461Chris Lattner 42f9aaae06cd2109082cda2b09ef3f23e0e1cff47bChris Lattner/// BugpointIsInterrupted - Set to true when the user presses ctrl-c. 43f9aaae06cd2109082cda2b09ef3f23e0e1cff47bChris Lattner/// 44f9aaae06cd2109082cda2b09ef3f23e0e1cff47bChris Lattnerextern bool BugpointIsInterrupted; 45f9aaae06cd2109082cda2b09ef3f23e0e1cff47bChris Lattner 46afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerclass BugDriver { 474434ed44c45c87a72b7a0bf2f91211f895022b91Owen Anderson LLVMContext& Context; 48197f728d49fa0cc0baa5aadb2b905fbd8c22a81eDan Gohman const char *ToolName; // argv[0] of bugpoint 49a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman std::string ReferenceOutputFile; // Name of `good' output file 50afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner Module *Program; // The raw program, linked together 518261dfed05e32302469ef707cc881fed2c31f85fRafael Espindola std::vector<std::string> PassesToRun; 52218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner AbstractInterpreter *Interpreter; // How to run the program 5370ef449741da8b1ef035e04a55958652a0200ba1Dan Gohman AbstractInterpreter *SafeInterpreter; // To generate reference output, etc. 54a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman GCC *gcc; 556a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins bool run_find_bugs; 569686ae7f4ea5f19ce77e31e64e0916db41a82662Chris Lattner unsigned Timeout; 579ba8a76f8baaa1092d60ccfbc04e7efdc207c98fAnton Korobeynikov unsigned MemoryLimit; 58c3e6859d8dc9014fee8023497153add9a2148f22Jeffrey Yasskin bool UseValgrind; 59640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 60aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner // FIXME: sort out public/private distinctions... 6106905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner friend class ReducePassList; 625073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman friend class ReduceMisCodegenFunctions; 635073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman 64afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerpublic: 657f99f74b7fc298dad4c61c15b064dc951d2b3cbbRafael Espindola BugDriver(const char *toolname, bool find_bugs, 66c3e6859d8dc9014fee8023497153add9a2148f22Jeffrey Yasskin unsigned timeout, unsigned memlimit, bool use_valgrind, 67c3e6859d8dc9014fee8023497153add9a2148f22Jeffrey Yasskin LLVMContext& ctxt); 68c1dc0679706f7538cd17169b920967c54661e5b6Jeffrey Yasskin ~BugDriver(); 69218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner 70197f728d49fa0cc0baa5aadb2b905fbd8c22a81eDan Gohman const char *getToolName() const { return ToolName; } 71afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 725d8cace94a71169ce8493baa7f3305a27fe0cd84Rafael Espindola LLVMContext& getContext() const { return Context; } 738b477ed579794ba6d76915d56b3f448a7dd20120Owen Anderson 74afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner // Set up methods... these methods are used to copy information about the 75afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner // command line arguments into instance variables of BugDriver. 76afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner // 77afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner bool addSources(const std::vector<std::string> &FileNames); 788261dfed05e32302469ef707cc881fed2c31f85fRafael Espindola void addPass(std::string p) { PassesToRun.push_back(p); } 798261dfed05e32302469ef707cc881fed2c31f85fRafael Espindola void setPassesToRun(const std::vector<std::string> &PTR) { 809c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner PassesToRun = PTR; 819c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner } 828261dfed05e32302469ef707cc881fed2c31f85fRafael Espindola const std::vector<std::string> &getPassesToRun() const { 83efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner return PassesToRun; 84efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner } 85afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 86afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// run - The top level method that is invoked after all of the instance 87c4bb052ecccfafa0ffa928d0b061db35734ee2eeReid Spencer /// variables are set up from command line arguments. The \p as_child argument 88c4bb052ecccfafa0ffa928d0b061db35734ee2eeReid Spencer /// indicates whether the driver is to run in parent mode or child mode. 89afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// 9022ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky bool run(std::string &ErrMsg); 91afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 92025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// debugOptimizerCrash - This method is called when some optimizer pass 93025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// crashes on input. It attempts to prune down the testcase to something 94025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// reasonable, and figure out exactly which pass is crashing. 95afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// 966a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins bool debugOptimizerCrash(const std::string &ID = "passes"); 973da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman 98025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// debugCodeGeneratorCrash - This method is called when the code generator 99025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// crashes on an input. It attempts to reduce the input as much as possible 100025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner /// while still causing the code generator to crash. 10122ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky bool debugCodeGeneratorCrash(std::string &Error); 102afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 103afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// debugMiscompilation - This method is used when the passes selected are not 104afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// crashing, but the generated output is semantically different from the 105afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// input. 10622ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky void debugMiscompilation(std::string *Error); 107afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 108218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// debugPassMiscompilation - This method is called when the specified pass 109218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// miscompiles Program as input. It tries to reduce the testcase to 110218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// something that smaller that still miscompiles the program. 111218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// ReferenceOutput contains the filename of the file containing the output we 112218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// are to match. 113218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// 1148be3291f5942e3ae4a5d66c480e7aabe2f771031Owen Anderson bool debugPassMiscompilation(const PassInfo *ThePass, 115ea3e5e56fdc56e5c2ddafb36eab26676e137dfa0Jeff Cohen const std::string &ReferenceOutput); 116218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner 1175073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman /// compileSharedObject - This method creates a SharedObject from a given 1188ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif /// BitcodeFile for debugging a code generator. 119a0f5b15e1eb8642d92b3141a6b88a5729ea979dcChris Lattner /// 12022ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky std::string compileSharedObject(const std::string &BitcodeFile, 12122ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky std::string &Error); 1225073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman 1235073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman /// debugCodeGenerator - This method narrows down a module to a function or 1245073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman /// set of functions, using the CBE as a ``safe'' code generator for other 1255073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman /// functions that are not under consideration. 12622ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky bool debugCodeGenerator(std::string *Error); 1275073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman 128fe04db890b87d9ac4c4a607e6bd0035e8cc2ad6cMisha Brukman /// isExecutingJIT - Returns true if bugpoint is currently testing the JIT 129fe04db890b87d9ac4c4a607e6bd0035e8cc2ad6cMisha Brukman /// 13091eabc13d3a456cc4b387d3d7fdb041d976732c7Misha Brukman bool isExecutingJIT(); 13191eabc13d3a456cc4b387d3d7fdb041d976732c7Misha Brukman 13206905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner /// runPasses - Run all of the passes in the "PassesToRun" list, discard the 13306905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner /// output, and return true if any of the passes crashed. 1345d8cace94a71169ce8493baa7f3305a27fe0cd84Rafael Espindola bool runPasses(Module *M) const { 1355d8cace94a71169ce8493baa7f3305a27fe0cd84Rafael Espindola return runPasses(M, PassesToRun); 13606905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner } 13706905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner 138efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *getProgram() const { return Program; } 139efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 140efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner /// swapProgramIn - Set the current module to the specified module, returning 141efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner /// the old one. 142efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *swapProgramIn(Module *M) { 143efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Module *OldProgram = Program; 144efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner Program = M; 145efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner return OldProgram; 146efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner } 14706905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner 14870ef449741da8b1ef035e04a55958652a0200ba1Dan Gohman AbstractInterpreter *switchToSafeInterpreter() { 149a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner AbstractInterpreter *Old = Interpreter; 15070ef449741da8b1ef035e04a55958652a0200ba1Dan Gohman Interpreter = (AbstractInterpreter*)SafeInterpreter; 151a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner return Old; 152a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 153a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner 154a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner void switchToInterpreter(AbstractInterpreter *AI) { 155a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner Interpreter = AI; 156a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner } 1573da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman 15806905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner /// setNewProgram - If we reduce or update the program somehow, call this 15906905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner /// method to update bugdriver with it. This deletes the old module and sets 16006905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner /// the specified one as the current program. 16106905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner void setNewProgram(Module *M); 16206905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner 16322ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky /// compileProgram - Try to compile the specified module, returning false and 16422ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky /// setting Error if an error occurs. This is used for code generation 16522ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky /// crash testing. 166ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner /// 167248d1c65f1ce5bc04b892998b2c2061e6a5f8e1cRafael Espindola void compileProgram(Module *M, std::string *Error) const; 168ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner 169a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// executeProgram - This method runs "Program", capturing the output of the 170ac15da67055a33ce418be23ce7681358b3093aebNick Lewycky /// program to a file. A recommended filename may be optionally specified. 171a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// 17210757dd8e1a66128b205bd04797c8aed0cb7a1bdRafael Espindola std::string executeProgram(const Module *Program, 17310757dd8e1a66128b205bd04797c8aed0cb7a1bdRafael Espindola std::string OutputFilename, 17422ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky std::string Bitcode, 17522ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky const std::string &SharedObjects, 17622ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky AbstractInterpreter *AI, 17713793264e7cbf58e3b7b0cff3baac8e0b7a11a9dRafael Espindola std::string *Error) const; 178a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner 17970ef449741da8b1ef035e04a55958652a0200ba1Dan Gohman /// executeProgramSafely - Used to create reference output with the "safe" 180a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// backend, if reference output is not provided. If there is a problem with 18122ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky /// the code generator (e.g., llc crashes), this will return false and set 18222ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky /// Error. 183a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// 18410757dd8e1a66128b205bd04797c8aed0cb7a1bdRafael Espindola std::string executeProgramSafely(const Module *Program, 18513793264e7cbf58e3b7b0cff3baac8e0b7a11a9dRafael Espindola std::string OutputFile, 18613793264e7cbf58e3b7b0cff3baac8e0b7a11a9dRafael Espindola std::string *Error) const; 187a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner 1886a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// createReferenceFile - calls compileProgram and then records the output 1896a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// into ReferenceOutputFile. Returns true if reference file created, false 1906a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// otherwise. Note: initializeExecutionEnvironment should be called BEFORE 1916a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// this function. 1926a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// 193c0431fe1ca52c5d159c604957f337aa3eb1ec3d3Chris Lattner bool createReferenceFile(Module *M, const std::string &Filename 194c0431fe1ca52c5d159c604957f337aa3eb1ec3d3Chris Lattner = "bugpoint.reference.out"); 1956a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins 196a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// diffProgram - This method executes the specified module and diffs the 197a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// output against the file specified by ReferenceOutputFile. If the output 19822ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky /// is different, 1 is returned. If there is a problem with the code 19922ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky /// generator (e.g., llc crashes), this will return -1 and set Error. 200a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner /// 20110757dd8e1a66128b205bd04797c8aed0cb7a1bdRafael Espindola bool diffProgram(const Module *Program, 20210757dd8e1a66128b205bd04797c8aed0cb7a1bdRafael Espindola const std::string &BitcodeFile = "", 203a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner const std::string &SharedObj = "", 20422ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky bool RemoveBitcode = false, 20513793264e7cbf58e3b7b0cff3baac8e0b7a11a9dRafael Espindola std::string *Error = 0) const; 20622ff748712b348300e51248339b6e8cf9b59e2c6Nick Lewycky 207bae1b71cbb930e419df03db209ebc547a0e4ec72Rafael Espindola /// EmitProgressBitcode - This function is used to output M to a file named 208bae1b71cbb930e419df03db209ebc547a0e4ec72Rafael Espindola /// "bugpoint-ID.bc". 2090cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// 210bae1b71cbb930e419df03db209ebc547a0e4ec72Rafael Espindola void EmitProgressBitcode(const Module *M, const std::string &ID, 211ca356afe09454b3378165ded4eda294bd6341428Rafael Espindola bool NoFlyer = false) const; 2120cc8807029f577996a442b96d24c3346ed6de091Chris Lattner 2130cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// deleteInstructionFromProgram - This method clones the current Program and 2140cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// deletes the specified instruction from the cloned module. It then runs a 2150cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code 2160cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// which depends on the value. The modified module is then returned. 2170cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// 218866aa0d742b7bc9811fd1b45507af999c605205aRafael Espindola Module *deleteInstructionFromProgram(const Instruction *I, unsigned Simp); 2190cc8807029f577996a442b96d24c3346ed6de091Chris Lattner 2200cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// performFinalCleanups - This method clones the current Program and performs 2210cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// a series of cleanups intended to get rid of extra cruft on the module. If 2220cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// the MayModifySemantics argument is true, then the cleanups is allowed to 2230cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// modify how the code behaves. 2240cc8807029f577996a442b96d24c3346ed6de091Chris Lattner /// 2250cc8807029f577996a442b96d24c3346ed6de091Chris Lattner Module *performFinalCleanups(Module *M, bool MayModifySemantics = false); 2260cc8807029f577996a442b96d24c3346ed6de091Chris Lattner 2277546c3884a400b72d10fc19f120c6798b294a39dChris Lattner /// ExtractLoop - Given a module, extract up to one loop from it into a new 2287546c3884a400b72d10fc19f120c6798b294a39dChris Lattner /// function. This returns null if there are no extractable loops in the 2297546c3884a400b72d10fc19f120c6798b294a39dChris Lattner /// program or if the loop extractor crashes. 2307546c3884a400b72d10fc19f120c6798b294a39dChris Lattner Module *ExtractLoop(Module *M); 2317546c3884a400b72d10fc19f120c6798b294a39dChris Lattner 2325e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner /// ExtractMappedBlocksFromModule - Extract all but the specified basic blocks 2335e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner /// into their own functions. The only detail is that M is actually a module 2345e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner /// cloned from the one the BBs are in, so some mapping needs to be performed. 2355e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner /// If this operation fails for some reason (ie the implementation is buggy), 2365e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner /// this function should return null, otherwise it returns a new Module. 2375e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner Module *ExtractMappedBlocksFromModule(const std::vector<BasicBlock*> &BBs, 2385e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner Module *M); 2395e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner 2403b6441e1050a9a2a55c79f58513191b3195fdaf7Chris Lattner /// runPassesOn - Carefully run the specified set of pass on the specified 2413b6441e1050a9a2a55c79f58513191b3195fdaf7Chris Lattner /// module, returning the transformed module on success, or a null pointer on 2420a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner /// failure. If AutoDebugCrashes is set to true, then bugpoint will 2430a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner /// automatically attempt to track down a crashing pass if one exists, and 2440a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner /// this method will never return null. 2458261dfed05e32302469ef707cc881fed2c31f85fRafael Espindola Module *runPassesOn(Module *M, const std::vector<std::string> &Passes, 2466fa98b13206583e6eb90b8304758b35548914944Nick Lewycky bool AutoDebugCrashes = false, unsigned NumExtraArgs = 0, 2476fa98b13206583e6eb90b8304758b35548914944Nick Lewycky const char * const *ExtraArgs = NULL); 2483b6441e1050a9a2a55c79f58513191b3195fdaf7Chris Lattner 2498ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif /// runPasses - Run the specified passes on Program, outputting a bitcode 250afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// file and writting the filename into OutputFile if successful. If the 251afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// optimizations fail for some reason (optimizer crashes), return true, 2528ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif /// otherwise return false. If DeleteOutput is set to true, the bitcode is 253afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// deleted on success, and the filename string is undefined. This prints to 254ac95cc79ac0b899d566cc29c0f646f39c2fa35c0Dan Gohman /// outs() a single line message indicating whether compilation was successful 2556fa98b13206583e6eb90b8304758b35548914944Nick Lewycky /// or failed, unless Quiet is set. ExtraArgs specifies additional arguments 2566fa98b13206583e6eb90b8304758b35548914944Nick Lewycky /// to pass to the child bugpoint instance. 257afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// 258ca356afe09454b3378165ded4eda294bd6341428Rafael Espindola bool runPasses(Module *Program, 2598261dfed05e32302469ef707cc881fed2c31f85fRafael Espindola const std::vector<std::string> &PassesToRun, 260218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner std::string &OutputFilename, bool DeleteOutput = false, 2616fa98b13206583e6eb90b8304758b35548914944Nick Lewycky bool Quiet = false, unsigned NumExtraArgs = 0, 2626fa98b13206583e6eb90b8304758b35548914944Nick Lewycky const char * const *ExtraArgs = NULL) const; 2636a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins 2646a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// runManyPasses - Take the specified pass list and create different 2656a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// combinations of passes to compile the program with. Compile the program with 2666a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// each set and mark test to see if it compiled correctly. If the passes 2676a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// compiled correctly output nothing and rearrange the passes into a new order. 2686a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// If the passes did not compile correctly, output the command required to 2696a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// recreate the failure. This returns true if a compiler error is found. 2706a3f31cb707972ebde1e45a61fa8f5bcff132ebaPatrick Jenkins /// 2718261dfed05e32302469ef707cc881fed2c31f85fRafael Espindola bool runManyPasses(const std::vector<std::string> &AllPasses, 2723472766f9eb7d66f234c390ce1b3a8b76f0ee9ceDuncan Sands std::string &ErrMsg); 27311b8cd197a740bc9af2f27cb88d535c4be2cdd0eChris Lattner 274efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner /// writeProgramToFile - This writes the current "Program" to the named 2758ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif /// bitcode file. If an error occurs, true is returned. 276efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner /// 277bae1b71cbb930e419df03db209ebc547a0e4ec72Rafael Espindola bool writeProgramToFile(const std::string &Filename, const Module *M) const; 27888088f4067ae002aebf6e32079c446b06fab31f1Rafael Espindola bool writeProgramToFile(const std::string &Filename, int FD, 27988088f4067ae002aebf6e32079c446b06fab31f1Rafael Espindola const Module *M) const; 280afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 28111b8cd197a740bc9af2f27cb88d535c4be2cdd0eChris Lattnerprivate: 282afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// runPasses - Just like the method above, but this just returns true or 283afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// false indicating whether or not the optimizer crashed on the specified 284afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// input (true = crashed). 285afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner /// 2865d8cace94a71169ce8493baa7f3305a27fe0cd84Rafael Espindola bool runPasses(Module *M, 2878261dfed05e32302469ef707cc881fed2c31f85fRafael Espindola const std::vector<std::string> &PassesToRun, 288afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner bool DeleteOutput = true) const { 289afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner std::string Filename; 2905d8cace94a71169ce8493baa7f3305a27fe0cd84Rafael Espindola return runPasses(M, PassesToRun, Filename, DeleteOutput); 291afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner } 292afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 293218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// initializeExecutionEnvironment - This method is used to set up the 294218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// environment for executing LLVM programs. 295218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner /// 296218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner bool initializeExecutionEnvironment(); 297afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner}; 298afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner 2998ff70c2635bfd4e02c0140a5dc9ca909fffba35aGabor Greif/// ParseInputFile - Given a bitcode or assembly input filename, parse and 300efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// return it, or return null if not possible. 301efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// 30231895e73591d3c9ceae731a1274c8f56194b9616Owen AndersonModule *ParseInputFile(const std::string &InputFilename, 3034434ed44c45c87a72b7a0bf2f91211f895022b91Owen Anderson LLVMContext& ctxt); 304efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 305efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 306640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner/// getPassesString - Turn a list of passes into a string which indicates the 307640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner/// command line options that must be passed to add the passes. 308640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner/// 3098261dfed05e32302469ef707cc881fed2c31f85fRafael Espindolastd::string getPassesString(const std::vector<std::string> &Passes); 310640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner 311efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// PrintFunctionList - prints out list of problematic functions 312efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// 313efdc0b505712d1ca4460def27e51c430f033d58dChris Lattnervoid PrintFunctionList(const std::vector<Function*> &Funcs); 314efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner 3154e3be89cb5cde6e2df294c64db3bc28133b67594Bill Wendling/// PrintGlobalVariableList - prints out list of problematic global variables 3164e3be89cb5cde6e2df294c64db3bc28133b67594Bill Wendling/// 3174e3be89cb5cde6e2df294c64db3bc28133b67594Bill Wendlingvoid PrintGlobalVariableList(const std::vector<GlobalVariable*> &GVs); 3184e3be89cb5cde6e2df294c64db3bc28133b67594Bill Wendling 319aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner// DeleteFunctionBody - "Remove" the function by deleting all of it's basic 320aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner// blocks, making it external. 321aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner// 322aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattnervoid DeleteFunctionBody(Function *F); 323aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner 324be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// SplitFunctionsOutOfModule - Given a module and a list of functions in the 325be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// module, split the functions OUT of the specified module, and place them in 326be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// the new module. 327d50330cd02b00c8e3de40e8544c45701b9891d87Dan GohmanModule *SplitFunctionsOutOfModule(Module *M, const std::vector<Function*> &F, 3281ed219a9d2279ce5a5bbcf16d9b7ccc05cce638cRafael Espindola ValueToValueMapTy &VMap); 329be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner 330d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 331d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 332afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#endif 333