@@ -3217,6 +3217,8 @@ AnnotationDecorations tryParseAnnotationString(SPIRVModule *BM,
32173217
32183218 std::pair<StringRef, StringRef> Split = AnnotatedDecoration.split (' :' );
32193219 StringRef Name = Split.first , ValueStr = Split.second ;
3220+ SPIRVDBG (spvdbgs () << " [tryParseAnnotationString]: AnnotationString: "
3221+ << Name.str () << " \n " );
32203222
32213223 unsigned DecorationKind = 0 ;
32223224 if (!Name.getAsInteger (10 , DecorationKind)) {
@@ -4367,19 +4369,17 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
43674369 // i8* <ptr> is a pointer on a GV, which can carry optinal variadic
43684370 // clang::annotation attribute expression arguments.
43694371 case Intrinsic::ptr_annotation: {
4370- // Strip all bitcast and addrspace casts from the pointer argument:
4371- // llvm annotation intrinsic only takes i8*, so the original pointer
4372- // probably had to loose its addrspace and its original type.
4373- Value *AnnotSubj = II->getArgOperand (0 );
4374- while (isa<BitCastInst>(AnnotSubj) || isa<AddrSpaceCastInst>(AnnotSubj)) {
4375- AnnotSubj = cast<CastInst>(AnnotSubj)->getOperand (0 );
4372+ Value *AnnotSubj = nullptr ;
4373+ if (auto *BI = dyn_cast<BitCastInst>(II->getArgOperand (0 ))) {
4374+ AnnotSubj = BI->getOperand (0 );
4375+ } else {
4376+ AnnotSubj = II->getOperand (0 );
43764377 }
43774378
43784379 std::string AnnotationString;
43794380 processAnnotationString (II, AnnotationString);
43804381 AnnotationDecorations Decorations =
43814382 tryParseAnnotationString (BM, AnnotationString);
4382-
43834383 // Translate FPGARegIntel annotations to OpFPGARegINTEL.
43844384 if (AnnotationString == kOCLBuiltinName ::FPGARegIntel) {
43854385 auto *Ty = transScavengedType (II);
@@ -4389,76 +4389,26 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
43894389 return transValue (BI, BB);
43904390 }
43914391
4392- // If the pointer is a GEP on a struct, then we have to emit a member
4393- // decoration for the GEP-accessed struct, or a memory access decoration
4394- // for the GEP itself. There may not be a GEP in this case if the access is
4395- // to the first member of the struct; if so, attempt to get a struct type
4396- // from an alloca instead.
4397- SPIRVType *StructTy = nullptr ;
4398- [[maybe_unused]] SPIRVValue *ResPtr = nullptr ;
4399- [[maybe_unused]] SPIRVWord MemberNumber = 0 ;
4400- if (auto *const GI = dyn_cast<GetElementPtrInst>(AnnotSubj)) {
4401- if (auto *const STy = dyn_cast<StructType>(GI->getSourceElementType ())) {
4402- StructTy = transType (STy);
4403- ResPtr = transValue (GI, BB);
4404- MemberNumber = dyn_cast<ConstantInt>(GI->getOperand (2 ))->getZExtValue ();
4405- }
4406- } else if (auto *const AI = dyn_cast<AllocaInst>(AnnotSubj)) {
4407- if (auto *const STy = dyn_cast<StructType>(AI->getAllocatedType ())) {
4408- StructTy = transType (STy);
4409- ResPtr = transValue (AI, BB);
4410- MemberNumber = 0 ;
4411- }
4412- }
4413- if (StructTy) {
4414-
4415- // If we didn't find any IntelFPGA-specific decorations, let's add the
4416- // whole annotation string as UserSemantic Decoration
4417- if (Decorations.empty ()) {
4418- // TODO: Is there a way to detect that the annotation belongs solely
4419- // to struct member memory atributes or struct member memory access
4420- // controls? This would allow emitting just the necessary decoration.
4421- StructTy->addMemberDecorate (new SPIRVMemberDecorateUserSemanticAttr (
4422- StructTy, MemberNumber, AnnotationString.c_str ()));
4423- ResPtr->addDecorate (new SPIRVDecorateUserSemanticAttr (
4424- ResPtr, AnnotationString.c_str ()));
4425- } else {
4426- addAnnotationDecorationsForStructMember (
4427- StructTy, MemberNumber, Decorations.MemoryAttributesVec );
4428- // Apply the LSU parameter decoration to the pointer result of a GEP
4429- // to the given struct member (InBoundsPtrAccessChain in SPIR-V).
4430- // Decorating the member itself with a MemberDecoration is not feasible,
4431- // because multiple accesses to the struct-held memory can require
4432- // different LSU parameters.
4433- addAnnotationDecorations (ResPtr, Decorations.MemoryAccessesVec );
4434- if (allowDecorateWithBufferLocationOrLatencyControlINTEL (II)) {
4435- addAnnotationDecorations (ResPtr, Decorations.BufferLocationVec );
4436- addAnnotationDecorations (ResPtr, Decorations.LatencyControlVec );
4437- }
4438- }
4439- II->replaceAllUsesWith (II->getOperand (0 ));
4392+ SPIRVValue *DecSubj = transValue (AnnotSubj, BB);
4393+ if (Decorations.empty ()) {
4394+ DecSubj->addDecorate (
4395+ new SPIRVDecorateUserSemanticAttr (DecSubj, AnnotationString.c_str ()));
44404396 } else {
4441- // Memory accesses to a standalone pointer variable
4442- auto *DecSubj = transValue (II->getArgOperand (0 ), BB);
4443- if (Decorations.empty ())
4444- DecSubj->addDecorate (new SPIRVDecorateUserSemanticAttr (
4445- DecSubj, AnnotationString.c_str ()));
4446- else {
4447- // Apply the LSU parameter decoration to the pointer result of an
4448- // instruction. Note it's the address to the accessed memory that's
4449- // loaded from the original pointer variable, and not the value
4450- // accessed by the latter.
4451- addAnnotationDecorations (DecSubj, Decorations.MemoryAccessesVec );
4452- if (allowDecorateWithBufferLocationOrLatencyControlINTEL (II)) {
4453- addAnnotationDecorations (DecSubj, Decorations.BufferLocationVec );
4454- addAnnotationDecorations (DecSubj, Decorations.LatencyControlVec );
4455- }
4456-
4457- addAnnotationDecorations (DecSubj, Decorations.CacheControlVec );
4397+ addAnnotationDecorations (DecSubj, Decorations.MemoryAttributesVec );
4398+ // Apply the LSU parameter decoration to the pointer result of a GEP
4399+ // to the given struct member (InBoundsPtrAccessChain in SPIR-V).
4400+ // Decorating the member itself with a MemberDecoration is not feasible,
4401+ // because multiple accesses to the struct-held memory can require
4402+ // different LSU parameters.
4403+ addAnnotationDecorations (DecSubj, Decorations.MemoryAccessesVec );
4404+ addAnnotationDecorations (DecSubj, Decorations.CacheControlVec );
4405+ if (allowDecorateWithBufferLocationOrLatencyControlINTEL (II)) {
4406+ addAnnotationDecorations (DecSubj, Decorations.BufferLocationVec );
4407+ addAnnotationDecorations (DecSubj, Decorations.LatencyControlVec );
44584408 }
4459- II->replaceAllUsesWith (II->getOperand (0 ));
44604409 }
4461- return nullptr ;
4410+ II->replaceAllUsesWith (II->getOperand (0 ));
4411+ return DecSubj;
44624412 }
44634413 case Intrinsic::stacksave: {
44644414 if (BM->isAllowedToUseExtension (
0 commit comments