diff --git a/llvm/include/llvm/CodeGen/LiveIntervals.h b/llvm/include/llvm/CodeGen/LiveIntervals.h index 708917be497ef..4a4d53ee7c25e 100644 --- a/llvm/include/llvm/CodeGen/LiveIntervals.h +++ b/llvm/include/llvm/CodeGen/LiveIntervals.h @@ -30,6 +30,7 @@ #include "llvm/CodeGen/SlotIndexes.h" #include "llvm/CodeGen/TargetRegisterInfo.h" #include "llvm/MC/LaneBitmask.h" +#include "llvm/Support/Allocator.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" @@ -64,6 +65,15 @@ class LiveIntervals { MachineDominatorTree *DomTree = nullptr; std::unique_ptr LICalc; + // Allocator for SubRanges. + BumpPtrAllocator Allocator; + + // Allocator for VirtRegIntervals + SpecificBumpPtrAllocator LIAllocator; + + // Allocator for RegUnitRanges + SpecificBumpPtrAllocator LRAllocator; + /// Special pool allocator for VNInfo's (LiveInterval val#). VNInfo::Allocator VNInfoAllocator; @@ -170,7 +180,7 @@ class LiveIntervals { /// Interval removal. void removeInterval(Register Reg) { auto &Interval = VirtRegIntervals[Reg]; - delete Interval; + // FIXME: SpecificBumpPtrAllocator missing deallocate for asan poisoning Interval = nullptr; } @@ -416,7 +426,8 @@ class LiveIntervals { if (!LR) { // Compute missing ranges on demand. // Use segment set to speed-up initial computation of the live range. - RegUnitRanges[Unit] = LR = new LiveRange(UseSegmentSetForPhysRegs); + RegUnitRanges[Unit] = LR = + new (LRAllocator.Allocate()) LiveRange(UseSegmentSetForPhysRegs); computeRegUnitRange(*LR, Unit); } return *LR; @@ -433,7 +444,7 @@ class LiveIntervals { /// Remove computed live range for register unit \p Unit. Subsequent uses /// should rely on on-demand recomputation. void removeRegUnit(unsigned Unit) { - delete RegUnitRanges[Unit]; + Allocator.Deallocate(RegUnitRanges[Unit]); RegUnitRanges[Unit] = nullptr; } @@ -481,7 +492,7 @@ class LiveIntervals { bool computeDeadValues(LiveInterval &LI, SmallVectorImpl *dead); - static LiveInterval *createInterval(Register Reg); + LiveInterval *createInterval(Register Reg); void printInstrs(raw_ostream &O) const; void dumpInstrs() const; diff --git a/llvm/lib/CodeGen/LiveIntervals.cpp b/llvm/lib/CodeGen/LiveIntervals.cpp index 3485a27335f13..2b46e4e6393d5 100644 --- a/llvm/lib/CodeGen/LiveIntervals.cpp +++ b/llvm/lib/CodeGen/LiveIntervals.cpp @@ -142,18 +142,17 @@ bool LiveIntervals::invalidate( } void LiveIntervals::clear() { - // Free the live intervals themselves. - for (unsigned i = 0, e = VirtRegIntervals.size(); i != e; ++i) - delete VirtRegIntervals[Register::index2VirtReg(i)]; - VirtRegIntervals.clear(); RegMaskSlots.clear(); RegMaskBits.clear(); RegMaskBlocks.clear(); - for (LiveRange *LR : RegUnitRanges) - delete LR; + LRAllocator.DestroyAll(); RegUnitRanges.clear(); + // Free the live intervals themselves. + LIAllocator.DestroyAll(); + VirtRegIntervals.clear(); + // Release VNInfo memory regions, VNInfo objects don't need to be dtor'd. VNInfoAllocator.Reset(); } @@ -222,7 +221,7 @@ LLVM_DUMP_METHOD void LiveIntervals::dump() const { print(dbgs()); } LiveInterval *LiveIntervals::createInterval(Register reg) { float Weight = reg.isPhysical() ? huge_valf : 0.0F; - return new LiveInterval(reg, Weight); + return new (LIAllocator.Allocate()) LiveInterval(reg, Weight); } /// Compute the live interval of a virtual register, based on defs and uses. @@ -374,7 +373,8 @@ void LiveIntervals::computeLiveInRegUnits() { LiveRange *LR = RegUnitRanges[Unit]; if (!LR) { // Use segment set to speed-up initial computation of the live range. - LR = RegUnitRanges[Unit] = new LiveRange(UseSegmentSetForPhysRegs); + LR = RegUnitRanges[Unit] = new (Allocator.Allocate()) + LiveRange(UseSegmentSetForPhysRegs); NewRanges.push_back(Unit); } VNInfo *VNI = LR->createDeadDef(Begin, getVNInfoAllocator());