1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[IR] Fix some Clang-tidy modernize-use-auto warnings; other minor fixes (NFC).

llvm-svn: 328850
This commit is contained in:
Eugene Zelenko 2018-03-30 00:47:31 +00:00
parent 1fe0ee8df0
commit 6d05e6705c
4 changed files with 288 additions and 167 deletions

View File

@ -6,11 +6,11 @@
// License. See LICENSE.TXT for details. // License. See LICENSE.TXT for details.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// //
/// \file /// \file
/// \brief This file contains the simple types necessary to represent the /// \brief This file contains the simple types necessary to represent the
/// attributes associated with functions and their calls. /// attributes associated with functions and their calls.
/// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#ifndef LLVM_IR_ATTRIBUTES_H #ifndef LLVM_IR_ATTRIBUTES_H
@ -35,7 +35,6 @@ namespace llvm {
class AttrBuilder; class AttrBuilder;
class AttributeImpl; class AttributeImpl;
class AttributeListImpl; class AttributeListImpl;
class AttributeList;
class AttributeSetNode; class AttributeSetNode;
template<typename T> struct DenseMapInfo; template<typename T> struct DenseMapInfo;
class Function; class Function;
@ -203,6 +202,9 @@ inline Attribute unwrap(LLVMAttributeRef Attr) {
/// copy. Adding and removing enum attributes is intended to be fast, but adding /// copy. Adding and removing enum attributes is intended to be fast, but adding
/// and removing string or integer attributes involves a FoldingSet lookup. /// and removing string or integer attributes involves a FoldingSet lookup.
class AttributeSet { class AttributeSet {
friend AttributeListImpl;
template <typename Ty> friend struct DenseMapInfo;
// TODO: Extract AvailableAttrs from AttributeSetNode and store them here. // TODO: Extract AvailableAttrs from AttributeSetNode and store them here.
// This will allow an efficient implementation of addAttribute and // This will allow an efficient implementation of addAttribute and
// removeAttribute for enum attrs. // removeAttribute for enum attrs.
@ -210,9 +212,6 @@ class AttributeSet {
/// Private implementation pointer. /// Private implementation pointer.
AttributeSetNode *SetNode = nullptr; AttributeSetNode *SetNode = nullptr;
friend AttributeListImpl;
template <typename Ty> friend struct DenseMapInfo;
private: private:
explicit AttributeSet(AttributeSetNode *ASN) : SetNode(ASN) {} explicit AttributeSet(AttributeSetNode *ASN) : SetNode(ASN) {}
@ -292,14 +291,14 @@ public:
/// \class /// \class
/// \brief Provide DenseMapInfo for AttributeSet. /// \brief Provide DenseMapInfo for AttributeSet.
template <> struct DenseMapInfo<AttributeSet> { template <> struct DenseMapInfo<AttributeSet> {
static inline AttributeSet getEmptyKey() { static AttributeSet getEmptyKey() {
uintptr_t Val = static_cast<uintptr_t>(-1); auto Val = static_cast<uintptr_t>(-1);
Val <<= PointerLikeTypeTraits<void *>::NumLowBitsAvailable; Val <<= PointerLikeTypeTraits<void *>::NumLowBitsAvailable;
return AttributeSet(reinterpret_cast<AttributeSetNode *>(Val)); return AttributeSet(reinterpret_cast<AttributeSetNode *>(Val));
} }
static inline AttributeSet getTombstoneKey() { static AttributeSet getTombstoneKey() {
uintptr_t Val = static_cast<uintptr_t>(-2); auto Val = static_cast<uintptr_t>(-2);
Val <<= PointerLikeTypeTraits<void *>::NumLowBitsAvailable; Val <<= PointerLikeTypeTraits<void *>::NumLowBitsAvailable;
return AttributeSet(reinterpret_cast<AttributeSetNode *>(Val)); return AttributeSet(reinterpret_cast<AttributeSetNode *>(Val));
} }
@ -333,7 +332,6 @@ private:
friend class AttributeListImpl; friend class AttributeListImpl;
friend class AttributeSet; friend class AttributeSet;
friend class AttributeSetNode; friend class AttributeSetNode;
template <typename Ty> friend struct DenseMapInfo; template <typename Ty> friend struct DenseMapInfo;
/// \brief The attributes that we are managing. This can be null to represent /// \brief The attributes that we are managing. This can be null to represent
@ -652,14 +650,14 @@ public:
/// \class /// \class
/// \brief Provide DenseMapInfo for AttributeList. /// \brief Provide DenseMapInfo for AttributeList.
template <> struct DenseMapInfo<AttributeList> { template <> struct DenseMapInfo<AttributeList> {
static inline AttributeList getEmptyKey() { static AttributeList getEmptyKey() {
uintptr_t Val = static_cast<uintptr_t>(-1); auto Val = static_cast<uintptr_t>(-1);
Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable; Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable;
return AttributeList(reinterpret_cast<AttributeListImpl *>(Val)); return AttributeList(reinterpret_cast<AttributeListImpl *>(Val));
} }
static inline AttributeList getTombstoneKey() { static AttributeList getTombstoneKey() {
uintptr_t Val = static_cast<uintptr_t>(-2); auto Val = static_cast<uintptr_t>(-2);
Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable; Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable;
return AttributeList(reinterpret_cast<AttributeListImpl *>(Val)); return AttributeList(reinterpret_cast<AttributeListImpl *>(Val));
} }
@ -691,9 +689,11 @@ class AttrBuilder {
public: public:
AttrBuilder() = default; AttrBuilder() = default;
AttrBuilder(const Attribute &A) { AttrBuilder(const Attribute &A) {
addAttribute(A); addAttribute(A);
} }
AttrBuilder(AttributeList AS, unsigned Idx); AttrBuilder(AttributeList AS, unsigned Idx);
AttrBuilder(AttributeSet AS); AttrBuilder(AttributeSet AS);
@ -807,6 +807,7 @@ public:
td_const_iterator td_end() const { return TargetDepAttrs.end(); } td_const_iterator td_end() const { return TargetDepAttrs.end(); }
td_range td_attrs() { return td_range(td_begin(), td_end()); } td_range td_attrs() { return td_range(td_begin(), td_end()); }
td_const_range td_attrs() const { td_const_range td_attrs() const {
return td_const_range(td_begin(), td_end()); return td_const_range(td_begin(), td_end());
} }

File diff suppressed because it is too large Load Diff

View File

@ -38,7 +38,6 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <limits> #include <limits>
#include <map>
#include <string> #include <string>
#include <tuple> #include <tuple>
#include <utility> #include <utility>
@ -186,14 +185,14 @@ uint64_t Attribute::getValueAsInt() const {
} }
StringRef Attribute::getKindAsString() const { StringRef Attribute::getKindAsString() const {
if (!pImpl) return StringRef(); if (!pImpl) return {};
assert(isStringAttribute() && assert(isStringAttribute() &&
"Invalid attribute type to get the kind as a string!"); "Invalid attribute type to get the kind as a string!");
return pImpl->getKindAsString(); return pImpl->getKindAsString();
} }
StringRef Attribute::getValueAsString() const { StringRef Attribute::getValueAsString() const {
if (!pImpl) return StringRef(); if (!pImpl) return {};
assert(isStringAttribute() && assert(isStringAttribute() &&
"Invalid attribute type to get the value as a string!"); "Invalid attribute type to get the value as a string!");
return pImpl->getValueAsString(); return pImpl->getValueAsString();
@ -241,7 +240,7 @@ std::pair<unsigned, Optional<unsigned>> Attribute::getAllocSizeArgs() const {
} }
std::string Attribute::getAsString(bool InAttrGrp) const { std::string Attribute::getAsString(bool InAttrGrp) const {
if (!pImpl) return ""; if (!pImpl) return {};
if (hasAttribute(Attribute::SanitizeAddress)) if (hasAttribute(Attribute::SanitizeAddress))
return "sanitize_address"; return "sanitize_address";
@ -538,7 +537,7 @@ AttributeSet AttributeSet::addAttributes(LLVMContext &C,
return *this; return *this;
AttrBuilder B(AS); AttrBuilder B(AS);
for (Attribute I : *this) for (const auto I : *this)
B.addAttribute(I); B.addAttribute(I);
return get(C, B); return get(C, B);
@ -637,7 +636,7 @@ AttributeSetNode::AttributeSetNode(ArrayRef<Attribute> Attrs)
// There's memory after the node where we can store the entries in. // There's memory after the node where we can store the entries in.
std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>()); std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>());
for (Attribute I : *this) { for (const auto I : *this) {
if (!I.isStringAttribute()) { if (!I.isStringAttribute()) {
AvailableAttrs |= ((uint64_t)1) << I.getKindAsEnum(); AvailableAttrs |= ((uint64_t)1) << I.getKindAsEnum();
} }
@ -656,7 +655,7 @@ AttributeSetNode *AttributeSetNode::get(LLVMContext &C,
SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end()); SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end());
std::sort(SortedAttrs.begin(), SortedAttrs.end()); std::sort(SortedAttrs.begin(), SortedAttrs.end());
for (Attribute Attr : SortedAttrs) for (const auto Attr : SortedAttrs)
Attr.Profile(ID); Attr.Profile(ID);
void *InsertPoint; void *InsertPoint;
@ -719,7 +718,7 @@ AttributeSetNode *AttributeSetNode::get(LLVMContext &C, const AttrBuilder &B) {
} }
bool AttributeSetNode::hasAttribute(StringRef Kind) const { bool AttributeSetNode::hasAttribute(StringRef Kind) const {
for (Attribute I : *this) for (const auto I : *this)
if (I.hasAttribute(Kind)) if (I.hasAttribute(Kind))
return true; return true;
return false; return false;
@ -727,43 +726,43 @@ bool AttributeSetNode::hasAttribute(StringRef Kind) const {
Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const { Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const {
if (hasAttribute(Kind)) { if (hasAttribute(Kind)) {
for (Attribute I : *this) for (const auto I : *this)
if (I.hasAttribute(Kind)) if (I.hasAttribute(Kind))
return I; return I;
} }
return Attribute(); return {};
} }
Attribute AttributeSetNode::getAttribute(StringRef Kind) const { Attribute AttributeSetNode::getAttribute(StringRef Kind) const {
for (Attribute I : *this) for (const auto I : *this)
if (I.hasAttribute(Kind)) if (I.hasAttribute(Kind))
return I; return I;
return Attribute(); return {};
} }
unsigned AttributeSetNode::getAlignment() const { unsigned AttributeSetNode::getAlignment() const {
for (Attribute I : *this) for (const auto I : *this)
if (I.hasAttribute(Attribute::Alignment)) if (I.hasAttribute(Attribute::Alignment))
return I.getAlignment(); return I.getAlignment();
return 0; return 0;
} }
unsigned AttributeSetNode::getStackAlignment() const { unsigned AttributeSetNode::getStackAlignment() const {
for (Attribute I : *this) for (const auto I : *this)
if (I.hasAttribute(Attribute::StackAlignment)) if (I.hasAttribute(Attribute::StackAlignment))
return I.getStackAlignment(); return I.getStackAlignment();
return 0; return 0;
} }
uint64_t AttributeSetNode::getDereferenceableBytes() const { uint64_t AttributeSetNode::getDereferenceableBytes() const {
for (Attribute I : *this) for (const auto I : *this)
if (I.hasAttribute(Attribute::Dereferenceable)) if (I.hasAttribute(Attribute::Dereferenceable))
return I.getDereferenceableBytes(); return I.getDereferenceableBytes();
return 0; return 0;
} }
uint64_t AttributeSetNode::getDereferenceableOrNullBytes() const { uint64_t AttributeSetNode::getDereferenceableOrNullBytes() const {
for (Attribute I : *this) for (const auto I : *this)
if (I.hasAttribute(Attribute::DereferenceableOrNull)) if (I.hasAttribute(Attribute::DereferenceableOrNull))
return I.getDereferenceableOrNullBytes(); return I.getDereferenceableOrNullBytes();
return 0; return 0;
@ -771,7 +770,7 @@ uint64_t AttributeSetNode::getDereferenceableOrNullBytes() const {
std::pair<unsigned, Optional<unsigned>> std::pair<unsigned, Optional<unsigned>>
AttributeSetNode::getAllocSizeArgs() const { AttributeSetNode::getAllocSizeArgs() const {
for (Attribute I : *this) for (const auto I : *this)
if (I.hasAttribute(Attribute::AllocSize)) if (I.hasAttribute(Attribute::AllocSize))
return I.getAllocSizeArgs(); return I.getAllocSizeArgs();
return std::make_pair(0, 0); return std::make_pair(0, 0);
@ -813,7 +812,7 @@ AttributeListImpl::AttributeListImpl(LLVMContext &C,
"Too many attributes"); "Too many attributes");
static_assert(attrIdxToArrayIdx(AttributeList::FunctionIndex) == 0U, static_assert(attrIdxToArrayIdx(AttributeList::FunctionIndex) == 0U,
"function should be stored in slot 0"); "function should be stored in slot 0");
for (Attribute I : Sets[0]) { for (const auto I : Sets[0]) {
if (!I.isStringAttribute()) if (!I.isStringAttribute())
AvailableFunctionAttrs |= 1ULL << I.getKindAsEnum(); AvailableFunctionAttrs |= 1ULL << I.getKindAsEnum();
} }
@ -870,14 +869,14 @@ AttributeList::get(LLVMContext &C,
ArrayRef<std::pair<unsigned, Attribute>> Attrs) { ArrayRef<std::pair<unsigned, Attribute>> Attrs) {
// If there are no attributes then return a null AttributesList pointer. // If there are no attributes then return a null AttributesList pointer.
if (Attrs.empty()) if (Attrs.empty())
return AttributeList(); return {};
assert(std::is_sorted(Attrs.begin(), Attrs.end(), assert(std::is_sorted(Attrs.begin(), Attrs.end(),
[](const std::pair<unsigned, Attribute> &LHS, [](const std::pair<unsigned, Attribute> &LHS,
const std::pair<unsigned, Attribute> &RHS) { const std::pair<unsigned, Attribute> &RHS) {
return LHS.first < RHS.first; return LHS.first < RHS.first;
}) && "Misordered Attributes list!"); }) && "Misordered Attributes list!");
assert(none_of(Attrs, assert(llvm::none_of(Attrs,
[](const std::pair<unsigned, Attribute> &Pair) { [](const std::pair<unsigned, Attribute> &Pair) {
return Pair.second.hasAttribute(Attribute::None); return Pair.second.hasAttribute(Attribute::None);
}) && }) &&
@ -906,7 +905,7 @@ AttributeList::get(LLVMContext &C,
ArrayRef<std::pair<unsigned, AttributeSet>> Attrs) { ArrayRef<std::pair<unsigned, AttributeSet>> Attrs) {
// If there are no attributes then return a null AttributesList pointer. // If there are no attributes then return a null AttributesList pointer.
if (Attrs.empty()) if (Attrs.empty())
return AttributeList(); return {};
assert(std::is_sorted(Attrs.begin(), Attrs.end(), assert(std::is_sorted(Attrs.begin(), Attrs.end(),
[](const std::pair<unsigned, AttributeSet> &LHS, [](const std::pair<unsigned, AttributeSet> &LHS,
@ -914,7 +913,7 @@ AttributeList::get(LLVMContext &C,
return LHS.first < RHS.first; return LHS.first < RHS.first;
}) && }) &&
"Misordered Attributes list!"); "Misordered Attributes list!");
assert(none_of(Attrs, assert(llvm::none_of(Attrs,
[](const std::pair<unsigned, AttributeSet> &Pair) { [](const std::pair<unsigned, AttributeSet> &Pair) {
return !Pair.second.hasAttributes(); return !Pair.second.hasAttributes();
}) && }) &&
@ -923,7 +922,7 @@ AttributeList::get(LLVMContext &C,
unsigned MaxIndex = Attrs.back().first; unsigned MaxIndex = Attrs.back().first;
SmallVector<AttributeSet, 4> AttrVec(attrIdxToArrayIdx(MaxIndex) + 1); SmallVector<AttributeSet, 4> AttrVec(attrIdxToArrayIdx(MaxIndex) + 1);
for (auto Pair : Attrs) for (const auto Pair : Attrs)
AttrVec[attrIdxToArrayIdx(Pair.first)] = Pair.second; AttrVec[attrIdxToArrayIdx(Pair.first)] = Pair.second;
return getImpl(C, AttrVec); return getImpl(C, AttrVec);
@ -953,7 +952,7 @@ AttributeList AttributeList::get(LLVMContext &C, AttributeSet FnAttrs,
// If all attribute sets were empty, we can use the empty attribute list. // If all attribute sets were empty, we can use the empty attribute list.
if (NumSets == 0) if (NumSets == 0)
return AttributeList(); return {};
SmallVector<AttributeSet, 8> AttrSets; SmallVector<AttributeSet, 8> AttrSets;
AttrSets.reserve(NumSets); AttrSets.reserve(NumSets);
@ -973,7 +972,7 @@ AttributeList AttributeList::get(LLVMContext &C, AttributeSet FnAttrs,
AttributeList AttributeList::get(LLVMContext &C, unsigned Index, AttributeList AttributeList::get(LLVMContext &C, unsigned Index,
const AttrBuilder &B) { const AttrBuilder &B) {
if (!B.hasAttributes()) if (!B.hasAttributes())
return AttributeList(); return {};
Index = attrIdxToArrayIdx(Index); Index = attrIdxToArrayIdx(Index);
SmallVector<AttributeSet, 8> AttrSets(Index + 1); SmallVector<AttributeSet, 8> AttrSets(Index + 1);
AttrSets[Index] = AttributeSet::get(C, B); AttrSets[Index] = AttributeSet::get(C, B);
@ -983,7 +982,7 @@ AttributeList AttributeList::get(LLVMContext &C, unsigned Index,
AttributeList AttributeList::get(LLVMContext &C, unsigned Index, AttributeList AttributeList::get(LLVMContext &C, unsigned Index,
ArrayRef<Attribute::AttrKind> Kinds) { ArrayRef<Attribute::AttrKind> Kinds) {
SmallVector<std::pair<unsigned, Attribute>, 8> Attrs; SmallVector<std::pair<unsigned, Attribute>, 8> Attrs;
for (Attribute::AttrKind K : Kinds) for (const auto K : Kinds)
Attrs.emplace_back(Index, Attribute::get(C, K)); Attrs.emplace_back(Index, Attribute::get(C, K));
return get(C, Attrs); return get(C, Attrs);
} }
@ -991,7 +990,7 @@ AttributeList AttributeList::get(LLVMContext &C, unsigned Index,
AttributeList AttributeList::get(LLVMContext &C, unsigned Index, AttributeList AttributeList::get(LLVMContext &C, unsigned Index,
ArrayRef<StringRef> Kinds) { ArrayRef<StringRef> Kinds) {
SmallVector<std::pair<unsigned, Attribute>, 8> Attrs; SmallVector<std::pair<unsigned, Attribute>, 8> Attrs;
for (StringRef K : Kinds) for (const auto K : Kinds)
Attrs.emplace_back(Index, Attribute::get(C, K)); Attrs.emplace_back(Index, Attribute::get(C, K));
return get(C, Attrs); return get(C, Attrs);
} }
@ -999,22 +998,22 @@ AttributeList AttributeList::get(LLVMContext &C, unsigned Index,
AttributeList AttributeList::get(LLVMContext &C, AttributeList AttributeList::get(LLVMContext &C,
ArrayRef<AttributeList> Attrs) { ArrayRef<AttributeList> Attrs) {
if (Attrs.empty()) if (Attrs.empty())
return AttributeList(); return {};
if (Attrs.size() == 1) if (Attrs.size() == 1)
return Attrs[0]; return Attrs[0];
unsigned MaxSize = 0; unsigned MaxSize = 0;
for (AttributeList List : Attrs) for (const auto List : Attrs)
MaxSize = std::max(MaxSize, List.getNumAttrSets()); MaxSize = std::max(MaxSize, List.getNumAttrSets());
// If every list was empty, there is no point in merging the lists. // If every list was empty, there is no point in merging the lists.
if (MaxSize == 0) if (MaxSize == 0)
return AttributeList(); return {};
SmallVector<AttributeSet, 8> NewAttrSets(MaxSize); SmallVector<AttributeSet, 8> NewAttrSets(MaxSize);
for (unsigned I = 0; I < MaxSize; ++I) { for (unsigned I = 0; I < MaxSize; ++I) {
AttrBuilder CurBuilder; AttrBuilder CurBuilder;
for (AttributeList List : Attrs) for (const auto List : Attrs)
CurBuilder.merge(List.getAttributes(I - 1)); CurBuilder.merge(List.getAttributes(I - 1));
NewAttrSets[I] = AttributeSet::get(C, CurBuilder); NewAttrSets[I] = AttributeSet::get(C, CurBuilder);
} }
@ -1124,7 +1123,7 @@ AttributeList
AttributeList::removeAttributes(LLVMContext &C, unsigned Index, AttributeList::removeAttributes(LLVMContext &C, unsigned Index,
const AttrBuilder &AttrsToRemove) const { const AttrBuilder &AttrsToRemove) const {
if (!pImpl) if (!pImpl)
return AttributeList(); return {};
Index = attrIdxToArrayIdx(Index); Index = attrIdxToArrayIdx(Index);
SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end()); SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
@ -1139,7 +1138,7 @@ AttributeList::removeAttributes(LLVMContext &C, unsigned Index,
AttributeList AttributeList::removeAttributes(LLVMContext &C, AttributeList AttributeList::removeAttributes(LLVMContext &C,
unsigned WithoutIndex) const { unsigned WithoutIndex) const {
if (!pImpl) if (!pImpl)
return AttributeList(); return {};
WithoutIndex = attrIdxToArrayIdx(WithoutIndex); WithoutIndex = attrIdxToArrayIdx(WithoutIndex);
if (WithoutIndex >= getNumAttrSets()) if (WithoutIndex >= getNumAttrSets())
return *this; return *this;
@ -1273,7 +1272,7 @@ std::string AttributeList::getAsString(unsigned Index, bool InAttrGrp) const {
AttributeSet AttributeList::getAttributes(unsigned Index) const { AttributeSet AttributeList::getAttributes(unsigned Index) const {
Index = attrIdxToArrayIdx(Index); Index = attrIdxToArrayIdx(Index);
if (!pImpl || Index >= getNumAttrSets()) if (!pImpl || Index >= getNumAttrSets())
return AttributeSet(); return {};
return pImpl->begin()[Index]; return pImpl->begin()[Index];
} }
@ -1313,12 +1312,12 @@ LLVM_DUMP_METHOD void AttributeList::dump() const {
// FIXME: Remove this ctor, use AttributeSet. // FIXME: Remove this ctor, use AttributeSet.
AttrBuilder::AttrBuilder(AttributeList AL, unsigned Index) { AttrBuilder::AttrBuilder(AttributeList AL, unsigned Index) {
AttributeSet AS = AL.getAttributes(Index); AttributeSet AS = AL.getAttributes(Index);
for (const Attribute &A : AS) for (const auto &A : AS)
addAttribute(A); addAttribute(A);
} }
AttrBuilder::AttrBuilder(AttributeSet AS) { AttrBuilder::AttrBuilder(AttributeSet AS) {
for (const Attribute &A : AS) for (const auto &A : AS)
addAttribute(A); addAttribute(A);
} }
@ -1389,7 +1388,7 @@ AttrBuilder &AttrBuilder::removeAttributes(AttributeList A, uint64_t Index) {
} }
AttrBuilder &AttrBuilder::removeAttribute(StringRef A) { AttrBuilder &AttrBuilder::removeAttribute(StringRef A) {
std::map<std::string, std::string>::iterator I = TargetDepAttrs.find(A); auto I = TargetDepAttrs.find(A);
if (I != TargetDepAttrs.end()) if (I != TargetDepAttrs.end())
TargetDepAttrs.erase(I); TargetDepAttrs.erase(I);
return *this; return *this;
@ -1529,7 +1528,7 @@ bool AttrBuilder::hasAttributes() const {
bool AttrBuilder::hasAttributes(AttributeList AL, uint64_t Index) const { bool AttrBuilder::hasAttributes(AttributeList AL, uint64_t Index) const {
AttributeSet AS = AL.getAttributes(Index); AttributeSet AS = AL.getAttributes(Index);
for (Attribute Attr : AS) { for (const auto Attr : AS) {
if (Attr.isEnumAttribute() || Attr.isIntAttribute()) { if (Attr.isEnumAttribute() || Attr.isIntAttribute()) {
if (contains(Attr.getKindAsEnum())) if (contains(Attr.getKindAsEnum()))
return true; return true;

View File

@ -1,4 +1,4 @@
//===---- IRBuilder.cpp - Builder for LLVM Instrs -------------------------===// //===- IRBuilder.cpp - Builder for LLVM Instrs ----------------------------===//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -13,12 +13,27 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/IR/IRBuilder.h" #include "llvm/IR/IRBuilder.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/None.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h" #include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h" #include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h" #include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h" #include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/Statepoint.h" #include "llvm/IR/Statepoint.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/MathExtras.h"
#include <cassert>
#include <cstdint>
#include <vector>
using namespace llvm; using namespace llvm;
/// CreateGlobalString - Make a new global variable with an initializer that /// CreateGlobalString - Make a new global variable with an initializer that
@ -30,10 +45,9 @@ GlobalVariable *IRBuilderBase::CreateGlobalString(StringRef Str,
unsigned AddressSpace) { unsigned AddressSpace) {
Constant *StrConstant = ConstantDataArray::getString(Context, Str); Constant *StrConstant = ConstantDataArray::getString(Context, Str);
Module &M = *BB->getParent()->getParent(); Module &M = *BB->getParent()->getParent();
GlobalVariable *GV = new GlobalVariable(M, StrConstant->getType(), auto *GV = new GlobalVariable(M, StrConstant->getType(), true,
true, GlobalValue::PrivateLinkage, GlobalValue::PrivateLinkage, StrConstant, Name,
StrConstant, Name, nullptr, nullptr, GlobalVariable::NotThreadLocal,
GlobalVariable::NotThreadLocal,
AddressSpace); AddressSpace);
GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
return GV; return GV;
@ -45,7 +59,7 @@ Type *IRBuilderBase::getCurrentFunctionReturnType() const {
} }
Value *IRBuilderBase::getCastedInt8PtrValue(Value *Ptr) { Value *IRBuilderBase::getCastedInt8PtrValue(Value *Ptr) {
PointerType *PT = cast<PointerType>(Ptr->getType()); auto *PT = cast<PointerType>(Ptr->getType());
if (PT->getElementType()->isIntegerTy(8)) if (PT->getElementType()->isIntegerTy(8))
return Ptr; return Ptr;
@ -386,7 +400,7 @@ CallInst *IRBuilderBase::CreateAssumption(Value *Cond) {
CallInst *IRBuilderBase::CreateMaskedLoad(Value *Ptr, unsigned Align, CallInst *IRBuilderBase::CreateMaskedLoad(Value *Ptr, unsigned Align,
Value *Mask, Value *PassThru, Value *Mask, Value *PassThru,
const Twine &Name) { const Twine &Name) {
PointerType *PtrTy = cast<PointerType>(Ptr->getType()); auto *PtrTy = cast<PointerType>(Ptr->getType());
Type *DataTy = PtrTy->getElementType(); Type *DataTy = PtrTy->getElementType();
assert(DataTy->isVectorTy() && "Ptr should point to a vector"); assert(DataTy->isVectorTy() && "Ptr should point to a vector");
assert(Mask && "Mask should not be all-ones (null)"); assert(Mask && "Mask should not be all-ones (null)");
@ -406,7 +420,7 @@ CallInst *IRBuilderBase::CreateMaskedLoad(Value *Ptr, unsigned Align,
/// be accessed in memory /// be accessed in memory
CallInst *IRBuilderBase::CreateMaskedStore(Value *Val, Value *Ptr, CallInst *IRBuilderBase::CreateMaskedStore(Value *Val, Value *Ptr,
unsigned Align, Value *Mask) { unsigned Align, Value *Mask) {
PointerType *PtrTy = cast<PointerType>(Ptr->getType()); auto *PtrTy = cast<PointerType>(Ptr->getType());
Type *DataTy = PtrTy->getElementType(); Type *DataTy = PtrTy->getElementType();
assert(DataTy->isVectorTy() && "Ptr should point to a vector"); assert(DataTy->isVectorTy() && "Ptr should point to a vector");
assert(Mask && "Mask should not be all-ones (null)"); assert(Mask && "Mask should not be all-ones (null)");
@ -520,7 +534,7 @@ static CallInst *CreateGCStatepointCallCommon(
ArrayRef<T1> TransitionArgs, ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs, ArrayRef<T1> TransitionArgs, ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs,
const Twine &Name) { const Twine &Name) {
// Extract out the type of the callee. // Extract out the type of the callee.
PointerType *FuncPtrType = cast<PointerType>(ActualCallee->getType()); auto *FuncPtrType = cast<PointerType>(ActualCallee->getType());
assert(isa<FunctionType>(FuncPtrType->getElementType()) && assert(isa<FunctionType>(FuncPtrType->getElementType()) &&
"actual callee must be a callable value"); "actual callee must be a callable value");
@ -531,7 +545,7 @@ static CallInst *CreateGCStatepointCallCommon(
Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint, Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint,
ArgTypes); ArgTypes);
std::vector<llvm::Value *> Args = std::vector<Value *> Args =
getStatepointArgs(*Builder, ID, NumPatchBytes, ActualCallee, Flags, getStatepointArgs(*Builder, ID, NumPatchBytes, ActualCallee, Flags,
CallArgs, TransitionArgs, DeoptArgs, GCArgs); CallArgs, TransitionArgs, DeoptArgs, GCArgs);
return createCallHelper(FnStatepoint, Args, Builder, Name); return createCallHelper(FnStatepoint, Args, Builder, Name);
@ -571,7 +585,7 @@ static InvokeInst *CreateGCStatepointInvokeCommon(
uint32_t Flags, ArrayRef<T0> InvokeArgs, ArrayRef<T1> TransitionArgs, uint32_t Flags, ArrayRef<T0> InvokeArgs, ArrayRef<T1> TransitionArgs,
ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs, const Twine &Name) { ArrayRef<T2> DeoptArgs, ArrayRef<T3> GCArgs, const Twine &Name) {
// Extract out the type of the callee. // Extract out the type of the callee.
PointerType *FuncPtrType = cast<PointerType>(ActualInvokee->getType()); auto *FuncPtrType = cast<PointerType>(ActualInvokee->getType());
assert(isa<FunctionType>(FuncPtrType->getElementType()) && assert(isa<FunctionType>(FuncPtrType->getElementType()) &&
"actual callee must be a callable value"); "actual callee must be a callable value");
@ -580,7 +594,7 @@ static InvokeInst *CreateGCStatepointInvokeCommon(
Function *FnStatepoint = Intrinsic::getDeclaration( Function *FnStatepoint = Intrinsic::getDeclaration(
M, Intrinsic::experimental_gc_statepoint, {FuncPtrType}); M, Intrinsic::experimental_gc_statepoint, {FuncPtrType});
std::vector<llvm::Value *> Args = std::vector<Value *> Args =
getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee, Flags, getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee, Flags,
InvokeArgs, TransitionArgs, DeoptArgs, GCArgs); InvokeArgs, TransitionArgs, DeoptArgs, GCArgs);
return createInvokeHelper(FnStatepoint, NormalDest, UnwindDest, Args, Builder, return createInvokeHelper(FnStatepoint, NormalDest, UnwindDest, Args, Builder,
@ -663,4 +677,3 @@ CallInst *IRBuilderBase::CreateIntrinsic(Intrinsic::ID ID,
Function *Fn = Intrinsic::getDeclaration(M, ID, { Args.front()->getType() }); Function *Fn = Intrinsic::getDeclaration(M, ID, { Args.front()->getType() });
return createCallHelper(Fn, Args, this, Name, FMFSource); return createCallHelper(Fn, Args, this, Name, FMFSource);
} }