compiler: move allocations > 256 bytes to the heap

Этот коммит содержится в:
Damian Gryski 2022-02-10 19:28:34 -08:00 коммит произвёл Ron Evans
родитель f2fef290c9
коммит 4b2edc9a26
2 изменённых файлов: 4 добавлений и 2 удалений

Просмотреть файл

@ -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