[llvm-branch-commits] [llvm] 8f8c207 - [Verifier] Add tied-ness verification to statepoint intsruction

Serguei Katkov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jan 13 00:16:49 PST 2021


Author: Serguei Katkov
Date: 2021-01-13T14:40:44+07:00
New Revision: 8f8c207b8f2e69be652ef7afa30a92312bbb2bf0

URL: https://github.com/llvm/llvm-project/commit/8f8c207b8f2e69be652ef7afa30a92312bbb2bf0
DIFF: https://github.com/llvm/llvm-project/commit/8f8c207b8f2e69be652ef7afa30a92312bbb2bf0.diff

LOG: [Verifier] Add tied-ness verification to statepoint intsruction

Reviewers: reames, dantrushin
Reviewed By: reames, dantrushin
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D94483

Added: 
    llvm/test/MachineVerifier/verifier-statepoint.mir

Modified: 
    llvm/lib/CodeGen/MachineVerifier.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index 41fdf2f83444..1cfadef251c5 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -1663,6 +1663,22 @@ void MachineVerifier::visitMachineInstrBefore(const MachineInstr *MI) {
     VerifyStackMapConstant(SO.getNumAllocaIdx());
     VerifyStackMapConstant(SO.getNumGcMapEntriesIdx());
 
+    // Verify that all explicit statepoint defs are tied to gc operands as
+    // they are expected to be a relocation of gc operands.
+    unsigned FirstGCPtrIdx = SO.getFirstGCPtrIdx();
+    unsigned LastGCPtrIdx = SO.getNumAllocaIdx() - 2;
+    for (unsigned Idx = 0; Idx < MI->getNumDefs(); Idx++) {
+      unsigned UseOpIdx;
+      if (!MI->isRegTiedToUseOperand(Idx, &UseOpIdx)) {
+        report("STATEPOINT defs expected to be tied", MI);
+        break;
+      }
+      if (UseOpIdx < FirstGCPtrIdx || UseOpIdx > LastGCPtrIdx) {
+        report("STATEPOINT def tied to non-gc operand", MI);
+        break;
+      }
+    }
+
     // TODO: verify we have properly encoded deopt arguments
   } break;
   }

diff  --git a/llvm/test/MachineVerifier/verifier-statepoint.mir b/llvm/test/MachineVerifier/verifier-statepoint.mir
new file mode 100644
index 000000000000..c5c1717530da
--- /dev/null
+++ b/llvm/test/MachineVerifier/verifier-statepoint.mir
@@ -0,0 +1,30 @@
+# RUN: not --crash llc -o - %s -mtriple=x86_64-- -verify-machineinstrs -run-pass=none 2>&1 | FileCheck %s
+# REQUIRES: x86-registered-target
+
+# CHECK: Bad machine code: STATEPOINT defs expected to be tied
+# CHECK-NEXT: - function:    bad_statepoint
+# CHECK-NEXT: - basic block: %bb.0
+# CHECK-NEXT: - instruction: renamable $rdi = STATEPOINT 0, 0, 0, $r15, 2, 0, 2, 0, 2, 0, 2, 1, killed renamable $rdi, 2, 0, 2, 1, 0, 0, <regmask $bh $bl $bp $bph $bpl $bx $ebp $ebx $hbp $hbx $rbp $rbx $r12 $r13 $r14 $r15 $r12b $r13b $r14b $r15b $r12bh $r13bh $r14bh $r15bh $r12d $r13d $r14d $r15d $r12w $r13w $r14w $r15w $r12wh and 3 more...>, implicit-def $rsp, implicit-def $ssp
+
+# CHECK: Bad machine code: STATEPOINT def tied to non-gc operand
+# CHECK-NEXT: - function:    bad_statepoint
+# CHECK-NEXT: - basic block: %bb.0
+# CHECK-NEXT: - instruction: renamable $rdi = STATEPOINT 0, 0, 0, $r15, 2, 0, 2, 0, 2, 1, killed renamable $rdi(tied-def 0), 2, 0, 2, 0, 2, 1, 0, 0, <regmask $bh $bl $bp $bph $bpl $bx $ebp $ebx $hbp $hbx $rbp $rbx $r12 $r13 $r14 $r15 $r12b $r13b $r14b $r15b $r12bh $r13bh $r14bh $r15bh $r12d $r13d $r14d $r15d $r12w $r13w $r14w $r15w $r12wh and 3 more...>, implicit-def $rsp, implicit-def $ssp
+
+# CHECK: Bad machine code: STATEPOINT def tied to non-gc operand
+# CHECK-NEXT: - function:    bad_statepoint
+# CHECK-NEXT: - basic block: %bb.0
+# CHECK-NEXT: - instruction: renamable $r14, renamable $rdi = STATEPOINT 0, 0, 0, $r15, 2, 0, 2, 0, 2, 0, 2, 1, killed renamable $r14(tied-def 0), 2, 1, killed renamable $rdi(tied-def 1), 2, 1, 0, 0, <regmask $bh $bl $bp $bph $bpl $bx $ebp $ebx $hbp $hbx $rbp $rbx $r12 $r13 $r14 $r15 $r12b $r13b $r14b $r15b $r12bh $r13bh $r14bh $r15bh $r12d $r13d $r14d $r15d $r12w $r13w $r14w $r15w $r12wh and 3 more...>, implicit-def $rsp, implicit-def $ssp
+---
+name:              bad_statepoint
+tracksRegLiveness: true
+body:              |
+  bb.0:
+    liveins: $rdi, $r15, $r14
+
+    renamable $rdi = STATEPOINT 0, 0, 0, $r15, 2, 0, 2, 0, 2, 0, 2, 1, killed renamable $rdi, 2, 0, 2, 1, 0, 0, csr_64, implicit-def $rsp, implicit-def $ssp
+    renamable $rdi = STATEPOINT 0, 0, 0, $r15, 2, 0, 2, 0, 2, 1, killed renamable $rdi(tied-def 0), 2, 0, 2, 0, 2, 1, 0, 0, csr_64, implicit-def $rsp, implicit-def $ssp
+    renamable $r14, renamable $rdi = STATEPOINT 0, 0, 0, $r15, 2, 0, 2, 0, 2, 0, 2, 1, killed renamable $r14(tied-def 0), 2, 1, killed renamable $rdi(tied-def 1), 2, 1, 0, 0, csr_64, implicit-def $rsp, implicit-def $ssp
+    $rax = COPY killed renamable $rdi
+    RET 0, killed $rax
+...


        


More information about the llvm-branch-commits mailing list