Skip to content

Commit

Permalink
Clang formatted and removed irrelevant comments & #if directive
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-mchugh committed May 21, 2021
1 parent 4bd33be commit 98a2517
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
7 changes: 3 additions & 4 deletions include/opt-sched/Scheduler/aco.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Last Update: Jan. 2020
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include <limits>
#include <map>
#include <memory>
#include <utility>
#include <limits>
namespace llvm {
namespace opt_sched {

Expand All @@ -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
};

Expand Down Expand Up @@ -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
Expand Down
49 changes: 26 additions & 23 deletions lib/Scheduler/aco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -282,7 +284,8 @@ Choice ACOScheduler::SelectInstruction(const llvm::ArrayRef<Choice> &ready,
return ready.back();
}

std::unique_ptr<InstSchedule> ACOScheduler::FindOneSchedule(InstCount TargetRPCost) {
std::unique_ptr<InstSchedule>
ACOScheduler::FindOneSchedule(InstCount TargetRPCost) {
SchedInstruction *lastInst = NULL;
std::unique_ptr<InstSchedule> schedule =
llvm::make_unique<InstSchedule>(machMdl_, dataDepGraph_, true);
Expand Down Expand Up @@ -408,25 +411,18 @@ std::unique_ptr<InstSchedule> 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);
if (MovToNxtSlot_(inst))
InitNewCycle_();
rdyLst_->ResetIterator();
ready.clear();

}
rgn_->UpdateScheduleCost(schedule.get());
return schedule;
Expand All @@ -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");
Expand Down Expand Up @@ -491,11 +487,16 @@ FUNC_RESULT ACOScheduler::FindSchedule(InstSchedule *schedule_out,
std::unique_ptr<InstSchedule> iterationBest;
for (int i = 0; i < ants_per_iteration; i++) {
CrntAntEdges.clear();
std::unique_ptr<InstSchedule> schedule = FindOneSchedule(i && iterationBest && rgn_->GetSpillCostFunc() != SCF_SLIL ? iterationBest->GetNormSpillCost() : MaxRPTarget);
std::unique_ptr<InstSchedule> 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)) {
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion lib/Scheduler/bb_spill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 2 additions & 3 deletions lib/Scheduler/gen_sched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ bool ConstrainedScheduler::Initialize_(InstCount trgtSchedLngth,
return false;
}


//wipe the ready list per cycle
for (InstCount i = 0; i<schedUprBound_; ++i) {
// wipe the ready list per cycle
for (InstCount i = 0; i < schedUprBound_; ++i) {
if (frstRdyLstPerCycle_[i])
frstRdyLstPerCycle_[i]->Reset();
}
Expand Down

0 comments on commit 98a2517

Please sign in to comment.