TableGen/Record: Replace std::vector with SmallVector/ArrayRef

llvm-svn: 288648
This commit is contained in:
Matthias Braun 2016-12-05 06:41:51 +00:00
parent 8c8bbdcc14
commit 5d6cd19170
4 changed files with 60 additions and 63 deletions

View File

@ -342,8 +342,7 @@ public:
/// out, returning them as a new init of bits type. If it is not legal to use
/// the bit subscript operator on this initializer, return null.
///
virtual Init *
convertInitializerBitRange(const std::vector<unsigned> &Bits) const {
virtual Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const {
return nullptr;
}
@ -352,8 +351,7 @@ public:
/// elements, returning them as a new init of list type. If it is not legal
/// to take a slice of this, return null.
///
virtual Init *
convertInitListSlice(const std::vector<unsigned> &Elements) const {
virtual Init *convertInitListSlice(ArrayRef<unsigned> Elements) const {
return nullptr;
}
@ -423,10 +421,8 @@ public:
Init *convertInitializerTo(RecTy *Ty) const override;
Init *
convertInitializerBitRange(const std::vector<unsigned> &Bits) const override;
Init *
convertInitListSlice(const std::vector<unsigned> &Elements) const override;
Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
Init *convertInitListSlice(ArrayRef<unsigned> Elements) const override;
/// This method is used to implement the FieldInit class.
/// Implementors of this method should return the type of the named field if
@ -523,8 +519,7 @@ public:
unsigned getNumBits() const { return NumBits; }
Init *convertInitializerTo(RecTy *Ty) const override;
Init *
convertInitializerBitRange(const std::vector<unsigned> &Bits) const override;
Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
bool isComplete() const override {
for (unsigned i = 0; i != getNumBits(); ++i)
@ -577,8 +572,7 @@ public:
int64_t getValue() const { return Value; }
Init *convertInitializerTo(RecTy *Ty) const override;
Init *
convertInitializerBitRange(const std::vector<unsigned> &Bits) const override;
Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
std::string getAsString() const override;
@ -708,8 +702,7 @@ public:
Record *getElementAsRecord(unsigned i) const;
Init *
convertInitListSlice(const std::vector<unsigned> &Elements) const override;
Init *convertInitListSlice(ArrayRef<unsigned> Elements) const override;
Init *convertInitializerTo(RecTy *Ty) const override;
@ -760,7 +753,7 @@ public:
}
// Clone - Clone this operator, replacing arguments with the new list
virtual OpInit *clone(std::vector<Init *> &Operands) const = 0;
virtual OpInit *clone(ArrayRef<Init *> Operands) const = 0;
virtual unsigned getNumOperands() const = 0;
virtual Init *getOperand(unsigned i) const = 0;
@ -800,7 +793,7 @@ public:
void Profile(FoldingSetNodeID &ID) const;
// Clone - Clone this operator, replacing arguments with the new list
OpInit *clone(std::vector<Init *> &Operands) const override {
OpInit *clone(ArrayRef<Init *> Operands) const override {
assert(Operands.size() == 1 &&
"Wrong number of operands for unary operation");
return UnOpInit::get(getOpcode(), *Operands.begin(), getType());
@ -852,7 +845,7 @@ public:
void Profile(FoldingSetNodeID &ID) const;
// Clone - Clone this operator, replacing arguments with the new list
OpInit *clone(std::vector<Init *> &Operands) const override {
OpInit *clone(ArrayRef<Init *> Operands) const override {
assert(Operands.size() == 2 &&
"Wrong number of operands for binary operation");
return BinOpInit::get(getOpcode(), Operands[0], Operands[1], getType());
@ -908,7 +901,7 @@ public:
void Profile(FoldingSetNodeID &ID) const;
// Clone - Clone this operator, replacing arguments with the new list
OpInit *clone(std::vector<Init *> &Operands) const override {
OpInit *clone(ArrayRef<Init *> Operands) const override {
assert(Operands.size() == 3 &&
"Wrong number of operands for ternary operation");
return TernOpInit::get(getOpcode(), Operands[0], Operands[1], Operands[2],
@ -1086,7 +1079,7 @@ public:
Record *getDef() const { return Def; }
//virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
//virtual Init *convertInitializerBitRange(ArrayRef<unsigned> Bits);
RecTy *getFieldType(StringInit *FieldName) const override;
Init *getFieldInit(Record &R, const RecordVal *RV,
@ -1147,8 +1140,8 @@ public:
class DagInit : public TypedInit, public FoldingSetNode {
Init *Val;
StringInit *ValName;
std::vector<Init*> Args;
std::vector<StringInit*> ArgNames;
SmallVector<Init*, 4> Args;
SmallVector<StringInit*, 4> ArgNames;
DagInit(Init *V, StringInit *VN, ArrayRef<Init *> ArgRange,
ArrayRef<StringInit *> NameRange)
@ -1165,9 +1158,9 @@ public:
}
static DagInit *get(Init *V, StringInit *VN, ArrayRef<Init *> ArgRange,
ArrayRef<StringInit *> NameRange);
ArrayRef<StringInit*> NameRange);
static DagInit *get(Init *V, StringInit *VN,
const std::vector<std::pair<Init*, StringInit*>> &args);
ArrayRef<std::pair<Init*, StringInit*>> Args);
void Profile(FoldingSetNodeID &ID) const;
@ -1198,8 +1191,8 @@ public:
std::string getAsString() const override;
typedef std::vector<Init*>::const_iterator const_arg_iterator;
typedef std::vector<StringInit*>::const_iterator const_name_iterator;
typedef SmallVectorImpl<Init*>::const_iterator const_arg_iterator;
typedef SmallVectorImpl<StringInit*>::const_iterator const_name_iterator;
inline const_arg_iterator arg_begin() const { return Args.begin(); }
inline const_arg_iterator arg_end () const { return Args.end(); }

View File

@ -320,7 +320,7 @@ Init *BitsInit::convertInitializerTo(RecTy *Ty) const {
}
Init *
BitsInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) const {
BitsInit::convertInitializerBitRange(ArrayRef<unsigned> Bits) const {
SmallVector<Init *, 16> NewBits(Bits.size());
for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
@ -445,7 +445,7 @@ Init *IntInit::convertInitializerTo(RecTy *Ty) const {
}
Init *
IntInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) const {
IntInit::convertInitializerBitRange(ArrayRef<unsigned> Bits) const {
SmallVector<Init *, 16> NewBits(Bits.size());
for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
@ -537,7 +537,7 @@ Init *ListInit::convertInitializerTo(RecTy *Ty) const {
return const_cast<ListInit*>(this);
if (auto *LRT = dyn_cast<ListRecTy>(Ty)) {
std::vector<Init*> Elements;
SmallVector<Init*, 8> Elements;
Elements.reserve(getValues().size());
// Verify that all of the elements of the list are subclasses of the
@ -560,9 +560,8 @@ Init *ListInit::convertInitializerTo(RecTy *Ty) const {
return nullptr;
}
Init *
ListInit::convertInitListSlice(const std::vector<unsigned> &Elements) const {
std::vector<Init*> Vals;
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())
return nullptr;
@ -580,7 +579,7 @@ Record *ListInit::getElementAsRecord(unsigned i) const {
}
Init *ListInit::resolveReferences(Record &R, const RecordVal *RV) const {
std::vector<Init*> Resolved;
SmallVector<Init*, 8> Resolved;
Resolved.reserve(size());
bool Changed = false;
@ -837,8 +836,8 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
DefInit *ROp = dyn_cast<DefInit>(RHSs->getOperator());
if (!LOp || !ROp || LOp->getDef() != ROp->getDef())
PrintFatalError("Concated Dag operators do not match!");
std::vector<Init*> Args;
std::vector<StringInit*> ArgNames;
SmallVector<Init*, 8> Args;
SmallVector<StringInit*, 8> ArgNames;
for (unsigned i = 0, e = LHSs->getNumArgs(); i != e; ++i) {
Args.push_back(LHSs->getArg(i));
ArgNames.push_back(LHSs->getArgName(i));
@ -855,7 +854,7 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
ListInit *LHSs = dyn_cast<ListInit>(LHS);
ListInit *RHSs = dyn_cast<ListInit>(RHS);
if (LHSs && RHSs) {
std::vector<Init *> Args;
SmallVector<Init *, 8> Args;
Args.insert(Args.end(), LHSs->begin(), LHSs->end());
Args.insert(Args.end(), RHSs->begin(), RHSs->end());
return ListInit::get(
@ -989,7 +988,7 @@ static Init *EvaluateOperation(OpInit *RHSo, Init *LHS, Init *Arg,
if (isa<DagRecTy>(TArg->getType()))
return ForeachHelper(LHS, Arg, RHSo, Type, CurRec, CurMultiClass);
std::vector<Init *> NewOperands;
SmallVector<Init *, 8> NewOperands;
for (unsigned i = 0; i < RHSo->getNumOperands(); ++i) {
if (auto *RHSoo = dyn_cast<OpInit>(RHSo->getOperand(i))) {
if (Init *Result = EvaluateOperation(RHSoo, LHS, Arg,
@ -1030,7 +1029,7 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
Type, CurRec, CurMultiClass))
Val = Result;
std::vector<std::pair<Init *, StringInit*> > args;
SmallVector<std::pair<Init *, StringInit*>, 8> args;
for (unsigned int i = 0; i < MHSd->getNumArgs(); ++i) {
Init *Arg = MHSd->getArg(i);
StringInit *ArgName = MHSd->getArgName(i);
@ -1049,8 +1048,8 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
ListInit *MHSl = dyn_cast<ListInit>(MHS);
if (MHSl && isa<ListRecTy>(Type)) {
std::vector<Init *> NewOperands;
std::vector<Init *> NewList(MHSl->begin(), MHSl->end());
SmallVector<Init *, 8> NewOperands;
SmallVector<Init *, 8> NewList(MHSl->begin(), MHSl->end());
for (Init *&Item : NewList) {
NewOperands.clear();
@ -1271,8 +1270,7 @@ TypedInit::convertInitializerTo(RecTy *Ty) const {
return nullptr;
}
Init *
TypedInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) const {
Init *TypedInit::convertInitializerBitRange(ArrayRef<unsigned> Bits) const {
BitsRecTy *T = dyn_cast<BitsRecTy>(getType());
if (!T) return nullptr; // Cannot subscript a non-bits variable.
unsigned NumBits = T->getNumBits();
@ -1287,15 +1285,14 @@ TypedInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) const {
return BitsInit::get(NewBits);
}
Init *
TypedInit::convertInitListSlice(const std::vector<unsigned> &Elements) const {
Init *TypedInit::convertInitListSlice(ArrayRef<unsigned> Elements) const {
ListRecTy *T = dyn_cast<ListRecTy>(getType());
if (!T) return nullptr; // Cannot subscript a non-list variable.
if (Elements.size() == 1)
return VarListElementInit::get(const_cast<TypedInit *>(this), Elements[0]);
std::vector<Init*> ListInits;
SmallVector<Init*, 8> ListInits;
ListInits.reserve(Elements.size());
for (unsigned i = 0, e = Elements.size(); i != e; ++i)
ListInits.push_back(VarListElementInit::get(const_cast<TypedInit *>(this),
@ -1569,9 +1566,9 @@ DagInit::get(Init *V, StringInit *VN, ArrayRef<Init *> ArgRange,
DagInit *
DagInit::get(Init *V, StringInit *VN,
const std::vector<std::pair<Init*, StringInit*> > &args) {
std::vector<Init *> Args;
std::vector<StringInit *> Names;
ArrayRef<std::pair<Init*, StringInit*>> args) {
SmallVector<Init *, 8> Args;
SmallVector<StringInit *, 8> Names;
for (const auto &Arg : args) {
Args.push_back(Arg.first);
@ -1593,13 +1590,17 @@ Init *DagInit::convertInitializerTo(RecTy *Ty) const {
}
Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) const {
std::vector<Init*> NewArgs;
for (unsigned i = 0, e = Args.size(); i != e; ++i)
NewArgs.push_back(Args[i]->resolveReferences(R, RV));
SmallVector<Init*, 8> NewArgs;
NewArgs.reserve(Args.size());
bool ArgsChanged = false;
for (const Init *Arg : Args) {
Init *NewArg = Arg->resolveReferences(R, RV);
NewArgs.push_back(NewArg);
ArgsChanged |= NewArg != Arg;
}
Init *Op = Val->resolveReferences(R, RV);
if (Args != NewArgs || Op != Val)
if (Op != Val || ArgsChanged)
return DagInit::get(Op, ValName, NewArgs, ArgNames);
return const_cast<DagInit *>(this);

View File

@ -1428,9 +1428,9 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
Lex.Lex(); // eat the VarName.
}
std::vector<std::pair<llvm::Init*, StringInit*> > DagArgs;
SmallVector<std::pair<llvm::Init*, StringInit*>, 8> DagArgs;
if (Lex.getCode() != tgtok::r_paren) {
DagArgs = ParseDagArgList(CurRec);
ParseDagArgList(DagArgs, CurRec);
if (DagArgs.empty()) return nullptr;
}
@ -1603,9 +1603,9 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
/// DagArg ::= VARNAME
/// DagArgList ::= DagArg
/// DagArgList ::= DagArgList ',' DagArg
std::vector<std::pair<llvm::Init*, StringInit*> >
TGParser::ParseDagArgList(Record *CurRec) {
std::vector<std::pair<llvm::Init*, StringInit*> > Result;
void TGParser::ParseDagArgList(
SmallVectorImpl<std::pair<llvm::Init*, StringInit*>> &Result,
Record *CurRec) {
while (true) {
// DagArg ::= VARNAME
@ -1617,15 +1617,18 @@ TGParser::ParseDagArgList(Record *CurRec) {
} else {
// DagArg ::= Value (':' VARNAME)?
Init *Val = ParseValue(CurRec);
if (!Val)
return std::vector<std::pair<llvm::Init*, StringInit*> >();
if (!Val) {
Result.clear();
return;
}
// If the variable name is present, add it.
StringInit *VarName = nullptr;
if (Lex.getCode() == tgtok::colon) {
if (Lex.Lex() != tgtok::VarName) { // eat the ':'
TokError("expected variable name in dag literal");
return std::vector<std::pair<llvm::Init*, StringInit*> >();
Result.clear();
return;
}
VarName = StringInit::get(Lex.getCurStrVal());
Lex.Lex(); // eat the VarName.
@ -1636,8 +1639,6 @@ TGParser::ParseDagArgList(Record *CurRec) {
if (Lex.getCode() != tgtok::comma) break;
Lex.Lex(); // eat the ','
}
return Result;
}
/// ParseValueList - Parse a comma separated list of values, returning them as a

View File

@ -175,7 +175,9 @@ private: // Parser methods.
IDParseMode Mode = ParseValueMode);
std::vector<Init*> ParseValueList(Record *CurRec, Record *ArgsRec = nullptr,
RecTy *EltTy = nullptr);
std::vector<std::pair<llvm::Init*, StringInit*> > ParseDagArgList(Record *);
void ParseDagArgList(
SmallVectorImpl<std::pair<llvm::Init*, StringInit*>> &Result,
Record *CurRec);
bool ParseOptionalRangeList(std::vector<unsigned> &Ranges);
bool ParseOptionalBitList(std::vector<unsigned> &Ranges);
std::vector<unsigned> ParseRangeList();