[llvm] 2d4c4d3 - [TableGen] Change assertion information from a tuple to a struct [NFC]
Paul C. Anagnostopoulos via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 26 06:58:40 PDT 2021
Author: Paul C. Anagnostopoulos
Date: 2021-04-26T09:57:16-04:00
New Revision: 2d4c4d3c54365215849d964c2fdd31536585db19
URL: https://github.com/llvm/llvm-project/commit/2d4c4d3c54365215849d964c2fdd31536585db19
DIFF: https://github.com/llvm/llvm-project/commit/2d4c4d3c54365215849d964c2fdd31536585db19.diff
LOG: [TableGen] Change assertion information from a tuple to a struct [NFC]
Differential Revision: https://reviews.llvm.org/D100854
Added:
Modified:
llvm/include/llvm/TableGen/Record.h
llvm/lib/TableGen/Record.cpp
llvm/lib/TableGen/TGParser.cpp
llvm/lib/TableGen/TGParser.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index 3c8ad127b78ad..d8f978f504476 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -1471,7 +1471,16 @@ inline raw_ostream &operator<<(raw_ostream &OS, const RecordVal &RV) {
class Record {
public:
- using AssertionTuple = std::tuple<SMLoc, Init *, Init *>;
+ 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 @@ class Record {
SmallVector<SMLoc, 4> Locs;
SmallVector<Init *, 0> TemplateArgs;
SmallVector<RecordVal, 0> Values;
- // Vector of [source location, condition Init, message Init].
- SmallVector<AssertionTuple, 0> Assertions;
+ SmallVector<AssertionInfo, 0> 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 @@ class Record {
ArrayRef<RecordVal> getValues() const { return Values; }
- ArrayRef<AssertionTuple> getAssertions() const { return Assertions; }
+ ArrayRef<AssertionInfo> getAssertions() const { return Assertions; }
ArrayRef<std::pair<Record *, SMRange>> getSuperClasses() const {
return SuperClasses;
@@ -1616,7 +1624,7 @@ class Record {
}
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) {
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 501654e52b6b0..6e63fb3f7fffd 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -2379,10 +2379,10 @@ void Record::resolveReferences(Resolver &R, const RecordVal *SkipVal) {
// 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 @@ void Record::checkRecordAssertions() {
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);
}
}
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index a285f6023e083..1e5915f60bb74 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -365,8 +365,7 @@ bool TGParser::addEntry(RecordsEntry E) {
// 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 @@ bool TGParser::resolve(const std::vector<RecordsEntry> &Source,
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<Record::AssertionTuple> Tuple =
- std::make_unique<Record::AssertionTuple>(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<Record::AssertionInfo>(
+ E.Assertion->Loc, Condition, Message));
+ else
+ CheckAssert(E.Assertion->Loc, Condition, Message);
} else {
auto Rec = std::make_unique<Record>(*E.Rec);
@@ -3219,14 +3214,11 @@ bool TGParser::ParseAssert(MultiClass *CurMultiClass, Record *CurRec) {
if (!consume(tgtok::semi))
return TokError("expected ';'");
- if (CurRec) {
+ if (CurRec)
CurRec->addAssertion(ConditionLoc, Condition, Message);
- } else {
- std::unique_ptr<Record::AssertionTuple> Tuple =
- std::make_unique<Record::AssertionTuple>(ConditionLoc, Condition, Message);
- addEntry(std::move(Tuple));
- }
-
+ else
+ addEntry(std::make_unique<Record::AssertionInfo>(ConditionLoc, Condition,
+ Message));
return false;
}
diff --git a/llvm/lib/TableGen/TGParser.h b/llvm/lib/TableGen/TGParser.h
index 254ce3c90980e..f4311346555d0 100644
--- a/llvm/lib/TableGen/TGParser.h
+++ b/llvm/lib/TableGen/TGParser.h
@@ -37,20 +37,20 @@ namespace llvm {
};
/// RecordsEntry - Holds exactly one of a Record, ForeachLoop, or
- /// assertion tuple.
+ /// AssertionInfo.
struct RecordsEntry {
std::unique_ptr<Record> Rec;
std::unique_ptr<ForeachLoop> Loop;
- std::unique_ptr<Record::AssertionTuple> Assertion;
+ std::unique_ptr<Record::AssertionInfo> Assertion;
void dump() const;
RecordsEntry() {}
RecordsEntry(std::unique_ptr<Record> Rec) : Rec(std::move(Rec)) {}
RecordsEntry(std::unique_ptr<ForeachLoop> Loop)
- : Loop(std::move(Loop)) {}
- RecordsEntry(std::unique_ptr<Record::AssertionTuple> Assertion)
- : Assertion(std::move(Assertion)) {}
+ : Loop(std::move(Loop)) {}
+ RecordsEntry(std::unique_ptr<Record::AssertionInfo> Assertion)
+ : Assertion(std::move(Assertion)) {}
};
/// ForeachLoop - Record the iteration state associated with a for loop.
More information about the llvm-commits
mailing list