Merge pull request #16430 from jacobly0/llvm-builder

llvm: begin the journey of independence from llvm
This commit is contained in:
Andrew Kelley 2023-07-20 12:55:03 -07:00 committed by GitHub
commit 3f15010abe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 12572 additions and 4005 deletions

View File

@ -1357,8 +1357,6 @@ pub const Target = struct {
}
};
pub const stack_align = 16;
pub fn zigTriple(self: Target, allocator: mem.Allocator) ![]u8 {
return std.zig.CrossTarget.fromTarget(self).zigTriple(allocator);
}
@ -1833,7 +1831,7 @@ pub const Target = struct {
};
}
pub fn ptrBitWidth(target: std.Target) u16 {
pub fn ptrBitWidth(target: Target) u16 {
switch (target.abi) {
.gnux32, .muslx32, .gnuabin32, .gnuilp32 => return 32,
.gnuabi64 => return 64,
@ -1910,6 +1908,43 @@ pub const Target = struct {
}
}
pub fn stackAlignment(target: Target) u16 {
return switch (target.cpu.arch) {
.amdgcn => 4,
.x86 => switch (target.os.tag) {
.windows => 4,
else => 16,
},
.arm,
.armeb,
.thumb,
.thumbeb,
.mips,
.mipsel,
.sparc,
.sparcel,
=> 8,
.aarch64,
.aarch64_be,
.aarch64_32,
.bpfeb,
.bpfel,
.mips64,
.mips64el,
.powerpc64,
.powerpc64le,
.riscv32,
.riscv64,
.sparc64,
.x86_64,
.ve,
.wasm32,
.wasm64,
=> 16,
else => @divExact(target.ptrBitWidth(), 8),
};
}
/// Default signedness of `char` for the native C compiler for this target
/// Note that char signedness is implementation-defined and many compilers provide
/// an option to override the default signedness e.g. GCC's -funsigned-char / -fsigned-char
@ -2428,7 +2463,7 @@ pub const Target = struct {
else => {},
},
.avr => switch (c_type) {
.int, .uint, .long, .ulong, .float, .longdouble => return 1,
.char, .int, .uint, .long, .ulong, .float, .longdouble => return 1,
.short, .ushort => return 2,
.double => return 4,
.longlong, .ulonglong => return 8,

View File

@ -136,7 +136,7 @@ fn mainTerminal() void {
const have_tty = progress.terminal != null and
(progress.supports_ansi_escape_codes or progress.is_windows_terminal);
var async_frame_buffer: []align(std.Target.stack_align) u8 = undefined;
var async_frame_buffer: []align(builtin.target.stackAlignment()) u8 = undefined;
// TODO this is on the next line (using `undefined` above) because otherwise zig incorrectly
// ignores the alignment of the slice.
async_frame_buffer = &[_]u8{};

View File

@ -538,6 +538,7 @@ pub const InitOptions = struct {
want_lto: ?bool = null,
want_unwind_tables: ?bool = null,
use_llvm: ?bool = null,
use_lib_llvm: ?bool = null,
use_lld: ?bool = null,
use_clang: ?bool = null,
single_threaded: ?bool = null,
@ -753,7 +754,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
const root_name = try arena.dupeZ(u8, options.root_name);
// Make a decision on whether to use LLVM or our own backend.
const use_llvm = build_options.have_llvm and blk: {
const use_lib_llvm = options.use_lib_llvm orelse build_options.have_llvm;
const use_llvm = blk: {
if (options.use_llvm) |explicit|
break :blk explicit;
@ -1161,6 +1163,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
hash.add(valgrind);
hash.add(single_threaded);
hash.add(use_llvm);
hash.add(use_lib_llvm);
hash.add(dll_export_fns);
hash.add(options.is_test);
hash.add(options.test_evented_io);
@ -1444,6 +1447,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
.optimize_mode = options.optimize_mode,
.use_lld = use_lld,
.use_llvm = use_llvm,
.use_lib_llvm = use_lib_llvm,
.link_libc = link_libc,
.link_libcpp = link_libcpp,
.link_libunwind = link_libunwind,

View File

@ -835,10 +835,6 @@ pub const Decl = struct {
assert(decl.has_tv);
return @as(u32, @intCast(decl.alignment.toByteUnitsOptional() orelse decl.ty.abiAlignment(mod)));
}
pub fn intern(decl: *Decl, mod: *Module) Allocator.Error!void {
decl.val = (try decl.val.intern(decl.ty, mod)).toValue();
}
};
/// This state is attached to every Decl when Module emit_h is non-null.
@ -4204,7 +4200,7 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
try wip_captures.finalize();
for (comptime_mutable_decls.items) |decl_index| {
const decl = mod.declPtr(decl_index);
try decl.intern(mod);
_ = try decl.internValue(mod);
}
new_decl.analysis = .complete;
} else |err| switch (err) {
@ -4315,7 +4311,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
try wip_captures.finalize();
for (comptime_mutable_decls.items) |ct_decl_index| {
const ct_decl = mod.declPtr(ct_decl_index);
try ct_decl.intern(mod);
_ = try ct_decl.internValue(mod);
}
const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = 0 };
const section_src: LazySrcLoc = .{ .node_offset_var_decl_section = 0 };
@ -5362,7 +5358,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
try wip_captures.finalize();
for (comptime_mutable_decls.items) |ct_decl_index| {
const ct_decl = mod.declPtr(ct_decl_index);
try ct_decl.intern(mod);
_ = try ct_decl.internValue(mod);
}
// Copy the block into place and mark that as the main block.
@ -6369,7 +6365,7 @@ pub fn markDeclAlive(mod: *Module, decl: *Decl) Allocator.Error!void {
if (decl.alive) return;
decl.alive = true;
try decl.intern(mod);
_ = try decl.internValue(mod);
// This is the first time we are marking this Decl alive. We must
// therefore recurse into its value and mark any Decl it references

View File

@ -3899,7 +3899,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
try mod.declareDeclDependency(sema.owner_decl_index, decl_index);
const decl = mod.declPtr(decl_index);
if (iac.is_const) try decl.intern(mod);
if (iac.is_const) _ = try decl.internValue(mod);
const final_elem_ty = decl.ty;
const final_ptr_ty = try mod.ptrType(.{
.child = final_elem_ty.toIntern(),
@ -33577,7 +33577,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
try wip_captures.finalize();
for (comptime_mutable_decls.items) |ct_decl_index| {
const ct_decl = mod.declPtr(ct_decl_index);
try ct_decl.intern(mod);
_ = try ct_decl.internValue(mod);
}
} else {
if (fields_bit_sum > std.math.maxInt(u16)) {
@ -34645,7 +34645,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
try wip_captures.finalize();
for (comptime_mutable_decls.items) |ct_decl_index| {
const ct_decl = mod.declPtr(ct_decl_index);
try ct_decl.intern(mod);
_ = try ct_decl.internValue(mod);
}
struct_obj.have_field_inits = true;
@ -34744,7 +34744,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
try wip_captures.finalize();
for (comptime_mutable_decls.items) |ct_decl_index| {
const ct_decl = mod.declPtr(ct_decl_index);
try ct_decl.intern(mod);
_ = try ct_decl.internValue(mod);
}
try union_obj.fields.ensureTotalCapacity(mod.tmp_hack_arena.allocator(), fields_len);

File diff suppressed because it is too large Load Diff

7931
src/codegen/llvm/Builder.zig Normal file

File diff suppressed because it is too large Load Diff

View File

@ -40,21 +40,42 @@ pub const Context = opaque {
pub const halfType = LLVMHalfTypeInContext;
extern fn LLVMHalfTypeInContext(C: *Context) *Type;
pub const bfloatType = LLVMBFloatTypeInContext;
extern fn LLVMBFloatTypeInContext(C: *Context) *Type;
pub const floatType = LLVMFloatTypeInContext;
extern fn LLVMFloatTypeInContext(C: *Context) *Type;
pub const doubleType = LLVMDoubleTypeInContext;
extern fn LLVMDoubleTypeInContext(C: *Context) *Type;
pub const x86FP80Type = LLVMX86FP80TypeInContext;
extern fn LLVMX86FP80TypeInContext(C: *Context) *Type;
pub const fp128Type = LLVMFP128TypeInContext;
extern fn LLVMFP128TypeInContext(C: *Context) *Type;
pub const x86_fp80Type = LLVMX86FP80TypeInContext;
extern fn LLVMX86FP80TypeInContext(C: *Context) *Type;
pub const ppc_fp128Type = LLVMPPCFP128TypeInContext;
extern fn LLVMPPCFP128TypeInContext(C: *Context) *Type;
pub const x86_amxType = LLVMX86AMXTypeInContext;
extern fn LLVMX86AMXTypeInContext(C: *Context) *Type;
pub const x86_mmxType = LLVMX86MMXTypeInContext;
extern fn LLVMX86MMXTypeInContext(C: *Context) *Type;
pub const voidType = LLVMVoidTypeInContext;
extern fn LLVMVoidTypeInContext(C: *Context) *Type;
pub const labelType = LLVMLabelTypeInContext;
extern fn LLVMLabelTypeInContext(C: *Context) *Type;
pub const tokenType = LLVMTokenTypeInContext;
extern fn LLVMTokenTypeInContext(C: *Context) *Type;
pub const metadataType = LLVMMetadataTypeInContext;
extern fn LLVMMetadataTypeInContext(C: *Context) *Type;
pub const structType = LLVMStructTypeInContext;
extern fn LLVMStructTypeInContext(
C: *Context,
@ -114,9 +135,6 @@ pub const Value = opaque {
pub const getNextInstruction = LLVMGetNextInstruction;
extern fn LLVMGetNextInstruction(Inst: *Value) ?*Value;
pub const typeOf = LLVMTypeOf;
extern fn LLVMTypeOf(Val: *Value) *Type;
pub const setGlobalConstant = LLVMSetGlobalConstant;
extern fn LLVMSetGlobalConstant(GlobalVar: *Value, IsConstant: Bool) void;
@ -147,36 +165,135 @@ pub const Value = opaque {
pub const setAliasee = LLVMAliasSetAliasee;
extern fn LLVMAliasSetAliasee(Alias: *Value, Aliasee: *Value) void;
pub const constBitCast = LLVMConstBitCast;
extern fn LLVMConstBitCast(ConstantVal: *Value, ToType: *Type) *Value;
pub const constIntToPtr = LLVMConstIntToPtr;
extern fn LLVMConstIntToPtr(ConstantVal: *Value, ToType: *Type) *Value;
pub const constPtrToInt = LLVMConstPtrToInt;
extern fn LLVMConstPtrToInt(ConstantVal: *Value, ToType: *Type) *Value;
pub const constShl = LLVMConstShl;
extern fn LLVMConstShl(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constOr = LLVMConstOr;
extern fn LLVMConstOr(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constZExt = LLVMConstZExt;
extern fn LLVMConstZExt(ConstantVal: *Value, ToType: *Type) *Value;
pub const constZExtOrBitCast = LLVMConstZExtOrBitCast;
extern fn LLVMConstZExtOrBitCast(ConstantVal: *Value, ToType: *Type) *Value;
pub const constNeg = LLVMConstNeg;
extern fn LLVMConstNeg(ConstantVal: *Value) *Value;
pub const constNSWNeg = LLVMConstNSWNeg;
extern fn LLVMConstNSWNeg(ConstantVal: *Value) *Value;
pub const constNUWNeg = LLVMConstNUWNeg;
extern fn LLVMConstNUWNeg(ConstantVal: *Value) *Value;
pub const constNot = LLVMConstNot;
extern fn LLVMConstNot(ConstantVal: *Value) *Value;
pub const constAdd = LLVMConstAdd;
extern fn LLVMConstAdd(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constNSWAdd = LLVMConstNSWAdd;
extern fn LLVMConstNSWAdd(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constNUWAdd = LLVMConstNUWAdd;
extern fn LLVMConstNUWAdd(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constSub = LLVMConstSub;
extern fn LLVMConstSub(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constNSWSub = LLVMConstNSWSub;
extern fn LLVMConstNSWSub(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constNUWSub = LLVMConstNUWSub;
extern fn LLVMConstNUWSub(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constMul = LLVMConstMul;
extern fn LLVMConstMul(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constNSWMul = LLVMConstNSWMul;
extern fn LLVMConstNSWMul(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constNUWMul = LLVMConstNUWMul;
extern fn LLVMConstNUWMul(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constAnd = LLVMConstAnd;
extern fn LLVMConstAnd(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constOr = LLVMConstOr;
extern fn LLVMConstOr(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constXor = LLVMConstXor;
extern fn LLVMConstXor(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constShl = LLVMConstShl;
extern fn LLVMConstShl(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constLShr = LLVMConstLShr;
extern fn LLVMConstLShr(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constAShr = LLVMConstAShr;
extern fn LLVMConstAShr(LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constTrunc = LLVMConstTrunc;
extern fn LLVMConstTrunc(ConstantVal: *Value, ToType: *Type) *Value;
pub const constSExt = LLVMConstSExt;
extern fn LLVMConstSExt(ConstantVal: *Value, ToType: *Type) *Value;
pub const constZExt = LLVMConstZExt;
extern fn LLVMConstZExt(ConstantVal: *Value, ToType: *Type) *Value;
pub const constFPTrunc = LLVMConstFPTrunc;
extern fn LLVMConstFPTrunc(ConstantVal: *Value, ToType: *Type) *Value;
pub const constFPExt = LLVMConstFPExt;
extern fn LLVMConstFPExt(ConstantVal: *Value, ToType: *Type) *Value;
pub const constUIToFP = LLVMConstUIToFP;
extern fn LLVMConstUIToFP(ConstantVal: *Value, ToType: *Type) *Value;
pub const constSIToFP = LLVMConstSIToFP;
extern fn LLVMConstSIToFP(ConstantVal: *Value, ToType: *Type) *Value;
pub const constFPToUI = LLVMConstFPToUI;
extern fn LLVMConstFPToUI(ConstantVal: *Value, ToType: *Type) *Value;
pub const constFPToSI = LLVMConstFPToSI;
extern fn LLVMConstFPToSI(ConstantVal: *Value, ToType: *Type) *Value;
pub const constPtrToInt = LLVMConstPtrToInt;
extern fn LLVMConstPtrToInt(ConstantVal: *Value, ToType: *Type) *Value;
pub const constIntToPtr = LLVMConstIntToPtr;
extern fn LLVMConstIntToPtr(ConstantVal: *Value, ToType: *Type) *Value;
pub const constBitCast = LLVMConstBitCast;
extern fn LLVMConstBitCast(ConstantVal: *Value, ToType: *Type) *Value;
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;
pub const constInsertElement = LLVMConstInsertElement;
extern fn LLVMConstInsertElement(
VectorConstant: *Value,
ElementValueConstant: *Value,
IndexConstant: *Value,
) *Value;
pub const constShuffleVector = LLVMConstShuffleVector;
extern fn LLVMConstShuffleVector(
VectorAConstant: *Value,
VectorBConstant: *Value,
MaskConstant: *Value,
) *Value;
pub const isConstant = LLVMIsConstant;
extern fn LLVMIsConstant(Val: *Value) Bool;
pub const blockAddress = LLVMBlockAddress;
extern fn LLVMBlockAddress(F: *Value, BB: *BasicBlock) *Value;
pub const setWeak = LLVMSetWeak;
extern fn LLVMSetWeak(CmpXchgInst: *Value, IsWeak: Bool) void;
@ -186,6 +303,9 @@ pub const Value = opaque {
pub const setVolatile = LLVMSetVolatile;
extern fn LLVMSetVolatile(MemoryAccessInst: *Value, IsVolatile: Bool) void;
pub const setAtomicSingleThread = LLVMSetAtomicSingleThread;
extern fn LLVMSetAtomicSingleThread(AtomicInst: *Value, SingleThread: Bool) void;
pub const setAlignment = LLVMSetAlignment;
extern fn LLVMSetAlignment(V: *Value, Bytes: c_uint) void;
@ -231,17 +351,9 @@ pub const Value = opaque {
pub const addCase = LLVMAddCase;
extern fn LLVMAddCase(Switch: *Value, OnVal: *Value, Dest: *BasicBlock) void;
pub inline fn isPoison(Val: *Value) bool {
return LLVMIsPoison(Val).toBool();
}
extern fn LLVMIsPoison(Val: *Value) Bool;
pub const replaceAllUsesWith = LLVMReplaceAllUsesWith;
extern fn LLVMReplaceAllUsesWith(OldVal: *Value, NewVal: *Value) void;
pub const globalGetValueType = LLVMGlobalGetValueType;
extern fn LLVMGlobalGetValueType(Global: *Value) *Type;
pub const getLinkage = LLVMGetLinkage;
extern fn LLVMGetLinkage(Global: *Value) Linkage;
@ -259,6 +371,9 @@ pub const Value = opaque {
pub const attachMetaData = ZigLLVMAttachMetaData;
extern fn ZigLLVMAttachMetaData(GlobalVar: *Value, DIG: *DIGlobalVariableExpression) void;
pub const dump = LLVMDumpValue;
extern fn LLVMDumpValue(Val: *Value) void;
};
pub const Type = opaque {
@ -290,12 +405,18 @@ pub const Type = opaque {
pub const getUndef = LLVMGetUndef;
extern fn LLVMGetUndef(Ty: *Type) *Value;
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 vectorType = LLVMVectorType;
extern fn LLVMVectorType(ElementType: *Type, ElementCount: c_uint) *Type;
pub const scalableVectorType = LLVMScalableVectorType;
extern fn LLVMScalableVectorType(ElementType: *Type, ElementCount: c_uint) *Type;
pub const structSetBody = LLVMStructSetBody;
extern fn LLVMStructSetBody(
StructTy: *Type,
@ -304,23 +425,13 @@ pub const Type = opaque {
Packed: Bool,
) void;
pub const structGetTypeAtIndex = LLVMStructGetTypeAtIndex;
extern fn LLVMStructGetTypeAtIndex(StructTy: *Type, i: c_uint) *Type;
pub const getTypeKind = LLVMGetTypeKind;
extern fn LLVMGetTypeKind(Ty: *Type) TypeKind;
pub const getElementType = LLVMGetElementType;
extern fn LLVMGetElementType(Ty: *Type) *Type;
pub const countStructElementTypes = LLVMCountStructElementTypes;
extern fn LLVMCountStructElementTypes(StructTy: *Type) c_uint;
pub const isOpaqueStruct = LLVMIsOpaqueStruct;
extern fn LLVMIsOpaqueStruct(StructTy: *Type) Bool;
pub const isSized = LLVMTypeIsSized;
extern fn LLVMTypeIsSized(Ty: *Type) Bool;
pub const constGEP = LLVMConstGEP2;
extern fn LLVMConstGEP2(
Ty: *Type,
ConstantVal: *Value,
ConstantIndices: [*]const *Value,
NumIndices: c_uint,
) *Value;
pub const constInBoundsGEP = LLVMConstInBoundsGEP2;
extern fn LLVMConstInBoundsGEP2(
@ -329,6 +440,9 @@ pub const Type = opaque {
ConstantIndices: [*]const *Value,
NumIndices: c_uint,
) *Value;
pub const dump = LLVMDumpType;
extern fn LLVMDumpType(Ty: *Type) void;
};
pub const Module = opaque {
@ -439,15 +553,18 @@ pub const VerifierFailureAction = enum(c_int) {
ReturnStatus,
};
pub const constNeg = LLVMConstNeg;
extern fn LLVMConstNeg(ConstantVal: *Value) *Value;
pub const constVector = LLVMConstVector;
extern fn LLVMConstVector(
ScalarConstantVals: [*]*Value,
Size: c_uint,
) *Value;
pub const constICmp = LLVMConstICmp;
extern fn LLVMConstICmp(Predicate: IntPredicate, LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const constFCmp = LLVMConstFCmp;
extern fn LLVMConstFCmp(Predicate: RealPredicate, LHSConstant: *Value, RHSConstant: *Value) *Value;
pub const getEnumAttributeKindForName = LLVMGetEnumAttributeKindForName;
extern fn LLVMGetEnumAttributeKindForName(Name: [*]const u8, SLen: usize) c_uint;
@ -484,7 +601,7 @@ pub const Builder = opaque {
extern fn LLVMPositionBuilder(
Builder: *Builder,
Block: *BasicBlock,
Instr: *Value,
Instr: ?*Value,
) void;
pub const positionBuilderAtEnd = LLVMPositionBuilderAtEnd;
@ -678,6 +795,16 @@ pub const Builder = opaque {
pub const buildBitCast = LLVMBuildBitCast;
extern fn LLVMBuildBitCast(*Builder, Val: *Value, DestTy: *Type, Name: [*:0]const u8) *Value;
pub const buildGEP = LLVMBuildGEP2;
extern fn LLVMBuildGEP2(
B: *Builder,
Ty: *Type,
Pointer: *Value,
Indices: [*]const *Value,
NumIndices: c_uint,
Name: [*:0]const u8,
) *Value;
pub const buildInBoundsGEP = LLVMBuildInBoundsGEP2;
extern fn LLVMBuildInBoundsGEP2(
B: *Builder,
@ -731,14 +858,6 @@ pub const Builder = opaque {
Name: [*:0]const u8,
) *Value;
pub const buildVectorSplat = LLVMBuildVectorSplat;
extern fn LLVMBuildVectorSplat(
*Builder,
ElementCount: c_uint,
EltVal: *Value,
Name: [*:0]const u8,
) *Value;
pub const buildPtrToInt = LLVMBuildPtrToInt;
extern fn LLVMBuildPtrToInt(
*Builder,
@ -755,15 +874,6 @@ pub const Builder = opaque {
Name: [*:0]const u8,
) *Value;
pub const buildStructGEP = LLVMBuildStructGEP2;
extern fn LLVMBuildStructGEP2(
B: *Builder,
Ty: *Type,
Pointer: *Value,
Idx: c_uint,
Name: [*:0]const u8,
) *Value;
pub const buildTrunc = LLVMBuildTrunc;
extern fn LLVMBuildTrunc(
*Builder,
@ -1019,9 +1129,6 @@ pub const RealPredicate = enum(c_uint) {
pub const BasicBlock = opaque {
pub const deleteBasicBlock = LLVMDeleteBasicBlock;
extern fn LLVMDeleteBasicBlock(BB: *BasicBlock) void;
pub const getFirstInstruction = LLVMGetFirstInstruction;
extern fn LLVMGetFirstInstruction(BB: *BasicBlock) ?*Value;
};
pub const TargetMachine = opaque {
@ -1071,6 +1178,9 @@ pub const TargetData = opaque {
pub const abiSizeOfType = LLVMABISizeOfType;
extern fn LLVMABISizeOfType(TD: *TargetData, Ty: *Type) c_ulonglong;
pub const stringRep = LLVMCopyStringRepOfTargetData;
extern fn LLVMCopyStringRepOfTargetData(TD: *TargetData) [*:0]const u8;
};
pub const CodeModel = enum(c_int) {
@ -1440,29 +1550,6 @@ pub const AtomicRMWBinOp = enum(c_int) {
FMin,
};
pub const TypeKind = enum(c_int) {
Void,
Half,
Float,
Double,
X86_FP80,
FP128,
PPC_FP128,
Label,
Integer,
Function,
Struct,
Array,
Pointer,
Vector,
Metadata,
X86_MMX,
Token,
ScalableVector,
BFloat,
X86_AMX,
};
pub const CallConv = enum(c_uint) {
C = 0,
Fast = 8,
@ -1588,6 +1675,13 @@ pub const address_space = struct {
pub const constant_buffer_14: c_uint = 22;
pub const constant_buffer_15: c_uint = 23;
};
// See llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypetilities.h
pub const wasm = struct {
pub const variable: c_uint = 1;
pub const externref: c_uint = 10;
pub const funcref: c_uint = 20;
};
};
pub const DIEnumerator = opaque {};

View File

@ -110,6 +110,7 @@ pub const Options = struct {
/// other objects.
/// Otherwise (depending on `use_lld`) this link code directly outputs and updates the final binary.
use_llvm: bool,
use_lib_llvm: bool,
link_libc: bool,
link_libcpp: bool,
link_libunwind: bool,

View File

@ -439,6 +439,8 @@ const usage_build_generic =
\\ -fno-unwind-tables Never produce unwind table entries
\\ -fLLVM Force using LLVM as the codegen backend
\\ -fno-LLVM Prevent using LLVM as the codegen backend
\\ -flibLLVM Force using the LLVM API in the codegen backend
\\ -fno-libLLVM Prevent using the LLVM API in the codegen backend
\\ -fClang Force using Clang as the C/C++ compilation backend
\\ -fno-Clang Prevent using Clang as the C/C++ compilation backend
\\ -freference-trace[=num] How many lines of reference trace should be shown per compile error
@ -821,6 +823,7 @@ fn buildOutputType(
var stack_size_override: ?u64 = null;
var image_base_override: ?u64 = null;
var use_llvm: ?bool = null;
var use_lib_llvm: ?bool = null;
var use_lld: ?bool = null;
var use_clang: ?bool = null;
var link_eh_frame_hdr = false;
@ -1261,6 +1264,10 @@ fn buildOutputType(
use_llvm = true;
} else if (mem.eql(u8, arg, "-fno-LLVM")) {
use_llvm = false;
} else if (mem.eql(u8, arg, "-flibLLVM")) {
use_lib_llvm = true;
} else if (mem.eql(u8, arg, "-fno-libLLVM")) {
use_lib_llvm = false;
} else if (mem.eql(u8, arg, "-fLLD")) {
use_lld = true;
} else if (mem.eql(u8, arg, "-fno-LLD")) {
@ -3119,6 +3126,7 @@ fn buildOutputType(
.want_tsan = want_tsan,
.want_compiler_rt = want_compiler_rt,
.use_llvm = use_llvm,
.use_lib_llvm = use_lib_llvm,
.use_lld = use_lld,
.use_clang = use_clang,
.hash_style = hash_style,

View File

@ -560,10 +560,6 @@ LLVMValueRef ZigLLVMBuildUShlSat(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRe
return wrap(call_inst);
}
LLVMValueRef LLVMBuildVectorSplat(LLVMBuilderRef B, unsigned elem_count, LLVMValueRef V, const char *Name) {
return wrap(unwrap(B)->CreateVectorSplat(elem_count, unwrap(V), Name));
}
void ZigLLVMFnSetSubprogram(LLVMValueRef fn, ZigLLVMDISubprogram *subprogram) {
assert( isa<Function>(unwrap(fn)) );
Function *unwrapped_function = reinterpret_cast<Function*>(unwrap(fn));