LLVM Discussion Forums

[MLIR] [LLVM Dialect] Function Pointers

Hi all,

I am trying to solve this bug(I am the author of that bug too).

define i32 @foo(i32) {
  ret i32 2
}

define i32 @main() {
  %1 = alloca i32 (i32)*, align 8
  store i32 (i32)* @foo, i32 (i32)** %1, align 8
  %2 = load i32 (i32)*, i32 (i32)** %1, align 8
  %3 = call i32 %2(i32 10)
  ret i32 %3
}

The store instruction fails as it is unable to process the function as a pointer in its operand. What class object is a function pointer going to be (if such a class already exists) and if it does not inherit from Value class, can it?

It isn’t exactly clear if the question pertains to LLVM IR, or the representation of the LLVM dialect in MLIR. Can you clarify?

It isn’t exactly clear if the question pertains to LLVM IR or the representation of the LLVM dialect in MLIR. Can you clarify?

It is about the LLVM IR dialect in MLIR - I wanted a hint on the solution because I am new to tablegen and MLIR.

Sorry for delay. I could not grasp the sense of your question so I investigated the bug instead. The fix is a two-liner so I took the liberty of committing it to avoid wasting your time on it, https://reviews.llvm.org/rGdc553ce646cd.

If I understand the question correctly, the answer is llvm::Function derives from llvm::Constant so you can cast from the latter to the former using dyn_cast and then use mlir::SymbolRefAttr to refer to the function.

Thanks for the clarification @ftynse