Skip to content

Commit c653cd3

Browse files
committed
[Backport to 16] 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 308a0d7 commit c653cd3

3 files changed

Lines changed: 43 additions & 9 deletions

File tree

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,6 +3111,7 @@ using DecorationsInfoVec =
31113111
struct AnnotationDecorations {
31123112
DecorationsInfoVec MemoryAttributesVec;
31133113
DecorationsInfoVec MemoryAccessesVec;
3114+
DecorationsInfoVec CacheControlVec;
31143115
};
31153116

31163117
struct IntelLSUControlsInfo {
@@ -3301,6 +3302,8 @@ AnnotationDecorations tryParseAnnotationString(SPIRVModule *BM,
33013302
BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_fpga_memory_accesses);
33023303
const bool AllowFPGAMemAttr = BM->isAllowedToUseExtension(
33033304
ExtensionID::SPV_INTEL_fpga_memory_attributes);
3305+
const bool AllowCacheControls =
3306+
BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_cache_controls);
33043307

33053308
bool ValidDecorationFound = false;
33063309
DecorationsInfoVec DecorationsVec;
@@ -3319,8 +3322,14 @@ AnnotationDecorations tryParseAnnotationString(SPIRVModule *BM,
33193322
std::vector<std::string> DecValues;
33203323
if (tryParseAnnotationDecoValues(ValueStr, DecValues)) {
33213324
ValidDecorationFound = true;
3322-
DecorationsVec.emplace_back(static_cast<Decoration>(DecorationKind),
3323-
std::move(DecValues));
3325+
if (AllowCacheControls &&
3326+
DecorationKind == DecorationCacheControlLoadINTEL) {
3327+
Decorates.CacheControlVec.emplace_back(
3328+
static_cast<Decoration>(DecorationKind), std::move(DecValues));
3329+
} else {
3330+
DecorationsVec.emplace_back(static_cast<Decoration>(DecorationKind),
3331+
std::move(DecValues));
3332+
}
33243333
}
33253334
continue;
33263335
}
@@ -3507,6 +3516,30 @@ void addAnnotationDecorations(SPIRVEntry *E, DecorationsInfoVec &Decorations) {
35073516
E->addDecorate(I.first, Result);
35083517
}
35093518
} break;
3519+
case DecorationCacheControlLoadINTEL: {
3520+
if (M->isAllowedToUseExtension(ExtensionID::SPV_INTEL_cache_controls)) {
3521+
// Annotation "{6442:"0,1"}" yields a single quoted value "0,1";
3522+
// split it on comma to get the two operands.
3523+
std::vector<std::string> Args = I.second;
3524+
if (Args.size() == 1) {
3525+
auto Pos = Args[0].find(',');
3526+
if (Pos != std::string::npos) {
3527+
std::string Second = Args[0].substr(Pos + 1);
3528+
Args[0] = Args[0].substr(0, Pos);
3529+
Args.push_back(std::move(Second));
3530+
}
3531+
}
3532+
M->getErrorLog().checkError(
3533+
Args.size() == 2, SPIRVEC_InvalidLlvmModule,
3534+
"CacheControlLoadINTEL requires exactly 2 extra operands");
3535+
SPIRVWord CacheLevel = 0;
3536+
SPIRVWord CacheControl = 0;
3537+
StringRef(Args[0]).getAsInteger(10, CacheLevel);
3538+
StringRef(Args[1]).getAsInteger(10, CacheControl);
3539+
E->addDecorate(new SPIRVDecorateCacheControlLoadINTEL(
3540+
E, CacheLevel, static_cast<LoadCacheControl>(CacheControl)));
3541+
}
3542+
} break;
35103543
default:
35113544
// Other decorations are either not supported by the translator or
35123545
// handled in other places.
@@ -4331,15 +4364,18 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
43314364
} else {
43324365
// Memory accesses to a standalone pointer variable
43334366
auto *DecSubj = transValue(II->getArgOperand(0), BB);
4334-
if (Decorations.MemoryAccessesVec.empty())
4367+
if (Decorations.MemoryAccessesVec.empty() &&
4368+
Decorations.CacheControlVec.empty())
43354369
DecSubj->addDecorate(new SPIRVDecorateUserSemanticAttr(
43364370
DecSubj, AnnotationString.c_str()));
4337-
else
4371+
else {
43384372
// Apply the LSU parameter decoration to the pointer result of an
43394373
// instruction. Note it's the address to the accessed memory that's
43404374
// loaded from the original pointer variable, and not the value
43414375
// accessed by the latter.
43424376
addAnnotationDecorations(DecSubj, Decorations.MemoryAccessesVec);
4377+
addAnnotationDecorations(DecSubj, Decorations.CacheControlVec);
4378+
}
43434379
II->replaceAllUsesWith(II->getOperand(0));
43444380
}
43454381
return nullptr;

lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,10 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
630630
add(CapabilityRuntimeAlignedAttributeINTEL, "RuntimeAlignedAttributeINTEL");
631631
add(CapabilityMax, "Max");
632632
add(CapabilityFPGAArgumentInterfacesINTEL, "FPGAArgumentInterfacesINTEL");
633-
add(CapabilityRegisterLimitsINTEL, "RegisterLimitsINTEL");
633+
add(CapabilityFPGALatencyControlINTEL, "FPGALatencyControlINTEL");
634634
add(CapabilityFPMaxErrorINTEL, "FPMaxErrorINTEL");
635+
add(CapabilityCacheControlsINTEL, "CacheControlsINTEL");
636+
add(CapabilityRegisterLimitsINTEL, "RegisterLimitsINTEL");
635637
add(CapabilityBFloat16TypeKHR, "BFloat16TypeKHR");
636638
add(CapabilityBFloat16DotProductKHR, "BFloat16DotProductKHR");
637639
add(CapabilityBFloat16CooperativeMatrixKHR, "BFloat16CooperativeMatrixKHR");
@@ -655,7 +657,6 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
655657
add(internal::CapabilityMaskedGatherScatterINTEL, "MaskedGatherScatterINTEL");
656658
add(internal::CapabilityTensorFloat32RoundingINTEL,
657659
"TensorFloat32RoundingINTEL");
658-
add(internal::CapabilityCacheControlsINTEL, "CacheControlsINTEL");
659660
add(internal::CapabilityJointMatrixWIInstructionsINTEL,
660661
"JointMatrixWIInstructionsINTEL");
661662
add(internal::CapabilityCooperativeMatrixPrefetchINTEL,

lib/SPIRV/libSPIRV/spirv_internal.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ enum InternalCapability {
127127
ICapabilityTensorFloat32RoundingINTEL = 6425,
128128
ICapabilityMaskedGatherScatterINTEL = 6427,
129129
ICapabilityJointMatrixWIInstructionsINTEL = 6435,
130-
ICapabilityCacheControlsINTEL = 6441,
131130
ICapabilityBindlessImagesINTEL = 6528
132131
};
133132

@@ -203,8 +202,6 @@ _SPIRV_OP(Op, MaskedScatterINTEL)
203202
_SPIRV_OP(Capability, TensorFloat32RoundingINTEL)
204203
_SPIRV_OP(Op, RoundFToTF32INTEL)
205204

206-
_SPIRV_OP(Capability, CacheControlsINTEL)
207-
208205
_SPIRV_OP(Capability, BindlessImagesINTEL)
209206
_SPIRV_OP(Op, ConvertHandleToImageINTEL)
210207
_SPIRV_OP(Op, ConvertHandleToSamplerINTEL)

0 commit comments

Comments
 (0)