diff options
author | Jay Foad <jay.foad@amd.com> | 2025-05-09 16:10:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-09 16:10:52 +0100 |
commit | 6b7e65a1115bbeb4d881d2ac0a3adaa86d47d598 (patch) | |
tree | 5c7f58470d9d7024be4f13d49907eaf7a9da6dd7 /llvm/lib/CodeGen/MachineInstrBundle.cpp | |
parent | 7e64ade2ef1af72db235f6d76ecd319abc09690e (diff) | |
download | llvm-6b7e65a1115bbeb4d881d2ac0a3adaa86d47d598.zip llvm-6b7e65a1115bbeb4d881d2ac0a3adaa86d47d598.tar.gz llvm-6b7e65a1115bbeb4d881d2ac0a3adaa86d47d598.tar.bz2 |
[CodeGen] Simplify finalizeBundle. NFC. (#139234)
Use all_uses and all_defs instead of separate Defs vector. Use
SmallSetVector instead of separate SmallSet and SmallVector. Remove
unneeded `Added` set. Fold FrameSetup/FrameDestroy into the main loop
instead of doing a separate loop over the bundled instructions.
Diffstat (limited to 'llvm/lib/CodeGen/MachineInstrBundle.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineInstrBundle.cpp | 80 |
1 files changed, 30 insertions, 50 deletions
diff --git a/llvm/lib/CodeGen/MachineInstrBundle.cpp b/llvm/lib/CodeGen/MachineInstrBundle.cpp index 92189f6..34896c6 100644 --- a/llvm/lib/CodeGen/MachineInstrBundle.cpp +++ b/llvm/lib/CodeGen/MachineInstrBundle.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "llvm/CodeGen/MachineInstrBundle.h" +#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/CodeGen/MachineFunctionPass.h" @@ -134,103 +135,82 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB, BuildMI(MF, getDebugLoc(FirstMI, LastMI), TII->get(TargetOpcode::BUNDLE)); Bundle.prepend(MIB); - SmallVector<Register, 32> LocalDefs; - SmallSet<Register, 32> LocalDefSet; + SmallSetVector<Register, 32> LocalDefs; SmallSet<Register, 8> DeadDefSet; SmallSet<Register, 16> KilledDefSet; - SmallVector<Register, 8> ExternUses; - SmallSet<Register, 8> ExternUseSet; + SmallSetVector<Register, 8> ExternUses; SmallSet<Register, 8> KilledUseSet; SmallSet<Register, 8> UndefUseSet; - SmallVector<MachineOperand*, 4> Defs; for (auto MII = FirstMI; MII != LastMI; ++MII) { // Debug instructions have no effects to track. if (MII->isDebugInstr()) continue; - for (MachineOperand &MO : MII->operands()) { - if (!MO.isReg()) - continue; - if (MO.isDef()) { - Defs.push_back(&MO); - continue; - } - + for (MachineOperand &MO : MII->all_uses()) { Register Reg = MO.getReg(); if (!Reg) continue; - if (LocalDefSet.count(Reg)) { + if (LocalDefs.contains(Reg)) { MO.setIsInternalRead(); - if (MO.isKill()) + if (MO.isKill()) { // Internal def is now killed. KilledDefSet.insert(Reg); + } } else { - if (ExternUseSet.insert(Reg).second) { - ExternUses.push_back(Reg); + if (ExternUses.insert(Reg)) { if (MO.isUndef()) UndefUseSet.insert(Reg); } - if (MO.isKill()) + if (MO.isKill()) { // External def is now killed. KilledUseSet.insert(Reg); + } } } - for (MachineOperand *MO : Defs) { - Register Reg = MO->getReg(); + for (MachineOperand &MO : MII->all_defs()) { + Register Reg = MO.getReg(); if (!Reg) continue; - if (LocalDefSet.insert(Reg).second) { - LocalDefs.push_back(Reg); - if (MO->isDead()) { + if (LocalDefs.insert(Reg)) { + if (MO.isDead()) DeadDefSet.insert(Reg); - } } else { // Re-defined inside the bundle, it's no longer killed. KilledDefSet.erase(Reg); - if (!MO->isDead()) + if (!MO.isDead()) { // Previously defined but dead. DeadDefSet.erase(Reg); - } - - if (!MO->isDead() && Reg.isPhysical()) { - for (MCPhysReg SubReg : TRI->subregs(Reg)) { - if (LocalDefSet.insert(SubReg).second) - LocalDefs.push_back(SubReg); } } + + if (!MO.isDead() && Reg.isPhysical()) + LocalDefs.insert_range(TRI->subregs(Reg)); } - Defs.clear(); + // Set FrameSetup/FrameDestroy for the bundle. If any of the instructions + // got the property, then also set it on the bundle. + if (MII->getFlag(MachineInstr::FrameSetup)) + MIB.setMIFlag(MachineInstr::FrameSetup); + if (MII->getFlag(MachineInstr::FrameDestroy)) + MIB.setMIFlag(MachineInstr::FrameDestroy); } - SmallSet<Register, 32> Added; for (Register Reg : LocalDefs) { - if (Added.insert(Reg).second) { - // If it's not live beyond end of the bundle, mark it dead. - bool isDead = DeadDefSet.count(Reg) || KilledDefSet.count(Reg); - MIB.addReg(Reg, getDefRegState(true) | getDeadRegState(isDead) | - getImplRegState(true)); - } + // If it's not live beyond end of the bundle, mark it dead. + bool isDead = DeadDefSet.contains(Reg) || KilledDefSet.contains(Reg); + MIB.addReg(Reg, getDefRegState(true) | getDeadRegState(isDead) | + getImplRegState(true)); } for (Register Reg : ExternUses) { - bool isKill = KilledUseSet.count(Reg); - bool isUndef = UndefUseSet.count(Reg); + bool isKill = KilledUseSet.contains(Reg); + bool isUndef = UndefUseSet.contains(Reg); MIB.addReg(Reg, getKillRegState(isKill) | getUndefRegState(isUndef) | getImplRegState(true)); } - - // Set FrameSetup/FrameDestroy for the bundle. If any of the instructions got - // the property, then also set it on the bundle. - for (auto MII = FirstMI; MII != LastMI; ++MII) { - if (MII->getFlag(MachineInstr::FrameSetup)) - MIB.setMIFlag(MachineInstr::FrameSetup); - if (MII->getFlag(MachineInstr::FrameDestroy)) - MIB.setMIFlag(MachineInstr::FrameDestroy); - } } /// finalizeBundle - Same functionality as the previous finalizeBundle except |