compiler: add alloc attributes to runtime.alloc

This gives a small improvement now, and is needed to be able to use the
Heap2Stack transform that's available in the Attributor pass. This
Heap2Stack transform could replace our custom OptimizeAllocs pass.

Most of the changes are just IR that changed, the actual change is
relatively small.

To give an example of why this is useful, here is the code size before
this change:

    $ tinygo build -o test -size=short ./testdata/stdlib.go
       code    data     bss |   flash     ram
      95620    1812     968 |   97432    2780

    $ tinygo build -o test -size=short ./testdata/stdlib.go
       code    data     bss |   flash     ram
      95380    1812     968 |   97192    2780

That's a 0.25% reduction. Not a whole lot, but nice for such a small
patch.
This commit is contained in:
Ayke van Laethem
2023-03-11 20:57:40 +01:00
committed by Ron Evans
parent 5ed0cecf0d
commit f180339d6b
17 changed files with 504 additions and 447 deletions
+3 -1
View File
@@ -18,7 +18,7 @@ func main() {
s3 := make([]int, 3) // OUT: object allocated on the heap: escapes at line 19
returnIntSlice(s3)
_ = make([]int, getUnknownNumber()) // OUT: object allocated on the heap: size is not constant
useSlice(make([]int, getUnknownNumber())) // OUT: object allocated on the heap: size is not constant
s4 := make([]byte, 300) // OUT: object allocated on the heap: object size 300 exceeds maximum stack allocation size 256
readByteSlice(s4)
@@ -82,3 +82,5 @@ func getComplex128() complex128
func useInterface(interface{})
func callVariadic(...int)
func useSlice([]int)