zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit b1873f20744dfa9b5402b936ccc0858d7ef01529 (tree)
parent fcf77e06eab5e8b63a9778500c3f08a9ba8631f4
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sun,  3 Jul 2022 11:37:31 -0700

LLVM: update inline asm to LLVM14 semantics

This is the equivalent of d19290e603833a197bc8bfc8315561ec77291225
applied to stage2 instead of stage1.

Diffstat:
Msrc/codegen/llvm.zig | 16+++++++++++++++-
Msrc/codegen/llvm/bindings.zig | 3+++
2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig @@ -5433,6 +5433,7 @@ pub const FuncGen = struct { const llvm_params_len = inputs.len + outputs.len - return_count; const llvm_param_types = try arena.alloc(*const llvm.Type, llvm_params_len); const llvm_param_values = try arena.alloc(*const llvm.Value, llvm_params_len); + const llvm_param_attrs = try arena.alloc(bool, llvm_params_len); const target = self.dg.module.getTarget(); var llvm_param_i: usize = 0; @@ -5461,6 +5462,7 @@ pub const FuncGen = struct { const output_inst = try self.resolveInst(output); llvm_param_values[llvm_param_i] = output_inst; llvm_param_types[llvm_param_i] = output_inst.typeOf(); + llvm_param_attrs[llvm_param_i] = true; llvm_param_i += 1; } @@ -5530,6 +5532,11 @@ pub const FuncGen = struct { if (!std.mem.eql(u8, name, "_")) { name_map.putAssumeCapacityNoClobber(name, {}); } + + // In the case of indirect inputs, LLVM requires the callsite to have + // an elementtype(<ty>) attribute. + llvm_param_attrs[llvm_param_i] = constraint[0] == '*'; + llvm_param_i += 1; total_i += 1; } @@ -5622,7 +5629,7 @@ pub const FuncGen = struct { .ATT, .False, ); - return self.builder.buildCall( + const call = self.builder.buildCall( asm_fn, llvm_param_values.ptr, @intCast(c_uint, llvm_param_values.len), @@ -5630,6 +5637,13 @@ pub const FuncGen = struct { .Auto, "", ); + for (llvm_param_attrs) |need_elem_ty, i| { + if (need_elem_ty) { + const elem_ty = llvm_param_types[i].getElementType(); + llvm.setCallElemTypeAttr(call, i, elem_ty); + } + } + return call; } fn airIsNonNull( diff --git a/src/codegen/llvm/bindings.zig b/src/codegen/llvm/bindings.zig @@ -1320,6 +1320,9 @@ extern fn ZigLLVMWriteImportLibrary( kill_at: bool, ) bool; +pub const setCallElemTypeAttr = ZigLLVMSetCallElemTypeAttr; +extern fn ZigLLVMSetCallElemTypeAttr(Call: *const Value, arg_index: usize, return_type: *const Type) void; + pub const Linkage = enum(c_uint) { External, AvailableExternally,