Function sharing in MLIR

imagine we have a piece of code shown as below:

variable x
variable y

def bar() {
   ...
}

def foo() {
   ...
   bar()
}

def baz() {
   ...
}

if (x > 100 && y>100) {
   foo()
}
else if ( x<100&&y>100 || x >100&&y<100)
   bar()
} else {
   baz()
}

my question is how to express about structure(graph) with MLIR?
can anyone share some pointers?

seems that Symbols and Symbol Tables - MLIR (llvm.org) is one solution, but no sure if it is correct

Indeed this would be using symbols, there are tons of example in the code base, basically every instance of func.func and call.
This also should be covered in the tutorial: Toy Tutorial - MLIR ; have you already gone through it?

yes, i know func.func and call
and i’m aware of exist of symbol and symbol tables
but i can’t decide if i should use them or not regarding my scenario

MLIR uses local pools for constant values as well as Symbol accesses for global values and variables.

symbol and symbol table tutorial Symbols and Symbol Tables - MLIR (llvm.org) mentioned that symbol is to
solve the issue in parallel compilation
so is it mandatory feature?
can we use func.func and call w/o symbol?
…

I think you can build you own FuncOp and CallOp that would be using SSA values instead of Symbols in a module (which is a graph region itself so it should just work).
I don’t see a blocker for that right now, but I haven’t tried it either! (and I haven’t seen people trying it yet, so don’t expect an example :slight_smile: )

1 Like

I’m sorry, but could you help to share material regarding symbol, funcop and callop ?
or concrete scenario/example to use them
thank you very much