LLVM Discussion Forums

[RFC] Use absolute identifiers in mlir-tblgen

One thing I’ve noticed about using mlir-tblgen – it emits code assuming that the code is used either within the mlir namespace, or with at least some of the mlir namespace imported. E.g. from RewriterGen.cpp:454:

os << formatv(R"(struct {0} : public RewritePattern {
{0}(MLIRContext *context)
    : RewritePattern("{1}", {{)",

I’m wondering whether it’d be okay to change this to use absolute MLIR identifiers, so that the code looks something like:

os << formatv(R"(struct {0} : public ::mlir::RewritePattern {
{0}(::mlir::MLIRContext *context)
    : ::mlir::RewritePattern("{1}", {{)",


1 Like

For types/classes where we know unambigiously where they are this makes sense to me. We could make expectations clearer wrt in which namespace the code should get included etc.

@antiagainst Thoughts?

+1 from me. This is clearer and more resilient. It avoids subtle symbol resolution issues given that presumably we will have may dialects and they can well have similar ops. If pulling in two dialects for declarative patterns, the generated C++ patterns are safer with qualified symbols.

+1 from me as well. This change makes it a lot easier to use mlir-tblgen in projects outside of the LLVM tree.

@earhart, have you had a chance to start on this work? I’d be happy to collaborate.