diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-09-14 21:58:22 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-09-14 21:58:22 -0700 |
| commit | 0395b35cee8d4082cc40b0dcd0298f797f42309d (patch) | |
| tree | c4592f4e4cdb555836bb422d485b2c134e3f7547 /src/codegen.zig | |
| parent | 5d14590ed15ce23e7ef8032f8075dcfe76ba9dd8 (diff) | |
| download | zig-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/codegen.zig')
| -rw-r--r-- | src/codegen.zig | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index 1995d8baa7..511d4c2301 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -857,6 +857,8 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { .struct_field_ptr=> try self.airStructFieldPtr(inst), .struct_field_val=> try self.airStructFieldVal(inst), .array_to_slice => try self.airArrayToSlice(inst), + .cmpxchg_strong => try self.airCmpxchg(inst), + .cmpxchg_weak => try self.airCmpxchg(inst), .struct_field_ptr_index_0 => try self.airStructFieldPtrIndex(inst, 0), .struct_field_ptr_index_1 => try self.airStructFieldPtrIndex(inst, 1), @@ -4751,6 +4753,17 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { return self.finishAir(inst, result, .{ ty_op.operand, .none, .none }); } + fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void { + const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; + const extra = self.air.extraData(Air.Block, ty_pl.payload); + const result: MCValue = switch (arch) { + else => return self.fail("TODO implement airCmpxchg for {}", .{ + self.target.cpu.arch, + }), + }; + return self.finishAir(inst, result, .{ extra.ptr, extra.expected_value, extra.new_value }); + } + fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue { // First section of indexes correspond to a set number of constant values. const ref_int = @enumToInt(inst); |
