-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimise allocation of local variables #21
Comments
when do I get to tear the code apart and add big boy ssa ir? presumably it will be sometime I actually have time to do literally anything |
anytime, fam. I think we've half implemented SSA IR through phantom registers (they can only be created once, and right now are only assigned to once) and temporary virtual registers (created once, assigned once) |
Copy+pasted from discord locals/registers be translated with these rules:
|
say example: do -- block1
do (result i32) -- block2
i32.load 1
setvar var1
loadvar var1
call print
i32.load 2
setvar var2
end
loadvar var2
call print
end so using those rules, the above code will be translated to do
local var2;
do
local var1 = 1
print(var1)
var2 = 2
end
print(var2)
end |
and with the same rules: do -- block1
do -- block2
-- other code here
do -- block3
do -- block4
i32.load 1
setvar v1
loadvar v1
call print
i32.load 2
setvar v2
end
end
-- other code here
end
-- other code here
loadvar v2
print
end becomes do -- block1
local v2
do -- block2
-- other code here
do -- block3
do -- block4
local v1 = 1
print(v1)
v2 = 2
end
end
-- other code here
end
-- other code here
print(v2)
end |
increment if (sum(currentDeclarations in funcState.blocks) + funcState.currentDeclarations) >= 199 {
if(!funcState.useTableVariables) {
funcState.useTableVariables = true;
funcState.tableVariableIdx = 1;
}
-- allocate `tableVarName[${funcState.tableVariableIdx++}]`
} |
This way virtual registers are confined within a block and the LuaJIT's tracer heuristics can work better with inferring local variable lifespans
The text was updated successfully, but these errors were encountered: