[PATCH] D44196: TableGen: Move GenStrConcat to a helper function in BinOpInit
Nicolai Hähnle via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 7 03:15:57 PST 2018
nhaehnle created this revision.
nhaehnle added reviewers: arsenm, craig.topper, tra, MartinO.
Herald added a subscriber: wdng.
nhaehnle added a dependency: D44195: TableGen: Remove the cast-from-string-to-variable-reference feature.
Make it accessible for more users.
Change-Id: Ib05f09ba14e7942ced5d2f24b205efa285e40cd5
Repository:
rL LLVM
https://reviews.llvm.org/D44196
Files:
include/llvm/TableGen/Record.h
lib/TableGen/Record.cpp
lib/TableGen/TGParser.cpp
Index: lib/TableGen/TGParser.cpp
===================================================================
--- lib/TableGen/TGParser.cpp
+++ lib/TableGen/TGParser.cpp
@@ -1993,9 +1993,7 @@
break;
}
- Result =
- BinOpInit::get(BinOpInit::STRCONCAT, LHS, RHS, StringRecTy::get())
- ->Fold(CurRec);
+ Result = BinOpInit::getStrConcat(LHS, RHS);
break;
}
}
@@ -2830,12 +2828,10 @@
if (DefNameString) {
// We have a fully expanded string so there are no operators to
// resolve. We should concatenate the given prefix and name.
- DefName = BinOpInit::get(
- BinOpInit::STRCONCAT,
- UnOpInit::get(UnOpInit::CAST, DefmPrefix, StringRecTy::get())
- ->Fold(DefProto),
- DefName, StringRecTy::get())
- ->Fold(DefProto);
+ DefName = BinOpInit::getStrConcat(
+ UnOpInit::get(UnOpInit::CAST, DefmPrefix, StringRecTy::get())
+ ->Fold(DefProto),
+ DefName);
}
// Make a trail of SMLocs from the multiclass instantiations.
Index: lib/TableGen/Record.cpp
===================================================================
--- lib/TableGen/Record.cpp
+++ lib/TableGen/Record.cpp
@@ -815,6 +815,14 @@
return StringInit::get(Concat);
}
+Init *BinOpInit::getStrConcat(Init *I0, Init *I1) {
+ // Shortcut for the common case of concatenating two strings.
+ if (const StringInit *I0s = dyn_cast<StringInit>(I0))
+ if (const StringInit *I1s = dyn_cast<StringInit>(I1))
+ return ConcatStringInits(I0s, I1s);
+ return BinOpInit::get(BinOpInit::STRCONCAT, I0, I1, StringRecTy::get());
+}
+
Init *BinOpInit::Fold(Record *CurRec) const {
switch (getOpcode()) {
case CONCAT: {
@@ -2147,22 +2155,15 @@
return Defs;
}
-static Init *GetStrConcat(Init *I0, Init *I1) {
- // Shortcut for the common case of concatenating two strings.
- if (const StringInit *I0s = dyn_cast<StringInit>(I0))
- if (const StringInit *I1s = dyn_cast<StringInit>(I1))
- return ConcatStringInits(I0s, I1s);
- return BinOpInit::get(BinOpInit::STRCONCAT, I0, I1, StringRecTy::get());
-}
-
Init *llvm::QualifyName(Record &CurRec, MultiClass *CurMultiClass,
Init *Name, StringRef Scoper) {
- Init *NewName = GetStrConcat(CurRec.getNameInit(), StringInit::get(Scoper));
- NewName = GetStrConcat(NewName, Name);
+ Init *NewName =
+ BinOpInit::getStrConcat(CurRec.getNameInit(), StringInit::get(Scoper));
+ NewName = BinOpInit::getStrConcat(NewName, Name);
if (CurMultiClass && Scoper != "::") {
- Init *Prefix = GetStrConcat(CurMultiClass->Rec.getNameInit(),
- StringInit::get("::"));
- NewName = GetStrConcat(Prefix, NewName);
+ Init *Prefix = BinOpInit::getStrConcat(CurMultiClass->Rec.getNameInit(),
+ StringInit::get("::"));
+ NewName = BinOpInit::getStrConcat(Prefix, NewName);
}
if (BinOpInit *BinOp = dyn_cast<BinOpInit>(NewName))
Index: include/llvm/TableGen/Record.h
===================================================================
--- include/llvm/TableGen/Record.h
+++ include/llvm/TableGen/Record.h
@@ -821,6 +821,7 @@
static BinOpInit *get(BinaryOp opc, Init *lhs, Init *rhs,
RecTy *Type);
+ static Init *getStrConcat(Init *lhs, Init *rhs);
void Profile(FoldingSetNodeID &ID) const;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44196.137348.patch
Type: text/x-patch
Size: 3447 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180307/8b5c6eb3/attachment.bin>
More information about the llvm-commits
mailing list