mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Run opt instead of bugpoint itself.
Fixes PR753. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110333 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6d50ed6321
commit
d02dc8d096
@ -66,12 +66,12 @@ std::string llvm::getPassesString(const std::vector<const PassInfo*> &Passes) {
|
|||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
BugDriver::BugDriver(const char *toolname, bool as_child, bool find_bugs,
|
BugDriver::BugDriver(const char *toolname, bool find_bugs,
|
||||||
unsigned timeout, unsigned memlimit, bool use_valgrind,
|
unsigned timeout, unsigned memlimit, bool use_valgrind,
|
||||||
LLVMContext& ctxt)
|
LLVMContext& ctxt)
|
||||||
: Context(ctxt), ToolName(toolname), ReferenceOutputFile(OutputFile),
|
: Context(ctxt), ToolName(toolname), ReferenceOutputFile(OutputFile),
|
||||||
Program(0), Interpreter(0), SafeInterpreter(0), gcc(0),
|
Program(0), Interpreter(0), SafeInterpreter(0), gcc(0),
|
||||||
run_as_child(as_child), run_find_bugs(find_bugs), Timeout(timeout),
|
run_find_bugs(find_bugs), Timeout(timeout),
|
||||||
MemoryLimit(memlimit), UseValgrind(use_valgrind) {}
|
MemoryLimit(memlimit), UseValgrind(use_valgrind) {}
|
||||||
|
|
||||||
BugDriver::~BugDriver() {
|
BugDriver::~BugDriver() {
|
||||||
@ -119,15 +119,13 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) {
|
|||||||
Program = ParseInputFile(Filenames[0], Context);
|
Program = ParseInputFile(Filenames[0], Context);
|
||||||
if (Program == 0) return true;
|
if (Program == 0) return true;
|
||||||
|
|
||||||
if (!run_as_child)
|
outs() << "Read input file : '" << Filenames[0] << "'\n";
|
||||||
outs() << "Read input file : '" << Filenames[0] << "'\n";
|
|
||||||
|
|
||||||
for (unsigned i = 1, e = Filenames.size(); i != e; ++i) {
|
for (unsigned i = 1, e = Filenames.size(); i != e; ++i) {
|
||||||
std::auto_ptr<Module> M(ParseInputFile(Filenames[i], Context));
|
std::auto_ptr<Module> M(ParseInputFile(Filenames[i], Context));
|
||||||
if (M.get() == 0) return true;
|
if (M.get() == 0) return true;
|
||||||
|
|
||||||
if (!run_as_child)
|
outs() << "Linking in input file: '" << Filenames[i] << "'\n";
|
||||||
outs() << "Linking in input file: '" << Filenames[i] << "'\n";
|
|
||||||
std::string ErrorMessage;
|
std::string ErrorMessage;
|
||||||
if (Linker::LinkModules(Program, M.get(), &ErrorMessage)) {
|
if (Linker::LinkModules(Program, M.get(), &ErrorMessage)) {
|
||||||
errs() << ToolName << ": error linking in '" << Filenames[i] << "': "
|
errs() << ToolName << ": error linking in '" << Filenames[i] << "': "
|
||||||
@ -136,8 +134,7 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!run_as_child)
|
outs() << "*** All input ok\n";
|
||||||
outs() << "*** All input ok\n";
|
|
||||||
|
|
||||||
// All input files read successfully!
|
// All input files read successfully!
|
||||||
return false;
|
return false;
|
||||||
@ -149,14 +146,6 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) {
|
|||||||
/// variables are set up from command line arguments.
|
/// variables are set up from command line arguments.
|
||||||
///
|
///
|
||||||
bool BugDriver::run(std::string &ErrMsg) {
|
bool BugDriver::run(std::string &ErrMsg) {
|
||||||
// The first thing to do is determine if we're running as a child. If we are,
|
|
||||||
// then what to do is very narrow. This form of invocation is only called
|
|
||||||
// from the runPasses method to actually run those passes in a child process.
|
|
||||||
if (run_as_child) {
|
|
||||||
// Execute the passes
|
|
||||||
return runPassesAsChild(PassesToRun);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (run_find_bugs) {
|
if (run_find_bugs) {
|
||||||
// Rearrange the passes and apply them to the program. Repeat this process
|
// Rearrange the passes and apply them to the program. Repeat this process
|
||||||
// until the user kills the program or we find a bug.
|
// until the user kills the program or we find a bug.
|
||||||
|
@ -51,7 +51,6 @@ class BugDriver {
|
|||||||
AbstractInterpreter *Interpreter; // How to run the program
|
AbstractInterpreter *Interpreter; // How to run the program
|
||||||
AbstractInterpreter *SafeInterpreter; // To generate reference output, etc.
|
AbstractInterpreter *SafeInterpreter; // To generate reference output, etc.
|
||||||
GCC *gcc;
|
GCC *gcc;
|
||||||
bool run_as_child;
|
|
||||||
bool run_find_bugs;
|
bool run_find_bugs;
|
||||||
unsigned Timeout;
|
unsigned Timeout;
|
||||||
unsigned MemoryLimit;
|
unsigned MemoryLimit;
|
||||||
@ -62,7 +61,7 @@ class BugDriver {
|
|||||||
friend class ReduceMisCodegenFunctions;
|
friend class ReduceMisCodegenFunctions;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BugDriver(const char *toolname, bool as_child, bool find_bugs,
|
BugDriver(const char *toolname, bool find_bugs,
|
||||||
unsigned timeout, unsigned memlimit, bool use_valgrind,
|
unsigned timeout, unsigned memlimit, bool use_valgrind,
|
||||||
LLVMContext& ctxt);
|
LLVMContext& ctxt);
|
||||||
~BugDriver();
|
~BugDriver();
|
||||||
@ -290,9 +289,6 @@ private:
|
|||||||
return runPasses(M, PassesToRun, Filename, DeleteOutput);
|
return runPasses(M, PassesToRun, Filename, DeleteOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// runAsChild - The actual "runPasses" guts that runs in a child process.
|
|
||||||
int runPassesAsChild(const std::vector<const PassInfo*> &PassesToRun);
|
|
||||||
|
|
||||||
/// initializeExecutionEnvironment - This method is used to set up the
|
/// initializeExecutionEnvironment - This method is used to set up the
|
||||||
/// environment for executing LLVM programs.
|
/// environment for executing LLVM programs.
|
||||||
///
|
///
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "llvm/Support/FileUtilities.h"
|
#include "llvm/Support/FileUtilities.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/System/Path.h"
|
#include "llvm/System/Path.h"
|
||||||
#include "llvm/System/Program.h"
|
#include "llvm/System/Program.h"
|
||||||
@ -85,37 +86,6 @@ void BugDriver::EmitProgressBitcode(const Module *M,
|
|||||||
outs() << getPassesString(PassesToRun) << "\n";
|
outs() << getPassesString(PassesToRun) << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) {
|
|
||||||
std::string ErrInfo;
|
|
||||||
raw_fd_ostream OutFile(ChildOutput.c_str(), ErrInfo,
|
|
||||||
raw_fd_ostream::F_Binary);
|
|
||||||
if (!ErrInfo.empty()) {
|
|
||||||
errs() << "Error opening bitcode file: " << ChildOutput << "\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
PassManager PM;
|
|
||||||
// Make sure that the appropriate target data is always used...
|
|
||||||
PM.add(new TargetData(Program));
|
|
||||||
|
|
||||||
for (unsigned i = 0, e = Passes.size(); i != e; ++i) {
|
|
||||||
if (Passes[i]->getNormalCtor())
|
|
||||||
PM.add(Passes[i]->getNormalCtor()());
|
|
||||||
else
|
|
||||||
errs() << "Cannot create pass yet: " << Passes[i]->getPassName() << "\n";
|
|
||||||
}
|
|
||||||
// Check that the module is well formed on completion of optimization
|
|
||||||
PM.add(createVerifierPass());
|
|
||||||
|
|
||||||
// Write bitcode out to disk as the last step...
|
|
||||||
PM.add(createBitcodeWriterPass(OutFile));
|
|
||||||
|
|
||||||
// Run all queued passes.
|
|
||||||
PM.run(*Program);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
cl::opt<bool> SilencePasses("silence-passes", cl::desc("Suppress output of running passes (both stdout and stderr)"));
|
cl::opt<bool> SilencePasses("silence-passes", cl::desc("Suppress output of running passes (both stdout and stderr)"));
|
||||||
|
|
||||||
/// runPasses - Run the specified passes on Program, outputting a bitcode file
|
/// runPasses - Run the specified passes on Program, outputting a bitcode file
|
||||||
@ -164,17 +134,25 @@ bool BugDriver::runPasses(Module *Program,
|
|||||||
|
|
||||||
// setup the child process' arguments
|
// setup the child process' arguments
|
||||||
SmallVector<const char*, 8> Args;
|
SmallVector<const char*, 8> Args;
|
||||||
sys::Path tool = sys::Program::FindProgramByName(ToolName);
|
std::string Opt;
|
||||||
|
llvm::StringRef TN(ToolName);
|
||||||
|
if (TN.find('/') == llvm::StringRef::npos) {
|
||||||
|
Opt = ToolName;
|
||||||
|
} else {
|
||||||
|
std::pair<llvm::StringRef, llvm::StringRef> P = TN.rsplit('/');
|
||||||
|
Opt = P.first.str() + "/" + "opt";
|
||||||
|
}
|
||||||
|
|
||||||
|
sys::Path tool = sys::Program::FindProgramByName(Opt);
|
||||||
if (UseValgrind) {
|
if (UseValgrind) {
|
||||||
Args.push_back("valgrind");
|
Args.push_back("valgrind");
|
||||||
Args.push_back("--error-exitcode=1");
|
Args.push_back("--error-exitcode=1");
|
||||||
Args.push_back("-q");
|
Args.push_back("-q");
|
||||||
Args.push_back(tool.c_str());
|
Args.push_back(tool.c_str());
|
||||||
} else
|
} else
|
||||||
Args.push_back(ToolName);
|
Args.push_back(Opt.c_str());
|
||||||
|
|
||||||
Args.push_back("-as-child");
|
Args.push_back("-o");
|
||||||
Args.push_back("-child-output");
|
|
||||||
Args.push_back(OutputFilename.c_str());
|
Args.push_back(OutputFilename.c_str());
|
||||||
std::vector<std::string> pass_args;
|
std::vector<std::string> pass_args;
|
||||||
for (unsigned i = 0, e = PluginLoader::getNumPlugins(); i != e; ++i) {
|
for (unsigned i = 0, e = PluginLoader::getNumPlugins(); i != e; ++i) {
|
||||||
@ -192,6 +170,12 @@ bool BugDriver::runPasses(Module *Program,
|
|||||||
Args.push_back(*ExtraArgs);
|
Args.push_back(*ExtraArgs);
|
||||||
Args.push_back(0);
|
Args.push_back(0);
|
||||||
|
|
||||||
|
DEBUG(errs() << "\nAbout to run:\t";
|
||||||
|
for (unsigned i = 0, e = Args.size()-1; i != e; ++i)
|
||||||
|
errs() << " " << Args[i];
|
||||||
|
errs() << "\n";
|
||||||
|
);
|
||||||
|
|
||||||
sys::Path prog;
|
sys::Path prog;
|
||||||
if (UseValgrind)
|
if (UseValgrind)
|
||||||
prog = sys::Program::FindProgramByName("valgrind");
|
prog = sys::Program::FindProgramByName("valgrind");
|
||||||
|
@ -29,13 +29,6 @@
|
|||||||
#include "llvm/LinkAllVMCore.h"
|
#include "llvm/LinkAllVMCore.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
// AsChild - Specifies that this invocation of bugpoint is being generated
|
|
||||||
// from a parent process. It is not intended to be used by users so the
|
|
||||||
// option is hidden.
|
|
||||||
static cl::opt<bool>
|
|
||||||
AsChild("as-child", cl::desc("Run bugpoint as child process"),
|
|
||||||
cl::ReallyHidden);
|
|
||||||
|
|
||||||
static cl::opt<bool>
|
static cl::opt<bool>
|
||||||
FindBugs("find-bugs", cl::desc("Run many different optimization sequences "
|
FindBugs("find-bugs", cl::desc("Run many different optimization sequences "
|
||||||
"on program to find bugs"), cl::init(false));
|
"on program to find bugs"), cl::init(false));
|
||||||
@ -123,7 +116,7 @@ int main(int argc, char **argv) {
|
|||||||
MemoryLimit = 100;
|
MemoryLimit = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
BugDriver D(argv[0], AsChild, FindBugs, TimeoutValue, MemoryLimit,
|
BugDriver D(argv[0], FindBugs, TimeoutValue, MemoryLimit,
|
||||||
UseValgrind, Context);
|
UseValgrind, Context);
|
||||||
if (D.addSources(InputFilenames)) return 1;
|
if (D.addSources(InputFilenames)) return 1;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user