2003-10-21 01:57:13 +08:00
|
|
|
//===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
|
2005-04-22 08:00:37 +08:00
|
|
|
//
|
2003-10-21 01:47:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:44:31 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 08:00:37 +08:00
|
|
|
//
|
2003-10-21 01:47:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-11-21 06:28:10 +08:00
|
|
|
//
|
|
|
|
// This program is an automated compiler debugger tool. It is used to narrow
|
|
|
|
// down miscompilations and crash problems to a specific pass in the compiler,
|
|
|
|
// and the specific Module or Function input that is causing the problem.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "BugDriver.h"
|
2006-06-07 06:30:59 +08:00
|
|
|
#include "ToolRunner.h"
|
2006-08-21 13:34:03 +08:00
|
|
|
#include "llvm/LinkAllPasses.h"
|
2009-07-02 00:58:40 +08:00
|
|
|
#include "llvm/LLVMContext.h"
|
2002-11-21 06:28:10 +08:00
|
|
|
#include "llvm/Support/PassNameParser.h"
|
2004-09-02 06:55:40 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2006-12-06 09:18:01 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2004-09-02 06:55:40 +08:00
|
|
|
#include "llvm/Support/PluginLoader.h"
|
2009-03-06 13:34:10 +08:00
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
2009-07-20 15:01:01 +08:00
|
|
|
#include "llvm/Support/StandardPasses.h"
|
2004-12-27 14:18:02 +08:00
|
|
|
#include "llvm/System/Process.h"
|
2004-05-27 13:41:36 +08:00
|
|
|
#include "llvm/System/Signals.h"
|
2010-03-19 08:09:28 +08:00
|
|
|
#include "llvm/System/Valgrind.h"
|
2006-06-08 07:06:50 +08:00
|
|
|
#include "llvm/LinkAllVMCore.h"
|
2003-11-12 06:41:34 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2006-08-16 00:40:49 +08:00
|
|
|
static cl::opt<bool>
|
2008-02-19 01:15:45 +08:00
|
|
|
FindBugs("find-bugs", cl::desc("Run many different optimization sequences "
|
2006-08-16 00:40:49 +08:00
|
|
|
"on program to find bugs"), cl::init(false));
|
2005-12-23 04:02:55 +08:00
|
|
|
|
2002-11-21 06:28:10 +08:00
|
|
|
static cl::list<std::string>
|
|
|
|
InputFilenames(cl::Positional, cl::OneOrMore,
|
|
|
|
cl::desc("<input llvm ll/bc files>"));
|
|
|
|
|
2006-06-13 11:10:48 +08:00
|
|
|
static cl::opt<unsigned>
|
|
|
|
TimeoutValue("timeout", cl::init(300), cl::value_desc("seconds"),
|
|
|
|
cl::desc("Number of seconds program is allowed to run before it "
|
|
|
|
"is killed (default is 300s), 0 disables timeout"));
|
|
|
|
|
2010-03-19 08:09:28 +08:00
|
|
|
static cl::opt<int>
|
|
|
|
MemoryLimit("mlimit", cl::init(-1), cl::value_desc("MBytes"),
|
|
|
|
cl::desc("Maximum amount of memory to use. 0 disables check."
|
|
|
|
" Defaults to 100MB (800MB under valgrind)."));
|
|
|
|
|
|
|
|
static cl::opt<bool>
|
|
|
|
UseValgrind("enable-valgrind",
|
|
|
|
cl::desc("Run optimizations through valgrind"));
|
2007-02-17 03:11:07 +08:00
|
|
|
|
2002-11-21 06:28:10 +08:00
|
|
|
// The AnalysesList is automatically populated with registered Passes by the
|
|
|
|
// PassNameParser.
|
|
|
|
//
|
2010-07-20 16:26:15 +08:00
|
|
|
static cl::list<const PassInfo*, bool, PassNameParser>
|
Major addition to bugpoint: ability to debug code generators (LLC and LLI).
The C backend is assumed correct and is used to generate shared objects to be
loaded by the other two code generators.
LLC debugging should be functional now, LLI needs a few more additions to work,
the major one is renaming of external functions to call the JIT lazy function
resolver.
Bugpoint now has a command-line switch -mode with options 'compile' and
'codegen' to debug appropriate portions of tools.
ExecutionDriver.cpp: Added implementations of AbstractInterpreter for LLC and
GCC, broke out common code within other tools, and added ability to generate C
code with CBE individually, without executing the program, and the GCC tool can
generate executables shared objects or executables.
If no reference output is specified to Bugpoint, it will be generated with CBE,
because it is already assumed to be correct for the purposes of debugging using
this method. As a result, many functions now accept as an optional parameter a
shared object to be loaded in, if specified.
llvm-svn: 7293
2003-07-25 02:17:43 +08:00
|
|
|
PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
|
2002-11-21 06:28:10 +08:00
|
|
|
|
2009-07-20 15:01:01 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
StandardCompileOpts("std-compile-opts",
|
|
|
|
cl::desc("Include the standard compile time optimizations"));
|
|
|
|
|
|
|
|
static cl::opt<bool>
|
|
|
|
StandardLinkOpts("std-link-opts",
|
|
|
|
cl::desc("Include the standard link time optimizations"));
|
|
|
|
|
2009-08-18 11:35:57 +08:00
|
|
|
static cl::opt<std::string>
|
|
|
|
OverrideTriple("mtriple", cl::desc("Override target triple for module"));
|
|
|
|
|
2005-08-02 10:16:17 +08:00
|
|
|
/// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
|
|
|
|
bool llvm::BugpointIsInterrupted = false;
|
|
|
|
|
|
|
|
static void BugpointInterruptFunction() {
|
|
|
|
BugpointIsInterrupted = true;
|
|
|
|
}
|
|
|
|
|
2009-07-20 15:01:01 +08:00
|
|
|
// Hack to capture a pass list.
|
|
|
|
namespace {
|
|
|
|
class AddToDriver : public PassManager {
|
|
|
|
BugDriver &D;
|
|
|
|
public:
|
|
|
|
AddToDriver(BugDriver &_D) : D(_D) {}
|
|
|
|
|
|
|
|
virtual void add(Pass *P) {
|
2010-08-07 02:33:48 +08:00
|
|
|
const void *ID = P->getPassID();
|
|
|
|
const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(ID);
|
2010-08-08 11:55:08 +08:00
|
|
|
D.addPass(PI->getPassArgument());
|
2009-07-20 15:01:01 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2002-11-21 06:28:10 +08:00
|
|
|
int main(int argc, char **argv) {
|
2009-03-06 13:34:10 +08:00
|
|
|
llvm::sys::PrintStackTraceOnErrorSignal();
|
|
|
|
llvm::PrettyStackTraceProgram X(argc, argv);
|
|
|
|
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
2003-10-19 05:55:35 +08:00
|
|
|
cl::ParseCommandLineOptions(argc, argv,
|
2007-10-08 23:45:12 +08:00
|
|
|
"LLVM automatic testcase reducer. See\nhttp://"
|
2009-02-08 02:56:30 +08:00
|
|
|
"llvm.org/cmds/bugpoint.html"
|
2003-10-19 05:55:35 +08:00
|
|
|
" for more information.\n");
|
2005-08-02 10:16:17 +08:00
|
|
|
sys::SetInterruptFunction(BugpointInterruptFunction);
|
2009-07-02 00:58:40 +08:00
|
|
|
|
2009-07-16 06:16:10 +08:00
|
|
|
LLVMContext& Context = getGlobalContext();
|
2009-08-18 11:35:57 +08:00
|
|
|
// If we have an override, set it and then track the triple we want Modules
|
|
|
|
// to use.
|
2009-08-31 11:22:35 +08:00
|
|
|
if (!OverrideTriple.empty()) {
|
2010-08-28 09:30:02 +08:00
|
|
|
TargetTriple.setTriple(Triple::normalize(OverrideTriple));
|
|
|
|
outs() << "Override triple set to '" << TargetTriple.getTriple() << "'\n";
|
2009-08-31 11:22:35 +08:00
|
|
|
}
|
2009-08-18 11:35:57 +08:00
|
|
|
|
2010-03-19 08:09:28 +08:00
|
|
|
if (MemoryLimit < 0) {
|
|
|
|
// Set the default MemoryLimit. Be sure to update the flag's description if
|
|
|
|
// you change this.
|
|
|
|
if (sys::RunningOnValgrind() || UseValgrind)
|
|
|
|
MemoryLimit = 800;
|
|
|
|
else
|
|
|
|
MemoryLimit = 100;
|
|
|
|
}
|
|
|
|
|
2010-08-08 07:03:21 +08:00
|
|
|
BugDriver D(argv[0], FindBugs, TimeoutValue, MemoryLimit,
|
2010-03-19 08:09:28 +08:00
|
|
|
UseValgrind, Context);
|
2002-11-21 06:28:10 +08:00
|
|
|
if (D.addSources(InputFilenames)) return 1;
|
2009-08-18 11:35:57 +08:00
|
|
|
|
2009-07-20 15:01:01 +08:00
|
|
|
AddToDriver PM(D);
|
|
|
|
if (StandardCompileOpts) {
|
|
|
|
createStandardModulePasses(&PM, 3,
|
|
|
|
/*OptimizeSize=*/ false,
|
|
|
|
/*UnitAtATime=*/ true,
|
|
|
|
/*UnrollLoops=*/ true,
|
|
|
|
/*SimplifyLibCalls=*/ true,
|
|
|
|
/*HaveExceptions=*/ true,
|
|
|
|
createFunctionInliningPass());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StandardLinkOpts)
|
2009-07-28 07:23:47 +08:00
|
|
|
createStandardLTOPasses(&PM, /*Internalize=*/true,
|
2009-07-20 15:01:01 +08:00
|
|
|
/*RunInliner=*/true,
|
|
|
|
/*VerifyEach=*/false);
|
|
|
|
|
2010-08-08 11:55:08 +08:00
|
|
|
|
|
|
|
for (std::vector<const PassInfo*>::iterator I = PassList.begin(),
|
|
|
|
E = PassList.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
const PassInfo* PI = *I;
|
|
|
|
D.addPass(PI->getPassArgument());
|
|
|
|
}
|
2002-11-21 06:28:10 +08:00
|
|
|
|
2003-09-13 04:42:57 +08:00
|
|
|
// Bugpoint has the ability of generating a plethora of core files, so to
|
2004-09-02 06:55:40 +08:00
|
|
|
// avoid filling up the disk, we prevent it
|
2004-12-27 14:18:02 +08:00
|
|
|
sys::Process::PreventCoreFiles();
|
2003-09-13 04:42:57 +08:00
|
|
|
|
2010-04-12 13:08:25 +08:00
|
|
|
std::string Error;
|
|
|
|
bool Failure = D.run(Error);
|
|
|
|
if (!Error.empty()) {
|
|
|
|
errs() << Error;
|
|
|
|
return 1;
|
2004-02-19 01:32:54 +08:00
|
|
|
}
|
2010-04-12 13:08:25 +08:00
|
|
|
return Failure;
|
2002-11-21 06:28:10 +08:00
|
|
|
}
|