2023-01-02 14:28:25 +00:00
|
|
|
const std = @import("std");
|
2024-08-26 14:19:00 +00:00
|
|
|
|
2023-01-02 14:28:25 +00:00
|
|
|
const mlir = @import("mlir");
|
2025-07-28 13:54:28 +00:00
|
|
|
const stdx = @import("stdx");
|
2023-01-02 14:28:25 +00:00
|
|
|
|
|
|
|
|
pub fn func(
|
|
|
|
|
ctx: mlir.Context,
|
|
|
|
|
args: struct {
|
2023-10-13 16:08:08 +00:00
|
|
|
sym_name: []const u8,
|
2023-01-02 14:28:25 +00:00
|
|
|
args: []const mlir.Type,
|
|
|
|
|
arg_attrs: []const mlir.Attribute = &.{},
|
|
|
|
|
results: []const mlir.Type,
|
2023-03-21 10:50:39 +00:00
|
|
|
res_attrs: []const mlir.Attribute = &.{},
|
2023-01-02 14:28:25 +00:00
|
|
|
block: mlir.Block,
|
|
|
|
|
location: mlir.Location,
|
|
|
|
|
},
|
|
|
|
|
) mlir.Operation {
|
2025-07-28 13:54:28 +00:00
|
|
|
var attrs_tuple_buffer = stdx.BoundedArray(mlir.AttrTuple, 4){};
|
2024-08-26 14:19:00 +00:00
|
|
|
attrs_tuple_buffer.appendAssumeCapacity(.{ "sym_name", .string(ctx, args.sym_name) });
|
|
|
|
|
attrs_tuple_buffer.appendAssumeCapacity(.{ "function_type", .type_(.function(ctx, args.args, args.results)) });
|
2023-01-02 14:28:25 +00:00
|
|
|
if (args.arg_attrs.len > 0) {
|
2024-08-26 14:19:00 +00:00
|
|
|
attrs_tuple_buffer.appendAssumeCapacity(.{ "arg_attrs", .array(ctx, args.arg_attrs) });
|
2023-01-02 14:28:25 +00:00
|
|
|
}
|
2023-03-21 10:50:39 +00:00
|
|
|
|
|
|
|
|
if (args.res_attrs.len > 0) {
|
2024-08-26 14:19:00 +00:00
|
|
|
attrs_tuple_buffer.appendAssumeCapacity(.{ "res_attrs", .array(ctx, args.res_attrs) });
|
2023-03-21 10:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-02 14:28:25 +00:00
|
|
|
return mlir.Operation.make(ctx, "func.func", .{
|
|
|
|
|
.blocks = &.{args.block},
|
|
|
|
|
.attributes = attrs_tuple_buffer.constSlice(),
|
|
|
|
|
.location = args.location,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn call(ctx: mlir.Context, name: [:0]const u8, values: []const mlir.Value, results: []const mlir.Type, loc: mlir.Location) mlir.Operation {
|
|
|
|
|
return mlir.Operation.make(ctx, "func.call", .{
|
|
|
|
|
.variadic_operands = &.{values},
|
|
|
|
|
.results = results,
|
|
|
|
|
.verify = true,
|
2024-08-26 14:19:00 +00:00
|
|
|
.attributes = &.{.{ "callee", .symbol(ctx, name) }},
|
2023-01-02 14:28:25 +00:00
|
|
|
.location = loc,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn return_(ctx: mlir.Context, values: []const mlir.Value, loc: mlir.Location) mlir.Operation {
|
|
|
|
|
return mlir.Operation.make(ctx, "func.return", .{
|
|
|
|
|
.operands = values,
|
|
|
|
|
.verify = false,
|
|
|
|
|
.location = loc,
|
|
|
|
|
});
|
|
|
|
|
}
|