I'm trying to add a new target-specific attribute that goes on function parameters that become an LLVM attribute (will add this to LLVM as well) in the signature.
Something like
#[fn_attr]
fn my_fn(a: u32, #[param_attr] b: u32) {
// ...
}
Which should emit something like
; Function Attrs: fn_attr uwtable
define void @hello(i32 %a, i32 param_attr %b) unnamed_addr #0 {
start:
; ...
}
attributes #0 = { fn_attr uwtable "frame-pointer"="non-leaf" "probe-stack"="inline-asm" "target-cpu"="apple-m1" }
Adding fn_attr
was pretty straightforward as there's plenty of precedent for function attributes, but there isn't a clear way to do this for function parameters. I've managed to hack something that passes the attribute through AST -> HIR -> THIR, but I'm a bit lost on how to do this in the MIR. My current guess is to change <TyCtxt as Interner>::Tys
to be &'tcx List<(Attr, Ty<'tcx>)>
where Attr is a new set of hard-coded attributes. These can then be available when mucking with the ArgAbi
objects, which set the existing parameter LLVM attributes (e.g. noalias
, nocapture
, align
etc.). Does this sound right or am I missing something?