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)
92249224 return (try self.binConst(tag, lhs, rhs)).toValue();
92259225}
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
92419227pub fn asmConst(
92429228 self: *Builder,
92439229 ty: Type,
......@@ -10125,7 +10111,7 @@ fn arrayTypeAssumeCapacity(self: *Builder, len: u64, child: Type) Type {
1012510111 .data = self.addTypeExtraAssumeCapacity(data),
1012610112 });
1012710113 if (self.useLibLlvm()) self.llvm.types.appendAssumeCapacity(
10128 child.toLlvm(self).arrayType(@intCast(len)),
10114 child.toLlvm(self).arrayType2(len),
1012910115 );
1013010116 }
1013110117 return @enumFromInt(gop.index);
......@@ -10158,7 +10144,7 @@ fn arrayTypeAssumeCapacity(self: *Builder, len: u64, child: Type) Type {
1015810144 .data = self.addTypeExtraAssumeCapacity(data),
1015910145 });
1016010146 if (self.useLibLlvm()) self.llvm.types.appendAssumeCapacity(
10161 child.toLlvm(self).arrayType(@intCast(len)),
10147 child.toLlvm(self).arrayType2(len),
1016210148 );
1016310149 }
1016410150 return @enumFromInt(gop.index);
......@@ -10823,7 +10809,7 @@ fn arrayConstAssumeCapacity(
1082310809 for (llvm_vals, vals) |*llvm_val, val| llvm_val.* = val.toLlvm(self);
1082410810
1082510811 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),
1082710813 );
1082810814 }
1082910815 return result.constant;
......@@ -11536,42 +11522,6 @@ fn binConstAssumeCapacity(
1153611522 return @enumFromInt(gop.index);
1153711523}
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
1157511525fn asmConstAssumeCapacity(
1157611526 self: *Builder,
1157711527 ty: Type,
src/codegen/llvm/bindings.zig+4-11
......@@ -238,13 +238,6 @@ pub const Value = opaque {
238238 pub const constAddrSpaceCast = LLVMConstAddrSpaceCast;
239239 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
248241 pub const constExtractElement = LLVMConstExtractElement;
249242 extern fn LLVMConstExtractElement(VectorConstant: *Value, IndexConstant: *Value) *Value;
250243
......@@ -336,8 +329,8 @@ pub const Type = opaque {
336329 pub const constReal = LLVMConstReal;
337330 extern fn LLVMConstReal(RealTy: *Type, N: f64) *Value;
338331
339 pub const constArray = LLVMConstArray;
340 extern fn LLVMConstArray(ElementTy: *Type, ConstantVals: [*]const *Value, Length: c_uint) *Value;
332 pub const constArray2 = LLVMConstArray2;
333 extern fn LLVMConstArray2(ElementTy: *Type, ConstantVals: [*]const *Value, Length: u64) *Value;
341334
342335 pub const constNamedStruct = LLVMConstNamedStruct;
343336 extern fn LLVMConstNamedStruct(
......@@ -352,8 +345,8 @@ pub const Type = opaque {
352345 pub const getPoison = LLVMGetPoison;
353346 extern fn LLVMGetPoison(Ty: *Type) *Value;
354347
355 pub const arrayType = LLVMArrayType;
356 extern fn LLVMArrayType(ElementType: *Type, ElementCount: c_uint) *Type;
348 pub const arrayType2 = LLVMArrayType2;
349 extern fn LLVMArrayType2(ElementType: *Type, ElementCount: u64) *Type;
357350
358351 pub const vectorType = LLVMVectorType;
359352 extern fn LLVMVectorType(ElementType: *Type, ElementCount: c_uint) *Type;