forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OMPIRBuilder] Improve 'target if' implementation (#222)
This patch cleans up support for the 'if' clause on 'target' directives by reusing the existing `emitIfClause()` function rather than duplicating code. One side effect of this change is that constant 'if' values will no longer result in the generation of branches. Instead, code is generated only for the applicable case. It also adds a unit test to ensure it works as expected.
- Loading branch information
Showing
2 changed files
with
67 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// RUN: mlir-translate -mlir-to-llvmir %s 2>&1 | FileCheck %s | ||
|
||
// Set a dummy target triple to enable target region outlining. | ||
module attributes {omp.target_triples = ["amdgcn-amd-amdhsa"]} { | ||
llvm.func @foo(%0 : i1) { | ||
omp.target if(%0) { | ||
omp.terminator | ||
} | ||
llvm.return | ||
} | ||
|
||
// CHECK: define void @foo(i1 %[[COND:.*]]) { | ||
|
||
// CHECK: br i1 %[[COND]], label %[[THEN_LABEL:.*]], label %[[ELSE_LABEL:.*]] | ||
|
||
// CHECK: [[THEN_LABEL]]: | ||
// CHECK: %[[RES:.*]] = call i32 @__tgt_target_kernel({{.*}}) | ||
// CHECK-NEXT: %[[OFFLOAD_CHECK:.*]] = icmp ne i32 %[[RES]], 0 | ||
// CHECK-NEXT: br i1 %[[OFFLOAD_CHECK]], label %[[OFF_FAIL_LABEL:.*]], label %[[OFF_SUCC_LABEL:.*]] | ||
|
||
// CHECK: [[OFF_FAIL_LABEL]]: | ||
// CHECK-NEXT: call void @[[FALLBACK_FN:.*]]() | ||
// CHECK-NEXT: br label %[[OFF_CONT_LABEL:.*]] | ||
|
||
// CHECK: [[OFF_CONT_LABEL]]: | ||
// CHECK-NEXT: br label %[[END_LABEL:.*]] | ||
|
||
// CHECK: [[ELSE_LABEL]]: | ||
// CHECK-NEXT: call void @[[FALLBACK_FN]]() | ||
// CHECK-NEXT: br label %[[END_LABEL]] | ||
|
||
// CHECK: [[END_LABEL]]: | ||
// CHECK-NEXT: ret void | ||
} |