[Mlir-commits] [mlir] [MLIR] emitc: Add fmtArgs to verbatim (PR #123294)
Matthias Gehre
llvmlistbot at llvm.org
Thu Jan 30 06:03:38 PST 2025
mgehre-amd wrote:
> I have two high level questions before reviewing in detail.
>
> Can you show a case on how you intend to use this feature. It looks like this can be used (and abused) to do all kinds of side effecting operations to MLIR values, and I'm not sure how this interacts with the whole system.
Yes, verbatim is a sharp knife and you can stab yourself with it. Our main applications is to generate `#pragmas my_own pragma varable=v1` that refer to local variables. Similarly, I guess it can be useful to call macros on local variables.
> For the generalization of opaque types; Do you use it for other things than templated types? I have considered having a template type like `!emitc.template<"std::vector", [i32]>`. This would be more structured than string formatting, but maybe it is too limiting for your use cases.
Yes, we use it to generate template instantiations. `!emitc.template` would also work, but we found not much benefit over `!emitc.verbatim` because `template` types don't have more semantic meaning than `verbatim` types; it's just a more structured way to do the text replacement. On the other hand `!emitc.opaque` with arguments is strictly more powerful, so it's useful to have this first.
> If we agree to land this, can we somehow back the formatting on [llvm utilities](https://llvm.org/docs/ProgrammersManual.html#formatting-strings-the-formatv-function)?
I initially implemented it based on that. There is one main problem: the formatv functions expect the format string to be correct, and otherwise assert. Here, the format string is part of the user input and should lead to IR verification failure but not to an assert.
This lead me to implement a simple grammar for the replacement.
https://github.com/llvm/llvm-project/pull/123294
More information about the Mlir-commits
mailing list