diff options
| author | 2017-01-24 08:32:59 +0000 | |
|---|---|---|
| committer | 2017-01-24 08:32:59 +0000 | |
| commit | 53d771aafdbe5b919f264f53cba3788e2c4cffd2 (patch) | |
| tree | 7eca39498be0ff1e3a6daf583cd9ca5886bb2636 /gnu/llvm/lib/IR/Attributes.cpp | |
| parent | In preparation of compiling our kernels with -ffreestanding, explicitly map (diff) | |
| download | wireguard-openbsd-53d771aafdbe5b919f264f53cba3788e2c4cffd2.tar.xz wireguard-openbsd-53d771aafdbe5b919f264f53cba3788e2c4cffd2.zip | |
Import LLVM 4.0.0 rc1 including clang and lld to help the current
development effort on OpenBSD/arm64.
Diffstat (limited to 'gnu/llvm/lib/IR/Attributes.cpp')
| -rw-r--r-- | gnu/llvm/lib/IR/Attributes.cpp | 179 |
1 files changed, 28 insertions, 151 deletions
diff --git a/gnu/llvm/lib/IR/Attributes.cpp b/gnu/llvm/lib/IR/Attributes.cpp index d774c1ae9df..1ec53cf1e1d 100644 --- a/gnu/llvm/lib/IR/Attributes.cpp +++ b/gnu/llvm/lib/IR/Attributes.cpp @@ -38,7 +38,7 @@ using namespace llvm; // // In order to do this, we need to reserve one value of the second (optional) // allocsize argument to signify "not present." -LLVM_CONSTEXPR static unsigned AllocSizeNumElemsNotPresent = -1; +static const unsigned AllocSizeNumElemsNotPresent = -1; static uint64_t packAllocSizeArgs(unsigned ElemSizeArg, const Optional<unsigned> &NumElemsArg) { @@ -381,10 +381,18 @@ std::string Attribute::getAsString(bool InAttrGrp) const { std::string Result; Result += (Twine('"') + getKindAsString() + Twine('"')).str(); - StringRef Val = pImpl->getValueAsString(); - if (Val.empty()) return Result; - - Result += ("=\"" + Val + Twine('"')).str(); + std::string AttrVal = pImpl->getValueAsString(); + if (AttrVal.empty()) return Result; + + // Since some attribute strings contain special characters that cannot be + // printable, those have to be escaped to make the attribute value printable + // as is. e.g. "\01__gnu_mcount_nc" + { + raw_string_ostream OS(Result); + OS << "=\""; + PrintEscapedString(AttrVal, OS); + OS << "\""; + } return Result; } @@ -464,78 +472,6 @@ bool AttributeImpl::operator<(const AttributeImpl &AI) const { return getKindAsString() < AI.getKindAsString(); } -uint64_t AttributeImpl::getAttrMask(Attribute::AttrKind Val) { - // FIXME: Remove this. - switch (Val) { - case Attribute::EndAttrKinds: - llvm_unreachable("Synthetic enumerators which should never get here"); - - case Attribute::None: return 0; - case Attribute::ZExt: return 1 << 0; - case Attribute::SExt: return 1 << 1; - case Attribute::NoReturn: return 1 << 2; - case Attribute::InReg: return 1 << 3; - case Attribute::StructRet: return 1 << 4; - case Attribute::NoUnwind: return 1 << 5; - case Attribute::NoAlias: return 1 << 6; - case Attribute::ByVal: return 1 << 7; - case Attribute::Nest: return 1 << 8; - case Attribute::ReadNone: return 1 << 9; - case Attribute::ReadOnly: return 1 << 10; - case Attribute::NoInline: return 1 << 11; - case Attribute::AlwaysInline: return 1 << 12; - case Attribute::OptimizeForSize: return 1 << 13; - case Attribute::StackProtect: return 1 << 14; - case Attribute::StackProtectReq: return 1 << 15; - case Attribute::Alignment: return 31 << 16; - case Attribute::NoCapture: return 1 << 21; - case Attribute::NoRedZone: return 1 << 22; - case Attribute::NoImplicitFloat: return 1 << 23; - case Attribute::Naked: return 1 << 24; - case Attribute::InlineHint: return 1 << 25; - case Attribute::StackAlignment: return 7 << 26; - case Attribute::ReturnsTwice: return 1 << 29; - case Attribute::UWTable: return 1 << 30; - case Attribute::NonLazyBind: return 1U << 31; - case Attribute::SanitizeAddress: return 1ULL << 32; - case Attribute::MinSize: return 1ULL << 33; - case Attribute::NoDuplicate: return 1ULL << 34; - case Attribute::StackProtectStrong: return 1ULL << 35; - case Attribute::SanitizeThread: return 1ULL << 36; - case Attribute::SanitizeMemory: return 1ULL << 37; - case Attribute::NoBuiltin: return 1ULL << 38; - case Attribute::Returned: return 1ULL << 39; - case Attribute::Cold: return 1ULL << 40; - case Attribute::Builtin: return 1ULL << 41; - case Attribute::OptimizeNone: return 1ULL << 42; - case Attribute::InAlloca: return 1ULL << 43; - case Attribute::NonNull: return 1ULL << 44; - case Attribute::JumpTable: return 1ULL << 45; - case Attribute::Convergent: return 1ULL << 46; - case Attribute::SafeStack: return 1ULL << 47; - case Attribute::NoRecurse: return 1ULL << 48; - case Attribute::InaccessibleMemOnly: return 1ULL << 49; - case Attribute::InaccessibleMemOrArgMemOnly: return 1ULL << 50; - case Attribute::SwiftSelf: return 1ULL << 51; - case Attribute::SwiftError: return 1ULL << 52; - case Attribute::WriteOnly: return 1ULL << 53; - case Attribute::Dereferenceable: - llvm_unreachable("dereferenceable attribute not supported in raw format"); - break; - case Attribute::DereferenceableOrNull: - llvm_unreachable("dereferenceable_or_null attribute not supported in raw " - "format"); - break; - case Attribute::ArgMemOnly: - llvm_unreachable("argmemonly attribute not supported in raw format"); - break; - case Attribute::AllocSize: - llvm_unreachable("allocsize not supported in raw format"); - break; - } - llvm_unreachable("Unsupported attribute type"); -} - //===----------------------------------------------------------------------===// // AttributeSetNode Definition //===----------------------------------------------------------------------===// @@ -645,39 +581,6 @@ std::string AttributeSetNode::getAsString(bool InAttrGrp) const { // AttributeSetImpl Definition //===----------------------------------------------------------------------===// -uint64_t AttributeSetImpl::Raw(unsigned Index) const { - for (unsigned I = 0, E = getNumSlots(); I != E; ++I) { - if (getSlotIndex(I) != Index) continue; - const AttributeSetNode *ASN = getSlotNode(I); - uint64_t Mask = 0; - - for (AttributeSetNode::iterator II = ASN->begin(), - IE = ASN->end(); II != IE; ++II) { - Attribute Attr = *II; - - // This cannot handle string attributes. - if (Attr.isStringAttribute()) continue; - - Attribute::AttrKind Kind = Attr.getKindAsEnum(); - - if (Kind == Attribute::Alignment) - Mask |= (Log2_32(ASN->getAlignment()) + 1) << 16; - else if (Kind == Attribute::StackAlignment) - Mask |= (Log2_32(ASN->getStackAlignment()) + 1) << 26; - else if (Kind == Attribute::Dereferenceable) - llvm_unreachable("dereferenceable not supported in bit mask"); - else if (Kind == Attribute::AllocSize) - llvm_unreachable("allocsize not supported in bit mask"); - else - Mask |= AttributeImpl::getAttrMask(Kind); - } - - return Mask; - } - - return 0; -} - LLVM_DUMP_METHOD void AttributeSetImpl::dump() const { AttributeSet(const_cast<AttributeSetImpl *>(this)).dump(); } @@ -721,10 +624,11 @@ AttributeSet AttributeSet::get(LLVMContext &C, const std::pair<unsigned, Attribute> &RHS) { return LHS.first < RHS.first; }) && "Misordered Attributes list!"); - assert(std::none_of(Attrs.begin(), Attrs.end(), - [](const std::pair<unsigned, Attribute> &Pair) { - return Pair.second.hasAttribute(Attribute::None); - }) && "Pointless attribute!"); + assert(none_of(Attrs, + [](const std::pair<unsigned, Attribute> &Pair) { + return Pair.second.hasAttribute(Attribute::None); + }) && + "Pointless attribute!"); // Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes // list. @@ -738,8 +642,7 @@ AttributeSet AttributeSet::get(LLVMContext &C, ++I; } - AttrPairVec.push_back(std::make_pair(Index, - AttributeSetNode::get(C, AttrVec))); + AttrPairVec.emplace_back(Index, AttributeSetNode::get(C, AttrVec)); } return getImpl(C, AttrPairVec); @@ -791,13 +694,12 @@ AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index, default: Attr = Attribute::get(C, Kind); } - Attrs.push_back(std::make_pair(Index, Attr)); + Attrs.emplace_back(Index, Attr); } // Add target-dependent (string) attributes. for (const auto &TDA : B.td_attrs()) - Attrs.push_back( - std::make_pair(Index, Attribute::get(C, TDA.first, TDA.second))); + Attrs.emplace_back(Index, Attribute::get(C, TDA.first, TDA.second)); return get(C, Attrs); } @@ -806,7 +708,7 @@ AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index, ArrayRef<Attribute::AttrKind> Kinds) { SmallVector<std::pair<unsigned, Attribute>, 8> Attrs; for (Attribute::AttrKind K : Kinds) - Attrs.push_back(std::make_pair(Index, Attribute::get(C, K))); + Attrs.emplace_back(Index, Attribute::get(C, K)); return get(C, Attrs); } @@ -814,7 +716,7 @@ AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index, ArrayRef<StringRef> Kinds) { SmallVector<std::pair<unsigned, Attribute>, 8> Attrs; for (StringRef K : Kinds) - Attrs.push_back(std::make_pair(Index, Attribute::get(C, K))); + Attrs.emplace_back(Index, Attribute::get(C, K)); return get(C, Attrs); } @@ -1108,6 +1010,10 @@ bool AttributeSet::hasFnAttribute(Attribute::AttrKind Kind) const { return pImpl && pImpl->hasFnAttribute(Kind); } +bool AttributeSet::hasFnAttribute(StringRef Kind) const { + return hasAttribute(AttributeSet::FunctionIndex, Kind); +} + bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr, unsigned *Index) const { if (!pImpl) return false; @@ -1158,7 +1064,7 @@ uint64_t AttributeSet::getDereferenceableOrNullBytes(unsigned Index) const { std::pair<unsigned, Optional<unsigned>> AttributeSet::getAllocSizeArgs(unsigned Index) const { AttributeSetNode *ASN = getAttributes(Index); - return ASN ? ASN->getAllocSizeArgs() : std::make_pair(0, 0); + return ASN ? ASN->getAllocSizeArgs() : std::make_pair(0u, Optional<unsigned>(0u)); } std::string AttributeSet::getAsString(unsigned Index, bool InAttrGrp) const { @@ -1209,11 +1115,6 @@ AttributeSet AttributeSet::getSlotAttributes(unsigned Slot) const { return pImpl->getSlotAttributes(Slot); } -uint64_t AttributeSet::Raw(unsigned Index) const { - // FIXME: Remove this. - return pImpl ? pImpl->Raw(Index) : 0; -} - LLVM_DUMP_METHOD void AttributeSet::dump() const { dbgs() << "PAL[\n"; @@ -1514,30 +1415,6 @@ bool AttrBuilder::operator==(const AttrBuilder &B) { DerefBytes == B.DerefBytes; } -AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) { - // FIXME: Remove this in 4.0. - if (!Val) return *this; - - for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds; - I = Attribute::AttrKind(I + 1)) { - if (I == Attribute::Dereferenceable || - I == Attribute::DereferenceableOrNull || - I == Attribute::ArgMemOnly || - I == Attribute::AllocSize) - continue; - if (uint64_t A = (Val & AttributeImpl::getAttrMask(I))) { - Attrs[I] = true; - - if (I == Attribute::Alignment) - Alignment = 1ULL << ((A >> 16) - 1); - else if (I == Attribute::StackAlignment) - StackAlignment = 1ULL << ((A >> 26)-1); - } - } - - return *this; -} - //===----------------------------------------------------------------------===// // AttributeFuncs Function Defintions //===----------------------------------------------------------------------===// |
