llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clangir

@llvm/pr-subscribers-clang

Author: Qi Ye (Qi-Ye-079)

<details>
<summary>Changes</summary>

An OpenMP device module (`openmp_is_target_device = true` in 
`cir.lowering_options`) with some spirv* triples will lead to a crash in 
mlir-translate, after `CallConvLoweringPass` for SPIRV.
This isn't an issue in the call-conv lowering for SPIRV itself, but some 
missing gaps in MLIR/OpenMP dialect that incorrectly handles OpenMP device code 
translation. Therefore, we've decided to temporarily report error for OpenMP 
device code with SPIRV target, until MLIR side is fixed.
Tracking issue: https://github.com/llvm/llvm-project/issues/244021

---
Full diff: https://github.com/llvm/llvm-project/pull/243989.diff


2 Files Affected:

- (modified) clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp (+12) 
- (added) clang/test/CIR/Transforms/abi-lowering/spirv-openmp-device-nyi.cir 
(+52) 


``````````diff
diff --git a/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp 
b/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
index c101cb6d26fd2..f63190f8c3f83 100644
--- a/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
@@ -204,6 +204,18 @@ void CallConvLoweringPass::runOnOperation() {
   bool enableNoundefAttrs =
       !loweringOpts || loweringOpts.getEnableNoundefAttrs();
 
+  // FIXME: MLIR translation currently crashes on CC-lowered CIR module
+  // for some spirv* triples due to some MLIR/OpenMP dialect gaps,
+  // thus temporarily report error for OpenMP device code with
+  // spirv target until the fix lands in MLIR.
+  if (target == cir::CallConvTarget::SPIRV && loweringOpts &&
+      loweringOpts.getOpenmpIsTargetDevice()) {
+    moduleOp.emitOpError() << "OpenMP device code with SPIR-V target "
+                              "is not yet supported";
+    signalPassFailure();
+    return;
+  }
+
   DataLayout dl(moduleOp);
   CIRABIRewriteContext rewriteCtx(moduleOp, dl, enableNoundefAttrs);
   // A non-byval indirect parameter's slot outlives the rewrite that retypes
diff --git a/clang/test/CIR/Transforms/abi-lowering/spirv-openmp-device-nyi.cir 
b/clang/test/CIR/Transforms/abi-lowering/spirv-openmp-device-nyi.cir
new file mode 100644
index 0000000000000..a46fe21090fdd
--- /dev/null
+++ b/clang/test/CIR/Transforms/abi-lowering/spirv-openmp-device-nyi.cir
@@ -0,0 +1,52 @@
+// RUN: not cir-opt %s -split-input-file -cir-call-conv-lowering=target=spirv 
2>&1 | FileCheck %s
+
+// A SPIR-V OpenMP device module is rejected as a whole, on any SPIR-V triple
+// and whatever the signatures in it.
+
+!s8i = !cir.int<s, 8>
+
+module attributes {
+  cir.triple = "spirv64-intel",
+  cir.lowering_options = #cir.lowering_options<
+    exceptions = false, threadsafe_statics = true, cuda = false,
+    cuda_is_device = false, hip = false, hlsl = false, sycl_is_device = false,
+    gpu_rdc = false, openmp = true, openmp_is_target_device = true,
+    clang_abi_compat = 17, long_double_size = 0, enable_noundef_attrs = true,
+    no_trapping_math = true, ssp_buffer_size = 8>,
+  dlti.dl_spec = #dlti.dl_spec<
+    #dlti.dl_entry<i8, dense<8>: vector<2xi64>>,
+    #dlti.dl_entry<i32, dense<32>: vector<2xi64>>,
+    #dlti.dl_entry<i64, dense<64>: vector<2xi64>>>
+} {
+
+  cir.func @take_s8(%arg0: !s8i) cc(spir_function) requires_call_conv_lowering 
{
+    cir.return
+  }
+
+  // CHECK: error: 'builtin.module' op OpenMP device code with SPIR-V target 
is not yet supported
+}
+
+// -----
+
+!s8i = !cir.int<s, 8>
+
+module attributes {
+  cir.triple = "spirv64-unknown-unknown",
+  cir.lowering_options = #cir.lowering_options<
+    exceptions = false, threadsafe_statics = true, cuda = false,
+    cuda_is_device = false, hip = false, hlsl = false, sycl_is_device = false,
+    gpu_rdc = false, openmp = true, openmp_is_target_device = true,
+    clang_abi_compat = 17, long_double_size = 0, enable_noundef_attrs = true,
+    no_trapping_math = true, ssp_buffer_size = 8>,
+  dlti.dl_spec = #dlti.dl_spec<
+    #dlti.dl_entry<i8, dense<8>: vector<2xi64>>,
+    #dlti.dl_entry<i32, dense<32>: vector<2xi64>>,
+    #dlti.dl_entry<i64, dense<64>: vector<2xi64>>>
+} {
+
+  cir.func @take_s8(%arg0: !s8i) cc(spir_function) requires_call_conv_lowering 
{
+    cir.return
+  }
+
+  // CHECK: error: 'builtin.module' op OpenMP device code with SPIR-V target 
is not yet supported
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/243989
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to