aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2020-09-29 09:33:55 -0400
committerMatt Arsenault <Matthew.Arsenault@amd.com>2020-10-16 11:05:02 -0400
commit0a7cd99a702595ccf73c957be0127af9f25fb9a2 (patch)
tree01837b082bd0229afc320b4371fe3558b1a9758f /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parent97533b10b27db058cc77c81a4f964b66392871c6 (diff)
downloadllvm-0a7cd99a702595ccf73c957be0127af9f25fb9a2.zip
llvm-0a7cd99a702595ccf73c957be0127af9f25fb9a2.tar.gz
llvm-0a7cd99a702595ccf73c957be0127af9f25fb9a2.tar.bz2
Reapply "OpaquePtr: Add type to sret attribute"
This reverts commit eb9f7c28e5fe6d75fed3587023e17f2997c8024b. Previously this was incorrectly handling linking of the contained type, so this merges the fixes from D88973.
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp61
1 files changed, 39 insertions, 22 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 15ca3a5..bc479fa 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -715,9 +715,9 @@ private:
return getFnValueByID(ValNo, Ty);
}
- /// Upgrades old-style typeless byval attributes by adding the corresponding
- /// argument's pointee type.
- void propagateByValTypes(CallBase *CB, ArrayRef<Type *> ArgsFullTys);
+ /// Upgrades old-style typeless byval or sret attributes by adding the
+ /// corresponding argument's pointee type.
+ void propagateByValSRetTypes(CallBase *CB, ArrayRef<Type *> ArgsFullTys);
/// Converts alignment exponent (i.e. power of two (or zero)) to the
/// corresponding alignment to use. If alignment is too large, returns
@@ -1609,6 +1609,8 @@ Error BitcodeReader::parseAttributeGroupBlock() {
// this AttributeList with a function.
if (Kind == Attribute::ByVal)
B.addByValAttr(nullptr);
+ else if (Kind == Attribute::StructRet)
+ B.addStructRetAttr(nullptr);
B.addAttribute(Kind);
} else if (Record[i] == 1) { // Integer attribute
@@ -1652,6 +1654,8 @@ Error BitcodeReader::parseAttributeGroupBlock() {
return Err;
if (Kind == Attribute::ByVal) {
B.addByValAttr(HasType ? getTypeByID(Record[++i]) : nullptr);
+ } else if (Kind == Attribute::StructRet) {
+ B.addStructRetAttr(HasType ? getTypeByID(Record[++i]) : nullptr);
} else if (Kind == Attribute::ByRef) {
B.addByRefAttr(getTypeByID(Record[++i]));
} else if (Kind == Attribute::Preallocated) {
@@ -3286,17 +3290,24 @@ Error BitcodeReader::parseFunctionRecord(ArrayRef<uint64_t> Record) {
Func->setLinkage(getDecodedLinkage(RawLinkage));
Func->setAttributes(getAttributes(Record[4]));
- // Upgrade any old-style byval without a type by propagating the argument's
- // pointee type. There should be no opaque pointers where the byval type is
- // implicit.
+ // Upgrade any old-style byval or sret without a type by propagating the
+ // argument's pointee type. There should be no opaque pointers where the byval
+ // type is implicit.
for (unsigned i = 0; i != Func->arg_size(); ++i) {
- if (!Func->hasParamAttribute(i, Attribute::ByVal))
- continue;
+ for (Attribute::AttrKind Kind : {Attribute::ByVal, Attribute::StructRet}) {
+ if (!Func->hasParamAttribute(i, Kind))
+ continue;
- Type *PTy = cast<FunctionType>(FullFTy)->getParamType(i);
- Func->removeParamAttr(i, Attribute::ByVal);
- Func->addParamAttr(i, Attribute::getWithByValType(
- Context, getPointerElementFlatType(PTy)));
+ Func->removeParamAttr(i, Kind);
+
+ Type *PTy = cast<FunctionType>(FullFTy)->getParamType(i);
+ Type *PtrEltTy = getPointerElementFlatType(PTy);
+ Attribute NewAttr =
+ Kind == Attribute::ByVal
+ ? Attribute::getWithByValType(Context, PtrEltTy)
+ : Attribute::getWithStructRetType(Context, PtrEltTy);
+ Func->addParamAttr(i, NewAttr);
+ }
}
MaybeAlign Alignment;
@@ -3757,16 +3768,22 @@ Error BitcodeReader::typeCheckLoadStoreInst(Type *ValType, Type *PtrType) {
return Error::success();
}
-void BitcodeReader::propagateByValTypes(CallBase *CB,
- ArrayRef<Type *> ArgsFullTys) {
+void BitcodeReader::propagateByValSRetTypes(CallBase *CB,
+ ArrayRef<Type *> ArgsFullTys) {
for (unsigned i = 0; i != CB->arg_size(); ++i) {
- if (!CB->paramHasAttr(i, Attribute::ByVal))
- continue;
+ for (Attribute::AttrKind Kind : {Attribute::ByVal, Attribute::StructRet}) {
+ if (!CB->paramHasAttr(i, Kind))
+ continue;
- CB->removeParamAttr(i, Attribute::ByVal);
- CB->addParamAttr(
- i, Attribute::getWithByValType(
- Context, getPointerElementFlatType(ArgsFullTys[i])));
+ CB->removeParamAttr(i, Kind);
+
+ Type *PtrEltTy = getPointerElementFlatType(ArgsFullTys[i]);
+ Attribute NewAttr =
+ Kind == Attribute::ByVal
+ ? Attribute::getWithByValType(Context, PtrEltTy)
+ : Attribute::getWithStructRetType(Context, PtrEltTy);
+ CB->addParamAttr(i, NewAttr);
+ }
}
}
@@ -4618,7 +4635,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
cast<InvokeInst>(I)->setCallingConv(
static_cast<CallingConv::ID>(CallingConv::MaxID & CCInfo));
cast<InvokeInst>(I)->setAttributes(PAL);
- propagateByValTypes(cast<CallBase>(I), ArgsFullTys);
+ propagateByValSRetTypes(cast<CallBase>(I), ArgsFullTys);
break;
}
@@ -5225,7 +5242,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
TCK = CallInst::TCK_NoTail;
cast<CallInst>(I)->setTailCallKind(TCK);
cast<CallInst>(I)->setAttributes(PAL);
- propagateByValTypes(cast<CallBase>(I), ArgsFullTys);
+ propagateByValSRetTypes(cast<CallBase>(I), ArgsFullTys);
if (FMF.any()) {
if (!isa<FPMathOperator>(I))
return error("Fast-math-flags specified for call without "