authorgravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2024-04-05 13:20:14+02:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-04-06 14:57:46-04:00
log637b1d606d52ed2984013bfd1e196934b08de4a9
tree5986a9306ea88b47383367d7d91946f5e2a04a19
parent39420838061a9049fbc889212836a9d4d2ab9af4

LLVM Builder: Emit binary op optional flags for exact and no wrap


2 files changed, 86 insertions(+), 16 deletions(-)

src/codegen/llvm/Builder.zig+50-16
......@@ -14734,39 +14734,23 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1473414734 }, adapter);
1473514735 },
1473614736 .add,
14737 .@"add nsw",
14738 .@"add nuw",
14739 .@"add nuw nsw",
1474014737 .@"and",
1474114738 .fadd,
1474214739 .fdiv,
1474314740 .fmul,
1474414741 .mul,
14745 .@"mul nsw",
14746 .@"mul nuw",
14747 .@"mul nuw nsw",
1474814742 .frem,
1474914743 .fsub,
1475014744 .sdiv,
14751 .@"sdiv exact",
1475214745 .sub,
14753 .@"sub nsw",
14754 .@"sub nuw",
14755 .@"sub nuw nsw",
1475614746 .udiv,
14757 .@"udiv exact",
1475814747 .xor,
1475914748 .shl,
14760 .@"shl nsw",
14761 .@"shl nuw",
14762 .@"shl nuw nsw",
1476314749 .lshr,
14764 .@"lshr exact",
1476514750 .@"or",
1476614751 .urem,
1476714752 .srem,
1476814753 .ashr,
14769 .@"ashr exact",
1477014754 => |kind| {
1477114755 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
1477214756 try function_block.writeAbbrev(FunctionBlock.Binary{
......@@ -14775,6 +14759,56 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1477514759 .rhs = adapter.getOffsetValueIndex(extra.rhs),
1477614760 });
1477714761 },
14762 .@"sdiv exact",
14763 .@"udiv exact",
14764 .@"lshr exact",
14765 .@"ashr exact",
14766 => |kind| {
14767 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
14768 try function_block.writeAbbrev(FunctionBlock.BinaryExact{
14769 .opcode = kind.toBinaryOpcode(),
14770 .lhs = adapter.getOffsetValueIndex(extra.lhs),
14771 .rhs = adapter.getOffsetValueIndex(extra.rhs),
14772 });
14773 },
14774 .@"add nsw",
14775 .@"add nuw",
14776 .@"add nuw nsw",
14777 .@"mul nsw",
14778 .@"mul nuw",
14779 .@"mul nuw nsw",
14780 .@"sub nsw",
14781 .@"sub nuw",
14782 .@"sub nuw nsw",
14783 .@"shl nsw",
14784 .@"shl nuw",
14785 .@"shl nuw nsw",
14786 => |kind| {
14787 const extra = func.extraData(Function.Instruction.Binary, datas[instr_index]);
14788 try function_block.writeAbbrev(FunctionBlock.BinaryNoWrap{
14789 .opcode = kind.toBinaryOpcode(),
14790 .lhs = adapter.getOffsetValueIndex(extra.lhs),
14791 .rhs = adapter.getOffsetValueIndex(extra.rhs),
14792 .flags = switch (kind) {
14793 .@"add nsw",
14794 .@"mul nsw",
14795 .@"sub nsw",
14796 .@"shl nsw",
14797 => .{ .no_unsigned_wrap = false, .no_signed_wrap = true },
14798 .@"add nuw",
14799 .@"mul nuw",
14800 .@"sub nuw",
14801 .@"shl nuw",
14802 => .{ .no_unsigned_wrap = true, .no_signed_wrap = false },
14803 .@"add nuw nsw",
14804 .@"mul nuw nsw",
14805 .@"sub nuw nsw",
14806 .@"shl nuw nsw",
14807 => .{ .no_unsigned_wrap = true, .no_signed_wrap = true },
14808 else => unreachable,
14809 },
14810 });
14811 },
1477814812 .@"fadd fast",
1477914813 .@"fdiv fast",
1478014814 .@"fmul fast",
src/codegen/llvm/ir.zig+36
......@@ -1102,6 +1102,8 @@ pub const FunctionBlock = struct {
11021102 FNeg,
11031103 FNegFast,
11041104 Binary,
1105 BinaryNoWrap,
1106 BinaryExact,
11051107 BinaryFast,
11061108 Cmp,
11071109 CmpFast,
......@@ -1232,6 +1234,40 @@ pub const FunctionBlock = struct {
12321234 opcode: BinaryOpcode,
12331235 };
12341236
1237 pub const BinaryNoWrap = struct {
1238 const BinaryOpcode = Builder.BinaryOpcode;
1239 pub const ops = [_]AbbrevOp{
1240 .{ .literal = 2 },
1241 ValueAbbrev,
1242 ValueAbbrev,
1243 .{ .fixed = @bitSizeOf(BinaryOpcode) },
1244 .{ .fixed = 2 },
1245 };
1246
1247 lhs: u32,
1248 rhs: u32,
1249 opcode: BinaryOpcode,
1250 flags: packed struct(u2) {
1251 no_unsigned_wrap: bool,
1252 no_signed_wrap: bool,
1253 },
1254 };
1255
1256 pub const BinaryExact = struct {
1257 const BinaryOpcode = Builder.BinaryOpcode;
1258 pub const ops = [_]AbbrevOp{
1259 .{ .literal = 2 },
1260 ValueAbbrev,
1261 ValueAbbrev,
1262 .{ .fixed = @bitSizeOf(BinaryOpcode) },
1263 .{ .literal = 1 },
1264 };
1265
1266 lhs: u32,
1267 rhs: u32,
1268 opcode: BinaryOpcode,
1269 };
1270
12351271 pub const BinaryFast = struct {
12361272 const BinaryOpcode = Builder.BinaryOpcode;
12371273 pub const ops = [_]AbbrevOp{