forked from titzer/virgil
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lsra]: Fix nested live ranges due to
finishLoop
In certain edge cases, `finishLoop` would not insert `LsraEnd`s for active variables resulting in nested live ranges which manifested as an infinite loop in the register allocator (see discussion here [1]). This commit fixes this bug by keeping track of whether a variable will be made active in the future or not (i.e. if it will have a live range). If a variable will have a live range in the future, then `finishLoop` will make sure to insert `LsraEnd`s for them to avoid the above bug. [1]: titzer#308
- Loading branch information
Showing
12 changed files
with
430 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//@execute 0=true | ||
type JsonValue { | ||
case String(v: string); | ||
case Number(v: int); // TODO: float | ||
case Bool(v: bool); | ||
case Null; | ||
case JArray(v: Array<JsonValue>); | ||
case JObject(v: HashMap<string, JsonValue>); | ||
} | ||
|
||
class Vector<T> { | ||
def put(v: T) { } | ||
def extract() -> Array<T> { return null; } | ||
} | ||
class HashMap<K, V> { | ||
} | ||
|
||
def ERR_RET = JsonValue.Null; | ||
class JsonParser { | ||
var ok: bool; | ||
var state: int; | ||
|
||
def parse_value() -> JsonValue { | ||
match (state++) { | ||
0 => return ERR_RET; | ||
1 => return parse_string(); | ||
2 => return parse_number(); | ||
3 => return JsonValue.Null; | ||
4 => return JsonValue.Bool(true); | ||
5 => return JsonValue.Bool(false); | ||
6 => return parse_array(); | ||
7 => return parse_object(); | ||
} | ||
return ERR_RET; | ||
} | ||
def parse_string() -> JsonValue { | ||
return JsonValue.String(if(state++ == 8, "", "a")); | ||
} | ||
def parse_number() -> JsonValue { | ||
return JsonValue.Number(state++); | ||
} | ||
def parse_object() -> JsonValue { | ||
return JsonValue.JObject(null); | ||
} | ||
def parse_array() -> JsonValue { | ||
var vals = Vector<JsonValue>.new(); | ||
if (req1('[') == -1) return ERR_RET; | ||
vals.put(parse_value()); | ||
if (!ok) return ERR_RET; | ||
while (opt1(',') != -1) { | ||
vals.put(parse_value()); | ||
if (!ok) return ERR_RET; | ||
} | ||
if (req1(']') == -1) return ERR_RET; | ||
return JsonValue.JArray(vals.extract()); | ||
} | ||
def req1(ch: byte) -> int { | ||
ok = ch == '1'; | ||
return if(ch == '0', 1, -1); | ||
} | ||
def opt1(ch: byte) -> int { | ||
ok = ch == '2'; | ||
return -1; | ||
} | ||
} | ||
|
||
def main(a: int) -> bool { | ||
var x = JsonParser.new(); | ||
return x.parse_array() == ERR_RET; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//@execute 0=true; 1=false; 2=false | ||
type JsonValue { | ||
case String(v: string); | ||
case Number(v: int); // TODO: float | ||
case Bool(v: bool); | ||
case Null; | ||
case JArray(v: Array<JsonValue>); | ||
case JObject(v: HashMap<string, JsonValue>); | ||
} | ||
|
||
class Vector<T> { | ||
def put(v: T) { } | ||
def extract() -> Array<T> { return null; } | ||
} | ||
class HashMap<K, V> { | ||
} | ||
|
||
def ERR_RET = JsonValue.Null; | ||
class JsonParser { | ||
var ok: bool; | ||
var state: int; | ||
|
||
def parse_value() -> JsonValue { | ||
match (state++) { | ||
0 => return ERR_RET; | ||
1 => return parse_string(); | ||
2 => return parse_number(); | ||
3 => return JsonValue.Null; | ||
4 => return JsonValue.Bool(true); | ||
5 => return JsonValue.Bool(false); | ||
6 => return parse_array(); | ||
7 => return parse_object(); | ||
} | ||
return ERR_RET; | ||
} | ||
def parse_string() -> JsonValue { | ||
return JsonValue.String(if(state++ == 8, "", "a")); | ||
} | ||
def parse_number() -> JsonValue { | ||
return JsonValue.Number(state++); | ||
} | ||
def parse_object() -> JsonValue { | ||
return JsonValue.JObject(null); | ||
} | ||
def parse_array() -> JsonValue { | ||
var vals = Vector<JsonValue>.new(); | ||
if (req1('[') == -1) return ERR_RET; | ||
vals.put(parse_value()); | ||
if (!ok) return ERR_RET; | ||
while (opt1(',') != -1) { | ||
vals.put(parse_value()); | ||
if (!ok) return ERR_RET; | ||
} | ||
if (req1(']') == -1) return ERR_RET; | ||
return JsonValue.JArray(vals.extract()); | ||
} | ||
def req1(ch: byte) -> int { | ||
return 1; | ||
} | ||
def opt1(ch: byte) -> int { | ||
return -1; | ||
} | ||
} | ||
|
||
def main(a: int) -> bool { | ||
var x = JsonParser.new(); | ||
x.state = a; | ||
x.ok = a > 0; | ||
return x.parse_array() == ERR_RET; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//@execute 0=true; 1=false; 2=false | ||
type JsonValue { | ||
case String(v: string); | ||
case Number(v: int); // TODO: float | ||
case Bool(v: bool); | ||
case Null; | ||
case JArray(v: Array<JsonValue>); | ||
case JObject(v: HashMap<string, JsonValue>); | ||
} | ||
|
||
class Vector<T> { | ||
def put(v: T) { } | ||
def extract() -> Array<T> { return null; } | ||
} | ||
class HashMap<K, V> { | ||
} | ||
|
||
def ERR_RET = JsonValue.Null; | ||
class JsonParser { | ||
var ok: bool; | ||
var state: int; | ||
|
||
def parse_value() -> JsonValue { | ||
return JsonValue.String(if(state++ == 8, "", "a")); | ||
} | ||
def parse_array() -> JsonValue { | ||
var vals = Vector<JsonValue>.new(); | ||
if (req1() == -1) return ERR_RET; | ||
vals.put(parse_value()); | ||
if (!ok) return ERR_RET; | ||
while (opt1(',') != -1) { | ||
vals.put(parse_value()); | ||
if (!ok) return ERR_RET; | ||
} | ||
if (req1() == -1) return ERR_RET; | ||
return JsonValue.JArray(vals.extract()); | ||
} | ||
def req1() -> int { | ||
return 1; | ||
} | ||
def opt1(ch: byte) -> int { | ||
return -1; | ||
} | ||
} | ||
|
||
def main(a: int) -> bool { | ||
var x = JsonParser.new(); | ||
x.state = a; | ||
x.ok = a > 0; | ||
return x.parse_array() == ERR_RET; | ||
} |
Oops, something went wrong.