Enforcing MacOS aarch64 calling convention

Following the discussion from Using MacOS calling convention to call external functions - #4 by youben I was wondering how someone could enforce a specific calling convention in MLIR? It seems that LLVM IR has a mechanism to enforce that in a function call, however, I can’t find a way to do it in LLVM or Func dialect, so that it translate to a call with a specific calling convention in LLVM IR.

I’m asking about enforcing that on a specific function call, because I understand that we can’t enforce the use of MacOS aarch64 calling convention globally, but it would be an even better solution for me if that’s possible.

Have you taken a look at the CConv attribute of llvm.func: 'llvm' Dialect - MLIR

Yes I did, but I didn’t get the expected outcome. First, setting the CConv then running mlir::translateModuleToLLVMIR doesn’t seem to keep the attribute in the LLVM IR, where I would expect the calling convention to appear as specified here. Since the attribute wasn’t kept, I tried to add that manually, and compile with llc. I wasn’t sure of the exact value to use for my needs, as I couldn’t find a description that match, but I tried a different set of values, and it didn’t change anything, I kept having the same calling convention with all the different values I used. So I’m not quite sure if this is the way to go.

My guess is that you have to set the target triple and data layout on the real LLVM module and LLVM will take care of the calling conventions.

In tree is Flang, a MLIR Fortran compiler. It has a runtime written in C++. Flang makes calls to the runtime from MLIR.

This didn’t solve it unfortunately.

I was doing something wrong in my compiler, so this issue doesn’t apply anymore, the codegen is using appropriate calling convention to call my external function