Skip to content

Commit 25d6ead

Browse files
committed
- Support for extension SPV_INTEL_latency_control.
- Added a new test case for the extension SPV_INTEL_latency_control
1 parent 4ff98fd commit 25d6ead

File tree

5 files changed

+85
-10
lines changed

5 files changed

+85
-10
lines changed

llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ static const std::map<std::string, SPIRV::Extension::Extension, std::less<>>
9797
SPIRV::Extension::Extension::
9898
SPV_INTEL_subgroup_matrix_multiply_accumulate},
9999
{"SPV_INTEL_ternary_bitwise_function",
100-
SPIRV::Extension::Extension::SPV_INTEL_ternary_bitwise_function}};
100+
SPIRV::Extension::Extension::SPV_INTEL_ternary_bitwise_function},
101+
{"SPV_INTEL_fpga_latency_control",
102+
SPIRV::Extension::Extension::SPV_INTEL_fpga_latency_control}};
101103

102104
bool SPIRVExtensionsParser::parse(cl::Option &O, StringRef ArgName,
103105
StringRef ArgValue,

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,10 @@ static void addOpDecorateReqs(const MachineInstr &MI, unsigned DecIndex,
920920
} else if (Dec == SPIRV::Decoration::FPMaxErrorDecorationINTEL) {
921921
Reqs.addRequirements(SPIRV::Capability::FPMaxErrorINTEL);
922922
Reqs.addExtension(SPIRV::Extension::SPV_INTEL_fp_max_error);
923+
} else if (Dec == SPIRV::Decoration::LatencyControlConstraintINTEL ||
924+
Dec == SPIRV::Decoration::LatencyControlLabelINTEL) {
925+
Reqs.addRequirements(SPIRV::Capability::FPGALatencyControlINTEL);
926+
Reqs.addExtension(SPIRV::Extension::SPV_INTEL_fpga_latency_control);
923927
}
924928
}
925929

llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,23 @@ static SmallVector<Metadata *> parseAnnotation(Value *I,
212212
if (Item.length() == 0)
213213
break;
214214
if (Item[0] == '"') {
215-
Item = Item.substr(1, Item.length() - 2);
216-
// Acceptable format of the string snippet is:
217-
static const std::regex RStr("^(\\d+)(?:,(\\d+))*$");
218-
if (std::smatch MatchStr; std::regex_match(Item, MatchStr, RStr)) {
219-
for (std::size_t SubIdx = 1; SubIdx < MatchStr.size(); ++SubIdx)
220-
if (std::string SubStr = MatchStr[SubIdx].str(); SubStr.length())
221-
MDsItem.push_back(ConstantAsMetadata::get(
222-
ConstantInt::get(Int32Ty, std::stoi(SubStr))));
223-
} else {
215+
Item = Item.substr(1, Item.length() - 2); // Remove surrounding quotes
216+
217+
// Use regex iterator to capture all numbers
218+
static const std::regex NumberRegex("\\d+");
219+
std::sregex_token_iterator It(Item.begin(), Item.end(), NumberRegex);
220+
std::sregex_token_iterator End;
221+
222+
bool FoundNumber = false;
223+
while (It != End) {
224+
MDsItem.push_back(ConstantAsMetadata::get(
225+
ConstantInt::get(Int32Ty, std::stoi(*It))));
226+
++It;
227+
FoundNumber = true;
228+
}
229+
230+
// If no numbers were found, treat it as a regular string
231+
if (!FoundNumber) {
224232
MDsItem.push_back(MDString::get(Ctx, Item));
225233
}
226234
} else if (int32_t Num; llvm::to_integer(StringRef(Item), Num, 10)) {

llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ defm MemoryAccessAliasingINTEL : CapabilityOperand<5910, 0, 0, [SPV_INTEL_memory
517517
defm FPMaxErrorINTEL : CapabilityOperand<6169, 0, 0, [SPV_INTEL_fp_max_error], []>;
518518
defm TernaryBitwiseFunctionINTEL : CapabilityOperand<6241, 0, 0, [SPV_INTEL_ternary_bitwise_function], []>;
519519
defm SubgroupMatrixMultiplyAccumulateINTEL : CapabilityOperand<6236, 0, 0, [SPV_INTEL_subgroup_matrix_multiply_accumulate], []>;
520+
defm FPGALatencyControlINTEL : CapabilityOperand<6171, 0, 0, [SPV_INTEL_fpga_latency_control], []>;
520521

521522
//===----------------------------------------------------------------------===//
522523
// Multiclass used to define SourceLanguage enum values and at the same time
@@ -1268,6 +1269,8 @@ defm FunctionFloatingPointModeINTEL : DecorationOperand<6080, 0, 0, [], [Functio
12681269
defm AliasScopeINTEL : DecorationOperand<5914, 0, 0, [], [MemoryAccessAliasingINTEL]>;
12691270
defm NoAliasINTEL : DecorationOperand<5915, 0, 0, [], [MemoryAccessAliasingINTEL]>;
12701271
defm FPMaxErrorDecorationINTEL : DecorationOperand<6170, 0, 0, [], [FPMaxErrorINTEL]>;
1272+
defm LatencyControlLabelINTEL : DecorationOperand<6172, 0, 0, [], [FPGALatencyControlINTEL]>;
1273+
defm LatencyControlConstraintINTEL : DecorationOperand<6173, 0, 0, [], [FPGALatencyControlINTEL]>;
12711274

12721275
//===----------------------------------------------------------------------===//
12731276
// Multiclass used to define BuiltIn enum values and at the same time
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown -verify-machineinstrs --spirv-ext=+SPV_INTEL_fpga_latency_control %s -o - | FileCheck %s
2+
3+
; CHECK: OpCapability FPGALatencyControlINTEL
4+
; CHECK: OpExtension "SPV_INTEL_fpga_latency_control"
5+
; CHECK: OpDecorate %[[#ARGA:]] LatencyControlLabelINTEL 0
6+
; CHECK: OpDecorate %[[#ARGB:]] LatencyControlLabelINTEL 1
7+
; CHECK: OpDecorate %[[#ARGB]] LatencyControlConstraintINTEL 0 1 5
8+
; CHECK: %[[#OUT1:]] = OpBitcast %[[#]] %[[#]]
9+
; CHECK-DAG: %[[#]] = OpLoad %[[#]] %[[#OUT1]]
10+
; CHECK: %[[#OUT2:]] = OpBitcast %[[#]] %[[#]]
11+
; CHECK-DAG: %[[#]] = OpLoad %[[#]] %[[#OUT2]]
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+
15+
%struct.__spirv_Something = type { i32, i32 }
16+
17+
$_ZTSZ4fooEUlvE_ = comdat any
18+
19+
@.str = private unnamed_addr addrspace(1) constant [16 x i8] c"sycl-properties\00", section "llvm.metadata"
20+
@.str.1 = private unnamed_addr addrspace(1) constant [19 x i8] c"inc/fpga_utils.hpp\00", section "llvm.metadata"
21+
@.str.9 = private unnamed_addr addrspace(1) constant [11 x i8] c"{6172:\220\22}\00", section "llvm.metadata"
22+
@.str.10 = private unnamed_addr addrspace(1) constant [25 x i8] c"{6172:\221\22}{6173:\220,5,1\22}\00", section "llvm.metadata"
23+
24+
; Function Attrs: mustprogress norecurse
25+
define weak_odr dso_local spir_kernel void @_ZTSZ4fooEUlvE_(ptr %0) local_unnamed_addr #0 comdat !kernel_arg_buffer_location !5 !sycl_kernel_omit_args !5 {
26+
entry:
27+
%1 = alloca ptr, align 8
28+
store ptr %0, ptr %1, align 8
29+
%2 = load ptr, ptr %1, align 8
30+
%3 = getelementptr inbounds %struct.__spirv_Something, ptr %2, i32 0, i32 0
31+
%4 = bitcast ptr %3 to ptr
32+
%5 = call ptr @llvm.ptr.annotation.p0.p1(ptr %4, ptr addrspace(1) @.str.9, ptr addrspace(1) @.str.1, i32 5, ptr addrspace(1) null)
33+
%6 = load i32, ptr %5, align 8
34+
%7 = load ptr, ptr %1, align 8
35+
%8 = getelementptr inbounds %struct.__spirv_Something, ptr %7, i32 0, i32 1
36+
%9 = bitcast ptr %8 to ptr
37+
%10 = call ptr @llvm.ptr.annotation.p0.p1(ptr %9, ptr addrspace(1) @.str.10, ptr addrspace(1) @.str.1, i32 5, ptr addrspace(1) null)
38+
%11 = load i32, ptr %10, align 8
39+
ret void
40+
}
41+
42+
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite)
43+
declare ptr @llvm.ptr.annotation.p0.p1(ptr, ptr addrspace(1), ptr addrspace(1), i32, ptr addrspace(1)) #1
44+
45+
attributes #0 = { mustprogress norecurse "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-module-id"="sycl-properties-ptr-annotations.cpp" "uniform-work-group-size"="true" }
46+
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
47+
48+
!opencl.spir.version = !{!0, !0, !0, !0, !0, !0}
49+
!spirv.Source = !{!1, !1, !1, !1, !1, !1}
50+
!llvm.ident = !{!2, !2, !2, !2, !2, !2}
51+
!llvm.module.flags = !{!3, !4}
52+
53+
!0 = !{i32 1, i32 2}
54+
!1 = !{i32 4, i32 100000}
55+
!2 = !{!"clang version 15.0.0"}
56+
!3 = !{i32 1, !"wchar_size", i32 4}
57+
!4 = !{i32 7, !"frame-pointer", i32 2}
58+
!5 = !{}

0 commit comments

Comments
 (0)