xref: /aosp_15_r20/external/llvm/tools/bugpoint/BugDriver.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===- BugDriver.h - Top-Level BugPoint class -------------------*- C++ -*-===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This class contains all of the shared state and information that is used by
11*9880d681SAndroid Build Coastguard Worker // the BugPoint tool to track down errors in optimizations.  This class is the
12*9880d681SAndroid Build Coastguard Worker // main driver class that invokes all sub-functionality.
13*9880d681SAndroid Build Coastguard Worker //
14*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
15*9880d681SAndroid Build Coastguard Worker 
16*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_TOOLS_BUGPOINT_BUGDRIVER_H
17*9880d681SAndroid Build Coastguard Worker #define LLVM_TOOLS_BUGPOINT_BUGDRIVER_H
18*9880d681SAndroid Build Coastguard Worker 
19*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/ValueMap.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/Transforms/Utils/ValueMapper.h"
21*9880d681SAndroid Build Coastguard Worker #include <memory>
22*9880d681SAndroid Build Coastguard Worker #include <string>
23*9880d681SAndroid Build Coastguard Worker #include <vector>
24*9880d681SAndroid Build Coastguard Worker 
25*9880d681SAndroid Build Coastguard Worker namespace llvm {
26*9880d681SAndroid Build Coastguard Worker 
27*9880d681SAndroid Build Coastguard Worker class Value;
28*9880d681SAndroid Build Coastguard Worker class PassInfo;
29*9880d681SAndroid Build Coastguard Worker class Module;
30*9880d681SAndroid Build Coastguard Worker class GlobalVariable;
31*9880d681SAndroid Build Coastguard Worker class Function;
32*9880d681SAndroid Build Coastguard Worker class BasicBlock;
33*9880d681SAndroid Build Coastguard Worker class AbstractInterpreter;
34*9880d681SAndroid Build Coastguard Worker class Instruction;
35*9880d681SAndroid Build Coastguard Worker class LLVMContext;
36*9880d681SAndroid Build Coastguard Worker 
37*9880d681SAndroid Build Coastguard Worker class DebugCrashes;
38*9880d681SAndroid Build Coastguard Worker 
39*9880d681SAndroid Build Coastguard Worker class CC;
40*9880d681SAndroid Build Coastguard Worker 
41*9880d681SAndroid Build Coastguard Worker extern bool DisableSimplifyCFG;
42*9880d681SAndroid Build Coastguard Worker 
43*9880d681SAndroid Build Coastguard Worker /// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
44*9880d681SAndroid Build Coastguard Worker ///
45*9880d681SAndroid Build Coastguard Worker extern bool BugpointIsInterrupted;
46*9880d681SAndroid Build Coastguard Worker 
47*9880d681SAndroid Build Coastguard Worker class BugDriver {
48*9880d681SAndroid Build Coastguard Worker   LLVMContext& Context;
49*9880d681SAndroid Build Coastguard Worker   const char *ToolName;            // argv[0] of bugpoint
50*9880d681SAndroid Build Coastguard Worker   std::string ReferenceOutputFile; // Name of `good' output file
51*9880d681SAndroid Build Coastguard Worker   Module *Program;             // The raw program, linked together
52*9880d681SAndroid Build Coastguard Worker   std::vector<std::string> PassesToRun;
53*9880d681SAndroid Build Coastguard Worker   AbstractInterpreter *Interpreter;   // How to run the program
54*9880d681SAndroid Build Coastguard Worker   AbstractInterpreter *SafeInterpreter;  // To generate reference output, etc.
55*9880d681SAndroid Build Coastguard Worker   CC *cc;
56*9880d681SAndroid Build Coastguard Worker   bool run_find_bugs;
57*9880d681SAndroid Build Coastguard Worker   unsigned Timeout;
58*9880d681SAndroid Build Coastguard Worker   unsigned MemoryLimit;
59*9880d681SAndroid Build Coastguard Worker   bool UseValgrind;
60*9880d681SAndroid Build Coastguard Worker 
61*9880d681SAndroid Build Coastguard Worker   // FIXME: sort out public/private distinctions...
62*9880d681SAndroid Build Coastguard Worker   friend class ReducePassList;
63*9880d681SAndroid Build Coastguard Worker   friend class ReduceMisCodegenFunctions;
64*9880d681SAndroid Build Coastguard Worker 
65*9880d681SAndroid Build Coastguard Worker public:
66*9880d681SAndroid Build Coastguard Worker   BugDriver(const char *toolname, bool find_bugs,
67*9880d681SAndroid Build Coastguard Worker             unsigned timeout, unsigned memlimit, bool use_valgrind,
68*9880d681SAndroid Build Coastguard Worker             LLVMContext& ctxt);
69*9880d681SAndroid Build Coastguard Worker   ~BugDriver();
70*9880d681SAndroid Build Coastguard Worker 
getToolName()71*9880d681SAndroid Build Coastguard Worker   const char *getToolName() const { return ToolName; }
72*9880d681SAndroid Build Coastguard Worker 
getContext()73*9880d681SAndroid Build Coastguard Worker   LLVMContext& getContext() const { return Context; }
74*9880d681SAndroid Build Coastguard Worker 
75*9880d681SAndroid Build Coastguard Worker   // Set up methods... these methods are used to copy information about the
76*9880d681SAndroid Build Coastguard Worker   // command line arguments into instance variables of BugDriver.
77*9880d681SAndroid Build Coastguard Worker   //
78*9880d681SAndroid Build Coastguard Worker   bool addSources(const std::vector<std::string> &FileNames);
addPass(std::string p)79*9880d681SAndroid Build Coastguard Worker   void addPass(std::string p) { PassesToRun.push_back(std::move(p)); }
setPassesToRun(const std::vector<std::string> & PTR)80*9880d681SAndroid Build Coastguard Worker   void setPassesToRun(const std::vector<std::string> &PTR) {
81*9880d681SAndroid Build Coastguard Worker     PassesToRun = PTR;
82*9880d681SAndroid Build Coastguard Worker   }
getPassesToRun()83*9880d681SAndroid Build Coastguard Worker   const std::vector<std::string> &getPassesToRun() const {
84*9880d681SAndroid Build Coastguard Worker     return PassesToRun;
85*9880d681SAndroid Build Coastguard Worker   }
86*9880d681SAndroid Build Coastguard Worker 
87*9880d681SAndroid Build Coastguard Worker   /// run - The top level method that is invoked after all of the instance
88*9880d681SAndroid Build Coastguard Worker   /// variables are set up from command line arguments. The \p as_child argument
89*9880d681SAndroid Build Coastguard Worker   /// indicates whether the driver is to run in parent mode or child mode.
90*9880d681SAndroid Build Coastguard Worker   ///
91*9880d681SAndroid Build Coastguard Worker   bool run(std::string &ErrMsg);
92*9880d681SAndroid Build Coastguard Worker 
93*9880d681SAndroid Build Coastguard Worker   /// debugOptimizerCrash - This method is called when some optimizer pass
94*9880d681SAndroid Build Coastguard Worker   /// crashes on input.  It attempts to prune down the testcase to something
95*9880d681SAndroid Build Coastguard Worker   /// reasonable, and figure out exactly which pass is crashing.
96*9880d681SAndroid Build Coastguard Worker   ///
97*9880d681SAndroid Build Coastguard Worker   bool debugOptimizerCrash(const std::string &ID = "passes");
98*9880d681SAndroid Build Coastguard Worker 
99*9880d681SAndroid Build Coastguard Worker   /// debugCodeGeneratorCrash - This method is called when the code generator
100*9880d681SAndroid Build Coastguard Worker   /// crashes on an input.  It attempts to reduce the input as much as possible
101*9880d681SAndroid Build Coastguard Worker   /// while still causing the code generator to crash.
102*9880d681SAndroid Build Coastguard Worker   bool debugCodeGeneratorCrash(std::string &Error);
103*9880d681SAndroid Build Coastguard Worker 
104*9880d681SAndroid Build Coastguard Worker   /// debugMiscompilation - This method is used when the passes selected are not
105*9880d681SAndroid Build Coastguard Worker   /// crashing, but the generated output is semantically different from the
106*9880d681SAndroid Build Coastguard Worker   /// input.
107*9880d681SAndroid Build Coastguard Worker   void debugMiscompilation(std::string *Error);
108*9880d681SAndroid Build Coastguard Worker 
109*9880d681SAndroid Build Coastguard Worker   /// debugPassMiscompilation - This method is called when the specified pass
110*9880d681SAndroid Build Coastguard Worker   /// miscompiles Program as input.  It tries to reduce the testcase to
111*9880d681SAndroid Build Coastguard Worker   /// something that smaller that still miscompiles the program.
112*9880d681SAndroid Build Coastguard Worker   /// ReferenceOutput contains the filename of the file containing the output we
113*9880d681SAndroid Build Coastguard Worker   /// are to match.
114*9880d681SAndroid Build Coastguard Worker   ///
115*9880d681SAndroid Build Coastguard Worker   bool debugPassMiscompilation(const PassInfo *ThePass,
116*9880d681SAndroid Build Coastguard Worker                                const std::string &ReferenceOutput);
117*9880d681SAndroid Build Coastguard Worker 
118*9880d681SAndroid Build Coastguard Worker   /// compileSharedObject - This method creates a SharedObject from a given
119*9880d681SAndroid Build Coastguard Worker   /// BitcodeFile for debugging a code generator.
120*9880d681SAndroid Build Coastguard Worker   ///
121*9880d681SAndroid Build Coastguard Worker   std::string compileSharedObject(const std::string &BitcodeFile,
122*9880d681SAndroid Build Coastguard Worker                                   std::string &Error);
123*9880d681SAndroid Build Coastguard Worker 
124*9880d681SAndroid Build Coastguard Worker   /// debugCodeGenerator - This method narrows down a module to a function or
125*9880d681SAndroid Build Coastguard Worker   /// set of functions, using the CBE as a ``safe'' code generator for other
126*9880d681SAndroid Build Coastguard Worker   /// functions that are not under consideration.
127*9880d681SAndroid Build Coastguard Worker   bool debugCodeGenerator(std::string *Error);
128*9880d681SAndroid Build Coastguard Worker 
129*9880d681SAndroid Build Coastguard Worker   /// isExecutingJIT - Returns true if bugpoint is currently testing the JIT
130*9880d681SAndroid Build Coastguard Worker   ///
131*9880d681SAndroid Build Coastguard Worker   bool isExecutingJIT();
132*9880d681SAndroid Build Coastguard Worker 
getProgram()133*9880d681SAndroid Build Coastguard Worker   Module *getProgram() const { return Program; }
134*9880d681SAndroid Build Coastguard Worker 
135*9880d681SAndroid Build Coastguard Worker   /// swapProgramIn - Set the current module to the specified module, returning
136*9880d681SAndroid Build Coastguard Worker   /// the old one.
swapProgramIn(Module * M)137*9880d681SAndroid Build Coastguard Worker   Module *swapProgramIn(Module *M) {
138*9880d681SAndroid Build Coastguard Worker     Module *OldProgram = Program;
139*9880d681SAndroid Build Coastguard Worker     Program = M;
140*9880d681SAndroid Build Coastguard Worker     return OldProgram;
141*9880d681SAndroid Build Coastguard Worker   }
142*9880d681SAndroid Build Coastguard Worker 
switchToSafeInterpreter()143*9880d681SAndroid Build Coastguard Worker   AbstractInterpreter *switchToSafeInterpreter() {
144*9880d681SAndroid Build Coastguard Worker     AbstractInterpreter *Old = Interpreter;
145*9880d681SAndroid Build Coastguard Worker     Interpreter = (AbstractInterpreter*)SafeInterpreter;
146*9880d681SAndroid Build Coastguard Worker     return Old;
147*9880d681SAndroid Build Coastguard Worker   }
148*9880d681SAndroid Build Coastguard Worker 
switchToInterpreter(AbstractInterpreter * AI)149*9880d681SAndroid Build Coastguard Worker   void switchToInterpreter(AbstractInterpreter *AI) {
150*9880d681SAndroid Build Coastguard Worker     Interpreter = AI;
151*9880d681SAndroid Build Coastguard Worker   }
152*9880d681SAndroid Build Coastguard Worker 
153*9880d681SAndroid Build Coastguard Worker   /// setNewProgram - If we reduce or update the program somehow, call this
154*9880d681SAndroid Build Coastguard Worker   /// method to update bugdriver with it.  This deletes the old module and sets
155*9880d681SAndroid Build Coastguard Worker   /// the specified one as the current program.
156*9880d681SAndroid Build Coastguard Worker   void setNewProgram(Module *M);
157*9880d681SAndroid Build Coastguard Worker 
158*9880d681SAndroid Build Coastguard Worker   /// compileProgram - Try to compile the specified module, returning false and
159*9880d681SAndroid Build Coastguard Worker   /// setting Error if an error occurs.  This is used for code generation
160*9880d681SAndroid Build Coastguard Worker   /// crash testing.
161*9880d681SAndroid Build Coastguard Worker   ///
162*9880d681SAndroid Build Coastguard Worker   void compileProgram(Module *M, std::string *Error) const;
163*9880d681SAndroid Build Coastguard Worker 
164*9880d681SAndroid Build Coastguard Worker   /// executeProgram - This method runs "Program", capturing the output of the
165*9880d681SAndroid Build Coastguard Worker   /// program to a file.  A recommended filename may be optionally specified.
166*9880d681SAndroid Build Coastguard Worker   ///
167*9880d681SAndroid Build Coastguard Worker   std::string executeProgram(const Module *Program,
168*9880d681SAndroid Build Coastguard Worker                              std::string OutputFilename,
169*9880d681SAndroid Build Coastguard Worker                              std::string Bitcode,
170*9880d681SAndroid Build Coastguard Worker                              const std::string &SharedObjects,
171*9880d681SAndroid Build Coastguard Worker                              AbstractInterpreter *AI,
172*9880d681SAndroid Build Coastguard Worker                              std::string *Error) const;
173*9880d681SAndroid Build Coastguard Worker 
174*9880d681SAndroid Build Coastguard Worker   /// executeProgramSafely - Used to create reference output with the "safe"
175*9880d681SAndroid Build Coastguard Worker   /// backend, if reference output is not provided.  If there is a problem with
176*9880d681SAndroid Build Coastguard Worker   /// the code generator (e.g., llc crashes), this will return false and set
177*9880d681SAndroid Build Coastguard Worker   /// Error.
178*9880d681SAndroid Build Coastguard Worker   ///
179*9880d681SAndroid Build Coastguard Worker   std::string executeProgramSafely(const Module *Program,
180*9880d681SAndroid Build Coastguard Worker                                    const std::string &OutputFile,
181*9880d681SAndroid Build Coastguard Worker                                    std::string *Error) const;
182*9880d681SAndroid Build Coastguard Worker 
183*9880d681SAndroid Build Coastguard Worker   /// createReferenceFile - calls compileProgram and then records the output
184*9880d681SAndroid Build Coastguard Worker   /// into ReferenceOutputFile. Returns true if reference file created, false
185*9880d681SAndroid Build Coastguard Worker   /// otherwise. Note: initializeExecutionEnvironment should be called BEFORE
186*9880d681SAndroid Build Coastguard Worker   /// this function.
187*9880d681SAndroid Build Coastguard Worker   ///
188*9880d681SAndroid Build Coastguard Worker   bool createReferenceFile(Module *M, const std::string &Filename
189*9880d681SAndroid Build Coastguard Worker                                             = "bugpoint.reference.out-%%%%%%%");
190*9880d681SAndroid Build Coastguard Worker 
191*9880d681SAndroid Build Coastguard Worker   /// diffProgram - This method executes the specified module and diffs the
192*9880d681SAndroid Build Coastguard Worker   /// output against the file specified by ReferenceOutputFile.  If the output
193*9880d681SAndroid Build Coastguard Worker   /// is different, 1 is returned.  If there is a problem with the code
194*9880d681SAndroid Build Coastguard Worker   /// generator (e.g., llc crashes), this will return -1 and set Error.
195*9880d681SAndroid Build Coastguard Worker   ///
196*9880d681SAndroid Build Coastguard Worker   bool diffProgram(const Module *Program,
197*9880d681SAndroid Build Coastguard Worker                    const std::string &BitcodeFile = "",
198*9880d681SAndroid Build Coastguard Worker                    const std::string &SharedObj = "",
199*9880d681SAndroid Build Coastguard Worker                    bool RemoveBitcode = false,
200*9880d681SAndroid Build Coastguard Worker                    std::string *Error = nullptr) const;
201*9880d681SAndroid Build Coastguard Worker 
202*9880d681SAndroid Build Coastguard Worker   /// EmitProgressBitcode - This function is used to output M to a file named
203*9880d681SAndroid Build Coastguard Worker   /// "bugpoint-ID.bc".
204*9880d681SAndroid Build Coastguard Worker   ///
205*9880d681SAndroid Build Coastguard Worker   void EmitProgressBitcode(const Module *M, const std::string &ID,
206*9880d681SAndroid Build Coastguard Worker                            bool NoFlyer = false) const;
207*9880d681SAndroid Build Coastguard Worker 
208*9880d681SAndroid Build Coastguard Worker   /// This method clones the current Program and deletes the specified
209*9880d681SAndroid Build Coastguard Worker   /// instruction from the cloned module.  It then runs a series of cleanup
210*9880d681SAndroid Build Coastguard Worker   /// passes (ADCE and SimplifyCFG) to eliminate any code which depends on the
211*9880d681SAndroid Build Coastguard Worker   /// value. The modified module is then returned.
212*9880d681SAndroid Build Coastguard Worker   ///
213*9880d681SAndroid Build Coastguard Worker   std::unique_ptr<Module> deleteInstructionFromProgram(const Instruction *I,
214*9880d681SAndroid Build Coastguard Worker                                                        unsigned Simp);
215*9880d681SAndroid Build Coastguard Worker 
216*9880d681SAndroid Build Coastguard Worker   /// This method clones the current Program and performs a series of cleanups
217*9880d681SAndroid Build Coastguard Worker   /// intended to get rid of extra cruft on the module. If the
218*9880d681SAndroid Build Coastguard Worker   /// MayModifySemantics argument is true, then the cleanups is allowed to
219*9880d681SAndroid Build Coastguard Worker   /// modify how the code behaves.
220*9880d681SAndroid Build Coastguard Worker   ///
221*9880d681SAndroid Build Coastguard Worker   std::unique_ptr<Module> performFinalCleanups(Module *M,
222*9880d681SAndroid Build Coastguard Worker                                                bool MayModifySemantics = false);
223*9880d681SAndroid Build Coastguard Worker 
224*9880d681SAndroid Build Coastguard Worker   /// Given a module, extract up to one loop from it into a new function. This
225*9880d681SAndroid Build Coastguard Worker   /// returns null if there are no extractable loops in the program or if the
226*9880d681SAndroid Build Coastguard Worker   /// loop extractor crashes.
227*9880d681SAndroid Build Coastguard Worker   std::unique_ptr<Module> extractLoop(Module *M);
228*9880d681SAndroid Build Coastguard Worker 
229*9880d681SAndroid Build Coastguard Worker   /// Extract all but the specified basic blocks into their own functions. The
230*9880d681SAndroid Build Coastguard Worker   /// only detail is that M is actually a module cloned from the one the BBs are
231*9880d681SAndroid Build Coastguard Worker   /// in, so some mapping needs to be performed. If this operation fails for
232*9880d681SAndroid Build Coastguard Worker   /// some reason (ie the implementation is buggy), this function should return
233*9880d681SAndroid Build Coastguard Worker   /// null, otherwise it returns a new Module.
234*9880d681SAndroid Build Coastguard Worker   std::unique_ptr<Module>
235*9880d681SAndroid Build Coastguard Worker   extractMappedBlocksFromModule(const std::vector<BasicBlock *> &BBs,
236*9880d681SAndroid Build Coastguard Worker                                 Module *M);
237*9880d681SAndroid Build Coastguard Worker 
238*9880d681SAndroid Build Coastguard Worker   /// Carefully run the specified set of pass on the specified/ module,
239*9880d681SAndroid Build Coastguard Worker   /// returning the transformed module on success, or a null pointer on failure.
240*9880d681SAndroid Build Coastguard Worker   std::unique_ptr<Module> runPassesOn(Module *M,
241*9880d681SAndroid Build Coastguard Worker                                       const std::vector<std::string> &Passes,
242*9880d681SAndroid Build Coastguard Worker                                       unsigned NumExtraArgs = 0,
243*9880d681SAndroid Build Coastguard Worker                                       const char *const *ExtraArgs = nullptr);
244*9880d681SAndroid Build Coastguard Worker 
245*9880d681SAndroid Build Coastguard Worker   /// runPasses - Run the specified passes on Program, outputting a bitcode
246*9880d681SAndroid Build Coastguard Worker   /// file and writting the filename into OutputFile if successful.  If the
247*9880d681SAndroid Build Coastguard Worker   /// optimizations fail for some reason (optimizer crashes), return true,
248*9880d681SAndroid Build Coastguard Worker   /// otherwise return false.  If DeleteOutput is set to true, the bitcode is
249*9880d681SAndroid Build Coastguard Worker   /// deleted on success, and the filename string is undefined.  This prints to
250*9880d681SAndroid Build Coastguard Worker   /// outs() a single line message indicating whether compilation was successful
251*9880d681SAndroid Build Coastguard Worker   /// or failed, unless Quiet is set.  ExtraArgs specifies additional arguments
252*9880d681SAndroid Build Coastguard Worker   /// to pass to the child bugpoint instance.
253*9880d681SAndroid Build Coastguard Worker   ///
254*9880d681SAndroid Build Coastguard Worker   bool runPasses(Module *Program,
255*9880d681SAndroid Build Coastguard Worker                  const std::vector<std::string> &PassesToRun,
256*9880d681SAndroid Build Coastguard Worker                  std::string &OutputFilename, bool DeleteOutput = false,
257*9880d681SAndroid Build Coastguard Worker                  bool Quiet = false, unsigned NumExtraArgs = 0,
258*9880d681SAndroid Build Coastguard Worker                  const char * const *ExtraArgs = nullptr) const;
259*9880d681SAndroid Build Coastguard Worker 
260*9880d681SAndroid Build Coastguard Worker   /// runPasses - Just like the method above, but this just returns true or
261*9880d681SAndroid Build Coastguard Worker   /// false indicating whether or not the optimizer crashed on the specified
262*9880d681SAndroid Build Coastguard Worker   /// input (true = crashed).  Does not produce any output.
263*9880d681SAndroid Build Coastguard Worker   ///
runPasses(Module * M,const std::vector<std::string> & PassesToRun)264*9880d681SAndroid Build Coastguard Worker   bool runPasses(Module *M,
265*9880d681SAndroid Build Coastguard Worker                  const std::vector<std::string> &PassesToRun) const {
266*9880d681SAndroid Build Coastguard Worker     std::string Filename;
267*9880d681SAndroid Build Coastguard Worker     return runPasses(M, PassesToRun, Filename, true);
268*9880d681SAndroid Build Coastguard Worker   }
269*9880d681SAndroid Build Coastguard Worker 
270*9880d681SAndroid Build Coastguard Worker   /// runManyPasses - Take the specified pass list and create different
271*9880d681SAndroid Build Coastguard Worker   /// combinations of passes to compile the program with. Compile the program with
272*9880d681SAndroid Build Coastguard Worker   /// each set and mark test to see if it compiled correctly. If the passes
273*9880d681SAndroid Build Coastguard Worker   /// compiled correctly output nothing and rearrange the passes into a new order.
274*9880d681SAndroid Build Coastguard Worker   /// If the passes did not compile correctly, output the command required to
275*9880d681SAndroid Build Coastguard Worker   /// recreate the failure. This returns true if a compiler error is found.
276*9880d681SAndroid Build Coastguard Worker   ///
277*9880d681SAndroid Build Coastguard Worker   bool runManyPasses(const std::vector<std::string> &AllPasses,
278*9880d681SAndroid Build Coastguard Worker                      std::string &ErrMsg);
279*9880d681SAndroid Build Coastguard Worker 
280*9880d681SAndroid Build Coastguard Worker   /// writeProgramToFile - This writes the current "Program" to the named
281*9880d681SAndroid Build Coastguard Worker   /// bitcode file.  If an error occurs, true is returned.
282*9880d681SAndroid Build Coastguard Worker   ///
283*9880d681SAndroid Build Coastguard Worker   bool writeProgramToFile(const std::string &Filename, const Module *M) const;
284*9880d681SAndroid Build Coastguard Worker   bool writeProgramToFile(const std::string &Filename, int FD,
285*9880d681SAndroid Build Coastguard Worker                           const Module *M) const;
286*9880d681SAndroid Build Coastguard Worker 
287*9880d681SAndroid Build Coastguard Worker private:
288*9880d681SAndroid Build Coastguard Worker   /// initializeExecutionEnvironment - This method is used to set up the
289*9880d681SAndroid Build Coastguard Worker   /// environment for executing LLVM programs.
290*9880d681SAndroid Build Coastguard Worker   ///
291*9880d681SAndroid Build Coastguard Worker   bool initializeExecutionEnvironment();
292*9880d681SAndroid Build Coastguard Worker };
293*9880d681SAndroid Build Coastguard Worker 
294*9880d681SAndroid Build Coastguard Worker ///  Given a bitcode or assembly input filename, parse and return it, or return
295*9880d681SAndroid Build Coastguard Worker ///  null if not possible.
296*9880d681SAndroid Build Coastguard Worker ///
297*9880d681SAndroid Build Coastguard Worker std::unique_ptr<Module> parseInputFile(StringRef InputFilename,
298*9880d681SAndroid Build Coastguard Worker                                        LLVMContext &ctxt);
299*9880d681SAndroid Build Coastguard Worker 
300*9880d681SAndroid Build Coastguard Worker /// getPassesString - Turn a list of passes into a string which indicates the
301*9880d681SAndroid Build Coastguard Worker /// command line options that must be passed to add the passes.
302*9880d681SAndroid Build Coastguard Worker ///
303*9880d681SAndroid Build Coastguard Worker std::string getPassesString(const std::vector<std::string> &Passes);
304*9880d681SAndroid Build Coastguard Worker 
305*9880d681SAndroid Build Coastguard Worker /// PrintFunctionList - prints out list of problematic functions
306*9880d681SAndroid Build Coastguard Worker ///
307*9880d681SAndroid Build Coastguard Worker void PrintFunctionList(const std::vector<Function*> &Funcs);
308*9880d681SAndroid Build Coastguard Worker 
309*9880d681SAndroid Build Coastguard Worker /// PrintGlobalVariableList - prints out list of problematic global variables
310*9880d681SAndroid Build Coastguard Worker ///
311*9880d681SAndroid Build Coastguard Worker void PrintGlobalVariableList(const std::vector<GlobalVariable*> &GVs);
312*9880d681SAndroid Build Coastguard Worker 
313*9880d681SAndroid Build Coastguard Worker // DeleteGlobalInitializer - "Remove" the global variable by deleting its
314*9880d681SAndroid Build Coastguard Worker // initializer, making it external.
315*9880d681SAndroid Build Coastguard Worker //
316*9880d681SAndroid Build Coastguard Worker void DeleteGlobalInitializer(GlobalVariable *GV);
317*9880d681SAndroid Build Coastguard Worker 
318*9880d681SAndroid Build Coastguard Worker // DeleteFunctionBody - "Remove" the function by deleting all of it's basic
319*9880d681SAndroid Build Coastguard Worker // blocks, making it external.
320*9880d681SAndroid Build Coastguard Worker //
321*9880d681SAndroid Build Coastguard Worker void DeleteFunctionBody(Function *F);
322*9880d681SAndroid Build Coastguard Worker 
323*9880d681SAndroid Build Coastguard Worker /// Given a module and a list of functions in the module, split the functions
324*9880d681SAndroid Build Coastguard Worker /// OUT of the specified module, and place them in the new module.
325*9880d681SAndroid Build Coastguard Worker std::unique_ptr<Module>
326*9880d681SAndroid Build Coastguard Worker SplitFunctionsOutOfModule(Module *M, const std::vector<Function *> &F,
327*9880d681SAndroid Build Coastguard Worker                           ValueToValueMapTy &VMap);
328*9880d681SAndroid Build Coastguard Worker 
329*9880d681SAndroid Build Coastguard Worker } // End llvm namespace
330*9880d681SAndroid Build Coastguard Worker 
331*9880d681SAndroid Build Coastguard Worker #endif
332