diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/IR/Function.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/IR/Function.cpp | 229 |
1 files changed, 137 insertions, 92 deletions
diff --git a/contrib/llvm-project/llvm/lib/IR/Function.cpp b/contrib/llvm-project/llvm/lib/IR/Function.cpp index 4034b1505bd0..82b20a8af91b 100644 --- a/contrib/llvm-project/llvm/lib/IR/Function.cpp +++ b/contrib/llvm-project/llvm/lib/IR/Function.cpp @@ -140,25 +140,25 @@ bool Argument::hasPreallocatedAttr() const { bool Argument::hasPassPointeeByValueCopyAttr() const { if (!getType()->isPointerTy()) return false; AttributeList Attrs = getParent()->getAttributes(); - return Attrs.hasParamAttribute(getArgNo(), Attribute::ByVal) || - Attrs.hasParamAttribute(getArgNo(), Attribute::InAlloca) || - Attrs.hasParamAttribute(getArgNo(), Attribute::Preallocated); + return Attrs.hasParamAttr(getArgNo(), Attribute::ByVal) || + Attrs.hasParamAttr(getArgNo(), Attribute::InAlloca) || + Attrs.hasParamAttr(getArgNo(), Attribute::Preallocated); } bool Argument::hasPointeeInMemoryValueAttr() const { if (!getType()->isPointerTy()) return false; AttributeList Attrs = getParent()->getAttributes(); - return Attrs.hasParamAttribute(getArgNo(), Attribute::ByVal) || - Attrs.hasParamAttribute(getArgNo(), Attribute::StructRet) || - Attrs.hasParamAttribute(getArgNo(), Attribute::InAlloca) || - Attrs.hasParamAttribute(getArgNo(), Attribute::Preallocated) || - Attrs.hasParamAttribute(getArgNo(), Attribute::ByRef); + return Attrs.hasParamAttr(getArgNo(), Attribute::ByVal) || + Attrs.hasParamAttr(getArgNo(), Attribute::StructRet) || + Attrs.hasParamAttr(getArgNo(), Attribute::InAlloca) || + Attrs.hasParamAttr(getArgNo(), Attribute::Preallocated) || + Attrs.hasParamAttr(getArgNo(), Attribute::ByRef); } /// For a byval, sret, inalloca, or preallocated parameter, get the in-memory /// parameter type. -static Type *getMemoryParamAllocType(AttributeSet ParamAttrs, Type *ArgTy) { +static Type *getMemoryParamAllocType(AttributeSet ParamAttrs) { // FIXME: All the type carrying attributes are mutually exclusive, so there // should be a single query to get the stored type that handles any of them. if (Type *ByValTy = ParamAttrs.getByValType()) @@ -177,19 +177,19 @@ static Type *getMemoryParamAllocType(AttributeSet ParamAttrs, Type *ArgTy) { uint64_t Argument::getPassPointeeByValueCopySize(const DataLayout &DL) const { AttributeSet ParamAttrs = - getParent()->getAttributes().getParamAttributes(getArgNo()); - if (Type *MemTy = getMemoryParamAllocType(ParamAttrs, getType())) + getParent()->getAttributes().getParamAttrs(getArgNo()); + if (Type *MemTy = getMemoryParamAllocType(ParamAttrs)) return DL.getTypeAllocSize(MemTy); return 0; } Type *Argument::getPointeeInMemoryValueType() const { AttributeSet ParamAttrs = - getParent()->getAttributes().getParamAttributes(getArgNo()); - return getMemoryParamAllocType(ParamAttrs, getType()); + getParent()->getAttributes().getParamAttrs(getArgNo()); + return getMemoryParamAllocType(ParamAttrs); } -unsigned Argument::getParamAlignment() const { +uint64_t Argument::getParamAlignment() const { assert(getType()->isPointerTy() && "Only pointers have alignments"); return getParent()->getParamAlignment(getArgNo()); } @@ -278,8 +278,8 @@ bool Argument::hasSExtAttr() const { bool Argument::onlyReadsMemory() const { AttributeList Attrs = getParent()->getAttributes(); - return Attrs.hasParamAttribute(getArgNo(), Attribute::ReadOnly) || - Attrs.hasParamAttribute(getArgNo(), Attribute::ReadNone); + return Attrs.hasParamAttr(getArgNo(), Attribute::ReadOnly) || + Attrs.hasParamAttr(getArgNo(), Attribute::ReadNone); } void Argument::addAttrs(AttrBuilder &B) { @@ -354,7 +354,7 @@ Function *Function::createWithDefaultAttr(FunctionType *Ty, B.addAttribute("frame-pointer", "all"); break; } - F->addAttributes(AttributeList::FunctionIndex, B); + F->addFnAttrs(B); return F; } @@ -529,101 +529,144 @@ void Function::dropAllReferences() { clearMetadata(); } -void Function::addAttribute(unsigned i, Attribute::AttrKind Kind) { - AttributeList PAL = getAttributes(); - PAL = PAL.addAttribute(getContext(), i, Kind); - setAttributes(PAL); +void Function::addAttributeAtIndex(unsigned i, Attribute Attr) { + AttributeSets = AttributeSets.addAttributeAtIndex(getContext(), i, Attr); } -void Function::addAttribute(unsigned i, Attribute Attr) { - AttributeList PAL = getAttributes(); - PAL = PAL.addAttribute(getContext(), i, Attr); - setAttributes(PAL); +void Function::addFnAttr(Attribute::AttrKind Kind) { + AttributeSets = AttributeSets.addFnAttribute(getContext(), Kind); } -void Function::addAttributes(unsigned i, const AttrBuilder &Attrs) { - AttributeList PAL = getAttributes(); - PAL = PAL.addAttributes(getContext(), i, Attrs); - setAttributes(PAL); +void Function::addFnAttr(StringRef Kind, StringRef Val) { + AttributeSets = AttributeSets.addFnAttribute(getContext(), Kind, Val); +} + +void Function::addFnAttr(Attribute Attr) { + AttributeSets = AttributeSets.addFnAttribute(getContext(), Attr); +} + +void Function::addFnAttrs(const AttrBuilder &Attrs) { + AttributeSets = AttributeSets.addFnAttributes(getContext(), Attrs); +} + +void Function::addRetAttr(Attribute::AttrKind Kind) { + AttributeSets = AttributeSets.addRetAttribute(getContext(), Kind); +} + +void Function::addRetAttr(Attribute Attr) { + AttributeSets = AttributeSets.addRetAttribute(getContext(), Attr); +} + +void Function::addRetAttrs(const AttrBuilder &Attrs) { + AttributeSets = AttributeSets.addRetAttributes(getContext(), Attrs); } void Function::addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) { - AttributeList PAL = getAttributes(); - PAL = PAL.addParamAttribute(getContext(), ArgNo, Kind); - setAttributes(PAL); + AttributeSets = AttributeSets.addParamAttribute(getContext(), ArgNo, Kind); } void Function::addParamAttr(unsigned ArgNo, Attribute Attr) { - AttributeList PAL = getAttributes(); - PAL = PAL.addParamAttribute(getContext(), ArgNo, Attr); - setAttributes(PAL); + AttributeSets = AttributeSets.addParamAttribute(getContext(), ArgNo, Attr); } void Function::addParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) { - AttributeList PAL = getAttributes(); - PAL = PAL.addParamAttributes(getContext(), ArgNo, Attrs); - setAttributes(PAL); + AttributeSets = AttributeSets.addParamAttributes(getContext(), ArgNo, Attrs); } -void Function::removeAttribute(unsigned i, Attribute::AttrKind Kind) { - AttributeList PAL = getAttributes(); - PAL = PAL.removeAttribute(getContext(), i, Kind); - setAttributes(PAL); +void Function::removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) { + AttributeSets = AttributeSets.removeAttributeAtIndex(getContext(), i, Kind); } -void Function::removeAttribute(unsigned i, StringRef Kind) { - AttributeList PAL = getAttributes(); - PAL = PAL.removeAttribute(getContext(), i, Kind); - setAttributes(PAL); +void Function::removeAttributeAtIndex(unsigned i, StringRef Kind) { + AttributeSets = AttributeSets.removeAttributeAtIndex(getContext(), i, Kind); } -void Function::removeAttributes(unsigned i, const AttrBuilder &Attrs) { - AttributeList PAL = getAttributes(); - PAL = PAL.removeAttributes(getContext(), i, Attrs); - setAttributes(PAL); +void Function::removeFnAttr(Attribute::AttrKind Kind) { + AttributeSets = AttributeSets.removeFnAttribute(getContext(), Kind); +} + +void Function::removeFnAttr(StringRef Kind) { + AttributeSets = AttributeSets.removeFnAttribute(getContext(), Kind); +} + +void Function::removeFnAttrs(const AttrBuilder &Attrs) { + AttributeSets = AttributeSets.removeFnAttributes(getContext(), Attrs); +} + +void Function::removeRetAttr(Attribute::AttrKind Kind) { + AttributeSets = AttributeSets.removeRetAttribute(getContext(), Kind); +} + +void Function::removeRetAttr(StringRef Kind) { + AttributeSets = AttributeSets.removeRetAttribute(getContext(), Kind); +} + +void Function::removeRetAttrs(const AttrBuilder &Attrs) { + AttributeSets = AttributeSets.removeRetAttributes(getContext(), Attrs); } void Function::removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) { - AttributeList PAL = getAttributes(); - PAL = PAL.removeParamAttribute(getContext(), ArgNo, Kind); - setAttributes(PAL); + AttributeSets = AttributeSets.removeParamAttribute(getContext(), ArgNo, Kind); } void Function::removeParamAttr(unsigned ArgNo, StringRef Kind) { - AttributeList PAL = getAttributes(); - PAL = PAL.removeParamAttribute(getContext(), ArgNo, Kind); - setAttributes(PAL); + AttributeSets = AttributeSets.removeParamAttribute(getContext(), ArgNo, Kind); } void Function::removeParamAttrs(unsigned ArgNo, const AttrBuilder &Attrs) { - AttributeList PAL = getAttributes(); - PAL = PAL.removeParamAttributes(getContext(), ArgNo, Attrs); - setAttributes(PAL); + AttributeSets = + AttributeSets.removeParamAttributes(getContext(), ArgNo, Attrs); +} + +void Function::addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes) { + AttributeSets = + AttributeSets.addDereferenceableParamAttr(getContext(), ArgNo, Bytes); } -void Function::addDereferenceableAttr(unsigned i, uint64_t Bytes) { - AttributeList PAL = getAttributes(); - PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes); - setAttributes(PAL); +bool Function::hasFnAttribute(Attribute::AttrKind Kind) const { + return AttributeSets.hasFnAttr(Kind); } -void Function::addDereferenceableParamAttr(unsigned ArgNo, uint64_t Bytes) { - AttributeList PAL = getAttributes(); - PAL = PAL.addDereferenceableParamAttr(getContext(), ArgNo, Bytes); - setAttributes(PAL); +bool Function::hasFnAttribute(StringRef Kind) const { + return AttributeSets.hasFnAttr(Kind); +} + +bool Function::hasRetAttribute(Attribute::AttrKind Kind) const { + return AttributeSets.hasRetAttr(Kind); +} + +bool Function::hasParamAttribute(unsigned ArgNo, + Attribute::AttrKind Kind) const { + return AttributeSets.hasParamAttr(ArgNo, Kind); +} + +Attribute Function::getAttributeAtIndex(unsigned i, + Attribute::AttrKind Kind) const { + return AttributeSets.getAttributeAtIndex(i, Kind); +} + +Attribute Function::getAttributeAtIndex(unsigned i, StringRef Kind) const { + return AttributeSets.getAttributeAtIndex(i, Kind); } -void Function::addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes) { - AttributeList PAL = getAttributes(); - PAL = PAL.addDereferenceableOrNullAttr(getContext(), i, Bytes); - setAttributes(PAL); +Attribute Function::getFnAttribute(Attribute::AttrKind Kind) const { + return AttributeSets.getFnAttr(Kind); +} + +Attribute Function::getFnAttribute(StringRef Kind) const { + return AttributeSets.getFnAttr(Kind); +} + +/// gets the specified attribute from the list of attributes. +Attribute Function::getParamAttribute(unsigned ArgNo, + Attribute::AttrKind Kind) const { + return AttributeSets.getParamAttr(ArgNo, Kind); } void Function::addDereferenceableOrNullParamAttr(unsigned ArgNo, uint64_t Bytes) { - AttributeList PAL = getAttributes(); - PAL = PAL.addDereferenceableOrNullParamAttr(getContext(), ArgNo, Bytes); - setAttributes(PAL); + AttributeSets = AttributeSets.addDereferenceableOrNullParamAttr(getContext(), + ArgNo, Bytes); } DenormalMode Function::getDenormalMode(const fltSemantics &FPType) const { @@ -936,7 +979,8 @@ enum IIT_Info { IIT_BF16 = 48, IIT_STRUCT9 = 49, IIT_V256 = 50, - IIT_AMX = 51 + IIT_AMX = 51, + IIT_PPCF128 = 52 }; static void DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos, @@ -983,6 +1027,9 @@ static void DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos, case IIT_F128: OutputTable.push_back(IITDescriptor::get(IITDescriptor::Quad, 0)); return; + case IIT_PPCF128: + OutputTable.push_back(IITDescriptor::get(IITDescriptor::PPCQuad, 0)); + return; case IIT_I1: OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 1)); return; @@ -1207,6 +1254,7 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos, case IITDescriptor::Float: return Type::getFloatTy(Context); case IITDescriptor::Double: return Type::getDoubleTy(Context); case IITDescriptor::Quad: return Type::getFP128Ty(Context); + case IITDescriptor::PPCQuad: return Type::getPPC_FP128Ty(Context); case IITDescriptor::Integer: return IntegerType::get(Context, D.Integer_Width); @@ -1389,6 +1437,7 @@ static bool matchIntrinsicType( case IITDescriptor::Float: return !Ty->isFloatTy(); case IITDescriptor::Double: return !Ty->isDoubleTy(); case IITDescriptor::Quad: return !Ty->isFP128Ty(); + case IITDescriptor::PPCQuad: return !Ty->isPPC_FP128Ty(); case IITDescriptor::Integer: return !Ty->isIntegerTy(D.Integer_Width); case IITDescriptor::Vector: { VectorType *VT = dyn_cast<VectorType>(Ty); @@ -1403,11 +1452,6 @@ static bool matchIntrinsicType( if (!PT->isOpaque()) return matchIntrinsicType(PT->getElementType(), Infos, ArgTys, DeferredChecks, IsDeferredCheck); - // If typed pointers are supported, do not allow using opaque pointer in - // place of fixed pointer type. This would make the intrinsic signature - // non-unique. - if (Ty->getContext().supportsTypedPointers()) - return true; // Consume IIT descriptors relating to the pointer element type. while (Infos.front().Kind == IITDescriptor::Pointer) Infos = Infos.slice(1); @@ -1525,11 +1569,8 @@ static bool matchIntrinsicType( if (!ThisArgType || !ReferenceType) return true; - if (!ThisArgType->isOpaque()) - return ThisArgType->getElementType() != ReferenceType->getElementType(); - // If typed pointers are supported, do not allow opaque pointer to ensure - // uniqueness. - return Ty->getContext().supportsTypedPointers(); + return !ThisArgType->isOpaqueOrPointeeTypeMatches( + ReferenceType->getElementType()); } case IITDescriptor::VecOfAnyPtrsToElt: { unsigned RefArgNumber = D.getRefArgNumber(); @@ -1702,8 +1743,8 @@ Optional<Function *> Intrinsic::remangleIntrinsicFunction(Function *F) { /// and llvm.compiler.used variables. bool Function::hasAddressTaken(const User **PutOffender, bool IgnoreCallbackUses, - bool IgnoreAssumeLikeCalls, - bool IgnoreLLVMUsed) const { + bool IgnoreAssumeLikeCalls, bool IgnoreLLVMUsed, + bool IgnoreARCAttachedCall) const { for (const Use &U : uses()) { const User *FU = U.getUser(); if (isa<BlockAddress>(FU)) @@ -1747,6 +1788,11 @@ bool Function::hasAddressTaken(const User **PutOffender, return true; } if (!Call->isCallee(&U)) { + if (IgnoreARCAttachedCall && + Call->isOperandBundleOfType(LLVMContext::OB_clang_arc_attachedcall, + U.getOperandNo())) + continue; + if (PutOffender) *PutOffender = FU; return true; @@ -1846,10 +1892,9 @@ void Function::setValueSubclassDataBit(unsigned Bit, bool On) { void Function::setEntryCount(ProfileCount Count, const DenseSet<GlobalValue::GUID> *S) { - assert(Count.hasValue()); #if !defined(NDEBUG) auto PrevCount = getEntryCount(); - assert(!PrevCount.hasValue() || PrevCount.getType() == Count.getType()); + assert(!PrevCount.hasValue() || PrevCount->getType() == Count.getType()); #endif auto ImportGUIDs = getImportGUIDs(); @@ -1867,7 +1912,7 @@ void Function::setEntryCount(uint64_t Count, Function::ProfileCountType Type, setEntryCount(ProfileCount(Count, Type), Imports); } -ProfileCount Function::getEntryCount(bool AllowSynthetic) const { +Optional<ProfileCount> Function::getEntryCount(bool AllowSynthetic) const { MDNode *MD = getMetadata(LLVMContext::MD_prof); if (MD && MD->getOperand(0)) if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0))) { @@ -1877,7 +1922,7 @@ ProfileCount Function::getEntryCount(bool AllowSynthetic) const { // A value of -1 is used for SamplePGO when there were no samples. // Treat this the same as unknown. if (Count == (uint64_t)-1) - return ProfileCount::getInvalid(); + return None; return ProfileCount(Count, PCT_Real); } else if (AllowSynthetic && MDS->getString().equals("synthetic_function_entry_count")) { @@ -1886,7 +1931,7 @@ ProfileCount Function::getEntryCount(bool AllowSynthetic) const { return ProfileCount(Count, PCT_Synthetic); } } - return ProfileCount::getInvalid(); + return None; } DenseSet<GlobalValue::GUID> Function::getImportGUIDs() const { |