BugDriver.h revision 0a002569003fd23a4e117fe54a9bb8a6673b86da
107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com//===- BugDriver.h - Top-Level BugPoint class -------------------*- C++ -*-===// 207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com// 307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com// The LLVM Compiler Infrastructure 407393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com// 507393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com// This file was developed by the LLVM research group and is distributed under 607393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com// the University of Illinois Open Source License. See LICENSE.TXT for details. 707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com// 807393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com//===----------------------------------------------------------------------===// 907393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com// 1007393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com// This class contains all of the shared state and information that is used by 1107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com// the BugPoint tool to track down errors in optimizations. This class is the 1207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com// main driver class that invokes all sub-functionality. 1307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com// 1407393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com//===----------------------------------------------------------------------===// 1507393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 1607393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com#ifndef BUGDRIVER_H 1707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com#define BUGDRIVER_H 1807393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 1907393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com#include <vector> 2007393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com#include <string> 2107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 2207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.comnamespace llvm { 2307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 2407393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.comclass PassInfo; 2507393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.comclass Module; 2607393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.comclass Function; 2707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.comclass AbstractInterpreter; 2807393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.comclass Instruction; 2907393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 3007393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.comclass DebugCrashes; 3107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 3207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.comclass CBE; 3307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.comclass GCC; 3407393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 3507393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.comextern bool DisableSimplifyCFG; 3607393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 3707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.comclass BugDriver { 3807393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com const std::string ToolName; // Name of bugpoint 3907393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com std::string ReferenceOutputFile; // Name of `good' output file 4007393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com Module *Program; // The raw program, linked together 4107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com std::vector<const PassInfo*> PassesToRun; 4207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com AbstractInterpreter *Interpreter; // How to run the program 4307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com CBE *cbe; 4407393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com GCC *gcc; 4507393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 4607393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com // FIXME: sort out public/private distinctions... 4707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com friend class ReducePassList; 4807393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com friend class ReduceMisCodegenFunctions; 4907393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 5007393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.compublic: 5107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com BugDriver(const char *toolname); 5207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 5307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com const std::string &getToolName() const { return ToolName; } 5407393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 5507393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com // Set up methods... these methods are used to copy information about the 5607393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com // command line arguments into instance variables of BugDriver. 5707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com // 5807393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com bool addSources(const std::vector<std::string> &FileNames); 5907393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com template<class It> 6007393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com void addPasses(It I, It E) { PassesToRun.insert(PassesToRun.end(), I, E); } 6107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com void setPassesToRun(const std::vector<const PassInfo*> &PTR) { 6207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com PassesToRun = PTR; 6307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com } 6407393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com const std::vector<const PassInfo*> &getPassesToRun() const { 6507393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com return PassesToRun; 6607393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com } 6707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 6807393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// run - The top level method that is invoked after all of the instance 6907393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// variables are set up from command line arguments. 7007393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// 7107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com bool run(); 7207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 7307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// debugOptimizerCrash - This method is called when some optimizer pass 7407393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// crashes on input. It attempts to prune down the testcase to something 7507393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// reasonable, and figure out exactly which pass is crashing. 7607393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// 7707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com bool debugOptimizerCrash(); 7807393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 7907393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// debugCodeGeneratorCrash - This method is called when the code generator 8007393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// crashes on an input. It attempts to reduce the input as much as possible 8107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// while still causing the code generator to crash. 8207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com bool debugCodeGeneratorCrash(); 8307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 8407393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// debugMiscompilation - This method is used when the passes selected are not 8507393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// crashing, but the generated output is semantically different from the 8607393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// input. 8707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com bool debugMiscompilation(); 8807393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 8907393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// debugPassMiscompilation - This method is called when the specified pass 9007393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// miscompiles Program as input. It tries to reduce the testcase to 914fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com /// something that smaller that still miscompiles the program. 924fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com /// ReferenceOutput contains the filename of the file containing the output we 934fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com /// are to match. 944fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com /// 954fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com bool debugPassMiscompilation(const PassInfo *ThePass, 9607393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com const std::string &ReferenceOutput); 974fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com 98624637cc8ec22c000409704d0b403ac1b81ad4b0caryclark /// compileSharedObject - This method creates a SharedObject from a given 994fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com /// BytecodeFile for debugging a code generator. 100fa2aeee27af27f2934ee52a9732148f66481fb03caryclark@google.com /// 1018cb1daaa1e4343eb60a7c4f21c12e33de30dad64commit-bot@chromium.org std::string compileSharedObject(const std::string &BytecodeFile); 102fa2aeee27af27f2934ee52a9732148f66481fb03caryclark@google.com 103fa2aeee27af27f2934ee52a9732148f66481fb03caryclark@google.com /// debugCodeGenerator - This method narrows down a module to a function or 104624637cc8ec22c000409704d0b403ac1b81ad4b0caryclark /// set of functions, using the CBE as a ``safe'' code generator for other 105624637cc8ec22c000409704d0b403ac1b81ad4b0caryclark /// functions that are not under consideration. 10696fcdcc219d2a0d3579719b84b28bede76efba64halcanary bool debugCodeGenerator(); 10796fcdcc219d2a0d3579719b84b28bede76efba64halcanary 108624637cc8ec22c000409704d0b403ac1b81ad4b0caryclark /// isExecutingJIT - Returns true if bugpoint is currently testing the JIT 109624637cc8ec22c000409704d0b403ac1b81ad4b0caryclark /// 110624637cc8ec22c000409704d0b403ac1b81ad4b0caryclark bool isExecutingJIT(); 111fa2aeee27af27f2934ee52a9732148f66481fb03caryclark@google.com 112fa2aeee27af27f2934ee52a9732148f66481fb03caryclark@google.com /// runPasses - Run all of the passes in the "PassesToRun" list, discard the 11307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// output, and return true if any of the passes crashed. 11407393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com bool runPasses(Module *M = 0) { 11554359294a7c9dc54802d512a5d891a35c1663392caryclark if (M == 0) M = Program; 11654359294a7c9dc54802d512a5d891a35c1663392caryclark std::swap(M, Program); 11754359294a7c9dc54802d512a5d891a35c1663392caryclark bool Result = runPasses(PassesToRun); 11854359294a7c9dc54802d512a5d891a35c1663392caryclark std::swap(M, Program); 11954359294a7c9dc54802d512a5d891a35c1663392caryclark return Result; 12096fcdcc219d2a0d3579719b84b28bede76efba64halcanary } 12154359294a7c9dc54802d512a5d891a35c1663392caryclark 12254359294a7c9dc54802d512a5d891a35c1663392caryclark Module *getProgram() const { return Program; } 12354359294a7c9dc54802d512a5d891a35c1663392caryclark 12454359294a7c9dc54802d512a5d891a35c1663392caryclark /// swapProgramIn - Set the current module to the specified module, returning 12554359294a7c9dc54802d512a5d891a35c1663392caryclark /// the old one. 12654359294a7c9dc54802d512a5d891a35c1663392caryclark Module *swapProgramIn(Module *M) { 12754359294a7c9dc54802d512a5d891a35c1663392caryclark Module *OldProgram = Program; 12854359294a7c9dc54802d512a5d891a35c1663392caryclark Program = M; 12954359294a7c9dc54802d512a5d891a35c1663392caryclark return OldProgram; 13054359294a7c9dc54802d512a5d891a35c1663392caryclark } 13154359294a7c9dc54802d512a5d891a35c1663392caryclark 13254359294a7c9dc54802d512a5d891a35c1663392caryclark /// setNewProgram - If we reduce or update the program somehow, call this 13354359294a7c9dc54802d512a5d891a35c1663392caryclark /// method to update bugdriver with it. This deletes the old module and sets 13454359294a7c9dc54802d512a5d891a35c1663392caryclark /// the specified one as the current program. 13554359294a7c9dc54802d512a5d891a35c1663392caryclark void setNewProgram(Module *M); 13654359294a7c9dc54802d512a5d891a35c1663392caryclark 13754359294a7c9dc54802d512a5d891a35c1663392caryclark /// compileProgram - Try to compile the specified module, throwing an 13807393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// exception if an error occurs, or returning normally if not. This is used 13907393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// for code generation crash testing. 14007393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// 14107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com void compileProgram(Module *M); 14207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 14307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// executeProgram - This method runs "Program", capturing the output of the 14407393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// program to a file, returning the filename of the file. A recommended 14507393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// filename may be optionally specified. If there is a problem with the code 14607393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// generator (e.g., llc crashes), this will throw an exception. 14707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// 14807393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com std::string executeProgram(std::string RequestedOutputFilename = "", 14907393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com std::string Bytecode = "", 15007393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com const std::string &SharedObjects = "", 15107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com AbstractInterpreter *AI = 0, 15207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com bool *ProgramExitedNonzero = 0); 15307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 154624637cc8ec22c000409704d0b403ac1b81ad4b0caryclark /// executeProgramWithCBE - Used to create reference output with the C 155624637cc8ec22c000409704d0b403ac1b81ad4b0caryclark /// backend, if reference output is not provided. If there is a problem with 15607393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// the code generator (e.g., llc crashes), this will throw an exception. 15707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// 158624637cc8ec22c000409704d0b403ac1b81ad4b0caryclark std::string executeProgramWithCBE(std::string OutputFile = ""); 15907393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 16007393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// diffProgram - This method executes the specified module and diffs the 16107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// output against the file specified by ReferenceOutputFile. If the output 16207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// is different, true is returned. If there is a problem with the code 16307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// generator (e.g., llc crashes), this will throw an exception. 16407393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// 16507393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com bool diffProgram(const std::string &BytecodeFile = "", 16607393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com const std::string &SharedObj = "", 16707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com bool RemoveBytecode = false); 16807393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// EmitProgressBytecode - This function is used to output the current Program 169fa2aeee27af27f2934ee52a9732148f66481fb03caryclark@google.com /// to a file named "bugpoint-ID.bc". 170570863f2e22b8ea7d7c504bd15e4f766af097df2caryclark@google.com /// 171570863f2e22b8ea7d7c504bd15e4f766af097df2caryclark@google.com void EmitProgressBytecode(const std::string &ID, bool NoFlyer = false); 172570863f2e22b8ea7d7c504bd15e4f766af097df2caryclark@google.com 17354359294a7c9dc54802d512a5d891a35c1663392caryclark /// deleteInstructionFromProgram - This method clones the current Program and 17454359294a7c9dc54802d512a5d891a35c1663392caryclark /// deletes the specified instruction from the cloned module. It then runs a 17554359294a7c9dc54802d512a5d891a35c1663392caryclark /// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code 17654359294a7c9dc54802d512a5d891a35c1663392caryclark /// which depends on the value. The modified module is then returned. 17754359294a7c9dc54802d512a5d891a35c1663392caryclark /// 17854359294a7c9dc54802d512a5d891a35c1663392caryclark Module *deleteInstructionFromProgram(const Instruction *I, unsigned Simp) 17954359294a7c9dc54802d512a5d891a35c1663392caryclark const; 18054359294a7c9dc54802d512a5d891a35c1663392caryclark 18107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// performFinalCleanups - This method clones the current Program and performs 18207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// a series of cleanups intended to get rid of extra cruft on the module. If 18354359294a7c9dc54802d512a5d891a35c1663392caryclark /// the MayModifySemantics argument is true, then the cleanups is allowed to 1844fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com /// modify how the code behaves. 18507393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// 18607393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com Module *performFinalCleanups(Module *M, bool MayModifySemantics = false); 18707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 1884fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com /// ExtractLoop - Given a module, extract up to one loop from it into a new 1894fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com /// function. This returns null if there are no extractable loops in the 1904fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com /// program or if the loop extractor crashes. 19107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com Module *ExtractLoop(Module *M); 19207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 19307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// runPassesOn - Carefully run the specified set of pass on the specified 19407393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// module, returning the transformed module on success, or a null pointer on 19507393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// failure. If AutoDebugCrashes is set to true, then bugpoint will 19607393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// automatically attempt to track down a crashing pass if one exists, and 19707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// this method will never return null. 198fa2aeee27af27f2934ee52a9732148f66481fb03caryclark@google.com Module *runPassesOn(Module *M, const std::vector<const PassInfo*> &Passes, 199570863f2e22b8ea7d7c504bd15e4f766af097df2caryclark@google.com bool AutoDebugCrashes = false); 200570863f2e22b8ea7d7c504bd15e4f766af097df2caryclark@google.com 201570863f2e22b8ea7d7c504bd15e4f766af097df2caryclark@google.com /// runPasses - Run the specified passes on Program, outputting a bytecode 20207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// file and writting the filename into OutputFile if successful. If the 20307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// optimizations fail for some reason (optimizer crashes), return true, 20407393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// otherwise return false. If DeleteOutput is set to true, the bytecode is 20507393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// deleted on success, and the filename string is undefined. This prints to 2064fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com /// cout a single line message indicating whether compilation was successful 20707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// or failed, unless Quiet is set. 20854359294a7c9dc54802d512a5d891a35c1663392caryclark /// 2094fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com bool runPasses(const std::vector<const PassInfo*> &PassesToRun, 21007393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com std::string &OutputFilename, bool DeleteOutput = false, 21107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com bool Quiet = false) const; 21207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.comprivate: 2134fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com /// writeProgramToFile - This writes the current "Program" to the named 21407393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// bytecode file. If an error occurs, true is returned. 21554359294a7c9dc54802d512a5d891a35c1663392caryclark /// 2164fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com bool writeProgramToFile(const std::string &Filename, Module *M = 0) const; 21707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 21807393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com /// runPasses - Just like the method above, but this just returns true or 21954359294a7c9dc54802d512a5d891a35c1663392caryclark /// false indicating whether or not the optimizer crashed on the specified 22054359294a7c9dc54802d512a5d891a35c1663392caryclark /// input (true = crashed). 22154359294a7c9dc54802d512a5d891a35c1663392caryclark /// 22254359294a7c9dc54802d512a5d891a35c1663392caryclark bool runPasses(const std::vector<const PassInfo*> &PassesToRun, 22354359294a7c9dc54802d512a5d891a35c1663392caryclark bool DeleteOutput = true) const { 22454359294a7c9dc54802d512a5d891a35c1663392caryclark std::string Filename; 22554359294a7c9dc54802d512a5d891a35c1663392caryclark return runPasses(PassesToRun, Filename, DeleteOutput); 22654359294a7c9dc54802d512a5d891a35c1663392caryclark } 22754359294a7c9dc54802d512a5d891a35c1663392caryclark 22854359294a7c9dc54802d512a5d891a35c1663392caryclark /// initializeExecutionEnvironment - This method is used to set up the 22954359294a7c9dc54802d512a5d891a35c1663392caryclark /// environment for executing LLVM programs. 23054359294a7c9dc54802d512a5d891a35c1663392caryclark /// 23154359294a7c9dc54802d512a5d891a35c1663392caryclark bool initializeExecutionEnvironment(); 23254359294a7c9dc54802d512a5d891a35c1663392caryclark}; 23354359294a7c9dc54802d512a5d891a35c1663392caryclark 23454359294a7c9dc54802d512a5d891a35c1663392caryclark/// ParseInputFile - Given a bytecode or assembly input filename, parse and 23554359294a7c9dc54802d512a5d891a35c1663392caryclark/// return it, or return null if not possible. 23654359294a7c9dc54802d512a5d891a35c1663392caryclark/// 23754359294a7c9dc54802d512a5d891a35c1663392caryclarkModule *ParseInputFile(const std::string &InputFilename); 23854359294a7c9dc54802d512a5d891a35c1663392caryclark 23954359294a7c9dc54802d512a5d891a35c1663392caryclark 24054359294a7c9dc54802d512a5d891a35c1663392caryclark/// getPassesString - Turn a list of passes into a string which indicates the 24154359294a7c9dc54802d512a5d891a35c1663392caryclark/// command line options that must be passed to add the passes. 24254359294a7c9dc54802d512a5d891a35c1663392caryclark/// 24307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.comstd::string getPassesString(const std::vector<const PassInfo*> &Passes); 2444fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com 2454fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com/// PrintFunctionList - prints out list of problematic functions 2464fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com/// 24707393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.comvoid PrintFunctionList(const std::vector<Function*> &Funcs); 24807393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 24907393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com// DeleteFunctionBody - "Remove" the function by deleting all of it's basic 25007393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com// blocks, making it external. 25107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com// 25207393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.comvoid DeleteFunctionBody(Function *F); 25307393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 254fa2aeee27af27f2934ee52a9732148f66481fb03caryclark@google.com/// SplitFunctionsOutOfModule - Given a module and a list of functions in the 255570863f2e22b8ea7d7c504bd15e4f766af097df2caryclark@google.com/// module, split the functions OUT of the specified module, and place them in 256570863f2e22b8ea7d7c504bd15e4f766af097df2caryclark@google.com/// the new module. 257570863f2e22b8ea7d7c504bd15e4f766af097df2caryclark@google.comModule *SplitFunctionsOutOfModule(Module *M, const std::vector<Function*> &F); 25807393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 25907393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com} // End llvm namespace 26007393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com 26107393cab57ce74a4aae89a31fae9aaa9780fc19dcaryclark@google.com#endif 2624fdbb229649caf74e5c1b55a1823926df903af34caryclark@google.com