[llvm] 6d3027e - MachineSink: Move helper function and use more const
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 14 15:46:23 PDT 2023
Author: Matt Arsenault
Date: 2023-07-14T18:46:18-04:00
New Revision: 6d3027e3d1ae7fee44bae5fe02913c0959505f25
URL: https://github.com/llvm/llvm-project/commit/6d3027e3d1ae7fee44bae5fe02913c0959505f25
DIFF: https://github.com/llvm/llvm-project/commit/6d3027e3d1ae7fee44bae5fe02913c0959505f25.diff
LOG: MachineSink: Move helper function and use more const
Added:
Modified:
llvm/include/llvm/CodeGen/MachineBasicBlock.h
llvm/lib/CodeGen/MachineSink.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
index 1c5137f305b6b3..52388692c19664 100644
--- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
@@ -816,6 +816,9 @@ class MachineBasicBlock
/// the first instruction, which might be PHI.
/// Returns end() is there's no non-PHI instruction.
iterator getFirstNonPHI();
+ const_iterator getFirstNonPHI() const {
+ return const_cast<MachineBasicBlock *>(this)->getFirstNonPHI();
+ }
/// Return the first instruction in MBB after I that is not a PHI or a label.
/// This is the correct point to insert lowered copies at the beginning of a
diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp
index 72484dfc5ebc49..07f2f6c2e8b014 100644
--- a/llvm/lib/CodeGen/MachineSink.cpp
+++ b/llvm/lib/CodeGen/MachineSink.cpp
@@ -268,6 +268,47 @@ INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
INITIALIZE_PASS_END(MachineSinking, DEBUG_TYPE,
"Machine code sinking", false, false)
+/// Return true if a target defined block prologue instruction interferes
+/// with a sink candidate.
+static bool blockPrologueInterferes(const MachineBasicBlock *BB,
+ MachineBasicBlock::const_iterator End,
+ const MachineInstr &MI,
+ const TargetRegisterInfo *TRI,
+ const TargetInstrInfo *TII,
+ const MachineRegisterInfo *MRI) {
+ if (BB->begin() == End)
+ return false; // no prologue
+ for (MachineBasicBlock::const_iterator PI = BB->getFirstNonPHI(); PI != End;
+ ++PI) {
+ // Only check target defined prologue instructions
+ if (!TII->isBasicBlockPrologue(*PI))
+ continue;
+ for (auto &MO : MI.operands()) {
+ if (!MO.isReg())
+ continue;
+ Register Reg = MO.getReg();
+ if (!Reg)
+ continue;
+ if (MO.isUse()) {
+ if (Reg.isPhysical() &&
+ (TII->isIgnorableUse(MO) || (MRI && MRI->isConstantPhysReg(Reg))))
+ continue;
+ if (PI->modifiesRegister(Reg, TRI))
+ return true;
+ } else {
+ if (PI->readsRegister(Reg, TRI))
+ return true;
+ // Check for interference with non-dead defs
+ auto *DefOp = PI->findRegisterDefOperand(Reg, false, true, TRI);
+ if (DefOp && !DefOp->isDead())
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
bool MachineSinking::PerformTrivialForwardCoalescing(MachineInstr &MI,
MachineBasicBlock *MBB) {
if (!MI.isCopy())
@@ -1298,45 +1339,6 @@ bool MachineSinking::SinkIntoCycle(MachineCycle *Cycle, MachineInstr &I) {
return true;
}
-/// Return true if a target defined block prologue instruction interferes
-/// with a sink candidate.
-static bool blockPrologueInterferes(MachineBasicBlock *BB,
- MachineBasicBlock::iterator End,
- MachineInstr &MI,
- const TargetRegisterInfo *TRI,
- const TargetInstrInfo *TII,
- const MachineRegisterInfo *MRI) {
- if (BB->begin() == End)
- return false; // no prologue
- for (MachineBasicBlock::iterator PI = BB->getFirstNonPHI(); PI != End; ++PI) {
- // Only check target defined prologue instructions
- if (!TII->isBasicBlockPrologue(*PI))
- continue;
- for (auto &MO : MI.operands()) {
- if (!MO.isReg())
- continue;
- Register Reg = MO.getReg();
- if (!Reg)
- continue;
- if (MO.isUse()) {
- if (Reg.isPhysical() &&
- (TII->isIgnorableUse(MO) || (MRI && MRI->isConstantPhysReg(Reg))))
- continue;
- if (PI->modifiesRegister(Reg, TRI))
- return true;
- } else {
- if (PI->readsRegister(Reg, TRI))
- return true;
- // Check for interference with non-dead defs
- auto *DefOp = PI->findRegisterDefOperand(Reg, false, true, TRI);
- if (DefOp && !DefOp->isDead())
- return true;
- }
- }
- }
- return false;
-}
-
/// SinkInstruction - Determine whether it is safe to sink the specified machine
/// instruction out of its current block into a successor.
bool MachineSinking::SinkInstruction(MachineInstr &MI, bool &SawStore,
More information about the llvm-commits
mailing list