[llvm] [MCP] Enhance MCP copy Instruction removal for special case (PR #70778)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 6 03:05:52 PST 2023
================
@@ -184,6 +184,58 @@ class CopyTracker {
}
}
+ /// Clobber \p Reg first, and then remove the corresponding COPY
+ /// record pair from the tracker's copy maps. We need to locate and remove
+ /// the COPY instruction that defines \p Reg, as well as the
+ /// record that make src defines \p Reg.
+ void eraseRegMIPair(MCRegister Reg, const TargetRegisterInfo &TRI,
+ const TargetInstrInfo &TII, bool UseCopyInstr) {
+ for (MCRegUnit Unit : TRI.regunits(Reg)) {
+ auto I = Copies.find(Unit);
+
+ if (I != Copies.end()) {
+ // When we clobber the source of a copy, we need to clobber everything
+ // it defined.
+ markRegsUnavailable(I->second.DefRegs, TRI);
+ // When we clobber the destination of a copy, we need to clobber the
+ // whole register it defined.
+ if (MachineInstr *MI = I->second.MI) {
+ std::optional<DestSourcePair> CopyOperands =
+ isCopyInstr(*MI, TII, UseCopyInstr);
+
+ MCRegister Src = CopyOperands->Source->getReg().asMCReg();
+ MCRegister Def = CopyOperands->Destination->getReg().asMCReg();
+
+ markRegsUnavailable(Def, TRI);
+
+ // At this point, we need to locate the record in copy maps that use
+ // Src to define Def, and remove them from Tracker.
+ for (MCRegUnit SrcUnit : TRI.regunits(Src)) {
+ auto SrcCopy = Copies.find(SrcUnit);
+ if (SrcCopy != Copies.end() && SrcCopy->second.LastSeenUseInCopy) {
+ // If Src define multiple values, we only need
+ // to erase the such record in DefRegs.
+ for (auto itr = SrcCopy->second.DefRegs.begin();
+ itr != SrcCopy->second.DefRegs.end(); itr++) {
+ if (*itr == Def) {
+ SrcCopy->second.DefRegs.erase(itr);
+ // If DefReg becomes empty after removal, we can directly
+ // remove SrcCopy from the tracker's copy maps.
+ if (!SrcCopy->second.DefRegs.size()) {
----------------
qcolombet wrote:
Nit: `SrcCopy->second.DefRegs.empty()`
https://github.com/llvm/llvm-project/pull/70778
More information about the llvm-commits
mailing list