2006-06-07 06:30:59 +08:00
|
|
|
//===-- tools/bugpoint/ToolRunner.h -----------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2006-06-07 06:30:59 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file exposes an abstraction around a platform C compiler, used to
|
|
|
|
// compile C and assembly code. It also exposes an "AbstractIntepreter"
|
|
|
|
// interface, which is used to execute code using one of the LLVM execution
|
|
|
|
// engines.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_TOOLS_BUGPOINT_TOOLRUNNER_H
|
|
|
|
#define LLVM_TOOLS_BUGPOINT_TOOLRUNNER_H
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2009-08-18 11:35:57 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2009-08-05 17:32:10 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2016-09-07 01:18:22 +08:00
|
|
|
#include "llvm/Support/Error.h"
|
2010-11-30 02:16:10 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2012-12-04 18:44:52 +08:00
|
|
|
#include "llvm/Support/SystemUtils.h"
|
2006-06-07 06:30:59 +08:00
|
|
|
#include <exception>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2009-08-05 17:32:10 +08:00
|
|
|
extern cl::opt<bool> SaveTemps;
|
2009-08-18 11:35:57 +08:00
|
|
|
extern Triple TargetTriple;
|
2009-08-05 17:32:10 +08:00
|
|
|
|
2006-06-07 06:30:59 +08:00
|
|
|
class LLC;
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
2015-10-15 04:29:54 +08:00
|
|
|
// CC abstraction
|
2006-06-07 06:30:59 +08:00
|
|
|
//
|
2015-10-15 04:29:54 +08:00
|
|
|
class CC {
|
2016-09-02 09:21:37 +08:00
|
|
|
std::string CCPath; // The path to the cc executable.
|
|
|
|
std::string RemoteClientPath; // The path to the rsh / ssh executable.
|
2015-10-15 04:29:54 +08:00
|
|
|
std::vector<std::string> ccArgs; // CC-specific arguments.
|
|
|
|
CC(StringRef ccPath, StringRef RemotePath,
|
2016-09-02 09:21:37 +08:00
|
|
|
const std::vector<std::string> *CCArgs)
|
|
|
|
: CCPath(ccPath), RemoteClientPath(RemotePath) {
|
|
|
|
if (CCArgs)
|
|
|
|
ccArgs = *CCArgs;
|
2009-03-03 07:13:18 +08:00
|
|
|
}
|
2016-09-02 09:21:37 +08:00
|
|
|
|
2006-06-07 06:30:59 +08:00
|
|
|
public:
|
2010-03-16 14:41:47 +08:00
|
|
|
enum FileType { AsmFile, ObjectFile, CFile };
|
2006-06-07 06:30:59 +08:00
|
|
|
|
[bugpoint] Find 'opt', etc., in bugpoint directory
Summary:
When bugpoint attempts to find the other executables it needs to run,
such as `opt` or `clang`, it tries searching the user's PATH. However,
in many cases, the 'bugpoint' executable is part of an LLVM build, and
the 'opt' executable it's looking for is in that same directory.
Many LLVM tools handle this case by using the `Paths` parameter of
`llvm::sys::findProgramByName`, passing the parent path of the currently
running executable. Do this same thing for bugpoint. However, to
preserve the current behavior exactly, first search the user's PATH,
and then search for 'opt' in the directory containing 'bugpoint'.
Test Plan:
`check-llvm`. Many of the existing bugpoint tests no longer need to use the
`--opt-command` option as a result of these changes.
Reviewers: MatzeB, silvas, davide
Reviewed By: MatzeB, davide
Subscribers: davide, llvm-commits
Differential Revision: https://reviews.llvm.org/D54884
llvm-svn: 348734
2018-12-10 08:56:13 +08:00
|
|
|
static CC *create(const char *Argv0, std::string &Message,
|
|
|
|
const std::string &CCBinary,
|
2016-09-02 09:21:37 +08:00
|
|
|
const std::vector<std::string> *Args);
|
2006-06-07 06:30:59 +08:00
|
|
|
|
|
|
|
/// ExecuteProgram - Execute the program specified by "ProgramFile" (which is
|
|
|
|
/// either a .s file, or a .c file, specified by FileType), with the specified
|
|
|
|
/// arguments. Standard input is specified with InputFile, and standard
|
|
|
|
/// Output is captured to the specified OutputFile location. The SharedLibs
|
|
|
|
/// option specifies optional native shared objects that can be loaded into
|
|
|
|
/// the program for execution.
|
|
|
|
///
|
2016-09-07 01:18:22 +08:00
|
|
|
Expected<int> ExecuteProgram(
|
2016-09-02 09:21:37 +08:00
|
|
|
const std::string &ProgramFile, const std::vector<std::string> &Args,
|
|
|
|
FileType fileType, const std::string &InputFile,
|
2016-09-07 01:18:22 +08:00
|
|
|
const std::string &OutputFile,
|
2016-09-02 09:21:37 +08:00
|
|
|
const std::vector<std::string> &CCArgs = std::vector<std::string>(),
|
|
|
|
unsigned Timeout = 0, unsigned MemoryLimit = 0);
|
2006-06-07 06:30:59 +08:00
|
|
|
|
|
|
|
/// MakeSharedObject - This compiles the specified file (which is either a .c
|
|
|
|
/// file or a .s file) into a shared object.
|
|
|
|
///
|
2016-09-07 01:18:22 +08:00
|
|
|
Error MakeSharedObject(const std::string &InputFile, FileType fileType,
|
|
|
|
std::string &OutputFile,
|
|
|
|
const std::vector<std::string> &ArgsForCC);
|
2006-06-07 06:30:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
/// AbstractInterpreter Class - Subclasses of this class are used to execute
|
2007-07-05 05:55:50 +08:00
|
|
|
/// LLVM bitcode in a variety of ways. This abstract interface hides this
|
2006-06-07 06:30:59 +08:00
|
|
|
/// complexity behind a simple interface.
|
|
|
|
///
|
|
|
|
class AbstractInterpreter {
|
2011-12-20 10:50:00 +08:00
|
|
|
virtual void anchor();
|
2016-09-02 09:21:37 +08:00
|
|
|
|
2006-06-07 06:30:59 +08:00
|
|
|
public:
|
2009-08-06 04:21:17 +08:00
|
|
|
static LLC *createLLC(const char *Argv0, std::string &Message,
|
2016-09-02 09:21:37 +08:00
|
|
|
const std::string &CCBinary,
|
2014-04-28 12:05:08 +08:00
|
|
|
const std::vector<std::string> *Args = nullptr,
|
2015-10-15 04:29:54 +08:00
|
|
|
const std::vector<std::string> *CCArgs = nullptr,
|
2010-03-16 14:41:47 +08:00
|
|
|
bool UseIntegratedAssembler = false);
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2016-09-02 09:21:37 +08:00
|
|
|
static AbstractInterpreter *
|
2014-04-28 12:05:08 +08:00
|
|
|
createLLI(const char *Argv0, std::string &Message,
|
|
|
|
const std::vector<std::string> *Args = nullptr);
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2016-09-02 09:21:37 +08:00
|
|
|
static AbstractInterpreter *
|
2014-04-28 12:05:08 +08:00
|
|
|
createJIT(const char *Argv0, std::string &Message,
|
|
|
|
const std::vector<std::string> *Args = nullptr);
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2016-09-02 09:21:37 +08:00
|
|
|
static AbstractInterpreter *
|
[bugpoint] Find 'opt', etc., in bugpoint directory
Summary:
When bugpoint attempts to find the other executables it needs to run,
such as `opt` or `clang`, it tries searching the user's PATH. However,
in many cases, the 'bugpoint' executable is part of an LLVM build, and
the 'opt' executable it's looking for is in that same directory.
Many LLVM tools handle this case by using the `Paths` parameter of
`llvm::sys::findProgramByName`, passing the parent path of the currently
running executable. Do this same thing for bugpoint. However, to
preserve the current behavior exactly, first search the user's PATH,
and then search for 'opt' in the directory containing 'bugpoint'.
Test Plan:
`check-llvm`. Many of the existing bugpoint tests no longer need to use the
`--opt-command` option as a result of these changes.
Reviewers: MatzeB, silvas, davide
Reviewed By: MatzeB, davide
Subscribers: davide, llvm-commits
Differential Revision: https://reviews.llvm.org/D54884
llvm-svn: 348734
2018-12-10 08:56:13 +08:00
|
|
|
createCustomCompiler(const char *Argv0, std::string &Message,
|
2011-02-09 02:20:48 +08:00
|
|
|
const std::string &CompileCommandLine);
|
|
|
|
|
2016-09-02 09:21:37 +08:00
|
|
|
static AbstractInterpreter *
|
[bugpoint] Find 'opt', etc., in bugpoint directory
Summary:
When bugpoint attempts to find the other executables it needs to run,
such as `opt` or `clang`, it tries searching the user's PATH. However,
in many cases, the 'bugpoint' executable is part of an LLVM build, and
the 'opt' executable it's looking for is in that same directory.
Many LLVM tools handle this case by using the `Paths` parameter of
`llvm::sys::findProgramByName`, passing the parent path of the currently
running executable. Do this same thing for bugpoint. However, to
preserve the current behavior exactly, first search the user's PATH,
and then search for 'opt' in the directory containing 'bugpoint'.
Test Plan:
`check-llvm`. Many of the existing bugpoint tests no longer need to use the
`--opt-command` option as a result of these changes.
Reviewers: MatzeB, silvas, davide
Reviewed By: MatzeB, davide
Subscribers: davide, llvm-commits
Differential Revision: https://reviews.llvm.org/D54884
llvm-svn: 348734
2018-12-10 08:56:13 +08:00
|
|
|
createCustomExecutor(const char *Argv0, std::string &Message,
|
2011-02-09 02:20:48 +08:00
|
|
|
const std::string &ExecCommandLine);
|
2008-04-29 04:53:48 +08:00
|
|
|
|
2006-06-07 06:30:59 +08:00
|
|
|
virtual ~AbstractInterpreter() {}
|
|
|
|
|
2007-07-05 05:55:50 +08:00
|
|
|
/// compileProgram - Compile the specified program from bitcode to executable
|
2006-06-07 06:30:59 +08:00
|
|
|
/// code. This does not produce any output, it is only used when debugging
|
2010-04-12 13:08:25 +08:00
|
|
|
/// the code generator. It returns false if the code generator fails.
|
2016-09-07 01:18:22 +08:00
|
|
|
virtual Error compileProgram(const std::string &Bitcode, unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0) {
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Compile the specified program from bitcode to code understood by the CC
|
|
|
|
/// driver (either C or asm). Returns an error if the code generator fails,,
|
|
|
|
/// otherwise, the type of code emitted.
|
|
|
|
virtual Expected<CC::FileType> OutputCode(const std::string &Bitcode,
|
|
|
|
std::string &OutFile,
|
|
|
|
unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0) {
|
|
|
|
return make_error<StringError>(
|
|
|
|
"OutputCode not supported by this AbstractInterpreter!",
|
|
|
|
inconvertibleErrorCode());
|
2006-09-16 05:29:15 +08:00
|
|
|
}
|
2010-04-12 13:08:25 +08:00
|
|
|
|
2007-07-05 05:55:50 +08:00
|
|
|
/// ExecuteProgram - Run the specified bitcode file, emitting output to the
|
2010-04-12 13:08:25 +08:00
|
|
|
/// specified filename. This sets RetVal to the exit code of the program or
|
2016-09-07 01:18:22 +08:00
|
|
|
/// returns an Error if a problem was encountered that prevented execution of
|
2010-04-12 13:08:25 +08:00
|
|
|
/// the program.
|
2006-06-07 06:30:59 +08:00
|
|
|
///
|
2016-09-07 01:18:22 +08:00
|
|
|
virtual Expected<int> ExecuteProgram(
|
2016-09-02 09:21:37 +08:00
|
|
|
const std::string &Bitcode, const std::vector<std::string> &Args,
|
|
|
|
const std::string &InputFile, const std::string &OutputFile,
|
|
|
|
const std::vector<std::string> &CCArgs = std::vector<std::string>(),
|
|
|
|
const std::vector<std::string> &SharedLibs = std::vector<std::string>(),
|
|
|
|
unsigned Timeout = 0, unsigned MemoryLimit = 0) = 0;
|
2006-06-07 06:30:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
// LLC Implementation of AbstractIntepreter interface
|
|
|
|
//
|
|
|
|
class LLC : public AbstractInterpreter {
|
2009-03-03 07:13:18 +08:00
|
|
|
std::string LLCPath; // The path to the LLC executable.
|
|
|
|
std::vector<std::string> ToolArgs; // Extra args to pass to LLC.
|
2015-10-15 04:29:54 +08:00
|
|
|
CC *cc;
|
2010-03-16 14:41:47 +08:00
|
|
|
bool UseIntegratedAssembler;
|
2016-09-02 09:21:37 +08:00
|
|
|
|
2006-06-07 06:30:59 +08:00
|
|
|
public:
|
2016-09-02 09:21:37 +08:00
|
|
|
LLC(const std::string &llcPath, CC *cc, const std::vector<std::string> *Args,
|
2010-03-16 14:41:47 +08:00
|
|
|
bool useIntegratedAssembler)
|
2016-09-02 09:21:37 +08:00
|
|
|
: LLCPath(llcPath), cc(cc),
|
|
|
|
UseIntegratedAssembler(useIntegratedAssembler) {
|
2009-03-03 07:13:18 +08:00
|
|
|
ToolArgs.clear();
|
2016-09-02 09:21:37 +08:00
|
|
|
if (Args)
|
|
|
|
ToolArgs = *Args;
|
2006-06-07 06:30:59 +08:00
|
|
|
}
|
2015-10-15 04:29:54 +08:00
|
|
|
~LLC() override { delete cc; }
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2007-07-05 05:55:50 +08:00
|
|
|
/// compileProgram - Compile the specified program from bitcode to executable
|
2006-06-07 06:30:59 +08:00
|
|
|
/// code. This does not produce any output, it is only used when debugging
|
2010-04-12 13:08:25 +08:00
|
|
|
/// the code generator. Returns false if the code generator fails.
|
2016-09-07 01:18:22 +08:00
|
|
|
Error compileProgram(const std::string &Bitcode, unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0) override;
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2016-09-07 01:18:22 +08:00
|
|
|
Expected<int> ExecuteProgram(
|
2016-09-02 09:21:37 +08:00
|
|
|
const std::string &Bitcode, const std::vector<std::string> &Args,
|
|
|
|
const std::string &InputFile, const std::string &OutputFile,
|
|
|
|
const std::vector<std::string> &CCArgs = std::vector<std::string>(),
|
|
|
|
const std::vector<std::string> &SharedLibs = std::vector<std::string>(),
|
|
|
|
unsigned Timeout = 0, unsigned MemoryLimit = 0) override;
|
2006-06-07 06:30:59 +08:00
|
|
|
|
2016-09-07 01:18:22 +08:00
|
|
|
Expected<CC::FileType> OutputCode(const std::string &Bitcode,
|
|
|
|
std::string &OutFile, unsigned Timeout = 0,
|
|
|
|
unsigned MemoryLimit = 0) override;
|
2006-06-07 06:30:59 +08:00
|
|
|
};
|
|
|
|
|
[bugpoint] Find 'opt', etc., in bugpoint directory
Summary:
When bugpoint attempts to find the other executables it needs to run,
such as `opt` or `clang`, it tries searching the user's PATH. However,
in many cases, the 'bugpoint' executable is part of an LLVM build, and
the 'opt' executable it's looking for is in that same directory.
Many LLVM tools handle this case by using the `Paths` parameter of
`llvm::sys::findProgramByName`, passing the parent path of the currently
running executable. Do this same thing for bugpoint. However, to
preserve the current behavior exactly, first search the user's PATH,
and then search for 'opt' in the directory containing 'bugpoint'.
Test Plan:
`check-llvm`. Many of the existing bugpoint tests no longer need to use the
`--opt-command` option as a result of these changes.
Reviewers: MatzeB, silvas, davide
Reviewed By: MatzeB, davide
Subscribers: davide, llvm-commits
Differential Revision: https://reviews.llvm.org/D54884
llvm-svn: 348734
2018-12-10 08:56:13 +08:00
|
|
|
/// Find the first executable file \ExeName, either in the user's PATH or,
|
|
|
|
/// failing that, in the same directory as argv[0]. This allows us to find
|
|
|
|
/// another LLVM tool if it is built in the same directory. If no executable is
|
|
|
|
/// found, an error is returned.
|
|
|
|
ErrorOr<std::string> FindProgramByName(const std::string &ExeName,
|
|
|
|
const char *Argv0, void *MainAddr);
|
|
|
|
|
2006-06-07 06:30:59 +08:00
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|