From dc145e2f34b8c449bb4d63b14d92d3e7a9cdecda Mon Sep 17 00:00:00 2001 From: "Sabianin, Maksim" Date: Wed, 1 Apr 2026 10:29:14 -0700 Subject: [PATCH 1/4] [SYCL] Refactor sycl-post-link saveModule to improve code structure Extract prepareModuleBeforeSave() helper and change saveModule() to return Error for better error handling. Move output file index handling to call sites for more flexible function design. Output filenames changed from prefix_esimd_N.ext to prefix_N.esimd.ext as a consequence of the refactoring. Co-Authored-By: Claude Sonnet 4.5 --- llvm/test/tools/sycl-post-link/aot-esimd.ll | 4 +- .../multiple-filtered-outputs.ll | 70 +++++++++---------- .../spec-constants/default-value/esimd.ll | 6 +- .../tools/sycl-post-link/sycl-esimd/assert.ll | 2 +- .../sycl-esimd/basic-esimd-lower.ll | 8 +-- .../sycl-esimd/basic-sycl-esimd-split.ll | 6 +- .../sycl-esimd/nbarriers-metadata.ll | 2 +- .../no-sycl-esimd-split-shared-func.ll | 4 +- .../sycl-post-link/sycl-esimd/optnone.ll | 4 +- .../sycl-esimd/sycl-esimd-split-per-kernel.ll | 8 +-- .../sycl-esimd/sycl-esimd-split-per-source.ll | 8 +-- .../sycl-esimd/sycl-esimd-split-symbols.ll | 4 +- .../sycl-esimd/sycl-post-link-test.ll | 2 +- .../split-and-lower-esimd.ll | 2 +- .../tools/sycl-post-link/sycl-grf-size.ll | 14 ++-- llvm/tools/sycl-post-link/sycl-post-link.cpp | 67 +++++++++++------- 16 files changed, 112 insertions(+), 99 deletions(-) diff --git a/llvm/test/tools/sycl-post-link/aot-esimd.ll b/llvm/test/tools/sycl-post-link/aot-esimd.ll index b1235a929e9b2..c1426a0fa4d98 100644 --- a/llvm/test/tools/sycl-post-link/aot-esimd.ll +++ b/llvm/test/tools/sycl-post-link/aot-esimd.ll @@ -9,9 +9,9 @@ ; RUN: -o intel_gpu_dg1,%t-dg1.table ; RUN: FileCheck %s -input-file=%t-dg1.table -check-prefix=CHECK-TABLE -; RUN: FileCheck %s -input-file=%t-dg1_esimd_0.sym -check-prefix=CHECK-SYM -implicit-check-not=reqd_sub_group_size_kernel_1 +; RUN: FileCheck %s -input-file=%t-dg1_0.esimd.sym -check-prefix=CHECK-SYM -implicit-check-not=reqd_sub_group_size_kernel_1 -; CHECK-TABLE: _esimd_0.sym +; CHECK-TABLE: _0.esimd.sym ; CHECK-SYM: esimd_kernel target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64" diff --git a/llvm/test/tools/sycl-post-link/multiple-filtered-outputs.ll b/llvm/test/tools/sycl-post-link/multiple-filtered-outputs.ll index ef4227bd1305a..25fc51eab1d7c 100644 --- a/llvm/test/tools/sycl-post-link/multiple-filtered-outputs.ll +++ b/llvm/test/tools/sycl-post-link/multiple-filtered-outputs.ll @@ -44,59 +44,59 @@ ; CHECK-ALL-NEXT: _5.sym ; CHECK-ALL-EMPTY: -; PVC does not support sg8 (=1) or sg64 (=2) -; CHECK-PVC: _intel_gpu_pvc_0.prop|{{.*}}_0.sym -; CHECK-PVC-NEXT: _intel_gpu_pvc_3.prop|{{.*}}_3.sym -; CHECK-PVC-NEXT: _intel_gpu_pvc_4.prop|{{.*}}_4.sym -; CHECK-PVC-NEXT: _intel_gpu_pvc_5.prop|{{.*}}_5.sym +; PVC does not support sg8 (=1) or sg64 (=2) +; CHECK-PVC: _0.intel_gpu_pvc.prop|{{.*}}_0.sym +; CHECK-PVC-NEXT: _3.intel_gpu_pvc.prop|{{.*}}_3.sym +; CHECK-PVC-NEXT: _4.intel_gpu_pvc.prop|{{.*}}_4.sym +; CHECK-PVC-NEXT: _5.intel_gpu_pvc.prop|{{.*}}_5.sym ; CHECK-PVC-EMPTY: -; RUN: FileCheck %s -input-file=%t_intel_gpu_pvc_0.prop -check-prefix=CHECK-PVC-PROP -; RUN: FileCheck %s -input-file=%t_intel_gpu_pvc_3.prop -check-prefix=CHECK-PVC-PROP -; RUN: FileCheck %s -input-file=%t_intel_gpu_pvc_4.prop -check-prefix=CHECK-PVC-PROP -; RUN: FileCheck %s -input-file=%t_intel_gpu_pvc_5.prop -check-prefix=CHECK-PVC-PROP +; RUN: FileCheck %s -input-file=%t_0.intel_gpu_pvc.prop -check-prefix=CHECK-PVC-PROP +; RUN: FileCheck %s -input-file=%t_3.intel_gpu_pvc.prop -check-prefix=CHECK-PVC-PROP +; RUN: FileCheck %s -input-file=%t_4.intel_gpu_pvc.prop -check-prefix=CHECK-PVC-PROP +; RUN: FileCheck %s -input-file=%t_5.intel_gpu_pvc.prop -check-prefix=CHECK-PVC-PROP ; CHECK-PVC-PROP: compile_target=2|oBAAAAAAAAQauRXZs91ZwV3XwZ3Y ; TGLLP does not support fp64 (=0) or sg64 (=2) -; CHECK-TGLLP: _intel_gpu_tgllp_1.prop|{{.*}}_1.sym -; CHECK-TGLLP-NEXT: _intel_gpu_tgllp_3.prop|{{.*}}_3.sym -; CHECK-TGLLP-NEXT: _intel_gpu_tgllp_4.prop|{{.*}}_4.sym -; CHECK-TGLLP-NEXT: _intel_gpu_tgllp_5.prop|{{.*}}_5.sym +; CHECK-TGLLP: _1.intel_gpu_tgllp.prop|{{.*}}_1.sym +; CHECK-TGLLP-NEXT: _3.intel_gpu_tgllp.prop|{{.*}}_3.sym +; CHECK-TGLLP-NEXT: _4.intel_gpu_tgllp.prop|{{.*}}_4.sym +; CHECK-TGLLP-NEXT: _5.intel_gpu_tgllp.prop|{{.*}}_5.sym ; CHECK-TGLLP-EMPTY: -; RUN: FileCheck %s -input-file=%t_intel_gpu_tgllp_1.prop -check-prefix=CHECK-TGLLP-PROP -; RUN: FileCheck %s -input-file=%t_intel_gpu_tgllp_3.prop -check-prefix=CHECK-TGLLP-PROP -; RUN: FileCheck %s -input-file=%t_intel_gpu_tgllp_4.prop -check-prefix=CHECK-TGLLP-PROP -; RUN: FileCheck %s -input-file=%t_intel_gpu_tgllp_5.prop -check-prefix=CHECK-TGLLP-PROP +; RUN: FileCheck %s -input-file=%t_1.intel_gpu_tgllp.prop -check-prefix=CHECK-TGLLP-PROP +; RUN: FileCheck %s -input-file=%t_3.intel_gpu_tgllp.prop -check-prefix=CHECK-TGLLP-PROP +; RUN: FileCheck %s -input-file=%t_4.intel_gpu_tgllp.prop -check-prefix=CHECK-TGLLP-PROP +; RUN: FileCheck %s -input-file=%t_5.intel_gpu_tgllp.prop -check-prefix=CHECK-TGLLP-PROP ; CHECK-TGLLP-PROP: compile_target=2|4BAAAAAAAAQauRXZs91ZwV3X0dGbsBH ; CFL does not support sg64 (=2) -; CHECK-CFL: _intel_gpu_cfl_0.prop|{{.*}}_0.sym -; CHECK-CFL-NEXT: _intel_gpu_cfl_1.prop|{{.*}}_1.sym -; CHECK-CFL-NEXT: _intel_gpu_cfl_3.prop|{{.*}}_3.sym -; CHECK-CFL-NEXT: _intel_gpu_cfl_4.prop|{{.*}}_4.sym -; CHECK-CFL-NEXT: _intel_gpu_cfl_5.prop|{{.*}}_5.sym +; CHECK-CFL: _0.intel_gpu_cfl.prop|{{.*}}_0.sym +; CHECK-CFL-NEXT: _1.intel_gpu_cfl.prop|{{.*}}_1.sym +; CHECK-CFL-NEXT: _3.intel_gpu_cfl.prop|{{.*}}_3.sym +; CHECK-CFL-NEXT: _4.intel_gpu_cfl.prop|{{.*}}_4.sym +; CHECK-CFL-NEXT: _5.intel_gpu_cfl.prop|{{.*}}_5.sym ; CHECK-CFL-EMPTY: -; RUN: FileCheck %s -input-file=%t_intel_gpu_cfl_0.prop -check-prefix=CHECK-CFL-PROP -; RUN: FileCheck %s -input-file=%t_intel_gpu_cfl_1.prop -check-prefix=CHECK-CFL-PROP -; RUN: FileCheck %s -input-file=%t_intel_gpu_cfl_3.prop -check-prefix=CHECK-CFL-PROP -; RUN: FileCheck %s -input-file=%t_intel_gpu_cfl_4.prop -check-prefix=CHECK-CFL-PROP -; RUN: FileCheck %s -input-file=%t_intel_gpu_cfl_5.prop -check-prefix=CHECK-CFL-PROP +; RUN: FileCheck %s -input-file=%t_0.intel_gpu_cfl.prop -check-prefix=CHECK-CFL-PROP +; RUN: FileCheck %s -input-file=%t_1.intel_gpu_cfl.prop -check-prefix=CHECK-CFL-PROP +; RUN: FileCheck %s -input-file=%t_3.intel_gpu_cfl.prop -check-prefix=CHECK-CFL-PROP +; RUN: FileCheck %s -input-file=%t_4.intel_gpu_cfl.prop -check-prefix=CHECK-CFL-PROP +; RUN: FileCheck %s -input-file=%t_5.intel_gpu_cfl.prop -check-prefix=CHECK-CFL-PROP ; CHECK-CFL-PROP: compile_target=2|oBAAAAAAAAQauRXZs91ZwV3XjZGb ; LNL does not support sg8 (=1) or sg64 (=2) -; CHECK-LNL: _intel_gpu_lnl_m_0.prop|{{.*}}_0.sym -; CHECK-LNL-NEXT: _intel_gpu_lnl_m_3.prop|{{.*}}_3.sym -; CHECK-LNL-NEXT: _intel_gpu_lnl_m_4.prop|{{.*}}_4.sym -; CHECK-LNL-NEXT: _intel_gpu_lnl_m_5.prop|{{.*}}_5.sym +; CHECK-LNL: _0.intel_gpu_lnl_m.prop|{{.*}}_0.sym +; CHECK-LNL-NEXT: _3.intel_gpu_lnl_m.prop|{{.*}}_3.sym +; CHECK-LNL-NEXT: _4.intel_gpu_lnl_m.prop|{{.*}}_4.sym +; CHECK-LNL-NEXT: _5.intel_gpu_lnl_m.prop|{{.*}}_5.sym ; CHECK-LNL-EMPTY: ; BMG does not support sg8 (=1) or sg64 (=2) -; CHECK-BMG: _intel_gpu_bmg_g21_0.prop|{{.*}}_0.sym -; CHECK-BMG-NEXT: _intel_gpu_bmg_g21_3.prop|{{.*}}_3.sym -; CHECK-BMG-NEXT: _intel_gpu_bmg_g21_4.prop|{{.*}}_4.sym -; CHECK-BMG-NEXT: _intel_gpu_bmg_g21_5.prop|{{.*}}_5.sym +; CHECK-BMG: _0.intel_gpu_bmg_g21.prop|{{.*}}_0.sym +; CHECK-BMG-NEXT: _3.intel_gpu_bmg_g21.prop|{{.*}}_3.sym +; CHECK-BMG-NEXT: _4.intel_gpu_bmg_g21.prop|{{.*}}_4.sym +; CHECK-BMG-NEXT: _5.intel_gpu_bmg_g21.prop|{{.*}}_5.sym ; CHECK-BMG-EMPTY: target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64" diff --git a/llvm/test/tools/sycl-post-link/spec-constants/default-value/esimd.ll b/llvm/test/tools/sycl-post-link/spec-constants/default-value/esimd.ll index 5afb3b4aac1e4..75f0e33af3c3e 100644 --- a/llvm/test/tools/sycl-post-link/spec-constants/default-value/esimd.ll +++ b/llvm/test/tools/sycl-post-link/spec-constants/default-value/esimd.ll @@ -3,12 +3,12 @@ ; RUN: sycl-post-link -properties -split=auto -split-esimd -lower-esimd -O2 -spec-const=native -o %t.table %s -generate-device-image-default-spec-consts ; RUN: FileCheck %s -input-file=%t.table -check-prefix=CHECK-TABLE ; RUN: FileCheck %s -input-file=%t_1.prop -check-prefix=CHECK-PROP -; RUN: FileCheck %s -input-file=%t_esimd_1.prop -check-prefix=CHECK-ESIMD-PROP +; RUN: FileCheck %s -input-file=%t_1.esimd.prop -check-prefix=CHECK-ESIMD-PROP ; RUN: %if asserts %{ sycl-post-link -properties -debug-only=SpecConst -split=auto -split-esimd -lower-esimd -O2 -spec-const=native %s -generate-device-image-default-spec-consts 2>&1 | FileCheck %s --check-prefix=CHECK-LOG %} -; CHECK-TABLE: {{.*}}_esimd_0.bc|{{.*}}_esimd_0.prop +; CHECK-TABLE: {{.*}}_0.esimd.bc|{{.*}}_0.esimd.prop ; CHECK-TABLE: {{.*}}_0.bc|{{.*}}_0.prop -; CHECK-TABLE: {{.*}}_esimd_1.bc|{{.*}}_esimd_1.prop +; CHECK-TABLE: {{.*}}_1.esimd.bc|{{.*}}_1.esimd.prop ; CHECK-TABLE: {{.*}}_1.bc|{{.*}}_1.prop ; CHECK-PROP: specConstsReplacedWithDefault=1|1 diff --git a/llvm/test/tools/sycl-post-link/sycl-esimd/assert.ll b/llvm/test/tools/sycl-post-link/sycl-esimd/assert.ll index 59c159a544476..862765c436ce0 100644 --- a/llvm/test/tools/sycl-post-link/sycl-esimd/assert.ll +++ b/llvm/test/tools/sycl-post-link/sycl-esimd/assert.ll @@ -1,5 +1,5 @@ ; RUN: sycl-post-link -properties -split-esimd -S < %s -o %t.table -; RUN: FileCheck %s -input-file=%t_esimd_0.prop +; RUN: FileCheck %s -input-file=%t_0.esimd.prop ; Verify we mark a image with an ESIMD kernel with the isEsimdImage property diff --git a/llvm/test/tools/sycl-post-link/sycl-esimd/basic-esimd-lower.ll b/llvm/test/tools/sycl-post-link/sycl-esimd/basic-esimd-lower.ll index 84625d4eb3295..47540f9c0a0c6 100644 --- a/llvm/test/tools/sycl-post-link/sycl-esimd/basic-esimd-lower.ll +++ b/llvm/test/tools/sycl-post-link/sycl-esimd/basic-esimd-lower.ll @@ -4,19 +4,19 @@ ; No lowering ; RUN: sycl-post-link -properties -split-esimd -S < %s -o %t.table -; RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes CHECK-NO-LOWERING +; RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes CHECK-NO-LOWERING ; Default lowering ; RUN: sycl-post-link -properties -split-esimd -lower-esimd -S < %s -o %t.table -; RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes CHECK-O2 +; RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes CHECK-O2 ; -O2 lowering ; RUN: sycl-post-link -properties -split-esimd -lower-esimd -O2 -S < %s -o %t.table -; RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes CHECK-O2 +; RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes CHECK-O2 ; -O0 lowering, requires `-force-disable-esimd-opt` to disable all optimizations. ; RUN: sycl-post-link -properties -split-esimd -lower-esimd -O0 -force-disable-esimd-opt -S < %s -o %t.table -; RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes CHECK-O0 +; RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes CHECK-O0 target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" target triple = "spir64-unknown-linux" diff --git a/llvm/test/tools/sycl-post-link/sycl-esimd/basic-sycl-esimd-split.ll b/llvm/test/tools/sycl-post-link/sycl-esimd/basic-sycl-esimd-split.ll index 25258107ad0e0..97237ffd93fd4 100644 --- a/llvm/test/tools/sycl-post-link/sycl-esimd/basic-sycl-esimd-split.ll +++ b/llvm/test/tools/sycl-post-link/sycl-esimd/basic-sycl-esimd-split.ll @@ -1,9 +1,9 @@ ; RUN: sycl-post-link -properties -split-esimd -S < %s -o %t.table ; RUN: FileCheck %s -input-file=%t.table ; RUN: FileCheck %s -input-file=%t_0.ll --check-prefixes CHECK-SYCL-IR -; RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes CHECK-ESIMD-IR +; RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes CHECK-ESIMD-IR ; RUN: FileCheck %s -input-file=%t_0.prop --check-prefixes CHECK-SYCL-PROP -; RUN: FileCheck %s -input-file=%t_esimd_0.prop --check-prefixes CHECK-ESIMD-PROP +; RUN: FileCheck %s -input-file=%t_0.esimd.prop --check-prefixes CHECK-ESIMD-PROP ; This is basic test of splitting SYCL and ESIMD kernels into separate modules. ; ESIMD module should have isEsimdImage=1 property set after splitting. @@ -38,7 +38,7 @@ attributes #0 = { "sycl-module-id"="a.cpp" } ; CHECK: [Code|Properties] ; CHECK-DAG: {{.*}}tmp_0.ll|{{.*}}_0.prop -; CHECK-DAG: {{.*}}tmp_esimd_0.ll|{{.*}}_esimd_0.prop +; CHECK-DAG: {{.*}}tmp_0.esimd.ll|{{.*}}_0.esimd.prop ; CHECK-SYCL-IR-DAG: define dso_local spir_kernel void @SYCL_kernel() ; CHECK-SYCL-IR-DAG: declare dso_local spir_func i64 @_Z28__spirv_GlobalInvocationId_xv() diff --git a/llvm/test/tools/sycl-post-link/sycl-esimd/nbarriers-metadata.ll b/llvm/test/tools/sycl-post-link/sycl-esimd/nbarriers-metadata.ll index 20ae18777b559..e1b52ee975a82 100644 --- a/llvm/test/tools/sycl-post-link/sycl-esimd/nbarriers-metadata.ll +++ b/llvm/test/tools/sycl-post-link/sycl-esimd/nbarriers-metadata.ll @@ -1,5 +1,5 @@ ; RUN: sycl-post-link -properties -split-esimd -lower-esimd -S < %s -o %t.table -; RUN: FileCheck %s -input-file=%t_esimd_0.ll +; RUN: FileCheck %s -input-file=%t_0.esimd.ll target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64" target triple = "spir64-unknown-unknown" diff --git a/llvm/test/tools/sycl-post-link/sycl-esimd/no-sycl-esimd-split-shared-func.ll b/llvm/test/tools/sycl-post-link/sycl-esimd/no-sycl-esimd-split-shared-func.ll index f3d02960a5de9..64a2ff400cd7b 100644 --- a/llvm/test/tools/sycl-post-link/sycl-esimd/no-sycl-esimd-split-shared-func.ll +++ b/llvm/test/tools/sycl-post-link/sycl-esimd/no-sycl-esimd-split-shared-func.ll @@ -8,7 +8,7 @@ ; RUN: sycl-post-link -properties -lower-esimd -symbols -split=auto -S < %s -o %t.table ; RUN: FileCheck %s -input-file=%t.table --check-prefixes CHECK-TABLE ; RUN: FileCheck %s -input-file=%t_0.sym --check-prefixes CHECK-HELPERS-SYM-1 -; RUN: FileCheck %s -input-file=%t_esimd_1.sym --check-prefixes CHECK-HELPERS-SYM-2 +; RUN: FileCheck %s -input-file=%t_1.esimd.sym --check-prefixes CHECK-HELPERS-SYM-2 ; RUN: FileCheck %s -input-file=%t_2.sym --check-prefixes CHECK-ESIMD-SYM ; RUN: FileCheck %s -input-file=%t_2.ll @@ -20,7 +20,7 @@ ; SIMD_CALL_HELPER_* functions generated by the compiler, because we don't ; expect them to be referenced externally. ; CHECK-TABLE: {{.*}}_0.ll|{{.*}}_0.prop|{{.*}}_0.sym -; CHECK-TABLE: {{.*}}_esimd_1.ll|{{.*}}_esimd_1.prop|{{.*}}_esimd_1.sym +; CHECK-TABLE: {{.*}}_1.esimd.ll|{{.*}}_1.esimd.prop|{{.*}}_1.esimd.sym ; CHECK-TABLE: {{.*}}_2.ll|{{.*}}_2.prop|{{.*}}_2.sym ; CHECK-TABLE-EMPTY: diff --git a/llvm/test/tools/sycl-post-link/sycl-esimd/optnone.ll b/llvm/test/tools/sycl-post-link/sycl-esimd/optnone.ll index 80d691bc4a8cb..a2a106bb2cacc 100644 --- a/llvm/test/tools/sycl-post-link/sycl-esimd/optnone.ll +++ b/llvm/test/tools/sycl-post-link/sycl-esimd/optnone.ll @@ -1,9 +1,9 @@ ; This ensures we remove optnone from ESIMD functions unless they are SIMT or we didn't split ESIMD code out. ; RUN: sycl-post-link -properties -split-esimd -lower-esimd -S < %s -o %t.table -; RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes CHECK,CHECK-ESIMD-SPLIT +; RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes CHECK,CHECK-ESIMD-SPLIT ; RUN: sycl-post-link -properties -lower-esimd -S < %s -o %t1.table -; RUN: FileCheck %s -input-file=%t1_esimd_0.ll --check-prefixes CHECK,CHECK-NO-ESIMD-SPLIT +; RUN: FileCheck %s -input-file=%t1_0.esimd.ll --check-prefixes CHECK,CHECK-NO-ESIMD-SPLIT target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64" target triple = "spir64-unknown-unknown" diff --git a/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-esimd-split-per-kernel.ll b/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-esimd-split-per-kernel.ll index eabed45ec75f0..63cd103cfc00d 100644 --- a/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-esimd-split-per-kernel.ll +++ b/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-esimd-split-per-kernel.ll @@ -2,8 +2,8 @@ ; RUN: FileCheck %s -input-file=%t.table ; RUN: FileCheck %s -input-file=%t_0.ll --check-prefixes CHECK-SYCL-IR-0 ; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-SYCL-IR-1 -; RUN: FileCheck %s -input-file=%t_esimd_2.ll --check-prefixes CHECK-ESIMD-IR-2 -; RUN: FileCheck %s -input-file=%t_esimd_3.ll --check-prefixes CHECK-ESIMD-IR-3 +; RUN: FileCheck %s -input-file=%t_2.esimd.ll --check-prefixes CHECK-ESIMD-IR-2 +; RUN: FileCheck %s -input-file=%t_3.esimd.ll --check-prefixes CHECK-ESIMD-IR-3 ; This test checks that after we split SYCL and ESIMD kernels into ; separate modules, we split those two modules further according to @@ -54,8 +54,8 @@ attributes #1 = { "sycl-module-id"="a.cpp" } ; CHECK: [Code|Properties] ; CHECK-DAG: {{.*}}tmp_0.ll|{{.*}}_0.prop ; CHECK-DAG: {{.*}}tmp_1.ll|{{.*}}_1.prop -; CHECK-DAG: {{.*}}tmp_esimd_2.ll|{{.*}}_esimd_2.prop -; CHECK-DAG: {{.*}}tmp_esimd_3.ll|{{.*}}_esimd_3.prop +; CHECK-DAG: {{.*}}tmp_2.esimd.ll|{{.*}}_2.esimd.prop +; CHECK-DAG: {{.*}}tmp_3.esimd.ll|{{.*}}_3.esimd.prop ; CHECK-SYCL-IR-1-DAG: define dso_local spir_kernel void @SYCL_kernel1() ; CHECK-SYCL-IR-1-DAG: declare dso_local spir_func i64 @_Z28__spirv_GlobalInvocationId_xv() diff --git a/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-esimd-split-per-source.ll b/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-esimd-split-per-source.ll index 610e52b8476ce..7f997cf4d6dca 100644 --- a/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-esimd-split-per-source.ll +++ b/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-esimd-split-per-source.ll @@ -2,8 +2,8 @@ ; RUN: FileCheck %s -input-file=%t.table ; RUN: FileCheck %s -input-file=%t_0.ll --check-prefixes CHECK-SYCL-IR-0 ; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-SYCL-IR-1 -; RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes CHECK-ESIMD-IR-0 -; RUN: FileCheck %s -input-file=%t_esimd_1.ll --check-prefixes CHECK-ESIMD-IR-1 +; RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes CHECK-ESIMD-IR-0 +; RUN: FileCheck %s -input-file=%t_1.esimd.ll --check-prefixes CHECK-ESIMD-IR-1 ; This test checks that after we split SYCL and ESIMD kernels into ; separate modules, we split those two modules further according to @@ -68,8 +68,8 @@ attributes #1 = { "sycl-module-id"="b.cpp" } ; CHECK: [Code|Properties] ; CHECK-DAG: {{.*}}tmp_0.ll|{{.*}}_0.prop ; CHECK-DAG: {{.*}}tmp_1.ll|{{.*}}_1.prop -; CHECK-DAG: {{.*}}tmp_esimd_0.ll|{{.*}}_esimd_0.prop -; CHECK-DAG: {{.*}}tmp_esimd_1.ll|{{.*}}_esimd_1.prop +; CHECK-DAG: {{.*}}tmp_0.esimd.ll|{{.*}}_0.esimd.prop +; CHECK-DAG: {{.*}}tmp_1.esimd.ll|{{.*}}_1.esimd.prop ; CHECK-SYCL-IR-1-DAG: define dso_local spir_kernel void @SYCL_kernel1() ; CHECK-SYCL-IR-1-DAG: define dso_local spir_kernel void @SYCL_kernel2() diff --git a/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-esimd-split-symbols.ll b/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-esimd-split-symbols.ll index cf0f42ab9a063..dcbaad8caa86b 100644 --- a/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-esimd-split-symbols.ll +++ b/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-esimd-split-symbols.ll @@ -1,7 +1,7 @@ ; RUN: sycl-post-link -properties -split-esimd -symbols -S < %s -o %t.table ; RUN: FileCheck %s -input-file=%t.table ; RUN: FileCheck %s -input-file=%t_0.sym --check-prefixes CHECK-SYCL-SYM -; RUN: FileCheck %s -input-file=%t_esimd_0.sym --check-prefixes CHECK-ESIMD-SYM +; RUN: FileCheck %s -input-file=%t_0.esimd.sym --check-prefixes CHECK-ESIMD-SYM ; This test checks symbols generation when we split SYCL and ESIMD kernels into ; separate modules. @@ -49,7 +49,7 @@ attributes #1 = { "sycl-module-id"="b.cpp" } ; CHECK: [Code|Properties|Symbols] ; CHECK-DAG: {{.*}}tmp_0.ll|{{.*}}_0.prop|{{.*}}_0.sym -; CHECK-DAG: {{.*}}tmp_esimd_0.ll|{{.*}}_esimd_0.prop|{{.*}}_esimd_0.sym +; CHECK-DAG: {{.*}}tmp_0.esimd.ll|{{.*}}_0.esimd.prop|{{.*}}_0.esimd.sym ; CHECK-SYCL-SYM: SYCL_kernel1 ; CHECK-SYCL-SYM: SYCL_kernel2 diff --git a/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-post-link-test.ll b/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-post-link-test.ll index 4b523d4c9ad1b..3fb5060c5c444 100644 --- a/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-post-link-test.ll +++ b/llvm/test/tools/sycl-post-link/sycl-esimd/sycl-post-link-test.ll @@ -1,6 +1,6 @@ ; -O0 lowering, requires `-force-disable-esimd-opt` to disable all optimizations. ; RUN: sycl-post-link -properties -split-esimd -lower-esimd -O0 -force-disable-esimd-opt -S < %s -o %t.table -; RUN: FileCheck %s -input-file=%t_esimd_0.ll +; RUN: FileCheck %s -input-file=%t_0.esimd.ll ; This test checks that IR code below can be successfully processed by ; sycl-post-link. In this IR no extractelement instruction and no casting are used diff --git a/llvm/test/tools/sycl-post-link/sycl-external-funcs/split-and-lower-esimd.ll b/llvm/test/tools/sycl-post-link/sycl-external-funcs/split-and-lower-esimd.ll index 55a3a7aad9c3b..cdb051cf5003e 100644 --- a/llvm/test/tools/sycl-post-link/sycl-external-funcs/split-and-lower-esimd.ll +++ b/llvm/test/tools/sycl-post-link/sycl-external-funcs/split-and-lower-esimd.ll @@ -1,5 +1,5 @@ ; RUN: sycl-post-link -properties -split=auto -split-esimd -lower-esimd -O0 -S < %s -o %t.table -; RUN: FileCheck %s -input-file=%t_esimd_0.ll +; RUN: FileCheck %s -input-file=%t_0.esimd.ll ; This test checks that unreferenced functions with sycl-module-id ; attribute are not dropped from the module and ESIMD lowering diff --git a/llvm/test/tools/sycl-post-link/sycl-grf-size.ll b/llvm/test/tools/sycl-post-link/sycl-grf-size.ll index 28bb07e18fae7..7c48ad11f838a 100644 --- a/llvm/test/tools/sycl-post-link/sycl-grf-size.ll +++ b/llvm/test/tools/sycl-post-link/sycl-grf-size.ll @@ -2,22 +2,22 @@ ; RUN: sycl-post-link -properties -split=source -symbols -split-esimd -lower-esimd -S < %s -o %t.table ; RUN: FileCheck %s -input-file=%t.table -; RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes CHECK-ESIMD-LargeGRF-IR --implicit-check-not='__ESIMD_kernel()' -; RUN: FileCheck %s -input-file=%t_esimd_0.prop --check-prefixes CHECK-ESIMD-LargeGRF-PROP -; RUN: FileCheck %s -input-file=%t_esimd_0.sym --check-prefixes CHECK-ESIMD-LargeGRF-SYM +; RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes CHECK-ESIMD-LargeGRF-IR --implicit-check-not='__ESIMD_kernel()' +; RUN: FileCheck %s -input-file=%t_0.esimd.prop --check-prefixes CHECK-ESIMD-LargeGRF-PROP +; RUN: FileCheck %s -input-file=%t_0.esimd.sym --check-prefixes CHECK-ESIMD-LargeGRF-SYM ; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-SYCL-LargeGRF-IR --implicit-check-not='__SYCL_kernel()' ; RUN: FileCheck %s -input-file=%t_1.prop --check-prefixes CHECK-SYCL-LargeGRF-PROP ; RUN: FileCheck %s -input-file=%t_1.sym --check-prefixes CHECK-SYCL-LargeGRF-SYM ; RUN: FileCheck %s -input-file=%t_3.ll --check-prefixes CHECK-SYCL-IR --implicit-check-not='__SYCL_kernel_large_grf()' ; RUN: FileCheck %s -input-file=%t_3.prop --check-prefixes CHECK-SYCL-PROP ; RUN: FileCheck %s -input-file=%t_3.sym --check-prefixes CHECK-SYCL-SYM -; RUN: FileCheck %s -input-file=%t_esimd_2.ll --check-prefixes CHECK-ESIMD-IR --implicit-check-not='__ESIMD_large_grf_kernel()' -; RUN: FileCheck %s -input-file=%t_esimd_2.prop --check-prefixes CHECK-ESIMD-PROP +; RUN: FileCheck %s -input-file=%t_2.esimd.ll --check-prefixes CHECK-ESIMD-IR --implicit-check-not='__ESIMD_large_grf_kernel()' +; RUN: FileCheck %s -input-file=%t_2.esimd.prop --check-prefixes CHECK-ESIMD-PROP ; CHECK: [Code|Properties|Symbols] -; CHECK: {{.*}}_esimd_0.ll|{{.*}}_esimd_0.prop|{{.*}}_esimd_0.sym +; CHECK: {{.*}}_0.esimd.ll|{{.*}}_0.esimd.prop|{{.*}}_0.esimd.sym ; CHECK: {{.*}}_1.ll|{{.*}}_1.prop|{{.*}}_1.sym -; CHECK: {{.*}}_esimd_2.ll|{{.*}}_esimd_2.prop|{{.*}}_esimd_2.sym +; CHECK: {{.*}}_2.esimd.ll|{{.*}}_2.esimd.prop|{{.*}}_2.esimd.sym ; CHECK-ESIMD-LargeGRF-PROP: isEsimdImage=1|1 ; CHECK-ESIMD-LargeGRF-PROP: sycl-grf-size=1|256 diff --git a/llvm/tools/sycl-post-link/sycl-post-link.cpp b/llvm/tools/sycl-post-link/sycl-post-link.cpp index 48b83bd1f86d4..923474605809f 100644 --- a/llvm/tools/sycl-post-link/sycl-post-link.cpp +++ b/llvm/tools/sycl-post-link/sycl-post-link.cpp @@ -344,41 +344,43 @@ bool isTargetCompatibleWithModule(const std::string &Target, void addTableRow(util::SimpleTable &Table, const IrPropSymFilenameTriple &RowData); +void prepareModuleBeforeSave(module_split::ModuleDesc &MD, bool Cleanup, + bool AllowDeviceImageDependencies = false) { + MD.saveSplitInformationAsMetadata(); + if (Cleanup) + MD.cleanup(AllowDeviceImageDependencies); +} + /// \param OutTables List of tables (one for each target) to output results /// \param MD Module descriptor to save -/// \param OutputPrefix Prefix for all generated outputs. +/// \param OutputPrefix Prefix for all generated outputs. Output files use +/// dot-separated suffixes: OutputPrefix.esimd.ext for ESIMD modules or +/// OutputPrefix.target.ext for target-specific property files (e.g., +/// prefix_0.esimd.ll, prefix_0.intel_gpu_pvc.prop). /// \param IRFilename Filename of IR component. If filename is not empty, it /// is recorded in the OutTable. Otherwise, a new file is created to save /// the IR component, and the new name is recorded in the OutTable. -void saveModule( +Error saveModule( const std::vector> &OutTables, - module_split::ModuleDesc &MD, const int I, const Twine &OutputPrefix, + module_split::ModuleDesc &MD, const Twine &OutputPrefix, const StringRef IRFilename) { IrPropSymFilenameTriple BaseTriple; - StringRef Suffix = MD.isESIMD() ? "_esimd" : ""; - MD.saveSplitInformationAsMetadata(); + StringRef Suffix = MD.isESIMD() ? ".esimd" : ""; if (!IRFilename.empty()) { // Don't save IR, just record the filename. BaseTriple.Ir = IRFilename.str(); } else { - if (!MD.isSYCLDeviceLib()) { - // For deviceLib Modules, we don't need to do clean up and no entry-point - // is included. The module only includes a bunch of exported functions - // intended to be invoked by user's device modules. - MD.cleanup(AllowDeviceImageDependencies); - } - StringRef IRExtension = OutputAssembly ? ".ll" : ".bc"; - BaseTriple.Ir = - (OutputPrefix + Suffix + "_" + Twine(I) + IRExtension).str(); + BaseTriple.Ir = (OutputPrefix + Suffix + IRExtension).str(); ExitOnErr(saveModuleIR(MD.getModule(), BaseTriple.Ir)); } if (DoSymGen) { // Save the names of the entry points - the symbol table. - BaseTriple.Sym = (OutputPrefix + Suffix + "_" + Twine(I) + ".sym").str(); - ExitOnErr(saveModuleSymbolTable(MD, BaseTriple.Sym)); + BaseTriple.Sym = (OutputPrefix + Suffix + ".sym").str(); + if (Error E = saveModuleSymbolTable(MD, BaseTriple.Sym)) + return E; } for (const auto &[Table, OutputFile] : zip_equal(OutTables, OutputFiles)) { @@ -392,20 +394,21 @@ void saveModule( StringRef Target = OutputFile.Target; std::string NewSuff = Suffix.str(); if (!Target.empty()) - NewSuff = (Twine("_") + Target).str(); + NewSuff = (Twine(".") + Target).str(); - CopyTriple.Prop = - (OutputPrefix + NewSuff + "_" + Twine(I) + ".prop").str(); - ExitOnErr(saveModuleProperties(MD, Props, CopyTriple.Prop, Target)); + CopyTriple.Prop = (OutputPrefix + NewSuff + ".prop").str(); + if (Error E = saveModuleProperties(MD, Props, CopyTriple.Prop, Target)) + return E; } addTableRow(*Table, CopyTriple); } + + return Error::success(); } Error saveDeviceLibModule( const std::vector> &OutTables, - const Twine &OutputPrefix, const int I, - const std::string &DeviceLibFileName) { + const Twine &OutputPrefix, const std::string &DeviceLibFileName) { assert(!DeviceLibFileName.empty() && "DeviceLibFileName is expected to be non-empty."); SMDiagnostic Err; @@ -422,7 +425,11 @@ Error saveDeviceLibModule( llvm::module_split::ModuleDesc DeviceLibMD(std::move(DeviceLibIR), DeviceLibFileName); - saveModule(OutTables, DeviceLibMD, I, OutputPrefix, ""); + // For deviceLib Modules, we don't need to do clean up and no entry-point + // is included. The module only includes a bunch of exported functions + // intended to be invoked by user's device modules. + prepareModuleBeforeSave(DeviceLibMD, /*Cleanup*/ false); + saveModule(OutTables, DeviceLibMD, OutputPrefix, ""); return Error::success(); } @@ -600,7 +607,10 @@ processInputModule(std::unique_ptr M, const StringRef OutputPrefix) { } for (const std::unique_ptr &IrMD : MMs) { IsBF16DeviceLibUsed |= isSYCLDeviceLibBF16Used(IrMD->getModule()); - saveModule(Tables, *IrMD, ID, OutputPrefix, OutIRFileName); + prepareModuleBeforeSave(*IrMD, /*Cleanup*/ OutIRFileName.empty(), + AllowDeviceImageDependencies); + ExitOnErr(saveModule(Tables, *IrMD, OutputPrefix + "_" + Twine(ID), + OutIRFileName)); } ++ID; @@ -610,7 +620,10 @@ processInputModule(std::unique_ptr M, const StringRef OutputPrefix) { const std::unique_ptr &IrMD = MMsWithDefaultSpecConsts[i]; IsBF16DeviceLibUsed |= isSYCLDeviceLibBF16Used(IrMD->getModule()); - saveModule(Tables, *IrMD, ID, OutputPrefix, OutIRFileName); + prepareModuleBeforeSave(*IrMD, /*Cleanup*/ OutIRFileName.empty(), + AllowDeviceImageDependencies); + ExitOnErr(saveModule(Tables, *IrMD, OutputPrefix + "_" + Twine(ID), + OutIRFileName)); } ++ID; @@ -618,9 +631,9 @@ processInputModule(std::unique_ptr M, const StringRef OutputPrefix) { } if (IsBF16DeviceLibUsed && (DeviceLibDir.getNumOccurrences() > 0)) { - ExitOnErr(saveDeviceLibModule(Tables, OutputPrefix, ID, + ExitOnErr(saveDeviceLibModule(Tables, OutputPrefix + "_" + Twine(ID), "libsycl-fallback-bfloat16.bc")); - ExitOnErr(saveDeviceLibModule(Tables, OutputPrefix, ID + 1, + ExitOnErr(saveDeviceLibModule(Tables, OutputPrefix + "_" + Twine(ID + 1), "libsycl-native-bfloat16.bc")); } return Tables; From 10ba9a4173791408f16853544b5b016bbc1ce5a3 Mon Sep 17 00:00:00 2001 From: "Sabianin, Maksim" Date: Wed, 1 Apr 2026 13:43:38 -0700 Subject: [PATCH 2/4] resolve mistake --- llvm/tools/sycl-post-link/sycl-post-link.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/llvm/tools/sycl-post-link/sycl-post-link.cpp b/llvm/tools/sycl-post-link/sycl-post-link.cpp index 923474605809f..62323c1efd8e0 100644 --- a/llvm/tools/sycl-post-link/sycl-post-link.cpp +++ b/llvm/tools/sycl-post-link/sycl-post-link.cpp @@ -429,8 +429,7 @@ Error saveDeviceLibModule( // is included. The module only includes a bunch of exported functions // intended to be invoked by user's device modules. prepareModuleBeforeSave(DeviceLibMD, /*Cleanup*/ false); - saveModule(OutTables, DeviceLibMD, OutputPrefix, ""); - return Error::success(); + return saveModule(OutTables, DeviceLibMD, OutputPrefix, ""); } void addTableRow(util::SimpleTable &Table, From 7a79d77723b5bd4d9408c6b40ebaea669086c7fd Mon Sep 17 00:00:00 2001 From: "Sabianin, Maksim" Date: Wed, 1 Apr 2026 15:34:05 -0700 Subject: [PATCH 3/4] fix sycl/test/ failing tests --- sycl/test/check_device_code/esimd/NBarrierAttr.cpp | 2 +- sycl/test/check_device_code/esimd/dpas.cpp | 2 +- sycl/test/check_device_code/esimd/fp16_converts.cpp | 2 +- sycl/test/check_device_code/esimd/genx_func_attr.cpp | 2 +- sycl/test/check_device_code/esimd/glob.cpp | 2 +- sycl/test/check_device_code/esimd/intrins_trans.cpp | 4 ++-- sycl/test/check_device_code/esimd/lower-external-funcs.cpp | 2 +- sycl/test/check_device_code/esimd/lsc.cpp | 4 ++-- .../esimd/memory_properties_atomic_update.cpp | 4 ++-- .../esimd/memory_properties_copytocopyfrom.cpp | 4 ++-- .../test/check_device_code/esimd/memory_properties_gather.cpp | 4 ++-- .../check_device_code/esimd/memory_properties_load_store.cpp | 4 ++-- .../check_device_code/esimd/memory_properties_prefetch_2d.cpp | 4 ++-- .../check_device_code/esimd/memory_properties_scatter.cpp | 4 ++-- sycl/test/check_device_code/esimd/slm_init_specconst_size.cpp | 2 +- sycl/test/check_device_code/esimd/spirv_intrins_trans.cpp | 2 +- sycl/test/esimd/sycl_half_basic_ops.cpp | 2 +- sycl/test/esimd/sycl_half_math_ops.cpp | 2 +- 18 files changed, 26 insertions(+), 26 deletions(-) diff --git a/sycl/test/check_device_code/esimd/NBarrierAttr.cpp b/sycl/test/check_device_code/esimd/NBarrierAttr.cpp index 22664873922d1..a1de47122751a 100644 --- a/sycl/test/check_device_code/esimd/NBarrierAttr.cpp +++ b/sycl/test/check_device_code/esimd/NBarrierAttr.cpp @@ -1,6 +1,6 @@ // RUN: %clangxx -O2 -fsycl -fsycl-device-only -Xclang -emit-llvm %s -o %t // RUN: sycl-post-link -split=none -properties -lower-esimd -O2 -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll +// RUN: FileCheck %s -input-file=%t_0.esimd.ll // Checks NBarrier ESIMD intrinsic translation. diff --git a/sycl/test/check_device_code/esimd/dpas.cpp b/sycl/test/check_device_code/esimd/dpas.cpp index f23495cbbd86a..25f4c4fddff71 100644 --- a/sycl/test/check_device_code/esimd/dpas.cpp +++ b/sycl/test/check_device_code/esimd/dpas.cpp @@ -1,7 +1,7 @@ // RUN: %clangxx -fsycl -c -Xclang -emit-llvm %s -o %t // RUN: %clangxx -fsycl -c -fsycl-device-only -Xclang -emit-llvm %s -o %t // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll +// RUN: FileCheck %s -input-file=%t_0.esimd.ll #include #include diff --git a/sycl/test/check_device_code/esimd/fp16_converts.cpp b/sycl/test/check_device_code/esimd/fp16_converts.cpp index d3ac2b3296251..a2f78010c242d 100644 --- a/sycl/test/check_device_code/esimd/fp16_converts.cpp +++ b/sycl/test/check_device_code/esimd/fp16_converts.cpp @@ -8,7 +8,7 @@ // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll +// RUN: FileCheck %s -input-file=%t_0.esimd.ll #include #include diff --git a/sycl/test/check_device_code/esimd/genx_func_attr.cpp b/sycl/test/check_device_code/esimd/genx_func_attr.cpp index d9c813f725d1c..6ae6de476e4c0 100644 --- a/sycl/test/check_device_code/esimd/genx_func_attr.cpp +++ b/sycl/test/check_device_code/esimd/genx_func_attr.cpp @@ -1,6 +1,6 @@ // RUN: %clangxx -O2 -fsycl -fsycl-device-only -Xclang -emit-llvm %s -o %t // RUN: sycl-post-link -split=none -properties -lower-esimd -O2 -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll +// RUN: FileCheck %s -input-file=%t_0.esimd.ll // Checks ESIMD intrinsic translation. diff --git a/sycl/test/check_device_code/esimd/glob.cpp b/sycl/test/check_device_code/esimd/glob.cpp index 1fbe43d100889..00ec02fa298dd 100644 --- a/sycl/test/check_device_code/esimd/glob.cpp +++ b/sycl/test/check_device_code/esimd/glob.cpp @@ -1,6 +1,6 @@ // RUN: %clangxx -fsycl -c -fsycl-device-only -Xclang -emit-llvm %s -o %t // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -O2 -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll +// RUN: FileCheck %s -input-file=%t_0.esimd.ll // This test checks that globals with register attribute are allowed in ESIMD // mode, can be accessed in functions and correct LLVM IR is generated diff --git a/sycl/test/check_device_code/esimd/intrins_trans.cpp b/sycl/test/check_device_code/esimd/intrins_trans.cpp index bd53a074003f0..02e81a81aaf03 100644 --- a/sycl/test/check_device_code/esimd/intrins_trans.cpp +++ b/sycl/test/check_device_code/esimd/intrins_trans.cpp @@ -2,13 +2,13 @@ // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -properties -split=none -split-esimd -lower-esimd -lower-esimd-force-stateless-mem=false -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATEFUL +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATEFUL // RUN: %clangxx %clang_O0 -fsycl -fsycl-device-only -fsycl-esimd-force-stateless-mem -Xclang -emit-llvm %s -o %t // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -properties -split=none -split-esimd -lower-esimd -lower-esimd-force-stateless-mem=true -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATELESS +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATELESS // Checks ESIMD intrinsic translation with opaque pointers. // NOTE: must be run with %clang_O0, as optimizer optimizes away some of the diff --git a/sycl/test/check_device_code/esimd/lower-external-funcs.cpp b/sycl/test/check_device_code/esimd/lower-external-funcs.cpp index 7c42a71faa4fd..c7e2c272c1d9b 100644 --- a/sycl/test/check_device_code/esimd/lower-external-funcs.cpp +++ b/sycl/test/check_device_code/esimd/lower-external-funcs.cpp @@ -1,6 +1,6 @@ // RUN: %clangxx -fsycl -fsycl-device-only -S -emit-llvm -x c++ %s -o %t // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -O2 -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll +// RUN: FileCheck %s -input-file=%t_0.esimd.ll // This test checks that unreferenced SYCL_EXTERNAL functions are not dropped // from the module and go through sycl-post-link. This test also checks that diff --git a/sycl/test/check_device_code/esimd/lsc.cpp b/sycl/test/check_device_code/esimd/lsc.cpp index 39e2596f0e687..fc81e4c4db45d 100644 --- a/sycl/test/check_device_code/esimd/lsc.cpp +++ b/sycl/test/check_device_code/esimd/lsc.cpp @@ -2,13 +2,13 @@ // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -lower-esimd-force-stateless-mem=false -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATEFUL +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATEFUL // RUN: %clangxx -O0 -fsycl -fsycl-esimd-force-stateless-mem -fsycl-device-only -Xclang -emit-llvm %s -o %t // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATELESS +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATELESS // Checks ESIMD intrinsic translation. // NOTE: must be run in -O0, as optimizer optimizes away some of the code. diff --git a/sycl/test/check_device_code/esimd/memory_properties_atomic_update.cpp b/sycl/test/check_device_code/esimd/memory_properties_atomic_update.cpp index b4e5ba53020d9..58c46d3d941ec 100644 --- a/sycl/test/check_device_code/esimd/memory_properties_atomic_update.cpp +++ b/sycl/test/check_device_code/esimd/memory_properties_atomic_update.cpp @@ -2,13 +2,13 @@ // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -lower-esimd-force-stateless-mem=false -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATEFUL +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATEFUL // RUN: %clangxx -O0 -fsycl -fsycl-device-only -fsycl-esimd-force-stateless-mem -D__ESIMD_GATHER_SCATTER_LLVM_IR -Xclang -emit-llvm %s -o %t // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -lower-esimd-force-stateless-mem -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATELESS +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATELESS // Checks ESIMD memory functions accepting compile time properties for // atomic_update APIs. NOTE: must be run in -O0, as optimizer optimizes away diff --git a/sycl/test/check_device_code/esimd/memory_properties_copytocopyfrom.cpp b/sycl/test/check_device_code/esimd/memory_properties_copytocopyfrom.cpp index 1c73b4983a431..ad7decd7f2368 100644 --- a/sycl/test/check_device_code/esimd/memory_properties_copytocopyfrom.cpp +++ b/sycl/test/check_device_code/esimd/memory_properties_copytocopyfrom.cpp @@ -2,13 +2,13 @@ // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -lower-esimd-force-stateless-mem=false -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATEFUL +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATEFUL // RUN: %clangxx -O0 -fsycl -fsycl-device-only -fsycl-esimd-force-stateless-mem -D__ESIMD_GATHER_SCATTER_LLVM_IR -Xclang -emit-llvm %s -o %t // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -lower-esimd-force-stateless-mem -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATELESS +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATELESS // Checks ESIMD copy_to and copy_from functions accepting compile time // properties. NOTE: must be run in -O0, as optimizer optimizes away some of the diff --git a/sycl/test/check_device_code/esimd/memory_properties_gather.cpp b/sycl/test/check_device_code/esimd/memory_properties_gather.cpp index 77b5f8ad3f1bb..5dbd81dfab67e 100644 --- a/sycl/test/check_device_code/esimd/memory_properties_gather.cpp +++ b/sycl/test/check_device_code/esimd/memory_properties_gather.cpp @@ -2,13 +2,13 @@ // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -lower-esimd-force-stateless-mem=false -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATEFUL +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATEFUL // RUN: %clangxx -O0 -fsycl -fsycl-device-only -fsycl-esimd-force-stateless-mem -D__ESIMD_GATHER_SCATTER_LLVM_IR -Xclang -emit-llvm %s -o %t // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -lower-esimd-force-stateless-mem -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATELESS +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATELESS // Checks ESIMD memory functions accepting compile time properties for gather // APIs. NOTE: must be run in -O0, as optimizer optimizes away some of the code. diff --git a/sycl/test/check_device_code/esimd/memory_properties_load_store.cpp b/sycl/test/check_device_code/esimd/memory_properties_load_store.cpp index f51652ab05d41..fe66b2fea633b 100644 --- a/sycl/test/check_device_code/esimd/memory_properties_load_store.cpp +++ b/sycl/test/check_device_code/esimd/memory_properties_load_store.cpp @@ -2,13 +2,13 @@ // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -lower-esimd-force-stateless-mem=false -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATEFUL +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATEFUL // RUN: %clangxx -O0 -fsycl -fsycl-device-only -fsycl-esimd-force-stateless-mem -D__ESIMD_GATHER_SCATTER_LLVM_IR -Xclang -emit-llvm %s -o %t // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -lower-esimd-force-stateless-mem -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATELESS +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATELESS // Checks ESIMD memory functions accepting compile time properties for // block_load and block_store. NOTE: must be run in -O0, as optimizer optimizes diff --git a/sycl/test/check_device_code/esimd/memory_properties_prefetch_2d.cpp b/sycl/test/check_device_code/esimd/memory_properties_prefetch_2d.cpp index 63a35f833b7d6..f9b48de124192 100644 --- a/sycl/test/check_device_code/esimd/memory_properties_prefetch_2d.cpp +++ b/sycl/test/check_device_code/esimd/memory_properties_prefetch_2d.cpp @@ -2,13 +2,13 @@ // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -lower-esimd-force-stateless-mem=false -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATEFUL +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATEFUL // RUN: %clangxx -O0 -fsycl -fsycl-device-only -fsycl-esimd-force-stateless-mem -D__ESIMD_GATHER_SCATTER_LLVM_IR -Xclang -emit-llvm %s -o %t // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -lower-esimd-force-stateless-mem -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATELESS +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATELESS // Checks ESIMD memory functions accepting compile time properties for prefetch // and 2D APIs. NOTE: must be run in -O0, as optimizer optimizes away some of diff --git a/sycl/test/check_device_code/esimd/memory_properties_scatter.cpp b/sycl/test/check_device_code/esimd/memory_properties_scatter.cpp index 6a594c45554f4..6eea859ef2f1b 100644 --- a/sycl/test/check_device_code/esimd/memory_properties_scatter.cpp +++ b/sycl/test/check_device_code/esimd/memory_properties_scatter.cpp @@ -2,13 +2,13 @@ // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -lower-esimd-force-stateless-mem=false -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATEFUL +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATEFUL // RUN: %clangxx -O0 -fsycl -fsycl-device-only -fsycl-esimd-force-stateless-mem -D__ESIMD_GATHER_SCATTER_LLVM_IR -Xclang -emit-llvm %s -o %t // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -lower-esimd-force-stateless-mem -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes=CHECK,CHECK-STATELESS +// RUN: FileCheck %s -input-file=%t_0.esimd.ll --check-prefixes=CHECK,CHECK-STATELESS // Checks ESIMD memory functions accepting compile time properties for scatter // APIs. NOTE: must be run in -O0, as optimizer optimizes away some of the code. diff --git a/sycl/test/check_device_code/esimd/slm_init_specconst_size.cpp b/sycl/test/check_device_code/esimd/slm_init_specconst_size.cpp index ce1483d6610c8..398fc74f42386 100644 --- a/sycl/test/check_device_code/esimd/slm_init_specconst_size.cpp +++ b/sycl/test/check_device_code/esimd/slm_init_specconst_size.cpp @@ -1,6 +1,6 @@ // RUN: %clangxx -O2 -fsycl -fsycl-device-only %s -o %t // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -O2 -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll +// RUN: FileCheck %s -input-file=%t_0.esimd.ll // Checks that we set 0 as VCSLMSize when slm_init is used with // non-constant operand, like with specialization constant. diff --git a/sycl/test/check_device_code/esimd/spirv_intrins_trans.cpp b/sycl/test/check_device_code/esimd/spirv_intrins_trans.cpp index a82fe98a86765..946801999626b 100644 --- a/sycl/test/check_device_code/esimd/spirv_intrins_trans.cpp +++ b/sycl/test/check_device_code/esimd/spirv_intrins_trans.cpp @@ -2,7 +2,7 @@ // -O0 lowering, requires `-force-disable-esimd-opt` to disable all // optimizations. // RUN: sycl-post-link -split=none -split-esimd -lower-esimd -O0 -force-disable-esimd-opt -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll +// RUN: FileCheck %s -input-file=%t_0.esimd.ll // This test checks that all LLVM-IR instructions that work with SPIR-V builtins // are correctly translated into GenX counterparts (implemented in diff --git a/sycl/test/esimd/sycl_half_basic_ops.cpp b/sycl/test/esimd/sycl_half_basic_ops.cpp index 8b3a08be647f0..fe013afbdd433 100644 --- a/sycl/test/esimd/sycl_half_basic_ops.cpp +++ b/sycl/test/esimd/sycl_half_basic_ops.cpp @@ -1,6 +1,6 @@ // RUN: %clangxx -fsycl -fsycl-device-only -S %s -o %t // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -S %t -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll +// RUN: FileCheck %s -input-file=%t_0.esimd.ll // The test checks that there are no unexpected extra conversions or intrinsic // calls added by the API headers or compiler when generating code diff --git a/sycl/test/esimd/sycl_half_math_ops.cpp b/sycl/test/esimd/sycl_half_math_ops.cpp index 01cce67ea1f2c..a7ef3b43c4328 100644 --- a/sycl/test/esimd/sycl_half_math_ops.cpp +++ b/sycl/test/esimd/sycl_half_math_ops.cpp @@ -1,6 +1,6 @@ // RUN: %clangxx -fsycl -fsycl-device-only -S %s -o %t.ll // RUN: sycl-post-link -split=none -properties -split-esimd -lower-esimd -S %t.ll -o %t.table -// RUN: FileCheck %s -input-file=%t_esimd_0.ll +// RUN: FileCheck %s -input-file=%t_0.esimd.ll // The test checks that there are no unexpected extra conversions or intrinsic // calls added by the API headers or compiler when generating code From b9c093f3a758239f92e970e5f327b4d5a83e1d62 Mon Sep 17 00:00:00 2001 From: "Sabianin, Maksim" Date: Tue, 7 Apr 2026 06:11:30 -0700 Subject: [PATCH 4/4] address comments --- llvm/tools/sycl-post-link/sycl-post-link.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/llvm/tools/sycl-post-link/sycl-post-link.cpp b/llvm/tools/sycl-post-link/sycl-post-link.cpp index 62323c1efd8e0..99d7877b2df1c 100644 --- a/llvm/tools/sycl-post-link/sycl-post-link.cpp +++ b/llvm/tools/sycl-post-link/sycl-post-link.cpp @@ -344,10 +344,10 @@ bool isTargetCompatibleWithModule(const std::string &Target, void addTableRow(util::SimpleTable &Table, const IrPropSymFilenameTriple &RowData); -void prepareModuleBeforeSave(module_split::ModuleDesc &MD, bool Cleanup, - bool AllowDeviceImageDependencies = false) { +void prepareModuleBeforeSave(module_split::ModuleDesc &MD, bool RunCleanup, + bool AllowDeviceImageDependencies) { MD.saveSplitInformationAsMetadata(); - if (Cleanup) + if (RunCleanup) MD.cleanup(AllowDeviceImageDependencies); } @@ -373,7 +373,8 @@ Error saveModule( } else { StringRef IRExtension = OutputAssembly ? ".ll" : ".bc"; BaseTriple.Ir = (OutputPrefix + Suffix + IRExtension).str(); - ExitOnErr(saveModuleIR(MD.getModule(), BaseTriple.Ir)); + if (Error E = saveModuleIR(MD.getModule(), BaseTriple.Ir)) + return E; } if (DoSymGen) { @@ -428,7 +429,8 @@ Error saveDeviceLibModule( // For deviceLib Modules, we don't need to do clean up and no entry-point // is included. The module only includes a bunch of exported functions // intended to be invoked by user's device modules. - prepareModuleBeforeSave(DeviceLibMD, /*Cleanup*/ false); + prepareModuleBeforeSave(DeviceLibMD, /*RunCleanup*/ false, + /*AllowDeviceImageDependencies*/ false); return saveModule(OutTables, DeviceLibMD, OutputPrefix, ""); } @@ -606,7 +608,7 @@ processInputModule(std::unique_ptr M, const StringRef OutputPrefix) { } for (const std::unique_ptr &IrMD : MMs) { IsBF16DeviceLibUsed |= isSYCLDeviceLibBF16Used(IrMD->getModule()); - prepareModuleBeforeSave(*IrMD, /*Cleanup*/ OutIRFileName.empty(), + prepareModuleBeforeSave(*IrMD, /*RunCleanup*/ OutIRFileName.empty(), AllowDeviceImageDependencies); ExitOnErr(saveModule(Tables, *IrMD, OutputPrefix + "_" + Twine(ID), OutIRFileName)); @@ -619,7 +621,7 @@ processInputModule(std::unique_ptr M, const StringRef OutputPrefix) { const std::unique_ptr &IrMD = MMsWithDefaultSpecConsts[i]; IsBF16DeviceLibUsed |= isSYCLDeviceLibBF16Used(IrMD->getModule()); - prepareModuleBeforeSave(*IrMD, /*Cleanup*/ OutIRFileName.empty(), + prepareModuleBeforeSave(*IrMD, /*RunCleanup*/ OutIRFileName.empty(), AllowDeviceImageDependencies); ExitOnErr(saveModule(Tables, *IrMD, OutputPrefix + "_" + Twine(ID), OutIRFileName));