compiler: move allocations > 256 bytes to the heap
Этот коммит содержится в:
родитель
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
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче