Skip to content

[flang][OpenMP] Skip runtime mapping with no offload targets #144534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 20, 2025

Conversation

kparzysz
Copy link
Contributor

When no offload targets are specified flang will ignore "target" constructs, but not "target data" constructs. This patch makes the behavior consistent across all offload-related operations.

While ignoring "target" may produce semantically incorrect code, it may still be a useful debugging tool.

When no offload targets are specified flang will ignore "target"
constructs, but not "target data" constructs. This patch makes the
behavior consistent across all offload-related operations.

While ignoring "target" may produce semantically incorrect code, it
may still be a useful debugging tool.
@kparzysz kparzysz requested review from skatrak, tblah and mjklemm June 17, 2025 14:38
@llvmbot llvmbot added mlir:llvm mlir flang Flang issues not falling into any other category mlir:openmp flang:fir-hlfir flang:openmp labels Jun 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 17, 2025

@llvm/pr-subscribers-mlir-openmp
@llvm/pr-subscribers-mlir-llvm
@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)

Changes

When no offload targets are specified flang will ignore "target" constructs, but not "target data" constructs. This patch makes the behavior consistent across all offload-related operations.

While ignoring "target" may produce semantically incorrect code, it may still be a useful debugging tool.


Patch is 30.76 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/144534.diff

5 Files Affected:

  • (added) flang/test/Lower/ignore-target-data.f90 (+20)
  • (modified) mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+11)
  • (modified) mlir/test/Target/LLVMIR/omptarget-llvm.mlir (+184-164)
  • (modified) mlir/test/Target/LLVMIR/omptargetdata-nowait-llvm.mlir (+24-18)
  • (modified) mlir/test/Target/LLVMIR/openmp-data-target-device.mlir (+1-1)
diff --git a/flang/test/Lower/ignore-target-data.f90 b/flang/test/Lower/ignore-target-data.f90
new file mode 100644
index 0000000000000..a2182ee0f5b0b
--- /dev/null
+++ b/flang/test/Lower/ignore-target-data.f90
@@ -0,0 +1,20 @@
+!RUN: %flang_fc1 -emit-llvm -fopenmp %s -o - | FileCheck %s
+
+!Make sure that there are no calls to the mapper.
+
+!CHECK-NOT: call{{.*}}__tgt_target_data_begin_mapper
+!CHECK-NOT: call{{.*}}__tgt_target_data_end_mapper
+
+program test
+
+call f(1, 2)
+
+contains
+
+subroutine f(x, y)
+  integer :: x, y
+  !$omp target data map(tofrom: x, y)
+  x = x + y
+  !$omp end target data
+end subroutine
+end
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 90ce06a0345c0..5985f2b0f5621 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -4378,6 +4378,9 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
   llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
   llvm::OpenMPIRBuilder::TargetDataInfo info(/*RequiresDevicePointerInfo=*/true,
                                              /*SeparateBeginEndCalls=*/true);
+  bool isTargetDevice = ompBuilder->Config.isTargetDevice();
+  bool isOffloadEntry =
+      isTargetDevice || !ompBuilder->Config.TargetTriples.empty();
 
   LogicalResult result =
       llvm::TypeSwitch<Operation *, LogicalResult>(op)
@@ -4402,6 +4405,8 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
           .Case([&](omp::TargetEnterDataOp enterDataOp) -> LogicalResult {
             if (failed(checkImplementationStatus(*enterDataOp)))
               return failure();
+            if (!isOffloadEntry)
+              return success();
 
             if (auto ifVar = enterDataOp.getIfExpr())
               ifCond = moduleTranslation.lookupValue(ifVar);
@@ -4422,6 +4427,8 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
           .Case([&](omp::TargetExitDataOp exitDataOp) -> LogicalResult {
             if (failed(checkImplementationStatus(*exitDataOp)))
               return failure();
+            if (!isOffloadEntry)
+              return success();
 
             if (auto ifVar = exitDataOp.getIfExpr())
               ifCond = moduleTranslation.lookupValue(ifVar);
@@ -4442,6 +4449,8 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
           .Case([&](omp::TargetUpdateOp updateDataOp) -> LogicalResult {
             if (failed(checkImplementationStatus(*updateDataOp)))
               return failure();
+            if (!isOffloadEntry)
+              return success();
 
             if (auto ifVar = updateDataOp.getIfExpr())
               ifCond = moduleTranslation.lookupValue(ifVar);
@@ -4467,6 +4476,8 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
 
   if (failed(result))
     return failure();
+  if (!isOffloadEntry)
+    return success();
 
   using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
   MapInfoData mapData;
diff --git a/mlir/test/Target/LLVMIR/omptarget-llvm.mlir b/mlir/test/Target/LLVMIR/omptarget-llvm.mlir
index 971bea2068544..e6ea3aaeec656 100644
--- a/mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ b/mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -1,15 +1,17 @@
 // RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
 
-llvm.func @_QPopenmp_target_data() {
-  %0 = llvm.mlir.constant(1 : i64) : i64
-  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array<i32: 0, 0>, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
-  %2 = omp.map.info var_ptr(%1 : !llvm.ptr, i32)   map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
-  omp.target_data map_entries(%2 : !llvm.ptr) {
-    %3 = llvm.mlir.constant(99 : i32) : i32
-    llvm.store %3, %1 : i32, !llvm.ptr
-    omp.terminator
+module attributes {omp.target_triples = ["amdgcn-amd-amdhsa"]} {
+  llvm.func @_QPopenmp_target_data() {
+    %0 = llvm.mlir.constant(1 : i64) : i64
+    %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array<i32: 0, 0>, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+    %2 = omp.map.info var_ptr(%1 : !llvm.ptr, i32)   map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
+    omp.target_data map_entries(%2 : !llvm.ptr) {
+      %3 = llvm.mlir.constant(99 : i32) : i32
+      llvm.store %3, %1 : i32, !llvm.ptr
+      omp.terminator
+    }
+    llvm.return
   }
-  llvm.return
 }
 
 // CHECK:         @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
@@ -38,23 +40,25 @@ llvm.func @_QPopenmp_target_data() {
 
 // -----
 
-llvm.func @_QPopenmp_target_data_region(%0 : !llvm.ptr) {
-  %1 = llvm.mlir.constant(1023 : index) : i64
-  %2 = llvm.mlir.constant(0 : index) : i64
-  %3 = llvm.mlir.constant(1024 : index) : i64
-  %4 = llvm.mlir.constant(1 : index) : i64
-  %5 = omp.map.bounds   lower_bound(%2 : i64) upper_bound(%1 : i64) extent(%3 : i64) stride(%4 : i64) start_idx(%4 : i64)
-  %6 = omp.map.info var_ptr(%0 : !llvm.ptr, !llvm.array<1024 x i32>)   map_clauses(from) capture(ByRef) bounds(%5)  -> !llvm.ptr {name = ""}
-  omp.target_data map_entries(%6 : !llvm.ptr) {
-    %7 = llvm.mlir.constant(99 : i32) : i32
-    %8 = llvm.mlir.constant(1 : i64) : i64
-    %9 = llvm.mlir.constant(1 : i64) : i64
-    %10 = llvm.mlir.constant(0 : i64) : i64
-    %11 = llvm.getelementptr %0[0, %10] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<1024 x i32>
-    llvm.store %7, %11 : i32, !llvm.ptr
-    omp.terminator
+module attributes {omp.target_triples = ["amdgcn-amd-amdhsa"]} {
+  llvm.func @_QPopenmp_target_data_region(%0 : !llvm.ptr) {
+    %1 = llvm.mlir.constant(1023 : index) : i64
+    %2 = llvm.mlir.constant(0 : index) : i64
+    %3 = llvm.mlir.constant(1024 : index) : i64
+    %4 = llvm.mlir.constant(1 : index) : i64
+    %5 = omp.map.bounds   lower_bound(%2 : i64) upper_bound(%1 : i64) extent(%3 : i64) stride(%4 : i64) start_idx(%4 : i64)
+    %6 = omp.map.info var_ptr(%0 : !llvm.ptr, !llvm.array<1024 x i32>)   map_clauses(from) capture(ByRef) bounds(%5)  -> !llvm.ptr {name = ""}
+    omp.target_data map_entries(%6 : !llvm.ptr) {
+      %7 = llvm.mlir.constant(99 : i32) : i32
+      %8 = llvm.mlir.constant(1 : i64) : i64
+      %9 = llvm.mlir.constant(1 : i64) : i64
+      %10 = llvm.mlir.constant(0 : i64) : i64
+      %11 = llvm.getelementptr %0[0, %10] : (!llvm.ptr, i64) -> !llvm.ptr, !llvm.array<1024 x i32>
+      llvm.store %7, %11 : i32, !llvm.ptr
+      omp.terminator
+    }
+    llvm.return
   }
-  llvm.return
 }
 
 // CHECK:         @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4096]
@@ -85,50 +89,52 @@ llvm.func @_QPopenmp_target_data_region(%0 : !llvm.ptr) {
 
 // -----
 
-llvm.func @_QPomp_target_enter_exit(%1 : !llvm.ptr, %3 : !llvm.ptr) {
-  %4 = llvm.mlir.constant(1 : i64) : i64
-  %5 = llvm.alloca %4 x i32 {bindc_name = "dvc", in_type = i32, operandSegmentSizes = array<i32: 0, 0>, uniq_name = "_QFomp_target_enter_exitEdvc"} : (i64) -> !llvm.ptr
-  %6 = llvm.mlir.constant(1 : i64) : i64
-  %7 = llvm.alloca %6 x i32 {bindc_name = "i", in_type = i32, operandSegmentSizes = array<i32: 0, 0>, uniq_name = "_QFomp_target_enter_exitEi"} : (i64) -> !llvm.ptr
-  %8 = llvm.mlir.constant(5 : i32) : i32
-  llvm.store %8, %7 : i32, !llvm.ptr
-  %9 = llvm.mlir.constant(2 : i32) : i32
-  llvm.store %9, %5 : i32, !llvm.ptr
-  %10 = llvm.load %7 : !llvm.ptr -> i32
-  %11 = llvm.mlir.constant(10 : i32) : i32
-  %12 = llvm.icmp "slt" %10, %11 : i32
-  %13 = llvm.load %5 : !llvm.ptr -> i32
-  %14 = llvm.mlir.constant(1023 : index) : i64
-  %15 = llvm.mlir.constant(0 : index) : i64
-  %16 = llvm.mlir.constant(1024 : index) : i64
-  %17 = llvm.mlir.constant(1 : index) : i64
-  %18 = omp.map.bounds   lower_bound(%15 : i64) upper_bound(%14 : i64) extent(%16 : i64) stride(%17 : i64) start_idx(%17 : i64)
-  %map1 = omp.map.info var_ptr(%1 : !llvm.ptr, !llvm.array<1024 x i32>)   map_clauses(to) capture(ByRef) bounds(%18) -> !llvm.ptr {name = ""}
-  %19 = llvm.mlir.constant(511 : index) : i64
-  %20 = llvm.mlir.constant(0 : index) : i64
-  %21 = llvm.mlir.constant(512 : index) : i64
-  %22 = llvm.mlir.constant(1 : index) : i64
-  %23 = omp.map.bounds   lower_bound(%20 : i64) upper_bound(%19 : i64) extent(%21 : i64) stride(%22 : i64) start_idx(%22 : i64)
-  %map2 = omp.map.info var_ptr(%3 : !llvm.ptr, !llvm.array<512 x i32>)   map_clauses(exit_release_or_enter_alloc) capture(ByRef) bounds(%23) -> !llvm.ptr {name = ""}
-  omp.target_enter_data   if(%12) device(%13 : i32) map_entries(%map1, %map2 : !llvm.ptr, !llvm.ptr)
-  %24 = llvm.load %7 : !llvm.ptr -> i32
-  %25 = llvm.mlir.constant(10 : i32) : i32
-  %26 = llvm.icmp "sgt" %24, %25 : i32
-  %27 = llvm.load %5 : !llvm.ptr -> i32
-  %28 = llvm.mlir.constant(1023 : index) : i64
-  %29 = llvm.mlir.constant(0 : index) : i64
-  %30 = llvm.mlir.constant(1024 : index) : i64
-  %31 = llvm.mlir.constant(1 : index) : i64
-  %32 = omp.map.bounds   lower_bound(%29 : i64) upper_bound(%28 : i64) extent(%30 : i64) stride(%31 : i64) start_idx(%31 : i64)
-  %map3 = omp.map.info var_ptr(%1 : !llvm.ptr, !llvm.array<1024 x i32>)   map_clauses(from) capture(ByRef) bounds(%32) -> !llvm.ptr {name = ""}
-  %33 = llvm.mlir.constant(511 : index) : i64
-  %34 = llvm.mlir.constant(0 : index) : i64
-  %35 = llvm.mlir.constant(512 : index) : i64
-  %36 = llvm.mlir.constant(1 : index) : i64
-  %37 = omp.map.bounds   lower_bound(%34 : i64) upper_bound(%33 : i64) extent(%35 : i64) stride(%36 : i64) start_idx(%36 : i64)
-  %map4 = omp.map.info var_ptr(%3 : !llvm.ptr, !llvm.array<512 x i32>)   map_clauses(exit_release_or_enter_alloc) capture(ByRef) bounds(%37) -> !llvm.ptr {name = ""}
-  omp.target_exit_data   if(%26) device(%27 : i32) map_entries(%map3, %map4 : !llvm.ptr, !llvm.ptr)
-  llvm.return
+module attributes {omp.target_triples = ["amdgcn-amd-amdhsa"]} {
+  llvm.func @_QPomp_target_enter_exit(%1 : !llvm.ptr, %3 : !llvm.ptr) {
+    %4 = llvm.mlir.constant(1 : i64) : i64
+    %5 = llvm.alloca %4 x i32 {bindc_name = "dvc", in_type = i32, operandSegmentSizes = array<i32: 0, 0>, uniq_name = "_QFomp_target_enter_exitEdvc"} : (i64) -> !llvm.ptr
+    %6 = llvm.mlir.constant(1 : i64) : i64
+    %7 = llvm.alloca %6 x i32 {bindc_name = "i", in_type = i32, operandSegmentSizes = array<i32: 0, 0>, uniq_name = "_QFomp_target_enter_exitEi"} : (i64) -> !llvm.ptr
+    %8 = llvm.mlir.constant(5 : i32) : i32
+    llvm.store %8, %7 : i32, !llvm.ptr
+    %9 = llvm.mlir.constant(2 : i32) : i32
+    llvm.store %9, %5 : i32, !llvm.ptr
+    %10 = llvm.load %7 : !llvm.ptr -> i32
+    %11 = llvm.mlir.constant(10 : i32) : i32
+    %12 = llvm.icmp "slt" %10, %11 : i32
+    %13 = llvm.load %5 : !llvm.ptr -> i32
+    %14 = llvm.mlir.constant(1023 : index) : i64
+    %15 = llvm.mlir.constant(0 : index) : i64
+    %16 = llvm.mlir.constant(1024 : index) : i64
+    %17 = llvm.mlir.constant(1 : index) : i64
+    %18 = omp.map.bounds   lower_bound(%15 : i64) upper_bound(%14 : i64) extent(%16 : i64) stride(%17 : i64) start_idx(%17 : i64)
+    %map1 = omp.map.info var_ptr(%1 : !llvm.ptr, !llvm.array<1024 x i32>)   map_clauses(to) capture(ByRef) bounds(%18) -> !llvm.ptr {name = ""}
+    %19 = llvm.mlir.constant(511 : index) : i64
+    %20 = llvm.mlir.constant(0 : index) : i64
+    %21 = llvm.mlir.constant(512 : index) : i64
+    %22 = llvm.mlir.constant(1 : index) : i64
+    %23 = omp.map.bounds   lower_bound(%20 : i64) upper_bound(%19 : i64) extent(%21 : i64) stride(%22 : i64) start_idx(%22 : i64)
+    %map2 = omp.map.info var_ptr(%3 : !llvm.ptr, !llvm.array<512 x i32>)   map_clauses(exit_release_or_enter_alloc) capture(ByRef) bounds(%23) -> !llvm.ptr {name = ""}
+    omp.target_enter_data   if(%12) device(%13 : i32) map_entries(%map1, %map2 : !llvm.ptr, !llvm.ptr)
+    %24 = llvm.load %7 : !llvm.ptr -> i32
+    %25 = llvm.mlir.constant(10 : i32) : i32
+    %26 = llvm.icmp "sgt" %24, %25 : i32
+    %27 = llvm.load %5 : !llvm.ptr -> i32
+    %28 = llvm.mlir.constant(1023 : index) : i64
+    %29 = llvm.mlir.constant(0 : index) : i64
+    %30 = llvm.mlir.constant(1024 : index) : i64
+    %31 = llvm.mlir.constant(1 : index) : i64
+    %32 = omp.map.bounds   lower_bound(%29 : i64) upper_bound(%28 : i64) extent(%30 : i64) stride(%31 : i64) start_idx(%31 : i64)
+    %map3 = omp.map.info var_ptr(%1 : !llvm.ptr, !llvm.array<1024 x i32>)   map_clauses(from) capture(ByRef) bounds(%32) -> !llvm.ptr {name = ""}
+    %33 = llvm.mlir.constant(511 : index) : i64
+    %34 = llvm.mlir.constant(0 : index) : i64
+    %35 = llvm.mlir.constant(512 : index) : i64
+    %36 = llvm.mlir.constant(1 : index) : i64
+    %37 = omp.map.bounds   lower_bound(%34 : i64) upper_bound(%33 : i64) extent(%35 : i64) stride(%36 : i64) start_idx(%36 : i64)
+    %map4 = omp.map.info var_ptr(%3 : !llvm.ptr, !llvm.array<512 x i32>)   map_clauses(exit_release_or_enter_alloc) capture(ByRef) bounds(%37) -> !llvm.ptr {name = ""}
+    omp.target_exit_data   if(%26) device(%27 : i32) map_entries(%map3, %map4 : !llvm.ptr, !llvm.ptr)
+    llvm.return
+  }
 }
 
 // CHECK:         @.offload_sizes = private unnamed_addr constant [2 x i64] [i64 4096, i64 2048]
@@ -205,18 +211,20 @@ llvm.func @_QPomp_target_enter_exit(%1 : !llvm.ptr, %3 : !llvm.ptr) {
 
 // -----
 
-llvm.func @_QPopenmp_target_use_dev_ptr() {
-  %0 = llvm.mlir.constant(1 : i64) : i64
-  %a = llvm.alloca %0 x !llvm.ptr : (i64) -> !llvm.ptr
-  %map1 = omp.map.info var_ptr(%a : !llvm.ptr, !llvm.ptr)   map_clauses(from) capture(ByRef) -> !llvm.ptr {name = ""}
-  %map2 = omp.map.info var_ptr(%a : !llvm.ptr, !llvm.ptr)   map_clauses(from) capture(ByRef) -> !llvm.ptr {name = ""}
-  omp.target_data  map_entries(%map1 : !llvm.ptr) use_device_ptr(%map2 -> %arg0 : !llvm.ptr)  {
-    %1 = llvm.mlir.constant(10 : i32) : i32
-    %2 = llvm.load %arg0 : !llvm.ptr -> !llvm.ptr
-    llvm.store %1, %2 : i32, !llvm.ptr
-    omp.terminator
+module attributes {omp.target_triples = ["amdgcn-amd-amdhsa"]} {
+  llvm.func @_QPopenmp_target_use_dev_ptr() {
+    %0 = llvm.mlir.constant(1 : i64) : i64
+    %a = llvm.alloca %0 x !llvm.ptr : (i64) -> !llvm.ptr
+    %map1 = omp.map.info var_ptr(%a : !llvm.ptr, !llvm.ptr)   map_clauses(from) capture(ByRef) -> !llvm.ptr {name = ""}
+    %map2 = omp.map.info var_ptr(%a : !llvm.ptr, !llvm.ptr)   map_clauses(from) capture(ByRef) -> !llvm.ptr {name = ""}
+    omp.target_data  map_entries(%map1 : !llvm.ptr) use_device_ptr(%map2 -> %arg0 : !llvm.ptr)  {
+      %1 = llvm.mlir.constant(10 : i32) : i32
+      %2 = llvm.load %arg0 : !llvm.ptr -> !llvm.ptr
+      llvm.store %1, %2 : i32, !llvm.ptr
+      omp.terminator
+    }
+    llvm.return
   }
-  llvm.return
 }
 
 // CHECK:         @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 8]
@@ -249,18 +257,20 @@ llvm.func @_QPopenmp_target_use_dev_ptr() {
 
 // -----
 
-llvm.func @_QPopenmp_target_use_dev_addr() {
-  %0 = llvm.mlir.constant(1 : i64) : i64
-  %a = llvm.alloca %0 x !llvm.ptr : (i64) -> !llvm.ptr
-  %map = omp.map.info var_ptr(%a : !llvm.ptr, !llvm.ptr)   map_clauses(from) capture(ByRef) -> !llvm.ptr {name = ""}
-  %map2 = omp.map.info var_ptr(%a : !llvm.ptr, !llvm.ptr)   map_clauses(from) capture(ByRef) -> !llvm.ptr {name = ""}
-  omp.target_data  map_entries(%map : !llvm.ptr) use_device_addr(%map2 -> %arg0 : !llvm.ptr)  {
-    %1 = llvm.mlir.constant(10 : i32) : i32
-    %2 = llvm.load %arg0 : !llvm.ptr -> !llvm.ptr
-    llvm.store %1, %2 : i32, !llvm.ptr
-    omp.terminator
+module attributes {omp.target_triples = ["amdgcn-amd-amdhsa"]} {
+  llvm.func @_QPopenmp_target_use_dev_addr() {
+    %0 = llvm.mlir.constant(1 : i64) : i64
+    %a = llvm.alloca %0 x !llvm.ptr : (i64) -> !llvm.ptr
+    %map = omp.map.info var_ptr(%a : !llvm.ptr, !llvm.ptr)   map_clauses(from) capture(ByRef) -> !llvm.ptr {name = ""}
+    %map2 = omp.map.info var_ptr(%a : !llvm.ptr, !llvm.ptr)   map_clauses(from) capture(ByRef) -> !llvm.ptr {name = ""}
+    omp.target_data  map_entries(%map : !llvm.ptr) use_device_addr(%map2 -> %arg0 : !llvm.ptr)  {
+      %1 = llvm.mlir.constant(10 : i32) : i32
+      %2 = llvm.load %arg0 : !llvm.ptr -> !llvm.ptr
+      llvm.store %1, %2 : i32, !llvm.ptr
+      omp.terminator
+    }
+    llvm.return
   }
-  llvm.return
 }
 
 // CHECK:         @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 8]
@@ -291,17 +301,19 @@ llvm.func @_QPopenmp_target_use_dev_addr() {
 
 // -----
 
-llvm.func @_QPopenmp_target_use_dev_addr_no_ptr() {
-  %0 = llvm.mlir.constant(1 : i64) : i64
-  %a = llvm.alloca %0 x i32 : (i64) -> !llvm.ptr
-  %map = omp.map.info var_ptr(%a : !llvm.ptr, i32)   map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
-  %map2 = omp.map.info var_ptr(%a : !llvm.ptr, i32)   map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
-  omp.target_data  map_entries(%map : !llvm.ptr) use_device_addr(%map2 -> %arg0 : !llvm.ptr)  {
-    %1 = llvm.mlir.constant(10 : i32) : i32
-    llvm.store %1, %arg0 : i32, !llvm.ptr
-    omp.terminator
+module attributes {omp.target_triples = ["amdgcn-amd-amdhsa"]} {
+  llvm.func @_QPopenmp_target_use_dev_addr_no_ptr() {
+    %0 = llvm.mlir.constant(1 : i64) : i64
+    %a = llvm.alloca %0 x i32 : (i64) -> !llvm.ptr
+    %map = omp.map.info var_ptr(%a : !llvm.ptr, i32)   map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
+    %map2 = omp.map.info var_ptr(%a : !llvm.ptr, i32)   map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
+    omp.target_data  map_entries(%map : !llvm.ptr) use_device_addr(%map2 -> %arg0 : !llvm.ptr)  {
+      %1 = llvm.mlir.constant(10 : i32) : i32
+      llvm.store %1, %arg0 : i32, !llvm.ptr
+      omp.terminator
+    }
+    llvm.return
   }
-  llvm.return
 }
 
 // CHECK:         @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
@@ -331,23 +343,25 @@ llvm.func @_QPopenmp_target_use_dev_addr_no_ptr() {
 
 // -----
 
-llvm.func @_QPopenmp_target_use_dev_addr_nomap() {
-  %0 = llvm.mlir.constant(1 : i64) : i64
-  %a = llvm.alloca %0 x !llvm.ptr : (i64) -> !llvm.ptr
-  %1 = llvm.mlir.constant(1 : i64) : i64
-  %b = llvm.alloca %0 x !llvm.ptr : (i64) -> !llvm.ptr
-  %map = omp.map.info var_ptr(%b : !llvm.ptr, !llvm.ptr)   map_clauses(from) capture(ByRef) -> !llvm.ptr {name = ""}
-  %map2 = omp.map.info var_ptr(%a : !llvm.ptr, !llvm.ptr)   map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
-  omp.target_data  map_entries(%map : !llvm.ptr) use_device_addr(%map2 -> %arg0 : !llvm.ptr)  {
-    %2 = llvm.mlir.constant(10 : i32) : i32
-    %3 = llvm.load %arg0 : !llvm.ptr -> !llvm.ptr
-    llvm.store %2, %3 : i32, !llvm.ptr
-    %4 = llvm.mlir.constant(20 : i32) : i32
-    %5 = llvm.load %b : !llvm.ptr -> !llvm.ptr
-    llvm.store %4, %5 : i32, !llvm.ptr
-    omp.terminator
+module attributes {omp.target_triples = ["amdgcn-amd-amdhsa"]} {
+  llvm.func @_QPopenmp_target_use_dev_addr_nomap() {
+    %0 = llvm.mlir.constant(1 : i64) : i64
+    %a = llvm.alloca %0 x !llvm.ptr : (i64) -> !llvm.ptr
+    %1 = llvm.mlir.constant(1 : i64) : i64
+    %b = llvm.alloca %0 x !llvm.ptr : (i64) -> !llvm.ptr
+    %map = omp.map.info var_ptr(%b : !llvm.ptr, !llvm.ptr)   map_clauses(from) capture(ByRef) -> !llvm.ptr {name = ""}
+    %map2 = omp.map.info var_ptr(%a : !llvm.ptr, !llvm.ptr)   map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
+    omp.target_data  map_entries(%map : !llvm.ptr) use_device_addr(%map2 -> %arg0 : !llvm.ptr)  {
+      %2 = llvm.mlir.constant(10 : i32) : i32
+      %3 = llvm.load %arg0 : !llvm.ptr -> !llvm.ptr
+      llvm.store %2, %3 : i32, !llvm.ptr
+      %4 = llvm.mlir.constant(20 : i32) : i32
+      %5 = llvm.load %b : !llvm.ptr -> !llvm.ptr
+      llvm.store %4, %5 : i32, !llvm.ptr
+      omp.terminator
+    }
+    llvm.return
   }
-  llvm.return
 }
 
 // CHECK:         @.offload_sizes = private unnamed_addr constant [2 x i64] [i64 8, i64 0]
@@ -387,25 +401,27 @@ llvm.func @_QPopenmp_target_use_dev_addr_nomap() {
 
 // -----
 
-llvm.func @_QPopenmp_target_use_dev_both() {
-  %0 = llvm.mlir.constant(1 : i64) : i64
-  %a = llvm.alloca %0 x !llvm.ptr : (i64) -> !llvm.ptr
-  %1 = llvm.mlir.constant(1 : i64) : i64
-  %b = llvm.alloca %0 x !llvm.ptr : (i64) -> !llvm.ptr
-  %map = omp.map.info var_ptr(%a : !llvm.ptr, !llvm.ptr)   map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
-  %map1...
[truncated]

@kparzysz
Copy link
Contributor Author

In the 3 mlir tests I added a module with an "omp.target_triples" attribute to make sure that the expected code is still generated.

Copy link
Member

@skatrak skatrak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Krzysztof!

When no offload targets are specified flang will ignore "target" constructs, but not "target data" constructs.

To point something out, this is not exactly what happens. Host implementations of target constructs will still be produced regardless of whether offload targets were specified. The difference when they aren't is that no kernel launches (i.e. __tgt_target_kernel plus kernel argument structure setup) are produced in the host, but rather host fallback code is branched to directly.

Having said that, I can't imagine why we would need to keep "target data"-related runtime calls when there's no offloading target, so the approach sounds good to me. Maybe it would be good for someone more familiar with current map support to confirm the removal of __tgt_target_data_{begin,end}_mapper is fine when running only on the host (CC: @agozillon, @TIFitis).

Comment on lines 4408 to 4409
if (!isOffloadEntry)
return success();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think it would be more readable if we checked this condition and exited early before this TypeSwitch, rather than checking on each case and then later after it was executed.

Also, shouldn't we still process the body of omp.target_data? That code still should run on the host, AFAIU.

if (!isOffloadEntry && !isa<omp::TargetDataOp>(op))
  return success();

LogicalResult result = llvm::TypeSwitch...;

if (failed(result))
  return failure();

using InsertPointTy = ...

@kparzysz
Copy link
Contributor Author

but rather host fallback code is branched to directly.

Well... That was the intent here. I dug up an old patch I had, so it's possible that something is missing. I'll take a closer look at it.

@kparzysz kparzysz changed the title [flang][OpenMP] Ignore target-data operations with no offload targets [flang][OpenMP] Skip runtime mapping with no offload targets Jun 18, 2025
@kparzysz
Copy link
Contributor Author

Ping. I have updated the PR with generating the body of the construct.

Copy link
Member

@skatrak skatrak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Krzysztof, I still have some comments on implementation details, but I won't block this if you have a strong opinion against them. LGTM!

Comment on lines 4479 to 4482
if (!isOffloadEntry) {
// Pretend we have IF(false) if we're not doing offload.
ifCond = builder.getFalse();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just reduce the changes to this? At the moment, the isOffloadEntry condition is checked in multiple places, which adds complexity, but overriding the if condition would be enough to get the wanted behavior (let me know if I'm missing anything there). In my opinion, overhead shouldn't be a concern, since the early returns above only skip a few constant time cheap operations.

If overhead is still a concern for you, I think the other suggestion I made would achieve that while keeping this logic contained and make things easier to follow.

Suggested change
if (!isOffloadEntry) {
// Pretend we have IF(false) if we're not doing offload.
ifCond = builder.getFalse();
}
// Pretend we have IF(false) if we're not doing offload.
if (!isOffloadEntry)
ifCond = builder.getFalse();

@kparzysz kparzysz merged commit 349f8d6 into llvm:main Jun 20, 2025
7 checks passed
@kparzysz kparzysz deleted the user/kparzysz/ignore-target-data branch June 20, 2025 13:09
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 20, 2025

LLVM Buildbot has detected a new failure on builder ppc64le-flang-rhel-clang running on ppc64le-flang-rhel-test while building flang,mlir at step 6 "test-build-unified-tree-check-flang".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/157/builds/31331

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-flang) failure: test (failure)
******************** TEST 'Flang :: Lower/ignore-target-data.f90' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/flang -fc1 -emit-llvm -fopenmp /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Lower/ignore-target-data.f90 -o - | /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/FileCheck /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Lower/ignore-target-data.f90 --check-prefix=NORT # RUN: at line 1
+ /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/FileCheck /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Lower/ignore-target-data.f90 --check-prefix=NORT
+ /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/flang -fc1 -emit-llvm -fopenmp /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Lower/ignore-target-data.f90 -o -
/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/flang -fc1 -emit-llvm -fopenmp /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Lower/ignore-target-data.f90 -o - | /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/FileCheck /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Lower/ignore-target-data.f90 --check-prefix=LLVM # RUN: at line 2
+ /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/flang -fc1 -emit-llvm -fopenmp /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Lower/ignore-target-data.f90 -o -
+ /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/bin/FileCheck /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Lower/ignore-target-data.f90 --check-prefix=LLVM
/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Lower/ignore-target-data.f90:9:8: error: LLVM: expected string not found in input
!LLVM: define internal void @_QFPf(ptr %[[A0:[0-9]+]], ptr %[[A1:[0-9]+]]) {
       ^
<stdin>:1:1: note: scanning from here
; ModuleID = 'FIRModule'
^
<stdin>:18:1: note: possible intended match here
define internal void @_QFPf(ptr %0, ptr %1) #0 {
^

Input file: <stdin>
Check file: /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Lower/ignore-target-data.f90

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           1: ; ModuleID = 'FIRModule' 
check:9'0     X~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
           2: source_filename = "FIRModule" 
check:9'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           3: target datalayout = "e-m:e-Fn32-i64:64-i128:128-n32:64-S128-v256:256:256-v512:512:512" 
check:9'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           4: target triple = "powerpc64le-unknown-linux-gnu" 
check:9'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           5:  
check:9'0     ~
           6: @0 = private unnamed_addr constant [167 x i8] c";/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/test/Lower/ignore-target-data.f90;x;25;14;;\00", align 1 
check:9'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           .
           .
           .
          13:  store i32 2, ptr %2, align 4 
check:9'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          14:  call void @_QFPf(ptr %1, ptr %2) 
check:9'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          15:  ret void 
check:9'0     ~~~~~~~~~~
          16: } 
...

@kparzysz
Copy link
Contributor Author

6ba1955 should fix this.

@antmox
Copy link
Contributor

antmox commented Jun 23, 2025

Hi @kparzysz,

Could this be the cause of these buildbot failures ?

#0 0x0000c042cabcb9e0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0x700b9e0)
#1 0x0000c042cabc9894 llvm::sys::RunSignalHandlers() (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0x7009894)
#2 0x0000c042cabcc0dc SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x0000f7ce5330a8f8 (linux-vdso.so.1+0x8f8)
#4 0x0000f7ce52ccf1f0 __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x0000f7ce52c8a67c gsignal ./signal/../sysdeps/posix/raise.c:27:6
#6 0x0000f7ce52c77130 abort ./stdlib/abort.c:81:7
#7 0x0000f7ce52c83fd4 __assert_fail_base ./assert/assert.c:91:7
#8 0x0000f7ce52c8404c (/lib/aarch64-linux-gnu/libc.so.6+0x3404c)
#9 0x0000c042cf8e4270 llvm::TargetFolder::FoldGEP(llvm::Type*, llvm::Value*, llvm::ArrayRefllvm::Value*, llvm::GEPNoWrapFlags) const ConstantFolding.cpp:0:0
#10 0x0000c042c93bd8ec llvm::IRBuilderBase::CreateGEP(llvm::Type*, llvm::Value*, llvm::ArrayRefllvm::Value*, llvm::Twine const&, llvm::GEPNoWrapFlags) AArch64ISelLowering.cpp:0:0
#11 0x0000c042ccb537d4 convertOperationImpl(mlir::Operation&, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) LLVMToLLVMIRTranslation.cpp:0:0
#12 0x0000c042ce32b084 mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&, bool) (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0xa76b084)
#13 0x0000c042ce32bba4 mlir::LLVM::ModuleTranslation::convertBlockImpl(mlir::Block&, bool, llvm::IRBuilderBase&, bool) (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0xa76bba4)
#14 0x0000c042cc8f0ef0 inlineConvertOmpRegions(mlir::Region&, llvm::StringRef, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&, llvm::SmallVectorImplllvm::Value*) OpenMPToLLVMIRTranslation.cpp:0:0
#15 0x0000c042cc8f3788 llvm::Expectedllvm::IRBuilderBase::InsertPoint llvm::function_ref<llvm::Expectedllvm::IRBuilderBase::InsertPoint (llvm::IRBuilderBase::InsertPoint, llvm::OpenMPIRBuilder::BodyGenTy)>::callback_fn<convertOmpTargetData(mlir::Operation
, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&)::$_5>(long, llvm::IRBuilderBase::InsertPoint, llvm::OpenMPIRBuilder::BodyGenTy) OpenMPToLLVMIRTranslation.cpp:0:0
#16 0x0000c042cf213350 llvm::OpenMPIRBuilder::createTargetData(llvm::OpenMPIRBuilder::LocationDescription const&, llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint, llvm::Value*, llvm::Value*, llvm::OpenMPIRBuilder::TargetDataInfo&, llvm::function_ref<llvm::OpenMPIRBuilder::MapInfosTy& (llvm::IRBuilderBase::InsertPoint)>, llvm::function_ref<llvm::Expectedllvm::Function* (unsigned int)>, llvm::omp::RuntimeFunction*, llvm::function_ref<llvm::Expectedllvm::IRBuilderBase::InsertPoint (llvm::IRBuilderBase::InsertPoint, llvm::OpenMPIRBuilder::BodyGenTy)>, llvm::function_ref<void (unsigned int, llvm::Value*)>, llvm::Value*) (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0xb653350)
#17 0x0000c042cc8e168c convertOmpTargetData(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) OpenMPToLLVMIRTranslation.cpp:0:0
#18 0x0000c042cc8db950 convertHostOrTargetOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) OpenMPToLLVMIRTranslation.cpp:0:0
#19 0x0000c042ce32b084 mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&, bool) (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0xa76b084)
#20 0x0000c042ce32bba4 mlir::LLVM::ModuleTranslation::convertBlockImpl(mlir::Block&, bool, llvm::IRBuilderBase&, bool) (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0xa76bba4)
#21 0x0000c042cc8f0ef0 inlineConvertOmpRegions(mlir::Region&, llvm::StringRef, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&, llvm::SmallVectorImplllvm::Value*) OpenMPToLLVMIRTranslation.cpp:0:0
#22 0x0000c042cc8f3788 llvm::Expectedllvm::IRBuilderBase::InsertPoint llvm::function_ref<llvm::Expectedllvm::IRBuilderBase::InsertPoint (llvm::IRBuilderBase::InsertPoint, llvm::OpenMPIRBuilder::BodyGenTy)>::callback_fn<convertOmpTargetData(mlir::Operation
, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&)::$_5>(long, llvm::IRBuilderBase::InsertPoint, llvm::OpenMPIRBuilder::BodyGenTy) OpenMPToLLVMIRTranslation.cpp:0:0
#23 0x0000c042cf213350 llvm::OpenMPIRBuilder::createTargetData(llvm::OpenMPIRBuilder::LocationDescription const&, llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint, llvm::Value*, llvm::Value*, llvm::OpenMPIRBuilder::TargetDataInfo&, llvm::function_ref<llvm::OpenMPIRBuilder::MapInfosTy& (llvm::IRBuilderBase::InsertPoint)>, llvm::function_ref<llvm::Expectedllvm::Function* (unsigned int)>, llvm::omp::RuntimeFunction*, llvm::function_ref<llvm::Expectedllvm::IRBuilderBase::InsertPoint (llvm::IRBuilderBase::InsertPoint, llvm::OpenMPIRBuilder::BodyGenTy)>, llvm::function_ref<void (unsigned int, llvm::Value*)>, llvm::Value*) (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0xb653350)
#24 0x0000c042cc8e168c convertOmpTargetData(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) OpenMPToLLVMIRTranslation.cpp:0:0
#25 0x0000c042cc8db950 convertHostOrTargetOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) OpenMPToLLVMIRTranslation.cpp:0:0
#26 0x0000c042ce32b084 mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&, bool) (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0xa76b084)
#27 0x0000c042ce32bba4 mlir::LLVM::ModuleTranslation::convertBlockImpl(mlir::Block&, bool, llvm::IRBuilderBase&, bool) (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0xa76bba4)
#28 0x0000c042ce32fd38 mlir::LLVM::ModuleTranslation::convertOneFunction(mlir::LLVM::LLVMFuncOp) (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0xa76fd38)
#29 0x0000c042ce332288 mlir::LLVM::ModuleTranslation::convertFunctions() (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0xa772288)
#30 0x0000c042ce334e90 mlir::translateModuleToLLVMIR(mlir::Operation*, llvm::LLVMContext&, llvm::StringRef, bool) (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0xa774e90)
#31 0x0000c042cac1b728 Fortran::frontend::CodeGenAction::generateLLVMIR() (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0x705b728)
#32 0x0000c042cac1f094 Fortran::frontend::CodeGenAction::executeAction() (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0x705f094)
#33 0x0000c042cac1223c Fortran::frontend::FrontendAction::execute() (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0x705223c)
#34 0x0000c042cabfc914 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0x703c914)
#35 0x0000c042cac16830 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0x7056830)
#36 0x0000c042c930dea8 fc1_main(llvm::ArrayRef<char const*>, char const*) (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0x574dea8)
#37 0x0000c042c930cd38 main (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0x574cd38)
#38 0x0000f7ce52c773fc __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#39 0x0000f7ce52c774cc call_init ./csu/../csu/libc-start.c:128:20
#40 0x0000f7ce52c774cc __libc_start_main ./csu/../csu/libc-start.c:379:5
#41 0x0000c042c930bdf0 _start (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1.install/bin/flang+0x574bdf0)

@kparzysz
Copy link
Contributor Author

All of these seem to fail with the stage 2 compiler. I'll try to reproduce this locally.

@antmox
Copy link
Contributor

antmox commented Jun 23, 2025

it also fails on stage1
looks related to ifCond = builder.getFalse();

flang: llvmws/repro/llvm/llvm/include/llvm/Support/Casting.h:662: decltype(auto) llvm::dyn_cast(From*) [with To = llvm::Constant; From = llvm::Value]: Assertion `detail
::isPresent(Val) && "dyn_cast on a non-existent value"' failed.

@antmox
Copy link
Contributor

antmox commented Jun 24, 2025

Hi @kparzysz
Any news about this ? 7 bots have been failing for more than 3 days here.
If more time is needed to fix the issue, let's revert the patch in the meantime

antmox added a commit that referenced this pull request Jun 24, 2025
…144534)" (#145478)

And also revert 6ba1955 "[flang][OpenMP] Fix ignore-target-data.f90 test"

As it causes several bot failures
#144534 (comment)
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jun 24, 2025
…ad targets (#144534)" (#145478)

And also revert 6ba1955 "[flang][OpenMP] Fix ignore-target-data.f90 test"

As it causes several bot failures
llvm/llvm-project#144534 (comment)
@kparzysz
Copy link
Contributor Author

I tried compiling the failing file from gfortran test suite, but I couldn't get it to fail. I used flang compiled with gcc, clang, and clang+asan.

Did it fail for you with the gfortran tests using stage 1?

@antmox
Copy link
Contributor

antmox commented Jun 24, 2025

on my side, I compiled flang with clang-18.1.8, configured with the following flags:
-DLLVM_TARGETS_TO_BUILD=AArch64
-DLLVM_INSTALL_UTILS=ON
-DCMAKE_CXX_STANDARD=17
-DLLVM_ENABLE_WERROR=OFF
-DFLANG_ENABLE_WERROR=ON
-DBUILD_SHARED_LIBS=ON
-DLLVM_ENABLE_ASSERTIONS=ON
-DLLVM_ENABLE_LIBCXX=On
-DCMAKE_BUILD_TYPE=Release
'-DLLVM_ENABLE_PROJECTS=llvm;clang;mlir;flang'
-DLLVM_ENABLE_RUNTIMES=flang-rt
'-DLLVM_LIT_ARGS=-v -vv'
and I confirm that it failed with flang from stage1

DrSergei pushed a commit to DrSergei/llvm-project that referenced this pull request Jun 24, 2025
…lvm#144534)" (llvm#145478)

And also revert 6ba1955 "[flang][OpenMP] Fix ignore-target-data.f90 test"

As it causes several bot failures
llvm#144534 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants