aboutsummaryrefslogtreecommitdiff
path: root/src/pex/optimizer
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-07-19 20:18:15 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2025-07-19 20:18:15 +0200
commitae10b7d764d9587ab92a682781f8479107e8dff0 (patch)
tree13e060f304ca1cac98ae1e71a2a6e27d9c5fb269 /src/pex/optimizer
parentd138a622dcc77302cc452c52946f6202b6a03f5e (diff)
add pex
Diffstat (limited to 'src/pex/optimizer')
-rw-r--r--src/pex/optimizer/root.zig38
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);
+ }
+}