Skip to content

SPIRV patches #2015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions llvm-spirv/lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3470,6 +3470,18 @@ bool SPIRVToLLVM::transVectorComputeMetadata(SPIRVFunction *BF) {
std::to_string(Kind));
F->addAttribute(ArgNo + 1, Attr);
}
if (BA->hasDecorate(DecorationFuncParamKindINTEL, 0, &Kind)) {
Attribute Attr = Attribute::get(*Context, kVCMetadata::VCArgumentKind,
std::to_string(Kind));
F->addAttribute(ArgNo + 1, Attr);
}
if (BA->hasDecorate(DecorationFuncParamDescINTEL)) {
auto Desc =
BA->getDecorationStringLiteral(DecorationFuncParamDescINTEL).front();
Attribute Attr =
Attribute::get(*Context, kVCMetadata::VCArgumentDesc, Desc);
F->addAttribute(ArgNo + 1, Attr);
}
}

// Do not add float control if there is no any
Expand Down
13 changes: 13 additions & 0 deletions llvm-spirv/lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,19 @@ void LLVMToSPIRV::transVectorComputeMetadata(Function *F) {
.getAsInteger(0, Kind);
BA->addDecorate(DecorationFuncParamIOKind, Kind);
}
if (Attrs.hasAttribute(ArgNo + 1, kVCMetadata::VCArgumentKind)) {
SPIRVWord Kind;
Attrs.getAttribute(ArgNo + 1, kVCMetadata::VCArgumentKind)
.getValueAsString()
.getAsInteger(0, Kind);
BA->addDecorate(DecorationFuncParamKindINTEL, Kind);
}
if (Attrs.hasAttribute(ArgNo + 1, kVCMetadata::VCArgumentDesc)) {
StringRef Desc =
Attrs.getAttribute(ArgNo + 1, kVCMetadata::VCArgumentDesc)
.getValueAsString();
BA->addDecorate(new SPIRVDecorateFuncParamDescAttr(BA, Desc.str()));
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions llvm-spirv/lib/SPIRV/VectorComputeUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ const static char VCSLMSize[] = "VCSLMSize";
const static char VCGlobalVariable[] = "VCGlobalVariable";
const static char VCVolatile[] = "VCVolatile";
const static char VCByteOffset[] = "VCByteOffset";
const static char VCArgumentKind[] = "VCArgumentKind";
const static char VCArgumentDesc[] = "VCArgumentDesc";
} // namespace kVCMetadata

///////////////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 12 additions & 0 deletions llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDecorate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ void SPIRVDecorate::encode(spv_ostream &O) const {
case DecorationUserSemantic:
SPIRVDecorateUserSemanticAttr::encodeLiterals(Encoder, Literals);
break;
case DecorationFuncParamDescINTEL:
SPIRVDecorateFuncParamDescAttr::encodeLiterals(Encoder, Literals);
break;
default:
Encoder << Literals;
}
Expand All @@ -130,6 +133,9 @@ void SPIRVDecorate::decode(std::istream &I) {
case DecorationUserSemantic:
SPIRVDecorateUserSemanticAttr::decodeLiterals(Decoder, Literals);
break;
case DecorationFuncParamDescINTEL:
SPIRVDecorateFuncParamDescAttr::decodeLiterals(Decoder, Literals);
break;
default:
Decoder >> Literals;
}
Expand All @@ -149,6 +155,9 @@ void SPIRVMemberDecorate::encode(spv_ostream &O) const {
case DecorationUserSemantic:
SPIRVDecorateUserSemanticAttr::encodeLiterals(Encoder, Literals);
break;
case DecorationFuncParamDescINTEL:
SPIRVDecorateFuncParamDescAttr::encodeLiterals(Encoder, Literals);
break;
default:
Encoder << Literals;
}
Expand All @@ -172,6 +181,9 @@ void SPIRVMemberDecorate::decode(std::istream &I) {
case DecorationUserSemantic:
SPIRVDecorateUserSemanticAttr::decodeLiterals(Decoder, Literals);
break;
case DecorationFuncParamDescINTEL:
SPIRVDecorateFuncParamDescAttr::decodeLiterals(Decoder, Literals);
break;
default:
Decoder >> Literals;
}
Expand Down
9 changes: 9 additions & 0 deletions llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDecorate.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,15 @@ class SPIRVDecorateUserSemanticAttr
: SPIRVDecorateStrAttrBase(TheTarget, AnnotateString) {}
};

class SPIRVDecorateFuncParamDescAttr
: public SPIRVDecorateStrAttrBase<DecorationFuncParamDescINTEL> {
public:
// Complete constructor for UserSemantic decoration
SPIRVDecorateFuncParamDescAttr(SPIRVEntry *TheTarget,
const std::string &AnnotateString)
: SPIRVDecorateStrAttrBase(TheTarget, AnnotateString) {}
};

class SPIRVDecorateMergeINTELAttr : public SPIRVDecorate {
public:
// Complete constructor for MergeINTEL decoration
Expand Down
2 changes: 2 additions & 0 deletions llvm-spirv/lib/SPIRV/libSPIRV/SPIRVEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ template <> inline void SPIRVMap<Decoration, SPIRVCapVec>::init() {
{CapabilityVectorComputeINTEL});
ADD_VEC_INIT(DecorationFuncParamIOKind, {CapabilityVectorComputeINTEL});
ADD_VEC_INIT(DecorationStackCallINTEL, {CapabilityVectorComputeINTEL});
ADD_VEC_INIT(DecorationFuncParamKindINTEL, {CapabilityVectorComputeINTEL});
ADD_VEC_INIT(DecorationFuncParamDescINTEL, {CapabilityVectorComputeINTEL});
}

template <> inline void SPIRVMap<BuiltIn, SPIRVCapVec>::init() {
Expand Down
2 changes: 2 additions & 0 deletions llvm-spirv/lib/SPIRV/libSPIRV/SPIRVIsValidEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ inline bool isValid(spv::Decoration V) {
case DecorationReferencedIndirectlyINTEL:
case DecorationVectorComputeFunctionINTEL:
case DecorationStackCallINTEL:
case DecorationFuncParamKindINTEL:
case DecorationFuncParamDescINTEL:
case DecorationVectorComputeVariableINTEL:
case DecorationGlobalVariableOffsetINTEL:
case DecorationFuncParamIOKind:
Expand Down
2 changes: 2 additions & 0 deletions llvm-spirv/lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ template <> inline void SPIRVMap<Decoration, std::string>::init() {
add(DecorationIOPipeStorageINTEL, "IOPipeStorageINTEL");
add(DecorationVectorComputeFunctionINTEL, "VectorComputeFunctionINTEL");
add(DecorationStackCallINTEL, "StackCallINTEL");
add(DecorationFuncParamKindINTEL, "FuncParamKindINTEL");
add(DecorationFuncParamDescINTEL, "FuncParamDescINTEL");
add(DecorationVectorComputeVariableINTEL, "VectorComputeVariableINTEL");
add(DecorationGlobalVariableOffsetINTEL, "GlobalVariableOffsetINTEL");
add(DecorationFuncParamIOKind, "FuncParamIOKind");
Expand Down
2 changes: 2 additions & 0 deletions llvm-spirv/lib/SPIRV/libSPIRV/spirv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ enum Decoration {
DecorationRestrictPointerEXT = 5355,
DecorationAliasedPointer = 5356,
DecorationAliasedPointerEXT = 5356,
DecorationFuncParamKindINTEL = 9624,
DecorationFuncParamDescINTEL = 9625,
DecorationReferencedIndirectlyINTEL = 5602,
DecorationSideEffectsINTEL = 5608,
DecorationVectorComputeVariableINTEL = 5624,
Expand Down
32 changes: 32 additions & 0 deletions llvm-spirv/test/transcoding/decoration_func_param_desc.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc -o %t.spv --spirv-ext=+SPV_INTEL_vector_compute
; RUN: llvm-spirv %t.spv -o %t.spt --to-text
; RUN: llvm-spirv -r %t.spv -o %t.bc
; RUN: llvm-dis %t.bc -o %t.ll
; RUN: FileCheck %s --input-file %t.spt -check-prefix=SPV
; RUN: FileCheck %s --input-file %t.ll -check-prefix=LLVM

; ModuleID = 'slm.bc'
source_filename = "slm.cpp"
target datalayout = "e-p:64:64-i64:64-n8:16:32"
target triple = "spir"

; LLVM: @k_rte(i32 "VCArgumentDesc"="0" %ibuf, i32 "VCArgumentDesc"="1" %obuf)
; SPV: Name [[IBUF:[0-9]+]] "ibuf"
; SPV: Name [[OBUF:[0-9]+]] "obuf"
; SPV: Decorate [[IBUF]] FuncParamDescINTEL "0"
; SPV: Decorate [[OBUF]] FuncParamDescINTEL "1"
; Function Attrs: noinline norecurse nounwind readnone
define dso_local dllexport spir_kernel void @k_rte(i32 "VCArgumentDesc"="0" %ibuf, i32 "VCArgumentDesc"="1" %obuf) local_unnamed_addr #1 {
entry:
ret void
}

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" }

!llvm.module.flags = !{!0}
!llvm.ident = !{!1}

; Note
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 8.0.1"}
32 changes: 32 additions & 0 deletions llvm-spirv/test/transcoding/decoration_func_param_kind.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc -o %t.spv --spirv-ext=+SPV_INTEL_vector_compute
; RUN: llvm-spirv %t.spv -o %t.spt --to-text
; RUN: llvm-spirv -r %t.spv -o %t.bc
; RUN: llvm-dis %t.bc -o %t.ll
; RUN: FileCheck %s --input-file %t.spt -check-prefix=SPV
; RUN: FileCheck %s --input-file %t.ll -check-prefix=LLVM

; ModuleID = 'slm.bc'
source_filename = "slm.cpp"
target datalayout = "e-p:64:64-i64:64-n8:16:32"
target triple = "spir"

; LLVM: @k_rte(i32 "VCArgumentKind"="0" %ibuf, i32 "VCArgumentKind"="1" %obuf)
; SPV: Name [[IBUF:[0-9]+]] "ibuf"
; SPV: Name [[OBUF:[0-9]+]] "obuf"
; SPV: Decorate [[IBUF]] FuncParamKindINTEL 0
; SPV: Decorate [[OBUF]] FuncParamKindINTEL 1
; Function Attrs: noinline norecurse nounwind readnone
define dso_local dllexport spir_kernel void @k_rte(i32 "VCArgumentKind"="0" %ibuf, i32 "VCArgumentKind"="1" %obuf) local_unnamed_addr #1 {
entry:
ret void
}

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" }

!llvm.module.flags = !{!0}
!llvm.ident = !{!1}

; Note
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 8.0.1"}