[llvm] r288650 - TableGen: Use range based for; reserve vectors where possible
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 4 23:00:44 PST 2016
Author: matze
Date: Mon Dec 5 01:00:44 2016
New Revision: 288650
URL: http://llvm.org/viewvc/llvm-project?rev=288650&view=rev
Log:
TableGen: Use range based for; reserve vectors where possible
Modified:
llvm/trunk/lib/TableGen/Record.cpp
Modified: llvm/trunk/lib/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Record.cpp?rev=288650&r1=288649&r2=288650&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Record.cpp (original)
+++ llvm/trunk/lib/TableGen/Record.cpp Mon Dec 5 01:00:44 2016
@@ -562,10 +562,11 @@ Init *ListInit::convertInitializerTo(Rec
Init *ListInit::convertInitListSlice(ArrayRef<unsigned> Elements) const {
SmallVector<Init*, 8> Vals;
- for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
- if (Elements[i] >= size())
+ Vals.reserve(Elements.size());
+ for (unsigned Element : Elements) {
+ if (Element >= size())
return nullptr;
- Vals.push_back(getElement(Elements[i]));
+ Vals.push_back(getElement(Element));
}
return ListInit::get(Vals, getType());
}
@@ -614,9 +615,11 @@ Init *ListInit::resolveListElementRefere
std::string ListInit::getAsString() const {
std::string Result = "[";
- for (unsigned i = 0, e = NumValues; i != e; ++i) {
- if (i) Result += ", ";
- Result += getElement(i)->getAsString();
+ const char *sep = "";
+ for (Init *Element : *this) {
+ Result += sep;
+ sep = ", ";
+ Result += Element->getAsString();
}
return Result + "]";
}
@@ -989,7 +992,8 @@ static Init *EvaluateOperation(OpInit *R
return ForeachHelper(LHS, Arg, RHSo, Type, CurRec, CurMultiClass);
SmallVector<Init *, 8> NewOperands;
- for (unsigned i = 0; i < RHSo->getNumOperands(); ++i) {
+ NewOperands.reserve(RHSo->getNumOperands());
+ for (unsigned i = 0, e = RHSo->getNumOperands(); i < e; ++i) {
if (auto *RHSoo = dyn_cast<OpInit>(RHSo->getOperand(i))) {
if (Init *Result = EvaluateOperation(RHSoo, LHS, Arg,
Type, CurRec, CurMultiClass))
@@ -1275,12 +1279,13 @@ Init *TypedInit::convertInitializerBitRa
if (!T) return nullptr; // Cannot subscript a non-bits variable.
unsigned NumBits = T->getNumBits();
- SmallVector<Init *, 16> NewBits(Bits.size());
- for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
- if (Bits[i] >= NumBits)
+ SmallVector<Init *, 16> NewBits;
+ NewBits.reserve(Bits.size());
+ for (unsigned Bit : Bits) {
+ if (Bit >= NumBits)
return nullptr;
- NewBits[i] = VarBitInit::get(const_cast<TypedInit *>(this), Bits[i]);
+ NewBits.push_back(VarBitInit::get(const_cast<TypedInit *>(this), Bit));
}
return BitsInit::get(NewBits);
}
@@ -1294,9 +1299,9 @@ Init *TypedInit::convertInitListSlice(Ar
SmallVector<Init*, 8> ListInits;
ListInits.reserve(Elements.size());
- for (unsigned i = 0, e = Elements.size(); i != e; ++i)
+ for (unsigned Element : Elements)
ListInits.push_back(VarListElementInit::get(const_cast<TypedInit *>(this),
- Elements[i]));
+ Element));
return ListInit::get(ListInits, T);
}
@@ -1702,13 +1707,13 @@ void Record::setName(StringRef Name) {
}
void Record::resolveReferencesTo(const RecordVal *RV) {
- for (unsigned i = 0, e = Values.size(); i != e; ++i) {
- if (RV == &Values[i]) // Skip resolve the same field as the given one
+ for (RecordVal &Value : Values) {
+ if (RV == &Value) // Skip resolve the same field as the given one
continue;
- if (Init *V = Values[i].getValue())
- if (Values[i].setValue(V->resolveReferences(*this, RV)))
+ if (Init *V = Value.getValue())
+ if (Value.setValue(V->resolveReferences(*this, RV)))
PrintFatalError(getLoc(), "Invalid value is found when setting '" +
- Values[i].getNameInitAsString() +
+ Value.getNameInitAsString() +
"' after resolving references" +
(RV ? " against '" + RV->getNameInitAsString() +
"' of (" + RV->getValue()->getAsUnquotedString() +
More information about the llvm-commits
mailing list