Skip to content

Commit e3a174b

Browse files
committed
Replace the sil-llvm-gen binary with a symlink to swift-frontend
rdar://76551283
1 parent bc7b632 commit e3a174b

File tree

9 files changed

+107
-108
lines changed

9 files changed

+107
-108
lines changed

Diff for: include/swift/Driver/Driver.h

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class Driver {
169169
SILOpt, // sil-opt
170170
SILFuncExtractor,// sil-func-extractor
171171
SILNM, // sil-nm
172+
SILLLVMGen, // sil-llvm-gen
172173
AutolinkExtract, // swift-autolink-extract
173174
SwiftIndent, // swift-indent
174175
SymbolGraph, // swift-symbolgraph

Diff for: lib/Driver/Driver.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ void Driver::parseDriverKind(ArrayRef<const char *> Args) {
102102
.Case("sil-opt", DriverKind::SILOpt)
103103
.Case("sil-func-extractor", DriverKind::SILFuncExtractor)
104104
.Case("sil-nm", DriverKind::SILNM)
105+
.Case("sil-llvm-gen", DriverKind::SILLLVMGen)
105106
.Case("swift-autolink-extract", DriverKind::AutolinkExtract)
106107
.Case("swift-indent", DriverKind::SwiftIndent)
107108
.Case("swift-symbolgraph-extract", DriverKind::SymbolGraph)
@@ -3561,6 +3562,7 @@ void Driver::printHelp(bool ShowHidden) const {
35613562
case DriverKind::SILOpt:
35623563
case DriverKind::SILFuncExtractor:
35633564
case DriverKind::SILNM:
3565+
case DriverKind::SILLLVMGen:
35643566
case DriverKind::AutolinkExtract:
35653567
case DriverKind::SwiftIndent:
35663568
case DriverKind::SymbolGraph:

Diff for: lib/DriverTool/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set(driver_sources_and_options
33
sil_opt_main.cpp
44
sil_func_extractor_main.cpp
55
sil_nm_main.cpp
6+
sil_llvm_gen_main.cpp
67
autolink_extract_main.cpp
78
modulewrap_main.cpp
89
swift_api_digester_main.cpp

Diff for: lib/DriverTool/driver.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ extern int sil_func_extractor_main(ArrayRef<const char *> argv, void *MainAddr);
7272
/// Run 'sil-nm'
7373
extern int sil_nm_main(ArrayRef<const char *> argv, void *MainAddr);
7474

75+
/// Run 'sil-llvm-gen'
76+
extern int sil_llvm_gen_main(ArrayRef<const char *> argv, void *MainAddr);
77+
7578
/// Run 'swift-autolink-extract'.
7679
extern int autolink_extract_main(ArrayRef<const char *> Args, const char *Argv0,
7780
void *MainAddr);
@@ -296,6 +299,8 @@ static int run_driver(StringRef ExecName,
296299
return sil_func_extractor_main(argv, (void *)(intptr_t)getExecutablePath);
297300
case Driver::DriverKind::SILNM:
298301
return sil_nm_main(argv, (void *)(intptr_t)getExecutablePath);
302+
case Driver::DriverKind::SILLLVMGen:
303+
return sil_llvm_gen_main(argv, (void *)(intptr_t)getExecutablePath);
299304
case Driver::DriverKind::AutolinkExtract:
300305
return autolink_extract_main(
301306
TheDriver.getArgsWithoutProgramNameAndDriverMode(argv),

Diff for: tools/sil-llvm-gen/SILLLVMGen.cpp renamed to lib/DriverTool/sil_llvm_gen_main.cpp

+93-93
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- SILLLVMGen.cpp ---------------------------------------------------===//
1+
//===--- sil_llvm_gen_main.cpp --------------------------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -48,107 +48,107 @@
4848
#include <cstdio>
4949
using namespace swift;
5050

51-
static llvm::cl::opt<std::string> InputFilename(llvm::cl::desc("input file"),
52-
llvm::cl::init("-"),
53-
llvm::cl::Positional);
54-
55-
static llvm::cl::opt<std::string>
56-
OutputFilename("o", llvm::cl::init("-"), llvm::cl::desc("output filename"));
57-
58-
static llvm::cl::list<std::string>
59-
ImportPaths("I",
60-
llvm::cl::desc("add a directory to the import search path"));
61-
62-
static llvm::cl::list<std::string> FrameworkPaths(
63-
"F", llvm::cl::desc("add a directory to the framework search path"));
64-
65-
static llvm::cl::opt<std::string>
66-
ModuleName("module-name",
67-
llvm::cl::desc("The name of the module if processing"
68-
" a module. Necessary for processing "
69-
"stdin."));
70-
71-
static llvm::cl::opt<std::string> ResourceDir(
72-
"resource-dir",
73-
llvm::cl::desc("The directory that holds the compiler resource files"));
74-
75-
static llvm::cl::opt<std::string>
76-
SDKPath("sdk", llvm::cl::desc("The path to the SDK for use with the clang "
77-
"importer."),
78-
llvm::cl::init(""));
79-
80-
static llvm::cl::opt<std::string> Target("target",
81-
llvm::cl::desc("target triple"));
82-
83-
static llvm::cl::opt<bool>
84-
PrintStats("print-stats", llvm::cl::desc("Print various statistics"));
85-
86-
static llvm::cl::opt<std::string>
87-
ModuleCachePath("module-cache-path",
88-
llvm::cl::desc("Clang module cache path"));
89-
90-
static llvm::cl::opt<bool>
91-
PerformWMO("wmo", llvm::cl::desc("Enable whole-module optimizations"));
92-
93-
static llvm::cl::opt<IRGenOutputKind> OutputKind(
94-
"output-kind", llvm::cl::desc("Type of output to produce"),
95-
llvm::cl::values(clEnumValN(IRGenOutputKind::LLVMAssemblyAfterOptimization,
96-
"llvm-as", "Emit llvm assembly"),
97-
clEnumValN(IRGenOutputKind::LLVMBitcode, "llvm-bc",
98-
"Emit llvm bitcode"),
99-
clEnumValN(IRGenOutputKind::NativeAssembly, "as",
100-
"Emit native assembly"),
101-
clEnumValN(IRGenOutputKind::ObjectFile, "object",
102-
"Emit an object file")),
103-
llvm::cl::init(IRGenOutputKind::ObjectFile));
104-
105-
static llvm::cl::opt<bool>
106-
DisableLegacyTypeInfo("disable-legacy-type-info",
107-
llvm::cl::desc("Don't try to load backward deployment layouts"));
108-
109-
// This function isn't referenced outside its translation unit, but it
110-
// can't use the "static" keyword because its address is used for
111-
// getMainExecutable (since some platforms don't support taking the
112-
// address of main, and some platforms can't implement getMainExecutable
113-
// without being given the address of a function in the main executable).
114-
void anchorForGetMainExecutable() {}
115-
116-
int main(int argc, char **argv) {
117-
PROGRAM_START(argc, argv);
51+
struct SILLLVMGenOptions {
52+
llvm::cl::opt<std::string>
53+
InputFilename = llvm::cl::opt<std::string>(llvm::cl::desc("input file"),
54+
llvm::cl::init("-"),
55+
llvm::cl::Positional);
56+
57+
llvm::cl::opt<std::string>
58+
OutputFilename = llvm::cl::opt<std::string>("o", llvm::cl::init("-"), llvm::cl::desc("output filename"));
59+
60+
llvm::cl::list<std::string>
61+
ImportPaths = llvm::cl::list<std::string>("I",
62+
llvm::cl::desc("add a directory to the import search path"));
63+
64+
llvm::cl::list<std::string>
65+
FrameworkPaths = llvm::cl::list<std::string>(
66+
"F", llvm::cl::desc("add a directory to the framework search path"));
67+
68+
llvm::cl::opt<std::string>
69+
ModuleName = llvm::cl::opt<std::string>("module-name",
70+
llvm::cl::desc("The name of the module if processing"
71+
" a module. Necessary for processing "
72+
"stdin."));
73+
74+
llvm::cl::opt<std::string>
75+
ResourceDir = llvm::cl::opt<std::string>(
76+
"resource-dir",
77+
llvm::cl::desc("The directory that holds the compiler resource files"));
78+
79+
llvm::cl::opt<std::string>
80+
SDKPath = llvm::cl::opt<std::string>("sdk", llvm::cl::desc("The path to the SDK for use with the clang "
81+
"importer."),
82+
llvm::cl::init(""));
83+
84+
llvm::cl::opt<std::string>
85+
Target = llvm::cl::opt<std::string>("target",
86+
llvm::cl::desc("target triple"));
87+
88+
llvm::cl::opt<bool>
89+
PrintStats = llvm::cl::opt<bool>("print-stats", llvm::cl::desc("Print various statistics"));
90+
91+
llvm::cl::opt<std::string>
92+
ModuleCachePath = llvm::cl::opt<std::string>("module-cache-path",
93+
llvm::cl::desc("Clang module cache path"));
94+
95+
llvm::cl::opt<bool>
96+
PerformWMO = llvm::cl::opt<bool>("wmo", llvm::cl::desc("Enable whole-module optimizations"));
97+
98+
llvm::cl::opt<IRGenOutputKind>
99+
OutputKind = llvm::cl::opt<IRGenOutputKind>(
100+
"output-kind", llvm::cl::desc("Type of output to produce"),
101+
llvm::cl::values(clEnumValN(IRGenOutputKind::LLVMAssemblyAfterOptimization,
102+
"llvm-as", "Emit llvm assembly"),
103+
clEnumValN(IRGenOutputKind::LLVMBitcode, "llvm-bc",
104+
"Emit llvm bitcode"),
105+
clEnumValN(IRGenOutputKind::NativeAssembly, "as",
106+
"Emit native assembly"),
107+
clEnumValN(IRGenOutputKind::ObjectFile, "object",
108+
"Emit an object file")),
109+
llvm::cl::init(IRGenOutputKind::ObjectFile));
110+
111+
llvm::cl::opt<bool>
112+
DisableLegacyTypeInfo = llvm::cl::opt<bool>("disable-legacy-type-info",
113+
llvm::cl::desc("Don't try to load backward deployment layouts"));
114+
};
115+
116+
int sil_llvm_gen_main(ArrayRef<const char *> argv, void *MainAddr) {
118117
INITIALIZE_LLVM();
119118

120-
llvm::cl::ParseCommandLineOptions(argc, argv, "Swift LLVM IR Generator\n");
119+
SILLLVMGenOptions options;
121120

122-
if (PrintStats)
121+
llvm::cl::ParseCommandLineOptions(argv.size(), argv.data(), "Swift LLVM IR Generator\n");
122+
123+
if (options.PrintStats)
123124
llvm::EnableStatistics();
124125

125126
CompilerInvocation Invocation;
126127

127-
Invocation.setMainExecutablePath(llvm::sys::fs::getMainExecutable(
128-
argv[0], reinterpret_cast<void *>(&anchorForGetMainExecutable)));
128+
Invocation.setMainExecutablePath(llvm::sys::fs::getMainExecutable(argv[0], MainAddr));
129129

130130
// Give the context the list of search paths to use for modules.
131-
Invocation.setImportSearchPaths(ImportPaths);
131+
Invocation.setImportSearchPaths(options.ImportPaths);
132132
std::vector<SearchPathOptions::FrameworkSearchPath> FramePaths;
133-
for (const auto &path : FrameworkPaths) {
133+
for (const auto &path : options.FrameworkPaths) {
134134
FramePaths.push_back({path, /*isSystem=*/false});
135135
}
136136
Invocation.setFrameworkSearchPaths(FramePaths);
137137
// Set the SDK path and target if given.
138-
if (SDKPath.getNumOccurrences() == 0) {
138+
if (options.SDKPath.getNumOccurrences() == 0) {
139139
const char *SDKROOT = getenv("SDKROOT");
140140
if (SDKROOT)
141-
SDKPath = SDKROOT;
141+
options.SDKPath = SDKROOT;
142142
}
143-
if (!SDKPath.empty())
144-
Invocation.setSDKPath(SDKPath);
145-
if (!Target.empty())
146-
Invocation.setTargetTriple(Target);
147-
if (!ResourceDir.empty())
148-
Invocation.setRuntimeResourcePath(ResourceDir);
143+
if (!options.SDKPath.empty())
144+
Invocation.setSDKPath(options.SDKPath);
145+
if (!options.Target.empty())
146+
Invocation.setTargetTriple(options.Target);
147+
if (!options.ResourceDir.empty())
148+
Invocation.setRuntimeResourcePath(options.ResourceDir);
149149
// Set the module cache path. If not passed in we use the default swift module
150150
// cache.
151-
Invocation.getClangImporterOptions().ModuleCachePath = ModuleCachePath;
151+
Invocation.getClangImporterOptions().ModuleCachePath = options.ModuleCachePath;
152152
Invocation.setParseStdlib();
153153

154154
// Setup the language options
@@ -160,16 +160,16 @@ int main(int argc, char **argv) {
160160

161161
// Setup the IRGen Options.
162162
IRGenOptions &Opts = Invocation.getIRGenOptions();
163-
Opts.OutputKind = OutputKind;
164-
Opts.DisableLegacyTypeInfo = DisableLegacyTypeInfo;
163+
Opts.OutputKind = options.OutputKind;
164+
Opts.DisableLegacyTypeInfo = options.DisableLegacyTypeInfo;
165165

166166
serialization::ExtendedValidationInfo extendedInfo;
167167
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
168-
Invocation.setUpInputForSILTool(InputFilename, ModuleName,
168+
Invocation.setUpInputForSILTool(options.InputFilename, options.ModuleName,
169169
/*alwaysSetModuleToMain*/ false,
170-
/*bePrimary*/ !PerformWMO, extendedInfo);
170+
/*bePrimary*/ !options.PerformWMO, extendedInfo);
171171
if (!FileBufOrErr) {
172-
fprintf(stderr, "Error! Failed to open file: %s\n", InputFilename.c_str());
172+
fprintf(stderr, "Error! Failed to open file: %s\n", options.InputFilename.c_str());
173173
exit(-1);
174174
}
175175

@@ -184,16 +184,16 @@ int main(int argc, char **argv) {
184184
}
185185

186186
llvm::vfs::OnDiskOutputBackend Backend;
187-
auto outFile = Backend.createFile(OutputFilename);
187+
auto outFile = Backend.createFile(options.OutputFilename);
188188
if (!outFile) {
189189
CI.getDiags().diagnose(SourceLoc(), diag::error_opening_output,
190-
OutputFilename, toString(outFile.takeError()));
190+
options.OutputFilename, toString(outFile.takeError()));
191191
return 1;
192192
}
193193
auto closeFile = llvm::make_scope_exit([&]() {
194194
if (auto E = outFile->keep()) {
195195
CI.getDiags().diagnose(SourceLoc(), diag::error_closing_output,
196-
OutputFilename, toString(std::move(E)));
196+
options.OutputFilename, toString(std::move(E)));
197197
}
198198
});
199199

@@ -204,10 +204,10 @@ int main(int argc, char **argv) {
204204
const auto &SILOpts = Invocation.getSILOptions();
205205
auto &SILTypes = CI.getSILTypes();
206206
auto moduleName = CI.getMainModule()->getName().str();
207-
const PrimarySpecificPaths PSPs(OutputFilename, InputFilename);
207+
const PrimarySpecificPaths PSPs(options.OutputFilename, options.InputFilename);
208208

209209
auto getDescriptor = [&]() -> IRGenDescriptor {
210-
if (PerformWMO) {
210+
if (options.PerformWMO) {
211211
return IRGenDescriptor::forWholeModule(
212212
mod, Opts, TBDOpts, SILOpts, SILTypes,
213213
/*SILMod*/ nullptr, moduleName, PSPs);

Diff for: test/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ function(get_test_dependencies SDK result_var_name)
5252
if (SWIFT_INCLUDE_TOOLS)
5353
list(APPEND deps_binaries
5454
lldb-moduleimport-test
55-
sil-llvm-gen
5655
sil-passpipeline-dumper
5756
swift-frontend
5857
swift-demangle

Diff for: tools/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ add_swift_tool_subdirectory(swift-demangle)
2323
add_swift_tool_subdirectory(swift-demangle-yamldump)
2424
add_swift_tool_subdirectory(swift-def-to-strings-converter)
2525
add_swift_tool_subdirectory(swift-serialize-diagnostics)
26-
add_swift_tool_subdirectory(sil-llvm-gen)
2726
add_swift_tool_subdirectory(sil-passpipeline-dumper)
2827
add_swift_tool_subdirectory(swift-llvm-opt)
2928
add_swift_tool_subdirectory(swift-ast-script)

Diff for: tools/driver/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ swift_create_post_build_symlink(swift-frontend
104104
DESTINATION "sil-nm${CMAKE_EXECUTABLE_SUFFIX}"
105105
WORKING_DIRECTORY "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
106106

107+
swift_create_post_build_symlink(swift-frontend
108+
SOURCE "swift-frontend${CMAKE_EXECUTABLE_SUFFIX}"
109+
DESTINATION "sil-llvm-gen${CMAKE_EXECUTABLE_SUFFIX}"
110+
WORKING_DIRECTORY "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
111+
107112
swift_create_post_build_symlink(swift-frontend
108113
SOURCE "swift-frontend${CMAKE_EXECUTABLE_SUFFIX}"
109114
DESTINATION "swift-indent${CMAKE_EXECUTABLE_SUFFIX}"

Diff for: tools/sil-llvm-gen/CMakeLists.txt

-13
This file was deleted.

0 commit comments

Comments
 (0)