authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-30 14:31:46-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-30 18:33:02-07:00
log152462e2e1513ca9d7db5c2d6a2a61b547c5151c
treebb541574002b430386c403b1a45e7bc92b3c3c93
parent902dc8c721c762bc5d1b9786bad47b21da45042c

stage2: object format affects whether LLVM can be used


2 files changed, 19 insertions(+), 6 deletions(-)

src/Compilation.zig+1-5
...@@ -1024,10 +1024,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1024,10 +1024,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1024 if (options.use_llvm) |explicit|1024 if (options.use_llvm) |explicit|
1025 break :blk explicit;1025 break :blk explicit;
10261026
1027 // If we are outputting .c code we must use Zig backend.
1028 if (ofmt == .c)
1029 break :blk false;
1030
1031 // If emitting to LLVM bitcode object format, must use LLVM backend.1027 // If emitting to LLVM bitcode object format, must use LLVM backend.
1032 if (options.emit_llvm_ir != null or options.emit_llvm_bc != null)1028 if (options.emit_llvm_ir != null or options.emit_llvm_bc != null)
1033 break :blk true;1029 break :blk true;
...@@ -1042,7 +1038,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1042,7 +1038,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1042 break :blk true;1038 break :blk true;
10431039
1044 // If LLVM does not support the target, then we can't use it.1040 // If LLVM does not support the target, then we can't use it.
1045 if (!target_util.hasLlvmSupport(options.target))1041 if (!target_util.hasLlvmSupport(options.target, ofmt))
1046 break :blk false;1042 break :blk false;
10471043
1048 // Prefer LLVM for release builds.1044 // Prefer LLVM for release builds.
src/target.zig+18-1
...@@ -204,7 +204,24 @@ pub fn hasValgrindSupport(target: std.Target) bool {...@@ -204,7 +204,24 @@ pub fn hasValgrindSupport(target: std.Target) bool {
204/// The set of targets that LLVM has non-experimental support for.204/// The set of targets that LLVM has non-experimental support for.
205/// Used to select between LLVM backend and self-hosted backend when compiling in205/// Used to select between LLVM backend and self-hosted backend when compiling in
206/// release modes.206/// release modes.
207pub fn hasLlvmSupport(target: std.Target) bool {207pub fn hasLlvmSupport(target: std.Target, ofmt: std.Target.ObjectFormat) bool {
208 switch (ofmt) {
209 // LLVM does not support these object formats:
210 .c,
211 .plan9,
212 => return false,
213
214 .coff,
215 .elf,
216 .macho,
217 .wasm,
218 .spirv,
219 .hex,
220 .raw,
221 .nvptx,
222 => {},
223 }
224
208 return switch (target.cpu.arch) {225 return switch (target.cpu.arch) {
209 .arm,226 .arm,
210 .armeb,227 .armeb,