1 //===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This program is an automated compiler debugger tool. It is used to narrow
11 // down miscompilations and crash problems to a specific pass in the compiler,
12 // and the specific Module or Function input that is causing the problem.
14 //===----------------------------------------------------------------------===//
16 #include "BugDriver.h"
17 #include "ToolRunner.h"
18 #include "llvm/LinkAllPasses.h"
19 #include "llvm/Support/PassNameParser.h"
20 #include "llvm/Support/CommandLine.h"
21 #include "llvm/Support/ManagedStatic.h"
22 #include "llvm/Support/PluginLoader.h"
23 #include "llvm/System/Process.h"
24 #include "llvm/System/Signals.h"
25 #include "llvm/LinkAllVMCore.h"
29 // AsChild - Specifies that this invocation of bugpoint is being generated
30 // from a parent process. It is not intended to be used by users so the
33 AsChild("as-child", cl::desc("Run bugpoint as child process"),
37 FindBugs("find-bugs", cl::desc("Run many different optimization sequences "
38 "on program to find bugs"), cl::init(false));
40 static cl::list<std::string>
41 InputFilenames(cl::Positional, cl::OneOrMore,
42 cl::desc("<input llvm ll/bc files>"));
44 static cl::opt<unsigned>
45 TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"),
46 cl::desc("Number of seconds program is allowed to run before it "
47 "is killed (default is 300s), 0 disables timeout"));
49 static cl::opt<unsigned>
50 MemoryLimit("mlimit", cl::init(100), cl::value_desc("MBytes"),
51 cl::desc("Maximum amount of memory to use. 0 disables check."));
53 // The AnalysesList is automatically populated with registered Passes by the
56 static cl::list<const PassInfo*, bool, PassNameParser>
57 PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
59 /// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
60 bool llvm::BugpointIsInterrupted = false;
62 static void BugpointInterruptFunction() {
63 BugpointIsInterrupted = true;
66 int main(int argc, char **argv) {
67 llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
68 cl::ParseCommandLineOptions(argc, argv,
69 "LLVM automatic testcase reducer. See\nhttp://"
70 "llvm.org/docs/CommandGuide/bugpoint.html"
71 " for more information.\n");
72 sys::PrintStackTraceOnErrorSignal();
73 sys::SetInterruptFunction(BugpointInterruptFunction);
75 BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit);
76 if (D.addSources(InputFilenames)) return 1;
77 D.addPasses(PassList.begin(), PassList.end());
79 // Bugpoint has the ability of generating a plethora of core files, so to
80 // avoid filling up the disk, we prevent it
81 sys::Process::PreventCoreFiles();
85 } catch (ToolExecutionError &TEE) {
86 std::cerr << "Tool execution error: " << TEE.what() << '\n';
87 } catch (const std::string& msg) {
88 std::cerr << argv[0] << ": " << msg << "\n";
90 std::cerr << "Whoops, an exception leaked out of bugpoint. "
91 << "This is a bug in bugpoint!\n";