authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-07 15:49:25-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-08 21:32:50-04:00
loga66cd54f94cf675a67f6de594e3d59e7ca14b92f
tree74a504e82a2a2045a89aea0dcf22d8ed83044710
parenta0cb03ed99d0e157389d8afad4ab4f9c8e8ea2db

llvm: cleanup even more unused LLVM API bindings


3 files changed, 69 insertions(+), 94 deletions(-)

src/codegen/llvm.zig+2-4
...@@ -9775,10 +9775,8 @@ pub const FuncGen = struct {...@@ -9775,10 +9775,8 @@ pub const FuncGen = struct {
9775 else9775 else
9776 try self.wip.cast(.bitcast, non_int_val, small_int_ty, "");9776 try self.wip.cast(.bitcast, non_int_val, small_int_ty, "");
9777 const shift_rhs = try o.builder.intValue(int_ty, running_bits);9777 const shift_rhs = try o.builder.intValue(int_ty, running_bits);
9778 // If the field is as large as the entire packed struct, this9778 const extended_int_val =
9779 // zext would go from, e.g. i16 to i16. This is legal with9779 try self.wip.conv(.unsigned, small_int_val, int_ty, "");
9780 // constZExtOrBitCast but not legal with constZExt.
9781 const extended_int_val = try self.wip.conv(.unsigned, small_int_val, int_ty, "");
9782 const shifted = try self.wip.bin(.shl, extended_int_val, shift_rhs, "");9780 const shifted = try self.wip.bin(.shl, extended_int_val, shift_rhs, "");
9783 running_int = try self.wip.bin(.@"or", running_int, shifted, "");9781 running_int = try self.wip.bin(.@"or", running_int, shifted, "");
9784 running_bits += ty_bit_size;9782 running_bits += ty_bit_size;
src/codegen/llvm/Builder.zig+67
...@@ -6894,6 +6894,7 @@ pub const Constant = enum(u32) {...@@ -6894,6 +6894,7 @@ pub const Constant = enum(u32) {
6894 @"and",6894 @"and",
6895 @"or",6895 @"or",
6896 xor,6896 xor,
6897 select,
6897 @"asm",6898 @"asm",
6898 @"asm sideeffect",6899 @"asm sideeffect",
6899 @"asm alignstack",6900 @"asm alignstack",
...@@ -7005,6 +7006,12 @@ pub const Constant = enum(u32) {...@@ -7005,6 +7006,12 @@ pub const Constant = enum(u32) {
7005 rhs: Constant,7006 rhs: Constant,
7006 };7007 };
70077008
7009 pub const Select = extern struct {
7010 cond: Constant,
7011 lhs: Constant,
7012 rhs: Constant,
7013 };
7014
7008 pub const Assembly = extern struct {7015 pub const Assembly = extern struct {
7009 type: Type,7016 type: Type,
7010 assembly: String,7017 assembly: String,
...@@ -7136,6 +7143,7 @@ pub const Constant = enum(u32) {...@@ -7136,6 +7143,7 @@ pub const Constant = enum(u32) {
7136 .@"or",7143 .@"or",
7137 .xor,7144 .xor,
7138 => builder.constantExtraData(Binary, item.data).lhs.typeOf(builder),7145 => builder.constantExtraData(Binary, item.data).lhs.typeOf(builder),
7146 .select => builder.constantExtraData(Select, item.data).lhs.typeOf(builder),
7139 .@"asm",7147 .@"asm",
7140 .@"asm sideeffect",7148 .@"asm sideeffect",
7141 .@"asm alignstack",7149 .@"asm alignstack",
...@@ -7500,6 +7508,15 @@ pub const Constant = enum(u32) {...@@ -7500,6 +7508,15 @@ pub const Constant = enum(u32) {
7500 extra.rhs.fmt(data.builder),7508 extra.rhs.fmt(data.builder),
7501 });7509 });
7502 },7510 },
7511 .select => |tag| {
7512 const extra = data.builder.constantExtraData(Select, item.data);
7513 try writer.print("{s} ({%}, {%}, {%})", .{
7514 @tagName(tag),
7515 extra.cond.fmt(data.builder),
7516 extra.lhs.fmt(data.builder),
7517 extra.rhs.fmt(data.builder),
7518 });
7519 },
7503 .@"asm",7520 .@"asm",
7504 .@"asm sideeffect",7521 .@"asm sideeffect",
7505 .@"asm alignstack",7522 .@"asm alignstack",
...@@ -8802,6 +8819,20 @@ pub fn binValue(self: *Builder, tag: Constant.Tag, lhs: Constant, rhs: Constant)...@@ -8802,6 +8819,20 @@ pub fn binValue(self: *Builder, tag: Constant.Tag, lhs: Constant, rhs: Constant)
8802 return (try self.binConst(tag, lhs, rhs)).toValue();8819 return (try self.binConst(tag, lhs, rhs)).toValue();
8803}8820}
88048821
8822pub fn selectConst(
8823 self: *Builder,
8824 cond: Constant,
8825 lhs: Constant,
8826 rhs: Constant,
8827) Allocator.Error!Constant {
8828 try self.ensureUnusedConstantCapacity(1, Constant.Select, 0);
8829 return self.selectConstAssumeCapacity(cond, lhs, rhs);
8830}
8831
8832pub fn selectValue(self: *Builder, cond: Constant, lhs: Constant, rhs: Constant) Allocator.Error!Value {
8833 return (try self.selectConst(cond, lhs, rhs)).toValue();
8834}
8835
8805pub fn asmConst(8836pub fn asmConst(
8806 self: *Builder,8837 self: *Builder,
8807 ty: Type,8838 ty: Type,
...@@ -11063,6 +11094,42 @@ fn binConstAssumeCapacity(...@@ -11063,6 +11094,42 @@ fn binConstAssumeCapacity(
11063 return @enumFromInt(gop.index);11094 return @enumFromInt(gop.index);
11064}11095}
1106511096
11097comptime {
11098 _ = &selectValue;
11099}
11100
11101fn selectConstAssumeCapacity(self: *Builder, cond: Constant, lhs: Constant, rhs: Constant) Constant {
11102 const Adapter = struct {
11103 builder: *const Builder,
11104 pub fn hash(_: @This(), key: Constant.Select) u32 {
11105 return @truncate(std.hash.Wyhash.hash(
11106 std.hash.uint32(@intFromEnum(Constant.Tag.select)),
11107 std.mem.asBytes(&key),
11108 ));
11109 }
11110 pub fn eql(ctx: @This(), lhs_key: Constant.Select, _: void, rhs_index: usize) bool {
11111 if (ctx.builder.constant_items.items(.tag)[rhs_index] != .select) return false;
11112 const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
11113 const rhs_extra = ctx.builder.constantExtraData(Constant.Select, rhs_data);
11114 return std.meta.eql(lhs_key, rhs_extra);
11115 }
11116 };
11117 const data = Constant.Select{ .cond = cond, .lhs = lhs, .rhs = rhs };
11118 const gop = self.constant_map.getOrPutAssumeCapacityAdapted(data, Adapter{ .builder = self });
11119 if (!gop.found_existing) {
11120 gop.key_ptr.* = {};
11121 gop.value_ptr.* = {};
11122 self.constant_items.appendAssumeCapacity(.{
11123 .tag = .select,
11124 .data = self.addConstantExtraAssumeCapacity(data),
11125 });
11126 if (self.useLibLlvm()) self.llvm.constants.appendAssumeCapacity(
11127 cond.toLlvm(self).constSelect(lhs.toLlvm(self), rhs.toLlvm(self)),
11128 );
11129 }
11130 return @enumFromInt(gop.index);
11131}
11132
11066fn asmConstAssumeCapacity(11133fn asmConstAssumeCapacity(
11067 self: *Builder,11134 self: *Builder,
11068 ty: Type,11135 ty: Type,
src/codegen/llvm/bindings.zig-90
...@@ -93,17 +93,6 @@ pub const Context = opaque {...@@ -93,17 +93,6 @@ pub const Context = opaque {
93 pub const constString = LLVMConstStringInContext;93 pub const constString = LLVMConstStringInContext;
94 extern fn LLVMConstStringInContext(C: *Context, Str: [*]const u8, Length: c_uint, DontNullTerminate: Bool) *Value;94 extern fn LLVMConstStringInContext(C: *Context, Str: [*]const u8, Length: c_uint, DontNullTerminate: Bool) *Value;
9595
96 pub const constStruct = LLVMConstStructInContext;
97 extern fn LLVMConstStructInContext(
98 C: *Context,
99 ConstantVals: [*]const *Value,
100 Count: c_uint,
101 Packed: Bool,
102 ) *Value;
103
104 pub const createBasicBlock = LLVMCreateBasicBlockInContext;
105 extern fn LLVMCreateBasicBlockInContext(C: *Context, Name: [*:0]const u8) *BasicBlock;
106
107 pub const appendBasicBlock = LLVMAppendBasicBlockInContext;96 pub const appendBasicBlock = LLVMAppendBasicBlockInContext;
108 extern fn LLVMAppendBasicBlockInContext(C: *Context, Fn: *Value, Name: [*:0]const u8) *BasicBlock;97 extern fn LLVMAppendBasicBlockInContext(C: *Context, Fn: *Value, Name: [*:0]const u8) *BasicBlock;
10998
...@@ -127,9 +116,6 @@ pub const Value = opaque {...@@ -127,9 +116,6 @@ pub const Value = opaque {
127 pub const getFirstBasicBlock = LLVMGetFirstBasicBlock;116 pub const getFirstBasicBlock = LLVMGetFirstBasicBlock;
128 extern fn LLVMGetFirstBasicBlock(Fn: *Value) ?*BasicBlock;117 extern fn LLVMGetFirstBasicBlock(Fn: *Value) ?*BasicBlock;
129118
130 pub const appendExistingBasicBlock = LLVMAppendExistingBasicBlock;
131 extern fn LLVMAppendExistingBasicBlock(Fn: *Value, BB: *BasicBlock) void;
132
133 pub const addIncoming = LLVMAddIncoming;119 pub const addIncoming = LLVMAddIncoming;
134 extern fn LLVMAddIncoming(120 extern fn LLVMAddIncoming(
135 PhiNode: *Value,121 PhiNode: *Value,
...@@ -138,9 +124,6 @@ pub const Value = opaque {...@@ -138,9 +124,6 @@ pub const Value = opaque {
138 Count: c_uint,124 Count: c_uint,
139 ) void;125 ) void;
140126
141 pub const getNextInstruction = LLVMGetNextInstruction;
142 extern fn LLVMGetNextInstruction(Inst: *Value) ?*Value;
143
144 pub const setGlobalConstant = LLVMSetGlobalConstant;127 pub const setGlobalConstant = LLVMSetGlobalConstant;
145 extern fn LLVMSetGlobalConstant(GlobalVar: *Value, IsConstant: Bool) void;128 extern fn LLVMSetGlobalConstant(GlobalVar: *Value, IsConstant: Bool) void;
146129
...@@ -162,30 +145,9 @@ pub const Value = opaque {...@@ -162,30 +145,9 @@ pub const Value = opaque {
162 pub const deleteGlobal = LLVMDeleteGlobal;145 pub const deleteGlobal = LLVMDeleteGlobal;
163 extern fn LLVMDeleteGlobal(GlobalVar: *Value) void;146 extern fn LLVMDeleteGlobal(GlobalVar: *Value) void;
164147
165 pub const getNextGlobalAlias = LLVMGetNextGlobalAlias;
166 extern fn LLVMGetNextGlobalAlias(GA: *Value) *Value;
167
168 pub const getAliasee = LLVMAliasGetAliasee;
169 extern fn LLVMAliasGetAliasee(Alias: *Value) *Value;
170
171 pub const setAliasee = LLVMAliasSetAliasee;148 pub const setAliasee = LLVMAliasSetAliasee;
172 extern fn LLVMAliasSetAliasee(Alias: *Value, Aliasee: *Value) void;149 extern fn LLVMAliasSetAliasee(Alias: *Value, Aliasee: *Value) void;
173150
174 pub const constZExtOrBitCast = LLVMConstZExtOrBitCast;
175 extern fn LLVMConstZExtOrBitCast(ConstantVal: *Value, ToType: *Type) *Value;
176
177 pub const constNeg = LLVMConstNeg;
178 extern fn LLVMConstNeg(ConstantVal: *Value) *Value;
179
180 pub const constNSWNeg = LLVMConstNSWNeg;
181 extern fn LLVMConstNSWNeg(ConstantVal: *Value) *Value;
182
183 pub const constNUWNeg = LLVMConstNUWNeg;
184 extern fn LLVMConstNUWNeg(ConstantVal: *Value) *Value;
185
186 pub const constNot = LLVMConstNot;
187 extern fn LLVMConstNot(ConstantVal: *Value) *Value;
188
189 pub const constAdd = LLVMConstAdd;151 pub const constAdd = LLVMConstAdd;
190 extern fn LLVMConstAdd(LHSConstant: *Value, RHSConstant: *Value) *Value;152 extern fn LLVMConstAdd(LHSConstant: *Value, RHSConstant: *Value) *Value;
191153
...@@ -309,9 +271,6 @@ pub const Value = opaque {...@@ -309,9 +271,6 @@ pub const Value = opaque {
309 pub const setVolatile = LLVMSetVolatile;271 pub const setVolatile = LLVMSetVolatile;
310 extern fn LLVMSetVolatile(MemoryAccessInst: *Value, IsVolatile: Bool) void;272 extern fn LLVMSetVolatile(MemoryAccessInst: *Value, IsVolatile: Bool) void;
311273
312 pub const setAtomicSingleThread = LLVMSetAtomicSingleThread;
313 extern fn LLVMSetAtomicSingleThread(AtomicInst: *Value, SingleThread: Bool) void;
314
315 pub const setAlignment = LLVMSetAlignment;274 pub const setAlignment = LLVMSetAlignment;
316 extern fn LLVMSetAlignment(V: *Value, Bytes: c_uint) void;275 extern fn LLVMSetAlignment(V: *Value, Bytes: c_uint) void;
317276
...@@ -366,9 +325,6 @@ pub const Value = opaque {...@@ -366,9 +325,6 @@ pub const Value = opaque {
366 pub const getAlignment = LLVMGetAlignment;325 pub const getAlignment = LLVMGetAlignment;
367 extern fn LLVMGetAlignment(V: *Value) c_uint;326 extern fn LLVMGetAlignment(V: *Value) c_uint;
368327
369 pub const addByValAttr = ZigLLVMAddByValAttr;
370 extern fn ZigLLVMAddByValAttr(Fn: *Value, ArgNo: c_uint, type: *Type) void;
371
372 pub const attachMetaData = ZigLLVMAttachMetaData;328 pub const attachMetaData = ZigLLVMAttachMetaData;
373 extern fn ZigLLVMAttachMetaData(GlobalVar: *Value, DIG: *DIGlobalVariableExpression) void;329 extern fn ZigLLVMAttachMetaData(GlobalVar: *Value, DIG: *DIGlobalVariableExpression) void;
374330
...@@ -380,9 +336,6 @@ pub const Type = opaque {...@@ -380,9 +336,6 @@ pub const Type = opaque {
380 pub const constNull = LLVMConstNull;336 pub const constNull = LLVMConstNull;
381 extern fn LLVMConstNull(Ty: *Type) *Value;337 extern fn LLVMConstNull(Ty: *Type) *Value;
382338
383 pub const constAllOnes = LLVMConstAllOnes;
384 extern fn LLVMConstAllOnes(Ty: *Type) *Value;
385
386 pub const constInt = LLVMConstInt;339 pub const constInt = LLVMConstInt;
387 extern fn LLVMConstInt(IntTy: *Type, N: c_ulonglong, SignExtend: Bool) *Value;340 extern fn LLVMConstInt(IntTy: *Type, N: c_ulonglong, SignExtend: Bool) *Value;
388341
...@@ -476,9 +429,6 @@ pub const Module = opaque {...@@ -476,9 +429,6 @@ pub const Module = opaque {
476 pub const addFunctionInAddressSpace = ZigLLVMAddFunctionInAddressSpace;429 pub const addFunctionInAddressSpace = ZigLLVMAddFunctionInAddressSpace;
477 extern fn ZigLLVMAddFunctionInAddressSpace(*Module, Name: [*:0]const u8, FunctionTy: *Type, AddressSpace: c_uint) *Value;430 extern fn ZigLLVMAddFunctionInAddressSpace(*Module, Name: [*:0]const u8, FunctionTy: *Type, AddressSpace: c_uint) *Value;
478431
479 pub const getNamedFunction = LLVMGetNamedFunction;
480 extern fn LLVMGetNamedFunction(*Module, Name: [*:0]const u8) ?*Value;
481
482 pub const printToString = LLVMPrintModuleToString;432 pub const printToString = LLVMPrintModuleToString;
483 extern fn LLVMPrintModuleToString(*Module) [*:0]const u8;433 extern fn LLVMPrintModuleToString(*Module) [*:0]const u8;
484434
...@@ -488,18 +438,9 @@ pub const Module = opaque {...@@ -488,18 +438,9 @@ pub const Module = opaque {
488 pub const addGlobalInAddressSpace = LLVMAddGlobalInAddressSpace;438 pub const addGlobalInAddressSpace = LLVMAddGlobalInAddressSpace;
489 extern fn LLVMAddGlobalInAddressSpace(M: *Module, Ty: *Type, Name: [*:0]const u8, AddressSpace: c_uint) *Value;439 extern fn LLVMAddGlobalInAddressSpace(M: *Module, Ty: *Type, Name: [*:0]const u8, AddressSpace: c_uint) *Value;
490440
491 pub const getNamedGlobal = LLVMGetNamedGlobal;
492 extern fn LLVMGetNamedGlobal(M: *Module, Name: [*:0]const u8) ?*Value;
493
494 pub const dump = LLVMDumpModule;441 pub const dump = LLVMDumpModule;
495 extern fn LLVMDumpModule(M: *Module) void;442 extern fn LLVMDumpModule(M: *Module) void;
496443
497 pub const getFirstGlobalAlias = LLVMGetFirstGlobalAlias;
498 extern fn LLVMGetFirstGlobalAlias(M: *Module) *Value;
499
500 pub const getLastGlobalAlias = LLVMGetLastGlobalAlias;
501 extern fn LLVMGetLastGlobalAlias(M: *Module) *Value;
502
503 pub const addAlias = LLVMAddAlias2;444 pub const addAlias = LLVMAddAlias2;
504 extern fn LLVMAddAlias2(445 extern fn LLVMAddAlias2(
505 M: *Module,446 M: *Module,
...@@ -541,9 +482,6 @@ pub const Module = opaque {...@@ -541,9 +482,6 @@ pub const Module = opaque {
541 extern fn LLVMWriteBitcodeToFile(M: *Module, Path: [*:0]const u8) c_int;482 extern fn LLVMWriteBitcodeToFile(M: *Module, Path: [*:0]const u8) c_int;
542};483};
543484
544pub const lookupIntrinsicID = LLVMLookupIntrinsicID;
545extern fn LLVMLookupIntrinsicID(Name: [*]const u8, NameLen: usize) c_uint;
546
547pub const disposeMessage = LLVMDisposeMessage;485pub const disposeMessage = LLVMDisposeMessage;
548extern fn LLVMDisposeMessage(Message: [*:0]const u8) void;486extern fn LLVMDisposeMessage(Message: [*:0]const u8) void;
549487
...@@ -604,12 +542,6 @@ pub const Builder = opaque {...@@ -604,12 +542,6 @@ pub const Builder = opaque {
604 Instr: ?*Value,542 Instr: ?*Value,
605 ) void;543 ) void;
606544
607 pub const positionBuilderAtEnd = LLVMPositionBuilderAtEnd;
608 extern fn LLVMPositionBuilderAtEnd(Builder: *Builder, Block: *BasicBlock) void;
609
610 pub const getInsertBlock = LLVMGetInsertBlock;
611 extern fn LLVMGetInsertBlock(Builder: *Builder) *BasicBlock;
612
613 pub const buildZExt = LLVMBuildZExt;545 pub const buildZExt = LLVMBuildZExt;
614 extern fn LLVMBuildZExt(546 extern fn LLVMBuildZExt(
615 *Builder,547 *Builder,
...@@ -618,14 +550,6 @@ pub const Builder = opaque {...@@ -618,14 +550,6 @@ pub const Builder = opaque {
618 Name: [*:0]const u8,550 Name: [*:0]const u8,
619 ) *Value;551 ) *Value;
620552
621 pub const buildZExtOrBitCast = LLVMBuildZExtOrBitCast;
622 extern fn LLVMBuildZExtOrBitCast(
623 *Builder,
624 Val: *Value,
625 DestTy: *Type,
626 Name: [*:0]const u8,
627 ) *Value;
628
629 pub const buildSExt = LLVMBuildSExt;553 pub const buildSExt = LLVMBuildSExt;
630 extern fn LLVMBuildSExt(554 extern fn LLVMBuildSExt(
631 *Builder,555 *Builder,
...@@ -634,14 +558,6 @@ pub const Builder = opaque {...@@ -634,14 +558,6 @@ pub const Builder = opaque {
634 Name: [*:0]const u8,558 Name: [*:0]const u8,
635 ) *Value;559 ) *Value;
636560
637 pub const buildSExtOrBitCast = LLVMBuildSExtOrBitCast;
638 extern fn LLVMBuildSExtOrBitCast(
639 *Builder,
640 Val: *Value,
641 DestTy: *Type,
642 Name: [*:0]const u8,
643 ) *Value;
644
645 pub const buildCall = LLVMBuildCall2;561 pub const buildCall = LLVMBuildCall2;
646 extern fn LLVMBuildCall2(562 extern fn LLVMBuildCall2(
647 *Builder,563 *Builder,
...@@ -670,12 +586,6 @@ pub const Builder = opaque {...@@ -670,12 +586,6 @@ pub const Builder = opaque {
670 pub const buildLoad = LLVMBuildLoad2;586 pub const buildLoad = LLVMBuildLoad2;
671 extern fn LLVMBuildLoad2(*Builder, Ty: *Type, PointerVal: *Value, Name: [*:0]const u8) *Value;587 extern fn LLVMBuildLoad2(*Builder, Ty: *Type, PointerVal: *Value, Name: [*:0]const u8) *Value;
672588
673 pub const buildNeg = LLVMBuildNeg;
674 extern fn LLVMBuildNeg(*Builder, V: *Value, Name: [*:0]const u8) *Value;
675
676 pub const buildNot = LLVMBuildNot;
677 extern fn LLVMBuildNot(*Builder, V: *Value, Name: [*:0]const u8) *Value;
678
679 pub const buildFAdd = LLVMBuildFAdd;589 pub const buildFAdd = LLVMBuildFAdd;
680 extern fn LLVMBuildFAdd(*Builder, LHS: *Value, RHS: *Value, Name: [*:0]const u8) *Value;590 extern fn LLVMBuildFAdd(*Builder, LHS: *Value, RHS: *Value, Name: [*:0]const u8) *Value;
681591