diff --git a/include/opt-sched/Scheduler/aco.h b/include/opt-sched/Scheduler/aco.h index dce657d5..6ecda69f 100644 --- a/include/opt-sched/Scheduler/aco.h +++ b/include/opt-sched/Scheduler/aco.h @@ -14,10 +14,10 @@ Last Update: Jan. 2020 #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" +#include #include #include #include -#include namespace llvm { namespace opt_sched { @@ -32,7 +32,7 @@ enum class DCF_OPT { struct Choice { SchedInstruction *inst; - pheromone_t heuristic; // range 1 to 2 + pheromone_t heuristic; // range 1 to 2 InstCount readyOn; // number of cycles until this instruction becomes ready }; @@ -101,8 +101,7 @@ class ACOScheduler : public ConstrainedScheduler { pheromone_t ScRelMax; DCF_OPT DCFOption; SPILL_COST_FUNCTION DCFCostFn; - int localCmp=0, localCmpRej=0, globalCmp=0, globalCmpRej=0; - + int localCmp = 0, localCmpRej = 0, globalCmp = 0, globalCmpRej = 0; }; } // namespace opt_sched diff --git a/lib/Scheduler/aco.cpp b/lib/Scheduler/aco.cpp index 1ee03378..6569ff61 100644 --- a/lib/Scheduler/aco.cpp +++ b/lib/Scheduler/aco.cpp @@ -58,7 +58,8 @@ ACOScheduler::ACOScheduler(DataDepGraph *dataDepGraph, local_decay = schedIni.GetFloat("ACO_LOCAL_DECAY"); decay_factor = schedIni.GetFloat("ACO_DECAY_FACTOR"); ants_per_iteration1p = schedIni.GetInt("ACO_ANT_PER_ITERATION"); - ants_per_iteration2p = schedIni.GetInt("ACO2P_ANT_PER_ITERATION", ants_per_iteration1p); + ants_per_iteration2p = + schedIni.GetInt("ACO2P_ANT_PER_ITERATION", ants_per_iteration1p); ants_per_iteration = ants_per_iteration1p; print_aco_trace = schedIni.GetBool("ACO_TRACE"); IsTwoPassEn = schedIni.GetBool("USE_TWO_PASS"); @@ -114,11 +115,10 @@ pheromone_t &ACOScheduler::Pheromone(InstCount from, InstCount to) { return pheromone_[(row * count_) + to]; } - double ACOScheduler::Score(SchedInstruction *from, Choice choice) { -// tuneable heuristic importance is temporarily disabled -// return Pheromone(from, choice.inst) * -// pow(choice.heuristic, heuristicImportance_); + // tuneable heuristic importance is temporarily disabled + // return Pheromone(from, choice.inst) * + // pow(choice.heuristic, heuristicImportance_); double hf = heuristicImportance_ ? choice.heuristic : 1.0; return Pheromone(from, choice.inst) * hf; } @@ -196,10 +196,12 @@ bool ACOScheduler::shouldReplaceSchedule(InstSchedule *OldSched, InstCount NewSpillCost = NewSched->GetNormSpillCost(); InstCount OldSpillCost = OldSched->GetNormSpillCost(); #if DBG_SRS - Logger::Info("SRS2P/%sOld:%d,New:%d,OldNSC:%d,NewNSC:%d", IsGlobal ? "g/" : "", - OldCost, NewCost, OldSpillCost, NewSpillCost); + Logger::Info("SRS2P/%sOld:%d,New:%d,OldNSC:%d,NewNSC:%d", + IsGlobal ? "g/" : "", OldCost, NewCost, OldSpillCost, + NewSpillCost); #endif // DBG_SRS - return (NewCost < OldCost && NewSpillCost <= OldSpillCost) || NewSpillCost < OldSpillCost; + return (NewCost < OldCost && NewSpillCost <= OldSpillCost) || + NewSpillCost < OldSpillCost; } } @@ -282,7 +284,8 @@ Choice ACOScheduler::SelectInstruction(const llvm::ArrayRef &ready, return ready.back(); } -std::unique_ptr ACOScheduler::FindOneSchedule(InstCount TargetRPCost) { +std::unique_ptr +ACOScheduler::FindOneSchedule(InstCount TargetRPCost) { SchedInstruction *lastInst = NULL; std::unique_ptr schedule = llvm::make_unique(machMdl_, dataDepGraph_, true); @@ -408,17 +411,11 @@ std::unique_ptr ACOScheduler::FindOneSchedule(InstCount TargetRPCo rdyLst_->RemoveNextPriorityInst(); UpdtSlotAvlblty_(inst); -#define STOP_CONSTRUCTION_IF_INFEASIBLE 1 - -//this is a bugged compile time optimization. It causes crashes. -#if STOP_CONSTRUCTION_IF_INFEASIBLE if (rgn_->getUnnormalizedIncrementalRPCost() > TargetRPCost) { delete rdyLst_; rdyLst_ = new ReadyList(dataDepGraph_, prirts_); return nullptr; } -#endif - } /* Logger::Info("Chose instruction %d (for some reason)", instNum); */ schedule->AppendInst(instNum); @@ -426,7 +423,6 @@ std::unique_ptr ACOScheduler::FindOneSchedule(InstCount TargetRPCo InitNewCycle_(); rdyLst_->ResetIterator(); ready.clear(); - } rgn_->UpdateScheduleCost(schedule.get()); return schedule; @@ -445,7 +441,7 @@ FUNC_RESULT ACOScheduler::FindSchedule(InstSchedule *schedule_out, ants_per_iteration = IsFirst ? ants_per_iteration1p : ants_per_iteration2p; noImprovementMax = schedIni.GetInt(IsFirst ? "ACO_STOP_ITERATIONS" : "ACO2P_STOP_ITERATIONS"); - Logger::Info("ants/it:%d,stop_iter:%d",ants_per_iteration,noImprovementMax); + Logger::Info("ants/it:%d,stop_iter:%d", ants_per_iteration, noImprovementMax); if (DCFOption != DCF_OPT::OFF) { std::string DcfFnString = schedIni.GetString(IsFirst ? "ACO_DUAL_COST_FN" : "ACO2P_DUAL_COST_FN"); @@ -491,11 +487,16 @@ FUNC_RESULT ACOScheduler::FindSchedule(InstSchedule *schedule_out, std::unique_ptr iterationBest; for (int i = 0; i < ants_per_iteration; i++) { CrntAntEdges.clear(); - std::unique_ptr schedule = FindOneSchedule(i && iterationBest && rgn_->GetSpillCostFunc() != SCF_SLIL ? iterationBest->GetNormSpillCost() : MaxRPTarget); + std::unique_ptr schedule = FindOneSchedule( + i && iterationBest && rgn_->GetSpillCostFunc() != SCF_SLIL + ? iterationBest->GetNormSpillCost() + : MaxRPTarget); if (print_aco_trace) PrintSchedule(schedule.get()); ++localCmp; - if (iterationBest && bestSchedule && !(!IsFirst && iterationBest->GetNormSpillCost() <= bestSchedule->GetNormSpillCost())) + if (iterationBest && bestSchedule && + !(!IsFirst && iterationBest->GetNormSpillCost() <= + bestSchedule->GetNormSpillCost())) ++localCmpRej; if (shouldReplaceSchedule(iterationBest.get(), schedule.get(), /*IsGlobal=*/false)) { @@ -505,10 +506,11 @@ FUNC_RESULT ACOScheduler::FindSchedule(InstSchedule *schedule_out, } } ++globalCmp; - if (IsFirst || iterationBest->GetNormSpillCost() <= bestSchedule->GetNormSpillCost()) { + if (IsFirst || + iterationBest->GetNormSpillCost() <= bestSchedule->GetNormSpillCost()) { UpdatePheromone(iterationBest.get()); - } - else ++globalCmpRej; + } else + ++globalCmpRej; /* PrintSchedule(iterationBest); */ /* std::cout << iterationBest->GetCost() << std::endl; */ // TODO DRY @@ -543,7 +545,8 @@ FUNC_RESULT ACOScheduler::FindSchedule(InstSchedule *schedule_out, iterations++; } - Logger::Info("localCmp:%d,localCmpRej:%d,globalCmp:%d,globalCmpRej:%d", localCmp, localCmpRej, globalCmp, globalCmpRej); + Logger::Info("localCmp:%d,localCmpRej:%d,globalCmp:%d,globalCmpRej:%d", + localCmp, localCmpRej, globalCmp, globalCmpRej); Logger::Event(IsPostBB ? "AcoPostSchedComplete" : "ACOSchedComplete", "cost", bestSchedule->GetCost(), "iterations", iterations, diff --git a/lib/Scheduler/bb_spill.cpp b/lib/Scheduler/bb_spill.cpp index 73a87483..c40a5382 100644 --- a/lib/Scheduler/bb_spill.cpp +++ b/lib/Scheduler/bb_spill.cpp @@ -343,7 +343,9 @@ void BBWithSpill::storeExtraCost(InstSchedule *sched, SPILL_COST_FUNCTION Scf) { /*****************************************************************************/ -InstCount BBWithSpill::getUnnormalizedIncrementalRPCost() {return crntSpillCost_;} +InstCount BBWithSpill::getUnnormalizedIncrementalRPCost() { + return crntSpillCost_; +} /*****************************************************************************/ void BBWithSpill::InitForSchdulng() { diff --git a/lib/Scheduler/gen_sched.cpp b/lib/Scheduler/gen_sched.cpp index dbb9918a..14e6ad10 100644 --- a/lib/Scheduler/gen_sched.cpp +++ b/lib/Scheduler/gen_sched.cpp @@ -107,9 +107,8 @@ bool ConstrainedScheduler::Initialize_(InstCount trgtSchedLngth, return false; } - - //wipe the ready list per cycle - for (InstCount i = 0; iReset(); }