@@ -2926,6 +2926,7 @@ using DecorationsInfoVec =
29262926struct AnnotationDecorations {
29272927 DecorationsInfoVec MemoryAttributesVec;
29282928 DecorationsInfoVec MemoryAccessesVec;
2929+ DecorationsInfoVec CacheControlVec;
29292930};
29302931
29312932struct 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 }
0 commit comments