2010-12-08 21:04:29 +01:00
|
|
|
//===----- ScoreboardHazardRecognizer.cpp - Scheduler Support -------------===//
|
2009-08-10 17:55:25 +02: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 21:04:29 +01:00
|
|
|
// This file implements the ScoreboardHazardRecognizer class, which
|
|
|
|
// encapsultes hazard-avoidance heuristics for scheduling, based on the
|
|
|
|
// scheduling itineraries specified for the target.
|
2009-08-10 17:55:25 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-12-08 21:04:29 +01:00
|
|
|
#include "llvm/CodeGen/ScoreboardHazardRecognizer.h"
|
2010-06-14 23:06:53 +02:00
|
|
|
#include "llvm/CodeGen/ScheduleDAG.h"
|
2011-06-29 03:14:12 +02:00
|
|
|
#include "llvm/MC/MCInstrItineraries.h"
|
2009-08-10 17:55:25 +02:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-11 03:44:26 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-01-21 06:51:33 +01:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2009-08-10 17:55:25 +02:00
|
|
|
|
2009-08-22 22:08:44 +02:00
|
|
|
using namespace llvm;
|
2009-08-10 17:55:25 +02:00
|
|
|
|
2014-04-22 04:02:50 +02:00
|
|
|
#define DEBUG_TYPE ::llvm::ScoreboardHazardRecognizer::DebugType
|
|
|
|
|
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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
const char *ScoreboardHazardRecognizer::DebugType = "";
|
|
|
|
#endif
|
|
|
|
|
2010-12-08 21:04:29 +01:00
|
|
|
ScoreboardHazardRecognizer::
|
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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
ScoreboardHazardRecognizer(const InstrItineraryData *II,
|
|
|
|
const ScheduleDAG *SchedDAG,
|
|
|
|
const char *ParentDebugType) :
|
|
|
|
ScheduleHazardRecognizer(), ItinData(II), DAG(SchedDAG), IssueWidth(0),
|
|
|
|
IssueCount(0) {
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
DebugType = ParentDebugType;
|
|
|
|
#endif
|
|
|
|
|
2012-06-05 05:44:32 +02:00
|
|
|
// Determine the maximum depth of any itinerary. This determines the depth of
|
|
|
|
// the scoreboard. We always make the scoreboard at least 1 cycle deep to
|
|
|
|
// avoid dealing with the boundary condition.
|
2010-04-07 20:19:24 +02:00
|
|
|
unsigned ScoreboardDepth = 1;
|
2010-09-10 03:29:16 +02:00
|
|
|
if (ItinData && !ItinData->isEmpty()) {
|
2009-08-10 17:55:25 +02:00
|
|
|
for (unsigned idx = 0; ; ++idx) {
|
2010-09-10 03:29:16 +02:00
|
|
|
if (ItinData->isEndMarker(idx))
|
2009-08-10 17:55:25 +02:00
|
|
|
break;
|
|
|
|
|
2010-09-10 03:29:16 +02:00
|
|
|
const InstrStage *IS = ItinData->beginStage(idx);
|
|
|
|
const InstrStage *E = ItinData->endStage(idx);
|
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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
unsigned CurCycle = 0;
|
2009-08-10 17:55:25 +02:00
|
|
|
unsigned ItinDepth = 0;
|
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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
for (; IS != E; ++IS) {
|
|
|
|
unsigned StageDepth = CurCycle + IS->getCycles();
|
|
|
|
if (ItinDepth < StageDepth) ItinDepth = StageDepth;
|
|
|
|
CurCycle += IS->getNextCycles();
|
|
|
|
}
|
2009-08-10 17:55:25 +02:00
|
|
|
|
2010-12-08 21:04:29 +01:00
|
|
|
// Find the next power-of-2 >= ItinDepth
|
|
|
|
while (ItinDepth > ScoreboardDepth) {
|
|
|
|
ScoreboardDepth *= 2;
|
2012-06-05 05:44:32 +02:00
|
|
|
// Don't set MaxLookAhead until we find at least one nonzero stage.
|
|
|
|
// This way, an itinerary with no stages has MaxLookAhead==0, which
|
|
|
|
// completely bypasses the scoreboard hazard logic.
|
|
|
|
MaxLookAhead = ScoreboardDepth;
|
2010-12-08 21:04:29 +01:00
|
|
|
}
|
2009-08-10 17:55:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-07 20:19:32 +02:00
|
|
|
ReservedScoreboard.reset(ScoreboardDepth);
|
|
|
|
RequiredScoreboard.reset(ScoreboardDepth);
|
2009-08-10 17:55:25 +02:00
|
|
|
|
2012-07-07 06:00:00 +02:00
|
|
|
// If MaxLookAhead is not set above, then we are not enabled.
|
2012-06-05 05:44:40 +02:00
|
|
|
if (!isEnabled())
|
2012-06-05 05:44:32 +02:00
|
|
|
DEBUG(dbgs() << "Disabled scoreboard hazard recognizer\n");
|
2012-06-05 05:44:40 +02:00
|
|
|
else {
|
2012-07-07 06:00:00 +02:00
|
|
|
// A nonempty itinerary must have a SchedModel.
|
2014-09-02 19:43:54 +02:00
|
|
|
IssueWidth = ItinData->SchedModel.IssueWidth;
|
2012-06-05 05:44:32 +02:00
|
|
|
DEBUG(dbgs() << "Using scoreboard hazard recognizer: Depth = "
|
|
|
|
<< ScoreboardDepth << '\n');
|
2012-06-05 05:44:40 +02:00
|
|
|
}
|
2009-08-10 17:55:25 +02:00
|
|
|
}
|
|
|
|
|
2010-12-08 21:04:29 +01:00
|
|
|
void ScoreboardHazardRecognizer::Reset() {
|
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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
IssueCount = 0;
|
2010-04-07 20:19:32 +02:00
|
|
|
RequiredScoreboard.reset();
|
|
|
|
ReservedScoreboard.reset();
|
2009-08-10 17:55:25 +02:00
|
|
|
}
|
|
|
|
|
2012-09-12 00:23:19 +02:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2010-12-08 21:04:29 +01:00
|
|
|
void ScoreboardHazardRecognizer::Scoreboard::dump() const {
|
2010-01-04 22:26:07 +01:00
|
|
|
dbgs() << "Scoreboard:\n";
|
2010-04-07 20:19:24 +02:00
|
|
|
|
|
|
|
unsigned last = Depth - 1;
|
|
|
|
while ((last > 0) && ((*this)[last] == 0))
|
2009-08-10 17:55:25 +02:00
|
|
|
last--;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i <= last; i++) {
|
2012-06-22 22:27:13 +02:00
|
|
|
unsigned FUs = (*this)[i];
|
2010-01-04 22:26:07 +01:00
|
|
|
dbgs() << "\t";
|
2012-06-22 22:27:13 +02:00
|
|
|
for (int j = 31; j >= 0; j--)
|
|
|
|
dbgs() << ((FUs & (1 << j)) ? '1' : '0');
|
2010-01-04 22:26:07 +01:00
|
|
|
dbgs() << '\n';
|
2009-08-10 17:55:25 +02:00
|
|
|
}
|
|
|
|
}
|
2012-09-06 21:06:06 +02:00
|
|
|
#endif
|
2009-08-10 17:55:25 +02: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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
bool ScoreboardHazardRecognizer::atIssueLimit() const {
|
|
|
|
if (IssueWidth == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return IssueCount == IssueWidth;
|
|
|
|
}
|
|
|
|
|
2010-06-16 09:35:02 +02:00
|
|
|
ScheduleHazardRecognizer::HazardType
|
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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
ScoreboardHazardRecognizer::getHazardType(SUnit *SU, int Stalls) {
|
2010-09-10 03:29:16 +02:00
|
|
|
if (!ItinData || ItinData->isEmpty())
|
2009-09-22 18:47:52 +02:00
|
|
|
return NoHazard;
|
|
|
|
|
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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
// Note that stalls will be negative for bottom-up scheduling.
|
|
|
|
int cycle = Stalls;
|
2009-09-22 18:47:52 +02:00
|
|
|
|
|
|
|
// Use the itinerary for the underlying instruction to check for
|
|
|
|
// free FU's in the scoreboard at the appropriate future cycles.
|
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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
|
2011-06-28 21:10:37 +02:00
|
|
|
const MCInstrDesc *MCID = DAG->getInstrDesc(SU);
|
2014-04-14 02:51:57 +02:00
|
|
|
if (!MCID) {
|
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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
// Don't check hazards for non-machineinstr Nodes.
|
|
|
|
return NoHazard;
|
|
|
|
}
|
2011-06-28 21:10:37 +02:00
|
|
|
unsigned idx = MCID->getSchedClass();
|
2010-09-10 03:29:16 +02:00
|
|
|
for (const InstrStage *IS = ItinData->beginStage(idx),
|
|
|
|
*E = ItinData->endStage(idx); IS != E; ++IS) {
|
2009-09-22 18:47:52 +02:00
|
|
|
// We must find one of the stage's units free for every cycle the
|
|
|
|
// stage is occupied. FIXME it would be more accurate to find the
|
|
|
|
// same unit free in all the cycles.
|
|
|
|
for (unsigned int i = 0; i < IS->getCycles(); ++i) {
|
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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
int StageCycle = cycle + (int)i;
|
|
|
|
if (StageCycle < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (StageCycle >= (int)RequiredScoreboard.getDepth()) {
|
|
|
|
assert((StageCycle - Stalls) < (int)RequiredScoreboard.getDepth() &&
|
|
|
|
"Scoreboard depth exceeded!");
|
|
|
|
// This stage was stalled beyond pipeline depth, so cannot conflict.
|
|
|
|
break;
|
|
|
|
}
|
2010-04-07 20:19:24 +02:00
|
|
|
|
2012-06-22 22:27:13 +02:00
|
|
|
unsigned freeUnits = IS->getUnits();
|
2010-04-07 20:19:32 +02:00
|
|
|
switch (IS->getReservationKind()) {
|
|
|
|
case InstrStage::Required:
|
|
|
|
// Required FUs conflict with both reserved and required ones
|
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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
freeUnits &= ~ReservedScoreboard[StageCycle];
|
2010-04-07 20:19:32 +02:00
|
|
|
// FALLTHROUGH
|
|
|
|
case InstrStage::Reserved:
|
|
|
|
// Reserved FUs can conflict only with required ones.
|
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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
freeUnits &= ~RequiredScoreboard[StageCycle];
|
2010-04-07 20:19:32 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-09-22 18:47:52 +02:00
|
|
|
if (!freeUnits) {
|
2012-05-26 13:37:37 +02:00
|
|
|
DEBUG(dbgs() << "*** Hazard in cycle +" << StageCycle << ", ");
|
2010-01-04 22:26:07 +01:00
|
|
|
DEBUG(dbgs() << "SU(" << SU->NodeNum << "): ");
|
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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
DEBUG(DAG->dumpNode(SU));
|
2009-09-22 18:47:52 +02:00
|
|
|
return Hazard;
|
|
|
|
}
|
2009-08-10 17:55:25 +02:00
|
|
|
}
|
2010-04-07 20:19:24 +02:00
|
|
|
|
2009-09-22 18:47:52 +02:00
|
|
|
// Advance the cycle to the next stage.
|
|
|
|
cycle += IS->getNextCycles();
|
2009-08-10 17:55:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NoHazard;
|
|
|
|
}
|
2010-04-07 20:19:24 +02:00
|
|
|
|
2010-12-08 21:04:29 +01:00
|
|
|
void ScoreboardHazardRecognizer::EmitInstruction(SUnit *SU) {
|
2010-09-10 03:29:16 +02:00
|
|
|
if (!ItinData || ItinData->isEmpty())
|
2009-09-22 18:47:52 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Use the itinerary for the underlying instruction to reserve FU's
|
|
|
|
// in the scoreboard at the appropriate future cycles.
|
2011-06-28 21:10:37 +02:00
|
|
|
const MCInstrDesc *MCID = DAG->getInstrDesc(SU);
|
|
|
|
assert(MCID && "The scheduler must filter non-machineinstrs");
|
|
|
|
if (DAG->TII->isZeroCost(MCID->Opcode))
|
2011-01-21 06:51:33 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
++IssueCount;
|
|
|
|
|
|
|
|
unsigned cycle = 0;
|
|
|
|
|
2011-06-28 21:10:37 +02:00
|
|
|
unsigned idx = MCID->getSchedClass();
|
2010-09-10 03:29:16 +02:00
|
|
|
for (const InstrStage *IS = ItinData->beginStage(idx),
|
|
|
|
*E = ItinData->endStage(idx); IS != E; ++IS) {
|
2009-09-22 18:47:52 +02:00
|
|
|
// We must reserve one of the stage's units for every cycle the
|
|
|
|
// stage is occupied. FIXME it would be more accurate to reserve
|
|
|
|
// the same unit free in all the cycles.
|
|
|
|
for (unsigned int i = 0; i < IS->getCycles(); ++i) {
|
2010-04-07 20:19:32 +02:00
|
|
|
assert(((cycle + i) < RequiredScoreboard.getDepth()) &&
|
2009-09-22 18:47:52 +02:00
|
|
|
"Scoreboard depth exceeded!");
|
2010-04-07 20:19:24 +02:00
|
|
|
|
2012-06-22 22:27:13 +02:00
|
|
|
unsigned freeUnits = IS->getUnits();
|
2010-04-07 20:19:32 +02:00
|
|
|
switch (IS->getReservationKind()) {
|
|
|
|
case InstrStage::Required:
|
|
|
|
// Required FUs conflict with both reserved and required ones
|
|
|
|
freeUnits &= ~ReservedScoreboard[cycle + i];
|
|
|
|
// FALLTHROUGH
|
|
|
|
case InstrStage::Reserved:
|
|
|
|
// Reserved FUs can conflict only with required ones.
|
|
|
|
freeUnits &= ~RequiredScoreboard[cycle + i];
|
|
|
|
break;
|
|
|
|
}
|
2010-04-07 20:19:24 +02:00
|
|
|
|
2009-09-22 18:47:52 +02:00
|
|
|
// reduce to a single unit
|
2012-06-22 22:27:13 +02:00
|
|
|
unsigned freeUnit = 0;
|
2009-09-22 18:47:52 +02:00
|
|
|
do {
|
|
|
|
freeUnit = freeUnits;
|
|
|
|
freeUnits = freeUnit & (freeUnit - 1);
|
|
|
|
} while (freeUnits);
|
2010-04-07 20:19:24 +02:00
|
|
|
|
2010-04-07 20:19:32 +02:00
|
|
|
if (IS->getReservationKind() == InstrStage::Required)
|
|
|
|
RequiredScoreboard[cycle + i] |= freeUnit;
|
|
|
|
else
|
|
|
|
ReservedScoreboard[cycle + i] |= freeUnit;
|
2009-08-10 17:55:25 +02:00
|
|
|
}
|
2010-04-07 20:19:24 +02:00
|
|
|
|
2009-09-22 18:47:52 +02:00
|
|
|
// Advance the cycle to the next stage.
|
|
|
|
cycle += IS->getNextCycles();
|
2009-08-10 17:55:25 +02:00
|
|
|
}
|
2010-04-07 20:19:24 +02:00
|
|
|
|
2010-04-07 20:19:32 +02:00
|
|
|
DEBUG(ReservedScoreboard.dump());
|
|
|
|
DEBUG(RequiredScoreboard.dump());
|
2009-08-10 17:55:25 +02:00
|
|
|
}
|
2010-04-07 20:19:24 +02:00
|
|
|
|
2010-12-08 21:04:29 +01:00
|
|
|
void ScoreboardHazardRecognizer::AdvanceCycle() {
|
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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
IssueCount = 0;
|
2010-04-07 20:19:32 +02:00
|
|
|
ReservedScoreboard[0] = 0; ReservedScoreboard.advance();
|
|
|
|
RequiredScoreboard[0] = 0; RequiredScoreboard.advance();
|
2009-08-10 17:55:25 +02:00
|
|
|
}
|
2010-12-08 21:04:29 +01:00
|
|
|
|
|
|
|
void ScoreboardHazardRecognizer::RecedeCycle() {
|
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.
llvm-svn: 122541
2010-12-24 06:03:26 +01:00
|
|
|
IssueCount = 0;
|
2010-12-08 21:04:29 +01:00
|
|
|
ReservedScoreboard[ReservedScoreboard.getDepth()-1] = 0;
|
|
|
|
ReservedScoreboard.recede();
|
|
|
|
RequiredScoreboard[RequiredScoreboard.getDepth()-1] = 0;
|
|
|
|
RequiredScoreboard.recede();
|
|
|
|
}
|