blob: 6dc08556ce6ff5fdaed138ff17c35b3303da35ca [file] [log] [blame]
Chris Lattner94321112003-10-20 17:57:13 +00001//===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
John Criswell7c0e0222003-10-20 17:47:21 +00002//
3// 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.
7//
8//===----------------------------------------------------------------------===//
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 Lattnerafade922002-11-20 22:28:10 +000017#include "llvm/Support/PassNameParser.h"
Chris Lattner230fef82004-02-18 20:22:11 +000018#include "llvm/Support/ToolRunner.h"
Misha Brukmane49603d2003-08-07 21:19:30 +000019#include "Support/CommandLine.h"
Chris Lattnerbed85ff2004-05-27 05:41:36 +000020#include "llvm/System/Signals.h"
Misha Brukman67b36e42003-09-12 20:42:57 +000021#include "Config/unistd.h"
22#include <sys/resource.h>
Brian Gaeked0fde302003-11-11 22:41:34 +000023using namespace llvm;
24
Chris Lattnerafade922002-11-20 22:28:10 +000025static cl::list<std::string>
26InputFilenames(cl::Positional, cl::OneOrMore,
27 cl::desc("<input llvm ll/bc files>"));
28
29// The AnalysesList is automatically populated with registered Passes by the
30// PassNameParser.
31//
32static cl::list<const PassInfo*, bool, PassNameParser>
Misha Brukman50733362003-07-24 18:17:43 +000033PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
Chris Lattnerafade922002-11-20 22:28:10 +000034
Chris Lattnerafade922002-11-20 22:28:10 +000035int main(int argc, char **argv) {
Chris Lattner670406d2003-10-18 21:55:35 +000036 cl::ParseCommandLineOptions(argc, argv,
37 " LLVM automatic testcase reducer. See\nhttp://"
38 "llvm.cs.uiuc.edu/docs/CommandGuide/bugpoint.html"
39 " for more information.\n");
Chris Lattner3733f3b2004-02-19 20:33:00 +000040 PrintStackTraceOnErrorSignal();
Chris Lattnerafade922002-11-20 22:28:10 +000041
Chris Lattnerafade922002-11-20 22:28:10 +000042 BugDriver D(argv[0]);
43 if (D.addSources(InputFilenames)) return 1;
44 D.addPasses(PassList.begin(), PassList.end());
45
Misha Brukman67b36e42003-09-12 20:42:57 +000046 // Bugpoint has the ability of generating a plethora of core files, so to
47 // avoid filling up the disk, set the max core file size to 0.
48 struct rlimit rlim;
49 rlim.rlim_cur = rlim.rlim_max = 0;
50 int res = setrlimit(RLIMIT_CORE, &rlim);
51 if (res < 0) {
52 // setrlimit() may have failed, but we're not going to let that stop us
53 perror("setrlimit: RLIMIT_CORE");
54 }
55
Chris Lattner74d45272004-02-18 17:32:54 +000056 try {
57 return D.run();
Chris Lattner230fef82004-02-18 20:22:11 +000058 } catch (ToolExecutionError &TEE) {
Alkis Evlogimenos1d29a6d2004-02-19 07:39:26 +000059 std::cerr << "Tool execution error: " << TEE.what() << "\n";
Chris Lattner230fef82004-02-18 20:22:11 +000060 return 1;
Chris Lattner74d45272004-02-18 17:32:54 +000061 } catch (...) {
62 std::cerr << "Whoops, an exception leaked out of bugpoint. "
63 << "This is a bug in bugpoint!\n";
64 return 1;
65 }
Chris Lattnerafade922002-11-20 22:28:10 +000066}