summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2016-12-04 05:48:03 +0000
committerMatthias Braun <matze@braunis.de>2016-12-04 05:48:03 +0000
commit5084450e17cfff583fbb281815e9d55ee51f2008 (patch)
tree440f39d99ab3bdb7040cbfe6db490341ad984b95
parent85334ad0c5d15dcf84ff0e3675a86da0bc13786b (diff)
TableGen: Use StringRef instead of const std::string& for parameters
This avoid an extra construction of a std::string (and a heap allocation) when the caller only has a StringRef but no std::string at hand. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288610 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/TableGen/Record.h51
-rw-r--r--lib/TableGen/Record.cpp34
-rw-r--r--lib/TableGen/TGParser.cpp3
-rw-r--r--lib/TableGen/TGParser.h7
4 files changed, 44 insertions, 51 deletions
diff --git a/include/llvm/TableGen/Record.h b/include/llvm/TableGen/Record.h
index 37c7ddff9ad..e3de7441545 100644
--- a/include/llvm/TableGen/Record.h
+++ b/include/llvm/TableGen/Record.h
@@ -360,7 +360,7 @@ public:
/// Implementors of this method should return the type of the named field if
/// they are of record type.
///
- virtual RecTy *getFieldType(const std::string &FieldName) const {
+ virtual RecTy *getFieldType(StringRef FieldName) const {
return nullptr;
}
@@ -369,7 +369,7 @@ public:
/// this method should return non-null, otherwise it returns null.
///
virtual Init *getFieldInit(Record &R, const RecordVal *RV,
- const std::string &FieldName) const {
+ StringRef FieldName) const {
return nullptr;
}
@@ -436,7 +436,7 @@ public:
/// Implementors of this method should return the type of the named field if
/// they are of record type.
///
- RecTy *getFieldType(const std::string &FieldName) const override;
+ RecTy *getFieldType(StringRef FieldName) const override;
/// This method is used to implement
/// VarListElementInit::resolveReferences. If the list element is resolvable
@@ -961,7 +961,7 @@ public:
return I->getKind() == IK_VarInit;
}
- static VarInit *get(const std::string &VN, RecTy *T);
+ static VarInit *get(StringRef VN, RecTy *T);
static VarInit *get(Init *VN, RecTy *T);
const std::string &getName() const;
@@ -974,9 +974,9 @@ public:
Init *resolveListElementReference(Record &R, const RecordVal *RV,
unsigned Elt) const override;
- RecTy *getFieldType(const std::string &FieldName) const override;
+ RecTy *getFieldType(StringRef FieldName) const override;
Init *getFieldInit(Record &R, const RecordVal *RV,
- const std::string &FieldName) const override;
+ StringRef FieldName) const override;
/// This method is used by classes that refer to other
/// variables which may not be defined at the time they expression is formed.
@@ -1092,9 +1092,9 @@ public:
//virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
- RecTy *getFieldType(const std::string &FieldName) const override;
+ RecTy *getFieldType(StringRef FieldName) const override;
Init *getFieldInit(Record &R, const RecordVal *RV,
- const std::string &FieldName) const override;
+ StringRef FieldName) const override;
std::string getAsString() const override;
@@ -1117,7 +1117,7 @@ class FieldInit : public TypedInit {
Init *Rec; // Record we are referring to
std::string FieldName; // Field we are accessing
- FieldInit(Init *R, const std::string &FN)
+ FieldInit(Init *R, StringRef FN)
: TypedInit(IK_FieldInit, R->getFieldType(FN)), Rec(R), FieldName(FN) {
assert(getType() && "FieldInit with non-record type!");
}
@@ -1130,7 +1130,7 @@ public:
return I->getKind() == IK_FieldInit;
}
- static FieldInit *get(Init *R, const std::string &FN);
+ static FieldInit *get(Init *R, StringRef FN);
Init *getBit(unsigned Bit) const override;
@@ -1154,8 +1154,7 @@ class DagInit : public TypedInit, public FoldingSetNode {
std::vector<Init*> Args;
std::vector<std::string> ArgNames;
- DagInit(Init *V, const std::string &VN,
- ArrayRef<Init *> ArgRange,
+ DagInit(Init *V, StringRef VN, ArrayRef<Init *> ArgRange,
ArrayRef<std::string> NameRange)
: TypedInit(IK_DagInit, DagRecTy::get()), Val(V), ValName(VN),
Args(ArgRange.begin(), ArgRange.end()),
@@ -1169,10 +1168,9 @@ public:
return I->getKind() == IK_DagInit;
}
- static DagInit *get(Init *V, const std::string &VN,
- ArrayRef<Init *> ArgRange,
+ static DagInit *get(Init *V, StringRef VN, ArrayRef<Init *> ArgRange,
ArrayRef<std::string> NameRange);
- static DagInit *get(Init *V, const std::string &VN,
+ static DagInit *get(Init *V, StringRef VN,
const std::vector<std::pair<Init*, std::string>> &args);
void Profile(FoldingSetNodeID &ID) const;
@@ -1233,7 +1231,7 @@ class RecordVal {
public:
RecordVal(Init *N, RecTy *T, bool P);
- RecordVal(const std::string &N, RecTy *T, bool P);
+ RecordVal(StringRef N, RecTy *T, bool P);
const std::string &getName() const;
const Init *getNameInit() const { return NameAndPrefix.getPointer(); }
@@ -1309,8 +1307,8 @@ public:
init();
}
- explicit Record(const std::string &N, ArrayRef<SMLoc> locs,
- RecordKeeper &records, bool Anonymous = false)
+ explicit Record(StringRef N, ArrayRef<SMLoc> locs, RecordKeeper &records,
+ bool Anonymous = false)
: Record(StringInit::get(N), locs, records, Anonymous) {}
// When copy-constructing a Record, we must still guarantee a globally unique
@@ -1335,8 +1333,8 @@ public:
return getNameInit()->getAsUnquotedString();
}
- void setName(Init *Name); // Also updates RecordKeeper.
- void setName(const std::string &Name); // Also updates RecordKeeper.
+ void setName(Init *Name); // Also updates RecordKeeper.
+ void setName(StringRef Name); // Also updates RecordKeeper.
ArrayRef<SMLoc> getLoc() const { return Locs; }
@@ -1559,7 +1557,7 @@ struct MultiClass {
void dump() const;
- MultiClass(const std::string &Name, SMLoc Loc, RecordKeeper &Records) :
+ MultiClass(StringRef Name, SMLoc Loc, RecordKeeper &Records) :
Rec(Name, Loc, Records) {}
};
@@ -1571,12 +1569,12 @@ public:
const RecordMap &getClasses() const { return Classes; }
const RecordMap &getDefs() const { return Defs; }
- Record *getClass(const std::string &Name) const {
+ Record *getClass(StringRef Name) const {
auto I = Classes.find(Name);
return I == Classes.end() ? nullptr : I->second.get();
}
- Record *getDef(const std::string &Name) const {
+ Record *getDef(StringRef Name) const {
auto I = Defs.find(Name);
return I == Defs.end() ? nullptr : I->second.get();
}
@@ -1601,8 +1599,7 @@ public:
/// This method returns all concrete definitions
/// that derive from the specified class name. A class with the specified
/// name must exist.
- std::vector<Record *>
- getAllDerivedDefinitions(const std::string &ClassName) const;
+ std::vector<Record *> getAllDerivedDefinitions(StringRef ClassName) const;
void dump() const;
};
@@ -1718,12 +1715,12 @@ raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK);
/// Return an Init with a qualifier prefix referring
/// to CurRec's name.
Init *QualifyName(Record &CurRec, MultiClass *CurMultiClass,
- Init *Name, const std::string &Scoper);
+ Init *Name, StringRef Scoper);
/// Return an Init with a qualifier prefix referring
/// to CurRec's name.
Init *QualifyName(Record &CurRec, MultiClass *CurMultiClass,
- const std::string &Name, const std::string &Scoper);
+ StringRef Name, StringRef Scoper);
} // end namespace llvm
diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp
index bffe27144cf..3e1be837039 100644
--- a/lib/TableGen/Record.cpp
+++ b/lib/TableGen/Record.cpp
@@ -43,7 +43,7 @@ namespace llvm {
class TableGenStringKey {
public:
- TableGenStringKey(const std::string &str) : data(str) {}
+ TableGenStringKey(StringRef str) : data(str) {}
TableGenStringKey(const char *str) : data(str) {}
const std::string &str() const { return data; }
@@ -1155,7 +1155,7 @@ std::string TernOpInit::getAsString() const {
RHS->getAsString() + ")";
}
-RecTy *TypedInit::getFieldType(const std::string &FieldName) const {
+RecTy *TypedInit::getFieldType(StringRef FieldName) const {
if (RecordRecTy *RecordType = dyn_cast<RecordRecTy>(getType()))
if (RecordVal *Field = RecordType->getRecord()->getValue(FieldName))
return Field->getType();
@@ -1277,7 +1277,7 @@ TypedInit::convertInitListSlice(const std::vector<unsigned> &Elements) const {
}
-VarInit *VarInit::get(const std::string &VN, RecTy *T) {
+VarInit *VarInit::get(StringRef VN, RecTy *T) {
Init *Value = StringInit::get(VN);
return VarInit::get(Value, T);
}
@@ -1327,7 +1327,7 @@ Init *VarInit::resolveListElementReference(Record &R,
return nullptr;
}
-RecTy *VarInit::getFieldType(const std::string &FieldName) const {
+RecTy *VarInit::getFieldType(StringRef FieldName) const {
if (RecordRecTy *RTy = dyn_cast<RecordRecTy>(getType()))
if (const RecordVal *RV = RTy->getRecord()->getValue(FieldName))
return RV->getType();
@@ -1335,7 +1335,7 @@ RecTy *VarInit::getFieldType(const std::string &FieldName) const {
}
Init *VarInit::getFieldInit(Record &R, const RecordVal *RV,
- const std::string &FieldName) const {
+ StringRef FieldName) const {
if (isa<RecordRecTy>(getType()))
if (const RecordVal *Val = R.getValue(VarName)) {
if (RV != Val && (RV || isa<UnsetInit>(Val->getValue())))
@@ -1442,14 +1442,14 @@ Init *DefInit::convertInitializerTo(RecTy *Ty) const {
return nullptr;
}
-RecTy *DefInit::getFieldType(const std::string &FieldName) const {
+RecTy *DefInit::getFieldType(StringRef FieldName) const {
if (const RecordVal *RV = Def->getValue(FieldName))
return RV->getType();
return nullptr;
}
Init *DefInit::getFieldInit(Record &R, const RecordVal *RV,
- const std::string &FieldName) const {
+ StringRef FieldName) const {
return Def->getValue(FieldName)->getValue();
}
@@ -1457,7 +1457,7 @@ std::string DefInit::getAsString() const {
return Def->getName();
}
-FieldInit *FieldInit::get(Init *R, const std::string &FN) {
+FieldInit *FieldInit::get(Init *R, StringRef FN) {
typedef std::pair<Init *, TableGenStringKey> Key;
static DenseMap<Key, std::unique_ptr<FieldInit>> ThePool;
@@ -1503,7 +1503,7 @@ Init *FieldInit::resolveReferences(Record &R, const RecordVal *RV) const {
return const_cast<FieldInit *>(this);
}
-static void ProfileDagInit(FoldingSetNodeID &ID, Init *V, const std::string &VN,
+static void ProfileDagInit(FoldingSetNodeID &ID, Init *V, StringRef VN,
ArrayRef<Init *> ArgRange,
ArrayRef<std::string> NameRange) {
ID.AddPointer(V);
@@ -1520,8 +1520,7 @@ static void ProfileDagInit(FoldingSetNodeID &ID, Init *V, const std::string &VN,
}
DagInit *
-DagInit::get(Init *V, const std::string &VN,
- ArrayRef<Init *> ArgRange,
+DagInit::get(Init *V, StringRef VN, ArrayRef<Init *> ArgRange,
ArrayRef<std::string> NameRange) {
static FoldingSet<DagInit> ThePool;
static std::vector<std::unique_ptr<DagInit>> TheActualPool;
@@ -1540,7 +1539,7 @@ DagInit::get(Init *V, const std::string &VN,
}
DagInit *
-DagInit::get(Init *V, const std::string &VN,
+DagInit::get(Init *V, StringRef VN,
const std::vector<std::pair<Init*, std::string> > &args) {
std::vector<Init *> Args;
std::vector<std::string> Names;
@@ -1602,7 +1601,7 @@ RecordVal::RecordVal(Init *N, RecTy *T, bool P)
assert(Value && "Cannot create unset value for current type!");
}
-RecordVal::RecordVal(const std::string &N, RecTy *T, bool P)
+RecordVal::RecordVal(StringRef N, RecTy *T, bool P)
: NameAndPrefix(StringInit::get(N), P), Ty(T) {
Value = UnsetInit::get()->convertInitializerTo(Ty);
assert(Value && "Cannot create unset value for current type!");
@@ -1668,7 +1667,7 @@ void Record::setName(Init *NewName) {
// this. See TGParser::ParseDef and TGParser::ParseDefm.
}
-void Record::setName(const std::string &Name) {
+void Record::setName(StringRef Name) {
setName(StringInit::get(Name));
}
@@ -1909,7 +1908,7 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const RecordKeeper &RK) {
}
std::vector<Record *>
-RecordKeeper::getAllDerivedDefinitions(const std::string &ClassName) const {
+RecordKeeper::getAllDerivedDefinitions(StringRef ClassName) const {
Record *Class = getClass(ClassName);
if (!Class)
PrintFatalError("ERROR: Couldn't find the `" + ClassName + "' class!\n");
@@ -1923,7 +1922,7 @@ RecordKeeper::getAllDerivedDefinitions(const std::string &ClassName) const {
}
Init *llvm::QualifyName(Record &CurRec, MultiClass *CurMultiClass,
- Init *Name, const std::string &Scoper) {
+ Init *Name, StringRef Scoper) {
RecTy *Type = cast<TypedInit>(Name)->getType();
BinOpInit *NewName =
@@ -1950,7 +1949,6 @@ Init *llvm::QualifyName(Record &CurRec, MultiClass *CurMultiClass,
}
Init *llvm::QualifyName(Record &CurRec, MultiClass *CurMultiClass,
- const std::string &Name,
- const std::string &Scoper) {
+ StringRef Name, StringRef Scoper) {
return QualifyName(CurRec, CurMultiClass, StringInit::get(Name), Scoper);
}
diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp
index ff5c96b0cd5..3d0e4875f96 100644
--- a/lib/TableGen/TGParser.cpp
+++ b/lib/TableGen/TGParser.cpp
@@ -715,8 +715,7 @@ RecTy *TGParser::ParseType() {
/// ParseIDValue - This is just like ParseIDValue above, but it assumes the ID
/// has already been read.
-Init *TGParser::ParseIDValue(Record *CurRec,
- const std::string &Name, SMLoc NameLoc,
+Init *TGParser::ParseIDValue(Record *CurRec, StringRef Name, SMLoc NameLoc,
IDParseMode Mode) {
if (CurRec) {
if (const RecordVal *RV = CurRec->getValue(Name))
diff --git a/lib/TableGen/TGParser.h b/lib/TableGen/TGParser.h
index 739d9a9c5f3..4b163e67bc1 100644
--- a/lib/TableGen/TGParser.h
+++ b/lib/TableGen/TGParser.h
@@ -36,8 +36,7 @@ namespace llvm {
std::vector<unsigned> Bits;
Init *Value;
SMLoc Loc;
- LetRecord(const std::string &N, const std::vector<unsigned> &B, Init *V,
- SMLoc L)
+ LetRecord(StringRef N, const std::vector<unsigned> &B, Init *V, SMLoc L)
: Name(N), Bits(B), Value(V), Loc(L) {
}
};
@@ -107,7 +106,7 @@ private: // Semantic analysis methods.
bool SetValue(Record *TheRec, SMLoc Loc, Init *ValName,
ArrayRef<unsigned> BitList, Init *V,
bool AllowSelfAssignment = false);
- bool SetValue(Record *TheRec, SMLoc Loc, const std::string &ValName,
+ bool SetValue(Record *TheRec, SMLoc Loc, StringRef ValName,
ArrayRef<unsigned> BitList, Init *V,
bool AllowSelfAssignment = false) {
return SetValue(TheRec, Loc, StringInit::get(ValName), BitList, V,
@@ -168,7 +167,7 @@ private: // Parser methods.
SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm);
SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC);
- Init *ParseIDValue(Record *CurRec, const std::string &Name, SMLoc NameLoc,
+ Init *ParseIDValue(Record *CurRec, StringRef Name, SMLoc NameLoc,
IDParseMode Mode = ParseValueMode);
Init *ParseSimpleValue(Record *CurRec, RecTy *ItemType = nullptr,
IDParseMode Mode = ParseValueMode);