Skip to content

Commit

Permalink
and there were 3
Browse files Browse the repository at this point in the history
  • Loading branch information
dleiferives committed May 24, 2024
1 parent 65f891e commit cf4b45e
Showing 1 changed file with 36 additions and 41 deletions.
77 changes: 36 additions & 41 deletions src/ir/phi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -819,43 +819,38 @@ fn gen_statement(
}
},
.immediate => {
var immFlagGaurd = true;
while (immFlagGaurd) {
immFlagGaurd = false;
if (selfRef != null and nullFlag == false) {
switch (selfRef.?.kind) {
.local => {
try fun.bbs.get(bb).versionMap.put(name, exprRef);
},
.param => {
try fun.bbs.get(bb).versionMap.put(name, exprRef);
},
.global => {
const storeInst = Inst.store(selfRef.?, exprRef);
try fun.addAnonInst(bb, storeInst);
},
.immediate => {
// we are not doing no constant folding here, use the immediate information
if (immFlagGaurd == true) {
utils.todo("Cannot assign to an immediate\n", .{});
}
switch (selfRef.?.extraImm) {
._invalid => {
selfRef = try fun.getNamedRef(ir, toName, bb);
// utils.todo("invalid extraImm\n", .{});
},
else => {},
}
selfRef.?.kind = selfRef.?.extraImm;
immFlagGaurd = true;
},
else => {
utils.todo("Cannot assign to an unknown param type {s}\n", .{@tagName(selfRef.?.kind)});
},
switch (exprRef.type) {
.null_ => {
// if it null we need somewhere to assign it to!
// var assignRef = try fun.getNamedRef(ir, toName, bb);

// generate the store instruction
// const nullInst = Inst.store(assignRef, exprRef);
// try fun.addAnonInst(bb, nullInst);
if (selfRef != null) {
switch (selfRef.?.kind) {
.local => {
_ = try fun.bbs.get(bb).versionMap.put(name, exprRef);
exprRef.extraImm = selfRef.?.kind;
},
.param => {
_ = try fun.bbs.get(bb).versionMap.put(name, exprRef);
exprRef.extraImm = selfRef.?.kind;
},
.global => {
const storeInst = Inst.store(selfRef.?, exprRef);
try fun.addAnonInst(bb, storeInst);
},
else => {
utils.todo("Cannot assign to an unknown param type\n", .{});
},
}
}
} else {
unreachable;
}
nullFlag = true;
},
else => {
utils.todo("undefined behavior on imm assignment", .{});
},
}
},
else => {
Expand Down Expand Up @@ -1060,16 +1055,16 @@ fn gen_expression(
const _bitcast = ".bitcast";
var allocNameArr = std.ArrayList(u8).init(ir.alloc);
var bitcastNameArr = std.ArrayList(u8).init(ir.alloc);
for (lenStr) |c| {
try allocNameArr.append(c);
try bitcastNameArr.append(c);
}
for (_malloc) |c| {
try allocNameArr.append(c);
}
for (_bitcast) |c| {
try bitcastNameArr.append(c);
}
for (lenStr) |c| {
try allocNameArr.append(c);
try bitcastNameArr.append(c);
}
const allocNameStr = try allocNameArr.toOwnedSlice();
const bitcastNameStr = try bitcastNameArr.toOwnedSlice();
const allocName = ir.internIdent(allocNameStr);
Expand Down Expand Up @@ -1791,7 +1786,7 @@ fn inputToIRStringHeader(input: []const u8, alloc: std.mem.Allocator) ![]const u
//
test "phi_stats" {
errdefer log.print();
const name = @embedFile("../../test-suite/tests/milestone2/benchmarks/killerBubbles/killerBubbles.mini");
const name = @embedFile("../../test-suite/tests/milestone2/benchmarks/array_sort/sort.mini");
var str = try inputToIRStringHeader(name, testAlloc);
std.debug.print("{s}\n", .{str});
}

0 comments on commit cf4b45e

Please sign in to comment.