From 63449f93a0a9a30dc29e604eb14e81a668eb9d09 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Wed, 10 Jan 2018 21:41:02 +0000 Subject: [PATCH] LiveRangeEdit: Simplify code; NFC Simplify the code slightly: Instead of creating empty subranges in one case and immediately removing them, do not create them in the first place. llvm-svn: 322226 --- llvm/include/llvm/CodeGen/LiveRangeEdit.h | 8 +++---- llvm/lib/CodeGen/LiveRangeEdit.cpp | 26 ++++++++++++----------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/llvm/include/llvm/CodeGen/LiveRangeEdit.h b/llvm/include/llvm/CodeGen/LiveRangeEdit.h index 84bccde0caa2..84ca51e3d72f 100644 --- a/llvm/include/llvm/CodeGen/LiveRangeEdit.h +++ b/llvm/include/llvm/CodeGen/LiveRangeEdit.h @@ -121,6 +121,9 @@ private: /// main live range of \p LI or in one of the matching subregister ranges. bool useIsKill(const LiveInterval &LI, const MachineOperand &MO) const; + /// Create a new empty interval based on OldReg. + LiveInterval &createEmptyIntervalFrom(unsigned OldReg, bool createSubRanges); + public: /// Create a LiveRangeEdit for breaking down parent into smaller pieces. /// @param parent The register being spilled or split. @@ -174,16 +177,13 @@ public: return makeArrayRef(NewRegs).slice(FirstNew); } - /// createEmptyIntervalFrom - Create a new empty interval based on OldReg. - LiveInterval &createEmptyIntervalFrom(unsigned OldReg); - /// createFrom - Create a new virtual register based on OldReg. unsigned createFrom(unsigned OldReg); /// create - Create a new register with the same class and original slot as /// parent. LiveInterval &createEmptyInterval() { - return createEmptyIntervalFrom(getReg()); + return createEmptyIntervalFrom(getReg(), true); } unsigned create() { return createFrom(getReg()); } diff --git a/llvm/lib/CodeGen/LiveRangeEdit.cpp b/llvm/lib/CodeGen/LiveRangeEdit.cpp index 86cfbd87f5b1..d00b36078672 100644 --- a/llvm/lib/CodeGen/LiveRangeEdit.cpp +++ b/llvm/lib/CodeGen/LiveRangeEdit.cpp @@ -31,21 +31,24 @@ STATISTIC(NumFracRanges, "Number of live ranges fractured by DCE"); void LiveRangeEdit::Delegate::anchor() { } -LiveInterval &LiveRangeEdit::createEmptyIntervalFrom(unsigned OldReg) { +LiveInterval &LiveRangeEdit::createEmptyIntervalFrom(unsigned OldReg, + bool createSubRanges) { unsigned VReg = MRI.createVirtualRegister(MRI.getRegClass(OldReg)); - if (VRM) { + if (VRM) VRM->setIsSplitFromReg(VReg, VRM->getOriginal(OldReg)); - } + LiveInterval &LI = LIS.createEmptyInterval(VReg); if (Parent && !Parent->isSpillable()) LI.markNotSpillable(); - // Create empty subranges if the OldReg's interval has them. Do not create - // the main range here---it will be constructed later after the subranges - // have been finalized. - LiveInterval &OldLI = LIS.getInterval(OldReg); - VNInfo::Allocator &Alloc = LIS.getVNInfoAllocator(); - for (LiveInterval::SubRange &S : OldLI.subranges()) - LI.createSubRange(Alloc, S.LaneMask); + if (createSubRanges) { + // Create empty subranges if the OldReg's interval has them. Do not create + // the main range here---it will be constructed later after the subranges + // have been finalized. + LiveInterval &OldLI = LIS.getInterval(OldReg); + VNInfo::Allocator &Alloc = LIS.getVNInfoAllocator(); + for (LiveInterval::SubRange &S : OldLI.subranges()) + LI.createSubRange(Alloc, S.LaneMask); + } return LI; } @@ -357,8 +360,7 @@ void LiveRangeEdit::eliminateDeadDef(MachineInstr *MI, ToShrinkSet &ToShrink, // LiveRangeEdit::DeadRemats and will be deleted after all the // allocations of the func are done. if (isOrigDef && DeadRemats && TII.isTriviallyReMaterializable(*MI, AA)) { - LiveInterval &NewLI = createEmptyIntervalFrom(Dest); - NewLI.removeEmptySubRanges(); + LiveInterval &NewLI = createEmptyIntervalFrom(Dest, false); VNInfo *VNI = NewLI.getNextValue(Idx, LIS.getVNInfoAllocator()); NewLI.addSegment(LiveInterval::Segment(Idx, Idx.getDeadSlot(), VNI)); pop_back();