Precompute and inline constant globals

This is necessary so that other constant globals referencing constant globals can be precomputed as well (NON_STANDALONE_FLOW in binaryen)
This commit is contained in:
dcodeIO
2017-12-06 23:38:17 +01:00
parent d63ed925a9
commit 9ae3328e58
13 changed files with 323 additions and 198 deletions

View File

@ -5,18 +5,6 @@
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $iv (func (param i32)))
(type $v (func))
(global $tlsf/ALIGN_SIZE_LOG2 i32 (i32.const 3))
(global $tlsf/ALIGN_SIZE (mut i32) (i32.const 0))
(global $tlsf/BLOCK_PREV_PHYS_OFFSET i32 (i32.const 0))
(global $tlsf/BLOCK_SIZE_OFFSET (mut i32) (i32.const 0))
(global $tlsf/BLOCK_NEXT_FREE_OFFSET (mut i32) (i32.const 0))
(global $tlsf/BLOCK_PREV_FREE_OFFSET (mut i32) (i32.const 0))
(global $tlsf/CONTROL_FL_BITMAP_OFFSET (mut i32) (i32.const 0))
(global $tlsf/FL_INDEX_MAX i32 (i32.const 30))
(global $tlsf/SL_INDEX_COUNT_LOG2 i32 (i32.const 5))
(global $tlsf/FL_INDEX_SHIFT (mut i32) (i32.const 0))
(global $tlsf/FL_INDEX_COUNT (mut i32) (i32.const 0))
(global $tlsf/SL_INDEX_COUNT (mut i32) (i32.const 0))
(memory $0 1)
(data (i32.const 4) "\08")
(export "control_construct" (func $tlsf/control_construct))
@ -47,7 +35,7 @@
(i32.store
(i32.add
(get_local $0)
(get_global $tlsf/BLOCK_NEXT_FREE_OFFSET)
(i32.const 8)
)
(get_local $1)
)
@ -56,7 +44,7 @@
(i32.store
(i32.add
(get_local $0)
(get_global $tlsf/BLOCK_PREV_FREE_OFFSET)
(i32.const 12)
)
(get_local $1)
)
@ -65,7 +53,7 @@
(i32.store
(i32.add
(get_local $0)
(get_global $tlsf/CONTROL_FL_BITMAP_OFFSET)
(i32.const 16)
)
(get_local $1)
)
@ -74,13 +62,16 @@
(if
(i32.ge_s
(get_local $1)
(get_global $tlsf/FL_INDEX_COUNT)
(i32.const 23)
)
(unreachable)
)
(i32.store
(i32.add
(get_local $0)
(i32.add
(get_local $0)
(i32.const 20)
)
(i32.mul
(get_local $1)
(i32.const 4)
@ -93,25 +84,28 @@
(if
(i32.ge_s
(get_local $1)
(get_global $tlsf/FL_INDEX_COUNT)
(i32.const 23)
)
(unreachable)
)
(if
(i32.ge_s
(get_local $2)
(get_global $tlsf/SL_INDEX_COUNT)
(i32.const 32)
)
(unreachable)
)
(i32.store
(i32.add
(get_local $0)
(i32.add
(get_local $0)
(i32.const 112)
)
(i32.mul
(i32.add
(i32.mul
(get_local $1)
(get_global $tlsf/SL_INDEX_COUNT)
(i32.const 32)
)
(get_local $2)
)
@ -143,7 +137,7 @@
(if
(i32.lt_s
(get_local $1)
(get_global $tlsf/FL_INDEX_COUNT)
(i32.const 23)
)
(block
(call $tlsf/control_set_sl
@ -158,7 +152,7 @@
(if
(i32.lt_s
(get_local $2)
(get_global $tlsf/SL_INDEX_COUNT)
(i32.const 32)
)
(block
(call $tlsf/control_set_block
@ -246,67 +240,9 @@
)
(unreachable)
)
(set_global $tlsf/ALIGN_SIZE
(i32.shl
(i32.const 1)
(get_global $tlsf/ALIGN_SIZE_LOG2)
)
)
(if
(i32.ne
(get_global $tlsf/ALIGN_SIZE)
(i32.const 8)
)
(unreachable)
)
(set_global $tlsf/BLOCK_SIZE_OFFSET
(i32.add
(get_global $tlsf/BLOCK_PREV_PHYS_OFFSET)
(i32.const 4)
)
)
(set_global $tlsf/BLOCK_NEXT_FREE_OFFSET
(i32.add
(get_global $tlsf/BLOCK_SIZE_OFFSET)
(i32.const 4)
)
)
(set_global $tlsf/BLOCK_PREV_FREE_OFFSET
(i32.add
(get_global $tlsf/BLOCK_NEXT_FREE_OFFSET)
(i32.const 4)
)
)
(set_global $tlsf/CONTROL_FL_BITMAP_OFFSET
(i32.add
(get_global $tlsf/BLOCK_PREV_FREE_OFFSET)
(i32.const 4)
)
)
(set_global $tlsf/FL_INDEX_SHIFT
(i32.add
(get_global $tlsf/SL_INDEX_COUNT_LOG2)
(get_global $tlsf/ALIGN_SIZE_LOG2)
)
)
(set_global $tlsf/FL_INDEX_COUNT
(i32.add
(i32.sub
(get_global $tlsf/FL_INDEX_MAX)
(get_global $tlsf/FL_INDEX_SHIFT)
)
(i32.const 1)
)
)
(set_global $tlsf/SL_INDEX_COUNT
(i32.shl
(i32.const 1)
(get_global $tlsf/SL_INDEX_COUNT_LOG2)
)
)
(call $tlsf/control_construct
(i32.load
(i32.const 8)
(i32.const 4)
)
)
)