authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-08-31 22:50:10-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-08-31 23:36:25-07:00
log77516af118f219f9d73494c8a1d5df3e23672680
treeb9e6a0ef5556fca556a22ec2dc29610c4ad68041
parent7efca2e6f51458de8e70a6f5cbbc292026321681

stage2: update LLVM backend to for LLVM 13

There was some new code in master branch enumerating all the targets and a new target was added so we needed to add the glue code. This commit also introduces some build options to support experimental LLVM targets.

4 files changed, 111 insertions(+), 19 deletions(-)

build.zig+28
...@@ -64,6 +64,26 @@ pub fn build(b: *Builder) !void {...@@ -64,6 +64,26 @@ pub fn build(b: *Builder) !void {
64 const omit_stage2 = b.option(bool, "omit-stage2", "Do not include stage2 behind a feature flag inside stage1") orelse false;64 const omit_stage2 = b.option(bool, "omit-stage2", "Do not include stage2 behind a feature flag inside stage1") orelse false;
65 const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false;65 const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false;
66 const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (is_stage1 or static_llvm);66 const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (is_stage1 or static_llvm);
67 const llvm_has_m68k = b.option(
68 bool,
69 "llvm-has-m68k",
70 "Whether LLVM has the experimental target m68k enabled",
71 ) orelse false;
72 const llvm_has_csky = b.option(
73 bool,
74 "llvm-has-csky",
75 "Whether LLVM has the experimental target csky enabled",
76 ) orelse false;
77 const llvm_has_ve = b.option(
78 bool,
79 "llvm-has-ve",
80 "Whether LLVM has the experimental target ve enabled",
81 ) orelse false;
82 const llvm_has_arc = b.option(
83 bool,
84 "llvm-has-arc",
85 "Whether LLVM has the experimental target arc enabled",
86 ) orelse false;
67 const enable_macos_sdk = b.option(bool, "enable-macos-sdk", "Run tests requiring presence of macOS SDK and frameworks") orelse false;87 const enable_macos_sdk = b.option(bool, "enable-macos-sdk", "Run tests requiring presence of macOS SDK and frameworks") orelse false;
68 const config_h_path_option = b.option([]const u8, "config_h", "Path to the generated config.h");88 const config_h_path_option = b.option([]const u8, "config_h", "Path to the generated config.h");
6989
...@@ -115,6 +135,10 @@ pub fn build(b: *Builder) !void {...@@ -115,6 +135,10 @@ pub fn build(b: *Builder) !void {
115 exe_options.addOption(u32, "mem_leak_frames", mem_leak_frames);135 exe_options.addOption(u32, "mem_leak_frames", mem_leak_frames);
116 exe_options.addOption(bool, "skip_non_native", skip_non_native);136 exe_options.addOption(bool, "skip_non_native", skip_non_native);
117 exe_options.addOption(bool, "have_llvm", enable_llvm);137 exe_options.addOption(bool, "have_llvm", enable_llvm);
138 exe_options.addOption(bool, "llvm_has_m68k", llvm_has_m68k);
139 exe_options.addOption(bool, "llvm_has_csky", llvm_has_csky);
140 exe_options.addOption(bool, "llvm_has_ve", llvm_has_ve);
141 exe_options.addOption(bool, "llvm_has_arc", llvm_has_arc);
118142
119 if (enable_llvm) {143 if (enable_llvm) {
120 const cmake_cfg = if (static_llvm) null else findAndParseConfigH(b, config_h_path_option);144 const cmake_cfg = if (static_llvm) null else findAndParseConfigH(b, config_h_path_option);
...@@ -261,6 +285,10 @@ pub fn build(b: *Builder) !void {...@@ -261,6 +285,10 @@ pub fn build(b: *Builder) !void {
261 test_stage2_options.addOption(bool, "is_stage1", is_stage1);285 test_stage2_options.addOption(bool, "is_stage1", is_stage1);
262 test_stage2_options.addOption(bool, "omit_stage2", omit_stage2);286 test_stage2_options.addOption(bool, "omit_stage2", omit_stage2);
263 test_stage2_options.addOption(bool, "have_llvm", enable_llvm);287 test_stage2_options.addOption(bool, "have_llvm", enable_llvm);
288 test_stage2_options.addOption(bool, "llvm_has_m68k", llvm_has_m68k);
289 test_stage2_options.addOption(bool, "llvm_has_csky", llvm_has_csky);
290 test_stage2_options.addOption(bool, "llvm_has_ve", llvm_has_ve);
291 test_stage2_options.addOption(bool, "llvm_has_arc", llvm_has_arc);
264 test_stage2_options.addOption(bool, "enable_qemu", is_qemu_enabled);292 test_stage2_options.addOption(bool, "enable_qemu", is_qemu_enabled);
265 test_stage2_options.addOption(bool, "enable_wine", is_wine_enabled);293 test_stage2_options.addOption(bool, "enable_wine", is_wine_enabled);
266 test_stage2_options.addOption(bool, "enable_wasmtime", is_wasmtime_enabled);294 test_stage2_options.addOption(bool, "enable_wasmtime", is_wasmtime_enabled);
src/codegen/llvm.zig+61-19
...@@ -7,6 +7,7 @@ const link = @import("../link.zig");...@@ -7,6 +7,7 @@ const link = @import("../link.zig");
7const log = std.log.scoped(.codegen);7const log = std.log.scoped(.codegen);
8const math = std.math;8const math = std.math;
99
10const build_options = @import("build_options");
10const Module = @import("../Module.zig");11const Module = @import("../Module.zig");
11const TypedValue = @import("../TypedValue.zig");12const TypedValue = @import("../TypedValue.zig");
12const Zir = @import("../Zir.zig");13const Zir = @import("../Zir.zig");
...@@ -1969,7 +1970,7 @@ fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void {...@@ -1969,7 +1970,7 @@ fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void {
1969 llvm.LLVMInitializeAMDGPUAsmPrinter();1970 llvm.LLVMInitializeAMDGPUAsmPrinter();
1970 llvm.LLVMInitializeAMDGPUAsmParser();1971 llvm.LLVMInitializeAMDGPUAsmParser();
1971 },1972 },
1972 .arm, .armeb => {1973 .thumb, .thumbeb, .arm, .armeb => {
1973 llvm.LLVMInitializeARMTarget();1974 llvm.LLVMInitializeARMTarget();
1974 llvm.LLVMInitializeARMTargetInfo();1975 llvm.LLVMInitializeARMTargetInfo();
1975 llvm.LLVMInitializeARMTargetMC();1976 llvm.LLVMInitializeARMTargetMC();
...@@ -2072,24 +2073,65 @@ fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void {...@@ -2072,24 +2073,65 @@ fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void {
2072 llvm.LLVMInitializeXCoreTargetInfo();2073 llvm.LLVMInitializeXCoreTargetInfo();
2073 llvm.LLVMInitializeXCoreTargetMC();2074 llvm.LLVMInitializeXCoreTargetMC();
2074 llvm.LLVMInitializeXCoreAsmPrinter();2075 llvm.LLVMInitializeXCoreAsmPrinter();
2075 // There is no LLVMInitializeXCoreAsmParser function available.2076 // There is no LLVMInitializeXCoreAsmParser function.
2076 },2077 },
2077 .arc => {},2078 .m68k => {
2078 .csky => {},2079 if (build_options.llvm_has_m68k) {
2079 .r600 => {},2080 llvm.LLVMInitializeM68kTarget();
2080 .tce, .tcele => {},2081 llvm.LLVMInitializeM68kTargetInfo();
2081 .thumb, .thumbeb => {},2082 llvm.LLVMInitializeM68kTargetMC();
2082 .le32, .le64 => {},2083 llvm.LLVMInitializeM68kAsmPrinter();
2083 .amdil, .amdil64 => {},2084 llvm.LLVMInitializeM68kAsmParser();
2084 .hsail, .hsail64 => {},2085 }
2085 .spir, .spir64 => {},2086 },
2086 .kalimba => {},2087 .csky => {
2087 .shave => {},2088 if (build_options.llvm_has_csky) {
2088 .renderscript32 => {},2089 llvm.LLVMInitializeCSKYTarget();
2089 .renderscript64 => {},2090 llvm.LLVMInitializeCSKYTargetInfo();
2090 .ve => {},2091 llvm.LLVMInitializeCSKYTargetMC();
2091 .spu_2 => {},2092 // There is no LLVMInitializeCSKYAsmPrinter function.
2092 .spirv32 => {},2093 llvm.LLVMInitializeCSKYAsmParser();
2093 .spirv64 => {},2094 }
2095 },
2096 .ve => {
2097 if (build_options.llvm_has_ve) {
2098 llvm.LLVMInitializeVETarget();
2099 llvm.LLVMInitializeVETargetInfo();
2100 llvm.LLVMInitializeVETargetMC();
2101 llvm.LLVMInitializeVEAsmPrinter();
2102 llvm.LLVMInitializeVEAsmParser();
2103 }
2104 },
2105 .arc => {
2106 if (build_options.llvm_has_arc) {
2107 llvm.LLVMInitializeARCTarget();
2108 llvm.LLVMInitializeARCTargetInfo();
2109 llvm.LLVMInitializeARCTargetMC();
2110 llvm.LLVMInitializeARCAsmPrinter();
2111 // There is no LLVMInitializeARCAsmParser function.
2112 }
2113 },
2114
2115 // LLVM backends that have no initialization functions.
2116 .tce,
2117 .tcele,
2118 .r600,
2119 .le32,
2120 .le64,
2121 .amdil,
2122 .amdil64,
2123 .hsail,
2124 .hsail64,
2125 .shave,
2126 .spir,
2127 .spir64,
2128 .kalimba,
2129 .renderscript32,
2130 .renderscript64,
2131 => {},
2132
2133 .spu_2 => unreachable, // LLVM does not support this backend
2134 .spirv32 => unreachable, // LLVM does not support this backend
2135 .spirv64 => unreachable, // LLVM does not support this backend
2094 }2136 }
2095}2137}
src/codegen/llvm/bindings.zig+18
...@@ -614,6 +614,10 @@ pub extern fn LLVMInitializeSystemZTargetInfo() void;...@@ -614,6 +614,10 @@ pub extern fn LLVMInitializeSystemZTargetInfo() void;
614pub extern fn LLVMInitializeWebAssemblyTargetInfo() void;614pub extern fn LLVMInitializeWebAssemblyTargetInfo() void;
615pub extern fn LLVMInitializeX86TargetInfo() void;615pub extern fn LLVMInitializeX86TargetInfo() void;
616pub extern fn LLVMInitializeXCoreTargetInfo() void;616pub extern fn LLVMInitializeXCoreTargetInfo() void;
617pub extern fn LLVMInitializeM68kTargetInfo() void;
618pub extern fn LLVMInitializeCSKYTargetInfo() void;
619pub extern fn LLVMInitializeVETargetInfo() void;
620pub extern fn LLVMInitializeARCTargetInfo() void;
617621
618pub extern fn LLVMInitializeAArch64Target() void;622pub extern fn LLVMInitializeAArch64Target() void;
619pub extern fn LLVMInitializeAMDGPUTarget() void;623pub extern fn LLVMInitializeAMDGPUTarget() void;
...@@ -632,6 +636,10 @@ pub extern fn LLVMInitializeSystemZTarget() void;...@@ -632,6 +636,10 @@ pub extern fn LLVMInitializeSystemZTarget() void;
632pub extern fn LLVMInitializeWebAssemblyTarget() void;636pub extern fn LLVMInitializeWebAssemblyTarget() void;
633pub extern fn LLVMInitializeX86Target() void;637pub extern fn LLVMInitializeX86Target() void;
634pub extern fn LLVMInitializeXCoreTarget() void;638pub extern fn LLVMInitializeXCoreTarget() void;
639pub extern fn LLVMInitializeM68kTarget() void;
640pub extern fn LLVMInitializeVETarget() void;
641pub extern fn LLVMInitializeCSKYTarget() void;
642pub extern fn LLVMInitializeARCTarget() void;
635643
636pub extern fn LLVMInitializeAArch64TargetMC() void;644pub extern fn LLVMInitializeAArch64TargetMC() void;
637pub extern fn LLVMInitializeAMDGPUTargetMC() void;645pub extern fn LLVMInitializeAMDGPUTargetMC() void;
...@@ -650,6 +658,10 @@ pub extern fn LLVMInitializeSystemZTargetMC() void;...@@ -650,6 +658,10 @@ pub extern fn LLVMInitializeSystemZTargetMC() void;
650pub extern fn LLVMInitializeWebAssemblyTargetMC() void;658pub extern fn LLVMInitializeWebAssemblyTargetMC() void;
651pub extern fn LLVMInitializeX86TargetMC() void;659pub extern fn LLVMInitializeX86TargetMC() void;
652pub extern fn LLVMInitializeXCoreTargetMC() void;660pub extern fn LLVMInitializeXCoreTargetMC() void;
661pub extern fn LLVMInitializeM68kTargetMC() void;
662pub extern fn LLVMInitializeCSKYTargetMC() void;
663pub extern fn LLVMInitializeVETargetMC() void;
664pub extern fn LLVMInitializeARCTargetMC() void;
653665
654pub extern fn LLVMInitializeAArch64AsmPrinter() void;666pub extern fn LLVMInitializeAArch64AsmPrinter() void;
655pub extern fn LLVMInitializeAMDGPUAsmPrinter() void;667pub extern fn LLVMInitializeAMDGPUAsmPrinter() void;
...@@ -668,6 +680,9 @@ pub extern fn LLVMInitializeSystemZAsmPrinter() void;...@@ -668,6 +680,9 @@ pub extern fn LLVMInitializeSystemZAsmPrinter() void;
668pub extern fn LLVMInitializeWebAssemblyAsmPrinter() void;680pub extern fn LLVMInitializeWebAssemblyAsmPrinter() void;
669pub extern fn LLVMInitializeX86AsmPrinter() void;681pub extern fn LLVMInitializeX86AsmPrinter() void;
670pub extern fn LLVMInitializeXCoreAsmPrinter() void;682pub extern fn LLVMInitializeXCoreAsmPrinter() void;
683pub extern fn LLVMInitializeM68kAsmPrinter() void;
684pub extern fn LLVMInitializeVEAsmPrinter() void;
685pub extern fn LLVMInitializeARCAsmPrinter() void;
671686
672pub extern fn LLVMInitializeAArch64AsmParser() void;687pub extern fn LLVMInitializeAArch64AsmParser() void;
673pub extern fn LLVMInitializeAMDGPUAsmParser() void;688pub extern fn LLVMInitializeAMDGPUAsmParser() void;
...@@ -684,6 +699,9 @@ pub extern fn LLVMInitializeSparcAsmParser() void;...@@ -684,6 +699,9 @@ pub extern fn LLVMInitializeSparcAsmParser() void;
684pub extern fn LLVMInitializeSystemZAsmParser() void;699pub extern fn LLVMInitializeSystemZAsmParser() void;
685pub extern fn LLVMInitializeWebAssemblyAsmParser() void;700pub extern fn LLVMInitializeWebAssemblyAsmParser() void;
686pub extern fn LLVMInitializeX86AsmParser() void;701pub extern fn LLVMInitializeX86AsmParser() void;
702pub extern fn LLVMInitializeM68kAsmParser() void;
703pub extern fn LLVMInitializeCSKYAsmParser() void;
704pub extern fn LLVMInitializeVEAsmParser() void;
687705
688extern fn ZigLLDLinkCOFF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int;706extern fn ZigLLDLinkCOFF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int;
689extern fn ZigLLDLinkELF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int;707extern fn ZigLLDLinkELF(argc: c_int, argv: [*:null]const ?[*:0]const u8, can_exit_early: bool) c_int;
src/config.zig.in+4
...@@ -1,4 +1,8 @@...@@ -1,4 +1,8 @@
1pub const have_llvm = true;1pub const have_llvm = true;
2pub const llvm_has_m68k = false;
3pub const llvm_has_csky = false;
4pub const llvm_has_ve = false;
5pub const llvm_has_arc = false;
2pub const version: [:0]const u8 = "@ZIG_VERSION@";6pub const version: [:0]const u8 = "@ZIG_VERSION@";
3pub const semver = @import("std").SemanticVersion.parse(version) catch unreachable;7pub const semver = @import("std").SemanticVersion.parse(version) catch unreachable;
4pub const enable_logging: bool = @ZIG_ENABLE_LOGGING_BOOL@;8pub const enable_logging: bool = @ZIG_ENABLE_LOGGING_BOOL@;