authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-08-11 16:57:48-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-19 09:37:31-07:00
log6a07b7024a33211f158f0c332267050955896918
tree514e132a904937816f33eb56d4ab9c9123e32d83
parent62a12e06315ce4c2eaadfc33bf32eb4af9417ba8

LLVM: update backend to LLVM 17

* LLVMConstSelect is removed (see https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179) * a couple functions use uint64_t instead of int now which means we no longer need `@intCast`. release/17.x branch, commit 8f4dd44097c9ae25dd203d5ac87f3b48f854bba8

2 files changed, 7 insertions(+), 64 deletions(-)

src/codegen/llvm/Builder.zig+3-53
...@@ -9224,20 +9224,6 @@ pub fn binValue(self: *Builder, tag: Constant.Tag, lhs: Constant, rhs: Constant)...@@ -9224,20 +9224,6 @@ pub fn binValue(self: *Builder, tag: Constant.Tag, lhs: Constant, rhs: Constant)
9224 return (try self.binConst(tag, lhs, rhs)).toValue();9224 return (try self.binConst(tag, lhs, rhs)).toValue();
9225}9225}
92269226
9227pub fn selectConst(
9228 self: *Builder,
9229 cond: Constant,
9230 lhs: Constant,
9231 rhs: Constant,
9232) Allocator.Error!Constant {
9233 try self.ensureUnusedConstantCapacity(1, Constant.Select, 0);
9234 return self.selectConstAssumeCapacity(cond, lhs, rhs);
9235}
9236
9237pub fn selectValue(self: *Builder, cond: Constant, lhs: Constant, rhs: Constant) Allocator.Error!Value {
9238 return (try self.selectConst(cond, lhs, rhs)).toValue();
9239}
9240
9241pub fn asmConst(9227pub fn asmConst(
9242 self: *Builder,9228 self: *Builder,
9243 ty: Type,9229 ty: Type,
...@@ -10125,7 +10111,7 @@ fn arrayTypeAssumeCapacity(self: *Builder, len: u64, child: Type) Type {...@@ -10125,7 +10111,7 @@ fn arrayTypeAssumeCapacity(self: *Builder, len: u64, child: Type) Type {
10125 .data = self.addTypeExtraAssumeCapacity(data),10111 .data = self.addTypeExtraAssumeCapacity(data),
10126 });10112 });
10127 if (self.useLibLlvm()) self.llvm.types.appendAssumeCapacity(10113 if (self.useLibLlvm()) self.llvm.types.appendAssumeCapacity(
10128 child.toLlvm(self).arrayType(@intCast(len)),10114 child.toLlvm(self).arrayType2(len),
10129 );10115 );
10130 }10116 }
10131 return @enumFromInt(gop.index);10117 return @enumFromInt(gop.index);
...@@ -10158,7 +10144,7 @@ fn arrayTypeAssumeCapacity(self: *Builder, len: u64, child: Type) Type {...@@ -10158,7 +10144,7 @@ fn arrayTypeAssumeCapacity(self: *Builder, len: u64, child: Type) Type {
10158 .data = self.addTypeExtraAssumeCapacity(data),10144 .data = self.addTypeExtraAssumeCapacity(data),
10159 });10145 });
10160 if (self.useLibLlvm()) self.llvm.types.appendAssumeCapacity(10146 if (self.useLibLlvm()) self.llvm.types.appendAssumeCapacity(
10161 child.toLlvm(self).arrayType(@intCast(len)),10147 child.toLlvm(self).arrayType2(len),
10162 );10148 );
10163 }10149 }
10164 return @enumFromInt(gop.index);10150 return @enumFromInt(gop.index);
...@@ -10823,7 +10809,7 @@ fn arrayConstAssumeCapacity(...@@ -10823,7 +10809,7 @@ fn arrayConstAssumeCapacity(
10823 for (llvm_vals, vals) |*llvm_val, val| llvm_val.* = val.toLlvm(self);10809 for (llvm_vals, vals) |*llvm_val, val| llvm_val.* = val.toLlvm(self);
1082410810
10825 self.llvm.constants.appendAssumeCapacity(10811 self.llvm.constants.appendAssumeCapacity(
10826 type_extra.child.toLlvm(self).constArray(llvm_vals.ptr, @intCast(llvm_vals.len)),10812 type_extra.child.toLlvm(self).constArray2(llvm_vals.ptr, llvm_vals.len),
10827 );10813 );
10828 }10814 }
10829 return result.constant;10815 return result.constant;
...@@ -11536,42 +11522,6 @@ fn binConstAssumeCapacity(...@@ -11536,42 +11522,6 @@ fn binConstAssumeCapacity(
11536 return @enumFromInt(gop.index);11522 return @enumFromInt(gop.index);
11537}11523}
1153811524
11539comptime {
11540 _ = &selectValue;
11541}
11542
11543fn selectConstAssumeCapacity(self: *Builder, cond: Constant, lhs: Constant, rhs: Constant) Constant {
11544 const Adapter = struct {
11545 builder: *const Builder,
11546 pub fn hash(_: @This(), key: Constant.Select) u32 {
11547 return @truncate(std.hash.Wyhash.hash(
11548 std.hash.uint32(@intFromEnum(Constant.Tag.select)),
11549 std.mem.asBytes(&key),
11550 ));
11551 }
11552 pub fn eql(ctx: @This(), lhs_key: Constant.Select, _: void, rhs_index: usize) bool {
11553 if (ctx.builder.constant_items.items(.tag)[rhs_index] != .select) return false;
11554 const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
11555 const rhs_extra = ctx.builder.constantExtraData(Constant.Select, rhs_data);
11556 return std.meta.eql(lhs_key, rhs_extra);
11557 }
11558 };
11559 const data = Constant.Select{ .cond = cond, .lhs = lhs, .rhs = rhs };
11560 const gop = self.constant_map.getOrPutAssumeCapacityAdapted(data, Adapter{ .builder = self });
11561 if (!gop.found_existing) {
11562 gop.key_ptr.* = {};
11563 gop.value_ptr.* = {};
11564 self.constant_items.appendAssumeCapacity(.{
11565 .tag = .select,
11566 .data = self.addConstantExtraAssumeCapacity(data),
11567 });
11568 if (self.useLibLlvm()) self.llvm.constants.appendAssumeCapacity(
11569 cond.toLlvm(self).constSelect(lhs.toLlvm(self), rhs.toLlvm(self)),
11570 );
11571 }
11572 return @enumFromInt(gop.index);
11573}
11574
11575fn asmConstAssumeCapacity(11525fn asmConstAssumeCapacity(
11576 self: *Builder,11526 self: *Builder,
11577 ty: Type,11527 ty: Type,
src/codegen/llvm/bindings.zig+4-11
...@@ -238,13 +238,6 @@ pub const Value = opaque {...@@ -238,13 +238,6 @@ pub const Value = opaque {
238 pub const constAddrSpaceCast = LLVMConstAddrSpaceCast;238 pub const constAddrSpaceCast = LLVMConstAddrSpaceCast;
239 extern fn LLVMConstAddrSpaceCast(ConstantVal: *Value, ToType: *Type) *Value;239 extern fn LLVMConstAddrSpaceCast(ConstantVal: *Value, ToType: *Type) *Value;
240240
241 pub const constSelect = LLVMConstSelect;
242 extern fn LLVMConstSelect(
243 ConstantCondition: *Value,
244 ConstantIfTrue: *Value,
245 ConstantIfFalse: *Value,
246 ) *Value;
247
248 pub const constExtractElement = LLVMConstExtractElement;241 pub const constExtractElement = LLVMConstExtractElement;
249 extern fn LLVMConstExtractElement(VectorConstant: *Value, IndexConstant: *Value) *Value;242 extern fn LLVMConstExtractElement(VectorConstant: *Value, IndexConstant: *Value) *Value;
250243
...@@ -336,8 +329,8 @@ pub const Type = opaque {...@@ -336,8 +329,8 @@ pub const Type = opaque {
336 pub const constReal = LLVMConstReal;329 pub const constReal = LLVMConstReal;
337 extern fn LLVMConstReal(RealTy: *Type, N: f64) *Value;330 extern fn LLVMConstReal(RealTy: *Type, N: f64) *Value;
338331
339 pub const constArray = LLVMConstArray;332 pub const constArray2 = LLVMConstArray2;
340 extern fn LLVMConstArray(ElementTy: *Type, ConstantVals: [*]const *Value, Length: c_uint) *Value;333 extern fn LLVMConstArray2(ElementTy: *Type, ConstantVals: [*]const *Value, Length: u64) *Value;
341334
342 pub const constNamedStruct = LLVMConstNamedStruct;335 pub const constNamedStruct = LLVMConstNamedStruct;
343 extern fn LLVMConstNamedStruct(336 extern fn LLVMConstNamedStruct(
...@@ -352,8 +345,8 @@ pub const Type = opaque {...@@ -352,8 +345,8 @@ pub const Type = opaque {
352 pub const getPoison = LLVMGetPoison;345 pub const getPoison = LLVMGetPoison;
353 extern fn LLVMGetPoison(Ty: *Type) *Value;346 extern fn LLVMGetPoison(Ty: *Type) *Value;
354347
355 pub const arrayType = LLVMArrayType;348 pub const arrayType2 = LLVMArrayType2;
356 extern fn LLVMArrayType(ElementType: *Type, ElementCount: c_uint) *Type;349 extern fn LLVMArrayType2(ElementType: *Type, ElementCount: u64) *Type;
357350
358 pub const vectorType = LLVMVectorType;351 pub const vectorType = LLVMVectorType;
359 extern fn LLVMVectorType(ElementType: *Type, ElementCount: c_uint) *Type;352 extern fn LLVMVectorType(ElementType: *Type, ElementCount: c_uint) *Type;