tiny.choir.ir.dialects.operationTemplate
Defined in ir.dialects.
API (20)
Actions
Public operations.
binaryFixedResultbinarySameTypebinarySameTypeFolddialectexplicitexplicitLeafexplicitTerminatorselectSameTypeselectSameTypeFoldternarySameTypeternarySameTypeFoldunaryExplicitTypeunaryExplicitTypeFoldunaryFixedResultunaryNoResultunarySameTypeunarySameTypeFoldunarySameTypeStringAttr
Types and contracts
Public types and contracts.
Source
Source: lib/choir/src/core/dialects/spec.zig:1421
zig
pub const operationTemplate = struct { pub const FoldFn = *const fn ( op: *const anyopaque, results: *interfaces.FoldResults, ) anyerror!void; pub const FixedResultTypeFn = *const fn (ctx: *Context) anyerror!Type; pub fn dialect(comptime DialectType: type) type { return struct { pub fn binarySameType( comptime mnemonic: []const u8, comptime options: opSpec.Options, ) type { return operationTemplate.binarySameType(DialectType, mnemonic, options); } pub fn binarySameTypeFold( comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime fold_fn: FoldFn, ) type { return operationTemplate.binarySameTypeFold(DialectType, mnemonic, options, fold_fn); } pub fn binaryFixedResult( comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime result_type_fn: FixedResultTypeFn, ) type { return operationTemplate.binaryFixedResult(DialectType, mnemonic, options, result_type_fn); } pub fn unarySameType( comptime mnemonic: []const u8, comptime options: opSpec.Options, ) type { return operationTemplate.unarySameType(DialectType, mnemonic, options); } pub fn unarySameTypeFold( comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime fold_fn: FoldFn, ) type { return operationTemplate.unarySameTypeFold(DialectType, mnemonic, options, fold_fn); } pub fn unaryFixedResult( comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime result_type_fn: FixedResultTypeFn, ) type { return operationTemplate.unaryFixedResult(DialectType, mnemonic, options, result_type_fn); } pub fn unarySameTypeStringAttr( comptime mnemonic: []const u8, comptime attr_name: []const u8, comptime attr_value: []const u8, comptime options: opSpec.Options, ) type { return operationTemplate.unarySameTypeStringAttr(DialectType, mnemonic, attr_name, attr_value, options); } pub fn unaryExplicitTypeFold( comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime fold_fn: FoldFn, ) type { return operationTemplate.unaryExplicitTypeFold(DialectType, mnemonic, options, fold_fn); } pub fn unaryExplicitType( comptime mnemonic: []const u8, comptime options: opSpec.Options, ) type { return operationTemplate.unaryExplicitType(DialectType, mnemonic, options); } pub fn unaryNoResult( comptime mnemonic: []const u8, comptime options: opSpec.Options, ) type { return operationTemplate.unaryNoResult(DialectType, mnemonic, options); } pub fn ternarySameType( comptime mnemonic: []const u8, comptime options: opSpec.Options, ) type { return operationTemplate.ternarySameType(DialectType, mnemonic, options); } pub fn ternarySameTypeFold( comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime fold_fn: FoldFn, ) type { return operationTemplate.ternarySameTypeFold(DialectType, mnemonic, options, fold_fn); } pub fn selectSameType( comptime mnemonic: []const u8, comptime options: opSpec.Options, ) type { return operationTemplate.selectSameType(DialectType, mnemonic, options); } pub fn selectSameTypeFold( comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime fold_fn: FoldFn, ) type { return operationTemplate.selectSameTypeFold(DialectType, mnemonic, options, fold_fn); } pub fn explicitLeaf( comptime OpType: type, comptime spec: anytype, ) type { return operationTemplate.explicitLeaf(DialectType, OpType, spec); } pub fn explicit( comptime OpType: type, comptime spec: anytype, ) type { return operationTemplate.explicit(DialectType, OpType, spec); } pub fn explicitTerminator( comptime OpType: type, comptime spec: anytype, ) type { return operationTemplate.explicitTerminator(DialectType, OpType, spec); } }; } pub fn binarySameType( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, ) type { return binarySameTypeImpl(DialectType, mnemonic, options, null); } pub fn binarySameTypeFold( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime fold_fn: FoldFn, ) type { return binarySameTypeImpl(DialectType, mnemonic, options, fold_fn); } pub fn binaryFixedResult( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime result_type_fn: FixedResultTypeFn, ) type { return binaryFixedResultImpl(DialectType, mnemonic, options, result_type_fn); } pub fn unarySameType( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, ) type { return unarySameTypeImpl(DialectType, mnemonic, options, null); } pub fn unarySameTypeFold( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime fold_fn: FoldFn, ) type { return unarySameTypeImpl(DialectType, mnemonic, options, fold_fn); } pub fn unaryFixedResult( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime result_type_fn: FixedResultTypeFn, ) type { return unaryFixedResultImpl(DialectType, mnemonic, options, result_type_fn); } pub fn unarySameTypeStringAttr( comptime DialectType: type, comptime mnemonic: []const u8, comptime attr_name: []const u8, comptime attr_value: []const u8, comptime options: opSpec.Options, ) type { return unarySameTypeStringAttrImpl(DialectType, mnemonic, attr_name, attr_value, options); } pub fn unaryExplicitTypeFold( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime fold_fn: FoldFn, ) type { return unaryExplicitTypeImpl(DialectType, mnemonic, options, fold_fn); } pub fn unaryExplicitType( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, ) type { return unaryExplicitTypeImpl(DialectType, mnemonic, options, null); } pub fn unaryNoResult( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, ) type { return unaryNoResultImpl(DialectType, mnemonic, options); } pub fn ternarySameType( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, ) type { return ternarySameTypeImpl(DialectType, mnemonic, options, null); } pub fn ternarySameTypeFold( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime fold_fn: FoldFn, ) type { return ternarySameTypeImpl(DialectType, mnemonic, options, fold_fn); } pub fn selectSameType( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, ) type { return selectSameTypeImpl(DialectType, mnemonic, options, null); } pub fn selectSameTypeFold( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime fold_fn: FoldFn, ) type { return selectSameTypeImpl(DialectType, mnemonic, options, fold_fn); } pub fn explicitLeaf( comptime DialectType: type, comptime OpType: type, comptime spec: anytype, ) type { const op_specs = opSpec.dialect(DialectType); const generated_spec = op_specs.leaf(spec); const accessors = operationAttributeAccessors(OpType, generated_spec); return struct { pub const operation_spec = generated_spec; pub const operation_name = generated_spec.name; pub const setI64Attr = accessors.setI64Attr; pub const getI64Attr = accessors.getI64Attr; pub const setBoolAttr = accessors.setBoolAttr; pub const getBoolAttr = accessors.getBoolAttr; pub const setStringAttr = accessors.setStringAttr; pub const getStringAttr = accessors.getStringAttr; pub const setDialectAttrPayload = accessors.setDialectAttrPayload; pub const getDialectAttrPayload = accessors.getDialectAttrPayload; pub const dialectAttrName = accessors.dialectAttrName; pub fn createLeaf( ctx: *Context, loc: Location, operands: []const *IrValue, result_types: []const Type, ) !OpType { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(operands); state.addTypes(result_types); const op = try builder.create(state); return .{ .op = op }; } pub fn getOperand(self: OpType, comptime component_name: []const u8) *IrValue { return operand(operation_spec, self.op, component_name); } pub fn getOptionalOperand(self: OpType, comptime component_name: []const u8) ?*IrValue { return optionalOperand(operation_spec, self.op, component_name); } pub fn getOperandSegment(self: OpType, comptime component_name: []const u8) ?[]const *IrValue { return operandSegmentValues(operation_spec, self.op, component_name); } pub fn getOperandSegmentValue(self: OpType, comptime component_name: []const u8) ?*IrValue { return operandSegmentValue(operation_spec, self.op, component_name); } pub fn getNamedResult(self: OpType, comptime component_name: []const u8) *IrValue { return result(operation_spec, self.op, component_name); } pub fn getOptionalResult(self: OpType, comptime component_name: []const u8) ?*IrValue { return optionalResult(operation_spec, self.op, component_name); } pub fn getResultSegment(self: OpType, comptime component_name: []const u8) ?[]IrValue { return resultSegmentValues(operation_spec, self.op, component_name); } pub fn getResultSegmentValue(self: OpType, comptime component_name: []const u8) ?*IrValue { return resultSegmentValue(operation_spec, self.op, component_name); } pub fn getResult(self: OpType) *IrValue { if (operation_spec.result_names.len != 1) { @compileError("operationTemplate.explicitLeaf getResult requires exactly one named result"); } return result(operation_spec, self.op, operation_spec.result_names[0]); } }; } pub fn explicit( comptime DialectType: type, comptime OpType: type, comptime spec: anytype, ) type { const op_specs = opSpec.dialect(DialectType); const generated_spec = op_specs.define(spec); const accessors = operationAttributeAccessors(OpType, generated_spec); return struct { pub const operation_spec = generated_spec; pub const operation_name = generated_spec.name; pub const setI64Attr = accessors.setI64Attr; pub const getI64Attr = accessors.getI64Attr; pub const setBoolAttr = accessors.setBoolAttr; pub const getBoolAttr = accessors.getBoolAttr; pub const setStringAttr = accessors.setStringAttr; pub const getStringAttr = accessors.getStringAttr; pub const setDialectAttrPayload = accessors.setDialectAttrPayload; pub const getDialectAttrPayload = accessors.getDialectAttrPayload; pub const dialectAttrName = accessors.dialectAttrName; pub fn createOperation( ctx: *Context, loc: Location, operands: []const *IrValue, result_types: []const Type, region_bodies: []const *Region, successors: []const *Block, ) !OpType { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(operands); state.addTypes(result_types); state.addRegionBodies(region_bodies); state.addSuccessors(successors); const op = try builder.create(state); return .{ .op = op }; } pub fn getOperand(self: OpType, comptime component_name: []const u8) *IrValue { return operand(operation_spec, self.op, component_name); } pub fn getOptionalOperand(self: OpType, comptime component_name: []const u8) ?*IrValue { return optionalOperand(operation_spec, self.op, component_name); } pub fn getOperandSegment(self: OpType, comptime component_name: []const u8) ?[]const *IrValue { return operandSegmentValues(operation_spec, self.op, component_name); } pub fn getOperandSegmentValue(self: OpType, comptime component_name: []const u8) ?*IrValue { return operandSegmentValue(operation_spec, self.op, component_name); } pub fn getNamedResult(self: OpType, comptime component_name: []const u8) *IrValue { return result(operation_spec, self.op, component_name); } pub fn getOptionalResult(self: OpType, comptime component_name: []const u8) ?*IrValue { return optionalResult(operation_spec, self.op, component_name); } pub fn getResultSegment(self: OpType, comptime component_name: []const u8) ?[]IrValue { return resultSegmentValues(operation_spec, self.op, component_name); } pub fn getResultSegmentValue(self: OpType, comptime component_name: []const u8) ?*IrValue { return resultSegmentValue(operation_spec, self.op, component_name); } pub fn getRegion(self: OpType, comptime component_name: []const u8) *Region { return region(operation_spec, self.op, component_name); } pub fn getOptionalRegion(self: OpType, comptime component_name: []const u8) ?*Region { return optionalRegion(operation_spec, self.op, component_name); } pub fn getSuccessor(self: OpType, comptime component_name: []const u8) *Block { return successor(operation_spec, self.op, component_name); } pub fn getOptionalSuccessor(self: OpType, comptime component_name: []const u8) ?*Block { return optionalSuccessor(operation_spec, self.op, component_name); } }; } pub fn explicitTerminator( comptime DialectType: type, comptime OpType: type, comptime spec: anytype, ) type { const op_specs = opSpec.dialect(DialectType); const generated_spec = op_specs.terminator(spec); const accessors = operationAttributeAccessors(OpType, generated_spec); return struct { pub const operation_spec = generated_spec; pub const operation_name = generated_spec.name; pub const setI64Attr = accessors.setI64Attr; pub const getI64Attr = accessors.getI64Attr; pub const setBoolAttr = accessors.setBoolAttr; pub const getBoolAttr = accessors.getBoolAttr; pub const setStringAttr = accessors.setStringAttr; pub const getStringAttr = accessors.getStringAttr; pub const setDialectAttrPayload = accessors.setDialectAttrPayload; pub const getDialectAttrPayload = accessors.getDialectAttrPayload; pub const dialectAttrName = accessors.dialectAttrName; pub fn createTerminator( ctx: *Context, loc: Location, operands: []const *IrValue, successors: []const *Block, ) !OpType { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(operands); state.addSuccessors(successors); const op = try builder.create(state); return .{ .op = op }; } pub fn getOperand(self: OpType, comptime component_name: []const u8) *IrValue { return operand(operation_spec, self.op, component_name); } pub fn getOptionalOperand(self: OpType, comptime component_name: []const u8) ?*IrValue { return optionalOperand(operation_spec, self.op, component_name); } pub fn getOperandSegment(self: OpType, comptime component_name: []const u8) ?[]const *IrValue { return operandSegmentValues(operation_spec, self.op, component_name); } pub fn getOperandSegmentValue(self: OpType, comptime component_name: []const u8) ?*IrValue { return operandSegmentValue(operation_spec, self.op, component_name); } pub fn getSuccessor(self: OpType, comptime component_name: []const u8) *Block { return successor(operation_spec, self.op, component_name); } pub fn getOptionalSuccessor(self: OpType, comptime component_name: []const u8) ?*Block { return optionalSuccessor(operation_spec, self.op, component_name); } }; } fn binarySameTypeImpl( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime fold_fn: ?FoldFn, ) type { const generated_spec = opSpec.shaped(operationName(DialectType.name, mnemonic), shape.leaf(2, 1), options); if (fold_fn) |fold_impl| { return struct { op: *Operation, pub const operation_spec = generated_spec; pub const operation_name = operation_spec.name; pub const fold = fold_impl; pub fn create(ctx: *Context, loc: Location, lhs: *IrValue, rhs: *IrValue) !@This() { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(&.{ lhs, rhs }); state.addTypes(&.{lhs.type}); const op = try builder.create(state); return .{ .op = op }; } pub fn getResult(self: *const @This()) *IrValue { return self.op.getResult(0).?; } pub fn getLhs(self: @This()) *IrValue { return self.op.getOperand(0).?; } pub fn getRhs(self: @This()) *IrValue { return self.op.getOperand(1).?; } }; } return struct { op: *Operation, pub const operation_spec = generated_spec; pub const operation_name = operation_spec.name; pub fn create(ctx: *Context, loc: Location, lhs: *IrValue, rhs: *IrValue) !@This() { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(&.{ lhs, rhs }); state.addTypes(&.{lhs.type}); const op = try builder.create(state); return .{ .op = op }; } pub fn getResult(self: *const @This()) *IrValue { return self.op.getResult(0).?; } pub fn getLhs(self: @This()) *IrValue { return self.op.getOperand(0).?; } pub fn getRhs(self: @This()) *IrValue { return self.op.getOperand(1).?; } }; } fn binaryFixedResultImpl( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime result_type_fn: FixedResultTypeFn, ) type { const generated_spec = opSpec.shaped(operationName(DialectType.name, mnemonic), shape.leaf(2, 1), options); return struct { op: *Operation, pub const operation_spec = generated_spec; pub const operation_name = operation_spec.name; pub fn create(ctx: *Context, loc: Location, lhs: *IrValue, rhs: *IrValue) !@This() { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(&.{ lhs, rhs }); state.addTypes(&.{try result_type_fn(ctx)}); const op = try builder.create(state); return .{ .op = op }; } pub fn getResult(self: *const @This()) *IrValue { return self.op.getResult(0).?; } pub fn getLhs(self: @This()) *IrValue { return self.op.getOperand(0).?; } pub fn getRhs(self: @This()) *IrValue { return self.op.getOperand(1).?; } }; } fn unarySameTypeImpl( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime fold_fn: ?FoldFn, ) type { const generated_spec = opSpec.shaped(operationName(DialectType.name, mnemonic), shape.leaf(1, 1), options); if (fold_fn) |fold_impl| { return struct { op: *Operation, pub const operation_spec = generated_spec; pub const operation_name = operation_spec.name; pub const fold = fold_impl; pub fn create(ctx: *Context, loc: Location, input: *IrValue) !@This() { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(&.{input}); state.addTypes(&.{input.type}); const op = try builder.create(state); return .{ .op = op }; } pub fn getResult(self: *const @This()) *IrValue { return self.op.getResult(0).?; } pub fn getInput(self: @This()) *IrValue { return self.op.getOperand(0).?; } }; } return struct { op: *Operation, pub const operation_spec = generated_spec; pub const operation_name = operation_spec.name; pub fn create(ctx: *Context, loc: Location, input: *IrValue) !@This() { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(&.{input}); state.addTypes(&.{input.type}); const op = try builder.create(state); return .{ .op = op }; } pub fn getResult(self: *const @This()) *IrValue { return self.op.getResult(0).?; } pub fn getInput(self: @This()) *IrValue { return self.op.getOperand(0).?; } }; } fn unaryFixedResultImpl( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime result_type_fn: FixedResultTypeFn, ) type { const generated_spec = opSpec.shaped(operationName(DialectType.name, mnemonic), shape.leaf(1, 1), options); return struct { op: *Operation, pub const operation_spec = generated_spec; pub const operation_name = operation_spec.name; pub fn create(ctx: *Context, loc: Location, input: *IrValue) !@This() { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(&.{input}); state.addTypes(&.{try result_type_fn(ctx)}); const op = try builder.create(state); return .{ .op = op }; } pub fn getResult(self: *const @This()) *IrValue { return self.op.getResult(0).?; } pub fn getInput(self: @This()) *IrValue { return self.op.getOperand(0).?; } }; } fn unarySameTypeStringAttrImpl( comptime DialectType: type, comptime mnemonic: []const u8, comptime attr_name: []const u8, comptime attr_value: []const u8, comptime options: opSpec.Options, ) type { const generated_options = optionsWithAttr(options, attr_name); const generated_spec = opSpec.shaped(operationName(DialectType.name, mnemonic), shape.leaf(1, 1), generated_options); return struct { op: *Operation, pub const operation_spec = generated_spec; pub const operation_name = operation_spec.name; pub fn create(ctx: *Context, loc: Location, input: *IrValue) !@This() { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(&.{input}); state.addTypes(&.{input.type}); const op = try builder.create(state); try op.setAttr(attr_name, try ctx.getStringAttr(attr_value)); return .{ .op = op }; } pub fn getResult(self: *const @This()) *IrValue { return self.op.getResult(0).?; } pub fn getInput(self: @This()) *IrValue { return self.op.getOperand(0).?; } pub fn getStringAttr(self: @This()) ?[]const u8 { const attr = self.op.getAttrAs(Attribute.StringAttr, attr_name) orelse return null; return attr.getValue(); } }; } fn unaryExplicitTypeImpl( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime fold_fn: ?FoldFn, ) type { const generated_spec = opSpec.shaped(operationName(DialectType.name, mnemonic), shape.leaf(1, 1), options); if (fold_fn) |fold_impl| { return struct { op: *Operation, pub const operation_spec = generated_spec; pub const operation_name = operation_spec.name; pub const fold = fold_impl; pub fn create(ctx: *Context, loc: Location, input: *IrValue, result_type: Type) !@This() { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(&.{input}); state.addTypes(&.{result_type}); const op = try builder.create(state); return .{ .op = op }; } pub fn getResult(self: *const @This()) *IrValue { return self.op.getResult(0).?; } pub fn getInput(self: @This()) *IrValue { return self.op.getOperand(0).?; } }; } return struct { op: *Operation, pub const operation_spec = generated_spec; pub const operation_name = operation_spec.name; pub fn create(ctx: *Context, loc: Location, input: *IrValue, result_type: Type) !@This() { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(&.{input}); state.addTypes(&.{result_type}); const op = try builder.create(state); return .{ .op = op }; } pub fn getResult(self: *const @This()) *IrValue { return self.op.getResult(0).?; } pub fn getInput(self: @This()) *IrValue { return self.op.getOperand(0).?; } }; } fn unaryNoResultImpl( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, ) type { const generated_spec = opSpec.shaped(operationName(DialectType.name, mnemonic), shape.leaf(1, 0), options); return struct { op: *Operation, pub const operation_spec = generated_spec; pub const operation_name = operation_spec.name; pub fn create(ctx: *Context, loc: Location, input: *IrValue) !@This() { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(&.{input}); const op = try builder.create(state); return .{ .op = op }; } pub fn getInput(self: @This()) *IrValue { return self.op.getOperand(0).?; } }; } fn ternarySameTypeImpl( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime fold_fn: ?FoldFn, ) type { const generated_spec = opSpec.shaped(operationName(DialectType.name, mnemonic), shape.leaf(3, 1), options); if (fold_fn) |fold_impl| { return struct { op: *Operation, pub const operation_spec = generated_spec; pub const operation_name = operation_spec.name; pub const fold = fold_impl; pub fn create(ctx: *Context, loc: Location, a: *IrValue, b: *IrValue, c: *IrValue) !@This() { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(&.{ a, b, c }); state.addTypes(&.{a.type}); const op = try builder.create(state); return .{ .op = op }; } pub fn getResult(self: *const @This()) *IrValue { return self.op.getResult(0).?; } pub fn getA(self: @This()) *IrValue { return self.op.getOperand(0).?; } pub fn getB(self: @This()) *IrValue { return self.op.getOperand(1).?; } pub fn getC(self: @This()) *IrValue { return self.op.getOperand(2).?; } }; } return struct { op: *Operation, pub const operation_spec = generated_spec; pub const operation_name = operation_spec.name; pub fn create(ctx: *Context, loc: Location, a: *IrValue, b: *IrValue, c: *IrValue) !@This() { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(&.{ a, b, c }); state.addTypes(&.{a.type}); const op = try builder.create(state); return .{ .op = op }; } pub fn getResult(self: *const @This()) *IrValue { return self.op.getResult(0).?; } pub fn getA(self: @This()) *IrValue { return self.op.getOperand(0).?; } pub fn getB(self: @This()) *IrValue { return self.op.getOperand(1).?; } pub fn getC(self: @This()) *IrValue { return self.op.getOperand(2).?; } }; } fn selectSameTypeImpl( comptime DialectType: type, comptime mnemonic: []const u8, comptime options: opSpec.Options, comptime fold_fn: ?FoldFn, ) type { const generated_spec = opSpec.shaped(operationName(DialectType.name, mnemonic), shape.leaf(3, 1), options); if (fold_fn) |fold_impl| { return struct { op: *Operation, pub const operation_spec = generated_spec; pub const operation_name = operation_spec.name; pub const fold = fold_impl; pub fn create(ctx: *Context, loc: Location, condition: *IrValue, true_value: *IrValue, false_value: *IrValue) !@This() { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(&.{ condition, true_value, false_value }); state.addTypes(&.{true_value.type}); const op = try builder.create(state); return .{ .op = op }; } pub fn getResult(self: *const @This()) *IrValue { return self.op.getResult(0).?; } pub fn getCondition(self: @This()) *IrValue { return self.op.getOperand(0).?; } pub fn getTrueValue(self: @This()) *IrValue { return self.op.getOperand(1).?; } pub fn getFalseValue(self: @This()) *IrValue { return self.op.getOperand(2).?; } }; } return struct { op: *Operation, pub const operation_spec = generated_spec; pub const operation_name = operation_spec.name; pub fn create(ctx: *Context, loc: Location, condition: *IrValue, true_value: *IrValue, false_value: *IrValue) !@This() { var builder = OperationBuilder.init(ctx); var state = Operation.State.init(operation_name, loc); state.addOperands(&.{ condition, true_value, false_value }); state.addTypes(&.{true_value.type}); const op = try builder.create(state); return .{ .op = op }; } pub fn getResult(self: *const @This()) *IrValue { return self.op.getResult(0).?; } pub fn getCondition(self: @This()) *IrValue { return self.op.getOperand(0).?; } pub fn getTrueValue(self: @This()) *IrValue { return self.op.getOperand(1).?; } pub fn getFalseValue(self: @This()) *IrValue { return self.op.getOperand(2).?; } }; } fn optionsWithAttr(comptime options: opSpec.Options, comptime attr_name: []const u8) opSpec.Options { return .{ .traits = options.traits, .attrs = attrsWithName(options.attrs, attr_name), .required_attrs = attrsWithName(options.required_attrs, attr_name), .attribute_specs = attributeSpecsWithNames(options.attribute_specs, attrsWithName(options.attrs, attr_name)), .operand_segments = options.operand_segments, .result_segments = options.result_segments, .operand_types = options.operand_types, .result_types = options.result_types, .properties = options.properties, .interfaces = options.interfaces, .dynamic_traits = options.dynamic_traits, }; } fn attrsWithName(comptime attrs: []const []const u8, comptime attr_name: []const u8) []const []const u8 { if (attr_name.len == 0) @compileError("operation attribute name cannot be empty"); for (attrs) |existing| { if (std.mem.eql(u8, existing, attr_name)) @compileError("operation attribute name is duplicated"); } const values = comptime blk: { var out: [attrs.len + 1][]const u8 = undefined; for (attrs, 0..) |attr, index| { out[index] = attr; } out[attrs.len] = attr_name; break :blk out; }; return &values; }};Source: lib/choir/src/core/dialects/root.zig:52
zig
pub const operationTemplate = spec.operationTemplate;Also reachable as
backends.wasm.emission.module_encoding.common.ir.dialects.operationTemplate.
Complete caller list for ir.dialects.operationTemplate.dialect
13 direct callers.
lib.choir.src.core.dialects.spec.test_operationTemplate_carries_verifier_helper_metadata[function] — test source atlib/choir/src/core/dialects/spec.zig:4027in nearest public ownerlib.choir.src.core.dialects.speclib.choir.src.core.dialects.spec.test_operationTemplate_explicit_leaf_mixin_derives_construction_from_one_spec[function] — test source atlib/choir/src/core/dialects/spec.zig:3541in nearest public ownerlib.choir.src.core.dialects.speclib.choir.src.core.dialects.spec.test_operationTemplate_explicit_leaf_mixin_derives_optional_and_segment_accessors[function] — test source atlib/choir/src/core/dialects/spec.zig:3666in nearest public ownerlib.choir.src.core.dialects.speclib.choir.src.core.dialects.spec.test_operationTemplate_explicit_leaf_mixin_derives_typed_attribute_accessors[function] — test source atlib/choir/src/core/dialects/spec.zig:3604in nearest public ownerlib.choir.src.core.dialects.speclib.choir.src.core.dialects.spec.test_operationTemplate_explicit_mixin_derives_non-leaf_construction_from_one_spec[function] — test source atlib/choir/src/core/dialects/spec.zig:3791in nearest public ownerlib.choir.src.core.dialects.speclib.choir.src.core.dialects.spec.test_operationTemplate_explicit_terminator_mixin_derives_construction_from_one_spec[function] — test source atlib/choir/src/core/dialects/spec.zig:3857in nearest public ownerlib.choir.src.core.dialects.speclib.choir.src.core.dialects.spec.test_operationTemplate_generates_explicit-result_unary_wrappers[function] — test source atlib/choir/src/core/dialects/spec.zig:4152in nearest public ownerlib.choir.src.core.dialects.speclib.choir.src.core.dialects.spec.test_operationTemplate_generates_fixed-result_leaf_operation_wrappers[function] — test source atlib/choir/src/core/dialects/spec.zig:3961in nearest public ownerlib.choir.src.core.dialects.speclib.choir.src.core.dialects.spec.test_operationTemplate_generates_same-type_leaf_operation_wrappers[function] — test source atlib/choir/src/core/dialects/spec.zig:3910in nearest public ownerlib.choir.src.core.dialects.speclib.choir.src.core.dialects.spec.test_operationTemplate_generates_select_same-type_wrappers[function] — test source atlib/choir/src/core/dialects/spec.zig:4102in nearest public ownerlib.choir.src.core.dialects.speclib.choir.src.core.dialects.spec.test_operationTemplate_generates_ternary_same-type_wrappers[function] — test source atlib/choir/src/core/dialects/spec.zig:4053in nearest public ownerlib.choir.src.core.dialects.speclib.choir.src.core.dialects.spec.test_operationTemplate_generates_unary_attr_and_no-result_wrappers[function] — test source atlib/choir/src/core/dialects/spec.zig:4197in nearest public ownerlib.choir.src.core.dialects.speclib.choir.src.core.dialects.spec.test_operationTemplate_nested_definitions_register_custom_wrappers[function] — test source atlib/choir/src/core/dialects/spec.zig:3468in nearest public ownerlib.choir.src.core.dialects.spec
Complete call list for ir.dialects.operationTemplate.dialect
17 direct calls.
tiny.choir.ir.dialects.operationTemplate.binaryFixedResult[function] atlib/choir/src/core/dialects/spec.zig:1578tiny.choir.ir.dialects.operationTemplate.binarySameType[function] atlib/choir/src/core/dialects/spec.zig:1561tiny.choir.ir.dialects.operationTemplate.binarySameTypeFold[function] atlib/choir/src/core/dialects/spec.zig:1569tiny.choir.ir.dialects.operationTemplate.explicit[function] atlib/choir/src/core/dialects/spec.zig:1758tiny.choir.ir.dialects.operationTemplate.explicitLeaf[function] atlib/choir/src/core/dialects/spec.zig:1682tiny.choir.ir.dialects.operationTemplate.explicitTerminator[function] atlib/choir/src/core/dialects/spec.zig:1847tiny.choir.ir.dialects.operationTemplate.selectSameType[function] atlib/choir/src/core/dialects/spec.zig:1665tiny.choir.ir.dialects.operationTemplate.selectSameTypeFold[function] atlib/choir/src/core/dialects/spec.zig:1673tiny.choir.ir.dialects.operationTemplate.ternarySameType[function] atlib/choir/src/core/dialects/spec.zig:1648tiny.choir.ir.dialects.operationTemplate.ternarySameTypeFold[function] atlib/choir/src/core/dialects/spec.zig:1656tiny.choir.ir.dialects.operationTemplate.unaryExplicitType[function] atlib/choir/src/core/dialects/spec.zig:1632tiny.choir.ir.dialects.operationTemplate.unaryExplicitTypeFold[function] atlib/choir/src/core/dialects/spec.zig:1623tiny.choir.ir.dialects.operationTemplate.unaryFixedResult[function] atlib/choir/src/core/dialects/spec.zig:1604tiny.choir.ir.dialects.operationTemplate.unaryNoResult[function] atlib/choir/src/core/dialects/spec.zig:1640tiny.choir.ir.dialects.operationTemplate.unarySameType[function] atlib/choir/src/core/dialects/spec.zig:1587tiny.choir.ir.dialects.operationTemplate.unarySameTypeFold[function] atlib/choir/src/core/dialects/spec.zig:1595tiny.choir.ir.dialects.operationTemplate.unarySameTypeStringAttr[function] atlib/choir/src/core/dialects/spec.zig:1613
Complete call list for ir.dialects.operationTemplate.explicit
16 direct calls.
tiny.choir.OperationBuilder.create[method] atlib/choir/src/core/builder.zig:204tiny.choir.OperationBuilder.init[function] atlib/choir/src/core/builder.zig:61tiny.choir.ir.dialects.opSpec.dialect[function] atlib/choir/src/core/dialects/spec.zig:941tiny.choir.ir.dialects.operand[function] atlib/choir/src/core/dialects/spec.zig:67tiny.choir.ir.dialects.operandSegmentValue[function] atlib/choir/src/core/dialects/spec.zig:133tiny.choir.ir.dialects.operandSegmentValues[function] atlib/choir/src/core/dialects/spec.zig:124lib.choir.src.core.dialects.spec.operationAttributeAccessors[function] — private source atlib/choir/src/core/dialects/spec.zig:1369in nearest public ownerlib.choir.src.core.dialects.spectiny.choir.ir.dialects.optionalOperand[function] atlib/choir/src/core/dialects/spec.zig:71tiny.choir.ir.dialects.optionalRegion[function] atlib/choir/src/core/dialects/spec.zig:87tiny.choir.ir.dialects.optionalResult[function] atlib/choir/src/core/dialects/spec.zig:79tiny.choir.ir.dialects.optionalSuccessor[function] atlib/choir/src/core/dialects/spec.zig:95tiny.choir.ir.dialects.region[function] atlib/choir/src/core/dialects/spec.zig:83tiny.choir.ir.dialects.result[function] atlib/choir/src/core/dialects/spec.zig:75tiny.choir.ir.dialects.resultSegmentValue[function] atlib/choir/src/core/dialects/spec.zig:148tiny.choir.ir.dialects.resultSegmentValues[function] atlib/choir/src/core/dialects/spec.zig:139tiny.choir.ir.dialects.successor[function] atlib/choir/src/core/dialects/spec.zig:91
Complete call list for ir.dialects.operationTemplate.explicitLeaf
12 direct calls.
tiny.choir.OperationBuilder.create[method] atlib/choir/src/core/builder.zig:204tiny.choir.OperationBuilder.init[function] atlib/choir/src/core/builder.zig:61tiny.choir.ir.dialects.opSpec.dialect[function] atlib/choir/src/core/dialects/spec.zig:941tiny.choir.ir.dialects.operand[function] atlib/choir/src/core/dialects/spec.zig:67tiny.choir.ir.dialects.operandSegmentValue[function] atlib/choir/src/core/dialects/spec.zig:133tiny.choir.ir.dialects.operandSegmentValues[function] atlib/choir/src/core/dialects/spec.zig:124lib.choir.src.core.dialects.spec.operationAttributeAccessors[function] — private source atlib/choir/src/core/dialects/spec.zig:1369in nearest public ownerlib.choir.src.core.dialects.spectiny.choir.ir.dialects.optionalOperand[function] atlib/choir/src/core/dialects/spec.zig:71tiny.choir.ir.dialects.optionalResult[function] atlib/choir/src/core/dialects/spec.zig:79tiny.choir.ir.dialects.result[function] atlib/choir/src/core/dialects/spec.zig:75tiny.choir.ir.dialects.resultSegmentValue[function] atlib/choir/src/core/dialects/spec.zig:148tiny.choir.ir.dialects.resultSegmentValues[function] atlib/choir/src/core/dialects/spec.zig:139
Complete call list for ir.dialects.operationTemplate.explicitTerminator
10 direct calls.
tiny.choir.OperationBuilder.create[method] atlib/choir/src/core/builder.zig:204tiny.choir.OperationBuilder.init[function] atlib/choir/src/core/builder.zig:61tiny.choir.ir.dialects.opSpec.dialect[function] atlib/choir/src/core/dialects/spec.zig:941tiny.choir.ir.dialects.operand[function] atlib/choir/src/core/dialects/spec.zig:67tiny.choir.ir.dialects.operandSegmentValue[function] atlib/choir/src/core/dialects/spec.zig:133tiny.choir.ir.dialects.operandSegmentValues[function] atlib/choir/src/core/dialects/spec.zig:124lib.choir.src.core.dialects.spec.operationAttributeAccessors[function] — private source atlib/choir/src/core/dialects/spec.zig:1369in nearest public ownerlib.choir.src.core.dialects.spectiny.choir.ir.dialects.optionalOperand[function] atlib/choir/src/core/dialects/spec.zig:71tiny.choir.ir.dialects.optionalSuccessor[function] atlib/choir/src/core/dialects/spec.zig:95tiny.choir.ir.dialects.successor[function] atlib/choir/src/core/dialects/spec.zig:91
Audit
| Definitions | 21 |
|---|---|
| Public names | 42 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |