Chris Lattner | 9432111 | 2003-10-20 17:57:13 +0000 | [diff] [blame] | 1 | //===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===// |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | 7c0e022 | 2003-10-20 17:47:21 +0000 | [diff] [blame] | 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. |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | 7c0e022 | 2003-10-20 17:47:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 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. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #include "BugDriver.h" |
Chris Lattner | f1b20d8 | 2006-06-06 22:30:59 +0000 | [diff] [blame] | 17 | #include "ToolRunner.h" |
Chris Lattner | 831843d | 2005-10-24 01:05:53 +0000 | [diff] [blame] | 18 | #include "llvm/Analysis/LinkAllAnalyses.h" |
| 19 | #include "llvm/Transforms/LinkAllPasses.h" |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 20 | #include "llvm/Support/PassNameParser.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 21 | #include "llvm/Support/CommandLine.h" |
| 22 | #include "llvm/Support/PluginLoader.h" |
Reid Spencer | 5116330 | 2004-12-27 06:18:02 +0000 | [diff] [blame] | 23 | #include "llvm/System/Process.h" |
Chris Lattner | bed85ff | 2004-05-27 05:41:36 +0000 | [diff] [blame] | 24 | #include "llvm/System/Signals.h" |
Reid Spencer | e3f0561 | 2006-06-07 23:06:50 +0000 | [diff] [blame] | 25 | #include "llvm/LinkAllVMCore.h" |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
Reid Spencer | c4bb052 | 2005-12-22 20:02:55 +0000 | [diff] [blame] | 28 | // AsChild - Specifies that this invocation of bugpoint is being generated |
| 29 | // from a parent process. It is not intended to be used by users so the |
| 30 | // option is hidden. |
| 31 | static cl::opt<bool> |
Patrick Jenkins | 6a3f31c | 2006-08-15 16:40:49 +0000 | [diff] [blame^] | 32 | AsChild("as-child", cl::desc("Run bugpoint as child process"), |
| 33 | cl::ReallyHidden); |
| 34 | |
| 35 | static cl::opt<bool> |
| 36 | FindBugs("find-bugs", cl::desc("Run many different optimization sequences" |
| 37 | "on program to find bugs"), cl::init(false)); |
Reid Spencer | c4bb052 | 2005-12-22 20:02:55 +0000 | [diff] [blame] | 38 | |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 39 | static cl::list<std::string> |
| 40 | InputFilenames(cl::Positional, cl::OneOrMore, |
| 41 | cl::desc("<input llvm ll/bc files>")); |
| 42 | |
Chris Lattner | 9686ae7 | 2006-06-13 03:10:48 +0000 | [diff] [blame] | 43 | static cl::opt<unsigned> |
| 44 | TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"), |
| 45 | cl::desc("Number of seconds program is allowed to run before it " |
| 46 | "is killed (default is 300s), 0 disables timeout")); |
| 47 | |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 48 | // The AnalysesList is automatically populated with registered Passes by the |
| 49 | // PassNameParser. |
| 50 | // |
| 51 | static cl::list<const PassInfo*, bool, PassNameParser> |
Misha Brukman | 5073336 | 2003-07-24 18:17:43 +0000 | [diff] [blame] | 52 | PassList(cl::desc("Passes available:"), cl::ZeroOrMore); |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 53 | |
Chris Lattner | f9aaae0 | 2005-08-02 02:16:17 +0000 | [diff] [blame] | 54 | /// BugpointIsInterrupted - Set to true when the user presses ctrl-c. |
| 55 | bool llvm::BugpointIsInterrupted = false; |
| 56 | |
| 57 | static void BugpointInterruptFunction() { |
| 58 | BugpointIsInterrupted = true; |
| 59 | } |
| 60 | |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 61 | int main(int argc, char **argv) { |
Chris Lattner | 670406d | 2003-10-18 21:55:35 +0000 | [diff] [blame] | 62 | cl::ParseCommandLineOptions(argc, argv, |
| 63 | " LLVM automatic testcase reducer. See\nhttp://" |
Reid Spencer | 9dce2b3 | 2006-03-14 05:54:52 +0000 | [diff] [blame] | 64 | "llvm.org/docs/CommandGuide/bugpoint.html" |
Chris Lattner | 670406d | 2003-10-18 21:55:35 +0000 | [diff] [blame] | 65 | " for more information.\n"); |
Reid Spencer | 9de7b33 | 2004-08-29 19:28:55 +0000 | [diff] [blame] | 66 | sys::PrintStackTraceOnErrorSignal(); |
Chris Lattner | f9aaae0 | 2005-08-02 02:16:17 +0000 | [diff] [blame] | 67 | sys::SetInterruptFunction(BugpointInterruptFunction); |
| 68 | |
Patrick Jenkins | 6a3f31c | 2006-08-15 16:40:49 +0000 | [diff] [blame^] | 69 | BugDriver D(argv[0],AsChild,FindBugs,TimeoutValue); |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 70 | if (D.addSources(InputFilenames)) return 1; |
| 71 | D.addPasses(PassList.begin(), PassList.end()); |
| 72 | |
Misha Brukman | 67b36e4 | 2003-09-12 20:42:57 +0000 | [diff] [blame] | 73 | // Bugpoint has the ability of generating a plethora of core files, so to |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 74 | // avoid filling up the disk, we prevent it |
Reid Spencer | 5116330 | 2004-12-27 06:18:02 +0000 | [diff] [blame] | 75 | sys::Process::PreventCoreFiles(); |
Misha Brukman | 67b36e4 | 2003-09-12 20:42:57 +0000 | [diff] [blame] | 76 | |
Chris Lattner | 74d4527 | 2004-02-18 17:32:54 +0000 | [diff] [blame] | 77 | try { |
| 78 | return D.run(); |
Chris Lattner | 230fef8 | 2004-02-18 20:22:11 +0000 | [diff] [blame] | 79 | } catch (ToolExecutionError &TEE) { |
Misha Brukman | eed80e2 | 2004-07-23 01:30:49 +0000 | [diff] [blame] | 80 | std::cerr << "Tool execution error: " << TEE.what() << '\n'; |
Reid Spencer | 1ef8bda | 2004-12-30 05:36:08 +0000 | [diff] [blame] | 81 | } catch (const std::string& msg) { |
| 82 | std::cerr << argv[0] << ": " << msg << "\n"; |
Chris Lattner | 74d4527 | 2004-02-18 17:32:54 +0000 | [diff] [blame] | 83 | } catch (...) { |
| 84 | std::cerr << "Whoops, an exception leaked out of bugpoint. " |
| 85 | << "This is a bug in bugpoint!\n"; |
Chris Lattner | 74d4527 | 2004-02-18 17:32:54 +0000 | [diff] [blame] | 86 | } |
Reid Spencer | 1ef8bda | 2004-12-30 05:36:08 +0000 | [diff] [blame] | 87 | return 1; |
Chris Lattner | afade92 | 2002-11-20 22:28:10 +0000 | [diff] [blame] | 88 | } |