Skip to content

Commit 63bd16a

Browse files
committed
Use unique_ptr
1 parent 231fddb commit 63bd16a

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

llvm/include/llvm/CodeGen/LiveDebugVariables.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,13 @@ class VirtRegMap;
3333

3434
class LiveDebugVariables {
3535
private:
36-
void *PImpl;
36+
struct Deleter {
37+
void operator()(void *Ptr) const;
38+
};
39+
std::unique_ptr<void, Deleter> PImpl;
3740

3841
public:
3942
LiveDebugVariables() = default;
40-
~LiveDebugVariables();
41-
42-
LiveDebugVariables(LiveDebugVariables &&Other) : PImpl(Other.PImpl) {
43-
Other.PImpl = nullptr;
44-
}
45-
46-
LiveDebugVariables &operator=(LiveDebugVariables &&Other);
47-
48-
LiveDebugVariables &operator=(const LiveDebugVariables &) = delete;
49-
LiveDebugVariables(const LiveDebugVariables &) = delete;
5043

5144
void analyze(MachineFunction &MF, LiveIntervals *LIS);
5245
/// splitRegister - Move any user variables in OldReg to the live ranges in

llvm/lib/CodeGen/LiveDebugVariables.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,14 +1316,13 @@ LiveDebugVariablesAnalysis::run(MachineFunction &MF,
13161316
return LDV;
13171317
}
13181318

1319-
LiveDebugVariables::~LiveDebugVariables() {
1320-
if (PImpl)
1321-
delete static_cast<LDVImpl *>(PImpl);
1319+
void LiveDebugVariables::Deleter::operator()(void *Ptr) const {
1320+
delete static_cast<LDVImpl *>(Ptr);
13221321
}
13231322

13241323
void LiveDebugVariables::releaseMemory() {
13251324
if (PImpl)
1326-
static_cast<LDVImpl *>(PImpl)->clear();
1325+
static_cast<LDVImpl *>(PImpl.get())->clear();
13271326
}
13281327

13291328
void LiveDebugVariables::analyze(MachineFunction &MF, LiveIntervals *LIS) {
@@ -1334,13 +1333,12 @@ void LiveDebugVariables::analyze(MachineFunction &MF, LiveIntervals *LIS) {
13341333
return;
13351334
}
13361335

1337-
if (!PImpl)
1338-
PImpl = new LDVImpl(LIS); // reuse same object across analysis runs
1336+
PImpl.reset(new LDVImpl(LIS));
13391337

13401338
// Have we been asked to track variable locations using instruction
13411339
// referencing?
13421340
bool InstrRef = MF.useDebugInstrRef();
1343-
static_cast<LDVImpl *>(PImpl)->runOnMachineFunction(MF, InstrRef);
1341+
static_cast<LDVImpl *>(PImpl.get())->runOnMachineFunction(MF, InstrRef);
13441342
}
13451343

13461344
//===----------------------------------------------------------------------===//
@@ -1523,7 +1521,7 @@ void LDVImpl::splitRegister(Register OldReg, ArrayRef<Register> NewRegs) {
15231521
void LiveDebugVariables::
15241522
splitRegister(Register OldReg, ArrayRef<Register> NewRegs, LiveIntervals &LIS) {
15251523
if (PImpl)
1526-
static_cast<LDVImpl *>(PImpl)->splitRegister(OldReg, NewRegs);
1524+
static_cast<LDVImpl *>(PImpl.get())->splitRegister(OldReg, NewRegs);
15271525
}
15281526

15291527
void UserValue::rewriteLocations(VirtRegMap &VRM, const MachineFunction &MF,
@@ -1975,12 +1973,12 @@ void LDVImpl::emitDebugValues(VirtRegMap *VRM) {
19751973

19761974
void LiveDebugVariables::emitDebugValues(VirtRegMap *VRM) {
19771975
if (PImpl)
1978-
static_cast<LDVImpl *>(PImpl)->emitDebugValues(VRM);
1976+
static_cast<LDVImpl *>(PImpl.get())->emitDebugValues(VRM);
19791977
}
19801978

19811979
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
19821980
LLVM_DUMP_METHOD void LiveDebugVariables::dump() const {
19831981
if (PImpl)
1984-
static_cast<LDVImpl *>(PImpl)->print(dbgs());
1982+
static_cast<LDVImpl *>(PImpl.get())->print(dbgs());
19851983
}
19861984
#endif

0 commit comments

Comments
 (0)