blob: 056ff52af0521912682804101b0b81516551d036 [file] [log] [blame]
Chris Lattnerebec8032003-10-20 17:57:13 +00001//===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
John Criswell09344dc2003-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 Lattner73a6bdd2002-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 Lattner73a6bdd2002-11-20 22:28:10 +000017#include "llvm/Support/PassNameParser.h"
Chris Lattner947143d2004-02-18 20:22:11 +000018#include "llvm/Support/ToolRunner.h"
Misha Brukman0c2305b2003-08-07 21:19:30 +000019#include "Support/CommandLine.h"
Chris Lattner278f5152004-05-27 05:41:36 +000020#include "llvm/System/Signals.h"
Chris Lattnerec2a1562004-07-11 01:08:19 +000021#include "Support/PluginLoader.h"
Misha Brukman46e18d42003-09-12 20:42:57 +000022#include "Config/unistd.h"
23#include <sys/resource.h>
Brian Gaeke960707c2003-11-11 22:41:34 +000024using namespace llvm;
25
Chris Lattner73a6bdd2002-11-20 22:28:10 +000026static cl::list<std::string>
27InputFilenames(cl::Positional, cl::OneOrMore,
28 cl::desc("<input llvm ll/bc files>"));
29
30// The AnalysesList is automatically populated with registered Passes by the
31// PassNameParser.
32//
33static cl::list<const PassInfo*, bool, PassNameParser>
Misha Brukmand792c9b2003-07-24 18:17:43 +000034PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
Chris Lattner73a6bdd2002-11-20 22:28:10 +000035
Chris Lattner73a6bdd2002-11-20 22:28:10 +000036int main(int argc, char **argv) {
Chris Lattner849619e2003-10-18 21:55:35 +000037 cl::ParseCommandLineOptions(argc, argv,
38 " LLVM automatic testcase reducer. See\nhttp://"
39 "llvm.cs.uiuc.edu/docs/CommandGuide/bugpoint.html"
40 " for more information.\n");
Chris Lattner56bfdec2004-02-19 20:33:00 +000041 PrintStackTraceOnErrorSignal();
Chris Lattner73a6bdd2002-11-20 22:28:10 +000042
Chris Lattner73a6bdd2002-11-20 22:28:10 +000043 BugDriver D(argv[0]);
44 if (D.addSources(InputFilenames)) return 1;
45 D.addPasses(PassList.begin(), PassList.end());
46
Misha Brukman46e18d42003-09-12 20:42:57 +000047 // Bugpoint has the ability of generating a plethora of core files, so to
48 // avoid filling up the disk, set the max core file size to 0.
49 struct rlimit rlim;
50 rlim.rlim_cur = rlim.rlim_max = 0;
51 int res = setrlimit(RLIMIT_CORE, &rlim);
52 if (res < 0) {
53 // setrlimit() may have failed, but we're not going to let that stop us
54 perror("setrlimit: RLIMIT_CORE");
55 }
56
Chris Lattnereb89dba2004-02-18 17:32:54 +000057 try {
58 return D.run();
Chris Lattner947143d2004-02-18 20:22:11 +000059 } catch (ToolExecutionError &TEE) {
Misha Brukman6aa3c832004-07-23 01:30:49 +000060 std::cerr << "Tool execution error: " << TEE.what() << '\n';
Chris Lattner947143d2004-02-18 20:22:11 +000061 return 1;
Chris Lattnereb89dba2004-02-18 17:32:54 +000062 } catch (...) {
63 std::cerr << "Whoops, an exception leaked out of bugpoint. "
64 << "This is a bug in bugpoint!\n";
65 return 1;
66 }
Chris Lattner73a6bdd2002-11-20 22:28:10 +000067}