Problem: the analyzer_
in CodeGenLLVM
and derived classes can generate invalid code for outlined functions.
Say, you have code like this
let x = y in
// attr compute_scope
blah = x
Then it gets outlined in codegen_cpu (for example):
let x = y in
call foo(x)
foo(x) {
blah = x
}
Now, if you were to run analyzer_->Simplify
on the body of foo
, you’d get
foo(x) {
blah = y
}
Because the analyzer_
knows that x
is same as y
(because of the Let
statemement), but doesn’t know that y
is no longer available in the outlined function foo
.
What should we do?
- P0: The simplest thing would be to create a new
analyzer_
object in the same way as we create newvar_map_
for outlined functions, but this may sacrifice performance. - P1: The other option would be to “unbind” all variables in the analyzer whose corresponding expressions have undefined variables. This would require changes to the Analyzer class: (1) we’d need to be able to create a copy of
Analyzer
(which is forbidden now), and (2) we’d need to create a functionrestrict
or something like that to unbind all variables with definitions from outside of a given set.