Skip to content

Commit 9718aa5

Browse files
committed
[Driver] Pass -emit-irgen thru to frontend.
Add a new filetype for this mode option: "Raw LLVM IR". When the mode option is emit-irgen, the new filetype will be the output kind; conversely when determining the mode option to use, if the output kind is the new filetype, the mode option will be emit-irgen.
1 parent 0fa07ba commit 9718aa5

File tree

7 files changed

+22
-2
lines changed

7 files changed

+22
-2
lines changed

include/swift/Basic/FileTypes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ TYPE("assembly", Assembly, "s", "")
5858
TYPE("raw-sil", RawSIL, "sil", "")
5959
TYPE("raw-sib", RawSIB, "sib", "")
6060
TYPE("llvm-ir", LLVM_IR, "ll", "")
61+
TYPE("raw-llvm-ir", RawLLVM_IR, "ll", "")
6162
TYPE("llvm-bc", LLVM_BC, "bc", "")
6263
TYPE("diagnostics", SerializedDiagnostics, "dia", "")
6364
TYPE("clang-header", ClangHeader, "h", "")

lib/Basic/FileTypes.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ bool file_types::isTextual(ID Id) {
9797
case file_types::TY_Assembly:
9898
case file_types::TY_ASTDump:
9999
case file_types::TY_RawSIL:
100+
case file_types::TY_RawLLVM_IR:
100101
case file_types::TY_LLVM_IR:
101102
case file_types::TY_ClangHeader:
102103
case file_types::TY_AutolinkFile:
@@ -165,6 +166,7 @@ bool file_types::isAfterLLVM(ID Id) {
165166
case file_types::TY_ClangHeader:
166167
case file_types::TY_AutolinkFile:
167168
case file_types::TY_Image:
169+
case file_types::TY_RawLLVM_IR:
168170
case file_types::TY_dSYM:
169171
case file_types::TY_SIB:
170172
case file_types::TY_RawSIB:
@@ -214,6 +216,7 @@ bool file_types::isPartOfSwiftCompilation(ID Id) {
214216
case file_types::TY_RawSIB:
215217
return true;
216218
case file_types::TY_Assembly:
219+
case file_types::TY_RawLLVM_IR:
217220
case file_types::TY_LLVM_IR:
218221
case file_types::TY_LLVM_BC:
219222
case file_types::TY_Object:
@@ -275,6 +278,7 @@ bool file_types::isProducedFromDiagnostics(ID Id) {
275278
case file_types::TY_SIB:
276279
case file_types::TY_RawSIB:
277280
case file_types::TY_Assembly:
281+
case file_types::TY_RawLLVM_IR:
278282
case file_types::TY_LLVM_IR:
279283
case file_types::TY_LLVM_BC:
280284
case file_types::TY_Object:

lib/Driver/Driver.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,9 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
11671167
break;
11681168

11691169
case options::OPT_emit_irgen:
1170+
OI.CompilerOutputType = file_types::TY_RawLLVM_IR;
1171+
break;
1172+
11701173
case options::OPT_emit_ir:
11711174
OI.CompilerOutputType = file_types::TY_LLVM_IR;
11721175
break;
@@ -1668,6 +1671,7 @@ void Driver::buildActions(SmallVectorImpl<const Action *> &TopLevelActions,
16681671
case file_types::TY_dSYM:
16691672
case file_types::TY_Dependencies:
16701673
case file_types::TY_Assembly:
1674+
case file_types::TY_RawLLVM_IR:
16711675
case file_types::TY_LLVM_IR:
16721676
case file_types::TY_LLVM_BC:
16731677
case file_types::TY_SerializedDiagnostics:

lib/Driver/ToolChains.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,8 @@ const char *ToolChain::JobContext::computeFrontendModeForCompile() const {
712712
return "-emit-sibgen";
713713
case file_types::TY_SIB:
714714
return "-emit-sib";
715+
case file_types::TY_RawLLVM_IR:
716+
return "-emit-irgen";
715717
case file_types::TY_LLVM_IR:
716718
return "-emit-ir";
717719
case file_types::TY_LLVM_BC:
@@ -977,6 +979,9 @@ ToolChain::constructInvocation(const BackendJobAction &job,
977979
case file_types::TY_Object:
978980
FrontendModeOption = "-c";
979981
break;
982+
case file_types::TY_RawLLVM_IR:
983+
FrontendModeOption = "-emit-irgen";
984+
break;
980985
case file_types::TY_LLVM_IR:
981986
FrontendModeOption = "-emit-ir";
982987
break;

lib/Frontend/FrontendOptions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ FrontendOptions::formatForPrincipalOutputFileForAction(ActionType action) {
335335
return TY_Assembly;
336336

337337
case ActionType::EmitIRGen:
338+
return TY_RawLLVM_IR;
339+
338340
case ActionType::EmitIR:
339341
return TY_LLVM_IR;
340342

test/Driver/emit-irgen.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: %swiftc_driver -### -emit-irgen %s -o - | %FileCheck %s
2+
3+
// CHECK: -emit-irgen

unittests/Basic/FileTypes.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ TEST(FileSystem, lookupTypeFromFilename) {
2727
// no extension, skip.
2828
if (Entry.first.empty())
2929
continue;
30-
// raw-sil and raw-sib do not have unique extension.
31-
if (Entry.second == TY_RawSIL || Entry.second == TY_RawSIB)
30+
// raw-sil, raw-sib, and raw-llvm-ir do not have unique extensions.
31+
if (Entry.second == TY_RawSIL || Entry.second == TY_RawSIB ||
32+
Entry.second == TY_RawLLVM_IR)
3233
continue;
3334

3435
std::string Filename = "Myfile." + Entry.first;

0 commit comments

Comments
 (0)