bugpoint.cpp revision 0324205bbb0ea8fb70e2bdfd5ea201c3a5fc24ec
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. 13// 14//===----------------------------------------------------------------------===// 15 16#include "BugDriver.h" 17#include "ToolRunner.h" 18#include "llvm/LinkAllPasses.h" 19#include "llvm/Support/PassNameParser.h" 20#include "llvm/Support/CommandLine.h" 21#include "llvm/Support/ManagedStatic.h" 22#include "llvm/Support/PluginLoader.h" 23#include "llvm/Support/PrettyStackTrace.h" 24#include "llvm/System/Process.h" 25#include "llvm/System/Signals.h" 26#include "llvm/LinkAllVMCore.h" 27#include <iostream> 28using namespace llvm; 29 30// AsChild - Specifies that this invocation of bugpoint is being generated 31// from a parent process. It is not intended to be used by users so the 32// option is hidden. 33static cl::opt<bool> 34AsChild("as-child", cl::desc("Run bugpoint as child process"), 35 cl::ReallyHidden); 36 37static cl::opt<bool> 38FindBugs("find-bugs", cl::desc("Run many different optimization sequences " 39 "on program to find bugs"), cl::init(false)); 40 41static cl::list<std::string> 42InputFilenames(cl::Positional, cl::OneOrMore, 43 cl::desc("<input llvm ll/bc files>")); 44 45static cl::opt<unsigned> 46TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"), 47 cl::desc("Number of seconds program is allowed to run before it " 48 "is killed (default is 300s), 0 disables timeout")); 49 50static cl::opt<unsigned> 51MemoryLimit("mlimit", cl::init(100), cl::value_desc("MBytes"), 52 cl::desc("Maximum amount of memory to use. 0 disables check.")); 53 54// The AnalysesList is automatically populated with registered Passes by the 55// PassNameParser. 56// 57static cl::list<const PassInfo*, bool, PassNameParser> 58PassList(cl::desc("Passes available:"), cl::ZeroOrMore); 59 60/// BugpointIsInterrupted - Set to true when the user presses ctrl-c. 61bool llvm::BugpointIsInterrupted = false; 62 63static void BugpointInterruptFunction() { 64 BugpointIsInterrupted = true; 65} 66 67int main(int argc, char **argv) { 68 llvm::sys::PrintStackTraceOnErrorSignal(); 69 llvm::PrettyStackTraceProgram X(argc, argv); 70 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. 71 cl::ParseCommandLineOptions(argc, argv, 72 "LLVM automatic testcase reducer. See\nhttp://" 73 "llvm.org/cmds/bugpoint.html" 74 " for more information.\n"); 75 sys::SetInterruptFunction(BugpointInterruptFunction); 76 77 BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit); 78 if (D.addSources(InputFilenames)) return 1; 79 D.addPasses(PassList.begin(), PassList.end()); 80 81 // Bugpoint has the ability of generating a plethora of core files, so to 82 // avoid filling up the disk, we prevent it 83 sys::Process::PreventCoreFiles(); 84 85 try { 86 return D.run(); 87 } catch (ToolExecutionError &TEE) { 88 std::cerr << "Tool execution error: " << TEE.what() << '\n'; 89 } catch (const std::string& msg) { 90 std::cerr << argv[0] << ": " << msg << "\n"; 91 } catch (const std::bad_alloc &e) { 92 std::cerr << "Oh no, a bugpoint process ran out of memory!\n" 93 "To increase the allocation limits for bugpoint child\n" 94 "processes, use the -mlimit option.\n"; 95 } catch (const std::exception &e) { 96 std::cerr << "Whoops, a std::exception leaked out of bugpoint: " 97 << e.what() << "\n" 98 << "This is a bug in bugpoint!\n"; 99 } catch (...) { 100 std::cerr << "Whoops, an exception leaked out of bugpoint. " 101 << "This is a bug in bugpoint!\n"; 102 } 103 return 1; 104} 105