authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-04 12:40:27+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-04 13:53:20+01:00
log8a73a965d3185cadee2bd819daa12b5b3f1daafc
tree1335bad7c1815691a90fa35cf7a72afe20bf8887
parent2307cf73b044527464e63aa315e3af343d6584ad
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

llvm: Add client request support for all archs supported by Valgrind.


2 files changed, 104 insertions(+), 26 deletions(-)

src/codegen/llvm.zig+67-15
...@@ -11595,29 +11595,81 @@ pub const FuncGen = struct {...@@ -11595,29 +11595,81 @@ pub const FuncGen = struct {
11595 template: [:0]const u8,11595 template: [:0]const u8,
11596 constraints: [:0]const u8,11596 constraints: [:0]const u8,
11597 } = switch (target.cpu.arch) {11597 } = switch (target.cpu.arch) {
11598 .x86 => .{11598 .arm, .armeb, .thumb, .thumbeb => .{
11599 .template =11599 .template =
11600 \\roll $$3, %edi ; roll $$13, %edi11600 \\ mov r12, r12, ror #3 ; mov r12, r12, ror #13
11601 \\roll $$61, %edi ; roll $$51, %edi11601 \\ mov r12, r12, ror #29 ; mov r12, r12, ror #19
11602 \\xchgl %ebx,%ebx11602 \\ orr r10, r10, r10
11603 ,11603 ,
11604 .constraints = "={edx},{eax},0,~{cc},~{memory}",11604 .constraints = "={r3},{r4},{r3},~{cc},~{memory}",
11605 },11605 },
11606 .x86_64 => .{11606 .aarch64, .aarch64_be => .{
11607 .template =11607 .template =
11608 \\rolq $$3, %rdi ; rolq $$13, %rdi11608 \\ ror x12, x12, #3 ; ror x12, x12, #13
11609 \\rolq $$61, %rdi ; rolq $$51, %rdi11609 \\ ror x12, x12, #51 ; ror x12, x12, #61
11610 \\xchgq %rbx,%rbx11610 \\ orr x10, x10, x10
11611 ,11611 ,
11612 .constraints = "={rdx},{rax},0,~{cc},~{memory}",11612 .constraints = "={x3},{x4},{x3},~{cc},~{memory}",
11613 },11613 },
11614 .aarch64, .aarch64_be => .{11614 .mips, .mipsel => .{
11615 .template =
11616 \\ srl $$0, $$0, 13
11617 \\ srl $$0, $$0, 29
11618 \\ srl $$0, $$0, 3
11619 \\ srl $$0, $$0, 19
11620 \\ or $$13, $$13, $$13
11621 ,
11622 .constraints = "={$11},{$12},{$11},~{memory}",
11623 },
11624 .mips64, .mips64el => .{
11625 .template =
11626 \\ dsll $$0, $$0, 3 ; dsll $$0, $$0, 13
11627 \\ dsll $$0, $$0, 29 ; dsll $$0, $$0, 19
11628 \\ or $$13, $$13, $$13
11629 ,
11630 .constraints = "={$11},{$12},{$11},~{memory}",
11631 },
11632 .powerpc, .powerpcle => .{
11633 .template =
11634 \\ rlwinm 0, 0, 3, 0, 31 ; rlwinm 0, 0, 13, 0, 31
11635 \\ rlwinm 0, 0, 29, 0, 31 ; rlwinm 0, 0, 19, 0, 31
11636 \\ or 1, 1, 1
11637 ,
11638 .constraints = "={r3},{r4},{r3},~{cc},~{memory}",
11639 },
11640 .powerpc64, .powerpc64le => .{
11641 .template =
11642 \\ rotldi 0, 0, 3 ; rotldi 0, 0, 13
11643 \\ rotldi 0, 0, 61 ; rotldi 0, 0, 51
11644 \\ or 1, 1, 1
11645 ,
11646 .constraints = "={r3},{r4},{r3},~{cc},~{memory}",
11647 },
11648 .s390x => .{
11649 .template =
11650 \\ lr %r15, %r15
11651 \\ lr %r1, %r1
11652 \\ lr %r2, %r2
11653 \\ lr %r3, %r3
11654 \\ lr %r2, %r2
11655 ,
11656 .constraints = "={r3},{r2},{r3},~{cc},~{memory}",
11657 },
11658 .x86 => .{
11659 .template =
11660 \\ roll $$3, %edi ; roll $$13, %edi
11661 \\ roll $$61, %edi ; roll $$51, %edi
11662 \\ xchgl %ebx, %ebx
11663 ,
11664 .constraints = "={edx},{eax},{edx},~{cc},~{memory}",
11665 },
11666 .x86_64 => .{
11615 .template =11667 .template =
11616 \\ror x12, x12, #3 ; ror x12, x12, #1311668 \\ rolq $$3, %rdi ; rolq $$13, %rdi
11617 \\ror x12, x12, #51 ; ror x12, x12, #6111669 \\ rolq $$61, %rdi ; rolq $$51, %rdi
11618 \\orr x10, x10, x1011670 \\ xchgq %rbx, %rbx
11619 ,11671 ,
11620 .constraints = "={x3},{x4},0,~{cc},~{memory}",11672 .constraints = "={rdx},{rax},{edx},~{cc},~{memory}",
11621 },11673 },
11622 else => unreachable,11674 else => unreachable,
11623 };11675 };
src/target.zig+37-11
...@@ -79,19 +79,45 @@ pub fn defaultSingleThreaded(target: std.Target) bool {...@@ -79,19 +79,45 @@ pub fn defaultSingleThreaded(target: std.Target) bool {
79 return false;79 return false;
80}80}
8181
82/// Valgrind supports more, but Zig does not support them yet.
83pub fn hasValgrindSupport(target: std.Target) bool {82pub fn hasValgrindSupport(target: std.Target) bool {
84 switch (target.cpu.arch) {83 // We can't currently output the necessary Valgrind client request assembly when using the C
85 .x86,84 // backend and compiling with an MSVC-like compiler.
86 .x86_64,85 const ofmt_c_msvc = (target.abi == .msvc or target.abi == .itanium) and target.ofmt == .c;
87 .aarch64,86
88 .aarch64_be,87 return switch (target.cpu.arch) {
89 => {88 .arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) {
90 return target.os.tag == .linux or target.os.tag == .solaris or target.os.tag == .illumos or89 .linux => true,
91 (target.os.tag == .windows and target.abi.isGnu());90 else => false,
92 },91 },
93 else => return false,92 .aarch64, .aarch64_be => switch (target.os.tag) {
94 }93 .linux, .freebsd => true,
94 else => false,
95 },
96 .mips, .mipsel, .mips64, .mips64el => switch (target.os.tag) {
97 .linux => true,
98 else => false,
99 },
100 .powerpc, .powerpcle, .powerpc64, .powerpc64le => switch (target.os.tag) {
101 .linux => true,
102 else => false,
103 },
104 .s390x => switch (target.os.tag) {
105 .linux => true,
106 else => false,
107 },
108 .x86 => switch (target.os.tag) {
109 .linux, .freebsd, .solaris, .illumos => true,
110 .windows => !ofmt_c_msvc,
111 else => false,
112 },
113 .x86_64 => switch (target.os.tag) {
114 .linux => target.abi != .gnux32 and target.abi != .muslx32,
115 .freebsd, .solaris, .illumos => true,
116 .windows => !ofmt_c_msvc,
117 else => false,
118 },
119 else => false,
120 };
95}121}
96122
97/// The set of targets that LLVM has non-experimental support for.123/// The set of targets that LLVM has non-experimental support for.