-
Notifications
You must be signed in to change notification settings - Fork 46
feat(lto): add global DCE phase-1 support for interface dispatch #1752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,7 +197,7 @@ func compileWithConfig( | |
| return | ||
| } | ||
|
|
||
| func use(goos, goarch string, wasiThreads, forceEspClang bool) (export Export, err error) { | ||
| func use(goos, goarch string, wasiThreads, forceEspClang, enableLTO bool) (export Export, err error) { | ||
| targetTriple := llvm.GetTargetTriple(goos, goarch) | ||
| llgoRoot := env.LLGoROOT() | ||
|
|
||
|
|
@@ -225,8 +225,11 @@ func use(goos, goarch string, wasiThreads, forceEspClang bool) (export Export, e | |
| "-Wl,--error-limit=0", | ||
| "-fuse-ld=lld", | ||
| // Enable ICF (Identical Code Folding) to reduce binary size | ||
| "-Xlinker", | ||
| "--icf=safe", | ||
| "-Wl,--icf=safe", | ||
| } | ||
| if enableLTO { | ||
| // Enable ThinLTO, using default lto kind(thinlto). | ||
| export.LDFLAGS = append(export.LDFLAGS, "-Wl,--lto-O1", "-v") | ||
| } | ||
| if clangRoot != "" { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two issues on this line:
|
||
| clangLib := filepath.Join(clangRoot, "lib") | ||
|
|
@@ -250,6 +253,9 @@ func use(goos, goarch string, wasiThreads, forceEspClang bool) (export Export, e | |
| "-Qunused-arguments", | ||
| "-Wno-unused-command-line-argument", | ||
| } | ||
| if enableLTO { | ||
| export.CCFLAGS = append(export.CCFLAGS, "-flto=full") | ||
| } | ||
|
|
||
| // Add sysroot for macOS only | ||
| if goos == "darwin" { | ||
|
|
@@ -424,7 +430,7 @@ func use(goos, goarch string, wasiThreads, forceEspClang bool) (export Export, e | |
| } | ||
|
|
||
| // UseTarget loads configuration from a target name (e.g., "rp2040", "wasi") | ||
| func UseTarget(targetName string) (export Export, err error) { | ||
| func UseTarget(targetName string, enableLTO bool) (export Export, err error) { | ||
| resolver := targets.NewDefaultResolver() | ||
|
|
||
| config, err := resolver.Resolve(targetName) | ||
|
|
@@ -499,6 +505,13 @@ func UseTarget(targetName string) (export Export, err error) { | |
| expandedCFlags := env.ExpandEnvSlice(config.CFlags, envs) | ||
| cflags = append(cflags, expandedCFlags...) | ||
|
|
||
| if config.Linker == "ld.lld" && enableLTO { | ||
| // Enable ThinLTO, Using default lto kind(thinlto). | ||
| ldflags = append(ldflags, "--lto-O1") | ||
| cflags = append(cflags, "-flto=full") | ||
| ccflags = append(ccflags, "-flto=full") | ||
| } | ||
|
|
||
| // The following parameters are inspired by tinygo/builder/library.go | ||
| // Handle CPU configuration | ||
| if cpu != "" { | ||
|
|
@@ -545,6 +558,8 @@ func UseTarget(targetName string) (export Export, err error) { | |
| ccflags = append(ccflags, "-fforce-enable-int128") | ||
| case "riscv64": | ||
| ccflags = append(ccflags, "-march=rv64gc") | ||
| // codegen option should be added to ldflags for lto | ||
| ldflags = append(ldflags, "-mllvm", "-march=rv64gc") | ||
| case "mips": | ||
| ccflags = append(ccflags, "-fno-pic") | ||
| } | ||
|
|
@@ -574,9 +589,17 @@ func UseTarget(targetName string) (export Export, err error) { | |
| // Handle code generation configuration | ||
| if config.CodeModel != "" { | ||
| ccflags = append(ccflags, "-mcmodel="+config.CodeModel) | ||
| if enableLTO { | ||
| // codegen option should be added to ldflags for lto | ||
| ldflags = append(ldflags, "-mllvm", "-code-model="+config.CodeModel) | ||
| } | ||
| } | ||
| if config.TargetABI != "" { | ||
| ccflags = append(ccflags, "-mabi="+config.TargetABI) | ||
| if enableLTO { | ||
| // codegen option should be added to ldflags for lto | ||
| ldflags = append(ldflags, "-mllvm", "-target-abi="+config.TargetABI) | ||
| } | ||
| } | ||
| if config.RelocationModel != "" { | ||
| switch config.RelocationModel { | ||
|
|
@@ -658,9 +681,9 @@ func UseTarget(targetName string) (export Export, err error) { | |
|
|
||
| // Use extends the original Use function to support target-based configuration | ||
| // If targetName is provided, it takes precedence over goos/goarch | ||
| func Use(goos, goarch, targetName string, wasiThreads, forceEspClang bool) (export Export, err error) { | ||
| func Use(goos, goarch, targetName string, wasiThreads, forceEspClang, enableLTO bool) (export Export, err error) { | ||
| if targetName != "" && !strings.HasPrefix(targetName, "wasm") && !strings.HasPrefix(targetName, "wasi") { | ||
| return UseTarget(targetName) | ||
| return UseTarget(targetName, enableLTO) | ||
| } | ||
| return use(goos, goarch, wasiThreads, forceEspClang) | ||
| return use(goos, goarch, wasiThreads, forceEspClang, enableLTO) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment mentions enabling ThinLTO, but the compiler flag being added on line 257 is
-flto=full, which enables full LTO. This is inconsistent and could be confusing. Please update the comment to reflect that full LTO is being used. A similar issue exists on line 509.