How to pass a function to custom dialect operations in tablegen

When building a custom dialect using tablegen, we can define operations in the following way:

def SomeOp : Dialect_Op<"my_op"> {
    let arguments = (ins FloatLike:$a, FloatLike:$b);
    let results = (outs FloatLike);

    let builders = [
        OpBuilder<(ins "Value":$a, "Value":$b), [{
         build($_builder, $_state, a.getType(), a, b);

What I want is to have one of the input argument being a function instead of a FloatLike. Is it possible to achieve that? Should I do it differently?

If you want it to be an SSA value of (built-in) function type, you can use FunctionType type constraint. If you want it to be a name of a function, you can use SymbolRef attribute constraints. Generally, call and call_indirect are good examples for you llvm-project/ at 8f681d5b272eeb5c0d13d225313f4ea9517f59f5 · llvm/llvm-project · GitHub.

1 Like