Skip to content

Commit 50054ba

Browse files
authored
[CodeGen] LiveRegMatrix: Use allocator through a unique_ptr (#120556)
`LIU::Matrix` holds on to a pointer to the allocator in LiveRegMatrix and is left hanging when the allocator moves with the LiveRegMatrix. This extends the lifetime of the allocator so that it does not get destroyed when moving a LiveRegMatrix object.
1 parent ca2ab74 commit 50054ba

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

llvm/include/llvm/CodeGen/LiveRegMatrix.h

+4-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class LiveRegMatrix {
4848
unsigned UserTag = 0;
4949

5050
// The matrix is represented as a LiveIntervalUnion per register unit.
51-
LiveIntervalUnion::Allocator LIUAlloc;
51+
std::unique_ptr<LiveIntervalUnion::Allocator> LIUAlloc;
5252
LiveIntervalUnion::Array Matrix;
5353

5454
// Cached queries per register unit.
@@ -59,15 +59,12 @@ class LiveRegMatrix {
5959
unsigned RegMaskVirtReg = 0;
6060
BitVector RegMaskUsable;
6161

62-
LiveRegMatrix() = default;
62+
LiveRegMatrix()
63+
: LIUAlloc(std::make_unique<LiveIntervalUnion::Allocator>()) {};
6364
void releaseMemory();
6465

6566
public:
66-
LiveRegMatrix(LiveRegMatrix &&Other)
67-
: TRI(Other.TRI), LIS(Other.LIS), VRM(Other.VRM), UserTag(Other.UserTag),
68-
Matrix(std::move(Other.Matrix)), Queries(std::move(Other.Queries)),
69-
RegMaskTag(Other.RegMaskTag), RegMaskVirtReg(Other.RegMaskVirtReg),
70-
RegMaskUsable(std::move(Other.RegMaskUsable)) {}
67+
LiveRegMatrix(LiveRegMatrix &&Other) = default;
7168

7269
void init(MachineFunction &MF, LiveIntervals &LIS, VirtRegMap &VRM);
7370

llvm/lib/CodeGen/LiveRegMatrix.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void LiveRegMatrix::init(MachineFunction &MF, LiveIntervals &pLIS,
6666
unsigned NumRegUnits = TRI->getNumRegUnits();
6767
if (NumRegUnits != Matrix.size())
6868
Queries.reset(new LiveIntervalUnion::Query[NumRegUnits]);
69-
Matrix.init(LIUAlloc, NumRegUnits);
69+
Matrix.init(*LIUAlloc, NumRegUnits);
7070

7171
// Make sure no stale queries get reused.
7272
invalidateVirtRegs();

0 commit comments

Comments
 (0)