Skip to content

Commit c315768

Browse files
committed
[Backport to 15] Remove internal values for SPV_INTEL_cache_controls (#2346, #3191)
The SPIR-V Headers for this extension were published so we should use them instead. Squashes #2346 and its follow-up #3191. Also adds CacheControlVec handling in ptr_annotation non-struct path and CacheControlLoadINTEL case in addAnnotationDecorations, which were missing on this release branch.
1 parent 5165b68 commit c315768

4 files changed

Lines changed: 44 additions & 8 deletions

File tree

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,6 +2926,7 @@ using DecorationsInfoVec =
29262926
struct AnnotationDecorations {
29272927
DecorationsInfoVec MemoryAttributesVec;
29282928
DecorationsInfoVec MemoryAccessesVec;
2929+
DecorationsInfoVec CacheControlVec;
29292930
};
29302931

29312932
struct IntelLSUControlsInfo {
@@ -3102,6 +3103,8 @@ AnnotationDecorations tryParseAnnotationString(SPIRVModule *BM,
31023103
BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_fpga_memory_accesses);
31033104
const bool AllowFPGAMemAttr = BM->isAllowedToUseExtension(
31043105
ExtensionID::SPV_INTEL_fpga_memory_attributes);
3106+
const bool AllowCacheControls =
3107+
BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_cache_controls);
31053108

31063109
bool ValidDecorationFound = false;
31073110
DecorationsInfoVec DecorationsVec;
@@ -3120,8 +3123,14 @@ AnnotationDecorations tryParseAnnotationString(SPIRVModule *BM,
31203123
std::vector<std::string> DecValues;
31213124
if (tryParseAnnotationDecoValues(ValueStr, DecValues)) {
31223125
ValidDecorationFound = true;
3123-
DecorationsVec.emplace_back(static_cast<Decoration>(DecorationKind),
3124-
std::move(DecValues));
3126+
if (AllowCacheControls &&
3127+
DecorationKind == DecorationCacheControlLoadINTEL) {
3128+
Decorates.CacheControlVec.emplace_back(
3129+
static_cast<Decoration>(DecorationKind), std::move(DecValues));
3130+
} else {
3131+
DecorationsVec.emplace_back(static_cast<Decoration>(DecorationKind),
3132+
std::move(DecValues));
3133+
}
31253134
}
31263135
continue;
31273136
}
@@ -3307,6 +3316,30 @@ void addAnnotationDecorations(SPIRVEntry *E, DecorationsInfoVec &Decorations) {
33073316
E->addDecorate(I.first, Result);
33083317
}
33093318
} break;
3319+
case DecorationCacheControlLoadINTEL: {
3320+
if (M->isAllowedToUseExtension(ExtensionID::SPV_INTEL_cache_controls)) {
3321+
// Annotation "{6442:"0,1"}" yields a single quoted value "0,1";
3322+
// split it on comma to get the two operands.
3323+
std::vector<std::string> Args = I.second;
3324+
if (Args.size() == 1) {
3325+
auto Pos = Args[0].find(',');
3326+
if (Pos != std::string::npos) {
3327+
std::string Second = Args[0].substr(Pos + 1);
3328+
Args[0] = Args[0].substr(0, Pos);
3329+
Args.push_back(std::move(Second));
3330+
}
3331+
}
3332+
M->getErrorLog().checkError(
3333+
Args.size() == 2, SPIRVEC_InvalidLlvmModule,
3334+
"CacheControlLoadINTEL requires exactly 2 extra operands");
3335+
SPIRVWord CacheLevel = 0;
3336+
SPIRVWord CacheControl = 0;
3337+
StringRef(Args[0]).getAsInteger(10, CacheLevel);
3338+
StringRef(Args[1]).getAsInteger(10, CacheControl);
3339+
E->addDecorate(new SPIRVDecorateCacheControlLoadINTEL(
3340+
E, CacheLevel, static_cast<LoadCacheControl>(CacheControl)));
3341+
}
3342+
} break;
33103343
default:
33113344
// Other decorations are either not supported by the translator or
33123345
// handled in other places.
@@ -4107,15 +4140,18 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
41074140
} else {
41084141
// Memory accesses to a standalone pointer variable
41094142
auto *DecSubj = transValue(II->getArgOperand(0), BB);
4110-
if (Decorations.MemoryAccessesVec.empty())
4143+
if (Decorations.MemoryAccessesVec.empty() &&
4144+
Decorations.CacheControlVec.empty())
41114145
DecSubj->addDecorate(new SPIRVDecorateUserSemanticAttr(
41124146
DecSubj, AnnotationString.c_str()));
4113-
else
4147+
else {
41144148
// Apply the LSU parameter decoration to the pointer result of an
41154149
// instruction. Note it's the address to the accessed memory that's
41164150
// loaded from the original pointer variable, and not the value
41174151
// accessed by the latter.
41184152
addAnnotationDecorations(DecSubj, Decorations.MemoryAccessesVec);
4153+
addAnnotationDecorations(DecSubj, Decorations.CacheControlVec);
4154+
}
41194155
II->replaceAllUsesWith(II->getOperand(0));
41204156
}
41214157
}

lib/SPIRV/libSPIRV/SPIRVEnum.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,9 @@ template <> inline void SPIRVMap<Decoration, SPIRVCapVec>::init() {
492492
{CapabilityFunctionPointersINTEL});
493493
ADD_VEC_INIT(DecorationFPMaxErrorDecorationINTEL,
494494
{CapabilityFPMaxErrorINTEL});
495+
ADD_VEC_INIT(DecorationCacheControlLoadINTEL, {CapabilityCacheControlsINTEL});
496+
ADD_VEC_INIT(DecorationCacheControlStoreINTEL,
497+
{CapabilityCacheControlsINTEL});
495498
}
496499

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

lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
613613
add(CapabilityGroupUniformArithmeticKHR, "GroupUniformArithmeticKHR");
614614
add(CapabilityRegisterLimitsINTEL, "RegisterLimitsINTEL");
615615
add(CapabilityFPMaxErrorINTEL, "FPMaxErrorINTEL");
616+
add(CapabilityCacheControlsINTEL, "CacheControlsINTEL");
616617
add(CapabilityBFloat16TypeKHR, "BFloat16TypeKHR");
617618
add(CapabilityBFloat16DotProductKHR, "BFloat16DotProductKHR");
618619
add(CapabilityBFloat16CooperativeMatrixKHR, "BFloat16CooperativeMatrixKHR");
@@ -642,7 +643,6 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
642643
add(internal::CapabilityMaskedGatherScatterINTEL, "MaskedGatherScatterINTEL");
643644
add(internal::CapabilityTensorFloat32RoundingINTEL,
644645
"TensorFloat32RoundingINTEL");
645-
add(internal::CapabilityCacheControlsINTEL, "CacheControlsINTEL");
646646
add(internal::CapabilityJointMatrixWIInstructionsINTEL,
647647
"JointMatrixWIInstructionsINTEL");
648648
add(internal::CapabilityCooperativeMatrixPrefetchINTEL,

lib/SPIRV/libSPIRV/spirv_internal.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ enum InternalCapability {
134134
ICapabilityTensorFloat32RoundingINTEL = 6425,
135135
ICapabilityMaskedGatherScatterINTEL = 6427,
136136
ICapabilityJointMatrixWIInstructionsINTEL = 6435,
137-
ICapabilityCacheControlsINTEL = 6441,
138137
ICapabilityBindlessImagesINTEL = 6528
139138
};
140139

@@ -215,8 +214,6 @@ _SPIRV_OP(Op, MaskedScatterINTEL)
215214
_SPIRV_OP(Capability, TensorFloat32RoundingINTEL)
216215
_SPIRV_OP(Op, RoundFToTF32INTEL)
217216

218-
_SPIRV_OP(Capability, CacheControlsINTEL)
219-
220217
_SPIRV_OP(Capability, BindlessImagesINTEL)
221218
_SPIRV_OP(Op, ConvertHandleToImageINTEL)
222219
_SPIRV_OP(Op, ConvertHandleToSamplerINTEL)

0 commit comments

Comments
 (0)