Skip to content

Make cir.call aware of calling conventions #803

Closed
@seven-mile

Description

@seven-mile

LLVM has both callee (Function) and callsite (CallInst) attributed by calling conv. Currently CIR always set default calling conv (CConv::C) when lowering to LLVM call / invoke ops, which produces wrong LLVM IR for callsites.


Here are some considerations from my side, FYI.

First of all, I'm not sure whether ClangIR should allow mismatch of call convs between callsite and callee: LLVM allows it, but I think Clang AST does not. In Clang AST, the calling conv is stored in type system (clang::FunctionType::ExtInfo). Thus, I lean towards the latter (they must match).

Then, we have two typical approaches here, again ; )

  • Extend !cir.func<> type with calling convention attribute. Infer the call conv for callsite when lowering.
    • This provides a straightforward equivalent to Clang AST, and defers the conversion until lowering.
  • Extend the cir.call operations directly and keep close with OG skeleton.
    • By utilizing the information from Clang AST, we can still easily determine the calling convention of the callsite in corner cases like invoking a function pointer.

I think both are workable for just correctness. But the first one preserve more information for analysis and cost more (more allocation size for every function type). FWIW: The so-called "more information" is the calling conventions of intermediate results of functions, which is not common. Most of the time, we are just doing bitcast of function pointers. I don't think such info involves vital optimizations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions