Commit 6a07b7024a

Andrew Kelley <andrew@ziglang.org>
2023-08-12 01:57:48
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
1 parent 62a12e0
Changed files (2)
src
src/codegen/llvm/bindings.zig
@@ -238,13 +238,6 @@ pub const Value = opaque {
     pub const constAddrSpaceCast = LLVMConstAddrSpaceCast;
     extern fn LLVMConstAddrSpaceCast(ConstantVal: *Value, ToType: *Type) *Value;
 
-    pub const constSelect = LLVMConstSelect;
-    extern fn LLVMConstSelect(
-        ConstantCondition: *Value,
-        ConstantIfTrue: *Value,
-        ConstantIfFalse: *Value,
-    ) *Value;
-
     pub const constExtractElement = LLVMConstExtractElement;
     extern fn LLVMConstExtractElement(VectorConstant: *Value, IndexConstant: *Value) *Value;
 
@@ -336,8 +329,8 @@ pub const Type = opaque {
     pub const constReal = LLVMConstReal;
     extern fn LLVMConstReal(RealTy: *Type, N: f64) *Value;
 
-    pub const constArray = LLVMConstArray;
-    extern fn LLVMConstArray(ElementTy: *Type, ConstantVals: [*]const *Value, Length: c_uint) *Value;
+    pub const constArray2 = LLVMConstArray2;
+    extern fn LLVMConstArray2(ElementTy: *Type, ConstantVals: [*]const *Value, Length: u64) *Value;
 
     pub const constNamedStruct = LLVMConstNamedStruct;
     extern fn LLVMConstNamedStruct(
@@ -352,8 +345,8 @@ pub const Type = opaque {
     pub const getPoison = LLVMGetPoison;
     extern fn LLVMGetPoison(Ty: *Type) *Value;
 
-    pub const arrayType = LLVMArrayType;
-    extern fn LLVMArrayType(ElementType: *Type, ElementCount: c_uint) *Type;
+    pub const arrayType2 = LLVMArrayType2;
+    extern fn LLVMArrayType2(ElementType: *Type, ElementCount: u64) *Type;
 
     pub const vectorType = LLVMVectorType;
     extern fn LLVMVectorType(ElementType: *Type, ElementCount: c_uint) *Type;
src/codegen/llvm/Builder.zig
@@ -9224,20 +9224,6 @@ pub fn binValue(self: *Builder, tag: Constant.Tag, lhs: Constant, rhs: Constant)
     return (try self.binConst(tag, lhs, rhs)).toValue();
 }
 
-pub fn selectConst(
-    self: *Builder,
-    cond: Constant,
-    lhs: Constant,
-    rhs: Constant,
-) Allocator.Error!Constant {
-    try self.ensureUnusedConstantCapacity(1, Constant.Select, 0);
-    return self.selectConstAssumeCapacity(cond, lhs, rhs);
-}
-
-pub fn selectValue(self: *Builder, cond: Constant, lhs: Constant, rhs: Constant) Allocator.Error!Value {
-    return (try self.selectConst(cond, lhs, rhs)).toValue();
-}
-
 pub fn asmConst(
     self: *Builder,
     ty: Type,
@@ -10125,7 +10111,7 @@ fn arrayTypeAssumeCapacity(self: *Builder, len: u64, child: Type) Type {
                 .data = self.addTypeExtraAssumeCapacity(data),
             });
             if (self.useLibLlvm()) self.llvm.types.appendAssumeCapacity(
-                child.toLlvm(self).arrayType(@intCast(len)),
+                child.toLlvm(self).arrayType2(len),
             );
         }
         return @enumFromInt(gop.index);
@@ -10158,7 +10144,7 @@ fn arrayTypeAssumeCapacity(self: *Builder, len: u64, child: Type) Type {
                 .data = self.addTypeExtraAssumeCapacity(data),
             });
             if (self.useLibLlvm()) self.llvm.types.appendAssumeCapacity(
-                child.toLlvm(self).arrayType(@intCast(len)),
+                child.toLlvm(self).arrayType2(len),
             );
         }
         return @enumFromInt(gop.index);
@@ -10823,7 +10809,7 @@ fn arrayConstAssumeCapacity(
         for (llvm_vals, vals) |*llvm_val, val| llvm_val.* = val.toLlvm(self);
 
         self.llvm.constants.appendAssumeCapacity(
-            type_extra.child.toLlvm(self).constArray(llvm_vals.ptr, @intCast(llvm_vals.len)),
+            type_extra.child.toLlvm(self).constArray2(llvm_vals.ptr, llvm_vals.len),
         );
     }
     return result.constant;
@@ -11536,42 +11522,6 @@ fn binConstAssumeCapacity(
     return @enumFromInt(gop.index);
 }
 
-comptime {
-    _ = &selectValue;
-}
-
-fn selectConstAssumeCapacity(self: *Builder, cond: Constant, lhs: Constant, rhs: Constant) Constant {
-    const Adapter = struct {
-        builder: *const Builder,
-        pub fn hash(_: @This(), key: Constant.Select) u32 {
-            return @truncate(std.hash.Wyhash.hash(
-                std.hash.uint32(@intFromEnum(Constant.Tag.select)),
-                std.mem.asBytes(&key),
-            ));
-        }
-        pub fn eql(ctx: @This(), lhs_key: Constant.Select, _: void, rhs_index: usize) bool {
-            if (ctx.builder.constant_items.items(.tag)[rhs_index] != .select) return false;
-            const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
-            const rhs_extra = ctx.builder.constantExtraData(Constant.Select, rhs_data);
-            return std.meta.eql(lhs_key, rhs_extra);
-        }
-    };
-    const data = Constant.Select{ .cond = cond, .lhs = lhs, .rhs = rhs };
-    const gop = self.constant_map.getOrPutAssumeCapacityAdapted(data, Adapter{ .builder = self });
-    if (!gop.found_existing) {
-        gop.key_ptr.* = {};
-        gop.value_ptr.* = {};
-        self.constant_items.appendAssumeCapacity(.{
-            .tag = .select,
-            .data = self.addConstantExtraAssumeCapacity(data),
-        });
-        if (self.useLibLlvm()) self.llvm.constants.appendAssumeCapacity(
-            cond.toLlvm(self).constSelect(lhs.toLlvm(self), rhs.toLlvm(self)),
-        );
-    }
-    return @enumFromInt(gop.index);
-}
-
 fn asmConstAssumeCapacity(
     self: *Builder,
     ty: Type,