1 //===- BugDriver.h - Top-Level BugPoint class -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class contains all of the shared state and information that is used by
11 // the BugPoint tool to track down errors in optimizations. This class is the
12 // main driver class that invokes all sub-functionality.
14 //===----------------------------------------------------------------------===//
25 class AbstractInterpreter;
29 class ReduceMiscompilingPasses;
30 class ReduceMiscompilingFunctions;
31 class ReduceCrashingFunctions;
32 class ReduceCrashingBlocks;
37 extern bool DisableSimplifyCFG;
40 const std::string ToolName; // Name of bugpoint
41 std::string ReferenceOutputFile; // Name of `good' output file
42 Module *Program; // The raw program, linked together
43 std::vector<const PassInfo*> PassesToRun;
44 AbstractInterpreter *Interpreter; // How to run the program
48 // FIXME: sort out public/private distinctions...
49 friend class DebugCrashes;
50 friend class ReduceMiscompilingPasses;
51 friend class ReduceMiscompilingFunctions;
52 friend class ReduceMisCodegenFunctions;
53 friend class ReduceCrashingFunctions;
54 friend class ReduceCrashingBlocks;
57 BugDriver(const char *toolname);
59 const std::string &getToolName() const { return ToolName; }
61 // Set up methods... these methods are used to copy information about the
62 // command line arguments into instance variables of BugDriver.
64 bool addSources(const std::vector<std::string> &FileNames);
66 void addPasses(It I, It E) { PassesToRun.insert(PassesToRun.end(), I, E); }
67 void setPassesToRun(const std::vector<const PassInfo*> &PTR) {
71 /// run - The top level method that is invoked after all of the instance
72 /// variables are set up from command line arguments.
76 /// debugCrash - This method is called when some pass crashes on input. It
77 /// attempts to prune down the testcase to something reasonable, and figure
78 /// out exactly which pass is crashing.
82 /// debugMiscompilation - This method is used when the passes selected are not
83 /// crashing, but the generated output is semantically different from the
85 bool debugMiscompilation();
87 /// debugPassMiscompilation - This method is called when the specified pass
88 /// miscompiles Program as input. It tries to reduce the testcase to
89 /// something that smaller that still miscompiles the program.
90 /// ReferenceOutput contains the filename of the file containing the output we
93 bool debugPassMiscompilation(const PassInfo *ThePass,
94 const std::string &ReferenceOutput);
96 /// compileSharedObject - This method creates a SharedObject from a given
97 /// BytecodeFile for debugging a code generator.
99 std::string compileSharedObject(const std::string &BytecodeFile);
101 /// debugCodeGenerator - This method narrows down a module to a function or
102 /// set of functions, using the CBE as a ``safe'' code generator for other
103 /// functions that are not under consideration.
104 bool debugCodeGenerator();
106 /// isExecutingJIT - Returns true if bugpoint is currently testing the JIT
108 bool isExecutingJIT();
111 /// ParseInputFile - Given a bytecode or assembly input filename, parse and
112 /// return it, or return null if not possible.
114 Module *ParseInputFile(const std::string &InputFilename) const;
116 /// writeProgramToFile - This writes the current "Program" to the named
117 /// bytecode file. If an error occurs, true is returned.
119 bool writeProgramToFile(const std::string &Filename, Module *M = 0) const;
122 /// EmitProgressBytecode - This function is used to output the current Program
123 /// to a file named "bugpoing-ID.bc".
125 void EmitProgressBytecode(const std::string &ID, bool NoFlyer = false);
127 /// runPasses - Run the specified passes on Program, outputting a bytecode
128 /// file and writting the filename into OutputFile if successful. If the
129 /// optimizations fail for some reason (optimizer crashes), return true,
130 /// otherwise return false. If DeleteOutput is set to true, the bytecode is
131 /// deleted on success, and the filename string is undefined. This prints to
132 /// cout a single line message indicating whether compilation was successful
133 /// or failed, unless Quiet is set.
135 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
136 std::string &OutputFilename, bool DeleteOutput = false,
137 bool Quiet = false) const;
139 /// runPasses - Just like the method above, but this just returns true or
140 /// false indicating whether or not the optimizer crashed on the specified
141 /// input (true = crashed).
143 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
144 bool DeleteOutput = true) const {
145 std::string Filename;
146 return runPasses(PassesToRun, Filename, DeleteOutput);
149 /// PrintFunctionList - prints out list of problematic functions
151 static void PrintFunctionList(const std::vector<Function*> &Funcs);
153 /// deleteInstructionFromProgram - This method clones the current Program and
154 /// deletes the specified instruction from the cloned module. It then runs a
155 /// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code
156 /// which depends on the value. The modified module is then returned.
158 Module *deleteInstructionFromProgram(Instruction *I, unsigned Simp) const;
160 /// performFinalCleanups - This method clones the current Program and performs
161 /// a series of cleanups intended to get rid of extra cruft on the module
162 /// before handing it to the user... if the module parameter is specified, it
163 /// operates directly on the specified Module, modifying it in place.
165 Module *performFinalCleanups(Module *M = 0) const;
167 /// initializeExecutionEnvironment - This method is used to set up the
168 /// environment for executing LLVM programs.
170 bool initializeExecutionEnvironment();
172 /// executeProgram - This method runs "Program", capturing the output of the
173 /// program to a file, returning the filename of the file. A recommended
174 /// filename may be optionally specified.
176 std::string executeProgram(std::string RequestedOutputFilename = "",
177 std::string Bytecode = "",
178 const std::string &SharedObjects = "",
179 AbstractInterpreter *AI = 0);
181 /// executeProgramWithCBE - Used to create reference output with the C
182 /// backend, if reference output is not provided.
184 std::string executeProgramWithCBE(std::string OutputFile = "",
185 std::string BytecodeFile = "",
186 const std::string &SharedObj = "") {
187 return executeProgram(OutputFile, BytecodeFile, SharedObj,
188 (AbstractInterpreter*)cbe);
191 /// diffProgram - This method executes the specified module and diffs the
192 /// output against the file specified by ReferenceOutputFile. If the output
193 /// is different, true is returned.
195 bool diffProgram(const std::string &BytecodeFile = "",
196 const std::string &SharedObj = "",
197 bool RemoveBytecode = false);
200 /// getPassesString - Turn a list of passes into a string which indicates the
201 /// command line options that must be passed to add the passes.
203 std::string getPassesString(const std::vector<const PassInfo*> &Passes);
205 // DeleteFunctionBody - "Remove" the function by deleting all of it's basic
206 // blocks, making it external.
208 void DeleteFunctionBody(Function *F);