tiny.chant.lower.memory
Defined in lower.
API (8)
Actions
Public operations.
Types and contracts
Public types and contracts.
Source
Source: lib/chant/src/lower/memory.zig
zig
const std = @import("std");const choir = @import("choir");const ast = @import("../ast/root.zig");const context = @import("context.zig");const convert = @import("convert.zig");const emit = @import("emit.zig");const Error = @import("error.zig").Error;const MemrefDialect = choir.dialects.MemrefDialect;const Lowerer = context.Lowerer;pub const Place = struct { memref: *choir.Value, index: *choir.Value, c_type: *const ast.Type,};pub fn allocaScalar(lowerer: *Lowerer, c_type: *const ast.Type) Error!*choir.Value { const scalar = try convert.scalarType(lowerer, c_type); const memref_type = MemrefDialect.getMemrefType1D(lowerer.ctx, 1, scalar, .host) catch return error.OutOfMemory; const alloca = MemrefDialect.AllocaOp.createStatic(lowerer.ctx, lowerer.loc, memref_type) catch return error.OutOfMemory; try emit.append(lowerer, alloca.op); var mutable = alloca; return mutable.getResult();}pub fn allocaObject(lowerer: *Lowerer, c_type: *const ast.Type, requested_alignment: ?u64) Error!*choir.Value { const scalar = try scalarElement(c_type); const count = try staticElementCount(c_type); const scalar_type = try convert.scalarType(lowerer, scalar); const memref_type = MemrefDialect.getMemrefType1DWithAttrs(lowerer.ctx, count, scalar_type, .host, .{ .alignment = objectAlignment(c_type, requested_alignment), }) catch return error.OutOfMemory; const alloca = MemrefDialect.AllocaOp.createStatic(lowerer.ctx, lowerer.loc, memref_type) catch return error.OutOfMemory; try emit.append(lowerer, alloca.op); var mutable = alloca; return mutable.getResult();}fn objectAlignment(c_type: *const ast.Type, requested_alignment: ?u64) ?u64 { const requested = requested_alignment orelse return null; const natural = ast.types.byteAlign(c_type) orelse 1; return @max(natural, requested);}pub fn loadScalar(lowerer: *Lowerer, memref: *choir.Value, c_type: *const ast.Type) Error!*choir.Value { const zero = try emit.indexConstant(lowerer, 0); return loadElement(lowerer, .{ .memref = memref, .index = zero, .c_type = c_type });}pub fn loadElement(lowerer: *Lowerer, place: Place) Error!*choir.Value { const scalar = try convert.scalarType(lowerer, place.c_type); const load = MemrefDialect.LoadOp.create(lowerer.ctx, lowerer.loc, place.memref, place.index, scalar) catch return error.OutOfMemory; try emit.append(lowerer, load.op); var mutable = load; return mutable.getResult();}pub fn storeElement(lowerer: *Lowerer, place: Place, value: *choir.Value) Error!void { const store = MemrefDialect.StoreOp.create(lowerer.ctx, lowerer.loc, value, place.memref, place.index) catch return error.OutOfMemory; try emit.append(lowerer, store.op);}pub fn scalarElement(c_type: *const ast.Type) Error!*const ast.Type { var current = c_type; while (current.kind == .array) { current = current.child orelse return error.UnsupportedType; } if (!ast.types.isArithmetic(current)) return error.UnsupportedType; return current;}pub fn staticElementCount(c_type: *const ast.Type) Error!u64 { if (c_type.kind != .array) return 1; const len = c_type.array_len orelse return error.UnsupportedConstruct; const child = c_type.child orelse return error.UnsupportedType; const child_count = try staticElementCount(child); return std.math.mul(u64, len, child_count) catch return error.UnsupportedConstruct;}Source: lib/chant/src/lower/root.zig:8
zig
pub const memory = @import("memory.zig");Complete call list for lower.memory.allocaObject
7 direct calls.
tiny.chant.lower.convert.scalarType[function] atlib/chant/src/lower/convert.zig:36tiny.chant.lower.emit.append[function] atlib/chant/src/lower/emit.zig:9lib.chant.src.lower.memory.objectAlignment[function] — private source atlib/chant/src/lower/memory.zig:40in nearest public ownertiny.chant.lower.memorytiny.chant.lower.memory.scalarElement[function] atlib/chant/src/lower/memory.zig:64tiny.chant.lower.memory.staticElementCount[function] atlib/chant/src/lower/memory.zig:73tiny.choir.dialects.MemrefDialect.AllocaOp.createStatic[function] atlib/choir/src/dialects/memref.zig:317tiny.choir.dialects.MemrefDialect.getMemrefType1DWithAttrs[function] atlib/choir/src/dialects/memref.zig:1265
Audit
| Definitions | 9 |
|---|---|
| Public names | 9 |
| Members | 3 |
| Version | 26.7.0 |
| Revision | daab053ee433 |