Skip to documentation
SLOP

tiny.choir.Region

Reference tiny.choir Region

Defined in tiny.choir.

API (28)

Actions

Public operations.

Types and contracts

Public types and contracts.

Fields and members

Public fields and members.

No direct callersNo direct callstiny.choirRegion
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/choir/src/core/region.zig:6

zig
pub const Region = struct {    allocator: std.mem.Allocator,    blocks: BlockList,    parent: ?*anyopaque,    pub const BlockList = struct {        head: ?*Block,        tail: ?*Block,        size: usize,        pub fn init() BlockList {            return .{                .head = null,                .tail = null,                .size = 0,            };        }        pub fn isEmpty(self: BlockList) bool {            return self.head == null;        }        pub fn front(self: BlockList) ?*Block {            return self.head;        }        pub fn back(self: BlockList) ?*Block {            return self.tail;        }    };    pub const BlockIterator = struct {        current: ?*Block,        pub fn next(self: *BlockIterator) ?*Block {            const block = self.current;            if (self.current) |b| {                self.current = b.next;            }            return block;        }    };    pub fn init(allocator: std.mem.Allocator) Region {        return .{            .allocator = allocator,            .blocks = BlockList.init(),            .parent = null,        };    }    pub fn deinit(self: *Region) void {        var current = self.blocks.head;        while (current) |block| {            const next = block.next;            block.deinit();            self.allocator.destroy(block);            current = next;        }    }    pub fn takeBody(self: *Region, source: *Region) !void {        if (self == source) return;        if (!source.empty() and !sameAllocator(self.allocator, source.allocator)) {            return error.RegionAllocatorMismatch;        }        self.deinit();        self.blocks = source.blocks;        source.blocks = BlockList.init();        var current = self.blocks.head;        while (current) |block| {            block.parent = self;            current = block.next;        }    }    pub fn dropAllReferences(self: *Region) void {        var blocks = self.getBlocks();        while (blocks.next()) |block| {            block.dropAllReferences();        }    }    pub fn hasNoDefinedValueUses(self: *Region) bool {        var blocks = self.getBlocks();        while (blocks.next()) |block| {            if (!block.hasNoDefinedValueUses()) return false;        }        return true;    }    pub fn dropAllDefinedValueUses(self: *Region) void {        var blocks = self.getBlocks();        while (blocks.next()) |block| {            block.dropAllDefinedValueUses();        }    }    pub fn walkOperations(        self: *Region,        options: @import("operation/root.zig").Operation.WalkOptions,        context: anytype,        callback: anytype,    ) anyerror!@import("operation/root.zig").Operation.WalkResult {        var blocks = self.getBlocks();        while (blocks.next()) |block| {            const result = try block.walkOperations(options, context, callback);            if (result.wasInterrupted()) return .interrupt;        }        return .advance;    }    pub fn cloneInto(self: *Region, dest: *Region, mapping: *Mapping) anyerror!void {        if (self == dest) return error.RegionCloneIntoSelf;        var source_block = self.blocks.head;        while (source_block) |block| : (source_block = block.next) {            const cloned_block = try dest.addBlock();            try mapping.mapBlock(block, cloned_block);            try cloned_block.arguments.ensureTotalCapacity(cloned_block.allocator, block.arguments.items.len);            for (block.arguments.items, 0..) |argument, index| {                const cloned_argument = try cloned_block.addArgument(                    argument.type,                    block.getArgumentLocation(index).?,                );                try mapping.mapValue(argument, cloned_argument);            }        }        source_block = self.blocks.head;        while (source_block) |block| : (source_block = block.next) {            const cloned_block = mapping.lookupBlock(block).?;            var ops = block.getOperations();            while (ops.next()) |op| {                const cloned_op = try op.cloneWithoutRegionsMapped(mapping, .{ .clone_operands = false });                try cloned_block.addOperation(cloned_op);            }        }        source_block = self.blocks.head;        while (source_block) |block| : (source_block = block.next) {            const cloned_block = mapping.lookupBlock(block).?;            var source_ops = block.getOperations();            var cloned_ops = cloned_block.getOperations();            while (source_ops.next()) |op| {                const cloned_op = cloned_ops.next().?;                try remapOperationBody(op, cloned_op, mapping);            }        }    }    pub fn empty(self: Region) bool {        return self.blocks.isEmpty();    }    pub fn hasOneBlock(self: Region) bool {        return self.blocks.size == 1;    }    pub fn getEntryBlock(self: Region) ?*Block {        return self.blocks.front();    }    pub fn addBlock(self: *Region) !*Block {        const block = try self.allocator.create(Block);        block.* = Block.init(self.allocator);        block.parent = self;        block.id = @intCast(self.blocks.size);        block.prev = self.blocks.tail;        block.next = null;        if (self.blocks.tail) |tail| {            tail.next = block;        } else {            self.blocks.head = block;        }        self.blocks.tail = block;        self.blocks.size += 1;        return block;    }    pub fn pushFront(self: *Region, block: *Block) void {        block.parent = self;        block.prev = null;        block.next = self.blocks.head;        if (self.blocks.head) |head| {            head.prev = block;        } else {            self.blocks.tail = block;        }        self.blocks.head = block;        self.blocks.size += 1;    }    pub fn pushBack(self: *Region, block: *Block) void {        block.parent = self;        block.prev = self.blocks.tail;        block.next = null;        if (self.blocks.tail) |tail| {            tail.next = block;        } else {            self.blocks.head = block;        }        self.blocks.tail = block;        self.blocks.size += 1;    }    pub fn eraseBlock(self: *Region, block: *Block) bool {        if (block.parent != @as(*anyopaque, @ptrCast(self))) return false;        if (!block.hasNoPredecessors()) return false;        var op_node = block.operations.tail;        while (op_node) |node| {            const op: *@import("operation/root.zig").Operation = @ptrCast(@alignCast(node));            op_node = op.prev_op;            op.erase();        }        std.debug.assert(block.hasNoDefinedValueUses());        const prev = block.prev;        const next = block.next;        if (prev) |prev_block| {            prev_block.next = next;        } else {            self.blocks.head = next;        }        if (next) |next_block| {            next_block.prev = prev;        } else {            self.blocks.tail = prev;        }        block.parent = null;        block.prev = null;        block.next = null;        self.blocks.size -= 1;        block.deinit();        self.allocator.destroy(block);        return true;    }    pub fn getParentOperation(self: *const Region) ?*@import("operation/root.zig").Operation {        const parent = self.parent orelse return null;        return @ptrCast(@alignCast(parent));    }    pub fn getBlocks(self: *Region) BlockIterator {        return BlockIterator{ .current = self.blocks.head };    }    pub fn format(self: Region, writer: *std.Io.Writer) std.Io.Writer.Error!void {        try writer.writeAll("{\n");        var current = self.blocks.head;        while (current) |block| {            try writer.print("  {f}\n", .{block.*});            current = block.next;        }        try writer.writeAll("}");    }    fn sameAllocator(a: std.mem.Allocator, b: std.mem.Allocator) bool {        return a.ptr == b.ptr and a.vtable == b.vtable;    }};

Source: lib/choir/src/root.zig:45

zig
pub const Region = ir.Region;
Called byCallsNo direct callsRegiongetEntryBlockRegion.BlockListfront
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsRegioninitRegiontakeBodyRegion.BlockListinit
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsRegionemptyRegion.BlockListisEmpty
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstest sourcelib.choir.src.core.regiontest: region takeBody rejects non-emp...test sourcelib.choir.src.core.regiontest: region takeBody transfers block...test sourcelib.choir.src.core.verifytest: verify region size consistencyBlockinitRegionaddBlock
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallsprivate sourcelib.choir.src.core.operation.lifecycleMethodsprivate sourcelib.choir.src.core.regionremapOperationBodyRegioncloneInto
Static calls · unresolved targets: 0 · external targets: 14.
Called byCallsNo direct callsprivate sourcelib.choir.src.core.operation.lifecycleMethodsprivate sourcelib.choir.src.core.parse.ParserparseStructureRegiontakeBodytest sourcelib.choir.src.core.regiontest: region takeBody rejects non-emp...test sourcelib.choir.src.core.regiontest: region takeBody transfers block...+3 moreRegiondeinit
Static calls · unresolved targets: 0 · external targets: 2.
Called byCallsprivate sourcelib.choir.src.core.operation.lifecycleMethodsRegiongetBlocksRegiondropAllDefinedValueUses
Static calls · unresolved targets: 0 · external targets: 2.
Called byCallsprivate sourcelib.choir.src.core.operation.lifecycleMethodsRegiongetBlocksRegiondropAllReferences
Static calls · unresolved targets: 0 · external targets: 2.
Called byCallstest sourcelib.choir.src.core.regiontest: region takeBody rejects non-emp...test sourcelib.choir.src.core.regiontest: region takeBody transfers block...Region.BlockListisEmptyRegionempty
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callersOperationeraseRegioneraseBlock
Static calls · unresolved targets: 0 · external targets: 4.
Called byCallsNo direct callsRegiondropAllDefinedValueUsesRegiondropAllReferencesRegionhasNoDefinedValueUsesRegionwalkOperationsRegiongetBlocks
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callersRegion.BlockListfrontRegiongetEntryBlock
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsprivate sourcelib.choir.src.core.operation.lifecycleMethodsRegiongetBlocksRegionhasNoDefinedValueUses
Static calls · unresolved targets: 0 · external targets: 2.
Called byCallsprivate sourcelib.choir.src.core.operation.lifecycleMethodsprivate sourcelib.choir.src.core.parse.ParserparseStructuretest sourcelib.choir.src.core.regiontest: region takeBody rejects non-emp...test sourcelib.choir.src.core.regiontest: region takeBody transfers block...test sourcelib.choir.src.core.verifytest: verify empty regiontest sourcelib.choir.src.core.verifytest: verify region size consistencyRegion.BlockListinitRegioninit
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallstest sourcelib.choir.src.core.regiontest: region takeBody rejects non-emp...test sourcelib.choir.src.core.regiontest: region takeBody transfers block...Region.BlockListinitRegiondeinitprivate sourcelib.choir.src.core.region.RegionsameAllocatorRegiontakeBody
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallsNo direct callersRegiongetBlocksRegionwalkOperations
Static calls · unresolved targets: 0 · external targets: 3.

Also reachable as

backends.wasm.emission.module_encoding.common.ir.Region, ir.Region.

Complete caller list for Region.deinit

8 direct callers.

Audit

Definitions26
Public names78
Members7
Version26.7.0
Revisiondaab053ee433