[Mlir-commits] [mlir] [mlir][emitc] Add a `declare_func` operation (PR #80297)

Simon Camphausen llvmlistbot at llvm.org
Fri Feb 2 01:11:31 PST 2024


simon-camp wrote:

I agree with the need to declare external functions. We can't rewrite an external func.func to a emitc.declare_func though. The former provides a symbol while the latter refrences an existing symbol. We can convert it to an emitc.func with empty body and adjust the emitter to print it correctly as a declaration. Then `extern "C"` would simply go into the specifier attribute.

So the emitc.declare_func is an operation that can be automatically inserted by a legalization pass to make the compiler happy for cases like mutually recursive functions.

```c
int isEven(unsigned int n) {
   return n == 0 ? 1 : isOdd(n-1);
}

int isOdd(unsigned int n) {
  return n == 1 = 1 : isEven(n-1);
}
```


https://github.com/llvm/llvm-project/pull/80297


More information about the Mlir-commits mailing list