[Mlir-commits] [mlir] [MLIR][TableGen] Add gen-attrdef-list (PR #126332)
Andy Kaylor
llvmlistbot at llvm.org
Mon Feb 10 14:55:21 PST 2025
andykaylor 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: https://github.com/llvm/clangir/pull/1330
I'll close this PR if the new clangir implementation is acceptable to the reviewers there.
https://github.com/llvm/llvm-project/pull/126332
More information about the Mlir-commits
mailing list