Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2e47e30
Implement combined GT
Quincunx271 Aug 26, 2020
f6ad66f
Make it work
Quincunx271 Sep 7, 2020
34b1957
Delay GT until after SeqListScheduler
Quincunx271 Sep 29, 2020
7fef6a9
Fix after-GT fixup to only do what's needed
Quincunx271 Feb 16, 2021
4466dc6
Revert "Fix after-GT fixup to only do what's needed"
Quincunx271 Feb 18, 2021
28b2317
Just reset what needs to be reset
Quincunx271 Feb 18, 2021
f6715d5
Move GT application to after heuristic
Quincunx271 Jan 13, 2021
1aae979
Fix gt; function was removed
Jan 13, 2021
71f4fb1
Actually run transformations
Jan 15, 2021
d312291
Print Ready list heuristics
Jan 21, 2021
631df69
Fix recomputation of upper/lower bounds
Quincunx271 Mar 5, 2021
e159823
Make Graph Trans application location an option
Quincunx271 Mar 8, 2021
33bc6ed
Enable a different position for second pass GT
Quincunx271 Mar 16, 2021
490e7cf
Log around possibly costly operations
Quincunx271 Mar 16, 2021
7e30eb5
Add removal of redundant edges
Quincunx271 Apr 30, 2021
9188af5
Fix error
Quincunx271 Apr 30, 2021
c0c5b25
Fix edge removal
Quincunx271 May 2, 2021
7eba7b3
Correctly output / update bounds / norm costs
Quincunx271 Jun 15, 2021
b42ceb7
Reset live intervals before computing SLIL LB
Quincunx271 Jun 16, 2021
fbdd86d
Support C++11
Quincunx271 Jun 23, 2021
5fec42c
Only recalc. bounds after GT if already computed
Quincunx271 Jun 28, 2021
dbd3ddd
Fix ILP redundant edge conditions
Quincunx271 Jun 29, 2021
445253d
Try using steady_clock instead of system_clock
Quincunx271 Jul 13, 2021
d0d4861
Record time taken by heuristic and LB
Quincunx271 Jul 14, 2021
598993c
Log TargetOccupancy
Quincunx271 Jul 24, 2021
37e696c
Remove unused function
Quincunx271 Aug 19, 2021
f433b68
Skip scheduling for regions which are too large
Quincunx271 Oct 15, 2021
f7a3c63
Improve the naming of the timing utility
Quincunx271 Oct 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions example/optsched-cfg/sched.ini
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ SECOND_PASS_LENGTH_TIMEOUT 5
# BLOCK : use the time limits in the above fields as is
TIMEOUT_PER INSTR

# The maximum number of instructions to use the scheduler for.
# Beyond this size, the heuristic scheduler is used.
MAX_REGION_LENGTH 2147483647

# The heuristic used for the list scheduler. Valid values are any combination of:
# CP: critical path
# LUC: last use count
Expand Down Expand Up @@ -243,9 +247,29 @@ REGIONS_TO_SCHEDULE fft1D_512:114
# history domination is disabled.
ENABLE_SUFFIX_CONCATENATION NO

# Where to perform graph transformations. Valid values are any combination of:
# BH - before heuristic; run on all blocks that we schedule
# AH - after heuristic; only if the heuristic scheduler doesn't prove optimality
GT_POSITION AH

# Where to perform graph transformations for the second pass.
# Valid values are the same as with GT_POSITION.
# However, note that the sequential list scheduler is practically never
# going to give an optimal schedule, so BH is almost certainly superior.
2ND_PASS_GT_POSITION BH

# Whether to apply the node superiority graph transformation.
STATIC_NODE_SUPERIORITY NO

# Whether to apply the ILP only node superiority graph transformation.
STATIC_NODE_SUPERIORITY_ILP NO

# Whether to apply the combined node superiority graph transformation.
STATIC_NODE_SUPERIORITY_ILP_PRESERVE_OCCUPANCY NO

# Whether the second pass of the two pass algorithm should use the combined node superiority graph transformation.
2ND_PASS_ILP_NODE_SUPERIORITY_PRESERVING_OCCUPANCY NO

# Whether to apply node superiority in multiple passes.
MULTI_PASS_NODE_SUPERIORITY NO

Expand Down
2 changes: 1 addition & 1 deletion include/opt-sched/Scheduler/bb_spill.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class BBWithSpill : public SchedRegion {
SchedPriorities hurstcPrirts, SchedPriorities enumPrirts,
bool vrfySched, Pruning PruningStrategy, bool SchedForRPOnly,
bool enblStallEnum, int SCW, SPILL_COST_FUNCTION spillCostFunc,
SchedulerType HeurSchedType);
SchedulerType HeurSchedType, GT_POSITION GraphTransPosition);
~BBWithSpill();

InstCount CmputExecCostLwrBound();
Expand Down
12 changes: 10 additions & 2 deletions include/opt-sched/Scheduler/graph_trans.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ class StaticNodeSupTrans : public GraphTrans {

static bool isNodeSuperior(DataDepGraph &DDG, int A, int B);

struct Statistics {
int NumEdgesAdded = 0;
int NumEdgesRemoved = 0;
};
static void removeRedundantEdges(DataDepGraph &DDG, int i, int j,
Statistics &Stats);

private:
// Are multiple passes enabled.
bool IsMultiPass;
Expand All @@ -103,8 +110,9 @@ class StaticNodeSupTrans : public GraphTrans {

// Check if there is superiority involving nodes A and B. If yes, choose which
// edge to add.
// Returns true if a superior edge was added.
bool TryAddingSuperiorEdge_(SchedInstruction *nodeA, SchedInstruction *nodeB);
// Returns the added edge if added, else nullptr
GraphEdge *TryAddingSuperiorEdge_(SchedInstruction *nodeA,
SchedInstruction *nodeB);

// Keep trying to find superior nodes until none can be found or there are no
// more independent nodes.
Expand Down
31 changes: 31 additions & 0 deletions include/opt-sched/Scheduler/graph_trans_ilp_occupancy_preserving.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
Description: Implement graph transformations to be applied before scheduling.
Author: Justin Bassett
Created: Aug. 2020
Last Update: Aug. 2020
*******************************************************************************/

#ifndef OPTSCHED_BASIC_GRAPH_TRANS_ILP_OCCUPANCY_PRESERVING_H
#define OPTSCHED_BASIC_GRAPH_TRANS_ILP_OCCUPANCY_PRESERVING_H

#include "opt-sched/Scheduler/graph_trans.h"

namespace llvm {
namespace opt_sched {

// Node superiority Occupancy preserving ILP graph transformation.
class StaticNodeSupOccupancyPreservingILPTrans : public GraphTrans {
public:
StaticNodeSupOccupancyPreservingILPTrans(DataDepGraph *dataDepGraph);

const char *Name() const override {
return "occupancy-preserving-ilp.nodesup";
}

FUNC_RESULT ApplyTrans() override;
};

} // namespace opt_sched
} // namespace llvm

#endif
7 changes: 7 additions & 0 deletions include/opt-sched/Scheduler/ready_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ class ReadyList {
// Constructs the priority-list key based on the schemes listed in prirts_.
unsigned long CmputKey_(SchedInstruction *inst, bool isUpdate, bool &changed);

template <typename InstructionVisitor>
void ForEachReadyInstruction(InstructionVisitor &&visitor) const {
for (const SchedInstruction &Inst : prirtyLst_) {
visitor(Inst);
}
}

private:
// An ordered vector of priorities
SchedPriorities prirts_;
Expand Down
70 changes: 69 additions & 1 deletion include/opt-sched/Scheduler/register.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Last Update: Jun. 2017
#include "opt-sched/Scheduler/sched_basic_data.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/iterator.h"
#include <memory>

using namespace llvm;
Expand Down Expand Up @@ -87,6 +88,8 @@ class Register {
bool IsInPossibleInterval(const SchedInstruction *inst) const;
const InstSetType &GetPossibleLiveInterval() const;

void resetLiveInterval();

private:
int16_t type_;
int num_;
Expand Down Expand Up @@ -124,10 +127,75 @@ class Register {

// Represents a file of registers of a certain type and tracks their usages.
class RegisterFile {
template <bool IsConst, typename R = typename std::conditional<
IsConst, const Register, Register>::type>
class RegisterFileIterator
: public llvm::iterator_facade_base<RegisterFileIterator<IsConst>,
std::random_access_iterator_tag, R> {

public:
RegisterFileIterator() = default;
explicit RegisterFileIterator(const RegisterFile &File, int Index)
: File(&File), Index(Index) {}

template <bool IsConst_ = IsConst,
typename std::enable_if<IsConst_, int>::type = 0>
RegisterFileIterator(const RegisterFileIterator<false> &Rhs) noexcept
: File(Rhs.File), Index(Rhs.Index) {}

bool operator==(const RegisterFileIterator &Rhs) const {
assert(File == Rhs.File);
return Index == Rhs.Index;
}

bool operator<(const RegisterFileIterator &Rhs) const {
assert(File == Rhs.File);
return Index < Rhs.Index;
}

std::ptrdiff_t operator-(const RegisterFileIterator &Rhs) const {
return Index - Rhs.Index;
}

R &operator*() const { return *File->GetReg(Index); }

RegisterFileIterator &operator++() {
++Index;
return *this;
}

RegisterFileIterator &operator--() {
--Index;
return *this;
}

RegisterFileIterator &operator+=(std::ptrdiff_t n) {
Index += n;
return *this;
}

RegisterFileIterator &operator-=(std::ptrdiff_t n) {
Index -= n;
return *this;
}

private:
const RegisterFile *File = nullptr;
int Index = 0;
};

public:
using iterator = RegisterFileIterator<false>;
using const_iterator = RegisterFileIterator<true>;

RegisterFile();
~RegisterFile();

iterator begin() { return iterator(*this, 0); }
iterator end() { return iterator(*this, GetRegCnt()); }
const_iterator begin() const { return const_iterator(*this, 0); }
const_iterator end() const { return const_iterator(*this, GetRegCnt()); }

int GetRegCnt() const;
void SetRegCnt(int regCnt);

Expand Down Expand Up @@ -157,7 +225,7 @@ class RegisterFile {
private:
int16_t regType_;
int physRegCnt_;
mutable SmallVector<std::unique_ptr<Register>, 8> Regs;
SmallVector<std::unique_ptr<Register>, 8> Regs;
};

} // namespace opt_sched
Expand Down
4 changes: 2 additions & 2 deletions include/opt-sched/Scheduler/sched_basic_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ class SchedInstruction : public GraphNode {
void ComputeAdjustedUseCnt(SchedInstruction *inst);

int16_t CmputLastUseCnt();
int16_t GetLastUseCnt() { return lastUseCnt_; }
int16_t GetLastUseCnt() const { return lastUseCnt_; }

InstType GetCrtclPathFrmRoot() { return crtclPathFrmRoot_; }
InstType GetCrtclPathFrmRoot() const { return crtclPathFrmRoot_; }

friend class SchedRange;

Expand Down
45 changes: 44 additions & 1 deletion include/opt-sched/Scheduler/sched_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ enum class BLOCKS_TO_KEEP {
ALL
};

// Where to perform graph transformations; flag enum
enum class GT_POSITION : uint32_t {
NONE = 0x0,
// Run on all blocks before the heuristic
BEFORE_HEURISTIC = 0x1,
// Run only if the heuristic scheduler doesn't prove the schedule optimal
AFTER_HEURISTIC = 0x2,
};

inline GT_POSITION operator|(GT_POSITION lhs, GT_POSITION rhs) {
return (GT_POSITION)((uint32_t)lhs | (uint32_t)rhs);
}

inline GT_POSITION operator&(GT_POSITION lhs, GT_POSITION rhs) {
return (GT_POSITION)((uint32_t)lhs & (uint32_t)rhs);
}

inline GT_POSITION &operator|=(GT_POSITION &lhs, GT_POSITION rhs) {
return lhs = lhs | rhs;
}

inline GT_POSITION &operator&=(GT_POSITION &lhs, GT_POSITION rhs) {
return lhs = lhs & rhs;
}

class ListScheduler;

class SchedRegion {
Expand All @@ -48,7 +73,8 @@ class SchedRegion {
int16_t sigHashSize, LB_ALG lbAlg, SchedPriorities hurstcPrirts,
SchedPriorities enumPrirts, bool vrfySched,
Pruning PruningStrategy, SchedulerType HeurSchedType,
SPILL_COST_FUNCTION spillCostFunc = SCF_PERP);
SPILL_COST_FUNCTION spillCostFunc,
GT_POSITION GraphTransPosition);
// Destroys the region. Must be overriden by child classes.
virtual ~SchedRegion() {}

Expand Down Expand Up @@ -205,6 +231,9 @@ class SchedRegion {
// TODO(max): Document.
int16_t sigHashSize_;

// Where to apply graph transformations
GT_POSITION GraphTransPosition_;

// The pruning technique to use for this region.
Pruning prune_;

Expand All @@ -224,6 +253,11 @@ class SchedRegion {
// The best schedule found so far (may be heuristic or enumerator generated)
InstSchedule *bestSched_;

void CalculateUpperBounds(bool BbSchedulerEnabled);
void CalculateLowerBounds(bool BbSchedulerEnabled);

bool IsLowerBoundSet_ = false;
bool IsUpperBoundSet_ = false;
// TODO(max): Document.
InstCount schedLwrBound_;
// TODO(max): Document.
Expand All @@ -244,6 +278,8 @@ class SchedRegion {
// TODO(max): Document.
InstCount crntSlotNum_;

bool needsTransitiveClosure(Milliseconds rgnTimeout) const;

// protected accessors:
SchedulerType GetHeuristicSchedulerType() const { return HeurSchedType_; }

Expand Down Expand Up @@ -324,6 +360,13 @@ class SchedRegion {

FUNC_RESULT runACO(InstSchedule *ReturnSched, InstSchedule *InitSched,
bool IsPostBB);

FUNC_RESULT applyGraphTransformations(bool BbScheduleEnabled,
InstSchedule *heuristicSched,
bool &isLstOptml,
InstSchedule *&bestSched);
FUNC_RESULT applyGraphTransformation(GraphTrans *GT);
void updateBoundsAfterGraphTransformations(bool BbSchedulerEnabled);
};

} // namespace opt_sched
Expand Down
11 changes: 9 additions & 2 deletions include/opt-sched/Scheduler/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ uint16_t clcltBitsNeededToHoldNum(uint64_t value);
Milliseconds GetProcessorTime();
// Returns a reference to an object that is supposed to initialized with the
// start time of the process
extern std::chrono::high_resolution_clock::time_point startTime;
extern std::chrono::steady_clock::time_point startTime;

// Executes the function, returning the number of milliseconds it took to do so.
template <typename F> Milliseconds countMillisToExecute(F &&fn) {
const Milliseconds Start = GetProcessorTime();
fn();
return GetProcessorTime() - Start;
}
} // namespace Utilities

inline uint16_t Utilities::clcltBitsNeededToHoldNum(uint64_t value) {
Expand All @@ -36,7 +43,7 @@ inline uint16_t Utilities::clcltBitsNeededToHoldNum(uint64_t value) {
}

inline Milliseconds Utilities::GetProcessorTime() {
auto currentTime = std::chrono::high_resolution_clock::now();
auto currentTime = std::chrono::steady_clock::now();
std::chrono::duration<double, std::milli> elapsed = currentTime - startTime;
return elapsed.count();
}
Expand Down
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(OPTSCHED_SRCS Scheduler/aco.cpp
Scheduler/graph.cpp
Scheduler/graph_trans.cpp
Scheduler/graph_trans_ilp.cpp
Scheduler/graph_trans_ilp_occupancy_preserving.cpp
Scheduler/hist_table.cpp
Scheduler/list_sched.cpp
Scheduler/logger.cpp
Expand Down
Loading