2010-12-08 20:04:29 +00:00
|
|
|
//=- llvm/CodeGen/ScoreboardHazardRecognizer.h - Schedule Support -*- C++ -*-=//
|
2010-06-14 21:06:53 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2010-12-08 20:04:29 +00:00
|
|
|
// This file defines the ScoreboardHazardRecognizer class, which
|
|
|
|
// encapsulates hazard-avoidance heuristics for scheduling, based on the
|
2010-06-14 21:06:53 +00:00
|
|
|
// scheduling itineraries specified for the target.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-12-08 20:04:29 +00:00
|
|
|
#ifndef LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
|
|
|
|
#define LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
|
2010-06-14 21:06:53 +00:00
|
|
|
|
|
|
|
#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2010-06-14 21:06:53 +00:00
|
|
|
|
|
|
|
#include <cassert>
|
2010-06-14 22:44:26 +00:00
|
|
|
#include <cstring>
|
2010-06-14 21:06:53 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class InstrItineraryData;
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122541 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-24 05:03:26 +00:00
|
|
|
class ScheduleDAG;
|
2010-06-14 21:06:53 +00:00
|
|
|
class SUnit;
|
|
|
|
|
2010-12-08 20:04:29 +00:00
|
|
|
class ScoreboardHazardRecognizer : public ScheduleHazardRecognizer {
|
|
|
|
// Scoreboard to track function unit usage. Scoreboard[0] is a
|
2010-06-14 21:06:53 +00:00
|
|
|
// mask of the FUs in use in the cycle currently being
|
2010-12-08 20:04:29 +00:00
|
|
|
// schedule. Scoreboard[1] is a mask for the next cycle. The
|
|
|
|
// Scoreboard is used as a circular buffer with the current cycle
|
2010-06-14 21:06:53 +00:00
|
|
|
// indicated by Head.
|
2010-12-08 20:04:29 +00:00
|
|
|
//
|
|
|
|
// Scoreboard always counts cycles in forward execution order. If used by a
|
|
|
|
// bottom-up scheduler, then the scoreboard cycles are the inverse of the
|
|
|
|
// scheduler's cycles.
|
|
|
|
class Scoreboard {
|
2010-06-14 21:06:53 +00:00
|
|
|
unsigned *Data;
|
|
|
|
|
|
|
|
// The maximum number of cycles monitored by the Scoreboard. This
|
|
|
|
// value is determined based on the target itineraries to ensure
|
|
|
|
// that all hazards can be tracked.
|
|
|
|
size_t Depth;
|
|
|
|
// Indices into the Scoreboard that represent the current cycle.
|
|
|
|
size_t Head;
|
|
|
|
public:
|
2010-12-08 20:04:29 +00:00
|
|
|
Scoreboard():Data(NULL), Depth(0), Head(0) { }
|
|
|
|
~Scoreboard() {
|
2010-06-14 21:06:53 +00:00
|
|
|
delete[] Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t getDepth() const { return Depth; }
|
|
|
|
unsigned& operator[](size_t idx) const {
|
2010-12-08 20:04:29 +00:00
|
|
|
// Depth is expected to be a power-of-2.
|
|
|
|
assert(Depth && !(Depth & (Depth - 1)) &&
|
|
|
|
"Scoreboard was not initialized properly!");
|
2010-06-14 21:06:53 +00:00
|
|
|
|
2010-12-08 20:04:29 +00:00
|
|
|
return Data[(Head + idx) & (Depth-1)];
|
2010-06-14 21:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset(size_t d = 1) {
|
|
|
|
if (Data == NULL) {
|
|
|
|
Depth = d;
|
|
|
|
Data = new unsigned[Depth];
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(Data, 0, Depth * sizeof(Data[0]));
|
|
|
|
Head = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void advance() {
|
2010-12-08 20:04:29 +00:00
|
|
|
Head = (Head + 1) & (Depth-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void recede() {
|
|
|
|
Head = (Head - 1) & (Depth-1);
|
2010-06-14 21:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Print the scoreboard.
|
|
|
|
void dump() const;
|
|
|
|
};
|
|
|
|
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122541 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-24 05:03:26 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// Support for tracing ScoreboardHazardRecognizer as a component within
|
|
|
|
// another module. Follows the current thread-unsafe model of tracing.
|
|
|
|
static const char *DebugType;
|
|
|
|
#endif
|
|
|
|
|
2010-06-14 21:06:53 +00:00
|
|
|
// Itinerary data for the target.
|
2010-09-10 01:29:16 +00:00
|
|
|
const InstrItineraryData *ItinData;
|
2010-06-14 21:06:53 +00:00
|
|
|
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122541 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-24 05:03:26 +00:00
|
|
|
const ScheduleDAG *DAG;
|
|
|
|
|
|
|
|
/// IssueWidth - Max issue per cycle. 0=Unknown.
|
|
|
|
unsigned IssueWidth;
|
|
|
|
|
|
|
|
/// IssueCount - Count instructions issued in this cycle.
|
|
|
|
unsigned IssueCount;
|
|
|
|
|
2010-12-08 20:04:29 +00:00
|
|
|
Scoreboard ReservedScoreboard;
|
|
|
|
Scoreboard RequiredScoreboard;
|
2010-06-14 21:06:53 +00:00
|
|
|
|
|
|
|
public:
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122541 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-24 05:03:26 +00:00
|
|
|
ScoreboardHazardRecognizer(const InstrItineraryData *ItinData,
|
|
|
|
const ScheduleDAG *DAG,
|
|
|
|
const char *ParentDebugType = "");
|
|
|
|
|
|
|
|
/// atIssueLimit - Return true if no more instructions may be issued in this
|
|
|
|
/// cycle.
|
|
|
|
virtual bool atIssueLimit() const;
|
2010-06-14 21:06:53 +00:00
|
|
|
|
Various bits of framework needed for precise machine-level selection
DAG scheduling during isel. Most new functionality is currently
guarded by -enable-sched-cycles and -enable-sched-hazard.
Added InstrItineraryData::IssueWidth field, currently derived from
ARM itineraries, but could be initialized differently on other targets.
Added ScheduleHazardRecognizer::MaxLookAhead to indicate whether it is
active, and if so how many cycles of state it holds.
Added SchedulingPriorityQueue::HasReadyFilter to allowing gating entry
into the scheduler's available queue.
ScoreboardHazardRecognizer now accesses the ScheduleDAG in order to
get information about it's SUnits, provides RecedeCycle for bottom-up
scheduling, correctly computes scoreboard depth, tracks IssueCount, and
considers potential stall cycles when checking for hazards.
ScheduleDAGRRList now models machine cycles and hazards (under
flags). It tracks MinAvailableCycle, drives the hazard recognizer and
priority queue's ready filter, manages a new PendingQueue, properly
accounts for stall cycles, etc.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122541 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-24 05:03:26 +00:00
|
|
|
// Stalls provides an cycle offset at which SU will be scheduled. It will be
|
|
|
|
// negative for bottom-up scheduling.
|
|
|
|
virtual HazardType getHazardType(SUnit *SU, int Stalls);
|
2010-06-14 21:06:53 +00:00
|
|
|
virtual void Reset();
|
|
|
|
virtual void EmitInstruction(SUnit *SU);
|
|
|
|
virtual void AdvanceCycle();
|
2010-12-08 20:04:29 +00:00
|
|
|
virtual void RecedeCycle();
|
2010-06-14 21:06:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-12-08 20:04:29 +00:00
|
|
|
#endif //!LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
|