@@ -9,16 +9,19 @@ const builtin = @import("builtin");
9
9
const assert = std .debug .assert ;
10
10
11
11
const Air = @This ();
12
- const Value = @import ("Value.zig" );
13
- const Type = @import ("Type.zig" );
14
12
const InternPool = @import ("InternPool.zig" );
13
+ const Type = @import ("Type.zig" );
14
+ const Value = @import ("Value.zig" );
15
15
const Zcu = @import ("Zcu.zig" );
16
16
const types_resolved = @import ("Air/types_resolved.zig" );
17
17
18
+ pub const Legalize = @import ("Air/Legalize.zig" );
19
+ pub const Liveness = @import ("Air/Liveness.zig" );
20
+
18
21
instructions : std .MultiArrayList (Inst ).Slice ,
19
22
/// The meaning of this data is determined by `Inst.Tag` value.
20
23
/// The first few indexes are reserved. See `ExtraIndex` for the values.
21
- extra : [] const u32 ,
24
+ extra : std . ArrayListUnmanaged ( u32 ) ,
22
25
23
26
pub const ExtraIndex = enum (u32 ) {
24
27
/// Payload index of the main `Block` in the `extra` array.
@@ -244,22 +247,27 @@ pub const Inst = struct {
244
247
/// Uses the `bin_op` field.
245
248
bit_or ,
246
249
/// Shift right. `>>`
250
+ /// The rhs type may be a scalar version of the lhs type.
247
251
/// Uses the `bin_op` field.
248
252
shr ,
249
253
/// Shift right. The shift produces a poison value if it shifts out any non-zero bits.
254
+ /// The rhs type may be a scalar version of the lhs type.
250
255
/// Uses the `bin_op` field.
251
256
shr_exact ,
252
257
/// Shift left. `<<`
258
+ /// The rhs type may be a scalar version of the lhs type.
253
259
/// Uses the `bin_op` field.
254
260
shl ,
255
261
/// Shift left; For unsigned integers, the shift produces a poison value if it shifts
256
262
/// out any non-zero bits. For signed integers, the shift produces a poison value if
257
263
/// it shifts out any bits that disagree with the resultant sign bit.
264
+ /// The rhs type may be a scalar version of the lhs type.
258
265
/// Uses the `bin_op` field.
259
266
shl_exact ,
260
267
/// Saturating integer shift left. `<<|`. The result is the same type as the `lhs`.
261
268
/// The `rhs` must have the same vector shape as the `lhs`, but with any unsigned
262
269
/// integer as the scalar type.
270
+ /// The rhs type may be a scalar version of the lhs type.
263
271
/// Uses the `bin_op` field.
264
272
shl_sat ,
265
273
/// Bitwise XOR. `^`
@@ -1378,9 +1386,9 @@ pub const UnionInit = struct {
1378
1386
};
1379
1387
1380
1388
pub fn getMainBody (air : Air ) []const Air.Inst.Index {
1381
- const body_index = air .extra [@intFromEnum (ExtraIndex .main_block )];
1389
+ const body_index = air .extra . items [@intFromEnum (ExtraIndex .main_block )];
1382
1390
const extra = air .extraData (Block , body_index );
1383
- return @ptrCast (air .extra [extra .end .. ][0.. extra .data .body_len ]);
1391
+ return @ptrCast (air .extra . items [extra .end .. ][0.. extra .data .body_len ]);
1384
1392
}
1385
1393
1386
1394
pub fn typeOf (air : * const Air , inst : Air.Inst.Ref , ip : * const InternPool ) Type {
@@ -1656,9 +1664,9 @@ pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end
1656
1664
var result : T = undefined ;
1657
1665
inline for (fields ) | field | {
1658
1666
@field (result , field .name ) = switch (field .type ) {
1659
- u32 = > air .extra [i ],
1660
- InternPool .Index , Inst .Ref = > @enumFromInt (air .extra [i ]),
1661
- i32 , CondBr .BranchHints = > @bitCast (air .extra [i ]),
1667
+ u32 = > air .extra . items [i ],
1668
+ InternPool .Index , Inst .Ref = > @enumFromInt (air .extra . items [i ]),
1669
+ i32 , CondBr .BranchHints = > @bitCast (air .extra . items [i ]),
1662
1670
else = > @compileError ("bad field type: " ++ @typeName (field .type )),
1663
1671
};
1664
1672
i += 1 ;
@@ -1671,7 +1679,7 @@ pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end
1671
1679
1672
1680
pub fn deinit (air : * Air , gpa : std.mem.Allocator ) void {
1673
1681
air .instructions .deinit (gpa );
1674
- gpa . free ( air .extra );
1682
+ air .extra . deinit ( gpa );
1675
1683
air .* = undefined ;
1676
1684
}
1677
1685
@@ -1700,7 +1708,7 @@ pub const NullTerminatedString = enum(u32) {
1700
1708
1701
1709
pub fn toSlice (nts : NullTerminatedString , air : Air ) [:0 ]const u8 {
1702
1710
if (nts == .none ) return "" ;
1703
- const bytes = std .mem .sliceAsBytes (air .extra [@intFromEnum (nts ).. ]);
1711
+ const bytes = std .mem .sliceAsBytes (air .extra . items [@intFromEnum (nts ).. ]);
1704
1712
return bytes [0.. std .mem .indexOfScalar (u8 , bytes , 0 ).? :0 ];
1705
1713
}
1706
1714
};
@@ -1943,7 +1951,7 @@ pub const UnwrappedSwitch = struct {
1943
1951
return us .getHintInner (us .cases_len );
1944
1952
}
1945
1953
fn getHintInner (us : UnwrappedSwitch , idx : u32 ) std.builtin.BranchHint {
1946
- const bag = us .air .extra [us .branch_hints_start .. ][idx / 10 ];
1954
+ const bag = us .air .extra . items [us .branch_hints_start .. ][idx / 10 ];
1947
1955
const bits : u3 = @truncate (bag >> @intCast (3 * (idx % 10 )));
1948
1956
return @enumFromInt (bits );
1949
1957
}
@@ -1971,13 +1979,13 @@ pub const UnwrappedSwitch = struct {
1971
1979
1972
1980
const extra = it .air .extraData (SwitchBr .Case , it .extra_index );
1973
1981
var extra_index = extra .end ;
1974
- const items : []const Inst.Ref = @ptrCast (it .air .extra [extra_index .. ][0.. extra .data .items_len ]);
1982
+ const items : []const Inst.Ref = @ptrCast (it .air .extra . items [extra_index .. ][0.. extra .data .items_len ]);
1975
1983
extra_index += items .len ;
1976
1984
// TODO: ptrcast from []const Inst.Ref to []const [2]Inst.Ref when supported
1977
- const ranges_ptr : [* ]const [2 ]Inst.Ref = @ptrCast (it .air .extra [extra_index .. ]);
1985
+ const ranges_ptr : [* ]const [2 ]Inst.Ref = @ptrCast (it .air .extra . items [extra_index .. ]);
1978
1986
const ranges : []const [2 ]Inst.Ref = ranges_ptr [0.. extra .data .ranges_len ];
1979
1987
extra_index += ranges .len * 2 ;
1980
- const body : []const Inst.Index = @ptrCast (it .air .extra [extra_index .. ][0.. extra .data .body_len ]);
1988
+ const body : []const Inst.Index = @ptrCast (it .air .extra . items [extra_index .. ][0.. extra .data .body_len ]);
1981
1989
extra_index += body .len ;
1982
1990
it .extra_index = @intCast (extra_index );
1983
1991
@@ -1992,7 +2000,7 @@ pub const UnwrappedSwitch = struct {
1992
2000
/// Returns the body of the "default" (`else`) case.
1993
2001
pub fn elseBody (it : * CaseIterator ) []const Inst.Index {
1994
2002
assert (it .next_case == it .cases_len );
1995
- return @ptrCast (it .air .extra [it .extra_index .. ][0.. it .else_body_len ]);
2003
+ return @ptrCast (it .air .extra . items [it .extra_index .. ][0.. it .else_body_len ]);
1996
2004
}
1997
2005
pub const Case = struct {
1998
2006
idx : u32 ,
@@ -2025,6 +2033,7 @@ pub fn unwrapSwitch(air: *const Air, switch_inst: Inst.Index) UnwrappedSwitch {
2025
2033
pub const typesFullyResolved = types_resolved .typesFullyResolved ;
2026
2034
pub const typeFullyResolved = types_resolved .checkType ;
2027
2035
pub const valFullyResolved = types_resolved .checkVal ;
2036
+ pub const legalize = Legalize .legalize ;
2028
2037
2029
2038
pub const CoveragePoint = enum (u1 ) {
2030
2039
/// Indicates the block is not a place of interest corresponding to
0 commit comments