-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[CodeGen] Add a pass for testing finalizeBundle #149813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This allows for unit testing of finalizeBundle with standard MIR tests using update_mir_test_checks.py.
@llvm/pr-subscribers-backend-amdgpu Author: Jay Foad (jayfoad) ChangesThis allows for unit testing of finalizeBundle with standard MIR tests Full diff: https://github.com/llvm/llvm-project/pull/149813.diff 5 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/Passes.h b/llvm/include/llvm/CodeGen/Passes.h
index 714285eb5d5d4..cad8ea5a28dcc 100644
--- a/llvm/include/llvm/CodeGen/Passes.h
+++ b/llvm/include/llvm/CodeGen/Passes.h
@@ -623,6 +623,9 @@ LLVM_ABI ModulePass *createWindowsSecureHotPatchingPass();
/// Lowers KCFI operand bundles for indirect calls.
LLVM_ABI FunctionPass *createKCFIPass();
+
+/// A pass for testing finalizeBundle.
+LLVM_ABI extern char &FinalizeBundleTestID;
} // namespace llvm
#endif
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index 2e231cfba2443..ccb5711e55820 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -340,6 +340,7 @@ LLVM_ABI void initializeWindowsSecureHotPatchingPass(PassRegistry &);
LLVM_ABI void initializeWinEHPreparePass(PassRegistry &);
LLVM_ABI void initializeWriteBitcodePassPass(PassRegistry &);
LLVM_ABI void initializeXRayInstrumentationLegacyPass(PassRegistry &);
+LLVM_ABI void initializeFinalizeBundleTestPass(PassRegistry &);
} // end namespace llvm
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index c3b4077b27dd8..bd52edd66c547 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -146,4 +146,5 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
initializeWasmEHPreparePass(Registry);
initializeWinEHPreparePass(Registry);
initializeXRayInstrumentationLegacyPass(Registry);
+ initializeFinalizeBundleTestPass(Registry);
}
diff --git a/llvm/lib/CodeGen/MachineInstrBundle.cpp b/llvm/lib/CodeGen/MachineInstrBundle.cpp
index 34896c67144bc..741bfb08ef2fb 100644
--- a/llvm/lib/CodeGen/MachineInstrBundle.cpp
+++ b/llvm/lib/CodeGen/MachineInstrBundle.cpp
@@ -359,3 +359,26 @@ PhysRegInfo llvm::AnalyzePhysRegInBundle(const MachineInstr &MI, Register Reg,
return PRI;
}
+
+namespace {
+class FinalizeBundleTest : public MachineFunctionPass {
+public:
+ static char ID;
+
+ FinalizeBundleTest() : MachineFunctionPass(ID) {
+ initializeFinalizeBundleTestPass(*PassRegistry::getPassRegistry());
+ }
+
+ bool runOnMachineFunction(MachineFunction &MF) override {
+ // For testing purposes, bundle the entire contents of each basic block
+ // except for terminators.
+ for (MachineBasicBlock &MBB : MF)
+ finalizeBundle(MBB, MBB.instr_begin(), MBB.getFirstInstrTerminator());
+ return true;
+ }
+};
+} // namespace
+
+char FinalizeBundleTest::ID = 0;
+INITIALIZE_PASS(FinalizeBundleTest, "finalizebundle-test",
+ "finalizeBundle test", false, false)
diff --git a/llvm/test/CodeGen/AMDGPU/finalize-bundle.mir b/llvm/test/CodeGen/AMDGPU/finalize-bundle.mir
new file mode 100644
index 0000000000000..be25e35765f67
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/finalize-bundle.mir
@@ -0,0 +1,18 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
+# RUN: llc -mtriple=amdgcn -mcpu=gfx1200 -run-pass finalizebundle-test %s -o - | FileCheck %s
+
+---
+name: test_overlap
+body: |
+ bb.0:
+ liveins: $vgpr0_vgpr1
+ ; CHECK-LABEL: name: test_overlap
+ ; CHECK: liveins: $vgpr0_vgpr1
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: BUNDLE implicit-def $vgpr2_vgpr3, implicit-def $vgpr2, implicit-def $vgpr2_lo16, implicit-def $vgpr2_hi16, implicit-def $vgpr3, implicit-def $vgpr3_lo16, implicit-def $vgpr3_hi16, implicit-def $vgpr3_vgpr4, implicit-def $vgpr4, implicit-def $vgpr4_lo16, implicit-def $vgpr4_hi16, implicit $vgpr0_vgpr1, implicit $exec, implicit $vgpr1_vgpr2 {
+ ; CHECK-NEXT: $vgpr2_vgpr3 = V_LSHLREV_B64_pseudo_e32 1, $vgpr0_vgpr1, implicit $exec
+ ; CHECK-NEXT: $vgpr3_vgpr4 = V_LSHLREV_B64_pseudo_e32 1, $vgpr1_vgpr2, implicit $exec
+ ; CHECK-NEXT: }
+ $vgpr2_vgpr3 = V_LSHLREV_B64_pseudo_e32 1, $vgpr0_vgpr1, implicit $exec
+ $vgpr3_vgpr4 = V_LSHLREV_B64_pseudo_e32 1, $vgpr1_vgpr2, implicit $exec
+...
|
} | ||
}; | ||
} // namespace | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also do the new PM version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or if this is just for tests, it could exclusively be new pm
This allows for unit testing of finalizeBundle with standard MIR tests
using update_mir_test_checks.py.