LLVM IR functions can have arbitrary attributes attached to them, some of which
affect may affect code transformations. Until we can model all attributes
consistently, provide a pass-through mechanism that forwards attributes from
the LLVMFuncOp in MLIR to LLVM IR functions during translation. This mechanism
relies on LLVM IR being able to recognize string representations of the
attributes and performs some additional checking to avoid hitting assertions
within LLVM code.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks Alex, I can confirm that with this, the expected behavior is reached on the LLVM matrix front.
Also + @fhahn
mlir/docs/Dialects/LLVM.md | ||
---|---|---|
107 | That seems a bit like a hack to me: when importing from LLVM are we gonna encode attributes this way? Are we gonna honor them? |
mlir/docs/Dialects/LLVM.md | ||
---|---|---|
107 | Isn't the LLVM string = string attribute the issue here? In other words, until/unless LLVM force more semantics on those attributes, isn't it a raising problem to import from LLVM and guesstimate types? |
mlir/docs/Dialects/LLVM.md | ||
---|---|---|
107 | LLVM has string attributes only for target specific I believe, otherwise there are rules for "IR-level" attributes: https://github.com/llvm/llvm-project/blob/master/llvm/include/llvm/IR/Attributes.td |
mlir/docs/Dialects/LLVM.md | ||
---|---|---|
107 | I agree that it feels hacky, but so does LLVM's approach. You can add arbitrary quoted strings as function attributes, which some passes of various levels of experimental-ness rely on, and we got to support that. We have a need for that today to support some forms of vectorization. While we could restrict this feature to only support string attributes, we would need to encode a list of allowed attributes somewhere, which sounds equivalent to just building support for them, and we don't have time to invest in that right now. I expect that we will eventually have first-class modeling for the equivalents of common attributes that may differ from what LLVM does with attributes (e.g., for inlining or FP math options). Until we do, we need to have a way to attach these attributes in the generated code for the purposes of code generation. https://github.com/llvm/llvm-project/blob/master/llvm/include/llvm/IR/Attributes.td is of little help because it does not say which attributes are allowed on functions (as opposed to, e.g., function attributes) and which of them are allowed to have values. Furthermore, there are attributes allowed on functions listed in https://llvm.org/docs/LangRef.html#function-attributes that are not listed in Attributes.td. |
mlir/docs/Dialects/LLVM.md | ||
---|---|---|
107 |
I meant function _argument_ attributes |
mlir/docs/Dialects/LLVM.md | ||
---|---|---|
107 | I agree that LLVM is not perfect, but this is much uglier and I'm gonna be concerned by any code that start to manipulate or emit this. It'll have to be very contained. |
mlir/docs/Dialects/LLVM.md | ||
---|---|---|
107 | The code Nicolas has uses platform-specific attributes, which are anyway strings that are not registered anyway. I don't see how to "fix" that without imposing our choices further down the pipeline. If someone suddenly starts to use this for an actual function attribute listed in LangRef, we will be able to model that attribute specifically, without having to prematurely overdesign all of them. |
That seems a bit like a hack to me: when importing from LLVM are we gonna encode attributes this way? Are we gonna honor them?
We're getting into the "json of compiler" here.