BugDriver.h revision 3da94aec4d429b2ba0f65fa040c33650cade196b
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
38afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerclass BugDriver {
39afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  const std::string ToolName;  // Name of bugpoint
40a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman  std::string ReferenceOutputFile; // Name of `good' output file
41afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  Module *Program;             // The raw program, linked together
42afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  std::vector<const PassInfo*> PassesToRun;
43218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  AbstractInterpreter *Interpreter;   // How to run the program
44a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman  CBE *cbe;
45a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman  GCC *gcc;
46640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner
47aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner  // FIXME: sort out public/private distinctions...
4806905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  friend class ReducePassList;
495073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  friend class ReduceMisCodegenFunctions;
505073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman
51afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerpublic:
525073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  BugDriver(const char *toolname);
53218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner
54218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  const std::string &getToolName() const { return ToolName; }
55afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
56afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  // Set up methods... these methods are used to copy information about the
57afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  // command line arguments into instance variables of BugDriver.
58afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  //
59afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  bool addSources(const std::vector<std::string> &FileNames);
60afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  template<class It>
61afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  void addPasses(It I, It E) { PassesToRun.insert(PassesToRun.end(), I, E); }
629c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner  void setPassesToRun(const std::vector<const PassInfo*> &PTR) {
639c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner    PassesToRun = PTR;
649c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner  }
65efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  const std::vector<const PassInfo*> &getPassesToRun() const {
66efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner    return PassesToRun;
67efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  }
68afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
69afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// run - The top level method that is invoked after all of the instance
70afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// variables are set up from command line arguments.
71afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  ///
72afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  bool run();
73afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
74025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  /// debugOptimizerCrash - This method is called when some optimizer pass
75025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  /// crashes on input.  It attempts to prune down the testcase to something
76025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  /// reasonable, and figure out exactly which pass is crashing.
77afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  ///
78025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  bool debugOptimizerCrash();
793da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman
80025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  /// debugCodeGeneratorCrash - This method is called when the code generator
81025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  /// crashes on an input.  It attempts to reduce the input as much as possible
82025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  /// while still causing the code generator to crash.
83025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  bool debugCodeGeneratorCrash();
84afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
85afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// debugMiscompilation - This method is used when the passes selected are not
86afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// crashing, but the generated output is semantically different from the
87afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// input.
88afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  bool debugMiscompilation();
89afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
90218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// debugPassMiscompilation - This method is called when the specified pass
91218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// miscompiles Program as input.  It tries to reduce the testcase to
92218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// something that smaller that still miscompiles the program.
93218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// ReferenceOutput contains the filename of the file containing the output we
94218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// are to match.
95218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  ///
96218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  bool debugPassMiscompilation(const PassInfo *ThePass,
97218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner			       const std::string &ReferenceOutput);
98218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner
995073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  /// compileSharedObject - This method creates a SharedObject from a given
1005073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  /// BytecodeFile for debugging a code generator.
101a0f5b15e1eb8642d92b3141a6b88a5729ea979dcChris Lattner  ///
102a0f5b15e1eb8642d92b3141a6b88a5729ea979dcChris Lattner  std::string compileSharedObject(const std::string &BytecodeFile);
1035073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman
1045073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  /// debugCodeGenerator - This method narrows down a module to a function or
1055073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  /// set of functions, using the CBE as a ``safe'' code generator for other
1065073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  /// functions that are not under consideration.
1075073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  bool debugCodeGenerator();
1085073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman
109fe04db890b87d9ac4c4a607e6bd0035e8cc2ad6cMisha Brukman  /// isExecutingJIT - Returns true if bugpoint is currently testing the JIT
110fe04db890b87d9ac4c4a607e6bd0035e8cc2ad6cMisha Brukman  ///
11191eabc13d3a456cc4b387d3d7fdb041d976732c7Misha Brukman  bool isExecutingJIT();
11291eabc13d3a456cc4b387d3d7fdb041d976732c7Misha Brukman
11306905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  /// runPasses - Run all of the passes in the "PassesToRun" list, discard the
11406905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  /// output, and return true if any of the passes crashed.
11506905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  bool runPasses(Module *M = 0) {
11606905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner    if (M == 0) M = Program;
11706905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner    std::swap(M, Program);
11806905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner    bool Result = runPasses(PassesToRun);
11906905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner    std::swap(M, Program);
12006905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner    return Result;
12106905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  }
12206905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner
123efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  Module *getProgram() const { return Program; }
124efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner
125efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  /// swapProgramIn - Set the current module to the specified module, returning
126efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  /// the old one.
127efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  Module *swapProgramIn(Module *M) {
128efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner    Module *OldProgram = Program;
129efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner    Program = M;
130efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner    return OldProgram;
131efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  }
13206905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner
133a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner  AbstractInterpreter *switchToCBE() {
134a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner    AbstractInterpreter *Old = Interpreter;
135a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner    Interpreter = (AbstractInterpreter*)cbe;
136a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner    return Old;
137a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner  }
138a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner
139a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner  void switchToInterpreter(AbstractInterpreter *AI) {
140a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner    Interpreter = AI;
141a57d86b436549503a7f96c5266444e022bdbaf55Chris Lattner  }
1423da94aec4d429b2ba0f65fa040c33650cade196bMisha Brukman
14306905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  /// setNewProgram - If we reduce or update the program somehow, call this
14406905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  /// method to update bugdriver with it.  This deletes the old module and sets
14506905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  /// the specified one as the current program.
14606905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  void setNewProgram(Module *M);
14706905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner
148ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner  /// compileProgram - Try to compile the specified module, throwing an
149ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner  /// exception if an error occurs, or returning normally if not.  This is used
150ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner  /// for code generation crash testing.
151ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner  ///
152ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner  void compileProgram(Module *M);
153ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner
154a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// executeProgram - This method runs "Program", capturing the output of the
155a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// program to a file, returning the filename of the file.  A recommended
156a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// filename may be optionally specified.  If there is a problem with the code
157a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// generator (e.g., llc crashes), this will throw an exception.
158a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  ///
159a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  std::string executeProgram(std::string RequestedOutputFilename = "",
160a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner                             std::string Bytecode = "",
161a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner                             const std::string &SharedObjects = "",
162a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner                             AbstractInterpreter *AI = 0,
163a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner                             bool *ProgramExitedNonzero = 0);
164a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner
165a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// executeProgramWithCBE - Used to create reference output with the C
166a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// backend, if reference output is not provided.  If there is a problem with
167a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// the code generator (e.g., llc crashes), this will throw an exception.
168a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  ///
169a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  std::string executeProgramWithCBE(std::string OutputFile = "");
170a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner
171a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// diffProgram - This method executes the specified module and diffs the
172a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// output against the file specified by ReferenceOutputFile.  If the output
173a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// is different, true is returned.  If there is a problem with the code
174a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// generator (e.g., llc crashes), this will throw an exception.
175a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  ///
176a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  bool diffProgram(const std::string &BytecodeFile = "",
177a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner                   const std::string &SharedObj = "",
178a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner                   bool RemoveBytecode = false);
1790cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// EmitProgressBytecode - This function is used to output the current Program
1800cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// to a file named "bugpoint-ID.bc".
1810cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  ///
1820cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  void EmitProgressBytecode(const std::string &ID, bool NoFlyer = false);
1830cc8807029f577996a442b96d24c3346ed6de091Chris Lattner
1840cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// deleteInstructionFromProgram - This method clones the current Program and
1850cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// deletes the specified instruction from the cloned module.  It then runs a
1860cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code
1870cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// which depends on the value.  The modified module is then returned.
1880cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  ///
1890cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  Module *deleteInstructionFromProgram(const Instruction *I, unsigned Simp)
1900cc8807029f577996a442b96d24c3346ed6de091Chris Lattner    const;
1910cc8807029f577996a442b96d24c3346ed6de091Chris Lattner
1920cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// performFinalCleanups - This method clones the current Program and performs
1930cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// a series of cleanups intended to get rid of extra cruft on the module.  If
1940cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// the MayModifySemantics argument is true, then the cleanups is allowed to
1950cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// modify how the code behaves.
1960cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  ///
1970cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  Module *performFinalCleanups(Module *M, bool MayModifySemantics = false);
1980cc8807029f577996a442b96d24c3346ed6de091Chris Lattner
1997546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  /// ExtractLoop - Given a module, extract up to one loop from it into a new
2007546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  /// function.  This returns null if there are no extractable loops in the
2017546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  /// program or if the loop extractor crashes.
2027546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  Module *ExtractLoop(Module *M);
2037546c3884a400b72d10fc19f120c6798b294a39dChris Lattner
2045e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner  /// ExtractMappedBlocksFromModule - Extract all but the specified basic blocks
2055e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner  /// into their own functions.  The only detail is that M is actually a module
2065e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner  /// cloned from the one the BBs are in, so some mapping needs to be performed.
2075e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner  /// If this operation fails for some reason (ie the implementation is buggy),
2085e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner  /// this function should return null, otherwise it returns a new Module.
2095e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner  Module *ExtractMappedBlocksFromModule(const std::vector<BasicBlock*> &BBs,
2105e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner                                        Module *M);
2115e783ab0b5fc3407ec59f1a598fdb9ef3b96b287Chris Lattner
2123b6441e1050a9a2a55c79f58513191b3195fdaf7Chris Lattner  /// runPassesOn - Carefully run the specified set of pass on the specified
2133b6441e1050a9a2a55c79f58513191b3195fdaf7Chris Lattner  /// module, returning the transformed module on success, or a null pointer on
2140a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner  /// failure.  If AutoDebugCrashes is set to true, then bugpoint will
2150a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner  /// automatically attempt to track down a crashing pass if one exists, and
2160a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner  /// this method will never return null.
2170a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner  Module *runPassesOn(Module *M, const std::vector<const PassInfo*> &Passes,
2180a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner                      bool AutoDebugCrashes = false);
2193b6441e1050a9a2a55c79f58513191b3195fdaf7Chris Lattner
220afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// runPasses - Run the specified passes on Program, outputting a bytecode
221afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// file and writting the filename into OutputFile if successful.  If the
222afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// optimizations fail for some reason (optimizer crashes), return true,
223afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// otherwise return false.  If DeleteOutput is set to true, the bytecode is
224afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// deleted on success, and the filename string is undefined.  This prints to
225afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// cout a single line message indicating whether compilation was successful
226218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// or failed, unless Quiet is set.
227afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  ///
228afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
229218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner                 std::string &OutputFilename, bool DeleteOutput = false,
230218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner		 bool Quiet = false) const;
23111b8cd197a740bc9af2f27cb88d535c4be2cdd0eChris Lattner
232efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  /// writeProgramToFile - This writes the current "Program" to the named
233efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  /// bytecode file.  If an error occurs, true is returned.
234efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  ///
235efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  bool writeProgramToFile(const std::string &Filename, Module *M = 0) const;
236afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
23711b8cd197a740bc9af2f27cb88d535c4be2cdd0eChris Lattnerprivate:
238afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// runPasses - Just like the method above, but this just returns true or
239afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// false indicating whether or not the optimizer crashed on the specified
240afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// input (true = crashed).
241afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  ///
242afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
243afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner                 bool DeleteOutput = true) const {
244afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner    std::string Filename;
245afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner    return runPasses(PassesToRun, Filename, DeleteOutput);
246afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  }
247afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
248218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// initializeExecutionEnvironment - This method is used to set up the
249218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// environment for executing LLVM programs.
250218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  ///
251218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  bool initializeExecutionEnvironment();
252afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner};
253afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
254efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// ParseInputFile - Given a bytecode or assembly input filename, parse and
255efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// return it, or return null if not possible.
256efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner///
257efdc0b505712d1ca4460def27e51c430f033d58dChris LattnerModule *ParseInputFile(const std::string &InputFilename);
258efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner
259efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner
260640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner/// getPassesString - Turn a list of passes into a string which indicates the
261640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner/// command line options that must be passed to add the passes.
262640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner///
263640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattnerstd::string getPassesString(const std::vector<const PassInfo*> &Passes);
264640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner
265efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// PrintFunctionList - prints out list of problematic functions
266efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner///
267efdc0b505712d1ca4460def27e51c430f033d58dChris Lattnervoid PrintFunctionList(const std::vector<Function*> &Funcs);
268efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner
269aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner// DeleteFunctionBody - "Remove" the function by deleting all of it's basic
270aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner// blocks, making it external.
271aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner//
272aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattnervoid DeleteFunctionBody(Function *F);
273aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner
274be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// SplitFunctionsOutOfModule - Given a module and a list of functions in the
275be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// module, split the functions OUT of the specified module, and place them in
276be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// the new module.
277be21ca54e08339ede5dd4bbb882182d22e274988Chris LattnerModule *SplitFunctionsOutOfModule(Module *M, const std::vector<Function*> &F);
278be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner
279d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
280d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
281afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#endif
282