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 //===----------------------------------------------------------------------===//
11 // This class contains all of the shared state and information that is used by
12 // the BugPoint tool to track down errors in optimizations. This class is the
13 // main driver class that invokes all sub-functionality.
15 //===----------------------------------------------------------------------===//
26 class AbstractInterpreter;
30 class ReduceMiscompilingPasses;
31 class ReduceMiscompilingFunctions;
32 class ReduceCrashingFunctions;
33 class ReduceCrashingBlocks;
38 extern bool DisableSimplifyCFG;
41 const std::string ToolName; // Name of bugpoint
42 std::string ReferenceOutputFile; // Name of `good' output file
43 Module *Program; // The raw program, linked together
44 std::vector<const PassInfo*> PassesToRun;
45 AbstractInterpreter *Interpreter; // How to run the program
49 // FIXME: sort out public/private distinctions...
50 friend class DebugCrashes;
51 friend class ReduceMiscompilingPasses;
52 friend class ReduceMiscompilingFunctions;
53 friend class ReduceMisCodegenFunctions;
54 friend class ReduceCrashingFunctions;
55 friend class ReduceCrashingBlocks;
58 BugDriver(const char *toolname);
60 const std::string &getToolName() const { return ToolName; }
62 // Set up methods... these methods are used to copy information about the
63 // command line arguments into instance variables of BugDriver.
65 bool addSources(const std::vector<std::string> &FileNames);
67 void addPasses(It I, It E) { PassesToRun.insert(PassesToRun.end(), I, E); }
68 void setPassesToRun(const std::vector<const PassInfo*> &PTR) {
72 /// run - The top level method that is invoked after all of the instance
73 /// variables are set up from command line arguments.
77 /// debugCrash - This method is called when some pass crashes on input. It
78 /// attempts to prune down the testcase to something reasonable, and figure
79 /// out exactly which pass is crashing.
83 /// debugMiscompilation - This method is used when the passes selected are not
84 /// crashing, but the generated output is semantically different from the
86 bool debugMiscompilation();
88 /// debugPassMiscompilation - This method is called when the specified pass
89 /// miscompiles Program as input. It tries to reduce the testcase to
90 /// something that smaller that still miscompiles the program.
91 /// ReferenceOutput contains the filename of the file containing the output we
94 bool debugPassMiscompilation(const PassInfo *ThePass,
95 const std::string &ReferenceOutput);
97 /// compileSharedObject - This method creates a SharedObject from a given
98 /// BytecodeFile for debugging a code generator.
100 std::string compileSharedObject(const std::string &BytecodeFile);
102 /// debugCodeGenerator - This method narrows down a module to a function or
103 /// set of functions, using the CBE as a ``safe'' code generator for other
104 /// functions that are not under consideration.
105 bool debugCodeGenerator();
107 /// isExecutingJIT - Returns true if bugpoint is currently testing the JIT
109 bool isExecutingJIT();
112 /// ParseInputFile - Given a bytecode or assembly input filename, parse and
113 /// return it, or return null if not possible.
115 Module *ParseInputFile(const std::string &InputFilename) const;
117 /// writeProgramToFile - This writes the current "Program" to the named
118 /// bytecode file. If an error occurs, true is returned.
120 bool writeProgramToFile(const std::string &Filename, Module *M = 0) const;
123 /// EmitProgressBytecode - This function is used to output the current Program
124 /// to a file named "bugpoing-ID.bc".
126 void EmitProgressBytecode(const std::string &ID, bool NoFlyer = false);
128 /// runPasses - Run the specified passes on Program, outputting a bytecode
129 /// file and writting the filename into OutputFile if successful. If the
130 /// optimizations fail for some reason (optimizer crashes), return true,
131 /// otherwise return false. If DeleteOutput is set to true, the bytecode is
132 /// deleted on success, and the filename string is undefined. This prints to
133 /// cout a single line message indicating whether compilation was successful
134 /// or failed, unless Quiet is set.
136 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
137 std::string &OutputFilename, bool DeleteOutput = false,
138 bool Quiet = false) const;
140 /// runPasses - Just like the method above, but this just returns true or
141 /// false indicating whether or not the optimizer crashed on the specified
142 /// input (true = crashed).
144 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
145 bool DeleteOutput = true) const {
146 std::string Filename;
147 return runPasses(PassesToRun, Filename, DeleteOutput);
150 /// PrintFunctionList - prints out list of problematic functions
152 static void PrintFunctionList(const std::vector<Function*> &Funcs);
154 /// deleteInstructionFromProgram - This method clones the current Program and
155 /// deletes the specified instruction from the cloned module. It then runs a
156 /// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code
157 /// which depends on the value. The modified module is then returned.
159 Module *deleteInstructionFromProgram(Instruction *I, unsigned Simp) const;
161 /// performFinalCleanups - This method clones the current Program and performs
162 /// a series of cleanups intended to get rid of extra cruft on the module
163 /// before handing it to the user... if the module parameter is specified, it
164 /// operates directly on the specified Module, modifying it in place.
166 Module *performFinalCleanups(Module *M = 0) const;
168 /// initializeExecutionEnvironment - This method is used to set up the
169 /// environment for executing LLVM programs.
171 bool initializeExecutionEnvironment();
173 /// executeProgram - This method runs "Program", capturing the output of the
174 /// program to a file, returning the filename of the file. A recommended
175 /// filename may be optionally specified.
177 std::string executeProgram(std::string RequestedOutputFilename = "",
178 std::string Bytecode = "",
179 const std::string &SharedObjects = "",
180 AbstractInterpreter *AI = 0);
182 /// executeProgramWithCBE - Used to create reference output with the C
183 /// backend, if reference output is not provided.
185 std::string executeProgramWithCBE(std::string OutputFile = "",
186 std::string BytecodeFile = "",
187 const std::string &SharedObj = "") {
188 return executeProgram(OutputFile, BytecodeFile, SharedObj,
189 (AbstractInterpreter*)cbe);
192 /// diffProgram - This method executes the specified module and diffs the
193 /// output against the file specified by ReferenceOutputFile. If the output
194 /// is different, true is returned.
196 bool diffProgram(const std::string &BytecodeFile = "",
197 const std::string &SharedObj = "",
198 bool RemoveBytecode = false);
201 /// getPassesString - Turn a list of passes into a string which indicates the
202 /// command line options that must be passed to add the passes.
204 std::string getPassesString(const std::vector<const PassInfo*> &Passes);
206 // DeleteFunctionBody - "Remove" the function by deleting all of it's basic
207 // blocks, making it external.
209 void DeleteFunctionBody(Function *F);