Skip to content

[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

Merged
merged 2 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/include/llvm/CodeGen/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions llvm/include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,5 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
initializeWasmEHPreparePass(Registry);
initializeWinEHPreparePass(Registry);
initializeXRayInstrumentationLegacyPass(Registry);
initializeFinalizeBundleTestPass(Registry);
}
23 changes: 23 additions & 0 deletions llvm/lib/CodeGen/MachineInstrBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Contributor

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?

Copy link
Contributor

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

char FinalizeBundleTest::ID = 0;
INITIALIZE_PASS(FinalizeBundleTest, "finalizebundle-test",
"finalizeBundle test", false, false)
18 changes: 18 additions & 0 deletions llvm/test/CodeGen/AMDGPU/finalize-bundle.mir
Original file line number Diff line number Diff line change
@@ -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
...
Loading