[Mlir-commits] [mlir] mlir: add an operation to EmitC for function template instantiation (PR #100895)
Rohan Yadav
llvmlistbot at llvm.org
Wed Jul 31 09:28:47 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:
> OTOH, is it even legal to cast function pointers to void *?
I think it's technically undefined because some kinds of hardware cannot support such a cast. However, the runtime library (CUTLASS) I'm trying to interact with only accepts void* function pointers for a particular function, so its not invalid either.
https://github.com/llvm/llvm-project/pull/100895
More information about the Mlir-commits
mailing list