Function brCond [src]

Prototype

pub fn brCond( self: *WipFunction, cond: Value, then: Block.Index, @"else": Block.Index, weights: enum { none, unpredictable, then_likely, else_likely }, ) Allocator.Error!Instruction.Index

Parameters

self: *WipFunctioncond: Valuethen: Block.Index@"else": Block.Indexweights: enum { none, unpredictable, then_likely, else_likely }

Source

pub fn brCond( self: *WipFunction, cond: Value, then: Block.Index, @"else": Block.Index, weights: enum { none, unpredictable, then_likely, else_likely }, ) Allocator.Error!Instruction.Index { assert(cond.typeOfWip(self) == .i1); try self.ensureUnusedExtraCapacity(1, Instruction.BrCond, 0); const instruction = try self.addInst(null, .{ .tag = .br_cond, .data = self.addExtraAssumeCapacity(Instruction.BrCond{ .cond = cond, .then = then, .@"else" = @"else", .weights = switch (weights) { .none => .none, .unpredictable => .unpredictable, .then_likely, .else_likely => w: { const branch_weights_str = try self.builder.metadataString("branch_weights"); const unlikely_const = try self.builder.metadataConstant(try self.builder.intConst(.i32, 1)); const likely_const = try self.builder.metadataConstant(try self.builder.intConst(.i32, 2000)); const weight_vals: [2]Metadata = switch (weights) { .none, .unpredictable => unreachable, .then_likely => .{ likely_const, unlikely_const }, .else_likely => .{ unlikely_const, likely_const }, }; const tuple = try self.builder.strTuple(branch_weights_str, &weight_vals); break :w @enumFromInt(@intFromEnum(tuple)); }, }, }), }); then.ptr(self).branches += 1; @"else".ptr(self).branches += 1; return instruction; }