[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
This commit is contained in:
Nikita Popov
2021-07-16 20:26:40 +02:00
parent 173332d175
commit be5af50e7d
83 changed files with 272 additions and 197 deletions

View File

@@ -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 "