Index: include/llvm/IR/IRBuilder.h =================================================================== --- include/llvm/IR/IRBuilder.h +++ include/llvm/IR/IRBuilder.h @@ -2267,6 +2267,28 @@ return V; } + Value *CreatePreserveDIAccessIndex(Value *Ptr, Value *Base, + StringRef BaseTypeName, + unsigned AccessIndex) { + assert(isa(Ptr->getType()) && + "Invalid Ptr type for preserve.di.access.index."); + auto *PtrType = Ptr->getType(); + + assert(isa(Base->getType()) && + "Invalid Ptr type for preserve.di.access.index."); + auto *BaseType = Base->getType(); + + Module *M = BB->getParent()->getParent(); + Function *FnPreserveDIAccessIndex = Intrinsic::getDeclaration( + M, Intrinsic::preserve_di_access_index, {PtrType, PtrType, BaseType}); + Value *RecordName = CreateGlobalStringPtr(BaseTypeName); + Value *IndexValue = getInt32(AccessIndex); + CallInst *Fn = CreateCall(FnPreserveDIAccessIndex, + {Ptr, Base, RecordName, IndexValue}); + + return Fn; + } + private: /// Helper function that creates an assume intrinsic call that /// represents an alignment assumption on the provided Ptr, Mask, Type Index: include/llvm/IR/Intrinsics.td =================================================================== --- include/llvm/IR/Intrinsics.td +++ include/llvm/IR/Intrinsics.td @@ -1021,6 +1021,11 @@ // Intrinsic to detect whether its argument is a constant. def int_is_constant : Intrinsic<[llvm_i1_ty], [llvm_any_ty], [IntrNoMem], "llvm.is.constant">; +// Intrinsic to preserve the original fieldindex. +def int_preserve_di_access_index : Intrinsic<[llvm_anyptr_ty], + [llvm_anyptr_ty, llvm_anyptr_ty, + llvm_ptr_ty, llvm_i32_ty], + [IntrNoMem, ImmArg<3>]>; //===-------------------------- Masked Intrinsics -------------------------===// //