BugDriver.h revision 11b8cd197a740bc9af2f27cb88d535c4be2cdd0e
1afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner//===- BugDriver.h - Top-Level BugPoint class -------------------*- C++ -*-===//
27c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell//
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.
77c0e022c5c4be4b11e199a53f73bbdd84e34aa80John Criswell//
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;
27218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattnerclass AbstractInterpreter;
286520785dcd22012535934098942d57c07c7631c2Chris Lattnerclass Instruction;
29afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
30aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattnerclass DebugCrashes;
31640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner
32a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukmanclass CBE;
33a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukmanclass GCC;
34a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman
3547ae4a1cee5eec5767a11403c0fac7c91ec45461Chris Lattnerextern bool DisableSimplifyCFG;
3647ae4a1cee5eec5767a11403c0fac7c91ec45461Chris Lattner
37afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerclass BugDriver {
38afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  const std::string ToolName;  // Name of bugpoint
39a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman  std::string ReferenceOutputFile; // Name of `good' output file
40afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  Module *Program;             // The raw program, linked together
41afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  std::vector<const PassInfo*> PassesToRun;
42218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  AbstractInterpreter *Interpreter;   // How to run the program
43a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman  CBE *cbe;
44a259c9be2acc9528ec7feb3cfd51dcde36d87bb3Misha Brukman  GCC *gcc;
45640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner
46aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner  // FIXME: sort out public/private distinctions...
4706905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  friend class ReducePassList;
485073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  friend class ReduceMisCodegenFunctions;
495073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman
50afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattnerpublic:
515073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  BugDriver(const char *toolname);
52218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner
53218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  const std::string &getToolName() const { return ToolName; }
54afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
55afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  // Set up methods... these methods are used to copy information about the
56afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  // command line arguments into instance variables of BugDriver.
57afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  //
58afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  bool addSources(const std::vector<std::string> &FileNames);
59afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  template<class It>
60afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  void addPasses(It I, It E) { PassesToRun.insert(PassesToRun.end(), I, E); }
619c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner  void setPassesToRun(const std::vector<const PassInfo*> &PTR) {
629c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner    PassesToRun = PTR;
639c6cfe1bffd37f29a265457b7515839c445b3e6aChris Lattner  }
64efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  const std::vector<const PassInfo*> &getPassesToRun() const {
65efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner    return PassesToRun;
66efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  }
67afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
68afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// run - The top level method that is invoked after all of the instance
69afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// variables are set up from command line arguments.
70afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  ///
71afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  bool run();
72afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
73025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  /// debugOptimizerCrash - This method is called when some optimizer pass
74025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  /// crashes on input.  It attempts to prune down the testcase to something
75025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  /// reasonable, and figure out exactly which pass is crashing.
76afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  ///
77025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  bool debugOptimizerCrash();
78025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner
79025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  /// debugCodeGeneratorCrash - This method is called when the code generator
80025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  /// crashes on an input.  It attempts to reduce the input as much as possible
81025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  /// while still causing the code generator to crash.
82025262692a6710de29a48e2b3905672cd12d13d2Chris Lattner  bool debugCodeGeneratorCrash();
83afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
84afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// debugMiscompilation - This method is used when the passes selected are not
85afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// crashing, but the generated output is semantically different from the
86afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// input.
87afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  bool debugMiscompilation();
88afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
89218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// debugPassMiscompilation - This method is called when the specified pass
90218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// miscompiles Program as input.  It tries to reduce the testcase to
91218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// something that smaller that still miscompiles the program.
92218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// ReferenceOutput contains the filename of the file containing the output we
93218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// are to match.
94218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  ///
95218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  bool debugPassMiscompilation(const PassInfo *ThePass,
96218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner			       const std::string &ReferenceOutput);
97218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner
985073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  /// compileSharedObject - This method creates a SharedObject from a given
995073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  /// BytecodeFile for debugging a code generator.
100a0f5b15e1eb8642d92b3141a6b88a5729ea979dcChris Lattner  ///
101a0f5b15e1eb8642d92b3141a6b88a5729ea979dcChris Lattner  std::string compileSharedObject(const std::string &BytecodeFile);
1025073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman
1035073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  /// debugCodeGenerator - This method narrows down a module to a function or
1045073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  /// set of functions, using the CBE as a ``safe'' code generator for other
1055073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  /// functions that are not under consideration.
1065073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman  bool debugCodeGenerator();
1075073336cd4da5df4ae13a167582d1dc90f32e4e0Misha Brukman
108fe04db890b87d9ac4c4a607e6bd0035e8cc2ad6cMisha Brukman  /// isExecutingJIT - Returns true if bugpoint is currently testing the JIT
109fe04db890b87d9ac4c4a607e6bd0035e8cc2ad6cMisha Brukman  ///
11091eabc13d3a456cc4b387d3d7fdb041d976732c7Misha Brukman  bool isExecutingJIT();
11191eabc13d3a456cc4b387d3d7fdb041d976732c7Misha Brukman
11206905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  /// runPasses - Run all of the passes in the "PassesToRun" list, discard the
11306905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  /// output, and return true if any of the passes crashed.
11406905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  bool runPasses(Module *M = 0) {
11506905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner    if (M == 0) M = Program;
11606905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner    std::swap(M, Program);
11706905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner    bool Result = runPasses(PassesToRun);
11806905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner    std::swap(M, Program);
11906905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner    return Result;
12006905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  }
12106905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner
122efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  Module *getProgram() const { return Program; }
123efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner
124efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  /// swapProgramIn - Set the current module to the specified module, returning
125efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  /// the old one.
126efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  Module *swapProgramIn(Module *M) {
127efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner    Module *OldProgram = Program;
128efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner    Program = M;
129efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner    return OldProgram;
130efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  }
13106905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner
13206905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  /// setNewProgram - If we reduce or update the program somehow, call this
13306905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  /// method to update bugdriver with it.  This deletes the old module and sets
13406905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  /// the specified one as the current program.
13506905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner  void setNewProgram(Module *M);
13606905db7d2a2b83c1b3236d5552629ada2d8d56dChris Lattner
137ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner  /// compileProgram - Try to compile the specified module, throwing an
138ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner  /// exception if an error occurs, or returning normally if not.  This is used
139ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner  /// for code generation crash testing.
140ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner  ///
141ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner  void compileProgram(Module *M);
142ea9212ca964ff6587227016f86a44160e586a4c8Chris Lattner
143a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// executeProgram - This method runs "Program", capturing the output of the
144a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// program to a file, returning the filename of the file.  A recommended
145a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// filename may be optionally specified.  If there is a problem with the code
146a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// generator (e.g., llc crashes), this will throw an exception.
147a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  ///
148a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  std::string executeProgram(std::string RequestedOutputFilename = "",
149a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner                             std::string Bytecode = "",
150a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner                             const std::string &SharedObjects = "",
151a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner                             AbstractInterpreter *AI = 0,
152a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner                             bool *ProgramExitedNonzero = 0);
153a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner
154a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// executeProgramWithCBE - Used to create reference output with the C
155a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// backend, if reference output is not provided.  If there is a problem with
156a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// the code generator (e.g., llc crashes), this will throw an exception.
157a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  ///
158a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  std::string executeProgramWithCBE(std::string OutputFile = "");
159a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner
160a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// diffProgram - This method executes the specified module and diffs the
161a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// output against the file specified by ReferenceOutputFile.  If the output
162a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// is different, true is returned.  If there is a problem with the code
163a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  /// generator (e.g., llc crashes), this will throw an exception.
164a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  ///
165a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner  bool diffProgram(const std::string &BytecodeFile = "",
166a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner                   const std::string &SharedObj = "",
167a36ec88203a979a686b0ed1d49e0d7039194f040Chris Lattner                   bool RemoveBytecode = false);
1680cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// EmitProgressBytecode - This function is used to output the current Program
1690cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// to a file named "bugpoint-ID.bc".
1700cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  ///
1710cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  void EmitProgressBytecode(const std::string &ID, bool NoFlyer = false);
1720cc8807029f577996a442b96d24c3346ed6de091Chris Lattner
1730cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// deleteInstructionFromProgram - This method clones the current Program and
1740cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// deletes the specified instruction from the cloned module.  It then runs a
1750cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code
1760cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// which depends on the value.  The modified module is then returned.
1770cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  ///
1780cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  Module *deleteInstructionFromProgram(const Instruction *I, unsigned Simp)
1790cc8807029f577996a442b96d24c3346ed6de091Chris Lattner    const;
1800cc8807029f577996a442b96d24c3346ed6de091Chris Lattner
1810cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// performFinalCleanups - This method clones the current Program and performs
1820cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// a series of cleanups intended to get rid of extra cruft on the module.  If
1830cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// the MayModifySemantics argument is true, then the cleanups is allowed to
1840cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  /// modify how the code behaves.
1850cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  ///
1860cc8807029f577996a442b96d24c3346ed6de091Chris Lattner  Module *performFinalCleanups(Module *M, bool MayModifySemantics = false);
1870cc8807029f577996a442b96d24c3346ed6de091Chris Lattner
1887546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  /// ExtractLoop - Given a module, extract up to one loop from it into a new
1897546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  /// function.  This returns null if there are no extractable loops in the
1907546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  /// program or if the loop extractor crashes.
1917546c3884a400b72d10fc19f120c6798b294a39dChris Lattner  Module *ExtractLoop(Module *M);
1927546c3884a400b72d10fc19f120c6798b294a39dChris Lattner
1933b6441e1050a9a2a55c79f58513191b3195fdaf7Chris Lattner  /// runPassesOn - Carefully run the specified set of pass on the specified
1943b6441e1050a9a2a55c79f58513191b3195fdaf7Chris Lattner  /// module, returning the transformed module on success, or a null pointer on
1950a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner  /// failure.  If AutoDebugCrashes is set to true, then bugpoint will
1960a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner  /// automatically attempt to track down a crashing pass if one exists, and
1970a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner  /// this method will never return null.
1980a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner  Module *runPassesOn(Module *M, const std::vector<const PassInfo*> &Passes,
1990a002569003fd23a4e117fe54a9bb8a6673b86daChris Lattner                      bool AutoDebugCrashes = false);
2003b6441e1050a9a2a55c79f58513191b3195fdaf7Chris Lattner
201afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// runPasses - Run the specified passes on Program, outputting a bytecode
202afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// file and writting the filename into OutputFile if successful.  If the
203afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// optimizations fail for some reason (optimizer crashes), return true,
204afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// otherwise return false.  If DeleteOutput is set to true, the bytecode is
205afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// deleted on success, and the filename string is undefined.  This prints to
206afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// cout a single line message indicating whether compilation was successful
207218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// or failed, unless Quiet is set.
208afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  ///
209afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
210218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner                 std::string &OutputFilename, bool DeleteOutput = false,
211218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner		 bool Quiet = false) const;
21211b8cd197a740bc9af2f27cb88d535c4be2cdd0eChris Lattner
213efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  /// writeProgramToFile - This writes the current "Program" to the named
214efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  /// bytecode file.  If an error occurs, true is returned.
215efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  ///
216efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner  bool writeProgramToFile(const std::string &Filename, Module *M = 0) const;
217afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
21811b8cd197a740bc9af2f27cb88d535c4be2cdd0eChris Lattnerprivate:
219afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// runPasses - Just like the method above, but this just returns true or
220afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// false indicating whether or not the optimizer crashed on the specified
221afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  /// input (true = crashed).
222afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  ///
223afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
224afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner                 bool DeleteOutput = true) const {
225afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner    std::string Filename;
226afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner    return runPasses(PassesToRun, Filename, DeleteOutput);
227afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner  }
228afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
229218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// initializeExecutionEnvironment - This method is used to set up the
230218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  /// environment for executing LLVM programs.
231218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  ///
232218e26ef3583cc3270f5f2a2b9cb1025e5b05ebeChris Lattner  bool initializeExecutionEnvironment();
233afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner};
234afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner
235efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// ParseInputFile - Given a bytecode or assembly input filename, parse and
236efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// return it, or return null if not possible.
237efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner///
238efdc0b505712d1ca4460def27e51c430f033d58dChris LattnerModule *ParseInputFile(const std::string &InputFilename);
239efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner
240efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner
241640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner/// getPassesString - Turn a list of passes into a string which indicates the
242640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner/// command line options that must be passed to add the passes.
243640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner///
244640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattnerstd::string getPassesString(const std::vector<const PassInfo*> &Passes);
245640f22e66d90439857a97a83896ee68c4f7128c9Chris Lattner
246efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner/// PrintFunctionList - prints out list of problematic functions
247efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner///
248efdc0b505712d1ca4460def27e51c430f033d58dChris Lattnervoid PrintFunctionList(const std::vector<Function*> &Funcs);
249efdc0b505712d1ca4460def27e51c430f033d58dChris Lattner
250aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner// DeleteFunctionBody - "Remove" the function by deleting all of it's basic
251aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner// blocks, making it external.
252aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner//
253aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattnervoid DeleteFunctionBody(Function *F);
254aae33f9137e4a64394d8f9fe66611ae53a0ef4e8Chris Lattner
255be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// SplitFunctionsOutOfModule - Given a module and a list of functions in the
256be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// module, split the functions OUT of the specified module, and place them in
257be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner/// the new module.
258be21ca54e08339ede5dd4bbb882182d22e274988Chris LattnerModule *SplitFunctionsOutOfModule(Module *M, const std::vector<Function*> &F);
259be21ca54e08339ede5dd4bbb882182d22e274988Chris Lattner
260d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
261d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
262afade9294af43c6b947b9aeaa1555883d5f853e3Chris Lattner#endif
263