Add frontend options to write SIL and LLVM IR as additional compilation output.

This commit adds -sil-output-path and -ir-output-path frontend options that
allow generating SIL and LLVM IR files as supplementary outputs during normal
compilation.

These options can be useful for debugging and analysis tools
workflows that need access to intermediate compilation artifacts
without requiring separate compiler invocations.

Expected behaviour:

Primary File mode:
 - SIL: Generates one .sil file per source file
 - IR: Generates one .ll file per source file

Single-threaded WMO mode:
 - SIL: Generates one .sil file for the entire module
 - IR: Generates one .ll file for the entire module

Multi-threaded WMO mode:
 - SIL: Generates one .sil file for the entire module
 - IR: Generates separate .ll files per source file

File Maps with WMO:
 - Both SIL and IR outputs using first entry's naming, which is
   consistent with the behaviour of other supplementary outputs.

rdar://160297898
This commit is contained in:
Ryan Mansfield
2025-09-18 15:53:31 -04:00
parent 5b4c5ebed4
commit ba0ce8aea6
15 changed files with 372 additions and 83 deletions

View File

@@ -0,0 +1,14 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-object -ir-output-path %t/test.ll %s -o %t/test.o
// RUN: %FileCheck -input-file %t/test.ll %s --check-prefix=IR-CHECK
// RUN: test -f %t/test.o
// Test that -ir-output-path produces LLVM IR output alongside normal compilation
func testFunction() -> Int {
return 42
}
let _ = testFunction()
// IR-CHECK: @"$s4test0A8FunctionSiyF"