[Mlir-commits] [mlir] [MLIR][TableGen] Add gen-attrdef-list (PR #126332)
River Riddle
llvmlistbot at llvm.org
Mon Feb 10 15:18:11 PST 2025
River707 wrote:
> @River707 Thanks! I had tried to figure out a way to do this with the existing GET_ATTRDEF_LIST but I couldn't find my way to a solution. It looks like TypeSwitch is the piece I was missing.
>
> I did still run into a problem trying to adapt my visitor base class, because (at least with the compiler I'm using) TypeSwitch doesn't like taking a template parameter for the return type. That is, when I try this:
>
> ```
> RetTy visit(mlir::Attribute attr) {
> #define GET_ATTRDEF_LIST
> return llvm::TypeSwitch<mlir::Attribute, RetTy>(attr)
> .Case<
> #include "clang/CIR/Dialect/IR/CIROpsAttributes.cpp.inc"
> >([&](auto attrT) { return getImpl()->visitCirAttr(attrT); })
> .Default([&](auto attrT) { return getImpl()->visitNonCirAttr(attrT); });
> }
> ```
>
> I get a bunch of errors like this:
>
> ```
> llvm-project/build/tools/clang/include/clang/CIR/Dialect/IR/CIROpsAttributes.cpp.inc: In member function ‘RetTy cir::CirAttrVisitor<ImplClass, RetTy>::visit(mlir::Attribute)’:
> llvm-project/build/tools/clang/include/clang/CIR/Dialect/IR/CIROpsAttributes.cpp.inc:12:16: error: expected primary-expression before ‘,’ token
> 12 | ::cir::LangAttr,
> | ^
> ```
>
> But if I switch to this:
>
> ```
> return llvm::TypeSwitch<mlir::Attribute, mlir::Value>(attr)
> ```
>
> It works. That feels like a compiler bug, but I could be missing something.
>
> However, I don't think I need it to work. I updated my clangir patch to just use TypeSwitch in my visitor implementation class, and I don't think I will even need to use GET_ATTRDEF_LIST.
>
> If you're interested, the updated clangir change is here: [llvm/clangir#1330](https://github.com/llvm/clangir/pull/1330)
>
> I'll close this PR if the new clangir implementation is acceptable to the reviewers there.
Nice, I'm glad that worked. This use case is one of the reasons I wrote TypeSwitch initially. The template error seems a bit weird, I feel like I've written that exact code before.
https://github.com/llvm/llvm-project/pull/126332
More information about the Mlir-commits
mailing list