[Mlir-commits] [mlir] mlir: add an operation to EmitC for function template instantiation (PR #100895)

Rohan Yadav llvmlistbot at llvm.org
Tue Jul 30 09:27:41 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)>;
----------------
rohany wrote:

I could, but right now there isn't a way to use the returned value except taking a pointer of it, as `call` excepts a `SymbolRefAttr`.

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


More information about the Mlir-commits mailing list