1 //===- BugDriver.h - Top-Level BugPoint class -------------------*- C++ -*-===//
3 // This class contains all of the shared state and information that is used by
4 // the BugPoint tool to track down errors in optimizations. This class is the
5 // main driver class that invokes all sub-functionality.
7 //===----------------------------------------------------------------------===//
18 class AbstractInterpreter;
22 class ReduceMiscompilingPasses;
23 class ReduceMiscompilingFunctions;
24 class ReduceCrashingFunctions;
25 class ReduceCrashingBlocks;
30 extern bool DisableSimplifyCFG;
33 const std::string ToolName; // Name of bugpoint
34 std::string ReferenceOutputFile; // Name of `good' output file
35 Module *Program; // The raw program, linked together
36 std::vector<const PassInfo*> PassesToRun;
37 AbstractInterpreter *Interpreter; // How to run the program
41 // FIXME: sort out public/private distinctions...
42 friend class DebugCrashes;
43 friend class ReduceMiscompilingPasses;
44 friend class ReduceMiscompilingFunctions;
45 friend class ReduceMisCodegenFunctions;
46 friend class ReduceCrashingFunctions;
47 friend class ReduceCrashingBlocks;
50 BugDriver(const char *toolname);
52 const std::string &getToolName() const { return ToolName; }
54 // Set up methods... these methods are used to copy information about the
55 // command line arguments into instance variables of BugDriver.
57 bool addSources(const std::vector<std::string> &FileNames);
59 void addPasses(It I, It E) { PassesToRun.insert(PassesToRun.end(), I, E); }
61 /// run - The top level method that is invoked after all of the instance
62 /// variables are set up from command line arguments.
66 /// debugCrash - This method is called when some pass crashes on input. It
67 /// attempts to prune down the testcase to something reasonable, and figure
68 /// out exactly which pass is crashing.
72 /// debugMiscompilation - This method is used when the passes selected are not
73 /// crashing, but the generated output is semantically different from the
75 bool debugMiscompilation();
77 /// debugPassMiscompilation - This method is called when the specified pass
78 /// miscompiles Program as input. It tries to reduce the testcase to
79 /// something that smaller that still miscompiles the program.
80 /// ReferenceOutput contains the filename of the file containing the output we
83 bool debugPassMiscompilation(const PassInfo *ThePass,
84 const std::string &ReferenceOutput);
86 /// compileSharedObject - This method creates a SharedObject from a given
87 /// BytecodeFile for debugging a code generator.
89 std::string compileSharedObject(const std::string &BytecodeFile);
91 /// debugCodeGenerator - This method narrows down a module to a function or
92 /// set of functions, using the CBE as a ``safe'' code generator for other
93 /// functions that are not under consideration.
94 bool debugCodeGenerator();
96 /// isExecutingJIT - Returns true if bugpoint is currently testing the JIT
98 bool isExecutingJIT();
101 /// ParseInputFile - Given a bytecode or assembly input filename, parse and
102 /// return it, or return null if not possible.
104 Module *ParseInputFile(const std::string &InputFilename) const;
106 /// writeProgramToFile - This writes the current "Program" to the named
107 /// bytecode file. If an error occurs, true is returned.
109 bool writeProgramToFile(const std::string &Filename, Module *M = 0) const;
112 /// EmitProgressBytecode - This function is used to output the current Program
113 /// to a file named "bugpoing-ID.bc".
115 void EmitProgressBytecode(const std::string &ID, bool NoFlyer = false);
117 /// runPasses - Run the specified passes on Program, outputting a bytecode
118 /// file and writting the filename into OutputFile if successful. If the
119 /// optimizations fail for some reason (optimizer crashes), return true,
120 /// otherwise return false. If DeleteOutput is set to true, the bytecode is
121 /// deleted on success, and the filename string is undefined. This prints to
122 /// cout a single line message indicating whether compilation was successful
123 /// or failed, unless Quiet is set.
125 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
126 std::string &OutputFilename, bool DeleteOutput = false,
127 bool Quiet = false) const;
129 /// runPasses - Just like the method above, but this just returns true or
130 /// false indicating whether or not the optimizer crashed on the specified
131 /// input (true = crashed).
133 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
134 bool DeleteOutput = true) const {
135 std::string Filename;
136 return runPasses(PassesToRun, Filename, DeleteOutput);
139 /// PrintFunctionList - prints out list of problematic functions
141 static void PrintFunctionList(const std::vector<Function*> &Funcs);
143 /// deleteInstructionFromProgram - This method clones the current Program and
144 /// deletes the specified instruction from the cloned module. It then runs a
145 /// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code
146 /// which depends on the value. The modified module is then returned.
148 Module *deleteInstructionFromProgram(Instruction *I, unsigned Simp) const;
150 /// performFinalCleanups - This method clones the current Program and performs
151 /// a series of cleanups intended to get rid of extra cruft on the module
152 /// before handing it to the user... if the module parameter is specified, it
153 /// operates directly on the specified Module, modifying it in place.
155 Module *performFinalCleanups(Module *M = 0) const;
157 /// initializeExecutionEnvironment - This method is used to set up the
158 /// environment for executing LLVM programs.
160 bool initializeExecutionEnvironment();
162 /// executeProgram - This method runs "Program", capturing the output of the
163 /// program to a file, returning the filename of the file. A recommended
164 /// filename may be optionally specified.
166 std::string executeProgram(std::string RequestedOutputFilename = "",
167 std::string Bytecode = "",
168 std::string SharedObject = "",
169 AbstractInterpreter *AI = 0);
171 /// executeProgramWithCBE - Used to create reference output with the C
172 /// backend, if reference output is not provided.
173 std::string executeProgramWithCBE(std::string RequestedOutputFilename = "",
174 std::string Bytecode = "",
175 std::string SharedObject = "");
177 /// diffProgram - This method executes the specified module and diffs the
178 /// output against the file specified by ReferenceOutputFile. If the output
179 /// is different, true is returned.
181 bool diffProgram(const std::string &BytecodeFile = "",
182 const std::string &SharedObject = "",
183 bool RemoveBytecode = false);
186 /// getPassesString - Turn a list of passes into a string which indicates the
187 /// command line options that must be passed to add the passes.
189 std::string getPassesString(const std::vector<const PassInfo*> &Passes);
191 // DeleteFunctionBody - "Remove" the function by deleting all of it's basic
192 // blocks, making it external.
194 void DeleteFunctionBody(Function *F);