Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/coroutine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ jobs:
go test ./internal/xtool/llvm -run '^TestGetTarget(Spec|Triple)$' -count=1
go test ./internal/crosscompile -run '^Test(UseTarget|UseExportsResolvedLLVMConfig|ResolvedLLVMTargetSpecWASIThreads)$' -count=1
go test ./internal/cabi -run '^TestDevLTOGlobalDCETargetArchAndNewTransformerArchSelection$' -count=1
go test ./ssa -run '^Test(ResolvedTargetConfig(|IsAuthoritativeAndFrozen)|TargetDataLegacyLayoutCompatibility|ResolvedPointerWidthMismatchFallsBack|NewProgramDefaultTargetCompatibility|ResolvedExternalBackendCompatibilityFallback|ResolvedTargetABINameControlsRISCVObject)$' -count=1
go test -v ./ssa -run '^Test(ResolvedTargetConfig(|IsAuthoritativeAndFrozen)|TargetDataLegacyLayoutCompatibility|ResolvedPointerWidthMismatchFallsBack|NewProgramDefaultTargetCompatibility|ResolvedExternalBackendCompatibilityFallback|ResolvedTargetABINameControlsRISCVObject)$' -count=1
go test ./internal/build -run '^Test(NewLLSSATargetUsesResolvedLLVMConfig|LLVMCPUAndFeaturesAffectBuildFingerprint|DefaultTargetKeepsLegacyCacheIdentity|NonDefaultLLVMFeaturesEnterCacheIdentity|ResolvedTargetCompatibilityAudit)$' -count=1

- name: Check llgo-tag build
run: go test -tags=llgo ./internal/coro

- name: Vet coroutine analysis
run: go vet ./internal/coro ./internal/build ./internal/xtool/llvm ./internal/crosscompile ./internal/cabi ./ssa
run: |
go vet ./internal/coro ./internal/build ./internal/xtool/llvm ./internal/crosscompile ./internal/cabi
# The SSA package has pre-existing sync.Map copylocks findings. Keep
# every other analyzer active while coroutine slices are integrated.
go vet -copylocks=false ./ssa
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ require (
)

replace github.com/goplus/llgo/runtime => ./runtime

replace github.com/xgo-dev/llvm => github.com/cpunion/llvm v0.9.4-0.20260715161341-b20c3fb9f902
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/cpunion/llvm v0.9.4-0.20260715161341-b20c3fb9f902 h1:MYGfF7OojuCifhuypcg58qvMfcQvzYk7R/fPtqU7rUE=
github.com/cpunion/llvm v0.9.4-0.20260715161341-b20c3fb9f902/go.mod h1:42vav2/cI5BAIcL543DZSMO9do8/aCK2z7JERH+AE+M=
github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0=
github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand All @@ -22,8 +24,6 @@ github.com/qiniu/x v1.18.0 h1:iMfc7Gqy1au+akr+Tl5Z40px7TR8VBLLkJsIeajKIbc=
github.com/qiniu/x v1.18.0/go.mod h1:Sx3Wy+0GI9OsX4a53mYj6A0o7mHJ94PUvraqGYb4EIs=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/xgo-dev/llvm v0.9.3 h1:P0tHtUEt5ziwIhrigDuJdZxlI68SzoCg3v8EyrTULY4=
github.com/xgo-dev/llvm v0.9.3/go.mod h1:42vav2/cI5BAIcL543DZSMO9do8/aCK2z7JERH+AE+M=
github.com/xgo-dev/plan9asm v0.3.0 h1:8JcpsNa7/B6YUNJPbIezOhpoURvH8VNDbBh8eQwHnnc=
github.com/xgo-dev/plan9asm v0.3.0/go.mod h1:0yM4CCIp2PyT8h+Ro3Ukro3lHL8ji9mzHEv5yfhOckc=
go.bug.st/serial v1.6.4 h1:7FmqNPgVp3pu2Jz5PoPtbZ9jJO5gnEnZIvnI1lzve8A=
Expand Down
27 changes: 20 additions & 7 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,7 @@ func Do(args []string, conf *Config) ([]Package, error) {
cl.EnableTrace(IsTraceEnabled())
llssa.Initialize(llssa.InitAll)

target := &llssa.Target{
GOOS: conf.Goos,
GOARCH: conf.Goarch,
Target: conf.Target,
OptLevel: conf.OptLevel,
}
target := newLLSSATarget(conf, export)

prog := llssa.NewProgram(target)
programOwnershipTransferred := false
Expand Down Expand Up @@ -633,6 +628,24 @@ func buildCoroPlan(ctx *context) error {
return nil
}

func newLLSSATarget(conf *Config, export crosscompile.Export) *llssa.Target {
target := &llssa.Target{
GOOS: conf.Goos,
GOARCH: conf.Goarch,
Target: conf.Target,
OptLevel: conf.OptLevel,
}
if export.LLVMTarget != "" {
target.Resolved = &llssa.TargetSpec{
Triple: export.LLVMTarget,
CPU: export.CPU,
Features: export.Features,
TargetABI: export.TargetABI,
}
}
return target
}

func applyFrontendGCFlags(conf *Config) {
for _, buildFlag := range conf.GoBuildFlags {
value, ok := strings.CutPrefix(buildFlag, "-gcflags=")
Expand Down Expand Up @@ -1514,7 +1527,7 @@ func buildPkg(ctx *context, aPkg *aPackage, verbose bool) error {
if ctx.passOpt {
mod := ret.Module()
mod.SetDataLayout(ctx.prog.DataLayout())
mod.SetTarget(ctx.prog.Target().Spec().Triple)
mod.SetTarget(ctx.prog.TargetSpec().Triple)
pbo := gllvm.NewPassBuilderOptions()
defer pbo.Dispose()
if err = gllvm.VerifyModule(mod, gllvm.ReturnStatusAction); err != nil {
Expand Down
31 changes: 29 additions & 2 deletions internal/build/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/goplus/llgo/internal/env"
"github.com/goplus/llgo/internal/packages"
intllvm "github.com/goplus/llgo/internal/xtool/llvm"
gopackages "golang.org/x/tools/go/packages"
)

Expand Down Expand Up @@ -72,7 +73,9 @@ func (c *context) collectFingerprint(pkg *aPackage) error {
func (c *context) collectEnvInputs(m *manifestBuilder) {
m.env.Goos = c.buildConf.Goos
m.env.Goarch = c.buildConf.Goarch
m.env.LlvmTriple = c.crossCompile.LLVMTarget
if c.hasNonDefaultLLVMConfig() {
m.env.LlvmTriple = c.crossCompile.LLVMTarget
}
m.env.LlgoVersion = env.Version()
m.env.LlgoCompilerHash = c.buildConf.CompilerHash
m.env.GoVersion = runtime.Version()
Expand Down Expand Up @@ -104,6 +107,10 @@ func (c *context) collectCommonInputs(m *manifestBuilder) {
m.common.BuildTags = strings.Split(c.buildConf.Tags, ",")
}
m.common.Target = c.buildConf.Target
if c.hasNonDefaultLLVMConfig() {
m.common.LLVMCPU = c.crossCompile.CPU
m.common.LLVMFeatures = c.crossCompile.Features
}
m.common.TargetABI = c.crossCompile.TargetABI
m.common.GoGlobalDCE = c.buildConf.goGlobalDCEEnabled()

Expand Down Expand Up @@ -284,14 +291,34 @@ func detectLLVMVersion(ctx *context) string {

// targetTriple returns the target triple for cache directory.
func (c *context) targetTriple() string {
llvmTarget := c.crossCompile.LLVMTarget
if !c.hasNonDefaultLLVMConfig() {
// Preserve the legacy cache namespace for ordinary GOOS/GOARCH builds.
// Their resolved LLVM defaults are deterministic inputs of the compiler
// version, while named targets need their explicit triple and ABI here.
llvmTarget = ""
}
return targetTriple(
c.buildConf.Goos,
c.buildConf.Goarch,
c.crossCompile.LLVMTarget,
llvmTarget,
c.crossCompile.TargetABI,
)
}

func (c *context) hasNonDefaultLLVMConfig() bool {
if c.buildConf.Target != "" {
return true
}
requested := c.crossCompile
if requested.LLVMTarget == "" && requested.CPU == "" && requested.Features == "" && requested.TargetABI == "" {
return false
}
defaults := intllvm.GetTargetSpec(c.buildConf.Goos, c.buildConf.Goarch, "")
return requested.LLVMTarget != defaults.Triple || requested.CPU != defaults.CPU ||
requested.Features != defaults.Features || requested.TargetABI != ""
}

// targetTriple returns the target triple string for cache directory
func targetTriple(goos, goarch, llvmTarget, targetABI string) string {
triple := llvmTarget
Expand Down
27 changes: 15 additions & 12 deletions internal/build/fingerprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,24 @@ func (s *envSection) empty() bool {
}

type commonSection struct {
AbiMode string `yaml:"ABI_MODE,omitempty"`
BuildTags []string `yaml:"BUILD_TAGS,omitempty"`
Target string `yaml:"TARGET,omitempty"`
TargetABI string `yaml:"TARGET_ABI,omitempty"`
GoGlobalDCE bool `yaml:"GO_GLOBAL_DCE,omitempty"`
CC string `yaml:"CC,omitempty"`
CCFlags []string `yaml:"CCFLAGS,omitempty"`
CFlags []string `yaml:"CFLAGS,omitempty"`
LDFlags []string `yaml:"LDFLAGS,omitempty"`
Linker string `yaml:"LINKER,omitempty"`
ExtraFiles []fileDigest `yaml:"EXTRA_FILES,omitempty"`
AbiMode string `yaml:"ABI_MODE,omitempty"`
BuildTags []string `yaml:"BUILD_TAGS,omitempty"`
Target string `yaml:"TARGET,omitempty"`
LLVMCPU string `yaml:"LLVM_CPU,omitempty"`
LLVMFeatures string `yaml:"LLVM_FEATURES,omitempty"`
TargetABI string `yaml:"TARGET_ABI,omitempty"`
GoGlobalDCE bool `yaml:"GO_GLOBAL_DCE,omitempty"`
CC string `yaml:"CC,omitempty"`
CCFlags []string `yaml:"CCFLAGS,omitempty"`
CFlags []string `yaml:"CFLAGS,omitempty"`
LDFlags []string `yaml:"LDFLAGS,omitempty"`
Linker string `yaml:"LINKER,omitempty"`
ExtraFiles []fileDigest `yaml:"EXTRA_FILES,omitempty"`
}

func (s *commonSection) empty() bool {
return s.AbiMode == "" && len(s.BuildTags) == 0 && s.Target == "" && s.TargetABI == "" &&
return s.AbiMode == "" && len(s.BuildTags) == 0 && s.Target == "" && s.LLVMCPU == "" &&
s.LLVMFeatures == "" && s.TargetABI == "" &&
!s.GoGlobalDCE && s.CC == "" && len(s.CCFlags) == 0 && len(s.CFlags) == 0 && len(s.LDFlags) == 0 &&
s.Linker == "" && len(s.ExtraFiles) == 0
}
Expand Down
Loading