Added the LAR (load segment access rights)
[llvm/avr.git] / tools / bugpoint / bugpoint.cpp
blob565f3f9a70876864bfcf7e0904e3cbea8bbc1971
1 //===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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/LLVMContext.h"
20 #include "llvm/Support/PassNameParser.h"
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/ManagedStatic.h"
23 #include "llvm/Support/PluginLoader.h"
24 #include "llvm/Support/PrettyStackTrace.h"
25 #include "llvm/Support/StandardPasses.h"
26 #include "llvm/System/Process.h"
27 #include "llvm/System/Signals.h"
28 #include "llvm/LinkAllVMCore.h"
29 using namespace llvm;
31 // AsChild - Specifies that this invocation of bugpoint is being generated
32 // from a parent process. It is not intended to be used by users so the
33 // option is hidden.
34 static cl::opt<bool>
35 AsChild("as-child", cl::desc("Run bugpoint as child process"),
36 cl::ReallyHidden);
38 static cl::opt<bool>
39 FindBugs("find-bugs", cl::desc("Run many different optimization sequences "
40 "on program to find bugs"), cl::init(false));
42 static cl::list<std::string>
43 InputFilenames(cl::Positional, cl::OneOrMore,
44 cl::desc("<input llvm ll/bc files>"));
46 static cl::opt<unsigned>
47 TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"),
48 cl::desc("Number of seconds program is allowed to run before it "
49 "is killed (default is 300s), 0 disables timeout"));
51 static cl::opt<unsigned>
52 MemoryLimit("mlimit", cl::init(100), cl::value_desc("MBytes"),
53 cl::desc("Maximum amount of memory to use. 0 disables check."));
55 // The AnalysesList is automatically populated with registered Passes by the
56 // PassNameParser.
58 static cl::list<const PassInfo*, bool, PassNameParser>
59 PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
61 static cl::opt<bool>
62 StandardCompileOpts("std-compile-opts",
63 cl::desc("Include the standard compile time optimizations"));
65 static cl::opt<bool>
66 StandardLinkOpts("std-link-opts",
67 cl::desc("Include the standard link time optimizations"));
69 static cl::opt<std::string>
70 OverrideTriple("mtriple", cl::desc("Override target triple for module"));
72 /// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
73 bool llvm::BugpointIsInterrupted = false;
75 static void BugpointInterruptFunction() {
76 BugpointIsInterrupted = true;
79 // Hack to capture a pass list.
80 namespace {
81 class AddToDriver : public PassManager {
82 BugDriver &D;
83 public:
84 AddToDriver(BugDriver &_D) : D(_D) {}
86 virtual void add(Pass *P) {
87 const PassInfo *PI = P->getPassInfo();
88 D.addPasses(&PI, &PI + 1);
93 int main(int argc, char **argv) {
94 llvm::sys::PrintStackTraceOnErrorSignal();
95 llvm::PrettyStackTraceProgram X(argc, argv);
96 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
97 cl::ParseCommandLineOptions(argc, argv,
98 "LLVM automatic testcase reducer. See\nhttp://"
99 "llvm.org/cmds/bugpoint.html"
100 " for more information.\n");
101 sys::SetInterruptFunction(BugpointInterruptFunction);
103 LLVMContext& Context = getGlobalContext();
104 // If we have an override, set it and then track the triple we want Modules
105 // to use.
106 if (!OverrideTriple.empty()) {
107 TargetTriple.setTriple(OverrideTriple);
108 outs() << "Override triple set to '" << OverrideTriple << "'\n";
111 BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit, Context);
112 if (D.addSources(InputFilenames)) return 1;
114 AddToDriver PM(D);
115 if (StandardCompileOpts) {
116 createStandardModulePasses(&PM, 3,
117 /*OptimizeSize=*/ false,
118 /*UnitAtATime=*/ true,
119 /*UnrollLoops=*/ true,
120 /*SimplifyLibCalls=*/ true,
121 /*HaveExceptions=*/ true,
122 createFunctionInliningPass());
125 if (StandardLinkOpts)
126 createStandardLTOPasses(&PM, /*Internalize=*/true,
127 /*RunInliner=*/true,
128 /*VerifyEach=*/false);
130 D.addPasses(PassList.begin(), PassList.end());
132 // Bugpoint has the ability of generating a plethora of core files, so to
133 // avoid filling up the disk, we prevent it
134 sys::Process::PreventCoreFiles();
136 try {
137 return D.run();
138 } catch (ToolExecutionError &TEE) {
139 errs() << "Tool execution error: " << TEE.what() << '\n';
140 } catch (const std::string& msg) {
141 errs() << argv[0] << ": " << msg << "\n";
142 } catch (const std::bad_alloc&) {
143 errs() << "Oh no, a bugpoint process ran out of memory!\n"
144 "To increase the allocation limits for bugpoint child\n"
145 "processes, use the -mlimit option.\n";
146 } catch (const std::exception &e) {
147 errs() << "Whoops, a std::exception leaked out of bugpoint: "
148 << e.what() << "\n"
149 << "This is a bug in bugpoint!\n";
150 } catch (...) {
151 errs() << "Whoops, an exception leaked out of bugpoint. "
152 << "This is a bug in bugpoint!\n";
154 return 1;