Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 52d629e

Browse files
committed
Use unique_ptr to manage objects owned by the ScheduleDAGMI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206784 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d0da5af commit 52d629e

File tree

5 files changed

+34
-29
lines changed

5 files changed

+34
-29
lines changed

include/llvm/CodeGen/MachineScheduler.h

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
#include "llvm/CodeGen/RegisterPressure.h"
8282
#include "llvm/CodeGen/ScheduleDAGInstrs.h"
8383

84+
#include <memory>
85+
8486
namespace llvm {
8587

8688
extern cl::opt<bool> ForceTopDown;
@@ -221,14 +223,14 @@ class ScheduleDAGMutation {
221223
class ScheduleDAGMI : public ScheduleDAGInstrs {
222224
protected:
223225
AliasAnalysis *AA;
224-
MachineSchedStrategy *SchedImpl;
226+
std::unique_ptr<MachineSchedStrategy> SchedImpl;
225227

226228
/// Topo - A topological ordering for SUnits which permits fast IsReachable
227229
/// and similar queries.
228230
ScheduleDAGTopologicalSort Topo;
229231

230232
/// Ordered list of DAG postprocessing steps.
231-
std::vector<ScheduleDAGMutation*> Mutations;
233+
std::vector<std::unique_ptr<ScheduleDAGMutation>> Mutations;
232234

233235
/// The top of the unscheduled zone.
234236
MachineBasicBlock::iterator CurrentTop;
@@ -246,17 +248,19 @@ class ScheduleDAGMI : public ScheduleDAGInstrs {
246248
unsigned NumInstrsScheduled;
247249
#endif
248250
public:
249-
ScheduleDAGMI(MachineSchedContext *C, MachineSchedStrategy *S, bool IsPostRA):
250-
ScheduleDAGInstrs(*C->MF, *C->MLI, *C->MDT, IsPostRA,
251-
/*RemoveKillFlags=*/IsPostRA, C->LIS),
252-
AA(C->AA), SchedImpl(S), Topo(SUnits, &ExitSU), CurrentTop(),
253-
CurrentBottom(), NextClusterPred(nullptr), NextClusterSucc(nullptr) {
251+
ScheduleDAGMI(MachineSchedContext *C, std::unique_ptr<MachineSchedStrategy> S,
252+
bool IsPostRA)
253+
: ScheduleDAGInstrs(*C->MF, *C->MLI, *C->MDT, IsPostRA,
254+
/*RemoveKillFlags=*/IsPostRA, C->LIS),
255+
AA(C->AA), SchedImpl(std::move(S)), Topo(SUnits, &ExitSU), CurrentTop(),
256+
CurrentBottom(), NextClusterPred(nullptr), NextClusterSucc(nullptr) {
254257
#ifndef NDEBUG
255258
NumInstrsScheduled = 0;
256259
#endif
257260
}
258261

259-
virtual ~ScheduleDAGMI();
262+
// Provide a vtable anchor
263+
~ScheduleDAGMI() override;
260264

261265
/// Return true if this DAG supports VReg liveness and RegPressure.
262266
virtual bool hasVRegLiveness() const { return false; }
@@ -266,8 +270,8 @@ class ScheduleDAGMI : public ScheduleDAGInstrs {
266270
/// building and before MachineSchedStrategy initialization.
267271
///
268272
/// ScheduleDAGMI takes ownership of the Mutation object.
269-
void addMutation(ScheduleDAGMutation *Mutation) {
270-
Mutations.push_back(Mutation);
273+
void addMutation(std::unique_ptr<ScheduleDAGMutation> Mutation) {
274+
Mutations.push_back(std::move(Mutation));
271275
}
272276

273277
/// \brief True if an edge can be added from PredSU to SuccSU without creating
@@ -375,11 +379,12 @@ class ScheduleDAGMILive : public ScheduleDAGMI {
375379
RegPressureTracker BotRPTracker;
376380

377381
public:
378-
ScheduleDAGMILive(MachineSchedContext *C, MachineSchedStrategy *S):
379-
ScheduleDAGMI(C, S, /*IsPostRA=*/false), RegClassInfo(C->RegClassInfo),
380-
DFSResult(nullptr), ShouldTrackPressure(false), RPTracker(RegPressure),
381-
TopRPTracker(TopPressure), BotRPTracker(BotPressure)
382-
{}
382+
ScheduleDAGMILive(MachineSchedContext *C,
383+
std::unique_ptr<MachineSchedStrategy> S)
384+
: ScheduleDAGMI(C, std::move(S), /*IsPostRA=*/false),
385+
RegClassInfo(C->RegClassInfo), DFSResult(nullptr),
386+
ShouldTrackPressure(false), RPTracker(RegPressure),
387+
TopRPTracker(TopPressure), BotRPTracker(BotPressure) {}
383388

384389
virtual ~ScheduleDAGMILive();
385390

lib/CodeGen/MachineScheduler.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,8 @@ void ReadyQueue::dump() {
487487
// virtual registers.
488488
// ===----------------------------------------------------------------------===/
489489

490+
// Provide a vtable anchor.
490491
ScheduleDAGMI::~ScheduleDAGMI() {
491-
DeleteContainerPointers(Mutations);
492-
delete SchedImpl;
493492
}
494493

495494
bool ScheduleDAGMI::canAddEdge(SUnit *SuccSU, SUnit *PredSU) {
@@ -3002,17 +3001,17 @@ void GenericScheduler::schedNode(SUnit *SU, bool IsTopNode) {
30023001
/// Create the standard converging machine scheduler. This will be used as the
30033002
/// default scheduler if the target does not set a default.
30043003
static ScheduleDAGInstrs *createGenericSchedLive(MachineSchedContext *C) {
3005-
ScheduleDAGMILive *DAG = new ScheduleDAGMILive(C, new GenericScheduler(C));
3004+
ScheduleDAGMILive *DAG = new ScheduleDAGMILive(C, make_unique<GenericScheduler>(C));
30063005
// Register DAG post-processors.
30073006
//
30083007
// FIXME: extend the mutation API to allow earlier mutations to instantiate
30093008
// data and pass it to later mutations. Have a single mutation that gathers
30103009
// the interesting nodes in one pass.
3011-
DAG->addMutation(new CopyConstrain(DAG->TII, DAG->TRI));
3010+
DAG->addMutation(make_unique<CopyConstrain>(DAG->TII, DAG->TRI));
30123011
if (EnableLoadCluster && DAG->TII->enableClusterLoads())
3013-
DAG->addMutation(new LoadClusterMutation(DAG->TII, DAG->TRI));
3012+
DAG->addMutation(make_unique<LoadClusterMutation>(DAG->TII, DAG->TRI));
30143013
if (EnableMacroFusion)
3015-
DAG->addMutation(new MacroFusion(DAG->TII));
3014+
DAG->addMutation(make_unique<MacroFusion>(DAG->TII));
30163015
return DAG;
30173016
}
30183017

@@ -3198,7 +3197,7 @@ void PostGenericScheduler::schedNode(SUnit *SU, bool IsTopNode) {
31983197

31993198
/// Create a generic scheduler with no vreg liveness or DAG mutation passes.
32003199
static ScheduleDAGInstrs *createGenericSchedPostRA(MachineSchedContext *C) {
3201-
return new ScheduleDAGMI(C, new PostGenericScheduler(C), /*IsPostRA=*/true);
3200+
return new ScheduleDAGMI(C, make_unique<PostGenericScheduler>(C), /*IsPostRA=*/true);
32023201
}
32033202

32043203
//===----------------------------------------------------------------------===//
@@ -3303,10 +3302,10 @@ class ILPScheduler : public MachineSchedStrategy {
33033302
} // namespace
33043303

33053304
static ScheduleDAGInstrs *createILPMaxScheduler(MachineSchedContext *C) {
3306-
return new ScheduleDAGMILive(C, new ILPScheduler(true));
3305+
return new ScheduleDAGMILive(C, make_unique<ILPScheduler>(true));
33073306
}
33083307
static ScheduleDAGInstrs *createILPMinScheduler(MachineSchedContext *C) {
3309-
return new ScheduleDAGMILive(C, new ILPScheduler(false));
3308+
return new ScheduleDAGMILive(C, make_unique<ILPScheduler>(false));
33103309
}
33113310
static MachineSchedRegistry ILPMaxRegistry(
33123311
"ilpmax", "Schedule bottom-up for max ILP", createILPMaxScheduler);
@@ -3395,7 +3394,7 @@ static ScheduleDAGInstrs *createInstructionShuffler(MachineSchedContext *C) {
33953394
bool TopDown = !ForceBottomUp;
33963395
assert((TopDown || !ForceTopDown) &&
33973396
"-misched-topdown incompatible with -misched-bottomup");
3398-
return new ScheduleDAGMILive(C, new InstructionShuffler(Alternate, TopDown));
3397+
return new ScheduleDAGMILive(C, make_unique<InstructionShuffler>(Alternate, TopDown));
33993398
}
34003399
static MachineSchedRegistry ShufflerRegistry(
34013400
"shuffle", "Shuffle machine instructions alternating directions",

lib/Target/Hexagon/HexagonMachineScheduler.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ VLIWResourceModel(const TargetMachine &TM, const TargetSchedModel *SM) :
9393
/// top-level schedule() driver.
9494
class VLIWMachineScheduler : public ScheduleDAGMILive {
9595
public:
96-
VLIWMachineScheduler(MachineSchedContext *C, MachineSchedStrategy *S):
97-
ScheduleDAGMILive(C, S) {}
96+
VLIWMachineScheduler(MachineSchedContext *C,
97+
std::unique_ptr<MachineSchedStrategy> S)
98+
: ScheduleDAGMILive(C, std::move(S)) {}
9899

99100
/// Schedule - This is called back from ScheduleDAGInstrs::Run() when it's
100101
/// time to do some work.

lib/Target/Hexagon/HexagonTargetMachine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extern "C" void LLVMInitializeHexagonTarget() {
5252
}
5353

5454
static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) {
55-
return new VLIWMachineScheduler(C, new ConvergingVLIWScheduler());
55+
return new VLIWMachineScheduler(C, make_unique<ConvergingVLIWScheduler>());
5656
}
5757

5858
static MachineSchedRegistry

lib/Target/R600/AMDGPUTargetMachine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extern "C" void LLVMInitializeR600Target() {
4242
}
4343

4444
static ScheduleDAGInstrs *createR600MachineScheduler(MachineSchedContext *C) {
45-
return new ScheduleDAGMILive(C, new R600SchedStrategy());
45+
return new ScheduleDAGMILive(C, make_unique<R600SchedStrategy>());
4646
}
4747

4848
static MachineSchedRegistry

0 commit comments

Comments
 (0)