From 7cf3b112248267e517758894ab8e6333792aea60 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Mon, 5 Dec 2016 06:00:41 +0000 Subject: [PATCH] TableGen: Use StringInit instead of std::string for DagInit name llvm-svn: 288643 --- llvm/include/llvm/TableGen/Record.h | 13 ++++++++----- llvm/lib/TableGen/Record.cpp | 16 ++++++++-------- llvm/lib/TableGen/TGParser.cpp | 4 ++-- llvm/utils/TableGen/CodeGenDAGPatterns.cpp | 8 ++++---- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h index 1cc6c22..8f08320 100644 --- a/llvm/include/llvm/TableGen/Record.h +++ b/llvm/include/llvm/TableGen/Record.h @@ -1146,11 +1146,11 @@ public: /// class DagInit : public TypedInit, public FoldingSetNode { Init *Val; - std::string ValName; + StringInit *ValName; std::vector Args; std::vector ArgNames; - DagInit(Init *V, StringRef VN, ArrayRef ArgRange, + DagInit(Init *V, StringInit *VN, ArrayRef ArgRange, ArrayRef NameRange) : TypedInit(IK_DagInit, DagRecTy::get()), Val(V), ValName(VN), Args(ArgRange.begin(), ArgRange.end()), @@ -1164,9 +1164,9 @@ public: return I->getKind() == IK_DagInit; } - static DagInit *get(Init *V, StringRef VN, ArrayRef ArgRange, + static DagInit *get(Init *V, StringInit *VN, ArrayRef ArgRange, ArrayRef NameRange); - static DagInit *get(Init *V, StringRef VN, + static DagInit *get(Init *V, StringInit *VN, const std::vector> &args); void Profile(FoldingSetNodeID &ID) const; @@ -1175,7 +1175,10 @@ public: Init *getOperator() const { return Val; } - StringRef getName() const { return ValName; } + StringInit *getName() const { return ValName; } + StringRef getNameStr() const { + return ValName ? ValName->getValue() : StringRef(); + } unsigned getNumArgs() const { return Args.size(); } Init *getArg(unsigned Num) const { diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp index f84a917..2744d4f 100644 --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -838,7 +838,7 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { Args.push_back(RHSs->getArg(i)); ArgNames.push_back(RHSs->getArgName(i)); } - return DagInit::get(LHSs->getOperator(), "", Args, ArgNames); + return DagInit::get(LHSs->getOperator(), nullptr, Args, ArgNames); } break; } @@ -1035,7 +1035,7 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type, args.push_back(std::make_pair(Arg, ArgName)); } - return DagInit::get(Val, "", args); + return DagInit::get(Val, nullptr, args); } ListInit *MHSl = dyn_cast(MHS); @@ -1523,11 +1523,11 @@ Init *FieldInit::resolveReferences(Record &R, const RecordVal *RV) const { return const_cast(this); } -static void ProfileDagInit(FoldingSetNodeID &ID, Init *V, StringRef VN, +static void ProfileDagInit(FoldingSetNodeID &ID, Init *V, StringInit *VN, ArrayRef ArgRange, ArrayRef NameRange) { ID.AddPointer(V); - ID.AddString(VN); + ID.AddPointer(VN); ArrayRef::iterator Arg = ArgRange.begin(); ArrayRef::iterator Name = NameRange.begin(); @@ -1540,7 +1540,7 @@ static void ProfileDagInit(FoldingSetNodeID &ID, Init *V, StringRef VN, } DagInit * -DagInit::get(Init *V, StringRef VN, ArrayRef ArgRange, +DagInit::get(Init *V, StringInit *VN, ArrayRef ArgRange, ArrayRef NameRange) { static FoldingSet ThePool; static std::vector TheActualPool; @@ -1559,7 +1559,7 @@ DagInit::get(Init *V, StringRef VN, ArrayRef ArgRange, } DagInit * -DagInit::get(Init *V, StringRef VN, +DagInit::get(Init *V, StringInit *VN, const std::vector > &args) { std::vector Args; std::vector Names; @@ -1598,8 +1598,8 @@ Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) const { std::string DagInit::getAsString() const { std::string Result = "(" + Val->getAsString(); - if (!ValName.empty()) - Result += ":" + ValName; + if (ValName) + Result += ":" + ValName->getAsUnquotedString(); if (!Args.empty()) { Result += " " + Args[0]->getAsString(); if (!ArgNames[0].empty()) Result += ":$" + ArgNames[0]; diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp index 5b8d730..cbee2e3 100644 --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -1418,13 +1418,13 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType, if (!Operator) return nullptr; // If the operator name is present, parse it. - std::string OperatorName; + StringInit *OperatorName = nullptr; if (Lex.getCode() == tgtok::colon) { if (Lex.Lex() != tgtok::VarName) { // eat the ':' TokError("expected variable name in dag operator"); return nullptr; } - OperatorName = Lex.getCurStrVal(); + OperatorName = StringInit::get(Lex.getCurStrVal()); Lex.Lex(); // eat the VarName. } diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp index 3bda5d0..64b0550 100644 --- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp +++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp @@ -2072,7 +2072,7 @@ TreePatternNode *TreePattern::ParseTreePattern(Init *TheInit, StringRef OpName){ /// (foo GPR, imm) -> (foo GPR, (imm)) if (R->isSubClassOf("SDNode") || R->isSubClassOf("PatFrag")) return ParseTreePattern( - DagInit::get(DI, "", + DagInit::get(DI, nullptr, std::vector >()), OpName); @@ -2226,9 +2226,9 @@ TreePatternNode *TreePattern::ParseTreePattern(Init *TheInit, StringRef OpName){ TreePatternNode *Result = new TreePatternNode(Operator, Children, NumResults); Result->setName(OpName); - if (!Dag->getName().empty()) { + if (Dag->getName()) { assert(Result->getName().empty()); - Result->setName(Dag->getName()); + Result->setName(Dag->getNameStr()); } return Result; } @@ -2546,7 +2546,7 @@ void CodeGenDAGPatterns::ParseDefaultOperands() { for (unsigned op = 0, e = DefaultInfo->getNumArgs(); op != e; ++op) Ops.push_back(std::make_pair(DefaultInfo->getArg(op), DefaultInfo->getArgName(op))); - DagInit *DI = DagInit::get(SomeSDNode, "", Ops); + DagInit *DI = DagInit::get(SomeSDNode, nullptr, Ops); // Create a TreePattern to parse this. TreePattern P(DefaultOps[i], DI, false, *this); -- 2.7.4