builder: free LLVM objects after use

This reduces the TinyGo memory consumption when running

  make tinygo-test

from 5.8GB to around 2GB on my laptop.
This commit is contained in:
Ayke van Laethem
2022-04-19 15:31:23 +02:00
committed by Ron Evans
parent ea3b5dc689
commit 777d3f3ea5
13 changed files with 49 additions and 6 deletions
+3
View File
@@ -33,7 +33,9 @@ func MakeGCStackSlots(mod llvm.Module) bool {
ctx := mod.Context()
builder := ctx.NewBuilder()
defer builder.Dispose()
targetData := llvm.NewTargetData(mod.DataLayout())
defer targetData.Dispose()
uintptrType := ctx.IntType(targetData.PointerSize() * 8)
// Look at *all* functions to see whether they are free of function pointer
@@ -326,6 +328,7 @@ func AddGlobalsBitmap(mod llvm.Module) bool {
ctx := mod.Context()
targetData := llvm.NewTargetData(mod.DataLayout())
defer targetData.Dispose()
uintptrType := ctx.IntType(targetData.PointerSize() * 8)
// Collect all globals that contain pointers (and thus must be scanned by