blob: 68ce96815ba80f455456d732fbe2a06018cf0f27 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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);
}
}
|