[Mlir-commits] [mlir] mlir: add an operation to EmitC for function template instantiation (PR #100895)
Simon Camphausen
llvmlistbot at llvm.org
Wed Jul 31 03:21:51 PDT 2024
================
@@ -1260,5 +1260,32 @@ def EmitC_SubscriptOp : EmitC_Op<"subscript", []> {
let assemblyFormat = "$value `[` $indices `]` attr-dict `:` functional-type(operands, results)";
}
+def EmitC_InstantiateFunctionTemplateOp : EmitC_Op<"instantiate_function_template", []> {
+ let summary = "Instantiate template operation";
+ let description = [{
+ Instantiate a function template with a given set of types
+ (given by the values as argument to this operation) to obtain
+ a function pointer.
+
+ Example:
+
+ ```mlir
+ %c1 = "emitc.constant"() <{value = 7 : i32}> : () -> i32
+ %0 = emitc.instantiate_function_template "func_template"<%c1> : (i32) -> !emitc.ptr<!emitc.opaque<"void">>
+ ```
+ Translates to the C++:
+ ```c++
+ int32_t v1 = 7;
+ void* v2 = &func_template<decltype(v1)>;
----------------
simon-camp wrote:
We can add an `call_indirect` op, similar to the `func` dialect. But we would need to also add support for function types in the emitter (or add an generic auto type, but that might have problems with wrongly inferred types if used in other places).
OTOH, is it even legal to cast function pointers to `void *`?
https://github.com/llvm/llvm-project/pull/100895
More information about the Mlir-commits
mailing list