aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-07-11 18:41:59 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-07-12 18:38:11 -0700
commit8324a93f2e382036b3a923f4ac869cf0d80438a2 (patch)
tree12bcfd2221e2946997ed708b7e91260385e50eba /src/codegen/llvm.zig
parent0d164f9a25f05a2917f4e1d4eb21c85b3279b47b (diff)
downloadzig-8324a93f2e382036b3a923f4ac869cf0d80438a2.tar.gz
zig-8324a93f2e382036b3a923f4ac869cf0d80438a2.zip
LLVM: always add some clobbers for some architectures
For some targets, Clang unconditionally adds some clobbers to all inline assembly. While this is probably not strictly necessary, if we don't follow Clang's lead here then we may risk tripping LLVM bugs since anything not used by Clang tends to be buggy and regress often.
Diffstat (limited to 'src/codegen/llvm.zig')
-rw-r--r--src/codegen/llvm.zig19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 4333b34d98..8857c96bc1 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -5432,6 +5432,25 @@ pub const FuncGen = struct {
total_i += 1;
}
}
+
+ // For some targets, Clang unconditionally adds some clobbers to all inline assembly.
+ // While this is probably not strictly necessary, if we don't follow Clang's lead
+ // here then we may risk tripping LLVM bugs since anything not used by Clang tends
+ // to be buggy and regress often.
+ switch (target.cpu.arch) {
+ .x86_64, .i386 => {
+ if (total_i != 0) try llvm_constraints.append(self.gpa, ',');
+ try llvm_constraints.appendSlice(self.gpa, "~{dirflag},~{fpsr},~{flags}");
+ total_i += 3;
+ },
+ .mips, .mipsel, .mips64, .mips64el => {
+ if (total_i != 0) try llvm_constraints.append(self.gpa, ',');
+ try llvm_constraints.appendSlice(self.gpa, "~{$1}");
+ total_i += 1;
+ },
+ else => {},
+ }
+
const asm_source = std.mem.sliceAsBytes(self.air.extra[extra_i..])[0..extra.data.source_len];
// hackety hacks until stage2 has proper inline asm in the frontend.