[flang-commits] [flang] [mlir] [mlir][func] Refactor FuncToLLVM discardable attributes algorithm (PR #188232)

Hocky Yudhiono via flang-commits flang-commits at lists.llvm.org
Tue Mar 24 23:56:12 PDT 2026


hockyy wrote:

So the behavior that I expect is:
- If it has the `llvm.*` prefix, remove it, and **propagate** it to LLVMFuncOp.
	- `llvm.passthrough` -> `passthrough`
	- `llvm.target_cpu` -> `target_cpu`
	- `llvm.target_features` -> `target_features`
	- `llvm.tune_cpu` -> `tune_cpu`
- If it has an ODS attribute name without the prefix, remove it, because it will crash the builder.
    - `linkage` only -> remove it
    - `passthrough` only -> remove it
- If it has special meaning, parse it, and assign it and put the info in `LoweredFuncAttrs`
	- `llvm.linkage` -> parse it
	- `llvm.readnone` -> parse it
- Other than that, should be an undefined behavior. Because the legacy code is propagating all of the attributes, I will just add it to `lowered.attrs`

cc @matthias-springer, sorry for tagging, I considered your comment https://github.com/llvm/llvm-project/pull/182987#discussion_r2845064902 here, but instead of letting it crash, I'm thinking of refactoring the attribute passing, and erroring out the creation when it's finding a duplicated attribute names.

> To work around the crash, you could error out before creating the llvm.func op if you detect an attribute that's defined in the ODS of llvm.func. However, there are around 50 attributes on llvm.func (each of which can likely reproduce this crash), and hard-coding these does not seem right. (I do not know of any mechanism to enumerate all ODS-defined attribute names.)



https://github.com/llvm/llvm-project/pull/188232


More information about the flang-commits mailing list