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 {
97759775 else
97769776 try self.wip.cast(.bitcast, non_int_val, small_int_ty, "");
97779777 const shift_rhs = try o.builder.intValue(int_ty, running_bits);
9778 // If the field is as large as the entire packed struct, this
9779 // zext would go from, e.g. i16 to i16. This is legal with
9780 // constZExtOrBitCast but not legal with constZExt.
9781 const extended_int_val = try self.wip.conv(.unsigned, small_int_val, int_ty, "");
9778 const extended_int_val =
9779 try self.wip.conv(.unsigned, small_int_val, int_ty, "");
97829780 const shifted = try self.wip.bin(.shl, extended_int_val, shift_rhs, "");
97839781 running_int = try self.wip.bin(.@"or", running_int, shifted, "");
97849782 running_bits += ty_bit_size;
src/codegen/llvm/Builder.zig+67
......@@ -6894,6 +6894,7 @@ pub const Constant = enum(u32) {
68946894 @"and",
68956895 @"or",
68966896 xor,
6897 select,
68976898 @"asm",
68986899 @"asm sideeffect",
68996900 @"asm alignstack",
......@@ -7005,6 +7006,12 @@ pub const Constant = enum(u32) {
70057006 rhs: Constant,
70067007 };
70077008
7009 pub const Select = extern struct {
7010 cond: Constant,
7011 lhs: Constant,
7012 rhs: Constant,
7013 };
7014
70087015 pub const Assembly = extern struct {
70097016 type: Type,
70107017 assembly: String,
......@@ -7136,6 +7143,7 @@ pub const Constant = enum(u32) {
71367143 .@"or",
71377144 .xor,
71387145 => builder.constantExtraData(Binary, item.data).lhs.typeOf(builder),
7146 .select => builder.constantExtraData(Select, item.data).lhs.typeOf(builder),
71397147 .@"asm",
71407148 .@"asm sideeffect",
71417149 .@"asm alignstack",
......@@ -7500,6 +7508,15 @@ pub const Constant = enum(u32) {
75007508 extra.rhs.fmt(data.builder),
75017509 });
75027510 },
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 },
75037520 .@"asm",
75047521 .@"asm sideeffect",
75057522 .@"asm alignstack",
......@@ -8802,6 +8819,20 @@ pub fn binValue(self: *Builder, tag: Constant.Tag, lhs: Constant, rhs: Constant)
88028819 return (try self.binConst(tag, lhs, rhs)).toValue();
88038820}
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
88058836pub fn asmConst(
88068837 self: *Builder,
88078838 ty: Type,
......@@ -11063,6 +11094,42 @@ fn binConstAssumeCapacity(
1106311094 return @enumFromInt(gop.index);
1106411095}
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
1106611133fn asmConstAssumeCapacity(
1106711134 self: *Builder,
1106811135 ty: Type,
src/codegen/llvm/bindings.zig-90
......@@ -93,17 +93,6 @@ pub const Context = opaque {
9393 pub const constString = LLVMConstStringInContext;
9494 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
10796 pub const appendBasicBlock = LLVMAppendBasicBlockInContext;
10897 extern fn LLVMAppendBasicBlockInContext(C: *Context, Fn: *Value, Name: [*:0]const u8) *BasicBlock;
10998
......@@ -127,9 +116,6 @@ pub const Value = opaque {
127116 pub const getFirstBasicBlock = LLVMGetFirstBasicBlock;
128117 extern fn LLVMGetFirstBasicBlock(Fn: *Value) ?*BasicBlock;
129118
130 pub const appendExistingBasicBlock = LLVMAppendExistingBasicBlock;
131 extern fn LLVMAppendExistingBasicBlock(Fn: *Value, BB: *BasicBlock) void;
132
133119 pub const addIncoming = LLVMAddIncoming;
134120 extern fn LLVMAddIncoming(
135121 PhiNode: *Value,
......@@ -138,9 +124,6 @@ pub const Value = opaque {
138124 Count: c_uint,
139125 ) void;
140126
141 pub const getNextInstruction = LLVMGetNextInstruction;
142 extern fn LLVMGetNextInstruction(Inst: *Value) ?*Value;
143
144127 pub const setGlobalConstant = LLVMSetGlobalConstant;
145128 extern fn LLVMSetGlobalConstant(GlobalVar: *Value, IsConstant: Bool) void;
146129
......@@ -162,30 +145,9 @@ pub const Value = opaque {
162145 pub const deleteGlobal = LLVMDeleteGlobal;
163146 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
171148 pub const setAliasee = LLVMAliasSetAliasee;
172149 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
189151 pub const constAdd = LLVMConstAdd;
190152 extern fn LLVMConstAdd(LHSConstant: *Value, RHSConstant: *Value) *Value;
191153
......@@ -309,9 +271,6 @@ pub const Value = opaque {
309271 pub const setVolatile = LLVMSetVolatile;
310272 extern fn LLVMSetVolatile(MemoryAccessInst: *Value, IsVolatile: Bool) void;
311273
312 pub const setAtomicSingleThread = LLVMSetAtomicSingleThread;
313 extern fn LLVMSetAtomicSingleThread(AtomicInst: *Value, SingleThread: Bool) void;
314
315274 pub const setAlignment = LLVMSetAlignment;
316275 extern fn LLVMSetAlignment(V: *Value, Bytes: c_uint) void;
317276
......@@ -366,9 +325,6 @@ pub const Value = opaque {
366325 pub const getAlignment = LLVMGetAlignment;
367326 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
372328 pub const attachMetaData = ZigLLVMAttachMetaData;
373329 extern fn ZigLLVMAttachMetaData(GlobalVar: *Value, DIG: *DIGlobalVariableExpression) void;
374330
......@@ -380,9 +336,6 @@ pub const Type = opaque {
380336 pub const constNull = LLVMConstNull;
381337 extern fn LLVMConstNull(Ty: *Type) *Value;
382338
383 pub const constAllOnes = LLVMConstAllOnes;
384 extern fn LLVMConstAllOnes(Ty: *Type) *Value;
385
386339 pub const constInt = LLVMConstInt;
387340 extern fn LLVMConstInt(IntTy: *Type, N: c_ulonglong, SignExtend: Bool) *Value;
388341
......@@ -476,9 +429,6 @@ pub const Module = opaque {
476429 pub const addFunctionInAddressSpace = ZigLLVMAddFunctionInAddressSpace;
477430 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
482432 pub const printToString = LLVMPrintModuleToString;
483433 extern fn LLVMPrintModuleToString(*Module) [*:0]const u8;
484434
......@@ -488,18 +438,9 @@ pub const Module = opaque {
488438 pub const addGlobalInAddressSpace = LLVMAddGlobalInAddressSpace;
489439 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
494441 pub const dump = LLVMDumpModule;
495442 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
503444 pub const addAlias = LLVMAddAlias2;
504445 extern fn LLVMAddAlias2(
505446 M: *Module,
......@@ -541,9 +482,6 @@ pub const Module = opaque {
541482 extern fn LLVMWriteBitcodeToFile(M: *Module, Path: [*:0]const u8) c_int;
542483};
543484
544pub const lookupIntrinsicID = LLVMLookupIntrinsicID;
545extern fn LLVMLookupIntrinsicID(Name: [*]const u8, NameLen: usize) c_uint;
546
547485pub const disposeMessage = LLVMDisposeMessage;
548486extern fn LLVMDisposeMessage(Message: [*:0]const u8) void;
549487
......@@ -604,12 +542,6 @@ pub const Builder = opaque {
604542 Instr: ?*Value,
605543 ) 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
613545 pub const buildZExt = LLVMBuildZExt;
614546 extern fn LLVMBuildZExt(
615547 *Builder,
......@@ -618,14 +550,6 @@ pub const Builder = opaque {
618550 Name: [*:0]const u8,
619551 ) *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
629553 pub const buildSExt = LLVMBuildSExt;
630554 extern fn LLVMBuildSExt(
631555 *Builder,
......@@ -634,14 +558,6 @@ pub const Builder = opaque {
634558 Name: [*:0]const u8,
635559 ) *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
645561 pub const buildCall = LLVMBuildCall2;
646562 extern fn LLVMBuildCall2(
647563 *Builder,
......@@ -670,12 +586,6 @@ pub const Builder = opaque {
670586 pub const buildLoad = LLVMBuildLoad2;
671587 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
679589 pub const buildFAdd = LLVMBuildFAdd;
680590 extern fn LLVMBuildFAdd(*Builder, LHS: *Value, RHS: *Value, Name: [*:0]const u8) *Value;
681591