fix merge error
This commit is contained in:
@@ -1305,6 +1305,85 @@ var streamline = function(ir, log) {
|
||||
push: 2, setarg: 3, put: 1
|
||||
}
|
||||
|
||||
// Build last_ref liveness array for a function's instructions.
|
||||
// Returns array where last_ref[slot] = last instruction index referencing that slot.
|
||||
// Uses get_slot_refs to only visit actual slot reference positions.
|
||||
var build_slot_liveness = function(instructions, nr_slots) {
|
||||
var last_ref = array(nr_slots, -1)
|
||||
var n = length(instructions)
|
||||
var refs = null
|
||||
var i = 0
|
||||
var j = 0
|
||||
var s = 0
|
||||
var instr = null
|
||||
var label_map = null
|
||||
var changed = false
|
||||
var op = null
|
||||
var target = null
|
||||
var tpos = 0
|
||||
|
||||
// Scan instructions for slot references
|
||||
while (i < n) {
|
||||
instr = instructions[i]
|
||||
if (is_array(instr)) {
|
||||
refs = get_slot_refs(instr)
|
||||
j = 0
|
||||
while (j < length(refs)) {
|
||||
s = instr[refs[j]]
|
||||
if (is_number(s) && s >= 0 && s < nr_slots) {
|
||||
last_ref[s] = i
|
||||
}
|
||||
j = j + 1
|
||||
}
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
// Extend for backward jumps (loops)
|
||||
label_map = {}
|
||||
i = 0
|
||||
while (i < n) {
|
||||
instr = instructions[i]
|
||||
if (is_text(instr) && !starts_with(instr, "_nop_")) {
|
||||
label_map[instr] = i
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
changed = true
|
||||
while (changed) {
|
||||
changed = false
|
||||
i = 0
|
||||
while (i < n) {
|
||||
instr = instructions[i]
|
||||
if (is_array(instr)) {
|
||||
target = null
|
||||
op = instr[0]
|
||||
if (op == "jump") {
|
||||
target = instr[1]
|
||||
} else if (op == "jump_true" || op == "jump_false" || op == "jump_not_null") {
|
||||
target = instr[2]
|
||||
}
|
||||
if (target != null && is_text(target)) {
|
||||
tpos = label_map[target]
|
||||
if (tpos != null && tpos < i) {
|
||||
s = 0
|
||||
while (s < nr_slots) {
|
||||
if (last_ref[s] >= 0 && last_ref[s] >= tpos && last_ref[s] < i) {
|
||||
last_ref[s] = i
|
||||
changed = true
|
||||
}
|
||||
s = s + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
}
|
||||
|
||||
return last_ref
|
||||
}
|
||||
|
||||
var insert_stone_text = function(func, log) {
|
||||
var instructions = func.instructions
|
||||
var nr_slots = func.nr_slots
|
||||
@@ -1320,6 +1399,7 @@ var streamline = function(ir, log) {
|
||||
var slot = 0
|
||||
var nc = 0
|
||||
var shift = 0
|
||||
var last_ref = null
|
||||
|
||||
if (instructions == null || length(instructions) == 0) {
|
||||
return null
|
||||
@@ -1329,10 +1409,13 @@ var streamline = function(ir, log) {
|
||||
events = log.events
|
||||
}
|
||||
|
||||
// Build liveness info (in separate function to stay under slot limit)
|
||||
last_ref = build_slot_liveness(instructions, nr_slots)
|
||||
|
||||
// Walk instructions, tracking types, inserting stone_text
|
||||
n = length(instructions)
|
||||
slot_types = array(nr_slots, T_UNKNOWN)
|
||||
result = []
|
||||
n = length(instructions)
|
||||
i = 0
|
||||
while (i < n) {
|
||||
instr = instructions[i]
|
||||
@@ -1353,9 +1436,10 @@ var streamline = function(ir, log) {
|
||||
}
|
||||
}
|
||||
} else if (op == "move") {
|
||||
// Conservatively stone source before move if provably text
|
||||
// Stone source before move only if source is provably text
|
||||
// AND source slot is still live after this instruction
|
||||
slot = instr[2]
|
||||
if (is_number(slot) && slot_is(slot_types, slot, T_TEXT)) {
|
||||
if (is_number(slot) && slot_is(slot_types, slot, T_TEXT) && last_ref[slot] > i) {
|
||||
result[] = ["stone_text", slot]
|
||||
nc = nc + 1
|
||||
if (is_number(dpc) && i < dpc) shift = shift + 1
|
||||
|
||||
Reference in New Issue
Block a user