Skip to content

Commit 13a1e49

Browse files
[SYCL][SPIRV] Add DecorationFuncParamKindINTEL and DecorationFuncParamDescINTEL (intel#2015)
This is a temporary workaround for ParamKind and ParamDesc metadata This commit will be removed in future Co-authored-by: Yuly Tarasov <[email protected]>
1 parent d4948b0 commit 13a1e49

11 files changed

+120
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3470,6 +3470,18 @@ bool SPIRVToLLVM::transVectorComputeMetadata(SPIRVFunction *BF) {
34703470
std::to_string(Kind));
34713471
F->addAttribute(ArgNo + 1, Attr);
34723472
}
3473+
if (BA->hasDecorate(DecorationFuncParamKindINTEL, 0, &Kind)) {
3474+
Attribute Attr = Attribute::get(*Context, kVCMetadata::VCArgumentKind,
3475+
std::to_string(Kind));
3476+
F->addAttribute(ArgNo + 1, Attr);
3477+
}
3478+
if (BA->hasDecorate(DecorationFuncParamDescINTEL)) {
3479+
auto Desc =
3480+
BA->getDecorationStringLiteral(DecorationFuncParamDescINTEL).front();
3481+
Attribute Attr =
3482+
Attribute::get(*Context, kVCMetadata::VCArgumentDesc, Desc);
3483+
F->addAttribute(ArgNo + 1, Attr);
3484+
}
34733485
}
34743486

34753487
// Do not add float control if there is no any

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,19 @@ void LLVMToSPIRV::transVectorComputeMetadata(Function *F) {
598598
.getAsInteger(0, Kind);
599599
BA->addDecorate(DecorationFuncParamIOKind, Kind);
600600
}
601+
if (Attrs.hasAttribute(ArgNo + 1, kVCMetadata::VCArgumentKind)) {
602+
SPIRVWord Kind;
603+
Attrs.getAttribute(ArgNo + 1, kVCMetadata::VCArgumentKind)
604+
.getValueAsString()
605+
.getAsInteger(0, Kind);
606+
BA->addDecorate(DecorationFuncParamKindINTEL, Kind);
607+
}
608+
if (Attrs.hasAttribute(ArgNo + 1, kVCMetadata::VCArgumentDesc)) {
609+
StringRef Desc =
610+
Attrs.getAttribute(ArgNo + 1, kVCMetadata::VCArgumentDesc)
611+
.getValueAsString();
612+
BA->addDecorate(new SPIRVDecorateFuncParamDescAttr(BA, Desc.str()));
613+
}
601614
}
602615
}
603616

llvm-spirv/lib/SPIRV/VectorComputeUtil.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ const static char VCSLMSize[] = "VCSLMSize";
116116
const static char VCGlobalVariable[] = "VCGlobalVariable";
117117
const static char VCVolatile[] = "VCVolatile";
118118
const static char VCByteOffset[] = "VCByteOffset";
119+
const static char VCArgumentKind[] = "VCArgumentKind";
120+
const static char VCArgumentDesc[] = "VCArgumentDesc";
119121
} // namespace kVCMetadata
120122

121123
///////////////////////////////////////////////////////////////////////////////

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDecorate.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ void SPIRVDecorate::encode(spv_ostream &O) const {
104104
case DecorationUserSemantic:
105105
SPIRVDecorateUserSemanticAttr::encodeLiterals(Encoder, Literals);
106106
break;
107+
case DecorationFuncParamDescINTEL:
108+
SPIRVDecorateFuncParamDescAttr::encodeLiterals(Encoder, Literals);
109+
break;
107110
default:
108111
Encoder << Literals;
109112
}
@@ -130,6 +133,9 @@ void SPIRVDecorate::decode(std::istream &I) {
130133
case DecorationUserSemantic:
131134
SPIRVDecorateUserSemanticAttr::decodeLiterals(Decoder, Literals);
132135
break;
136+
case DecorationFuncParamDescINTEL:
137+
SPIRVDecorateFuncParamDescAttr::decodeLiterals(Decoder, Literals);
138+
break;
133139
default:
134140
Decoder >> Literals;
135141
}
@@ -149,6 +155,9 @@ void SPIRVMemberDecorate::encode(spv_ostream &O) const {
149155
case DecorationUserSemantic:
150156
SPIRVDecorateUserSemanticAttr::encodeLiterals(Encoder, Literals);
151157
break;
158+
case DecorationFuncParamDescINTEL:
159+
SPIRVDecorateFuncParamDescAttr::encodeLiterals(Encoder, Literals);
160+
break;
152161
default:
153162
Encoder << Literals;
154163
}
@@ -172,6 +181,9 @@ void SPIRVMemberDecorate::decode(std::istream &I) {
172181
case DecorationUserSemantic:
173182
SPIRVDecorateUserSemanticAttr::decodeLiterals(Decoder, Literals);
174183
break;
184+
case DecorationFuncParamDescINTEL:
185+
SPIRVDecorateFuncParamDescAttr::decodeLiterals(Decoder, Literals);
186+
break;
175187
default:
176188
Decoder >> Literals;
177189
}

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDecorate.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,15 @@ class SPIRVDecorateUserSemanticAttr
413413
: SPIRVDecorateStrAttrBase(TheTarget, AnnotateString) {}
414414
};
415415

416+
class SPIRVDecorateFuncParamDescAttr
417+
: public SPIRVDecorateStrAttrBase<DecorationFuncParamDescINTEL> {
418+
public:
419+
// Complete constructor for UserSemantic decoration
420+
SPIRVDecorateFuncParamDescAttr(SPIRVEntry *TheTarget,
421+
const std::string &AnnotateString)
422+
: SPIRVDecorateStrAttrBase(TheTarget, AnnotateString) {}
423+
};
424+
416425
class SPIRVDecorateMergeINTELAttr : public SPIRVDecorate {
417426
public:
418427
// Complete constructor for MergeINTEL decoration

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVEnum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ template <> inline void SPIRVMap<Decoration, SPIRVCapVec>::init() {
393393
{CapabilityVectorComputeINTEL});
394394
ADD_VEC_INIT(DecorationFuncParamIOKind, {CapabilityVectorComputeINTEL});
395395
ADD_VEC_INIT(DecorationStackCallINTEL, {CapabilityVectorComputeINTEL});
396+
ADD_VEC_INIT(DecorationFuncParamKindINTEL, {CapabilityVectorComputeINTEL});
397+
ADD_VEC_INIT(DecorationFuncParamDescINTEL, {CapabilityVectorComputeINTEL});
396398
}
397399

398400
template <> inline void SPIRVMap<BuiltIn, SPIRVCapVec>::init() {

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVIsValidEnum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ inline bool isValid(spv::Decoration V) {
426426
case DecorationReferencedIndirectlyINTEL:
427427
case DecorationVectorComputeFunctionINTEL:
428428
case DecorationStackCallINTEL:
429+
case DecorationFuncParamKindINTEL:
430+
case DecorationFuncParamDescINTEL:
429431
case DecorationVectorComputeVariableINTEL:
430432
case DecorationGlobalVariableOffsetINTEL:
431433
case DecorationFuncParamIOKind:

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ template <> inline void SPIRVMap<Decoration, std::string>::init() {
366366
add(DecorationIOPipeStorageINTEL, "IOPipeStorageINTEL");
367367
add(DecorationVectorComputeFunctionINTEL, "VectorComputeFunctionINTEL");
368368
add(DecorationStackCallINTEL, "StackCallINTEL");
369+
add(DecorationFuncParamKindINTEL, "FuncParamKindINTEL");
370+
add(DecorationFuncParamDescINTEL, "FuncParamDescINTEL");
369371
add(DecorationVectorComputeVariableINTEL, "VectorComputeVariableINTEL");
370372
add(DecorationGlobalVariableOffsetINTEL, "GlobalVariableOffsetINTEL");
371373
add(DecorationFuncParamIOKind, "FuncParamIOKind");

llvm-spirv/lib/SPIRV/libSPIRV/spirv.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,8 @@ enum Decoration {
477477
DecorationRestrictPointerEXT = 5355,
478478
DecorationAliasedPointer = 5356,
479479
DecorationAliasedPointerEXT = 5356,
480+
DecorationFuncParamKindINTEL = 9624,
481+
DecorationFuncParamDescINTEL = 9625,
480482
DecorationReferencedIndirectlyINTEL = 5602,
481483
DecorationSideEffectsINTEL = 5608,
482484
DecorationVectorComputeVariableINTEL = 5624,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv --spirv-ext=+SPV_INTEL_vector_compute
3+
; RUN: llvm-spirv %t.spv -o %t.spt --to-text
4+
; RUN: llvm-spirv -r %t.spv -o %t.bc
5+
; RUN: llvm-dis %t.bc -o %t.ll
6+
; RUN: FileCheck %s --input-file %t.spt -check-prefix=SPV
7+
; RUN: FileCheck %s --input-file %t.ll -check-prefix=LLVM
8+
9+
; ModuleID = 'slm.bc'
10+
source_filename = "slm.cpp"
11+
target datalayout = "e-p:64:64-i64:64-n8:16:32"
12+
target triple = "spir"
13+
14+
; LLVM: @k_rte(i32 "VCArgumentDesc"="0" %ibuf, i32 "VCArgumentDesc"="1" %obuf)
15+
; SPV: Name [[IBUF:[0-9]+]] "ibuf"
16+
; SPV: Name [[OBUF:[0-9]+]] "obuf"
17+
; SPV: Decorate [[IBUF]] FuncParamDescINTEL "0"
18+
; SPV: Decorate [[OBUF]] FuncParamDescINTEL "1"
19+
; Function Attrs: noinline norecurse nounwind readnone
20+
define dso_local dllexport spir_kernel void @k_rte(i32 "VCArgumentDesc"="0" %ibuf, i32 "VCArgumentDesc"="1" %obuf) local_unnamed_addr #1 {
21+
entry:
22+
ret void
23+
}
24+
25+
attributes #1 = { noinline norecurse nounwind readnone "VCFunction" "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
26+
27+
!llvm.module.flags = !{!0}
28+
!llvm.ident = !{!1}
29+
30+
; Note
31+
!0 = !{i32 1, !"wchar_size", i32 4}
32+
!1 = !{!"clang version 8.0.1"}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv --spirv-ext=+SPV_INTEL_vector_compute
3+
; RUN: llvm-spirv %t.spv -o %t.spt --to-text
4+
; RUN: llvm-spirv -r %t.spv -o %t.bc
5+
; RUN: llvm-dis %t.bc -o %t.ll
6+
; RUN: FileCheck %s --input-file %t.spt -check-prefix=SPV
7+
; RUN: FileCheck %s --input-file %t.ll -check-prefix=LLVM
8+
9+
; ModuleID = 'slm.bc'
10+
source_filename = "slm.cpp"
11+
target datalayout = "e-p:64:64-i64:64-n8:16:32"
12+
target triple = "spir"
13+
14+
; LLVM: @k_rte(i32 "VCArgumentKind"="0" %ibuf, i32 "VCArgumentKind"="1" %obuf)
15+
; SPV: Name [[IBUF:[0-9]+]] "ibuf"
16+
; SPV: Name [[OBUF:[0-9]+]] "obuf"
17+
; SPV: Decorate [[IBUF]] FuncParamKindINTEL 0
18+
; SPV: Decorate [[OBUF]] FuncParamKindINTEL 1
19+
; Function Attrs: noinline norecurse nounwind readnone
20+
define dso_local dllexport spir_kernel void @k_rte(i32 "VCArgumentKind"="0" %ibuf, i32 "VCArgumentKind"="1" %obuf) local_unnamed_addr #1 {
21+
entry:
22+
ret void
23+
}
24+
25+
attributes #1 = { noinline norecurse nounwind readnone "VCFunction" "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
26+
27+
!llvm.module.flags = !{!0}
28+
!llvm.ident = !{!1}
29+
30+
; Note
31+
!0 = !{i32 1, !"wchar_size", i32 4}
32+
!1 = !{!"clang version 8.0.1"}

0 commit comments

Comments
 (0)