lib/choir/src/passes/pass/model.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

  1 const std = @import("std");
  2 const ir = @import("../../core/root.zig");
  3 
  4 pub const PassMutationScope = enum {
  5     read_only,
  6     isolated,
  7     whole_module,
  8 };
  9 
 10 pub const PassStateConcurrency = enum {
 11     exclusive,
 12     shared,
 13 };
 14 
 15 pub const PassRerunPolicy = enum {
 16     always,
 17     skip_if_unchanged,
 18 };
 19 
 20 pub const DependentDialects = []const []const u8;
 21 
 22 pub fn dialectDependencies(comptime names: DependentDialects) DependentDialects {
 23     comptime {
 24         for (names, 0..) |name, index| {
 25             if (name.len == 0) @compileError("dependent dialect name cannot be empty");
 26             for (names[0..index]) |prior| {
 27                 if (std.mem.eql(u8, name, prior)) @compileError("duplicate dependent dialect name");
 28             }
 29         }
 30     }
 31     return names;
 32 }
 33 
 34 pub const PassManagerRunOptions = ir.ThreadingOptions;
 35 
 36 pub const PassManagerFixedPointResult = struct {
 37     result: PassResult = .success,
 38     iterations: usize = 0,
 39     changed: bool = false,
 40 };
 41 
 42 pub const AnalysisId = u64;
 43 
 44 pub fn analysisId(comptime name: []const u8) AnalysisId {
 45     return ir.interfaceId(name);
 46 }
 47 
 48 pub const PassManagerStats = struct {
 49     pass_runs: u64 = 0,
 50     passes_skipped: u64 = 0,
 51     pass_failures: u64 = 0,
 52     verifier_failures: u64 = 0,
 53     passes_modified: u64 = 0,
 54     analysis_hits: u64 = 0,
 55     analysis_misses: u64 = 0,
 56     analyses_invalidated: u64 = 0,
 57 
 58     pub fn reset(self: *PassManagerStats) void {
 59         self.* = .{};
 60     }
 61 };
 62 
 63 pub const PassVerifierFailure = struct {
 64     pass_name: []const u8,
 65     target_op_name: []const u8,
 66     err: anyerror,
 67 };
 68 
 69 pub const PassFailureKind = enum {
 70     pass,
 71     verifier,
 72     target,
 73     exhausted,
 74 };
 75 
 76 pub const PassFailureReproducer = struct {
 77     pipeline: []const u8,
 78     ir: []const u8,
 79     max_threads: usize,
 80     worker_count: usize,
 81     verifier_enabled: bool,
 82     failure_kind: ?PassFailureKind = null,
 83     pass_name: ?[]const u8 = null,
 84     target_op_name: ?[]const u8 = null,
 85     target_symbol_name: ?[]const u8 = null,
 86     verifier_error: ?anyerror = null,
 87     verifier_error_name: ?[]const u8 = null,
 88 
 89     pub fn deinit(self: *PassFailureReproducer, allocator: std.mem.Allocator) void {
 90         allocator.free(self.pipeline);
 91         allocator.free(self.ir);
 92         if (self.pass_name) |name| allocator.free(name);
 93         if (self.target_op_name) |name| allocator.free(name);
 94         if (self.target_symbol_name) |name| allocator.free(name);
 95         if (self.verifier_error_name) |name| allocator.free(name);
 96         self.* = undefined;
 97     }
 98 };
 99 
100 pub const PassResult = enum {
101     success,
102     failure,
103 };