I'm adding a new target to Rust that needs additional LLVM attributes to properly specify programs. Though not exactly my scenario, amdgpu_kernel and the OpenCL address spaces are similar to what I'm trying to do.
There are two approaches I can take:
- Add a general-purpose
#[llvm_attr(attr1, attr2)]
that users can put on functions, arguments, etc and add wrapper macros outside the compiler for e.g.#[kernel]
and#[global]
that emit the correct llvm_attr. The nice thing about this approach is that it doesn't require me putting bespoke attributes for a single triple into rustc and this attribute might be useful for unrelated targets. Can deny attributes that rustc uses internally likenoalias
,readonly
, etc. - Bake the e.g.
#[kernel]
and#[global]
attributes into rustc that directly codegen the respective LLVM attributes.
I strongly prefer the first approach, though this has been shot down in the past.
Part of the challenge either way is that function parameter and local attributes quickly disappear after the AST gets lowered. So, you have to update the HIR, THIR, MIR, to propagate these attributes. With the second approach, you can use bitflags! to bake in the presence of the exact attributes you want, but with the first one it looks like you'd need to add an llvm_attrs
field that points to an interned delimited list of attrs or something.
Thoughts?