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 //===----------------------------------------------------------------------===//
27 class AbstractInterpreter;
31 class ReduceMiscompilingPasses;
32 class ReduceMiscompilingFunctions;
33 class ReduceCrashingFunctions;
34 class ReduceCrashingBlocks;
39 extern bool DisableSimplifyCFG;
42 const std::string ToolName; // Name of bugpoint
43 std::string ReferenceOutputFile; // Name of `good' output file
44 Module *Program; // The raw program, linked together
45 std::vector<const PassInfo*> PassesToRun;
46 AbstractInterpreter *Interpreter; // How to run the program
50 // FIXME: sort out public/private distinctions...
51 friend class DebugCrashes;
52 friend class ReduceMiscompilingPasses;
53 friend class ReduceMiscompilingFunctions;
54 friend class ReduceMisCodegenFunctions;
55 friend class ReduceCrashingFunctions;
56 friend class ReduceCrashingBlocks;
59 BugDriver(const char *toolname);
61 const std::string &getToolName() const { return ToolName; }
63 // Set up methods... these methods are used to copy information about the
64 // command line arguments into instance variables of BugDriver.
66 bool addSources(const std::vector<std::string> &FileNames);
68 void addPasses(It I, It E) { PassesToRun.insert(PassesToRun.end(), I, E); }
69 void setPassesToRun(const std::vector<const PassInfo*> &PTR) {
73 /// run - The top level method that is invoked after all of the instance
74 /// variables are set up from command line arguments.
78 /// debugCrash - This method is called when some pass crashes on input. It
79 /// attempts to prune down the testcase to something reasonable, and figure
80 /// out exactly which pass is crashing.
84 /// debugMiscompilation - This method is used when the passes selected are not
85 /// crashing, but the generated output is semantically different from the
87 bool debugMiscompilation();
89 /// debugPassMiscompilation - This method is called when the specified pass
90 /// miscompiles Program as input. It tries to reduce the testcase to
91 /// something that smaller that still miscompiles the program.
92 /// ReferenceOutput contains the filename of the file containing the output we
95 bool debugPassMiscompilation(const PassInfo *ThePass,
96 const std::string &ReferenceOutput);
98 /// compileSharedObject - This method creates a SharedObject from a given
99 /// BytecodeFile for debugging a code generator.
101 std::string compileSharedObject(const std::string &BytecodeFile);
103 /// debugCodeGenerator - This method narrows down a module to a function or
104 /// set of functions, using the CBE as a ``safe'' code generator for other
105 /// functions that are not under consideration.
106 bool debugCodeGenerator();
108 /// isExecutingJIT - Returns true if bugpoint is currently testing the JIT
110 bool isExecutingJIT();
113 /// ParseInputFile - Given a bytecode or assembly input filename, parse and
114 /// return it, or return null if not possible.
116 Module *ParseInputFile(const std::string &InputFilename) const;
118 /// writeProgramToFile - This writes the current "Program" to the named
119 /// bytecode file. If an error occurs, true is returned.
121 bool writeProgramToFile(const std::string &Filename, Module *M = 0) const;
124 /// EmitProgressBytecode - This function is used to output the current Program
125 /// to a file named "bugpoint-ID.bc".
127 void EmitProgressBytecode(const std::string &ID, bool NoFlyer = false);
129 /// runPasses - Run the specified passes on Program, outputting a bytecode
130 /// file and writting the filename into OutputFile if successful. If the
131 /// optimizations fail for some reason (optimizer crashes), return true,
132 /// otherwise return false. If DeleteOutput is set to true, the bytecode is
133 /// deleted on success, and the filename string is undefined. This prints to
134 /// cout a single line message indicating whether compilation was successful
135 /// or failed, unless Quiet is set.
137 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
138 std::string &OutputFilename, bool DeleteOutput = false,
139 bool Quiet = false) const;
141 /// runPasses - Just like the method above, but this just returns true or
142 /// false indicating whether or not the optimizer crashed on the specified
143 /// input (true = crashed).
145 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
146 bool DeleteOutput = true) const {
147 std::string Filename;
148 return runPasses(PassesToRun, Filename, DeleteOutput);
151 /// PrintFunctionList - prints out list of problematic functions
153 static void PrintFunctionList(const std::vector<Function*> &Funcs);
155 /// deleteInstructionFromProgram - This method clones the current Program and
156 /// deletes the specified instruction from the cloned module. It then runs a
157 /// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code
158 /// which depends on the value. The modified module is then returned.
160 Module *deleteInstructionFromProgram(Instruction *I, unsigned Simp) const;
162 /// performFinalCleanups - This method clones the current Program and performs
163 /// a series of cleanups intended to get rid of extra cruft on the module. If
164 /// the MayModifySemantics argument is true, then the cleanups is allowed to
165 /// modify how the code behaves.
167 Module *performFinalCleanups(Module *M, bool MayModifySemantics = false);
169 /// initializeExecutionEnvironment - This method is used to set up the
170 /// environment for executing LLVM programs.
172 bool initializeExecutionEnvironment();
174 /// executeProgram - This method runs "Program", capturing the output of the
175 /// program to a file, returning the filename of the file. A recommended
176 /// filename may be optionally specified. If there is a problem with the code
177 /// generator (e.g., llc crashes), this will throw an exception.
179 std::string executeProgram(std::string RequestedOutputFilename = "",
180 std::string Bytecode = "",
181 const std::string &SharedObjects = "",
182 AbstractInterpreter *AI = 0,
183 bool *ProgramExitedNonzero = 0);
185 /// executeProgramWithCBE - Used to create reference output with the C
186 /// backend, if reference output is not provided. If there is a problem with
187 /// the code generator (e.g., llc crashes), this will throw an exception.
189 std::string executeProgramWithCBE(std::string OutputFile = "");
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. If there is a problem with the code
194 /// generator (e.g., llc crashes), this will throw an exception.
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);
211 } // End llvm namespace