aboutsummaryrefslogtreecommitdiff
path: root/src/Air.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-09-14 21:58:22 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-09-14 21:58:22 -0700
commit0395b35cee8d4082cc40b0dcd0298f797f42309d (patch)
treec4592f4e4cdb555836bb422d485b2c134e3f7547 /src/Air.zig
parent5d14590ed15ce23e7ef8032f8075dcfe76ba9dd8 (diff)
downloadzig-0395b35cee8d4082cc40b0dcd0298f797f42309d.tar.gz
zig-0395b35cee8d4082cc40b0dcd0298f797f42309d.zip
stage2: implement cmpxchg and improve comptime eval
* Implement Sema for `@cmpxchgWeak` and `@cmpxchgStrong`. Both runtime and comptime codepaths are implement. * Implement Codegen for LLVM backend and C backend. * Add LazySrcLoc.node_offset_builtin_call_argX 3...5 * Sema: rework comptime control flow. - `error.ComptimeReturn` is used to signal that a comptime function call has returned a result (stored in the Inlining struct). `analyzeCall` notices this and handles the result. - The ZIR instructions `break_inline`, `block_inline`, `condbr_inline` are now redundant and can be deleted. `break`, `block`, and `condbr` function equivalently inside a comptime scope. - The ZIR instructions `loop` and `repeat` also are modified to directly perform comptime control flow inside a comptime scope, skipping an unnecessary mechanism for analysis of runtime code. This makes Zig perform closer to an interpreter when evaluating comptime code. * Sema: zirRetErrValue looks at Sema.ret_fn_ty rather than sema.func for adding to the inferred error set. This fixes a bug for inlined/comptime function calls. * Implement ZIR printing for cmpxchg. * stage1: make cmpxchg respect --single-threaded - Our LLVM C++ API wrapper failed to expose this boolean flag before. * Fix AIR printing for struct fields showing incorrect liveness data.
Diffstat (limited to 'src/Air.zig')
-rw-r--r--src/Air.zig23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Air.zig b/src/Air.zig
index bc939f6b04..29deb9a523 100644
--- a/src/Air.zig
+++ b/src/Air.zig
@@ -309,6 +309,10 @@ pub const Inst = struct {
/// Given a pointer to an array, return a slice.
/// Uses the `ty_op` field.
array_to_slice,
+ /// Uses the `ty_pl` field with payload `Cmpxchg`.
+ cmpxchg_weak,
+ /// Uses the `ty_pl` field with payload `Cmpxchg`.
+ cmpxchg_strong,
pub fn fromCmpOp(op: std.math.CompareOperator) Tag {
return switch (op) {
@@ -443,6 +447,23 @@ pub const Asm = struct {
zir_index: u32,
};
+pub const Cmpxchg = struct {
+ ptr: Inst.Ref,
+ expected_value: Inst.Ref,
+ new_value: Inst.Ref,
+ /// 0b00000000000000000000000000000XXX - success_order
+ /// 0b00000000000000000000000000XXX000 - failure_order
+ flags: u32,
+
+ pub fn successOrder(self: Cmpxchg) std.builtin.AtomicOrder {
+ return @intToEnum(std.builtin.AtomicOrder, @truncate(u3, self.flags));
+ }
+
+ pub fn failureOrder(self: Cmpxchg) std.builtin.AtomicOrder {
+ return @intToEnum(std.builtin.AtomicOrder, @truncate(u3, self.flags >> 3));
+ }
+};
+
pub fn getMainBody(air: Air) []const Air.Inst.Index {
const body_index = air.extra[@enumToInt(ExtraIndex.main_block)];
const extra = air.extraData(Block, body_index);
@@ -507,6 +528,8 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
.struct_field_ptr,
.struct_field_val,
.ptr_elem_ptr,
+ .cmpxchg_weak,
+ .cmpxchg_strong,
=> return air.getRefType(datas[inst].ty_pl.ty),
.not,