forked from OSchip/llvm-project
TableGen: Use range based for; reserve vectors where possible
llvm-svn: 288650
This commit is contained in:
parent
c66e75572e
commit
ca151317e8
|
@ -562,10 +562,11 @@ Init *ListInit::convertInitializerTo(RecTy *Ty) const {
|
||||||
|
|
||||||
Init *ListInit::convertInitListSlice(ArrayRef<unsigned> Elements) const {
|
Init *ListInit::convertInitListSlice(ArrayRef<unsigned> Elements) const {
|
||||||
SmallVector<Init*, 8> Vals;
|
SmallVector<Init*, 8> Vals;
|
||||||
for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
|
Vals.reserve(Elements.size());
|
||||||
if (Elements[i] >= size())
|
for (unsigned Element : Elements) {
|
||||||
|
if (Element >= size())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
Vals.push_back(getElement(Elements[i]));
|
Vals.push_back(getElement(Element));
|
||||||
}
|
}
|
||||||
return ListInit::get(Vals, getType());
|
return ListInit::get(Vals, getType());
|
||||||
}
|
}
|
||||||
|
@ -614,9 +615,11 @@ Init *ListInit::resolveListElementReference(Record &R, const RecordVal *IRV,
|
||||||
|
|
||||||
std::string ListInit::getAsString() const {
|
std::string ListInit::getAsString() const {
|
||||||
std::string Result = "[";
|
std::string Result = "[";
|
||||||
for (unsigned i = 0, e = NumValues; i != e; ++i) {
|
const char *sep = "";
|
||||||
if (i) Result += ", ";
|
for (Init *Element : *this) {
|
||||||
Result += getElement(i)->getAsString();
|
Result += sep;
|
||||||
|
sep = ", ";
|
||||||
|
Result += Element->getAsString();
|
||||||
}
|
}
|
||||||
return Result + "]";
|
return Result + "]";
|
||||||
}
|
}
|
||||||
|
@ -989,7 +992,8 @@ static Init *EvaluateOperation(OpInit *RHSo, Init *LHS, Init *Arg,
|
||||||
return ForeachHelper(LHS, Arg, RHSo, Type, CurRec, CurMultiClass);
|
return ForeachHelper(LHS, Arg, RHSo, Type, CurRec, CurMultiClass);
|
||||||
|
|
||||||
SmallVector<Init *, 8> NewOperands;
|
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 (auto *RHSoo = dyn_cast<OpInit>(RHSo->getOperand(i))) {
|
||||||
if (Init *Result = EvaluateOperation(RHSoo, LHS, Arg,
|
if (Init *Result = EvaluateOperation(RHSoo, LHS, Arg,
|
||||||
Type, CurRec, CurMultiClass))
|
Type, CurRec, CurMultiClass))
|
||||||
|
@ -1275,12 +1279,13 @@ Init *TypedInit::convertInitializerBitRange(ArrayRef<unsigned> Bits) const {
|
||||||
if (!T) return nullptr; // Cannot subscript a non-bits variable.
|
if (!T) return nullptr; // Cannot subscript a non-bits variable.
|
||||||
unsigned NumBits = T->getNumBits();
|
unsigned NumBits = T->getNumBits();
|
||||||
|
|
||||||
SmallVector<Init *, 16> NewBits(Bits.size());
|
SmallVector<Init *, 16> NewBits;
|
||||||
for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
|
NewBits.reserve(Bits.size());
|
||||||
if (Bits[i] >= NumBits)
|
for (unsigned Bit : Bits) {
|
||||||
|
if (Bit >= NumBits)
|
||||||
return nullptr;
|
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);
|
return BitsInit::get(NewBits);
|
||||||
}
|
}
|
||||||
|
@ -1294,9 +1299,9 @@ Init *TypedInit::convertInitListSlice(ArrayRef<unsigned> Elements) const {
|
||||||
|
|
||||||
SmallVector<Init*, 8> ListInits;
|
SmallVector<Init*, 8> ListInits;
|
||||||
ListInits.reserve(Elements.size());
|
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),
|
ListInits.push_back(VarListElementInit::get(const_cast<TypedInit *>(this),
|
||||||
Elements[i]));
|
Element));
|
||||||
return ListInit::get(ListInits, T);
|
return ListInit::get(ListInits, T);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1702,13 +1707,13 @@ void Record::setName(StringRef Name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Record::resolveReferencesTo(const RecordVal *RV) {
|
void Record::resolveReferencesTo(const RecordVal *RV) {
|
||||||
for (unsigned i = 0, e = Values.size(); i != e; ++i) {
|
for (RecordVal &Value : Values) {
|
||||||
if (RV == &Values[i]) // Skip resolve the same field as the given one
|
if (RV == &Value) // Skip resolve the same field as the given one
|
||||||
continue;
|
continue;
|
||||||
if (Init *V = Values[i].getValue())
|
if (Init *V = Value.getValue())
|
||||||
if (Values[i].setValue(V->resolveReferences(*this, RV)))
|
if (Value.setValue(V->resolveReferences(*this, RV)))
|
||||||
PrintFatalError(getLoc(), "Invalid value is found when setting '" +
|
PrintFatalError(getLoc(), "Invalid value is found when setting '" +
|
||||||
Values[i].getNameInitAsString() +
|
Value.getNameInitAsString() +
|
||||||
"' after resolving references" +
|
"' after resolving references" +
|
||||||
(RV ? " against '" + RV->getNameInitAsString() +
|
(RV ? " against '" + RV->getNameInitAsString() +
|
||||||
"' of (" + RV->getValue()->getAsUnquotedString() +
|
"' of (" + RV->getValue()->getAsUnquotedString() +
|
||||||
|
|
Loading…
Reference in New Issue