cdisselkoen / llvm-ir

LLVM IR in natural Rust data structures
MIT License
550 stars 46 forks source link

Add support for the new memory attribute in LLVM 16 #49

Closed Benjins closed 11 months ago

Benjins commented 1 year ago

The new memory(...) attribute describes how a function is allowed to access memory. It's documented here (I can't link to the section for that attribute, but it's under memory). There is also the original RFC for it

This PR adds support for it, so instead of UnknownAttribute it shows up as a Memory variant, with the arguments to the attribute accessible via fields on the variant

Its IR looks like:

define void @foo1() memory(readwrite, argmem: none) {
  ret void
}

define void @foo2() memory(read) {
  ret void
}

The data for the attribute is internally encoded as an int, a bitmask of permissions for each of the locations

The attributes test IR file is forked, now with an LLVM 16+ version that has these new memory attributes, along with tests in basic_tests.rs to verify that they parse the correct values