Skip to content

Control flow graph #222

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

Draft
wants to merge 54 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
c1d41af
remove operation cache from the scope
JeanJPNM Jan 5, 2024
5b0ec10
start experimenting with cfg based ir
JeanJPNM Jan 11, 2024
1dffe9e
ignore blocks that can't be connected
JeanJPNM Jan 12, 2024
26dae45
track backward edges
JeanJPNM Jan 12, 2024
50f4a33
add missing source locations to do while handler
JeanJPNM Jan 12, 2024
2475e60
always add an end instruction
JeanJPNM Jan 12, 2024
383fffd
prevent deop on do while loop jumps
JeanJPNM Jan 12, 2024
9b02c80
negate the condition value when the source isn't found
JeanJPNM Jan 13, 2024
6304a3b
refactor parent and edge fields
JeanJPNM Jan 14, 2024
f65f8ee
add handleWrite method
JeanJPNM Jan 20, 2024
234a422
dump changes
JeanJPNM Jan 29, 2024
baa9170
remove the AssignmentInstruction
JeanJPNM Feb 3, 2024
ac02501
update outdated scope definitions
JeanJPNM Feb 3, 2024
13080db
allow macro functions to run during node handling
JeanJPNM Feb 3, 2024
b9ff7fe
update basic value get methods
JeanJPNM Feb 3, 2024
d959354
convert math functions into comptime macro functions
JeanJPNM Feb 3, 2024
15dabc0
fix mlog math not being initialized properly
JeanJPNM Feb 4, 2024
9bc02ed
add constant operation folding
JeanJPNM Feb 4, 2024
85a2924
remove break-ifs that have constant conditions
JeanJPNM Feb 4, 2024
c629f4e
small refactor on BreakIfInstruction
JeanJPNM Feb 4, 2024
ba2be13
canonicalize binary operations
JeanJPNM Feb 4, 2024
6a2c064
apply transformations to binary operations
JeanJPNM Feb 4, 2024
5a4a10d
remove unused operations
JeanJPNM Feb 4, 2024
ad1963f
update break-if canonicalization
JeanJPNM Feb 4, 2024
d9ff33e
add missing code from graph.ts
JeanJPNM Feb 4, 2024
609065d
add missing code from other flow/ files
JeanJPNM Feb 4, 2024
8dedaf4
update block merging and skipping
JeanJPNM Feb 5, 2024
21de6dc
only traverse each block once
JeanJPNM Feb 5, 2024
aaad7d8
add missing import
JeanJPNM Feb 5, 2024
111a5ad
don't invert break-ifs when both targets are empty
JeanJPNM Feb 5, 2024
4a96582
prevent index out of bounds when removing unused instructions
JeanJPNM Feb 5, 2024
30cb0de
flip break-ifs that check if a value is falsy
JeanJPNM Feb 8, 2024
eefbef9
canonicalize range comparison operations
JeanJPNM Feb 8, 2024
e0b23e4
refactor logic for computing readers and writers of values
JeanJPNM Feb 19, 2024
0ed19f9
only accept immutable ids in the writer map
JeanJPNM Feb 19, 2024
f751439
optimize load instructions that are immediately used
JeanJPNM Feb 19, 2024
da23012
big changes
JeanJPNM Apr 17, 2024
97b8f5b
incomplete macro updates
JeanJPNM Apr 17, 2024
fcff1bd
migrate most built-in functions to work with the new IR
JeanJPNM Apr 18, 2024
3d09038
fix spawnWave argument count checks
JeanJPNM Apr 18, 2024
27c2b71
fix evaluation of computed keys in assignment expressions
JeanJPNM Jul 31, 2024
62a5025
fix wrong instruction list length when using endScript()
JeanJPNM Jan 9, 2025
8269ca0
improve generated instruction layout for most cases
JeanJPNM Jan 9, 2025
82f02a9
add the end-if instruction
JeanJPNM Jan 9, 2025
20590bf
remove legacy variable declaration handlers
JeanJPNM Jan 9, 2025
ba6f5da
remove the JumpOutValue class
JeanJPNM Jan 10, 2025
da616c4
fix implementation of print
JeanJPNM Jan 13, 2025
edc9f19
make DOT ir generator dependency free
JeanJPNM Jan 20, 2025
b732866
figured out why the back break check existed
JeanJPNM Jan 20, 2025
6c3fad8
use numbers to differentiate ids instead of object identities
JeanJPNM Jan 20, 2025
c30b864
fix return type of isTemplateObjectArray
JeanJPNM Jan 20, 2025
c60f732
generic changes
JeanJPNM Jan 20, 2025
1e752a2
fix named parameters of built-in functions
JeanJPNM Jan 21, 2025
81f0609
improve appearance of visualized nodes
JeanJPNM Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor parent and edge fields
  • Loading branch information
JeanJPNM committed Jan 14, 2024
commit 6304a3b8ed9ebfcdd15304f20e1b47facaf5da7c
12 changes: 10 additions & 2 deletions compiler/src/flow/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ export class Block {
public endInstruction?: TBlockEndInstruction,
) {}

get forwardParents(): Block[] {
return this.parents.filter(parent =>
parent.childEdges.some(
edge => edge.block === this && edge.type === "forward",
),
);
}

get children(): Block[] {
return this.edges.map(edge => edge.block);
return this.childEdges.map(edge => edge.block);
}

get edges(): TEdge[] {
get childEdges(): TEdge[] {
if (!this.endInstruction) return [];
switch (this.endInstruction.type) {
case "break":
Expand Down
17 changes: 5 additions & 12 deletions compiler/src/flow/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,9 @@ export class Graph {

const flatten = (block: Block) => {
if (visited.has(block)) return;
const { parents } = block;
const { forwardParents } = block;

if (
!parents
.filter(parent => {
const edge = parent.edges.find(edge => edge.block === block);
return edge?.type === "forward";
})
.every(parent => visited.has(parent))
) {
if (!forwardParents.every(parent => visited.has(parent))) {
return;
}
visited.add(block);
Expand Down Expand Up @@ -237,8 +230,8 @@ export class Graph {
// and because of how break-if is implemented
// having the alternate branch before the consequent branch
// reduces the amount of instructions needed
for (let i = block.edges.length - 1; i >= 0; i--) {
const edge = block.edges[i];
for (let i = block.childEdges.length - 1; i >= 0; i--) {
const edge = block.childEdges[i];
if (edge.type === "backward") continue;
// for (let i = 0; i < block.children.length; i++) {
flatten(edge.block);
Expand Down Expand Up @@ -300,7 +293,7 @@ export class Graph {
function traverse(block: Block, action: (block: Block) => void) {
function _traverse(block: Block) {
action(block);
for (const edge of block.edges) {
for (const edge of block.childEdges) {
if (edge.type === "backward") continue;
_traverse(edge.block);
}
Expand Down