@@ -3111,6 +3111,7 @@ using DecorationsInfoVec =
31113111struct AnnotationDecorations {
31123112 DecorationsInfoVec MemoryAttributesVec;
31133113 DecorationsInfoVec MemoryAccessesVec;
3114+ DecorationsInfoVec CacheControlVec;
31143115};
31153116
31163117struct 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 ;
0 commit comments