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 //===----------------------------------------------------------------------===//
17 class AbstractInterpreter;
21 class ReduceMiscompilingPasses;
22 class ReduceMiscompilingFunctions;
23 class ReduceCrashingFunctions;
24 class ReduceCrashingBlocks;
27 const std::string ToolName; // Name of bugpoint
28 Module *Program; // The raw program, linked together
29 std::vector<const PassInfo*> PassesToRun;
30 AbstractInterpreter *Interpreter; // How to run the program
32 // FIXME: sort out public/private distinctions...
33 friend class DebugCrashes;
34 friend class ReduceMiscompilingPasses;
35 friend class ReduceMiscompilingFunctions;
36 friend class ReduceCrashingFunctions;
37 friend class ReduceCrashingBlocks;
39 BugDriver(const char *toolname)
40 : ToolName(toolname), Program(0), Interpreter(0) {}
42 const std::string &getToolName() const { return ToolName; }
44 // Set up methods... these methods are used to copy information about the
45 // command line arguments into instance variables of BugDriver.
47 bool addSources(const std::vector<std::string> &FileNames);
49 void addPasses(It I, It E) { PassesToRun.insert(PassesToRun.end(), I, E); }
51 /// run - The top level method that is invoked after all of the instance
52 /// variables are set up from command line arguments.
56 /// debugCrash - This method is called when some pass crashes on input. It
57 /// attempts to prune down the testcase to something reasonable, and figure
58 /// out exactly which pass is crashing.
62 /// debugMiscompilation - This method is used when the passes selected are not
63 /// crashing, but the generated output is semantically different from the
65 bool debugMiscompilation();
67 /// debugPassMiscompilation - This method is called when the specified pass
68 /// miscompiles Program as input. It tries to reduce the testcase to
69 /// something that smaller that still miscompiles the program.
70 /// ReferenceOutput contains the filename of the file containing the output we
73 bool debugPassMiscompilation(const PassInfo *ThePass,
74 const std::string &ReferenceOutput);
77 /// ParseInputFile - Given a bytecode or assembly input filename, parse and
78 /// return it, or return null if not possible.
80 Module *ParseInputFile(const std::string &InputFilename) const;
82 /// writeProgramToFile - This writes the current "Program" to the named
83 /// bytecode file. If an error occurs, true is returned.
85 bool writeProgramToFile(const std::string &Filename, Module *M = 0) const;
88 /// EmitProgressBytecode - This function is used to output the current Program
89 /// to a file named "bugpoing-ID.bc".
91 void EmitProgressBytecode(const std::string &ID, bool NoFlyer = false);
93 /// runPasses - Run the specified passes on Program, outputting a bytecode
94 /// file and writting the filename into OutputFile if successful. If the
95 /// optimizations fail for some reason (optimizer crashes), return true,
96 /// otherwise return false. If DeleteOutput is set to true, the bytecode is
97 /// deleted on success, and the filename string is undefined. This prints to
98 /// cout a single line message indicating whether compilation was successful
99 /// or failed, unless Quiet is set.
101 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
102 std::string &OutputFilename, bool DeleteOutput = false,
103 bool Quiet = false) const;
105 /// runPasses - Just like the method above, but this just returns true or
106 /// false indicating whether or not the optimizer crashed on the specified
107 /// input (true = crashed).
109 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
110 bool DeleteOutput = true) const {
111 std::string Filename;
112 return runPasses(PassesToRun, Filename, DeleteOutput);
115 /// deleteInstructionFromProgram - This method clones the current Program and
116 /// deletes the specified instruction from the cloned module. It then runs a
117 /// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code
118 /// which depends on the value. The modified module is then returned.
120 Module *deleteInstructionFromProgram(Instruction *I, unsigned Simp) const;
122 /// performFinalCleanups - This method clones the current Program and performs
123 /// a series of cleanups intended to get rid of extra cruft on the module
124 /// before handing it to the user...
126 Module *performFinalCleanups() const;
128 /// initializeExecutionEnvironment - This method is used to set up the
129 /// environment for executing LLVM programs.
131 bool initializeExecutionEnvironment();
133 /// executeProgram - This method runs "Program", capturing the output of the
134 /// program to a file, returning the filename of the file. A recommended
135 /// filename may be optionally specified.
137 std::string executeProgram(std::string RequestedOutputFilename = "",
138 std::string Bytecode = "");
140 /// diffProgram - This method executes the specified module and diffs the
141 /// output against the file specified by ReferenceOutputFile. If the output
142 /// is different, true is returned.
144 bool diffProgram(const std::string &ReferenceOutputFile,
145 const std::string &BytecodeFile = "",
146 bool RemoveBytecode = false);
149 /// getPassesString - Turn a list of passes into a string which indicates the
150 /// command line options that must be passed to add the passes.
152 std::string getPassesString(const std::vector<const PassInfo*> &Passes);
154 // DeleteFunctionBody - "Remove" the function by deleting all of it's basic
155 // blocks, making it external.
157 void DeleteFunctionBody(Function *F);