Files
clang-p2996/mlir/docs/Dialects/emitc.md
Marius Brehler c4fd1fd6d4 [mlir][emitc] Rename call op to call_opaque (#72494)
This renames the `emitc.call` op to `emitc.call_opaque` as the existing
call op does not refer to the callee by symbol. The rename allows to
introduce a new call op alongside with a future `emitc.func` op to model
and facilitate functions and function calls.
2023-11-17 10:22:15 +01:00

1.3 KiB

The EmitC dialect allows to convert operations from other MLIR dialects to EmitC ops. Those can be translated to C/C++ via the Cpp emitter.

The following convention is followed:

  • If template arguments are passed to an emitc.call_opaque operation, C++ is generated.
  • If tensors are used, C++ is generated.
  • If multiple return values are used within in a functions or an emitc.call_opaque operation, C++11 is required.
  • If floating-point type template arguments are passed to an emitc.call_opaque operation, C++20 is required.
  • Else the generated code is compatible with C99.

These restrictions are neither inherent to the EmitC dialect itself nor to the Cpp emitter and therefore need to be considered while implementing conversions.

After the conversion, C/C++ code can be emitted with mlir-translate. The tool supports translating MLIR to C/C++ by passing -mlir-to-cpp. Furthermore, code with variables declared at top can be generated by passing the additional argument -declare-variables-at-top.

Besides operations part of the EmitC dialect, the Cpp targets supports translating the following operations:

  • 'cf' Dialect
    • cf.br
    • cf.cond_br
  • 'func' Dialect
    • func.call
    • func.constant
    • func.func
    • func.return
  • 'arith' Dialect
    • arith.constant