diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/libs/llvm12/lib/IR/Attributes.cpp | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/llvm12/lib/IR/Attributes.cpp')
-rw-r--r-- | contrib/libs/llvm12/lib/IR/Attributes.cpp | 352 |
1 files changed, 176 insertions, 176 deletions
diff --git a/contrib/libs/llvm12/lib/IR/Attributes.cpp b/contrib/libs/llvm12/lib/IR/Attributes.cpp index c4629decc6..58e23c7885 100644 --- a/contrib/libs/llvm12/lib/IR/Attributes.cpp +++ b/contrib/libs/llvm12/lib/IR/Attributes.cpp @@ -172,14 +172,14 @@ Attribute Attribute::getWithByValType(LLVMContext &Context, Type *Ty) { return get(Context, ByVal, Ty); } -Attribute Attribute::getWithStructRetType(LLVMContext &Context, Type *Ty) { - return get(Context, StructRet, Ty); -} - -Attribute Attribute::getWithByRefType(LLVMContext &Context, Type *Ty) { - return get(Context, ByRef, Ty); -} - +Attribute Attribute::getWithStructRetType(LLVMContext &Context, Type *Ty) { + return get(Context, StructRet, Ty); +} + +Attribute Attribute::getWithByRefType(LLVMContext &Context, Type *Ty) { + return get(Context, ByRef, Ty); +} + Attribute Attribute::getWithPreallocatedType(LLVMContext &Context, Type *Ty) { return get(Context, Preallocated, Ty); } @@ -371,8 +371,8 @@ std::string Attribute::getAsString(bool InAttrGrp) const { return "noalias"; if (hasAttribute(Attribute::NoBuiltin)) return "nobuiltin"; - if (hasAttribute(Attribute::NoCallback)) - return "nocallback"; + if (hasAttribute(Attribute::NoCallback)) + return "nocallback"; if (hasAttribute(Attribute::NoCapture)) return "nocapture"; if (hasAttribute(Attribute::NoDuplicate)) @@ -403,8 +403,8 @@ std::string Attribute::getAsString(bool InAttrGrp) const { return "nocf_check"; if (hasAttribute(Attribute::NoRecurse)) return "norecurse"; - if (hasAttribute(Attribute::NoProfile)) - return "noprofile"; + if (hasAttribute(Attribute::NoProfile)) + return "noprofile"; if (hasAttribute(Attribute::NoUnwind)) return "nounwind"; if (hasAttribute(Attribute::OptForFuzzing)) @@ -451,19 +451,19 @@ std::string Attribute::getAsString(bool InAttrGrp) const { return "zeroext"; if (hasAttribute(Attribute::Cold)) return "cold"; - if (hasAttribute(Attribute::Hot)) - return "hot"; + if (hasAttribute(Attribute::Hot)) + return "hot"; if (hasAttribute(Attribute::ImmArg)) return "immarg"; if (hasAttribute(Attribute::NoUndef)) return "noundef"; - if (hasAttribute(Attribute::MustProgress)) - return "mustprogress"; + if (hasAttribute(Attribute::MustProgress)) + return "mustprogress"; - const bool IsByVal = hasAttribute(Attribute::ByVal); - if (IsByVal || hasAttribute(Attribute::StructRet)) { + const bool IsByVal = hasAttribute(Attribute::ByVal); + if (IsByVal || hasAttribute(Attribute::StructRet)) { std::string Result; - Result += IsByVal ? "byval" : "sret"; + Result += IsByVal ? "byval" : "sret"; if (Type *Ty = getValueAsType()) { raw_string_ostream OS(Result); Result += '('; @@ -474,9 +474,9 @@ std::string Attribute::getAsString(bool InAttrGrp) const { return Result; } - const bool IsByRef = hasAttribute(Attribute::ByRef); - if (IsByRef || hasAttribute(Attribute::Preallocated)) { - std::string Result = IsByRef ? "byref" : "preallocated"; + 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); @@ -757,18 +757,18 @@ uint64_t AttributeSet::getDereferenceableOrNullBytes() const { return SetNode ? SetNode->getDereferenceableOrNullBytes() : 0; } -Type *AttributeSet::getByRefType() const { - return SetNode ? SetNode->getByRefType() : nullptr; -} - +Type *AttributeSet::getByRefType() const { + return SetNode ? SetNode->getByRefType() : nullptr; +} + Type *AttributeSet::getByValType() const { return SetNode ? SetNode->getByValType() : nullptr; } -Type *AttributeSet::getStructRetType() const { - return SetNode ? SetNode->getStructRetType() : nullptr; -} - +Type *AttributeSet::getStructRetType() const { + return SetNode ? SetNode->getStructRetType() : nullptr; +} + Type *AttributeSet::getPreallocatedType() const { return SetNode ? SetNode->getPreallocatedType() : nullptr; } @@ -865,12 +865,12 @@ AttributeSetNode *AttributeSetNode::get(LLVMContext &C, const AttrBuilder &B) { case Attribute::ByVal: Attr = Attribute::getWithByValType(C, B.getByValType()); break; - case Attribute::StructRet: - Attr = Attribute::getWithStructRetType(C, B.getStructRetType()); - break; - case Attribute::ByRef: - Attr = Attribute::getWithByRefType(C, B.getByRefType()); - break; + case Attribute::StructRet: + Attr = Attribute::getWithStructRetType(C, B.getStructRetType()); + break; + case Attribute::ByRef: + Attr = Attribute::getWithByRefType(C, B.getByRefType()); + break; case Attribute::Preallocated: Attr = Attribute::getWithPreallocatedType(C, B.getPreallocatedType()); break; @@ -954,25 +954,25 @@ MaybeAlign AttributeSetNode::getStackAlignment() const { Type *AttributeSetNode::getByValType() const { if (auto A = findEnumAttribute(Attribute::ByVal)) return A->getValueAsType(); - return nullptr; -} - -Type *AttributeSetNode::getStructRetType() const { - if (auto A = findEnumAttribute(Attribute::StructRet)) - return A->getValueAsType(); - return nullptr; -} - -Type *AttributeSetNode::getByRefType() const { - if (auto A = findEnumAttribute(Attribute::ByRef)) - return A->getValueAsType(); - return nullptr; -} - + return nullptr; +} + +Type *AttributeSetNode::getStructRetType() const { + if (auto A = findEnumAttribute(Attribute::StructRet)) + return A->getValueAsType(); + return nullptr; +} + +Type *AttributeSetNode::getByRefType() const { + if (auto A = findEnumAttribute(Attribute::ByRef)) + return A->getValueAsType(); + return nullptr; +} + Type *AttributeSetNode::getPreallocatedType() const { - if (auto A = findEnumAttribute(Attribute::Preallocated)) - return A->getValueAsType(); - return nullptr; + if (auto A = findEnumAttribute(Attribute::Preallocated)) + return A->getValueAsType(); + return nullptr; } uint64_t AttributeSetNode::getDereferenceableBytes() const { @@ -1010,7 +1010,7 @@ std::string AttributeSetNode::getAsString(bool InAttrGrp) const { /// Map from AttributeList index to the internal array index. Adding one happens /// to work, because -1 wraps around to 0. -static unsigned attrIdxToArrayIdx(unsigned Index) { +static unsigned attrIdxToArrayIdx(unsigned Index) { return Index + 1; } @@ -1023,7 +1023,7 @@ AttributeListImpl::AttributeListImpl(ArrayRef<AttributeSet> Sets) // Initialize AvailableFunctionAttrs and AvailableSomewhereAttrs // summary bitsets. - for (const auto &I : Sets[attrIdxToArrayIdx(AttributeList::FunctionIndex)]) + for (const auto &I : Sets[attrIdxToArrayIdx(AttributeList::FunctionIndex)]) if (!I.isStringAttribute()) AvailableFunctionAttrs.addAttribute(I.getKindAsEnum()); @@ -1111,10 +1111,10 @@ AttributeList::get(LLVMContext &C, return LHS.first < RHS.first; }) && "Misordered Attributes list!"); - assert(llvm::all_of(Attrs, - [](const std::pair<unsigned, Attribute> &Pair) { - return Pair.second.isValid(); - }) && + assert(llvm::all_of(Attrs, + [](const std::pair<unsigned, Attribute> &Pair) { + return Pair.second.isValid(); + }) && "Pointless attribute!"); // Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes @@ -1202,7 +1202,7 @@ AttributeList AttributeList::get(LLVMContext &C, AttributeSet FnAttrs, if (NumSets > 2) { // Drop the empty argument attribute sets at the end. ArgAttrs = ArgAttrs.take_front(NumSets - 2); - llvm::append_range(AttrSets, ArgAttrs); + llvm::append_range(AttrSets, ArgAttrs); } return getImpl(C, AttrSets); @@ -1274,11 +1274,11 @@ AttributeList AttributeList::get(LLVMContext &C, AttributeList AttributeList::addAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const { if (hasAttribute(Index, Kind)) return *this; - AttributeSet Attrs = getAttributes(Index); - // TODO: Insert at correct position and avoid sort. - SmallVector<Attribute, 8> NewAttrs(Attrs.begin(), Attrs.end()); - NewAttrs.push_back(Attribute::get(C, Kind)); - return setAttributes(C, Index, AttributeSet::get(C, NewAttrs)); + AttributeSet Attrs = getAttributes(Index); + // TODO: Insert at correct position and avoid sort. + SmallVector<Attribute, 8> NewAttrs(Attrs.begin(), Attrs.end()); + NewAttrs.push_back(Attribute::get(C, Kind)); + return setAttributes(C, Index, AttributeSet::get(C, NewAttrs)); } AttributeList AttributeList::addAttribute(LLVMContext &C, unsigned Index, @@ -1296,16 +1296,16 @@ AttributeList AttributeList::addAttribute(LLVMContext &C, unsigned Index, return addAttributes(C, Index, B); } -AttributeList AttributeList::setAttributes(LLVMContext &C, unsigned Index, - AttributeSet Attrs) const { - Index = attrIdxToArrayIdx(Index); - SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end()); - if (Index >= AttrSets.size()) - AttrSets.resize(Index + 1); - AttrSets[Index] = Attrs; - return AttributeList::getImpl(C, AttrSets); -} - +AttributeList AttributeList::setAttributes(LLVMContext &C, unsigned Index, + AttributeSet Attrs) const { + Index = attrIdxToArrayIdx(Index); + SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end()); + if (Index >= AttrSets.size()) + AttrSets.resize(Index + 1); + AttrSets[Index] = Attrs; + return AttributeList::getImpl(C, AttrSets); +} + AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index, const AttrBuilder &B) const { if (!B.hasAttributes()) @@ -1323,9 +1323,9 @@ AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index, "Attempt to change alignment!"); #endif - AttrBuilder Merged(getAttributes(Index)); + AttrBuilder Merged(getAttributes(Index)); Merged.merge(B); - return setAttributes(C, Index, AttributeSet::get(C, Merged)); + return setAttributes(C, Index, AttributeSet::get(C, Merged)); } AttributeList AttributeList::addParamAttribute(LLVMContext &C, @@ -1495,14 +1495,14 @@ Type *AttributeList::getParamByValType(unsigned Index) const { return getAttributes(Index+FirstArgIndex).getByValType(); } -Type *AttributeList::getParamStructRetType(unsigned Index) const { - return getAttributes(Index + FirstArgIndex).getStructRetType(); -} - -Type *AttributeList::getParamByRefType(unsigned Index) const { - return getAttributes(Index + FirstArgIndex).getByRefType(); -} - +Type *AttributeList::getParamStructRetType(unsigned Index) const { + return getAttributes(Index + FirstArgIndex).getStructRetType(); +} + +Type *AttributeList::getParamByRefType(unsigned Index) const { + return getAttributes(Index + FirstArgIndex).getByRefType(); +} + Type *AttributeList::getParamPreallocatedType(unsigned Index) const { return getAttributes(Index + FirstArgIndex).getPreallocatedType(); } @@ -1588,8 +1588,8 @@ void AttrBuilder::clear() { DerefBytes = DerefOrNullBytes = 0; AllocSizeArgs = 0; ByValType = nullptr; - StructRetType = nullptr; - ByRefType = nullptr; + StructRetType = nullptr; + ByRefType = nullptr; PreallocatedType = nullptr; } @@ -1608,10 +1608,10 @@ AttrBuilder &AttrBuilder::addAttribute(Attribute Attr) { StackAlignment = Attr.getStackAlignment(); else if (Kind == Attribute::ByVal) ByValType = Attr.getValueAsType(); - else if (Kind == Attribute::StructRet) - StructRetType = Attr.getValueAsType(); - else if (Kind == Attribute::ByRef) - ByRefType = Attr.getValueAsType(); + else if (Kind == Attribute::StructRet) + StructRetType = Attr.getValueAsType(); + else if (Kind == Attribute::ByRef) + ByRefType = Attr.getValueAsType(); else if (Kind == Attribute::Preallocated) PreallocatedType = Attr.getValueAsType(); else if (Kind == Attribute::Dereferenceable) @@ -1638,10 +1638,10 @@ AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) { StackAlignment.reset(); else if (Val == Attribute::ByVal) ByValType = nullptr; - else if (Val == Attribute::StructRet) - StructRetType = nullptr; - else if (Val == Attribute::ByRef) - ByRefType = nullptr; + else if (Val == Attribute::StructRet) + StructRetType = nullptr; + else if (Val == Attribute::ByRef) + ByRefType = nullptr; else if (Val == Attribute::Preallocated) PreallocatedType = nullptr; else if (Val == Attribute::Dereferenceable) @@ -1732,18 +1732,18 @@ AttrBuilder &AttrBuilder::addByValAttr(Type *Ty) { return *this; } -AttrBuilder &AttrBuilder::addStructRetAttr(Type *Ty) { - Attrs[Attribute::StructRet] = true; - StructRetType = Ty; - return *this; -} - -AttrBuilder &AttrBuilder::addByRefAttr(Type *Ty) { - Attrs[Attribute::ByRef] = true; - ByRefType = Ty; - return *this; -} - +AttrBuilder &AttrBuilder::addStructRetAttr(Type *Ty) { + Attrs[Attribute::StructRet] = true; + StructRetType = Ty; + return *this; +} + +AttrBuilder &AttrBuilder::addByRefAttr(Type *Ty) { + Attrs[Attribute::ByRef] = true; + ByRefType = Ty; + return *this; +} + AttrBuilder &AttrBuilder::addPreallocatedAttr(Type *Ty) { Attrs[Attribute::Preallocated] = true; PreallocatedType = Ty; @@ -1770,12 +1770,12 @@ AttrBuilder &AttrBuilder::merge(const AttrBuilder &B) { if (!ByValType) ByValType = B.ByValType; - if (!StructRetType) - StructRetType = B.StructRetType; - - if (!ByRefType) - ByRefType = B.ByRefType; - + if (!StructRetType) + StructRetType = B.StructRetType; + + if (!ByRefType) + ByRefType = B.ByRefType; + if (!PreallocatedType) PreallocatedType = B.PreallocatedType; @@ -1807,12 +1807,12 @@ AttrBuilder &AttrBuilder::remove(const AttrBuilder &B) { if (B.ByValType) ByValType = nullptr; - if (B.StructRetType) - StructRetType = nullptr; - - if (B.ByRefType) - ByRefType = nullptr; - + if (B.StructRetType) + StructRetType = nullptr; + + if (B.ByRefType) + ByRefType = nullptr; + if (B.PreallocatedType) PreallocatedType = nullptr; @@ -1876,7 +1876,7 @@ bool AttrBuilder::operator==(const AttrBuilder &B) const { return Alignment == B.Alignment && StackAlignment == B.StackAlignment && DerefBytes == B.DerefBytes && ByValType == B.ByValType && - StructRetType == B.StructRetType && ByRefType == B.ByRefType && + StructRetType == B.StructRetType && ByRefType == B.ByRefType && PreallocatedType == B.PreallocatedType; } @@ -1899,21 +1899,21 @@ AttrBuilder AttributeFuncs::typeIncompatible(Type *Ty) { .addAttribute(Attribute::NoAlias) .addAttribute(Attribute::NoCapture) .addAttribute(Attribute::NonNull) - .addAlignmentAttr(1) // the int here is ignored + .addAlignmentAttr(1) // the int here is ignored .addDereferenceableAttr(1) // the int here is ignored .addDereferenceableOrNullAttr(1) // the int here is ignored .addAttribute(Attribute::ReadNone) .addAttribute(Attribute::ReadOnly) .addAttribute(Attribute::InAlloca) .addPreallocatedAttr(Ty) - .addByValAttr(Ty) - .addStructRetAttr(Ty) - .addByRefAttr(Ty); - - // Some attributes can apply to all "values" but there are no `void` values. - if (Ty->isVoidTy()) - Incompatible.addAttribute(Attribute::NoUndef); - + .addByValAttr(Ty) + .addStructRetAttr(Ty) + .addByRefAttr(Ty); + + // Some attributes can apply to all "values" but there are no `void` values. + if (Ty->isVoidTy()) + Incompatible.addAttribute(Attribute::NoUndef); + return Incompatible; } @@ -1950,16 +1950,16 @@ static void setOR(Function &Caller, const Function &Callee) { /// If the inlined function had a higher stack protection level than the /// calling function, then bump up the caller's stack protection level. static void adjustCallerSSPLevel(Function &Caller, const Function &Callee) { -#ifndef NDEBUG - if (!Callee.hasFnAttribute(Attribute::AlwaysInline)) { - assert(!(!Callee.hasStackProtectorFnAttr() && - Caller.hasStackProtectorFnAttr()) && - "stack protected caller but callee requested no stack protector"); - assert(!(!Caller.hasStackProtectorFnAttr() && - Callee.hasStackProtectorFnAttr()) && - "stack protected callee but caller requested no stack protector"); - } -#endif +#ifndef NDEBUG + if (!Callee.hasFnAttribute(Attribute::AlwaysInline)) { + assert(!(!Callee.hasStackProtectorFnAttr() && + Caller.hasStackProtectorFnAttr()) && + "stack protected caller but callee requested no stack protector"); + assert(!(!Caller.hasStackProtectorFnAttr() && + Callee.hasStackProtectorFnAttr()) && + "stack protected callee but caller requested no stack protector"); + } +#endif // If upgrading the SSP attribute, clear out the old SSP Attributes first. // Having multiple SSP attributes doesn't actually hurt, but it adds useless // clutter to the IR. @@ -1995,19 +1995,19 @@ static void adjustCallerStackProbes(Function &Caller, const Function &Callee) { /// that is no larger. static void adjustCallerStackProbeSize(Function &Caller, const Function &Callee) { - Attribute CalleeAttr = Callee.getFnAttribute("stack-probe-size"); - if (CalleeAttr.isValid()) { - Attribute CallerAttr = Caller.getFnAttribute("stack-probe-size"); - if (CallerAttr.isValid()) { - uint64_t CallerStackProbeSize, CalleeStackProbeSize; - CallerAttr.getValueAsString().getAsInteger(0, CallerStackProbeSize); - CalleeAttr.getValueAsString().getAsInteger(0, CalleeStackProbeSize); - + Attribute CalleeAttr = Callee.getFnAttribute("stack-probe-size"); + if (CalleeAttr.isValid()) { + Attribute CallerAttr = Caller.getFnAttribute("stack-probe-size"); + if (CallerAttr.isValid()) { + uint64_t CallerStackProbeSize, CalleeStackProbeSize; + CallerAttr.getValueAsString().getAsInteger(0, CallerStackProbeSize); + CalleeAttr.getValueAsString().getAsInteger(0, CalleeStackProbeSize); + if (CallerStackProbeSize > CalleeStackProbeSize) { - Caller.addFnAttr(CalleeAttr); + Caller.addFnAttr(CalleeAttr); } } else { - Caller.addFnAttr(CalleeAttr); + Caller.addFnAttr(CalleeAttr); } } } @@ -2023,15 +2023,15 @@ adjustCallerStackProbeSize(Function &Caller, const Function &Callee) { /// handled as part of inline cost analysis. static void adjustMinLegalVectorWidth(Function &Caller, const Function &Callee) { - Attribute CallerAttr = Caller.getFnAttribute("min-legal-vector-width"); - if (CallerAttr.isValid()) { - Attribute CalleeAttr = Callee.getFnAttribute("min-legal-vector-width"); - if (CalleeAttr.isValid()) { - uint64_t CallerVectorWidth, CalleeVectorWidth; - CallerAttr.getValueAsString().getAsInteger(0, CallerVectorWidth); - CalleeAttr.getValueAsString().getAsInteger(0, CalleeVectorWidth); + Attribute CallerAttr = Caller.getFnAttribute("min-legal-vector-width"); + if (CallerAttr.isValid()) { + Attribute CalleeAttr = Callee.getFnAttribute("min-legal-vector-width"); + if (CalleeAttr.isValid()) { + uint64_t CallerVectorWidth, CalleeVectorWidth; + CallerAttr.getValueAsString().getAsInteger(0, CallerVectorWidth); + CalleeAttr.getValueAsString().getAsInteger(0, CalleeVectorWidth); if (CallerVectorWidth < CalleeVectorWidth) - Caller.addFnAttr(CalleeAttr); + Caller.addFnAttr(CalleeAttr); } else { // If the callee doesn't have the attribute then we don't know anything // and must drop the attribute from the caller. @@ -2098,25 +2098,25 @@ bool AttributeFuncs::areInlineCompatible(const Function &Caller, return hasCompatibleFnAttrs(Caller, Callee); } -bool AttributeFuncs::areOutlineCompatible(const Function &A, - const Function &B) { - return hasCompatibleFnAttrs(A, B); -} - +bool AttributeFuncs::areOutlineCompatible(const Function &A, + const Function &B) { + return hasCompatibleFnAttrs(A, B); +} + void AttributeFuncs::mergeAttributesForInlining(Function &Caller, const Function &Callee) { mergeFnAttrs(Caller, Callee); } - -void AttributeFuncs::mergeAttributesForOutlining(Function &Base, - const Function &ToMerge) { - - // We merge functions so that they meet the most general case. - // For example, if the NoNansFPMathAttr is set in one function, but not in - // the other, in the merged function we can say that the NoNansFPMathAttr - // is not set. - // However if we have the SpeculativeLoadHardeningAttr set true in one - // function, but not the other, we make sure that the function retains - // that aspect in the merged function. - mergeFnAttrs(Base, ToMerge); -} + +void AttributeFuncs::mergeAttributesForOutlining(Function &Base, + const Function &ToMerge) { + + // We merge functions so that they meet the most general case. + // For example, if the NoNansFPMathAttr is set in one function, but not in + // the other, in the merged function we can say that the NoNansFPMathAttr + // is not set. + // However if we have the SpeculativeLoadHardeningAttr set true in one + // function, but not the other, we make sure that the function retains + // that aspect in the merged function. + mergeFnAttrs(Base, ToMerge); +} |