stage2: Add .div to ir.zig

This commit is contained in:
gracefu 2021-04-08 05:24:17 +08:00
parent bcc371618f
commit 4c71942f84
No known key found for this signature in database
GPG Key ID: 2B0D39CC4E035325
4 changed files with 18 additions and 0 deletions

View File

@ -3540,6 +3540,7 @@ fn analyzeArithmetic(
.subwrap => .subwrap,
.mul => .mul,
.mulwrap => .mulwrap,
.div => .div,
else => return sema.mod.fail(&block.base, src, "TODO implement arithmetic for operand '{s}''", .{@tagName(zir_tag)}),
};

View File

@ -855,6 +855,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
.not => return self.genNot(inst.castTag(.not).?),
.mul => return self.genMul(inst.castTag(.mul).?),
.mulwrap => return self.genMulWrap(inst.castTag(.mulwrap).?),
.div => return self.genDiv(inst.castTag(.div).?),
.ptrtoint => return self.genPtrToInt(inst.castTag(.ptrtoint).?),
.ref => return self.genRef(inst.castTag(.ref).?),
.ret => return self.genRet(inst.castTag(.ret).?),
@ -1092,6 +1093,15 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
}
}
fn genDiv(self: *Self, inst: *ir.Inst.BinOp) !MCValue {
// No side effects, so if it's unreferenced, do nothing.
if (inst.base.isUnused())
return MCValue.dead;
switch (arch) {
else => return self.fail(inst.base.src, "TODO implement div for {}", .{self.target.cpu.arch}),
}
}
fn genBitAnd(self: *Self, inst: *ir.Inst.BinOp) !MCValue {
// No side effects, so if it's unreferenced, do nothing.
if (inst.base.isUnused())

View File

@ -582,6 +582,9 @@ pub fn genBody(o: *Object, body: ir.Body) error{ AnalysisFail, OutOfMemory }!voi
.mul => try genBinOp(o, inst.castTag(.sub).?, " * "),
// TODO make this do wrapping multiplication for signed ints
.mulwrap => try genBinOp(o, inst.castTag(.sub).?, " * "),
// TODO use a different strategy for div that communicates to the optimizer
// that wrapping is UB.
.div => try genBinOp(o, inst.castTag(.div).?, " / "),
.constant => unreachable, // excluded from function bodies
.alloc => try genAlloc(o, inst.castTag(.alloc).?),

View File

@ -115,6 +115,7 @@ pub const Inst = struct {
unreach,
mul,
mulwrap,
div,
not,
floatcast,
intcast,
@ -181,6 +182,7 @@ pub const Inst = struct {
.subwrap,
.mul,
.mulwrap,
.div,
.cmp_lt,
.cmp_lte,
.cmp_eq,
@ -752,6 +754,7 @@ const DumpTzir = struct {
.subwrap,
.mul,
.mulwrap,
.div,
.cmp_lt,
.cmp_lte,
.cmp_eq,
@ -891,6 +894,7 @@ const DumpTzir = struct {
.subwrap,
.mul,
.mulwrap,
.div,
.cmp_lt,
.cmp_lte,
.cmp_eq,