blob: 97ff5f701f0e01e1e30f85082061feb0ea4aeb82 [file] [log] [blame]
Chris Lattner94321112003-10-20 17:57:13 +00001//===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
Misha Brukman3da94ae2005-04-22 00:00:37 +00002//
John Criswell7c0e0222003-10-20 17:47:21 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukman3da94ae2005-04-22 00:00:37 +00007//
John Criswell7c0e0222003-10-20 17:47:21 +00008//===----------------------------------------------------------------------===//
Chris Lattnerafade922002-11-20 22:28:10 +00009//
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.
13//
14//===----------------------------------------------------------------------===//
15
16#include "BugDriver.h"
Chris Lattnerf1b20d82006-06-06 22:30:59 +000017#include "ToolRunner.h"
Reid Spencer62c51052006-08-21 05:34:03 +000018#include "llvm/LinkAllPasses.h"
Chris Lattnerafade922002-11-20 22:28:10 +000019#include "llvm/Support/PassNameParser.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000020#include "llvm/Support/CommandLine.h"
21#include "llvm/Support/PluginLoader.h"
Reid Spencer51163302004-12-27 06:18:02 +000022#include "llvm/System/Process.h"
Chris Lattnerbed85ff2004-05-27 05:41:36 +000023#include "llvm/System/Signals.h"
Reid Spencere3f05612006-06-07 23:06:50 +000024#include "llvm/LinkAllVMCore.h"
Brian Gaeked0fde302003-11-11 22:41:34 +000025using namespace llvm;
26
Reid Spencerc4bb0522005-12-22 20:02:55 +000027// AsChild - Specifies that this invocation of bugpoint is being generated
28// from a parent process. It is not intended to be used by users so the
29// option is hidden.
30static cl::opt<bool>
Patrick Jenkins6a3f31c2006-08-15 16:40:49 +000031AsChild("as-child", cl::desc("Run bugpoint as child process"),
32 cl::ReallyHidden);
33
34static cl::opt<bool>
35FindBugs("find-bugs", cl::desc("Run many different optimization sequences"
36 "on program to find bugs"), cl::init(false));
Reid Spencerc4bb0522005-12-22 20:02:55 +000037
Chris Lattnerafade922002-11-20 22:28:10 +000038static cl::list<std::string>
39InputFilenames(cl::Positional, cl::OneOrMore,
40 cl::desc("<input llvm ll/bc files>"));
41
Chris Lattner9686ae72006-06-13 03:10:48 +000042static cl::opt<unsigned>
43TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"),
44 cl::desc("Number of seconds program is allowed to run before it "
45 "is killed (default is 300s), 0 disables timeout"));
46
Chris Lattnerafade922002-11-20 22:28:10 +000047// The AnalysesList is automatically populated with registered Passes by the
48// PassNameParser.
49//
50static cl::list<const PassInfo*, bool, PassNameParser>
Misha Brukman50733362003-07-24 18:17:43 +000051PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
Chris Lattnerafade922002-11-20 22:28:10 +000052
Chris Lattnerf9aaae02005-08-02 02:16:17 +000053/// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
54bool llvm::BugpointIsInterrupted = false;
55
56static void BugpointInterruptFunction() {
57 BugpointIsInterrupted = true;
58}
59
Chris Lattnerafade922002-11-20 22:28:10 +000060int main(int argc, char **argv) {
Chris Lattner670406d2003-10-18 21:55:35 +000061 cl::ParseCommandLineOptions(argc, argv,
62 " LLVM automatic testcase reducer. See\nhttp://"
Reid Spencer9dce2b32006-03-14 05:54:52 +000063 "llvm.org/docs/CommandGuide/bugpoint.html"
Chris Lattner670406d2003-10-18 21:55:35 +000064 " for more information.\n");
Reid Spencer9de7b332004-08-29 19:28:55 +000065 sys::PrintStackTraceOnErrorSignal();
Chris Lattnerf9aaae02005-08-02 02:16:17 +000066 sys::SetInterruptFunction(BugpointInterruptFunction);
67
Patrick Jenkins6a3f31c2006-08-15 16:40:49 +000068 BugDriver D(argv[0],AsChild,FindBugs,TimeoutValue);
Chris Lattnerafade922002-11-20 22:28:10 +000069 if (D.addSources(InputFilenames)) return 1;
70 D.addPasses(PassList.begin(), PassList.end());
71
Misha Brukman67b36e42003-09-12 20:42:57 +000072 // Bugpoint has the ability of generating a plethora of core files, so to
Reid Spencer551ccae2004-09-01 22:55:40 +000073 // avoid filling up the disk, we prevent it
Reid Spencer51163302004-12-27 06:18:02 +000074 sys::Process::PreventCoreFiles();
Misha Brukman67b36e42003-09-12 20:42:57 +000075
Chris Lattner74d45272004-02-18 17:32:54 +000076 try {
77 return D.run();
Chris Lattner230fef82004-02-18 20:22:11 +000078 } catch (ToolExecutionError &TEE) {
Misha Brukmaneed80e22004-07-23 01:30:49 +000079 std::cerr << "Tool execution error: " << TEE.what() << '\n';
Reid Spencer1ef8bda2004-12-30 05:36:08 +000080 } catch (const std::string& msg) {
81 std::cerr << argv[0] << ": " << msg << "\n";
Chris Lattner74d45272004-02-18 17:32:54 +000082 } catch (...) {
83 std::cerr << "Whoops, an exception leaked out of bugpoint. "
84 << "This is a bug in bugpoint!\n";
Chris Lattner74d45272004-02-18 17:32:54 +000085 }
Reid Spencer1ef8bda2004-12-30 05:36:08 +000086 return 1;
Chris Lattnerafade922002-11-20 22:28:10 +000087}