[llvm-driver] Add various tools to the llvm-driver

The llvm-driver, enabled with LLVM_TOOL_LLVM_DRIVER_BUILD combines many llvm executables
into one to save overall toolchain size. This patch adds a few more llvm tools to the
llvm-driver.

Differential Revision: https://reviews.llvm.org/D135281
This commit is contained in:
Alex Brachet 2022-10-06 05:16:13 +00:00
parent 7cbc920669
commit d5090cd94a
25 changed files with 120 additions and 27 deletions

View File

@ -1,6 +1,6 @@
set(LLVM_LINK_COMPONENTS
BinaryFormat
InterfaceStub
InterfaceStub
Object
Support
TextAPI
@ -18,4 +18,6 @@ add_llvm_tool(llvm-ifs
DEPENDS
IFSOptsTableGen
GENERATE_DRIVER
)

View File

@ -376,7 +376,7 @@ static DriverConfig parseArgs(int argc, char *const *argv) {
return Config;
}
int main(int argc, char *argv[]) {
int llvm_ifs_main(int argc, char *argv[]) {
DriverConfig Config = parseArgs(argc, argv);
if (Config.InputFilePaths.empty())

View File

@ -16,6 +16,7 @@ add_llvm_tool(llvm-lipo
llvm-lipo.cpp
DEPENDS
LipoOptsTableGen
GENERATE_DRIVER
)
if(LLVM_INSTALL_CCTOOLS_SYMLINKS)

View File

@ -719,7 +719,7 @@ replaceSlices(LLVMContext &LLVMCtx,
exit(EXIT_SUCCESS);
}
int main(int argc, char **argv) {
int llvm_lipo_main(int argc, char **argv) {
InitLLVM X(argc, argv);
llvm::InitializeAllTargetInfos();
llvm::InitializeAllTargetMCs();

View File

@ -11,4 +11,5 @@ add_public_tablegen_target(MtTableGen)
add_llvm_tool(llvm-mt
llvm-mt.cpp
GENERATE_DRIVER
)

View File

@ -79,7 +79,7 @@ static void error(Error EC) {
});
}
int main(int Argc, const char **Argv) {
int llvm_mt_main(int Argc, char **Argv) {
InitLLVM X(Argc, Argv);
CvtResOptTable T;

View File

@ -21,6 +21,7 @@ add_llvm_tool(llvm-nm
DEPENDS
NmOptsTableGen
intrinsics_gen
GENERATE_DRIVER
)
if(LLVM_INSTALL_BINUTILS_SYMLINKS)

View File

@ -2297,7 +2297,7 @@ exportSymbolNamesFromFiles(const std::vector<std::string> &InputFilenames) {
printExportSymbolList(SymbolList);
}
int main(int argc, char **argv) {
int llvm_nm_main(int argc, char **argv) {
InitLLVM X(argc, argv);
BumpPtrAllocator A;
StringSaver Saver(A);
@ -2474,4 +2474,5 @@ int main(int argc, char **argv) {
if (HadError)
return 1;
return 0;
}

View File

@ -11,4 +11,5 @@ add_llvm_tool(llvm-profdata
DEPENDS
intrinsics_gen
GENERATE_DRIVER
)

View File

@ -2826,7 +2826,8 @@ static int show_main(int argc, const char *argv[]) {
return showMemProfProfile(Filename, ProfiledBinary, OS);
}
int main(int argc, const char *argv[]) {
int llvm_profdata_main(int argc, char **argvNonConst) {
const char **argv = const_cast<const char **>(argvNonConst);
InitLLVM X(argc, argv);
StringRef ProgName(sys::path::filename(argv[0]));

View File

@ -19,6 +19,7 @@ add_llvm_tool(llvm-rc
ResourceScriptParser.cpp
ResourceScriptStmt.cpp
ResourceScriptToken.cpp
GENERATE_DRIVER
)
add_llvm_tool_symlink(llvm-windres llvm-rc)

View File

@ -724,12 +724,12 @@ void doCvtres(std::string Src, std::string Dest, std::string TargetTriple) {
} // anonymous namespace
int main(int Argc, const char **Argv) {
int llvm_rc_main(int Argc, char **Argv) {
InitLLVM X(Argc, Argv);
ExitOnErr.setBanner("llvm-rc: ");
const char **DashDash = std::find_if(
Argv + 1, Argv + Argc, [](StringRef Str) { return Str == "--"; });
char **DashDash = std::find_if(Argv + 1, Argv + Argc,
[](StringRef Str) { return Str == "--"; });
ArrayRef<const char *> ArgsArr = makeArrayRef(Argv + 1, DashDash);
ArrayRef<const char *> FileArgsArr;
if (DashDash != Argv + Argc)

View File

@ -27,6 +27,7 @@ add_llvm_tool(llvm-readobj
Win64EHDumper.cpp
WindowsResourceDumper.cpp
XCOFFDumper.cpp
GENERATE_DRIVER
)
add_llvm_tool_symlink(llvm-readelf llvm-readobj)

View File

@ -613,7 +613,7 @@ std::unique_ptr<ScopedPrinter> createWriter() {
return std::make_unique<ScopedPrinter>(fouts());
}
int main(int argc, char *argv[]) {
int llvm_readobj_main(int argc, char *argv[]) {
InitLLVM X(argc, argv);
BumpPtrAllocator A;
StringSaver Saver(A);

View File

@ -12,6 +12,7 @@ add_llvm_tool(llvm-size
llvm-size.cpp
DEPENDS
SizeOptsTableGen
GENERATE_DRIVER
)
if(LLVM_INSTALL_BINUTILS_SYMLINKS)

View File

@ -866,7 +866,7 @@ static void printBerkeleyTotals() {
<< "(TOTALS)\n";
}
int main(int argc, char **argv) {
int llvm_size_main(int argc, char **argv) {
InitLLVM X(argc, argv);
BumpPtrAllocator A;
StringSaver Saver(A);
@ -941,4 +941,5 @@ int main(int argc, char **argv) {
if (HadError)
return 1;
return 0;
}

View File

@ -1,11 +1,12 @@
import("//llvm/utils/TableGen/tablegen.gni")
import("//llvm/utils/gn/build/driver_executable.gni")
tablegen("Opts") {
visibility = [ ":llvm-ifs" ]
args = [ "-gen-opt-parser-defs" ]
}
executable("llvm-ifs") {
driver_executable("llvm-ifs") {
deps = [
":Opts",
"//llvm/lib/InterfaceStub",

View File

@ -1,5 +1,6 @@
import("//llvm/tools/cctools_symlinks.gni")
import("//llvm/utils/TableGen/tablegen.gni")
import("//llvm/utils/gn/build/driver_executable.gni")
import("//llvm/utils/gn/build/symlink_or_copy.gni")
tablegen("LipoOpts") {
@ -23,7 +24,7 @@ group("symlinks") {
}
}
executable("llvm-lipo") {
driver_executable("llvm-lipo") {
deps = [
":LipoOpts",
"//llvm/lib/Object",

View File

@ -1,11 +1,12 @@
import("//llvm/utils/TableGen/tablegen.gni")
import("//llvm/utils/gn/build/driver_executable.gni")
tablegen("Opts") {
visibility = [ ":llvm-mt" ]
args = [ "-gen-opt-parser-defs" ]
}
executable("llvm-mt") {
driver_executable("llvm-mt") {
deps = [
":Opts",
"//llvm/lib/Option",

View File

@ -1,5 +1,6 @@
import("//llvm/tools/binutils_symlinks.gni")
import("//llvm/utils/TableGen/tablegen.gni")
import("//llvm/utils/gn/build/driver_executable.gni")
import("//llvm/utils/gn/build/symlink_or_copy.gni")
tablegen("Opts") {
@ -23,7 +24,7 @@ group("symlinks") {
}
}
executable("llvm-nm") {
driver_executable("llvm-nm") {
deps = [
":Opts",
"//llvm/lib/Bitcode/Reader",

View File

@ -1,4 +1,6 @@
executable("llvm-profdata") {
import("//llvm/utils/gn/build/driver_executable.gni")
driver_executable("llvm-profdata") {
deps = [
"//llvm/lib/IR",
"//llvm/lib/ProfileData",

View File

@ -1,5 +1,6 @@
import("//llvm/tools/binutils_symlinks.gni")
import("//llvm/utils/TableGen/tablegen.gni")
import("//llvm/utils/gn/build/driver_executable.gni")
import("//llvm/utils/gn/build/symlink_or_copy.gni")
tablegen("Opts") {
@ -33,7 +34,7 @@ group("symlinks") {
}
}
executable("llvm-rc") {
driver_executable("llvm-rc") {
deps = [
":Opts",
":WindresOpts",

View File

@ -1,5 +1,6 @@
import("//llvm/tools/binutils_symlinks.gni")
import("//llvm/utils/TableGen/tablegen.gni")
import("//llvm/utils/gn/build/driver_executable.gni")
import("//llvm/utils/gn/build/symlink_or_copy.gni")
tablegen("Opts") {
@ -27,7 +28,7 @@ group("symlinks") {
}
}
executable("llvm-readobj") {
driver_executable("llvm-readobj") {
deps = [
":Opts",
"//llvm/lib/BinaryFormat",

View File

@ -1,5 +1,6 @@
import("//llvm/tools/binutils_symlinks.gni")
import("//llvm/utils/TableGen/tablegen.gni")
import("//llvm/utils/gn/build/driver_executable.gni")
import("//llvm/utils/gn/build/symlink_or_copy.gni")
tablegen("Opts") {
@ -23,7 +24,7 @@ group("symlinks") {
}
}
executable("llvm-size") {
driver_executable("llvm-size") {
deps = [
":Opts",
"//llvm/lib/Object",

View File

@ -3124,12 +3124,21 @@ gentbl(
td_srcs = ["include/llvm/Option/OptParser.td"],
)
expand_template(
name = "ifs_main",
out = "llvm-ifs-driver.cpp",
substitutions = {
"@TOOL_NAME@": "llvm_ifs",
},
template = "cmake/modules/llvm-driver-template.cpp.in",
)
cc_binary(
name = "llvm-ifs",
srcs = glob([
"tools/llvm-ifs/*.cpp",
"tools/llvm-ifs/*.h",
]),
]) + ["llvm-ifs-driver.cpp"],
copts = llvm_copts,
stamp = 0,
deps = [
@ -3232,11 +3241,20 @@ gentbl(
td_srcs = ["include/llvm/Option/OptParser.td"],
)
expand_template(
name = "lipo_main",
out = "llvm-lipo-driver.cpp",
substitutions = {
"@TOOL_NAME@": "llvm_lipo",
},
template = "cmake/modules/llvm-driver-template.cpp.in",
)
cc_binary(
name = "llvm-lipo",
srcs = [
"tools/llvm-lipo/llvm-lipo.cpp",
],
] + ["llvm-lipo-driver.cpp"],
copts = llvm_copts,
stamp = 0,
deps = [
@ -3391,12 +3409,21 @@ gentbl(
td_srcs = ["include/llvm/Option/OptParser.td"],
)
expand_template(
name = "mt_main",
out = "llvm-mt-driver.cpp",
substitutions = {
"@TOOL_NAME@": "llvm_mt",
},
template = "cmake/modules/llvm-driver-template.cpp.in",
)
cc_binary(
name = "llvm-mt",
srcs = glob([
"tools/llvm-mt/*.cpp",
"tools/llvm-mt/*.h",
]),
]) + ["llvm-mt-driver.cpp"],
copts = llvm_copts,
stamp = 0,
deps = [
@ -3419,12 +3446,21 @@ gentbl(
td_srcs = ["include/llvm/Option/OptParser.td"],
)
expand_template(
name = "nm_main",
out = "llvm-nm-driver.cpp",
substitutions = {
"@TOOL_NAME@": "llvm_nm",
},
template = "cmake/modules/llvm-driver-template.cpp.in",
)
cc_binary(
name = "llvm-nm",
srcs = glob([
"tools/llvm-nm/*.cpp",
"tools/llvm-nm/*.h",
]),
]) + ["llvm-nm-driver.cpp"],
copts = llvm_copts,
stamp = 0,
deps = [
@ -3657,12 +3693,21 @@ cc_binary(
],
)
expand_template(
name = "profdata_main",
out = "llvm-profdata-driver.cpp",
substitutions = {
"@TOOL_NAME@": "llvm_profdata",
},
template = "cmake/modules/llvm-driver-template.cpp.in",
)
cc_binary(
name = "llvm-profdata",
srcs = glob([
"tools/llvm-profdata/*.cpp",
"tools/llvm-profdata/*.h",
]),
]) + ["llvm-profdata-driver.cpp"],
copts = llvm_copts,
stamp = 0,
deps = [
@ -3717,12 +3762,21 @@ cc_library(
textual_hdrs = glob(["tools/llvm-rc/*.def"]),
)
expand_template(
name = "rc_main",
out = "llvm-rc-driver.cpp",
substitutions = {
"@TOOL_NAME@": "llvm_rc",
},
template = "cmake/modules/llvm-driver-template.cpp.in",
)
cc_binary(
name = "llvm-rc",
srcs = glob([
"tools/llvm-rc/*.cpp",
"tools/llvm-rc/*.h",
]),
]) + ["llvm-rc-driver.cpp"],
copts = llvm_copts,
stamp = 0,
deps = [
@ -3752,12 +3806,21 @@ gentbl(
td_srcs = ["include/llvm/Option/OptParser.td"],
)
expand_template(
name = "readobj_main",
out = "llvm-readobj-driver.cpp",
substitutions = {
"@TOOL_NAME@": "llvm_readobj",
},
template = "cmake/modules/llvm-driver-template.cpp.in",
)
cc_binary(
name = "llvm-readobj",
srcs = glob([
"tools/llvm-readobj/*.cpp",
"tools/llvm-readobj/*.h",
]),
]) + ["llvm-readobj-driver.cpp"],
copts = llvm_copts,
stamp = 0,
deps = [
@ -3848,12 +3911,21 @@ gentbl(
td_srcs = ["include/llvm/Option/OptParser.td"],
)
expand_template(
name = "size_main",
out = "llvm-size-driver.cpp",
substitutions = {
"@TOOL_NAME@": "llvm_size",
},
template = "cmake/modules/llvm-driver-template.cpp.in",
)
cc_binary(
name = "llvm-size",
srcs = glob([
"tools/llvm-size/*.cpp",
"tools/llvm-size/*.h",
]),
]) + ["llvm-size-driver.cpp"],
copts = llvm_copts,
stamp = 0,
deps = [