mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 19:43:44 +00:00
compiler: move allocations > 256 bytes to the heap
This commit is contained in:
@@ -1571,8 +1571,9 @@ func (b *builder) createExpr(expr ssa.Value) (llvm.Value, error) {
|
||||
switch expr := expr.(type) {
|
||||
case *ssa.Alloc:
|
||||
typ := b.getLLVMType(expr.Type().Underlying().(*types.Pointer).Elem())
|
||||
if expr.Heap {
|
||||
size := b.targetData.TypeAllocSize(typ)
|
||||
size := b.targetData.TypeAllocSize(typ)
|
||||
// Move all "large" allocations to the heap. This value is also transform.maxStackAlloc.
|
||||
if expr.Heap || size > 256 {
|
||||
// Calculate ^uintptr(0)
|
||||
maxSize := llvm.ConstNot(llvm.ConstInt(b.uintptrType, 0, false)).ZExtValue()
|
||||
if size > maxSize {
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
// always be heap allocated.
|
||||
//
|
||||
// TODO: tune this, this is just a random value.
|
||||
// This value is also used in the compiler when translating ssa.Alloc nodes.
|
||||
const maxStackAlloc = 256
|
||||
|
||||
// OptimizeAllocs tries to replace heap allocations with stack allocations
|
||||
|
||||
Reference in New Issue
Block a user