From be5af50e7d028849bf2fab5f4b0f2ad36ae56e11 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 16 Jul 2021 20:26:40 +0200 Subject: [BPF] Use elementtype attribute for preserve.array/struct.index intrinsics Use the elementtype attribute introduced in D105407 for the llvm.preserve.array/struct.index intrinsics. It carries the element type of the GEP these intrinsics effectively encode. This patch: * Adds a verifier check that the attribute is required. * Adds it in the IRBuilder methods for these intrinsics. * Autoupgrades old bitcode without the attribute. * Updates the lowering code to use the attribute rather than the pointer element type. * Updates lots of tests to specify the attribute. * Adds -force-opaque-pointers to the intrinsic-array.ll test to demonstrate they work now. https://reviews.llvm.org/D106184 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 07db3c0..42e17f0 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -682,9 +682,10 @@ private: return getFnValueByID(ValNo, Ty); } - /// Upgrades old-style typeless byval or sret attributes by adding the - /// corresponding argument's pointee type. - void propagateByValSRetTypes(CallBase *CB, ArrayRef ArgsTys); + /// Upgrades old-style typeless byval/sret/inalloca attributes by adding the + /// corresponding argument's pointee type. Also upgrades intrinsics that now + /// require an elementtype attribute. + void propagateAttributeTypes(CallBase *CB, ArrayRef ArgsTys); /// Converts alignment exponent (i.e. power of two (or zero)) to the /// corresponding alignment to use. If alignment is too large, returns @@ -3809,7 +3810,7 @@ Error BitcodeReader::typeCheckLoadStoreInst(Type *ValType, Type *PtrType) { return Error::success(); } -void BitcodeReader::propagateByValSRetTypes(CallBase *CB, +void BitcodeReader::propagateAttributeTypes(CallBase *CB, ArrayRef ArgsTys) { for (unsigned i = 0; i != CB->arg_size(); ++i) { for (Attribute::AttrKind Kind : {Attribute::ByVal, Attribute::StructRet, @@ -3838,6 +3839,19 @@ void BitcodeReader::propagateByValSRetTypes(CallBase *CB, CB->addParamAttr(i, NewAttr); } } + + switch (CB->getIntrinsicID()) { + case Intrinsic::preserve_array_access_index: + case Intrinsic::preserve_struct_access_index: + if (!CB->getAttributes().getParamElementType(0)) { + Type *ElTy = cast(ArgsTys[0])->getElementType(); + Attribute NewAttr = Attribute::get(Context, Attribute::ElementType, ElTy); + CB->addParamAttr(0, NewAttr); + } + break; + default: + break; + } } /// Lazily parse the specified function body block. @@ -4679,7 +4693,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) { cast(I)->setCallingConv( static_cast(CallingConv::MaxID & CCInfo)); cast(I)->setAttributes(PAL); - propagateByValSRetTypes(cast(I), ArgsTys); + propagateAttributeTypes(cast(I), ArgsTys); break; } @@ -5318,7 +5332,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) { TCK = CallInst::TCK_NoTail; cast(I)->setTailCallKind(TCK); cast(I)->setAttributes(PAL); - propagateByValSRetTypes(cast(I), ArgsTys); + propagateAttributeTypes(cast(I), ArgsTys); if (FMF.any()) { if (!isa(I)) return error("Fast-math-flags specified for call without " -- cgit v1.1