diff options
Diffstat (limited to 'src/pex/optimizer')
| -rw-r--r-- | src/pex/optimizer/root.zig | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/pex/optimizer/root.zig b/src/pex/optimizer/root.zig new file mode 100644 index 0000000..68ce968 --- /dev/null +++ b/src/pex/optimizer/root.zig @@ -0,0 +1,38 @@ +const std = @import("std"); +const Block = @import("../block.zig"); +const Node = @import("../node.zig"); +const Rule = @import("../../rule.zig"); + +pub fn optimize_block( + blocks: []Block, + raw: *Block, + target: *Block, + node_pool: *std.heap.MemoryPool(Node), + allocator: std.mem.Allocator, +) !void { + target.* = try raw.clone(allocator, node_pool); + _ = blocks; + + for (target.heads.items) |head| { + try hard_link_right_recursion(target, head); + } +} + +pub fn hard_link_right_recursion( + block: *Block, + current: *Node, +) !void { + switch (current.instruction) { + .call => |id| if (id == block.id) { + if (current.next.?.instruction == .@"return") { + current.instruction = .{ .jump = &block.heads }; + return; + } + }, + else => {}, + } + + if (current.next) |next| { + try hard_link_right_recursion(block, next); + } +} |