Skip to content

Commit e4dfa92

Browse files
authored
1 parent 3448740 commit e4dfa92

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

include/LLVMSPIRVExtensions.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ EXT(SPV_KHR_bit_instructions)
1313
EXT(SPV_KHR_uniform_group_instructions)
1414
EXT(SPV_KHR_subgroup_rotate)
1515
EXT(SPV_KHR_non_semantic_info)
16+
EXT(SPV_KHR_shader_clock)
1617
EXT(SPV_INTEL_subgroups)
1718
EXT(SPV_INTEL_media_block_io)
1819
EXT(SPV_INTEL_device_side_avc_motion_estimation)

lib/SPIRV/libSPIRV/SPIRVInstruction.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3678,6 +3678,42 @@ class SPIRVTensorFloat32RoundingINTELInstBase : public SPIRVUnaryInst<OC> {
36783678
typedef SPIRVTensorFloat32RoundingINTELInstBase<internal::Op##x> SPIRV##x;
36793679
_SPIRV_OP(RoundFToTF32INTEL)
36803680
#undef _SPIRV_OP
3681-
} // namespace SPIRV
36823681

3682+
template <Op OC> class SPIRVReadClockKHRInstBase : public SPIRVUnaryInst<OC> {
3683+
protected:
3684+
SPIRVCapVec getRequiredCapability() const override {
3685+
return getVec(CapabilityShaderClockKHR);
3686+
}
3687+
3688+
std::optional<ExtensionID> getRequiredExtension() const override {
3689+
return ExtensionID::SPV_KHR_shader_clock;
3690+
}
3691+
3692+
void validate() const override {
3693+
SPIRVUnaryInst<OC>::validate();
3694+
3695+
SPIRVType *ResCompTy = this->getType();
3696+
SPIRVWord ResCompCount = 1;
3697+
if (ResCompTy->isTypeVector()) {
3698+
ResCompCount = ResCompTy->getVectorComponentCount();
3699+
ResCompTy = ResCompTy->getVectorComponentType();
3700+
}
3701+
auto InstName = OpCodeNameMap::map(OC);
3702+
SPIRVErrorLog &SPVErrLog = this->getModule()->getErrorLog();
3703+
3704+
// check for either 64 bit int type or two element vector of 32 bit int
3705+
// types.
3706+
SPVErrLog.checkError(
3707+
ResCompTy->isTypeInt(64) ||
3708+
(ResCompCount == 2 && ResCompTy->isTypeInt(32)),
3709+
SPIRVEC_InvalidInstruction,
3710+
InstName + "\nResult value must be a scalar of integer"
3711+
" 64-bit type or two element vector of 32-bit type\n");
3712+
}
3713+
};
3714+
#define _SPIRV_OP(x, ...) typedef SPIRVReadClockKHRInstBase<Op##x> SPIRV##x;
3715+
_SPIRV_OP(ReadClockKHR)
3716+
#undef _SPIRV_OP
3717+
3718+
} // namespace SPIRV
36833719
#endif // SPIRV_LIBSPIRV_SPIRVINSTRUCTION_H

lib/SPIRV/libSPIRV/SPIRVOpCodeEnum.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ _SPIRV_OP(SUDotKHR, 4452)
335335
_SPIRV_OP(SDotAccSatKHR, 4453)
336336
_SPIRV_OP(UDotAccSatKHR, 4454)
337337
_SPIRV_OP(SUDotAccSatKHR, 4455)
338+
_SPIRV_OP(ReadClockKHR, 5056)
338339
_SPIRV_OP(SubgroupShuffleINTEL, 5571)
339340
_SPIRV_OP(SubgroupShuffleDownINTEL, 5572)
340341
_SPIRV_OP(SubgroupShuffleUpINTEL, 5573)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv --spirv-ext=+SPV_KHR_shader_clock
3+
; RUN: llvm-spirv %t.spv -o %t.spt --to-text
4+
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
5+
; RUN: llvm-spirv %t.spv -o %t.rev.bc -r -emit-opaque-pointers --spirv-target-env=SPV-IR
6+
; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
7+
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
8+
9+
; RUN: not llvm-spirv %t.bc 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
10+
; CHECK-ERROR: RequiresExtension: Feature requires the following SPIR-V extension:
11+
; CHECK-ERROR-NEXT: SPV_KHR_shader_clock
12+
13+
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"
14+
target triple = "spir64-unknown-unknown"
15+
16+
; CHECK-SPIRV: Capability ShaderClockKHR
17+
; CHECK-SPIRV: Extension "SPV_KHR_shader_clock"
18+
; CHECK-SPIRV: TypeInt [[#I32Ty:]] 32
19+
; CHECK-SPIRV: TypeInt [[#I64Ty:]] 64
20+
; CHECK-SPIRV: TypeVector [[#I32v2Ty:]] [[#I32Ty]] 2
21+
22+
; CHECK-SPIRV: FunctionParameter [[#I32Ty]] [[I32ValId:.*]]
23+
24+
; CHECK-SPIRV: ReadClockKHR [[#I32v2Ty]] [[#]] [[I32ValId]]
25+
; CHECK-SPIRV: ReadClockKHR [[#I64Ty]] [[#]] [[I32ValId]]
26+
27+
; CHECK-LLVM: call spir_func <2 x i32> @_Z20__spirv_ReadClockKHR
28+
; CHECK-LLVM: call spir_func i64 @_Z20__spirv_ReadClockKHR
29+
30+
define spir_func void @_Z7read_types(i32 %a) {
31+
%1 = tail call spir_func <2 x i32> @_Z20__spirv_ReadClockKHRIDv2_jET_j(i32 %a)
32+
%2 = tail call spir_func i64 @_Z20__spirv_ReadClockKHRImET_j(i32 %a)
33+
ret void
34+
}
35+
36+
declare spir_func <2 x i32> @_Z20__spirv_ReadClockKHRIDv2_jET_j(i32)
37+
38+
declare spir_func i64 @_Z20__spirv_ReadClockKHRImET_j(i32)
39+
40+
!opencl.spir.version = !{!0}
41+
!spirv.Source = !{!1}
42+
!llvm.ident = !{!2}
43+
44+
!0 = !{i32 1, i32 2}
45+
!1 = !{i32 4, i32 100000}
46+
!2 = !{!"clang version 16.0.0"}

0 commit comments

Comments
 (0)