llir / llvm

Library for interacting with LLVM IR in pure Go.
https://llir.github.io/document/
BSD Zero Clause License
1.18k stars 78 forks source link

`SRet` struct location #213

Closed dannypsnl closed 2 years ago

dannypsnl commented 2 years ago

we define at here https://github.com/llir/llvm/blob/99c4c9dbff20c151c272de5e1c9d12f3d493a90b/ir/helper.go#L401

but previously it's at enum as parameter attribute, maybe we need a module for attribute?

mewmew commented 2 years ago

I'm not sure I fully understand. I might have misunderstood exactly what this issue is about.

Could you give an LLVM IR example including sret which we are currently unable to represent using the IR of llir/llvm/ir.

Cheers, Robin

dannypsnl commented 2 years ago

So, I found an ancient code for SRet: enum.ParamAttrSRet in https://github.com/llir/document. Of course, we can remove it, but when finding a replacement? I cannot find it since it's not at enum but ir module, this is quite confusing. So I want to extract a module like

module paramattr

type SRet struct {}

const (
        ImmArg             ParamAttr = iota // immarg
)

Then we have a more stable and predictable surface

mewmew commented 2 years ago

The parameter attribute sret was an enum in earlier versions of LLVM (before version 12.0), because it was only ever written as sret. All versions of LLVM from 12.0 and later use sret(Type) and the old syntax for using only sret in LLVM IR was removed.

Therefore, in commit 9e6e4202d5183eadd4b75c99e7a57d53049b00b9 we removed the sret enum from ir/enum, and introduced the ir.SRet struct which implements the ir.ParamAttribute interface. The ir.SRet struct stores the type of sret(Type).

Therefore, older versions of llir/llvm may include sret as an enum since the official LLVM did, but later versions only include sret as a struct (the ir.SRet struct), since the type has to be stored for sret(Type) and this is the only valid syntax in later versions of LLVM (from version 12.0 and later).

So, llir/llvm is following exactly what the official LLVM distribution is doing with regards to sret.

And, as we discussed previously, we don't have enough contributors and maintainers for the llir/llvm project to make it possible to support older versions of LLVM. We only include support for the latest versions.

Cheers, Robin