Skip to content

Commit af3c470

Browse files
changpengrampitec
authored andcommitted
AMDGPU: support s_monitor_sleep on gfx1250 (llvm#146293)
Co-Authored-by: Stanislav Mekhanoshin <[email protected]>
1 parent 085e99c commit af3c470

File tree

8 files changed

+76
-0
lines changed

8 files changed

+76
-0
lines changed

clang/include/clang/Basic/BuiltinsAMDGPU.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ TARGET_BUILTIN(__builtin_amdgcn_ds_load_tr16_b128_v8f16, "V8hV8h*3", "nc", "gfx1
654654
TARGET_BUILTIN(__builtin_amdgcn_ds_load_tr16_b128_v8bf16, "V8yV8y*3", "nc", "gfx1250-insts,wavefrontsize32")
655655

656656
TARGET_BUILTIN(__builtin_amdgcn_s_setprio_inc_wg, "vIs", "n", "setprio-inc-wg-inst")
657+
TARGET_BUILTIN(__builtin_amdgcn_s_monitor_sleep, "vIs", "n", "gfx1250-insts")
657658

658659
TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f16_fp8, "V2hs", "nc", "gfx1250-insts")
659660
TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_f16_bf8, "V2hs", "nc", "gfx1250-insts")

clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ void test_setprio_inc_wg() {
1515
__builtin_amdgcn_s_setprio_inc_wg(10);
1616
}
1717

18+
// CHECK-LABEL: @test_s_monitor_sleep(
19+
// CHECK-NEXT: entry:
20+
// CHECK-NEXT: call void @llvm.amdgcn.s.monitor.sleep(i16 10)
21+
// CHECK-NEXT: ret void
22+
//
23+
void test_s_monitor_sleep() {
24+
__builtin_amdgcn_s_monitor_sleep(10);
25+
}
26+
1827
// CHECK-LABEL: @test_cvt_pk_f16_fp8(
1928
// CHECK-NEXT: entry:
2029
// CHECK-NEXT: [[OUT_ADDR:%.*]] = alloca ptr addrspace(1), align 8, addrspace(5)

clang/test/SemaOpenCL/builtins-amdgcn-error-gfx1250-param.cl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
void test_setprio_inc_wg(short a) {
55
__builtin_amdgcn_s_setprio_inc_wg(a); // expected-error {{'__builtin_amdgcn_s_setprio_inc_wg' must be a constant integer}}
66
}
7+
8+
void test_s_monitor_sleep(short a) {
9+
__builtin_amdgcn_s_monitor_sleep(a); // expected-error {{'__builtin_amdgcn_s_monitor_sleep' must be a constant integer}}
10+
}

llvm/include/llvm/IR/IntrinsicsAMDGPU.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3500,6 +3500,15 @@ def int_amdgcn_ashr_pk_u8_i32 : ClangBuiltin<"__builtin_amdgcn_ashr_pk_u8_i32">,
35003500
DefaultAttrsIntrinsic<[llvm_i16_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
35013501
[IntrNoMem, IntrSpeculatable]>;
35023502

3503+
//===----------------------------------------------------------------------===//
3504+
// gfx1250 intrinsics
3505+
// ===----------------------------------------------------------------------===//
3506+
3507+
def int_amdgcn_s_monitor_sleep :
3508+
ClangBuiltin<"__builtin_amdgcn_s_monitor_sleep">,
3509+
DefaultAttrsIntrinsic<[], [llvm_i16_ty], [ImmArg<ArgIndex<0>>, IntrNoMem,
3510+
IntrHasSideEffects]>;
3511+
35033512
//===----------------------------------------------------------------------===//
35043513
// Special Intrinsics for backend internal use only. No frontend
35053514
// should emit calls to these.

llvm/lib/Target/AMDGPU/SOPInstructions.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,12 @@ def S_SET_GPR_IDX_OFF : SOPP_Pseudo<"s_set_gpr_idx_off", (ins) > {
16801680
let Uses = [MODE];
16811681
}
16821682
}
1683+
1684+
def S_MONITOR_SLEEP : SOPP_Pseudo <"s_monitor_sleep", (ins i16imm:$simm16), "$simm16",
1685+
[(int_amdgcn_s_monitor_sleep timm:$simm16)]> {
1686+
let SubtargetPredicate = isGFX1250Plus;
1687+
}
1688+
16831689
} // End hasSideEffects
16841690

16851691
let SubtargetPredicate = HasVGPRIndexMode in {
@@ -2692,6 +2698,12 @@ defm S_ICACHE_INV : SOPP_Real_32_gfx11_gfx12<0x03c>;
26922698

26932699
defm S_BARRIER : SOPP_Real_32_gfx11<0x03d>;
26942700

2701+
//===----------------------------------------------------------------------===//
2702+
// SOPP - GFX1250.
2703+
//===----------------------------------------------------------------------===//
2704+
2705+
defm S_MONITOR_SLEEP : SOPP_Real_32_gfx12<0x004>;
2706+
26952707
//===----------------------------------------------------------------------===//
26962708
// SOPP - GFX6, GFX7, GFX8, GFX9, GFX10
26972709
//===----------------------------------------------------------------------===//
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -global-isel=0 -mtriple=amdgcn -mcpu=gfx1250 < %s | FileCheck --check-prefix=GCN %s
2+
; RUN: llc -global-isel=1 -mtriple=amdgcn -mcpu=gfx1250 < %s | FileCheck --check-prefix=GCN %s
3+
4+
declare void @llvm.amdgcn.s.monitor.sleep(i16)
5+
6+
; GCN-LABEL: {{^}}test_monitor_sleep_1:
7+
; GCN: s_monitor_sleep 1
8+
define amdgpu_ps void @test_monitor_sleep_1() {
9+
call void @llvm.amdgcn.s.monitor.sleep(i16 1)
10+
ret void
11+
}
12+
13+
; FIXME: 0x8000 would look better
14+
15+
; GCN-LABEL: {{^}}test_monitor_sleep_forever:
16+
; GCN: s_monitor_sleep 0xffff8000
17+
define amdgpu_ps void @test_monitor_sleep_forever() {
18+
call void @llvm.amdgcn.s.monitor.sleep(i16 32768)
19+
ret void
20+
}

llvm/test/MC/AMDGPU/gfx1250_asm_sopp.s

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ s_wait_xcnt 0xf
1616
s_setprio_inc_wg 100
1717
// GFX1250: [0x64,0x00,0xbe,0xbf]
1818
// GFX12-ERR: :[[@LINE-2]]:{{[0-9]+}}: error: instruction not supported on this GPU
19+
20+
s_monitor_sleep 1
21+
// GFX1250: s_monitor_sleep 1 ; encoding: [0x01,0x00,0x84,0xbf]
22+
// GFX12-ERR: :[[@LINE-2]]:{{[0-9]+}}: error: instruction not supported on this GPU
23+
24+
s_monitor_sleep 32768
25+
// GFX1250: s_monitor_sleep 0x8000 ; encoding: [0x00,0x80,0x84,0xbf]
26+
// GFX12-ERR: :[[@LINE-2]]:{{[0-9]+}}: error: instruction not supported on this GPU
27+
28+
s_monitor_sleep 0
29+
// GFX1250: s_monitor_sleep 0 ; encoding: [0x00,0x00,0x84,0xbf]
30+
// GFX12-ERR: :[[@LINE-2]]:{{[0-9]+}}: error: instruction not supported on this GPU

llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_sopp.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@
1111

1212
# GFX1250: s_setprio_inc_wg 0x64 ; encoding: [0x64,0x00,0xbe,0xbf]
1313
0x64,0x00,0xbe,0xbf
14+
15+
# GFX1250: s_monitor_sleep 0 ; encoding: [0x00,0x00,0x84,0xbf]
16+
0x00,0x00,0x84,0xbf
17+
18+
# GFX1250: s_monitor_sleep 0x8000 ; encoding: [0x00,0x80,0x84,0xbf]
19+
0x00,0x80,0x84,0xbf
20+
21+
# GFX1250: s_monitor_sleep 1 ; encoding: [0x01,0x00,0x84,0xbf]
22+
0x01,0x00,0x84,0xbf

0 commit comments

Comments
 (0)