2003-10-20 17:57:13 +00:00
|
|
|
//===- bugpoint.cpp - The LLVM Bugpoint utility ---------------------------===//
|
2005-04-22 00:00:37 +00:00
|
|
|
//
|
2003-10-20 17:47:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:44:31 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 00:00:37 +00:00
|
|
|
//
|
2003-10-20 17:47:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-11-20 22:28:10 +00: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-06 22:30:59 +00:00
|
|
|
#include "ToolRunner.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/LLVMContext.h"
|
2014-03-04 12:32:42 +00:00
|
|
|
#include "llvm/IR/LegacyPassNameParser.h"
|
2013-01-10 21:56:40 +00:00
|
|
|
#include "llvm/LinkAllIR.h"
|
2013-01-19 08:03:47 +00:00
|
|
|
#include "llvm/LinkAllPasses.h"
|
2011-08-02 21:50:27 +00:00
|
|
|
#include "llvm/PassManager.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2006-12-06 01:18:01 +00:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/PluginLoader.h"
|
2009-03-06 05:34:10 +00:00
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/Process.h"
|
|
|
|
#include "llvm/Support/Signals.h"
|
|
|
|
#include "llvm/Support/Valgrind.h"
|
2011-08-02 21:50:24 +00:00
|
|
|
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
2011-01-13 19:48:54 +00:00
|
|
|
|
2011-01-14 15:55:50 +00:00
|
|
|
//Enable this macro to debug bugpoint itself.
|
|
|
|
//#define DEBUG_BUGPOINT 1
|
2011-01-13 19:48:54 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-01-15 08:21:38 +00:00
|
|
|
static cl::opt<bool>
|
2008-02-18 17:15:45 +00:00
|
|
|
FindBugs("find-bugs", cl::desc("Run many different optimization sequences "
|
2006-08-15 16:40:49 +00:00
|
|
|
"on program to find bugs"), cl::init(false));
|
2005-12-22 20:02:55 +00:00
|
|
|
|
2002-11-20 22:28:10 +00:00
|
|
|
static cl::list<std::string>
|
|
|
|
InputFilenames(cl::Positional, cl::OneOrMore,
|
|
|
|
cl::desc("<input llvm ll/bc files>"));
|
|
|
|
|
2006-06-13 03:10:48 +00: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 00:09:28 +00:00
|
|
|
static cl::opt<int>
|
|
|
|
MemoryLimit("mlimit", cl::init(-1), cl::value_desc("MBytes"),
|
2013-10-25 17:41:41 +00:00
|
|
|
cl::desc("Maximum amount of memory to use. 0 disables check."
|
|
|
|
" Defaults to 300MB (800MB under valgrind)."));
|
2010-03-19 00:09:28 +00:00
|
|
|
|
|
|
|
static cl::opt<bool>
|
|
|
|
UseValgrind("enable-valgrind",
|
|
|
|
cl::desc("Run optimizations through valgrind"));
|
2007-02-16 19:11:07 +00:00
|
|
|
|
2002-11-20 22:28:10 +00:00
|
|
|
// The AnalysesList is automatically populated with registered Passes by the
|
|
|
|
// PassNameParser.
|
|
|
|
//
|
2010-07-20 08:26:15 +00: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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7293 91177308-0d34-0410-b5e6-96231b3b80d8
2003-07-24 18:17:43 +00:00
|
|
|
PassList(cl::desc("Passes available:"), cl::ZeroOrMore);
|
2002-11-20 22:28:10 +00:00
|
|
|
|
2009-07-20 07:01:01 +00:00
|
|
|
static cl::opt<bool>
|
2014-01-15 08:21:38 +00:00
|
|
|
StandardCompileOpts("std-compile-opts",
|
2009-07-20 07:01:01 +00:00
|
|
|
cl::desc("Include the standard compile time optimizations"));
|
|
|
|
|
|
|
|
static cl::opt<bool>
|
2014-01-15 08:21:38 +00:00
|
|
|
StandardLinkOpts("std-link-opts",
|
2009-07-20 07:01:01 +00:00
|
|
|
cl::desc("Include the standard link time optimizations"));
|
|
|
|
|
2011-06-06 22:45:46 +00:00
|
|
|
static cl::opt<bool>
|
|
|
|
OptLevelO1("O1",
|
2014-02-19 22:16:49 +00:00
|
|
|
cl::desc("Optimization level 1. Identical to 'opt -O1'"));
|
2011-06-06 22:45:46 +00:00
|
|
|
|
|
|
|
static cl::opt<bool>
|
|
|
|
OptLevelO2("O2",
|
2014-02-19 22:16:49 +00:00
|
|
|
cl::desc("Optimization level 2. Identical to 'opt -O2'"));
|
2011-06-06 22:45:46 +00:00
|
|
|
|
|
|
|
static cl::opt<bool>
|
|
|
|
OptLevelO3("O3",
|
2014-02-19 22:16:49 +00:00
|
|
|
cl::desc("Optimization level 3. Identical to 'opt -O3'"));
|
2011-06-06 22:45:46 +00:00
|
|
|
|
2009-08-18 03:35:57 +00:00
|
|
|
static cl::opt<std::string>
|
|
|
|
OverrideTriple("mtriple", cl::desc("Override target triple for module"));
|
|
|
|
|
2005-08-02 02:16:17 +00:00
|
|
|
/// BugpointIsInterrupted - Set to true when the user presses ctrl-c.
|
|
|
|
bool llvm::BugpointIsInterrupted = false;
|
|
|
|
|
2011-01-13 19:48:54 +00:00
|
|
|
#ifndef DEBUG_BUGPOINT
|
2005-08-02 02:16:17 +00:00
|
|
|
static void BugpointInterruptFunction() {
|
|
|
|
BugpointIsInterrupted = true;
|
|
|
|
}
|
2011-01-13 19:48:54 +00:00
|
|
|
#endif
|
2005-08-02 02:16:17 +00:00
|
|
|
|
2009-07-20 07:01:01 +00:00
|
|
|
// Hack to capture a pass list.
|
|
|
|
namespace {
|
2011-06-06 22:45:46 +00:00
|
|
|
class AddToDriver : public FunctionPassManager {
|
2009-07-20 07:01:01 +00:00
|
|
|
BugDriver &D;
|
|
|
|
public:
|
2014-04-25 04:24:47 +00:00
|
|
|
AddToDriver(BugDriver &_D) : FunctionPassManager(nullptr), D(_D) {}
|
2014-01-15 08:21:38 +00:00
|
|
|
|
2014-03-08 08:27:28 +00:00
|
|
|
void add(Pass *P) override {
|
2010-08-06 18:33:48 +00:00
|
|
|
const void *ID = P->getPassID();
|
|
|
|
const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(ID);
|
2010-08-08 03:55:08 +00:00
|
|
|
D.addPass(PI->getPassArgument());
|
2009-07-20 07:01:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-03-14 04:04:14 +00:00
|
|
|
#ifdef LINK_POLLY_INTO_TOOLS
|
|
|
|
namespace polly {
|
|
|
|
void initializePollyPasses(llvm::PassRegistry &Registry);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-11-20 22:28:10 +00:00
|
|
|
int main(int argc, char **argv) {
|
2011-01-13 19:48:54 +00:00
|
|
|
#ifndef DEBUG_BUGPOINT
|
2009-03-06 05:34:10 +00:00
|
|
|
llvm::sys::PrintStackTraceOnErrorSignal();
|
|
|
|
llvm::PrettyStackTraceProgram X(argc, argv);
|
|
|
|
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
2011-01-13 19:48:54 +00:00
|
|
|
#endif
|
2014-01-15 08:21:38 +00:00
|
|
|
|
2010-10-19 17:21:58 +00:00
|
|
|
// Initialize passes
|
|
|
|
PassRegistry &Registry = *PassRegistry::getPassRegistry();
|
|
|
|
initializeCore(Registry);
|
|
|
|
initializeScalarOpts(Registry);
|
2013-01-28 01:35:51 +00:00
|
|
|
initializeObjCARCOpts(Registry);
|
2012-02-07 21:11:12 +00:00
|
|
|
initializeVectorization(Registry);
|
2010-10-19 17:21:58 +00:00
|
|
|
initializeIPO(Registry);
|
|
|
|
initializeAnalysis(Registry);
|
|
|
|
initializeIPA(Registry);
|
|
|
|
initializeTransformUtils(Registry);
|
|
|
|
initializeInstCombine(Registry);
|
|
|
|
initializeInstrumentation(Registry);
|
|
|
|
initializeTarget(Registry);
|
2014-01-15 08:21:38 +00:00
|
|
|
|
2014-03-14 04:04:14 +00:00
|
|
|
#ifdef LINK_POLLY_INTO_TOOLS
|
|
|
|
polly::initializePollyPasses(Registry);
|
|
|
|
#endif
|
|
|
|
|
2003-10-18 21:55:35 +00:00
|
|
|
cl::ParseCommandLineOptions(argc, argv,
|
2007-10-08 15:45:12 +00:00
|
|
|
"LLVM automatic testcase reducer. See\nhttp://"
|
2009-02-07 18:56:30 +00:00
|
|
|
"llvm.org/cmds/bugpoint.html"
|
2003-10-18 21:55:35 +00:00
|
|
|
" for more information.\n");
|
2011-01-13 19:48:54 +00:00
|
|
|
#ifndef DEBUG_BUGPOINT
|
2005-08-02 02:16:17 +00:00
|
|
|
sys::SetInterruptFunction(BugpointInterruptFunction);
|
2011-01-13 19:48:54 +00:00
|
|
|
#endif
|
2009-07-01 16:58:40 +00:00
|
|
|
|
2009-07-15 22:16:10 +00:00
|
|
|
LLVMContext& Context = getGlobalContext();
|
2009-08-18 03:35:57 +00:00
|
|
|
// If we have an override, set it and then track the triple we want Modules
|
|
|
|
// to use.
|
2009-08-31 03:22:35 +00:00
|
|
|
if (!OverrideTriple.empty()) {
|
2010-08-28 01:30:02 +00:00
|
|
|
TargetTriple.setTriple(Triple::normalize(OverrideTriple));
|
|
|
|
outs() << "Override triple set to '" << TargetTriple.getTriple() << "'\n";
|
2009-08-31 03:22:35 +00:00
|
|
|
}
|
2009-08-18 03:35:57 +00:00
|
|
|
|
2010-03-19 00:09:28 +00: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
|
2013-10-25 17:41:41 +00:00
|
|
|
MemoryLimit = 300;
|
2010-03-19 00:09:28 +00:00
|
|
|
}
|
|
|
|
|
2010-08-07 23:03:21 +00:00
|
|
|
BugDriver D(argv[0], FindBugs, TimeoutValue, MemoryLimit,
|
2010-03-19 00:09:28 +00:00
|
|
|
UseValgrind, Context);
|
2002-11-20 22:28:10 +00:00
|
|
|
if (D.addSources(InputFilenames)) return 1;
|
2014-01-15 08:21:38 +00:00
|
|
|
|
2009-07-20 07:01:01 +00:00
|
|
|
AddToDriver PM(D);
|
|
|
|
if (StandardCompileOpts) {
|
2011-05-22 00:20:07 +00:00
|
|
|
PassManagerBuilder Builder;
|
|
|
|
Builder.OptLevel = 3;
|
|
|
|
Builder.Inliner = createFunctionInliningPass();
|
|
|
|
Builder.populateModulePassManager(PM);
|
2009-07-20 07:01:01 +00:00
|
|
|
}
|
2014-01-15 08:21:38 +00:00
|
|
|
|
2011-05-22 00:20:07 +00:00
|
|
|
if (StandardLinkOpts) {
|
|
|
|
PassManagerBuilder Builder;
|
2014-08-05 20:10:38 +00:00
|
|
|
Builder.populateLTOPassManager(PM, /*RunInliner=*/true, false);
|
2011-05-22 00:20:07 +00:00
|
|
|
}
|
2009-07-20 07:01:01 +00:00
|
|
|
|
2011-06-06 22:45:46 +00:00
|
|
|
if (OptLevelO1 || OptLevelO2 || OptLevelO3) {
|
|
|
|
PassManagerBuilder Builder;
|
|
|
|
if (OptLevelO1)
|
|
|
|
Builder.Inliner = createAlwaysInlinerPass();
|
|
|
|
else if (OptLevelO2)
|
|
|
|
Builder.Inliner = createFunctionInliningPass(225);
|
|
|
|
else
|
|
|
|
Builder.Inliner = createFunctionInliningPass(275);
|
|
|
|
|
|
|
|
// Note that although clang/llvm-gcc use two separate passmanagers
|
|
|
|
// here, it shouldn't normally make a difference.
|
|
|
|
Builder.populateFunctionPassManager(PM);
|
|
|
|
Builder.populateModulePassManager(PM);
|
|
|
|
}
|
2010-08-08 03:55:08 +00: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-20 22:28:10 +00:00
|
|
|
|
2003-09-12 20:42:57 +00:00
|
|
|
// Bugpoint has the ability of generating a plethora of core files, so to
|
2004-09-01 22:55:40 +00:00
|
|
|
// avoid filling up the disk, we prevent it
|
2011-01-13 19:48:54 +00:00
|
|
|
#ifndef DEBUG_BUGPOINT
|
2004-12-27 06:18:02 +00:00
|
|
|
sys::Process::PreventCoreFiles();
|
2011-01-13 19:48:54 +00:00
|
|
|
#endif
|
2003-09-12 20:42:57 +00:00
|
|
|
|
2010-04-12 05:08:25 +00:00
|
|
|
std::string Error;
|
|
|
|
bool Failure = D.run(Error);
|
|
|
|
if (!Error.empty()) {
|
|
|
|
errs() << Error;
|
|
|
|
return 1;
|
2004-02-18 17:32:54 +00:00
|
|
|
}
|
2010-04-12 05:08:25 +00:00
|
|
|
return Failure;
|
2002-11-20 22:28:10 +00:00
|
|
|
}
|