Commit 5466e87fce
Changed files (9)
lib
std
src
lib/std/target.zig
@@ -804,6 +804,8 @@ pub const Target = struct {
hsail64,
spir,
spir64,
+ spirv32,
+ spirv64,
kalimba,
shave,
lanai,
@@ -815,8 +817,6 @@ pub const Target = struct {
// Stage1 currently assumes that architectures above this comment
// map one-to-one with the ZigLLVM_ArchType enum.
spu_2,
- spirv32,
- spirv64,
pub fn isX86(arch: Arch) bool {
return switch (arch) {
src/codegen/llvm/bindings.zig
@@ -331,10 +331,11 @@ pub const Module = opaque {
pub const getLastGlobalAlias = LLVMGetLastGlobalAlias;
extern fn LLVMGetLastGlobalAlias(M: *const Module) *const Value;
- pub const addAlias = LLVMAddAlias;
- extern fn LLVMAddAlias(
+ pub const addAlias = LLVMAddAlias2;
+ extern fn LLVMAddAlias2(
M: *const Module,
Ty: *const Type,
+ AddrSpace: c_uint,
Aliasee: *const Value,
Name: [*:0]const u8,
) *const Value;
@@ -458,8 +459,8 @@ pub const Builder = opaque {
pub const buildStore = LLVMBuildStore;
extern fn LLVMBuildStore(*const Builder, Val: *const Value, Ptr: *const Value) *const Value;
- pub const buildLoad = LLVMBuildLoad;
- extern fn LLVMBuildLoad(*const Builder, PointerVal: *const Value, Name: [*:0]const u8) *const Value;
+ pub const buildLoad = LLVMBuildLoad2;
+ extern fn LLVMBuildLoad2(*const Builder, Ty: *const Type, PointerVal: *const Value, Name: [*:0]const u8) *const Value;
pub const buildNeg = LLVMBuildNeg;
extern fn LLVMBuildNeg(*const Builder, V: *const Value, Name: [*:0]const u8) *const Value;
@@ -1067,9 +1068,9 @@ pub extern fn LLVMInitializeM68kAsmParser() void;
pub extern fn LLVMInitializeCSKYAsmParser() void;
pub extern fn LLVMInitializeVEAsmParser() void;
-extern fn ZigLLDLinkCOFF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int;
-extern fn ZigLLDLinkELF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int;
-extern fn ZigLLDLinkWasm(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int;
+extern fn ZigLLDLinkCOFF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool, disable_output: bool) c_int;
+extern fn ZigLLDLinkELF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool, disable_output: bool) c_int;
+extern fn ZigLLDLinkWasm(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool, disable_output: bool) c_int;
pub const LinkCOFF = ZigLLDLinkCOFF;
pub const LinkELF = ZigLLDLinkELF;
src/stage1/codegen.cpp
@@ -490,7 +490,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
for (size_t i = 1; i < fn->export_list.length; i += 1) {
GlobalExport *fn_export = &fn->export_list.items[i];
- LLVMAddAlias(g->module, LLVMTypeOf(llvm_fn), llvm_fn, buf_ptr(&fn_export->name));
+ LLVMAddAlias2(g->module, LLVMTypeOf(llvm_fn), 0, llvm_fn, buf_ptr(&fn_export->name));
}
}
@@ -901,10 +901,10 @@ static LLVMValueRef gen_store(CodeGen *g, LLVMValueRef value, LLVMValueRef ptr,
return gen_store_untyped(g, value, ptr, alignment, ptr_type->data.pointer.is_volatile);
}
-static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMValueRef ptr, uint32_t alignment, bool is_volatile,
- const char *name)
+static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMTypeRef elem_type, LLVMValueRef ptr,
+ uint32_t alignment, bool is_volatile, const char *name)
{
- LLVMValueRef result = LLVMBuildLoad(g->builder, ptr, name);
+ LLVMValueRef result = LLVMBuildLoad2(g->builder, elem_type, ptr, name);
if (is_volatile) LLVMSetVolatile(result, true);
if (alignment == 0) {
LLVMSetAlignment(result, LLVMABIAlignmentOfType(g->target_data_ref, LLVMGetElementType(LLVMTypeOf(ptr))));
@@ -916,8 +916,10 @@ static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMValueRef ptr, uint32_t alig
static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, const char *name) {
assert(ptr_type->id == ZigTypeIdPointer);
+ ZigType *elem_type = ptr_type->data.pointer.child_type;
uint32_t alignment = get_ptr_align(g, ptr_type);
- return gen_load_untyped(g, ptr, alignment, ptr_type->data.pointer.is_volatile, name);
+ return gen_load_untyped(g, get_llvm_type(g, elem_type), ptr, alignment,
+ ptr_type->data.pointer.is_volatile, name);
}
static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type, ZigType *ptr_type) {
@@ -1265,15 +1267,16 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
size_t len_field_index = slice_type->data.structure.fields[slice_len_index]->gen_index;
LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)len_field_index, "");
- LLVMValueRef len_value = gen_load_untyped(g, len_field_ptr, 0, false, "");
- LLVMValueRef index_val = gen_load_untyped(g, index_field_ptr, 0, false, "");
+ LLVMValueRef len_value = gen_load_untyped(g, usize_type_ref, len_field_ptr, 0, false, "");
+ LLVMValueRef index_val = gen_load_untyped(g, usize_type_ref, index_field_ptr, 0, false, "");
LLVMValueRef len_val_minus_one = LLVMBuildSub(g->builder, len_value, LLVMConstInt(usize_type_ref, 1, false), "");
LLVMValueRef masked_val = LLVMBuildAnd(g->builder, index_val, len_val_minus_one, "");
LLVMValueRef address_indices[] = {
masked_val,
};
- LLVMValueRef ptr_value = gen_load_untyped(g, ptr_field_ptr, 0, false, "");
+ LLVMTypeRef ptr_to_usize = LLVMPointerType(usize_type_ref, 0);
+ LLVMValueRef ptr_value = gen_load_untyped(g, ptr_to_usize, ptr_field_ptr, 0, false, "");
LLVMValueRef address_slot = LLVMBuildInBoundsGEP(g->builder, ptr_value, address_indices, 1, "");
gen_store_untyped(g, address_value, address_slot, 0, false);
@@ -8802,7 +8805,7 @@ static void do_code_gen(CodeGen *g) {
for (size_t export_i = 1; export_i < var->export_list.length; export_i += 1) {
GlobalExport *global_export = &var->export_list.items[export_i];
- LLVMAddAlias(g->module, LLVMTypeOf(var->value_ref), var->value_ref, buf_ptr(&global_export->name));
+ LLVMAddAlias2(g->module, LLVMTypeOf(var->value_ref), 0, var->value_ref, buf_ptr(&global_export->name));
}
}
src/stage1/target.cpp
@@ -60,6 +60,8 @@ static const ZigLLVM_ArchType arch_list[] = {
ZigLLVM_hsail64, // AMD HSAIL with 64-bit pointers
ZigLLVM_spir, // SPIR: standard portable IR for OpenCL 32-bit version
ZigLLVM_spir64, // SPIR: standard portable IR for OpenCL 64-bit version
+ ZigLLVM_spirv32, // SPIR-V with 32-bit pointers
+ ZigLLVM_spirv64, // SPIR-V with 64-bit pointers
ZigLLVM_kalimba, // Kalimba: generic kalimba
ZigLLVM_shave, // SHAVE: Movidius vector VLIW processors
ZigLLVM_lanai, // Lanai: Lanai 32-bit
src/clang.zig
@@ -1104,6 +1104,7 @@ pub const TypeClass = enum(c_int) {
VariableArray,
Atomic,
Attributed,
+ BitInt,
BlockPointer,
Builtin,
Complex,
@@ -1111,13 +1112,12 @@ pub const TypeClass = enum(c_int) {
Auto,
DeducedTemplateSpecialization,
DependentAddressSpace,
- DependentExtInt,
+ DependentBitInt,
DependentName,
DependentSizedExtVector,
DependentTemplateSpecialization,
DependentVector,
Elaborated,
- ExtInt,
FunctionNoProto,
FunctionProto,
InjectedClassName,
@@ -1146,6 +1146,7 @@ pub const TypeClass = enum(c_int) {
Typedef,
UnaryTransform,
UnresolvedUsing,
+ Using,
Vector,
ExtVector,
};
@@ -1187,6 +1188,7 @@ const StmtClass = enum(c_int) {
OMPDistributeSimdDirectiveClass,
OMPForDirectiveClass,
OMPForSimdDirectiveClass,
+ OMPGenericLoopDirectiveClass,
OMPMasterTaskLoopDirectiveClass,
OMPMasterTaskLoopSimdDirectiveClass,
OMPParallelForDirectiveClass,
@@ -1210,6 +1212,7 @@ const StmtClass = enum(c_int) {
OMPUnrollDirectiveClass,
OMPMaskedDirectiveClass,
OMPMasterDirectiveClass,
+ OMPMetaDirectiveClass,
OMPOrderedDirectiveClass,
OMPParallelDirectiveClass,
OMPParallelMasterDirectiveClass,
@@ -1746,6 +1749,7 @@ pub const BuiltinTypeKind = enum(c_int) {
Float16,
BFloat16,
Float128,
+ Ibm128,
NullPtr,
ObjCId,
ObjCClass,
src/zig_clang.cpp
@@ -294,13 +294,14 @@ void ZigClang_detect_enum_TypeClass(clang::Type::TypeClass ty) {
case clang::Type::DependentSizedArray:
case clang::Type::DependentSizedExtVector:
case clang::Type::DependentAddressSpace:
- case clang::Type::DependentExtInt:
+ case clang::Type::DependentBitInt:
case clang::Type::Vector:
case clang::Type::DependentVector:
case clang::Type::ExtVector:
case clang::Type::FunctionProto:
case clang::Type::FunctionNoProto:
case clang::Type::UnresolvedUsing:
+ case clang::Type::Using:
case clang::Type::Paren:
case clang::Type::Typedef:
case clang::Type::MacroQualified:
@@ -315,8 +316,8 @@ void ZigClang_detect_enum_TypeClass(clang::Type::TypeClass ty) {
case clang::Type::Record:
case clang::Type::Enum:
case clang::Type::Elaborated:
- case clang::Type::ExtInt:
case clang::Type::Attributed:
+ case clang::Type::BitInt:
case clang::Type::TemplateTypeParm:
case clang::Type::SubstTemplateTypeParm:
case clang::Type::SubstTemplateTypeParmPack:
@@ -345,6 +346,7 @@ static_assert((clang::Type::TypeClass)ZigClangType_IncompleteArray == clang::Typ
static_assert((clang::Type::TypeClass)ZigClangType_VariableArray == clang::Type::VariableArray, "");
static_assert((clang::Type::TypeClass)ZigClangType_Atomic == clang::Type::Atomic, "");
static_assert((clang::Type::TypeClass)ZigClangType_Attributed == clang::Type::Attributed, "");
+static_assert((clang::Type::TypeClass)ZigClangType_BitInt == clang::Type::BitInt, "");
static_assert((clang::Type::TypeClass)ZigClangType_BlockPointer == clang::Type::BlockPointer, "");
static_assert((clang::Type::TypeClass)ZigClangType_Builtin == clang::Type::Builtin, "");
static_assert((clang::Type::TypeClass)ZigClangType_Complex == clang::Type::Complex, "");
@@ -352,13 +354,12 @@ static_assert((clang::Type::TypeClass)ZigClangType_Decltype == clang::Type::Decl
static_assert((clang::Type::TypeClass)ZigClangType_Auto == clang::Type::Auto, "");
static_assert((clang::Type::TypeClass)ZigClangType_DeducedTemplateSpecialization == clang::Type::DeducedTemplateSpecialization, "");
static_assert((clang::Type::TypeClass)ZigClangType_DependentAddressSpace == clang::Type::DependentAddressSpace, "");
-static_assert((clang::Type::TypeClass)ZigClangType_DependentExtInt == clang::Type::DependentExtInt, "");
+static_assert((clang::Type::TypeClass)ZigClangType_DependentBitInt == clang::Type::DependentBitInt, "");
static_assert((clang::Type::TypeClass)ZigClangType_DependentName == clang::Type::DependentName, "");
static_assert((clang::Type::TypeClass)ZigClangType_DependentSizedExtVector == clang::Type::DependentSizedExtVector, "");
static_assert((clang::Type::TypeClass)ZigClangType_DependentTemplateSpecialization == clang::Type::DependentTemplateSpecialization, "");
static_assert((clang::Type::TypeClass)ZigClangType_DependentVector == clang::Type::DependentVector, "");
static_assert((clang::Type::TypeClass)ZigClangType_Elaborated == clang::Type::Elaborated, "");
-static_assert((clang::Type::TypeClass)ZigClangType_ExtInt == clang::Type::ExtInt, "");
static_assert((clang::Type::TypeClass)ZigClangType_FunctionNoProto == clang::Type::FunctionNoProto, "");
static_assert((clang::Type::TypeClass)ZigClangType_FunctionProto == clang::Type::FunctionProto, "");
static_assert((clang::Type::TypeClass)ZigClangType_InjectedClassName == clang::Type::InjectedClassName, "");
@@ -387,6 +388,7 @@ static_assert((clang::Type::TypeClass)ZigClangType_TypeOf == clang::Type::TypeOf
static_assert((clang::Type::TypeClass)ZigClangType_Typedef == clang::Type::Typedef, "");
static_assert((clang::Type::TypeClass)ZigClangType_UnaryTransform == clang::Type::UnaryTransform, "");
static_assert((clang::Type::TypeClass)ZigClangType_UnresolvedUsing == clang::Type::UnresolvedUsing, "");
+static_assert((clang::Type::TypeClass)ZigClangType_Using == clang::Type::Using, "");
static_assert((clang::Type::TypeClass)ZigClangType_Vector == clang::Type::Vector, "");
static_assert((clang::Type::TypeClass)ZigClangType_ExtVector == clang::Type::ExtVector, "");
@@ -429,6 +431,7 @@ void ZigClang_detect_enum_StmtClass(clang::Stmt::StmtClass x) {
case clang::Stmt::OMPDistributeSimdDirectiveClass:
case clang::Stmt::OMPForDirectiveClass:
case clang::Stmt::OMPForSimdDirectiveClass:
+ case clang::Stmt::OMPGenericLoopDirectiveClass:
case clang::Stmt::OMPMasterTaskLoopDirectiveClass:
case clang::Stmt::OMPMasterTaskLoopSimdDirectiveClass:
case clang::Stmt::OMPParallelForDirectiveClass:
@@ -452,6 +455,7 @@ void ZigClang_detect_enum_StmtClass(clang::Stmt::StmtClass x) {
case clang::Stmt::OMPUnrollDirectiveClass:
case clang::Stmt::OMPMaskedDirectiveClass:
case clang::Stmt::OMPMasterDirectiveClass:
+ case clang::Stmt::OMPMetaDirectiveClass:
case clang::Stmt::OMPOrderedDirectiveClass:
case clang::Stmt::OMPParallelDirectiveClass:
case clang::Stmt::OMPParallelMasterDirectiveClass:
@@ -654,6 +658,7 @@ static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPDistributeParallelForSimdD
static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPDistributeSimdDirectiveClass == clang::Stmt::OMPDistributeSimdDirectiveClass, "");
static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPForDirectiveClass == clang::Stmt::OMPForDirectiveClass, "");
static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPForSimdDirectiveClass == clang::Stmt::OMPForSimdDirectiveClass, "");
+static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPGenericLoopDirectiveClass == clang::Stmt::OMPGenericLoopDirectiveClass, "");
static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPMasterTaskLoopDirectiveClass == clang::Stmt::OMPMasterTaskLoopDirectiveClass, "");
static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPMasterTaskLoopSimdDirectiveClass == clang::Stmt::OMPMasterTaskLoopSimdDirectiveClass, "");
static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPParallelForDirectiveClass == clang::Stmt::OMPParallelForDirectiveClass, "");
@@ -677,6 +682,7 @@ static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPTileDirectiveClass == clan
static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPUnrollDirectiveClass == clang::Stmt::OMPUnrollDirectiveClass, "");
static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPMaskedDirectiveClass == clang::Stmt::OMPMaskedDirectiveClass, "");
static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPMasterDirectiveClass == clang::Stmt::OMPMasterDirectiveClass, "");
+static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPMetaDirectiveClass == clang::Stmt::OMPMetaDirectiveClass, "");
static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPOrderedDirectiveClass == clang::Stmt::OMPOrderedDirectiveClass, "");
static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPParallelDirectiveClass == clang::Stmt::OMPParallelDirectiveClass, "");
static_assert((clang::Stmt::StmtClass)ZigClangStmt_OMPParallelMasterDirectiveClass == clang::Stmt::OMPParallelMasterDirectiveClass, "");
@@ -1269,6 +1275,7 @@ void ZigClang_detect_enum_BuiltinTypeKind(clang::BuiltinType::Kind x) {
case clang::BuiltinType::Float16:
case clang::BuiltinType::BFloat16:
case clang::BuiltinType::Float128:
+ case clang::BuiltinType::Ibm128:
case clang::BuiltinType::NullPtr:
case clang::BuiltinType::ObjCId:
case clang::BuiltinType::ObjCClass:
@@ -1510,6 +1517,7 @@ static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeLongDouble == clang::
static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeFloat16 == clang::BuiltinType::Float16, "");
static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeBFloat16 == clang::BuiltinType::BFloat16, "");
static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeFloat128 == clang::BuiltinType::Float128, "");
+static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeIbm128 == clang::BuiltinType::Ibm128, "");
static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeNullPtr == clang::BuiltinType::NullPtr, "");
static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeObjCId == clang::BuiltinType::ObjCId, "");
static_assert((clang::BuiltinType::Kind)ZigClangBuiltinTypeObjCClass == clang::BuiltinType::ObjCClass, "");
src/zig_clang.h
@@ -251,6 +251,7 @@ enum ZigClangTypeClass {
ZigClangType_VariableArray,
ZigClangType_Atomic,
ZigClangType_Attributed,
+ ZigClangType_BitInt,
ZigClangType_BlockPointer,
ZigClangType_Builtin,
ZigClangType_Complex,
@@ -258,13 +259,12 @@ enum ZigClangTypeClass {
ZigClangType_Auto,
ZigClangType_DeducedTemplateSpecialization,
ZigClangType_DependentAddressSpace,
- ZigClangType_DependentExtInt,
+ ZigClangType_DependentBitInt,
ZigClangType_DependentName,
ZigClangType_DependentSizedExtVector,
ZigClangType_DependentTemplateSpecialization,
ZigClangType_DependentVector,
ZigClangType_Elaborated,
- ZigClangType_ExtInt,
ZigClangType_FunctionNoProto,
ZigClangType_FunctionProto,
ZigClangType_InjectedClassName,
@@ -293,6 +293,7 @@ enum ZigClangTypeClass {
ZigClangType_Typedef,
ZigClangType_UnaryTransform,
ZigClangType_UnresolvedUsing,
+ ZigClangType_Using,
ZigClangType_Vector,
ZigClangType_ExtVector,
};
@@ -334,6 +335,7 @@ enum ZigClangStmtClass {
ZigClangStmt_OMPDistributeSimdDirectiveClass,
ZigClangStmt_OMPForDirectiveClass,
ZigClangStmt_OMPForSimdDirectiveClass,
+ ZigClangStmt_OMPGenericLoopDirectiveClass,
ZigClangStmt_OMPMasterTaskLoopDirectiveClass,
ZigClangStmt_OMPMasterTaskLoopSimdDirectiveClass,
ZigClangStmt_OMPParallelForDirectiveClass,
@@ -357,6 +359,7 @@ enum ZigClangStmtClass {
ZigClangStmt_OMPUnrollDirectiveClass,
ZigClangStmt_OMPMaskedDirectiveClass,
ZigClangStmt_OMPMasterDirectiveClass,
+ ZigClangStmt_OMPMetaDirectiveClass,
ZigClangStmt_OMPOrderedDirectiveClass,
ZigClangStmt_OMPParallelDirectiveClass,
ZigClangStmt_OMPParallelMasterDirectiveClass,
@@ -893,6 +896,7 @@ enum ZigClangBuiltinTypeKind {
ZigClangBuiltinTypeFloat16,
ZigClangBuiltinTypeBFloat16,
ZigClangBuiltinTypeFloat128,
+ ZigClangBuiltinTypeIbm128,
ZigClangBuiltinTypeNullPtr,
ZigClangBuiltinTypeObjCId,
ZigClangBuiltinTypeObjCClass,
src/zig_llvm.cpp
@@ -35,6 +35,8 @@
#include <llvm/IR/Verifier.h>
#include <llvm/InitializePasses.h>
#include <llvm/MC/SubtargetFeature.h>
+#include <llvm/MC/TargetRegistry.h>
+#include <llvm/Passes/OptimizationLevel.h>
#include <llvm/Passes/PassBuilder.h>
#include <llvm/Passes/StandardInstrumentations.h>
#include <llvm/Object/Archive.h>
@@ -51,7 +53,6 @@
#include <llvm/Support/TimeProfiler.h>
#include <llvm/Support/Timer.h>
#include <llvm/Support/raw_ostream.h>
-#include <llvm/Support/TargetRegistry.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/Target/CodeGenCWrappers.h>
#include <llvm/Transforms/IPO.h>
@@ -273,7 +274,7 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
TargetMachine &target_machine = *reinterpret_cast<TargetMachine*>(targ_machine_ref);
target_machine.setO0WantsFastISel(true);
- Module &module = *unwrap(module_ref);
+ Module &llvm_module = *unwrap(module_ref);
// Pipeline configurations
PipelineTuningOptions pipeline_opts;
@@ -290,7 +291,6 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
PassBuilder pass_builder(&target_machine, pipeline_opts,
None, &instr_callbacks);
- using OptimizationLevel = typename PassBuilder::OptimizationLevel;
LoopAnalysisManager loop_am;
FunctionAnalysisManager function_am;
@@ -302,7 +302,7 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
return pass_builder.buildDefaultAAPipeline();
});
- Triple target_triple(module.getTargetTriple());
+ Triple target_triple(llvm_module.getTargetTriple());
auto tlii = std::make_unique<TargetLibraryInfoImpl>(target_triple);
function_am.registerPass([&] { return TargetLibraryAnalysis(*tlii); });
@@ -339,9 +339,9 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
// Thread sanitizer
if (tsan) {
- pass_builder.registerOptimizerLastEPCallback(
- [](ModulePassManager &module_pm, OptimizationLevel level) {
- module_pm.addPass(ThreadSanitizerPass());
+ pass_builder.registerOptimizerLastEPCallback([](ModulePassManager &module_pm, OptimizationLevel level) {
+ module_pm.addPass(ModuleThreadSanitizerPass());
+ module_pm.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
});
}
@@ -383,10 +383,10 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
}
// Optimization phase
- module_pm.run(module, module_am);
+ module_pm.run(llvm_module, module_am);
// Code generation phase
- codegen_pm.run(module);
+ codegen_pm.run(llvm_module);
if (llvm_ir_filename) {
if (LLVMPrintModuleToFile(module_ref, llvm_ir_filename, error_message)) {
@@ -395,10 +395,10 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
}
if (dest_bin && lto) {
- WriteBitcodeToFile(module, *dest_bin);
+ WriteBitcodeToFile(llvm_module, *dest_bin);
}
if (dest_bitcode) {
- WriteBitcodeToFile(module, *dest_bitcode);
+ WriteBitcodeToFile(llvm_module, *dest_bitcode);
}
if (time_report) {
@@ -421,7 +421,7 @@ LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *A
unsigned NumArgs, ZigLLVM_CallingConv CC, ZigLLVM_CallAttr attr, const char *Name)
{
Value *V = unwrap(Fn);
- FunctionType *FnT = cast<FunctionType>(cast<PointerType>(V->getType())->getElementType());
+ FunctionType *FnT = cast<FunctionType>(V->getType()->getNonOpaquePointerElementType());
CallInst *call_inst = CallInst::Create(FnT, V, makeArrayRef(unwrap(Args), NumArgs), Name);
call_inst->setCallingConv(static_cast<CallingConv::ID>(CC));
switch (attr) {
@@ -431,13 +431,13 @@ LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *A
call_inst->setTailCallKind(CallInst::TCK_NoTail);
break;
case ZigLLVM_CallAttrNeverInline:
- call_inst->addAttribute(AttributeList::FunctionIndex, Attribute::NoInline);
+ call_inst->addFnAttr(Attribute::NoInline);
break;
case ZigLLVM_CallAttrAlwaysTail:
call_inst->setTailCallKind(CallInst::TCK_MustTail);
break;
case ZigLLVM_CallAttrAlwaysInline:
- call_inst->addAttribute(AttributeList::FunctionIndex, Attribute::AlwaysInline);
+ call_inst->addFnAttr(Attribute::AlwaysInline);
break;
}
return wrap(unwrap(B)->Insert(call_inst));
@@ -972,44 +972,28 @@ void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state) {
void ZigLLVMAddByValAttr(LLVMValueRef fn_ref, unsigned ArgNo, LLVMTypeRef type_val) {
Function *func = unwrap<Function>(fn_ref);
- const AttributeList attr_set = func->getAttributes();
- AttrBuilder attr_builder;
+ AttrBuilder attr_builder(func->getContext());
Type *llvm_type = unwrap<Type>(type_val);
attr_builder.addByValAttr(llvm_type);
- const AttributeList new_attr_set = attr_set.addAttributes(func->getContext(), ArgNo + 1, attr_builder);
- func->setAttributes(new_attr_set);
+ func->addParamAttrs(ArgNo + 1, attr_builder);
}
void ZigLLVMAddSretAttr(LLVMValueRef fn_ref, unsigned ArgNo, LLVMTypeRef type_val) {
Function *func = unwrap<Function>(fn_ref);
- const AttributeList attr_set = func->getAttributes();
- AttrBuilder attr_builder;
+ AttrBuilder attr_builder(func->getContext());
Type *llvm_type = unwrap<Type>(type_val);
attr_builder.addStructRetAttr(llvm_type);
- const AttributeList new_attr_set = attr_set.addAttributes(func->getContext(), ArgNo + 1, attr_builder);
- func->setAttributes(new_attr_set);
+ func->addParamAttrs(ArgNo + 1, attr_builder);
}
void ZigLLVMAddFunctionAttr(LLVMValueRef fn_ref, const char *attr_name, const char *attr_value) {
Function *func = unwrap<Function>(fn_ref);
- const AttributeList attr_set = func->getAttributes();
- AttrBuilder attr_builder;
- if (attr_value) {
- attr_builder.addAttribute(attr_name, attr_value);
- } else {
- attr_builder.addAttribute(attr_name);
- }
- const AttributeList new_attr_set = attr_set.addAttributes(func->getContext(),
- AttributeList::FunctionIndex, attr_builder);
- func->setAttributes(new_attr_set);
+ func->addFnAttr(attr_name, attr_value);
}
void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn_ref) {
Function *func = unwrap<Function>(fn_ref);
- const AttributeList attr_set = func->getAttributes();
- const AttributeList new_attr_set = attr_set.addAttribute(func->getContext(), AttributeList::FunctionIndex,
- Attribute::Cold);
- func->setAttributes(new_attr_set);
+ func->addFnAttr(Attribute::Cold);
}
void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv) {
@@ -1102,12 +1086,9 @@ void ZigLLVMSetTailCall(LLVMValueRef Call) {
}
void ZigLLVMSetCallSret(LLVMValueRef Call, LLVMTypeRef return_type) {
- const AttributeList attr_set = unwrap<CallInst>(Call)->getAttributes();
- AttrBuilder attr_builder;
+ CallInst *call_inst = unwrap<CallInst>(Call);
Type *llvm_type = unwrap<Type>(return_type);
- attr_builder.addStructRetAttr(llvm_type);
- const AttributeList new_attr_set = attr_set.addAttributes(unwrap<CallInst>(Call)->getContext(), 1, attr_builder);
- unwrap<CallInst>(Call)->setAttributes(new_attr_set);
+ call_inst->addParamAttr(1, Attribute::getWithStructRetType(call_inst->getContext(), llvm_type));
}
void ZigLLVMFunctionSetPrefixData(LLVMValueRef function, LLVMValueRef data) {
@@ -1252,19 +1233,19 @@ bool ZigLLVMWriteArchive(const char *archive_name, const char **file_names, size
return false;
}
-int ZigLLDLinkCOFF(int argc, const char **argv, bool can_exit_early) {
+int ZigLLDLinkCOFF(int argc, const char **argv, bool can_exit_early, bool disable_output) {
std::vector<const char *> args(argv, argv + argc);
- return lld::coff::link(args, can_exit_early, llvm::outs(), llvm::errs());
+ return lld::coff::link(args, llvm::outs(), llvm::errs(), can_exit_early, disable_output);
}
-int ZigLLDLinkELF(int argc, const char **argv, bool can_exit_early) {
+int ZigLLDLinkELF(int argc, const char **argv, bool can_exit_early, bool disable_output) {
std::vector<const char *> args(argv, argv + argc);
- return lld::elf::link(args, can_exit_early, llvm::outs(), llvm::errs());
+ return lld::elf::link(args, llvm::outs(), llvm::errs(), can_exit_early, disable_output);
}
-int ZigLLDLinkWasm(int argc, const char **argv, bool can_exit_early) {
+int ZigLLDLinkWasm(int argc, const char **argv, bool can_exit_early, bool disable_output) {
std::vector<const char *> args(argv, argv + argc);
- return lld::wasm::link(args, can_exit_early, llvm::outs(), llvm::errs());
+ return lld::wasm::link(args, llvm::outs(), llvm::errs(), can_exit_early, disable_output);
}
inline LLVMAttributeRef wrap(Attribute Attr) {
@@ -1370,6 +1351,8 @@ static_assert((Triple::ArchType)ZigLLVM_hsail == Triple::hsail, "");
static_assert((Triple::ArchType)ZigLLVM_hsail64 == Triple::hsail64, "");
static_assert((Triple::ArchType)ZigLLVM_spir == Triple::spir, "");
static_assert((Triple::ArchType)ZigLLVM_spir64 == Triple::spir64, "");
+static_assert((Triple::ArchType)ZigLLVM_spirv32 == Triple::spirv32, "");
+static_assert((Triple::ArchType)ZigLLVM_spirv64 == Triple::spirv64, "");
static_assert((Triple::ArchType)ZigLLVM_kalimba == Triple::kalimba, "");
static_assert((Triple::ArchType)ZigLLVM_shave == Triple::shave, "");
static_assert((Triple::ArchType)ZigLLVM_lanai == Triple::lanai, "");
src/zig_llvm.h
@@ -346,6 +346,8 @@ enum ZigLLVM_ArchType {
ZigLLVM_hsail64, // AMD HSAIL with 64-bit pointers
ZigLLVM_spir, // SPIR: standard portable IR for OpenCL 32-bit version
ZigLLVM_spir64, // SPIR: standard portable IR for OpenCL 64-bit version
+ ZigLLVM_spirv32, // SPIR-V with 32-bit pointers
+ ZigLLVM_spirv64, // SPIR-V with 64-bit pointers
ZigLLVM_kalimba, // Kalimba: generic kalimba
ZigLLVM_shave, // SHAVE: Movidius vector VLIW processors
ZigLLVM_lanai, // Lanai: Lanai 32-bit
@@ -512,9 +514,9 @@ ZIG_EXTERN_C const char *ZigLLVMGetVendorTypeName(enum ZigLLVM_VendorType vendor
ZIG_EXTERN_C const char *ZigLLVMGetOSTypeName(enum ZigLLVM_OSType os);
ZIG_EXTERN_C const char *ZigLLVMGetEnvironmentTypeName(enum ZigLLVM_EnvironmentType abi);
-ZIG_EXTERN_C int ZigLLDLinkCOFF(int argc, const char **argv, bool can_exit_early);
-ZIG_EXTERN_C int ZigLLDLinkELF(int argc, const char **argv, bool can_exit_early);
-ZIG_EXTERN_C int ZigLLDLinkWasm(int argc, const char **argv, bool can_exit_early);
+ZIG_EXTERN_C int ZigLLDLinkCOFF(int argc, const char **argv, bool can_exit_early, bool disable_output);
+ZIG_EXTERN_C int ZigLLDLinkELF(int argc, const char **argv, bool can_exit_early, bool disable_output);
+ZIG_EXTERN_C int ZigLLDLinkWasm(int argc, const char **argv, bool can_exit_early, bool disable_output);
ZIG_EXTERN_C bool ZigLLVMWriteArchive(const char *archive_name, const char **file_names, size_t file_name_count,
enum ZigLLVM_OSType os_type);