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 const std::string ToolName; // Name of bugpoint
22 Module *Program; // The raw program, linked together
23 std::vector<const PassInfo*> PassesToRun;
24 AbstractInterpreter *Interpreter; // How to run the program
26 BugDriver(const char *toolname)
27 : ToolName(toolname), Program(0), Interpreter(0) {}
29 const std::string &getToolName() const { return ToolName; }
31 // Set up methods... these methods are used to copy information about the
32 // command line arguments into instance variables of BugDriver.
34 bool addSources(const std::vector<std::string> &FileNames);
36 void addPasses(It I, It E) { PassesToRun.insert(PassesToRun.end(), I, E); }
38 /// run - The top level method that is invoked after all of the instance
39 /// variables are set up from command line arguments.
43 /// debugCrash - This method is called when some pass crashes on input. It
44 /// attempts to prune down the testcase to something reasonable, and figure
45 /// out exactly which pass is crashing.
49 /// debugPassCrash - This method is called when the specified pass crashes on
50 /// Program as input. It tries to reduce the testcase to something that still
51 /// crashes, but it smaller.
53 bool debugPassCrash(const PassInfo *PI);
55 /// debugMiscompilation - This method is used when the passes selected are not
56 /// crashing, but the generated output is semantically different from the
58 bool debugMiscompilation();
60 /// debugPassMiscompilation - This method is called when the specified pass
61 /// miscompiles Program as input. It tries to reduce the testcase to
62 /// something that smaller that still miscompiles the program.
63 /// ReferenceOutput contains the filename of the file containing the output we
66 bool debugPassMiscompilation(const PassInfo *ThePass,
67 const std::string &ReferenceOutput);
70 /// ParseInputFile - Given a bytecode or assembly input filename, parse and
71 /// return it, or return null if not possible.
73 Module *ParseInputFile(const std::string &InputFilename) const;
75 /// writeProgramToFile - This writes the current "Program" to the named
76 /// bytecode file. If an error occurs, true is returned.
78 bool writeProgramToFile(const std::string &Filename, Module *M = 0) const;
81 /// EmitProgressBytecode - This function is used to output the current Program
82 /// to a file named "bugpoing-ID.bc".
84 void EmitProgressBytecode(const PassInfo *Pass, const std::string &ID);
86 /// runPasses - Run the specified passes on Program, outputting a bytecode
87 /// file and writting the filename into OutputFile if successful. If the
88 /// optimizations fail for some reason (optimizer crashes), return true,
89 /// otherwise return false. If DeleteOutput is set to true, the bytecode is
90 /// deleted on success, and the filename string is undefined. This prints to
91 /// cout a single line message indicating whether compilation was successful
92 /// or failed, unless Quiet is set.
94 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
95 std::string &OutputFilename, bool DeleteOutput = false,
96 bool Quiet = false) const;
98 /// runPasses - Just like the method above, but this just returns true or
99 /// false indicating whether or not the optimizer crashed on the specified
100 /// input (true = crashed).
102 bool runPasses(const std::vector<const PassInfo*> &PassesToRun,
103 bool DeleteOutput = true) const {
104 std::string Filename;
105 return runPasses(PassesToRun, Filename, DeleteOutput);
108 /// runPass - Run only the specified pass on the program.
110 bool runPass(const PassInfo *P, bool DeleteOutput = true) const {
111 return runPasses(std::vector<const PassInfo*>(1, P), DeleteOutput);
114 /// extractFunctionFromModule - This method is used to extract the specified
115 /// (non-external) function from the current program, slim down the module,
116 /// and then return it. This does not modify Program at all, it modifies a
117 /// copy, which it returns.
119 Module *extractFunctionFromModule(Function *F) const;
121 /// deleteInstructionFromProgram - This method clones the current Program and
122 /// deletes the specified instruction from the cloned module. It then runs a
123 /// series of cleanup passes (ADCE and SimplifyCFG) to eliminate any code
124 /// which depends on the value. The modified module is then returned.
126 Module *deleteInstructionFromProgram(Instruction *I, unsigned Simp) 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 = "");