[llvm] [TableGen] Add a !listflatten operator to TableGen (PR #109346)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 20 05:57:35 PDT 2024
================
@@ -987,6 +987,29 @@ Init *UnOpInit::Fold(Record *CurRec, bool IsFinal) const {
}
}
break;
+
+ case LISTFLATTEN:
+ if (ListInit *LHSList = dyn_cast<ListInit>(LHS)) {
+ ListRecTy *InnerListTy = dyn_cast<ListRecTy>(LHSList->getElementType());
+ // list of non-lists, !listflatten() is a NOP.
+ if (!InnerListTy)
+ return LHS;
+ std::vector<Init *> Flattened;
+ auto CanFlatten = [LHSList, &Flattened]() {
+ // Concatenate elements of all the inner lists.
+ for (Init *InnerInit : LHSList->getValues()) {
+ ListInit *InnerList = dyn_cast<ListInit>(InnerInit);
+ if (!InnerList)
+ return false;
+ for (Init *InnerElem : InnerList->getValues())
+ Flattened.push_back(InnerElem);
+ };
+ return true;
+ }();
----------------
jurahul wrote:
No, this is defining a lambda and then immediately calling it (with no args). The lambda will fill up the Flattend array and if failed, return false (which happens when there are still unresolved references from what I can tell. They do get resolved later though).
https://github.com/llvm/llvm-project/pull/109346
More information about the llvm-commits
mailing list