Files
swift-mirror/test/Frontend/wmo-supplementary-outputs.swift
Ryan Mansfield ba0ce8aea6 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
2025-10-06 15:45:49 -04:00

37 lines
2.2 KiB
Swift

// RUN: %empty-directory(%t)
// Test WMO supplementary output functionality
// Test SIL consolidates, IR separates in multi-threaded WMO
// RUN: %target-swift-frontend -wmo -num-threads 4 %S/../Driver/Inputs/main.swift %s -module-name=ThisModule -c -o %t/main.o -o %t/multi-threaded.o -sil-output-path %t/mt-wmo.sil -ir-output-path %t/main.ll -ir-output-path %t/multi-threaded.ll
// RUN: test -f %t/mt-wmo.sil && test -f %t/main.ll && test -f %t/multi-threaded.ll && test -f %t/main.o && test -f %t/multi-threaded.o
// RUN: %FileCheck -input-file %t/mt-wmo.sil %s --check-prefix=SIL-CHECK
// RUN: %FileCheck -input-file %t/main.ll %s --check-prefix=IR-CHECK-MAIN
// RUN: %FileCheck -input-file %t/multi-threaded.ll %s --check-prefix=IR-CHECK
// MARK: Single-threaded WMO tests - Both SIL and IR consolidate
// Test single-threaded WMO: both SIL and IR produce consolidated output
// RUN: %target-swift-frontend -wmo %S/../Driver/Inputs/main.swift %s -module-name=ThisModule -c -o %t/st-main.o -sil-output-path %t/st-wmo.sil -ir-output-path %t/st-wmo.ll
// RUN: test -f %t/st-wmo.sil && test -f %t/st-wmo.ll && test -f %t/st-main.o
// RUN: %FileCheck -input-file %t/st-wmo.sil %s --check-prefix=SIL-CHECK
// RUN: %FileCheck -input-file %t/st-wmo.ll %s --check-prefix=IR-CHECK
// MARK: WMO with supplementary output file maps - First entry consolidation
// Test file map consolidation: both SIL and IR use first entry naming with consolidated content
// RUN: echo '{"%/S/../Driver/Inputs/main.swift": {"sil": "%/t/map.sil", "llvm-ir": "%/t/map.ll"}, "%/s": {"sil": "%/t/unused.sil", "llvm-ir": "%/t/unused.ll"}}' > %t/map.json
// RUN: %target-swift-frontend -wmo %/S/../Driver/Inputs/main.swift %/s -module-name=ThisModule -c -o %t/map.o -supplementary-output-file-map %t/map.json
// RUN: test -f %t/map.sil && test -f %t/map.ll && test -f %t/map.o
// RUN: test ! -f %t/unused.sil && test ! -f %t/unused.ll
// RUN: %FileCheck -input-file %t/map.sil %s --check-prefix=SIL-CHECK
// RUN: %FileCheck -input-file %t/map.ll %s --check-prefix=IR-CHECK
// SIL-CHECK: sil {{.*}} @$s10ThisModule15libraryFunctionyyF
// IR-CHECK: @"$s10ThisModule15libraryFunctionyyF"
// IR-CHECK-MAIN: define{{.*}} i32 @main(
func libraryFunction() {}