Index: llvm/include/llvm/TableGen/Record.h =================================================================== --- llvm/include/llvm/TableGen/Record.h +++ llvm/include/llvm/TableGen/Record.h @@ -1471,7 +1471,16 @@ class Record { public: - using AssertionTuple = std::tuple; + struct AssertionInfo { + SMLoc Loc; + Init *Condition; + Init *Message; + + // User-defined constructor to support std::make_unique(). It can be + // removed in C++20 when braced initialization is supported. + AssertionInfo(SMLoc Loc, Init *Condition, Init *Message) + : Loc(Loc), Condition(Condition), Message(Message) {} + }; private: static unsigned LastID; @@ -1482,8 +1491,7 @@ SmallVector Locs; SmallVector TemplateArgs; SmallVector Values; - // Vector of [source location, condition Init, message Init]. - SmallVector Assertions; + SmallVector Assertions; // All superclasses in the inheritance forest in post-order (yes, it // must be a forest; diamond-shaped inheritance is not allowed). @@ -1558,7 +1566,7 @@ ArrayRef getValues() const { return Values; } - ArrayRef getAssertions() const { return Assertions; } + ArrayRef getAssertions() const { return Assertions; } ArrayRef> getSuperClasses() const { return SuperClasses; @@ -1616,7 +1624,7 @@ } void addAssertion(SMLoc Loc, Init *Condition, Init *Message) { - Assertions.push_back(std::make_tuple(Loc, Condition, Message)); + Assertions.push_back(AssertionInfo(Loc, Condition, Message)); } void appendAssertions(const Record *Rec) { Index: llvm/lib/TableGen/Record.cpp =================================================================== --- llvm/lib/TableGen/Record.cpp +++ llvm/lib/TableGen/Record.cpp @@ -2379,10 +2379,10 @@ // Resolve the assertion expressions. for (auto &Assertion : Assertions) { - Init *Value = std::get<1>(Assertion)->resolveReferences(R); - std::get<1>(Assertion) = Value; - Value = std::get<2>(Assertion)->resolveReferences(R); - std::get<2>(Assertion) = Value; + Init *Value = Assertion.Condition->resolveReferences(R); + Assertion.Condition = Value; + Value = Assertion.Message->resolveReferences(R); + Assertion.Message = Value; } } @@ -2634,9 +2634,9 @@ R.setFinal(true); for (auto Assertion : getAssertions()) { - Init *Condition = std::get<1>(Assertion)->resolveReferences(R); - Init *Message = std::get<2>(Assertion)->resolveReferences(R); - CheckAssert(std::get<0>(Assertion), Condition, Message); + Init *Condition = Assertion.Condition->resolveReferences(R); + Init *Message = Assertion.Message->resolveReferences(R); + CheckAssert(Assertion.Loc, Condition, Message); } } Index: llvm/lib/TableGen/TGParser.h =================================================================== --- llvm/lib/TableGen/TGParser.h +++ llvm/lib/TableGen/TGParser.h @@ -37,20 +37,20 @@ }; /// RecordsEntry - Holds exactly one of a Record, ForeachLoop, or - /// assertion tuple. + /// AssertionInfo. struct RecordsEntry { std::unique_ptr Rec; std::unique_ptr Loop; - std::unique_ptr Assertion; + std::unique_ptr Assertion; void dump() const; RecordsEntry() {} RecordsEntry(std::unique_ptr Rec) : Rec(std::move(Rec)) {} RecordsEntry(std::unique_ptr Loop) - : Loop(std::move(Loop)) {} - RecordsEntry(std::unique_ptr Assertion) - : Assertion(std::move(Assertion)) {} + : Loop(std::move(Loop)) {} + RecordsEntry(std::unique_ptr Assertion) + : Assertion(std::move(Assertion)) {} }; /// ForeachLoop - Record the iteration state associated with a for loop. Index: llvm/lib/TableGen/TGParser.cpp =================================================================== --- llvm/lib/TableGen/TGParser.cpp +++ llvm/lib/TableGen/TGParser.cpp @@ -365,8 +365,7 @@ // If it is an assertion, then it's a top-level one, so check it. if (E.Assertion) { - CheckAssert(std::get<0>(*E.Assertion), std::get<1>(*E.Assertion), - std::get<2>(*E.Assertion)); + CheckAssert(E.Assertion->Loc, E.Assertion->Condition, E.Assertion->Message); return false; } @@ -430,18 +429,14 @@ MapResolver R; for (const auto &S : Substs) R.set(S.first, S.second); - Init *Condition = std::get<1>(*E.Assertion)->resolveReferences(R); - Init *Message = std::get<2>(*E.Assertion)->resolveReferences(R); - - if (Dest) { - std::unique_ptr Tuple = - std::make_unique(std::get<0>(*E.Assertion), - std::move(Condition), - std::move(Message)); - Dest->push_back(std::move(Tuple)); - } else { - CheckAssert(std::get<0>(*E.Assertion), Condition, Message); - } + Init *Condition = E.Assertion->Condition->resolveReferences(R); + Init *Message = E.Assertion->Message->resolveReferences(R); + + if (Dest) + Dest->push_back(std::make_unique( + E.Assertion->Loc, Condition, Message)); + else + CheckAssert(E.Assertion->Loc, Condition, Message); } else { auto Rec = std::make_unique(*E.Rec); @@ -3219,14 +3214,11 @@ if (!consume(tgtok::semi)) return TokError("expected ';'"); - if (CurRec) { + if (CurRec) CurRec->addAssertion(ConditionLoc, Condition, Message); - } else { - std::unique_ptr Tuple = - std::make_unique(ConditionLoc, Condition, Message); - addEntry(std::move(Tuple)); - } - + else + addEntry(std::make_unique(ConditionLoc, Condition, + Message)); return false; }