[Mlir-commits] [mlir] [mlir][emitc] Add a `declare_func` operation (PR #80297)
Marius Brehler
llvmlistbot at llvm.org
Thu Feb 1 10:25:41 PST 2024
marbre wrote:
> That's a great and much needed feature. I used some terrible workarounds to achieve the same, and ended up using `VerbatimOp`.
>
> I'd add a test case for when the prototype is emitted inside the function body as well.
Well @simon-camp and me already started discussion the value of a function declaration within a function body. While this is legal in C, it is not as soon as it is a static function. Therefore, I see three option:
* Don't allow function declarations in function bodies at all.
* Allow function declarations in function bodies, but disallow declarations for static functions.
* Allow function declarations anyway and check if the output results in legal C in a validation pass (a validation pass is something I am currently working on).
> It looks like this feature would be incomplete without support of external functions (`mlir::func::FuncOp` which are only declaring the functions). I'd expect [this case](https://github.com/llvm/llvm-project/blob/e7d40a87ff230528131541f6ac17a2e1a7dc78e1/mlir/lib/Conversion/FuncToEmitC/FuncToEmitC.cpp#L60-L62) to naturally map to this operation? Otherwise the use case is rather limited.
To make sure I understand what you're proposing: A `func.func` with empty body should be converted to a `emitc.declare_func` with an `extern` specifier?
https://github.com/llvm/llvm-project/pull/80297
More information about the Mlir-commits
mailing list