[IR] Use a reference in a range-based for

This avoids unneeded copies when using a range-based for loops.

This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall.

Differential Revision: https://reviews.llvm.org/D70870
This commit is contained in:
Mark de Wever 2019-12-17 21:57:58 +01:00
parent b750486c5d
commit 1a8ff89653
2 changed files with 19 additions and 19 deletions

View File

@ -618,7 +618,7 @@ AttributeSet AttributeSet::addAttributes(LLVMContext &C,
return *this;
AttrBuilder B(AS);
for (const auto I : *this)
for (const auto &I : *this)
B.addAttribute(I);
return get(C, B);
@ -725,7 +725,7 @@ AttributeSetNode::AttributeSetNode(ArrayRef<Attribute> Attrs)
sizeof(AvailableAttrs) * CHAR_BIT,
"Too many attributes");
for (const auto I : *this) {
for (const auto &I : *this) {
if (!I.isStringAttribute()) {
Attribute::AttrKind Kind = I.getKindAsEnum();
AvailableAttrs[Kind / 8] |= 1ULL << (Kind % 8);
@ -745,7 +745,7 @@ AttributeSetNode *AttributeSetNode::get(LLVMContext &C,
SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end());
llvm::sort(SortedAttrs);
for (const auto Attr : SortedAttrs)
for (const auto &Attr : SortedAttrs)
Attr.Profile(ID);
void *InsertPoint;
@ -813,7 +813,7 @@ AttributeSetNode *AttributeSetNode::get(LLVMContext &C, const AttrBuilder &B) {
}
bool AttributeSetNode::hasAttribute(StringRef Kind) const {
for (const auto I : *this)
for (const auto &I : *this)
if (I.hasAttribute(Kind))
return true;
return false;
@ -821,7 +821,7 @@ bool AttributeSetNode::hasAttribute(StringRef Kind) const {
Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const {
if (hasAttribute(Kind)) {
for (const auto I : *this)
for (const auto &I : *this)
if (I.hasAttribute(Kind))
return I;
}
@ -829,42 +829,42 @@ Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const {
}
Attribute AttributeSetNode::getAttribute(StringRef Kind) const {
for (const auto I : *this)
for (const auto &I : *this)
if (I.hasAttribute(Kind))
return I;
return {};
}
MaybeAlign AttributeSetNode::getAlignment() const {
for (const auto I : *this)
for (const auto &I : *this)
if (I.hasAttribute(Attribute::Alignment))
return I.getAlignment();
return None;
}
MaybeAlign AttributeSetNode::getStackAlignment() const {
for (const auto I : *this)
for (const auto &I : *this)
if (I.hasAttribute(Attribute::StackAlignment))
return I.getStackAlignment();
return None;
}
Type *AttributeSetNode::getByValType() const {
for (const auto I : *this)
for (const auto &I : *this)
if (I.hasAttribute(Attribute::ByVal))
return I.getValueAsType();
return 0;
}
uint64_t AttributeSetNode::getDereferenceableBytes() const {
for (const auto I : *this)
for (const auto &I : *this)
if (I.hasAttribute(Attribute::Dereferenceable))
return I.getDereferenceableBytes();
return 0;
}
uint64_t AttributeSetNode::getDereferenceableOrNullBytes() const {
for (const auto I : *this)
for (const auto &I : *this)
if (I.hasAttribute(Attribute::DereferenceableOrNull))
return I.getDereferenceableOrNullBytes();
return 0;
@ -872,7 +872,7 @@ uint64_t AttributeSetNode::getDereferenceableOrNullBytes() const {
std::pair<unsigned, Optional<unsigned>>
AttributeSetNode::getAllocSizeArgs() const {
for (const auto I : *this)
for (const auto &I : *this)
if (I.hasAttribute(Attribute::AllocSize))
return I.getAllocSizeArgs();
return std::make_pair(0, 0);
@ -914,7 +914,7 @@ AttributeListImpl::AttributeListImpl(LLVMContext &C,
"Too many attributes");
static_assert(attrIdxToArrayIdx(AttributeList::FunctionIndex) == 0U,
"function should be stored in slot 0");
for (const auto I : Sets[0]) {
for (const auto &I : Sets[0]) {
if (!I.isStringAttribute()) {
Attribute::AttrKind Kind = I.getKindAsEnum();
AvailableFunctionAttrs[Kind / 8] |= 1ULL << (Kind % 8);
@ -1030,7 +1030,7 @@ AttributeList::get(LLVMContext &C,
MaxIndex = Attrs[Attrs.size() - 2].first;
SmallVector<AttributeSet, 4> AttrVec(attrIdxToArrayIdx(MaxIndex) + 1);
for (const auto Pair : Attrs)
for (const auto &Pair : Attrs)
AttrVec[attrIdxToArrayIdx(Pair.first)] = Pair.second;
return getImpl(C, AttrVec);
@ -1098,7 +1098,7 @@ AttributeList AttributeList::get(LLVMContext &C, unsigned Index,
AttributeList AttributeList::get(LLVMContext &C, unsigned Index,
ArrayRef<StringRef> Kinds) {
SmallVector<std::pair<unsigned, Attribute>, 8> Attrs;
for (const auto K : Kinds)
for (const auto &K : Kinds)
Attrs.emplace_back(Index, Attribute::get(C, K));
return get(C, Attrs);
}
@ -1111,7 +1111,7 @@ AttributeList AttributeList::get(LLVMContext &C,
return Attrs[0];
unsigned MaxSize = 0;
for (const auto List : Attrs)
for (const auto &List : Attrs)
MaxSize = std::max(MaxSize, List.getNumAttrSets());
// If every list was empty, there is no point in merging the lists.
@ -1121,7 +1121,7 @@ AttributeList AttributeList::get(LLVMContext &C,
SmallVector<AttributeSet, 8> NewAttrSets(MaxSize);
for (unsigned I = 0; I < MaxSize; ++I) {
AttrBuilder CurBuilder;
for (const auto List : Attrs)
for (const auto &List : Attrs)
CurBuilder.merge(List.getAttributes(I - 1));
NewAttrSets[I] = AttributeSet::get(C, CurBuilder);
}
@ -1659,7 +1659,7 @@ bool AttrBuilder::hasAttributes() const {
bool AttrBuilder::hasAttributes(AttributeList AL, uint64_t Index) const {
AttributeSet AS = AL.getAttributes(Index);
for (const auto Attr : AS) {
for (const auto &Attr : AS) {
if (Attr.isEnumAttribute() || Attr.isIntAttribute()) {
if (contains(Attr.getKindAsEnum()))
return true;

View File

@ -244,7 +244,7 @@ void ModuleSummaryIndex::dumpSCCs(raw_ostream &O) {
!I.isAtEnd(); ++I) {
O << "SCC (" << utostr(I->size()) << " node" << (I->size() == 1 ? "" : "s")
<< ") {\n";
for (const ValueInfo V : *I) {
for (const ValueInfo &V : *I) {
FunctionSummary *F = nullptr;
if (V.getSummaryList().size())
F = cast<FunctionSummary>(V.getSummaryList().front().get());