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
This commit is contained in:
David Blaikie 2014-04-21 20:32:32 +00:00
parent d0da5af325
commit 52d629e1bc
5 changed files with 34 additions and 29 deletions

View File

@ -81,6 +81,8 @@
#include "llvm/CodeGen/RegisterPressure.h" #include "llvm/CodeGen/RegisterPressure.h"
#include "llvm/CodeGen/ScheduleDAGInstrs.h" #include "llvm/CodeGen/ScheduleDAGInstrs.h"
#include <memory>
namespace llvm { namespace llvm {
extern cl::opt<bool> ForceTopDown; extern cl::opt<bool> ForceTopDown;
@ -221,14 +223,14 @@ public:
class ScheduleDAGMI : public ScheduleDAGInstrs { class ScheduleDAGMI : public ScheduleDAGInstrs {
protected: protected:
AliasAnalysis *AA; AliasAnalysis *AA;
MachineSchedStrategy *SchedImpl; std::unique_ptr<MachineSchedStrategy> SchedImpl;
/// Topo - A topological ordering for SUnits which permits fast IsReachable /// Topo - A topological ordering for SUnits which permits fast IsReachable
/// and similar queries. /// and similar queries.
ScheduleDAGTopologicalSort Topo; ScheduleDAGTopologicalSort Topo;
/// Ordered list of DAG postprocessing steps. /// Ordered list of DAG postprocessing steps.
std::vector<ScheduleDAGMutation*> Mutations; std::vector<std::unique_ptr<ScheduleDAGMutation>> Mutations;
/// The top of the unscheduled zone. /// The top of the unscheduled zone.
MachineBasicBlock::iterator CurrentTop; MachineBasicBlock::iterator CurrentTop;
@ -246,17 +248,19 @@ protected:
unsigned NumInstrsScheduled; unsigned NumInstrsScheduled;
#endif #endif
public: public:
ScheduleDAGMI(MachineSchedContext *C, MachineSchedStrategy *S, bool IsPostRA): ScheduleDAGMI(MachineSchedContext *C, std::unique_ptr<MachineSchedStrategy> S,
ScheduleDAGInstrs(*C->MF, *C->MLI, *C->MDT, IsPostRA, bool IsPostRA)
/*RemoveKillFlags=*/IsPostRA, C->LIS), : ScheduleDAGInstrs(*C->MF, *C->MLI, *C->MDT, IsPostRA,
AA(C->AA), SchedImpl(S), Topo(SUnits, &ExitSU), CurrentTop(), /*RemoveKillFlags=*/IsPostRA, C->LIS),
CurrentBottom(), NextClusterPred(nullptr), NextClusterSucc(nullptr) { AA(C->AA), SchedImpl(std::move(S)), Topo(SUnits, &ExitSU), CurrentTop(),
CurrentBottom(), NextClusterPred(nullptr), NextClusterSucc(nullptr) {
#ifndef NDEBUG #ifndef NDEBUG
NumInstrsScheduled = 0; NumInstrsScheduled = 0;
#endif #endif
} }
virtual ~ScheduleDAGMI(); // Provide a vtable anchor
~ScheduleDAGMI() override;
/// Return true if this DAG supports VReg liveness and RegPressure. /// Return true if this DAG supports VReg liveness and RegPressure.
virtual bool hasVRegLiveness() const { return false; } virtual bool hasVRegLiveness() const { return false; }
@ -266,8 +270,8 @@ public:
/// building and before MachineSchedStrategy initialization. /// building and before MachineSchedStrategy initialization.
/// ///
/// ScheduleDAGMI takes ownership of the Mutation object. /// ScheduleDAGMI takes ownership of the Mutation object.
void addMutation(ScheduleDAGMutation *Mutation) { void addMutation(std::unique_ptr<ScheduleDAGMutation> Mutation) {
Mutations.push_back(Mutation); Mutations.push_back(std::move(Mutation));
} }
/// \brief True if an edge can be added from PredSU to SuccSU without creating /// \brief True if an edge can be added from PredSU to SuccSU without creating
@ -375,11 +379,12 @@ protected:
RegPressureTracker BotRPTracker; RegPressureTracker BotRPTracker;
public: public:
ScheduleDAGMILive(MachineSchedContext *C, MachineSchedStrategy *S): ScheduleDAGMILive(MachineSchedContext *C,
ScheduleDAGMI(C, S, /*IsPostRA=*/false), RegClassInfo(C->RegClassInfo), std::unique_ptr<MachineSchedStrategy> S)
DFSResult(nullptr), ShouldTrackPressure(false), RPTracker(RegPressure), : ScheduleDAGMI(C, std::move(S), /*IsPostRA=*/false),
TopRPTracker(TopPressure), BotRPTracker(BotPressure) RegClassInfo(C->RegClassInfo), DFSResult(nullptr),
{} ShouldTrackPressure(false), RPTracker(RegPressure),
TopRPTracker(TopPressure), BotRPTracker(BotPressure) {}
virtual ~ScheduleDAGMILive(); virtual ~ScheduleDAGMILive();

View File

@ -487,9 +487,8 @@ void ReadyQueue::dump() {
// virtual registers. // virtual registers.
// ===----------------------------------------------------------------------===/ // ===----------------------------------------------------------------------===/
// Provide a vtable anchor.
ScheduleDAGMI::~ScheduleDAGMI() { ScheduleDAGMI::~ScheduleDAGMI() {
DeleteContainerPointers(Mutations);
delete SchedImpl;
} }
bool ScheduleDAGMI::canAddEdge(SUnit *SuccSU, SUnit *PredSU) { bool ScheduleDAGMI::canAddEdge(SUnit *SuccSU, SUnit *PredSU) {
@ -3002,17 +3001,17 @@ void GenericScheduler::schedNode(SUnit *SU, bool IsTopNode) {
/// Create the standard converging machine scheduler. This will be used as the /// Create the standard converging machine scheduler. This will be used as the
/// default scheduler if the target does not set a default. /// default scheduler if the target does not set a default.
static ScheduleDAGInstrs *createGenericSchedLive(MachineSchedContext *C) { static ScheduleDAGInstrs *createGenericSchedLive(MachineSchedContext *C) {
ScheduleDAGMILive *DAG = new ScheduleDAGMILive(C, new GenericScheduler(C)); ScheduleDAGMILive *DAG = new ScheduleDAGMILive(C, make_unique<GenericScheduler>(C));
// Register DAG post-processors. // Register DAG post-processors.
// //
// FIXME: extend the mutation API to allow earlier mutations to instantiate // FIXME: extend the mutation API to allow earlier mutations to instantiate
// data and pass it to later mutations. Have a single mutation that gathers // data and pass it to later mutations. Have a single mutation that gathers
// the interesting nodes in one pass. // the interesting nodes in one pass.
DAG->addMutation(new CopyConstrain(DAG->TII, DAG->TRI)); DAG->addMutation(make_unique<CopyConstrain>(DAG->TII, DAG->TRI));
if (EnableLoadCluster && DAG->TII->enableClusterLoads()) if (EnableLoadCluster && DAG->TII->enableClusterLoads())
DAG->addMutation(new LoadClusterMutation(DAG->TII, DAG->TRI)); DAG->addMutation(make_unique<LoadClusterMutation>(DAG->TII, DAG->TRI));
if (EnableMacroFusion) if (EnableMacroFusion)
DAG->addMutation(new MacroFusion(DAG->TII)); DAG->addMutation(make_unique<MacroFusion>(DAG->TII));
return DAG; return DAG;
} }
@ -3198,7 +3197,7 @@ void PostGenericScheduler::schedNode(SUnit *SU, bool IsTopNode) {
/// Create a generic scheduler with no vreg liveness or DAG mutation passes. /// Create a generic scheduler with no vreg liveness or DAG mutation passes.
static ScheduleDAGInstrs *createGenericSchedPostRA(MachineSchedContext *C) { static ScheduleDAGInstrs *createGenericSchedPostRA(MachineSchedContext *C) {
return new ScheduleDAGMI(C, new PostGenericScheduler(C), /*IsPostRA=*/true); return new ScheduleDAGMI(C, make_unique<PostGenericScheduler>(C), /*IsPostRA=*/true);
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -3303,10 +3302,10 @@ public:
} // namespace } // namespace
static ScheduleDAGInstrs *createILPMaxScheduler(MachineSchedContext *C) { static ScheduleDAGInstrs *createILPMaxScheduler(MachineSchedContext *C) {
return new ScheduleDAGMILive(C, new ILPScheduler(true)); return new ScheduleDAGMILive(C, make_unique<ILPScheduler>(true));
} }
static ScheduleDAGInstrs *createILPMinScheduler(MachineSchedContext *C) { static ScheduleDAGInstrs *createILPMinScheduler(MachineSchedContext *C) {
return new ScheduleDAGMILive(C, new ILPScheduler(false)); return new ScheduleDAGMILive(C, make_unique<ILPScheduler>(false));
} }
static MachineSchedRegistry ILPMaxRegistry( static MachineSchedRegistry ILPMaxRegistry(
"ilpmax", "Schedule bottom-up for max ILP", createILPMaxScheduler); "ilpmax", "Schedule bottom-up for max ILP", createILPMaxScheduler);
@ -3395,7 +3394,7 @@ static ScheduleDAGInstrs *createInstructionShuffler(MachineSchedContext *C) {
bool TopDown = !ForceBottomUp; bool TopDown = !ForceBottomUp;
assert((TopDown || !ForceTopDown) && assert((TopDown || !ForceTopDown) &&
"-misched-topdown incompatible with -misched-bottomup"); "-misched-topdown incompatible with -misched-bottomup");
return new ScheduleDAGMILive(C, new InstructionShuffler(Alternate, TopDown)); return new ScheduleDAGMILive(C, make_unique<InstructionShuffler>(Alternate, TopDown));
} }
static MachineSchedRegistry ShufflerRegistry( static MachineSchedRegistry ShufflerRegistry(
"shuffle", "Shuffle machine instructions alternating directions", "shuffle", "Shuffle machine instructions alternating directions",

View File

@ -93,8 +93,9 @@ VLIWResourceModel(const TargetMachine &TM, const TargetSchedModel *SM) :
/// top-level schedule() driver. /// top-level schedule() driver.
class VLIWMachineScheduler : public ScheduleDAGMILive { class VLIWMachineScheduler : public ScheduleDAGMILive {
public: public:
VLIWMachineScheduler(MachineSchedContext *C, MachineSchedStrategy *S): VLIWMachineScheduler(MachineSchedContext *C,
ScheduleDAGMILive(C, S) {} std::unique_ptr<MachineSchedStrategy> S)
: ScheduleDAGMILive(C, std::move(S)) {}
/// Schedule - This is called back from ScheduleDAGInstrs::Run() when it's /// Schedule - This is called back from ScheduleDAGInstrs::Run() when it's
/// time to do some work. /// time to do some work.

View File

@ -52,7 +52,7 @@ extern "C" void LLVMInitializeHexagonTarget() {
} }
static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) { static ScheduleDAGInstrs *createVLIWMachineSched(MachineSchedContext *C) {
return new VLIWMachineScheduler(C, new ConvergingVLIWScheduler()); return new VLIWMachineScheduler(C, make_unique<ConvergingVLIWScheduler>());
} }
static MachineSchedRegistry static MachineSchedRegistry

View File

@ -42,7 +42,7 @@ extern "C" void LLVMInitializeR600Target() {
} }
static ScheduleDAGInstrs *createR600MachineScheduler(MachineSchedContext *C) { static ScheduleDAGInstrs *createR600MachineScheduler(MachineSchedContext *C) {
return new ScheduleDAGMILive(C, new R600SchedStrategy()); return new ScheduleDAGMILive(C, make_unique<R600SchedStrategy>());
} }
static MachineSchedRegistry static MachineSchedRegistry