[llvm] [TableGen] Add a !listflatten operator to TableGen (PR #109346)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 23 13:48:10 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:
I changed this to have a non-side effecting lambda that returns an std::optional<std::vector<Init *>>. PTAL.
https://github.com/llvm/llvm-project/pull/109346
More information about the llvm-commits
mailing list