diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2021-03-06 13:23:57 -0500 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2021-03-28 11:12:23 -0400 |
commit | 4fefed65637ec46c8c2edad6b07b5569ac61e9e5 (patch) | |
tree | 171d28547e3a06a99265af6ead0f579bcf30a1d8 /llvm/lib/IR/Attributes.cpp | |
parent | c5243c63cda3c740d6e9c7e501f6518c21688da3 (diff) | |
download | llvm-4fefed65637ec46c8c2edad6b07b5569ac61e9e5.zip llvm-4fefed65637ec46c8c2edad6b07b5569ac61e9e5.tar.gz llvm-4fefed65637ec46c8c2edad6b07b5569ac61e9e5.tar.bz2 |
OpaquePtr: Turn inalloca into a type attribute
I think byval/sret and the others are close to being able to rip out
the code to support the missing type case. A lot of this code is
shared with inalloca, so catch this up to the others so that can
happen.
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 78 |
1 files changed, 61 insertions, 17 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 831186a..c174e4f 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -195,6 +195,10 @@ Attribute Attribute::getWithPreallocatedType(LLVMContext &Context, Type *Ty) { return get(Context, Preallocated, Ty); } +Attribute Attribute::getWithInAllocaType(LLVMContext &Context, Type *Ty) { + return get(Context, InAlloca, Ty); +} + Attribute Attribute::getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const Optional<unsigned> &NumElemsArg) { @@ -377,8 +381,6 @@ std::string Attribute::getAsString(bool InAttrGrp) const { return "inaccessiblememonly"; if (hasAttribute(Attribute::InaccessibleMemOrArgMemOnly)) return "inaccessiblemem_or_argmemonly"; - if (hasAttribute(Attribute::InAlloca)) - return "inalloca"; if (hasAttribute(Attribute::InlineHint)) return "inlinehint"; if (hasAttribute(Attribute::InReg)) @@ -484,24 +486,30 @@ std::string Attribute::getAsString(bool InAttrGrp) const { if (hasAttribute(Attribute::MustProgress)) return "mustprogress"; - const bool IsByVal = hasAttribute(Attribute::ByVal); - if (IsByVal || hasAttribute(Attribute::StructRet)) { + if (isTypeAttribute()) { std::string Result; - Result += IsByVal ? "byval" : "sret"; - if (Type *Ty = getValueAsType()) { - raw_string_ostream OS(Result); - Result += '('; - Ty->print(OS, false, true); - OS.flush(); - Result += ')'; + raw_string_ostream OS(Result); + + switch (getKindAsEnum()) { + case Attribute::ByVal: + Result += "byval"; + break; + case Attribute::StructRet: + Result += "sret"; + break; + case Attribute::ByRef: + Result += "byref"; + break; + case Attribute::Preallocated: + Result += "preallocated"; + break; + case Attribute::InAlloca: + Result += "inalloca"; + break; + default: + llvm_unreachable("unhandled type attribute"); } - return Result; - } - const bool IsByRef = hasAttribute(Attribute::ByRef); - if (IsByRef || hasAttribute(Attribute::Preallocated)) { - std::string Result = IsByRef ? "byref" : "preallocated"; - raw_string_ostream OS(Result); Result += '('; getValueAsType()->print(OS, false, true); OS.flush(); @@ -809,6 +817,10 @@ Type *AttributeSet::getPreallocatedType() const { return SetNode ? SetNode->getPreallocatedType() : nullptr; } +Type *AttributeSet::getInAllocaType() const { + return SetNode ? SetNode->getInAllocaType() : nullptr; +} + std::pair<unsigned, Optional<unsigned>> AttributeSet::getAllocSizeArgs() const { return SetNode ? SetNode->getAllocSizeArgs() : std::pair<unsigned, Optional<unsigned>>(0, 0); @@ -915,6 +927,9 @@ AttributeSetNode *AttributeSetNode::get(LLVMContext &C, const AttrBuilder &B) { case Attribute::Preallocated: Attr = Attribute::getWithPreallocatedType(C, B.getPreallocatedType()); break; + case Attribute::InAlloca: + Attr = Attribute::getWithInAllocaType(C, B.getInAllocaType()); + break; case Attribute::Alignment: assert(B.getAlignment() && "Alignment must be set"); Attr = Attribute::getWithAlignment(C, *B.getAlignment()); @@ -1021,6 +1036,12 @@ Type *AttributeSetNode::getPreallocatedType() const { return nullptr; } +Type *AttributeSetNode::getInAllocaType() const { + if (auto A = findEnumAttribute(Attribute::InAlloca)) + return A->getValueAsType(); + return nullptr; +} + uint64_t AttributeSetNode::getDereferenceableBytes() const { if (auto A = findEnumAttribute(Attribute::Dereferenceable)) return A->getDereferenceableBytes(); @@ -1578,6 +1599,10 @@ Type *AttributeList::getParamPreallocatedType(unsigned Index) const { return getAttributes(Index + FirstArgIndex).getPreallocatedType(); } +Type *AttributeList::getParamInAllocaType(unsigned Index) const { + return getAttributes(Index + FirstArgIndex).getInAllocaType(); +} + MaybeAlign AttributeList::getStackAlignment(unsigned Index) const { return getAttributes(Index).getStackAlignment(); } @@ -1699,6 +1724,9 @@ AttrBuilder &AttrBuilder::addAttribute(Attribute Attr) { AllocSizeArgs = Attr.getValueAsInt(); else if (Kind == Attribute::VScaleRange) VScaleRangeArgs = Attr.getValueAsInt(); + else if (Kind == Attribute::InAlloca) + InAllocaType = Attr.getValueAsType(); + return *this; } @@ -1723,6 +1751,8 @@ AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) { ByRefType = nullptr; else if (Val == Attribute::Preallocated) PreallocatedType = nullptr; + else if (Val == Attribute::InAlloca) + InAllocaType = nullptr; else if (Val == Attribute::Dereferenceable) DerefBytes = 0; else if (Val == Attribute::DereferenceableOrNull) @@ -1852,6 +1882,12 @@ AttrBuilder &AttrBuilder::addPreallocatedAttr(Type *Ty) { return *this; } +AttrBuilder &AttrBuilder::addInAllocaAttr(Type *Ty) { + Attrs[Attribute::InAlloca] = true; + InAllocaType = Ty; + return *this; +} + AttrBuilder &AttrBuilder::merge(const AttrBuilder &B) { // FIXME: What if both have alignments, but they don't match?! if (!Alignment) @@ -1881,6 +1917,9 @@ AttrBuilder &AttrBuilder::merge(const AttrBuilder &B) { if (!PreallocatedType) PreallocatedType = B.PreallocatedType; + if (!InAllocaType) + InAllocaType = B.InAllocaType; + if (!VScaleRangeArgs) VScaleRangeArgs = B.VScaleRangeArgs; @@ -1921,6 +1960,9 @@ AttrBuilder &AttrBuilder::remove(const AttrBuilder &B) { if (B.PreallocatedType) PreallocatedType = nullptr; + if (B.InAllocaType) + InAllocaType = nullptr; + if (B.VScaleRangeArgs) VScaleRangeArgs = 0; @@ -1985,6 +2027,7 @@ bool AttrBuilder::operator==(const AttrBuilder &B) const { DerefBytes == B.DerefBytes && ByValType == B.ByValType && StructRetType == B.StructRetType && ByRefType == B.ByRefType && PreallocatedType == B.PreallocatedType && + InAllocaType == B.InAllocaType && VScaleRangeArgs == B.VScaleRangeArgs; } @@ -2014,6 +2057,7 @@ AttrBuilder AttributeFuncs::typeIncompatible(Type *Ty) { .addAttribute(Attribute::ReadOnly) .addAttribute(Attribute::InAlloca) .addPreallocatedAttr(Ty) + .addInAllocaAttr(Ty) .addByValAttr(Ty) .addStructRetAttr(Ty) .addByRefAttr(Ty); |