[llvm] r228405 - LiveInterval: Fix SubRange memory leak.
Matthias Braun
matze at braunis.de
Fri Feb 6 09:28:47 PST 2015
Author: matze
Date: Fri Feb 6 11:28:47 2015
New Revision: 228405
URL: http://llvm.org/viewvc/llvm-project?rev=228405&view=rev
Log:
LiveInterval: Fix SubRange memory leak.
Modified:
llvm/trunk/include/llvm/CodeGen/LiveInterval.h
llvm/trunk/lib/CodeGen/LiveInterval.cpp
Modified: llvm/trunk/include/llvm/CodeGen/LiveInterval.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/LiveInterval.h?rev=228405&r1=228404&r2=228405&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/LiveInterval.h (original)
+++ llvm/trunk/include/llvm/CodeGen/LiveInterval.h Fri Feb 6 11:28:47 2015
@@ -606,6 +606,10 @@ namespace llvm {
LiveInterval(unsigned Reg, float Weight)
: SubRanges(nullptr), reg(Reg), weight(Weight) {}
+ ~LiveInterval() {
+ clearSubRanges();
+ }
+
template<typename T>
class SingleLinkedListIterator {
T *P;
@@ -681,9 +685,7 @@ namespace llvm {
}
/// Removes all subregister liveness information.
- void clearSubRanges() {
- SubRanges = nullptr;
- }
+ void clearSubRanges();
/// Removes all subranges without any segments (subranges without segments
/// are not considered valid and should only exist temporarily).
@@ -733,6 +735,9 @@ namespace llvm {
Range->Next = SubRanges;
SubRanges = Range;
}
+
+ /// Free memory held by SubRange.
+ void freeSubRange(SubRange *S);
};
inline raw_ostream &operator<<(raw_ostream &OS, const LiveInterval &LI) {
Modified: llvm/trunk/lib/CodeGen/LiveInterval.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveInterval.cpp?rev=228405&r1=228404&r2=228405&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LiveInterval.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveInterval.cpp Fri Feb 6 11:28:47 2015
@@ -598,6 +598,11 @@ VNInfo *LiveRange::MergeValueNumberInto(
return V2;
}
+void LiveInterval::freeSubRange(SubRange *S) {
+ S->~SubRange();
+ // Memory was allocated with BumpPtr allocator and is not freed here.
+}
+
void LiveInterval::removeEmptySubRanges() {
SubRange **NextPtr = &SubRanges;
SubRange *I = *NextPtr;
@@ -609,12 +614,22 @@ void LiveInterval::removeEmptySubRanges(
}
// Skip empty subranges until we find the first nonempty one.
do {
- I = I->Next;
+ SubRange *Next = I->Next;
+ freeSubRange(I);
+ I = Next;
} while (I != nullptr && I->empty());
*NextPtr = I;
}
}
+void LiveInterval::clearSubRanges() {
+ for (SubRange *I = SubRanges, *Next; I != nullptr; I = Next) {
+ Next = I->Next;
+ freeSubRange(I);
+ }
+ SubRanges = nullptr;
+}
+
/// Helper function for constructMainRangeFromSubranges(): Search the CFG
/// backwards until we find a place covered by a LiveRange segment that actually
/// has a valno set.
More information about the llvm-commits
mailing list