[llvm] 748f861 - llvm-reduce: Handle cloning for MachineJumpTableInfo (#69086)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 31 05:51:54 PDT 2023
Author: Matt Arsenault
Date: 2023-10-31T21:51:50+09:00
New Revision: 748f861bea5e22520e490efef15f334994602669
URL: https://github.com/llvm/llvm-project/commit/748f861bea5e22520e490efef15f334994602669
DIFF: https://github.com/llvm/llvm-project/commit/748f861bea5e22520e490efef15f334994602669.diff
LOG: llvm-reduce: Handle cloning for MachineJumpTableInfo (#69086)
Added:
llvm/test/tools/llvm-reduce/mir/preserve-jump-table-info.mir
Modified:
llvm/tools/llvm-reduce/ReducerWorkItem.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-reduce/mir/preserve-jump-table-info.mir b/llvm/test/tools/llvm-reduce/mir/preserve-jump-table-info.mir
new file mode 100644
index 000000000000000..3bfdc1c013c46f8
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/mir/preserve-jump-table-info.mir
@@ -0,0 +1,97 @@
+# REQUIRES: aarch64-registered-target
+# FIXME: Fails with -abort-on-invalid-reduction
+# RUN: llvm-reduce -simplify-mir --delta-passes=instructions -mtriple=aarch64-- --test FileCheck --test-arg --check-prefix=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t 2> %t.log
+# RUN: FileCheck --match-full-lines --check-prefix=RESULT %s < %t
+
+# Check that jump table info is preserved through cloning
+
+# CHECK-INTERESTINGNESS: MOVi32imm
+
+# RESULT: jumpTable:
+# RESULT-NEXT: kind: label-
diff erence32
+# RESULT-NEXT: entries:
+# RESULT-NEXT: - id: 0
+# RESULT-NEXT: blocks: [ '%bb.9', '%bb.5', '%bb.2', '%bb.2', '%bb.2', '%bb.2',
+# RESULT-NEXT: '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.6', '%bb.2',
+# RESULT-NEXT: '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.2',
+# RESULT-NEXT: '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.2',
+# RESULT-NEXT: '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.2',
+# RESULT-NEXT: '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.7', '%bb.2',
+# RESULT-NEXT: '%bb.2', '%bb.2', '%bb.2', '%bb.7' ]
+
+---
+name: widget
+tracksRegLiveness: true
+jumpTable:
+ kind: label-
diff erence32
+ entries:
+ - id: 0
+ blocks: [ '%bb.9', '%bb.5', '%bb.2', '%bb.2', '%bb.2', '%bb.2',
+ '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.6', '%bb.2',
+ '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.2',
+ '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.2',
+ '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.2',
+ '%bb.2', '%bb.2', '%bb.2', '%bb.2', '%bb.7', '%bb.2',
+ '%bb.2', '%bb.2', '%bb.2', '%bb.7' ]
+body: |
+ bb.0:
+ liveins: $w0, $w1, $x2, $x3, $x4, $w5, $w6
+
+ %0:gpr32 = COPY $w6
+ %1:gpr32 = COPY $w5
+ %2:gpr64common = COPY $x4
+ %3:gpr64 = COPY $x3
+ %4:gpr64common = COPY $x2
+ %5:gpr32common = COPY $w1
+ %6:gpr32 = COPY $w0
+ undef %7.sub_32:gpr64 = ORRWrs $wzr, %5, 0, implicit-def %7
+ %8:gpr64common = MOVaddrJT target-flags(aarch64-page) %jump-table.0, target-flags(aarch64-pageoff, aarch64-nc) %jump-table.0
+ %9:gpr32 = MOVi32imm 1
+ undef %10.sub_32:gpr64 = IMPLICIT_DEF
+
+ bb.1:
+
+ bb.2:
+ successors: %bb.3(0x0fbefbf0), %bb.4(0x70410410)
+
+ dead $wzr = SUBSWri %5, 39, 0, implicit-def $nzcv
+ Bcc 8, %bb.3, implicit killed $nzcv
+ B %bb.4
+
+ bb.3:
+ successors: %bb.11(0x00000000), %bb.2(0x80000000)
+
+ dead $wzr = SUBSWri %5, 64, 0, implicit-def $nzcv
+ Bcc 0, %bb.11, implicit killed $nzcv
+ B %bb.2
+
+ bb.4:
+ successors: %bb.9(0x01288b01), %bb.5(0x01288b01), %bb.2(0x11f46a91), %bb.6(0x23e8d524), %bb.7(0x47d1aa49)
+
+ early-clobber %11:gpr64, dead early-clobber %12:gpr64sp = JumpTableDest32 %8, %7, %jump-table.0
+ JUMP_TABLE_DEBUG_INFO 0
+ BR %11
+
+ bb.5:
+ B %bb.8
+
+ bb.6:
+ B %bb.2
+
+ bb.7:
+ B %bb.2
+
+ bb.8:
+ B %bb.8
+
+ bb.9:
+ TBZW %0, 0, %bb.1
+ B %bb.10
+
+ bb.10:
+ B %bb.1
+
+ bb.11:
+ BRK 1
+
+...
diff --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
index 2a327bf134601d6..f38d9b8a1d5f001 100644
--- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
+++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
@@ -19,6 +19,7 @@
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
@@ -153,6 +154,23 @@ static void cloneFrameInfo(
}
}
+static void cloneJumpTableInfo(
+ MachineFunction &DstMF, const MachineJumpTableInfo &SrcJTI,
+ const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB) {
+
+ auto *DstJTI = DstMF.getOrCreateJumpTableInfo(SrcJTI.getEntryKind());
+
+ std::vector<MachineBasicBlock *> DstBBs;
+
+ for (const MachineJumpTableEntry &Entry : SrcJTI.getJumpTables()) {
+ for (MachineBasicBlock *X : Entry.MBBs)
+ DstBBs.push_back(Src2DstMBB.find(X)->second);
+
+ DstJTI->createJumpTableIndex(DstBBs);
+ DstBBs.clear();
+ }
+}
+
static void cloneMemOperands(MachineInstr &DstMI, MachineInstr &SrcMI,
MachineFunction &SrcMF, MachineFunction &DstMF) {
// The new MachineMemOperands should be owned by the new function's
@@ -266,6 +284,10 @@ static std::unique_ptr<MachineFunction> cloneMF(MachineFunction *SrcMF,
// Copy stack objects and other info
cloneFrameInfo(DstMFI, SrcMFI, Src2DstMBB);
+ if (MachineJumpTableInfo *SrcJTI = SrcMF->getJumpTableInfo()) {
+ cloneJumpTableInfo(*DstMF, *SrcJTI, Src2DstMBB);
+ }
+
// Remap the debug info frame index references.
DstMF->VariableDbgInfos = SrcMF->VariableDbgInfos;
More information about the llvm-commits
mailing list