From 0f70bc05b34be5792c5e831366639e3f8bd26f19 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Thu, 23 Aug 2018 18:42:37 +0000 Subject: [PATCH] [llvm-mca] Set the Selection strategy to Default if nullptr is passed. * Set (not reset) the strategy in Scheduler::setCustomStrategyImpl() llvm-svn: 340566 --- llvm/tools/llvm-mca/Scheduler.cpp | 7 ++++++- llvm/tools/llvm-mca/Scheduler.h | 20 ++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/llvm/tools/llvm-mca/Scheduler.cpp b/llvm/tools/llvm-mca/Scheduler.cpp index 4ba48a2..cc904c8 100644 --- a/llvm/tools/llvm-mca/Scheduler.cpp +++ b/llvm/tools/llvm-mca/Scheduler.cpp @@ -24,6 +24,11 @@ using namespace llvm; ResourceStrategy::~ResourceStrategy() = default; +void Scheduler::initializeStrategy(std::unique_ptr S) { + // Ensure we have a valid (non-null) strategy object. + Strategy = S ? std::move(S) : llvm::make_unique(); +} + void DefaultResourceStrategy::skipMask(uint64_t Mask) { NextInSequenceMask &= (~Mask); if (!NextInSequenceMask) { @@ -116,7 +121,7 @@ void ResourceManager::setCustomStrategyImpl(std::unique_ptr S, unsigned Index = getResourceStateIndex(ResourceID); assert(Index < Resources.size() && "Invalid processor resource index!"); assert(S && "Unexpected null strategy in input!"); - Strategies[Index].reset(S.get()); + Strategies[Index] = std::move(S); } unsigned ResourceManager::resolveResourceMask(uint64_t Mask) const { diff --git a/llvm/tools/llvm-mca/Scheduler.h b/llvm/tools/llvm-mca/Scheduler.h index 37ebdb4..ed138fd 100644 --- a/llvm/tools/llvm-mca/Scheduler.h +++ b/llvm/tools/llvm-mca/Scheduler.h @@ -430,6 +430,11 @@ class Scheduler : public HardwareUnit { std::vector ReadySet; std::vector IssuedSet; + /// Verify the given selection strategy and set the Strategy member + /// accordingly. If no strategy is provided, the DefaultSchedulerStrategy is + /// used. + void initializeStrategy(std::unique_ptr S); + /// Issue an instruction without updating the ready queue. void issueInstructionImpl( InstRef &IR, @@ -446,16 +451,19 @@ class Scheduler : public HardwareUnit { public: Scheduler(const llvm::MCSchedModel &Model, LSUnit *Lsu) - : LSU(Lsu), Strategy(llvm::make_unique()), - Resources(llvm::make_unique(Model)) {} + : LSU(Lsu), Resources(llvm::make_unique(Model)) { + initializeStrategy(nullptr); + } Scheduler(const llvm::MCSchedModel &Model, LSUnit *Lsu, std::unique_ptr SelectStrategy) - : LSU(Lsu), Strategy(std::move(SelectStrategy)), - Resources(llvm::make_unique(Model)) {} + : LSU(Lsu), Resources(llvm::make_unique(Model)) { + initializeStrategy(std::move(SelectStrategy)); + } Scheduler(std::unique_ptr RM, LSUnit *Lsu, std::unique_ptr SelectStrategy) - : LSU(Lsu), Strategy(std::move(SelectStrategy)), - Resources(std::move(RM)) {} + : LSU(Lsu), Resources(std::move(RM)) { + initializeStrategy(std::move(SelectStrategy)); + } // Stalls generated by the scheduler. enum Status { -- 2.7.4