You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As suggested by @aykevl, the LLVM Attributor's HeapToStack optimization pass potentially replaces TinyGo's limited ability to prove allocations safe to move to the stack.
I've played with the attributor in LLVM 18.1 and so far have limited luck. First and foremost, merely replacing the function-attrs pass with the attributor pass,
diff--gita/transform/optimizer.gob/transform/optimizer.go
index 54f9762b..f600e1e5100644---a/transform/optimizer.go+++b/transform/optimizer.go
@@ -53,7+51,7 @@ funcOptimize(modllvm.Module, config*compileopts.Config) []error {
// Run some preparatory passes for the Go optimizer.po:=llvm.NewPassBuilderOptions()
deferpo.Dispose()
-optPasses:="globaldce,globalopt,ipsccp,instcombine<no-verify-fixpoint>,adce,function-attrs"+optPasses:="globaldce,globalopt,ipsccp,instcombine<no-verify-fixpoint>,adce,attributor"ifllvmutil.Version() <18 {
// LLVM 17 doesn't have the no-verify-fixpoint flag.optPasses="globaldce,globalopt,ipsccp,instcombine,adce,function-attrs"
results in significant slowdown in compilation of a medium sized test program, from a few seconds to almost 2 minutes. I don't know whether the attributor can be run incrementally to amortize the time cost. There is also the much faster attributor-light pass, but I haven't seen it eliminate any allocations, not even for LLVM's own heap_to_stack.ll tests. I suspect the H2S pass doesn't work or is disabled in attributor-light.
Then, I failed to eliminate allocations for "append" style functions (append, strconv.Append* etc.). For example:
As suggested by @aykevl, the LLVM Attributor's HeapToStack optimization pass potentially replaces TinyGo's limited ability to prove allocations safe to move to the stack.
I've played with the attributor in LLVM 18.1 and so far have limited luck. First and foremost, merely replacing the
function-attrs
pass with theattributor
pass,results in significant slowdown in compilation of a medium sized test program, from a few seconds to almost 2 minutes. I don't know whether the attributor can be run incrementally to amortize the time cost. There is also the much faster
attributor-light
pass, but I haven't seen it eliminate any allocations, not even for LLVM's ownheap_to_stack.ll
tests. I suspect the H2S pass doesn't work or is disabled inattributor-light
.Then, I failed to eliminate allocations for "append" style functions (
append
,strconv.Append*
etc.). For example:is a reduced form of the translation of the program
The result of running the same optimization passes that TinyGo runs:
Note how
stack_slice
has its allocation eliminated, whereasescaping_slice
hasn't. The only difference between the functions is the call tosliceGrow
.The text was updated successfully, but these errors were encountered: