diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2021-07-16 20:26:40 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-07-17 11:09:18 +0200 |
commit | be5af50e7d028849bf2fab5f4b0f2ad36ae56e11 (patch) | |
tree | d37dc35ffd633656cd4c8beccf4d3f41769c7e7f /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | 173332d175614561770469d237f8c5ba6378a0e7 (diff) | |
download | llvm-be5af50e7d028849bf2fab5f4b0f2ad36ae56e11.zip llvm-be5af50e7d028849bf2fab5f4b0f2ad36ae56e11.tar.gz llvm-be5af50e7d028849bf2fab5f4b0f2ad36ae56e11.tar.bz2 |
[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
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
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<Type *> 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<Type *> 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<Type *> 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<PointerType>(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<InvokeInst>(I)->setCallingConv( static_cast<CallingConv::ID>(CallingConv::MaxID & CCInfo)); cast<InvokeInst>(I)->setAttributes(PAL); - propagateByValSRetTypes(cast<CallBase>(I), ArgsTys); + propagateAttributeTypes(cast<CallBase>(I), ArgsTys); break; } @@ -5318,7 +5332,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) { TCK = CallInst::TCK_NoTail; cast<CallInst>(I)->setTailCallKind(TCK); cast<CallInst>(I)->setAttributes(PAL); - propagateByValSRetTypes(cast<CallBase>(I), ArgsTys); + propagateAttributeTypes(cast<CallBase>(I), ArgsTys); if (FMF.any()) { if (!isa<FPMathOperator>(I)) return error("Fast-math-flags specified for call without " |