2011-06-29 03:14:12 +02:00
|
|
|
//===-- llvm/MC/MCInstrItineraries.h - Scheduling ---------------*- C++ -*-===//
|
2005-10-27 20:18:05 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-10-27 20:18:05 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-08-17 18:02:57 +02:00
|
|
|
// This file describes the structures used for instruction
|
|
|
|
// itineraries, stages, and operand reads/writes. This is used by
|
|
|
|
// schedulers to determine instruction stages and latencies.
|
2005-10-27 20:18:05 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-06-29 03:14:12 +02:00
|
|
|
#ifndef LLVM_MC_MCINSTRITINERARIES_H
|
|
|
|
#define LLVM_MC_MCINSTRITINERARIES_H
|
2005-10-27 20:18:05 +02:00
|
|
|
|
2009-08-12 20:31:53 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
2005-10-27 20:18:05 +02:00
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-08-12 20:31:53 +02:00
|
|
|
/// Instruction stage - These values represent a non-pipelined step in
|
|
|
|
/// the execution of an instruction. Cycles represents the number of
|
|
|
|
/// discrete time slots needed to complete the stage. Units represent
|
|
|
|
/// the choice of functional units that can be used to complete the
|
|
|
|
/// stage. Eg. IntUnit1, IntUnit2. NextCycles indicates how many
|
|
|
|
/// cycles should elapse from the start of this stage to the start of
|
|
|
|
/// the next stage in the itinerary. A value of -1 indicates that the
|
|
|
|
/// next stage should start immediately after the current one.
|
|
|
|
/// For example:
|
|
|
|
///
|
|
|
|
/// { 1, x, -1 }
|
|
|
|
/// indicates that the stage occupies FU x for 1 cycle and that
|
|
|
|
/// the next stage starts immediately after this one.
|
|
|
|
///
|
|
|
|
/// { 2, x|y, 1 }
|
|
|
|
/// indicates that the stage occupies either FU x or FU y for 2
|
|
|
|
/// consecuative cycles and that the next stage starts one cycle
|
|
|
|
/// after this stage starts. That is, the stage requirements
|
|
|
|
/// overlap in time.
|
|
|
|
///
|
|
|
|
/// { 1, x, 0 }
|
|
|
|
/// indicates that the stage occupies FU x for 1 cycle and that
|
|
|
|
/// the next stage starts in this same cycle. This can be used to
|
|
|
|
/// indicate that the instruction requires multiple stages at the
|
|
|
|
/// same time.
|
2008-11-20 23:09:52 +01:00
|
|
|
///
|
2010-04-07 20:19:32 +02:00
|
|
|
/// FU reservation can be of two different kinds:
|
|
|
|
/// - FUs which instruction actually requires
|
|
|
|
/// - FUs which instruction just reserves. Reserved unit is not available for
|
|
|
|
/// execution of other instruction. However, several instructions can reserve
|
|
|
|
/// the same unit several times.
|
|
|
|
/// Such two types of units reservation is used to model instruction domain
|
|
|
|
/// change stalls, FUs using the same resource (e.g. same register file), etc.
|
|
|
|
|
2005-10-27 20:18:05 +02:00
|
|
|
struct InstrStage {
|
2010-04-07 20:19:32 +02:00
|
|
|
enum ReservationKinds {
|
|
|
|
Required = 0,
|
|
|
|
Reserved = 1
|
|
|
|
};
|
|
|
|
|
2009-08-12 20:31:53 +02:00
|
|
|
unsigned Cycles_; ///< Length of stage in machine cycles
|
|
|
|
unsigned Units_; ///< Choice of functional units
|
2010-04-07 20:19:32 +02:00
|
|
|
int NextCycles_; ///< Number of machine cycles to next stage
|
|
|
|
ReservationKinds Kind_; ///< Kind of the FU reservation
|
2009-08-12 20:31:53 +02:00
|
|
|
|
|
|
|
/// getCycles - returns the number of cycles the stage is occupied
|
|
|
|
unsigned getCycles() const {
|
|
|
|
return Cycles_;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getUnits - returns the choice of FUs
|
|
|
|
unsigned getUnits() const {
|
|
|
|
return Units_;
|
|
|
|
}
|
|
|
|
|
2010-04-07 20:19:32 +02:00
|
|
|
ReservationKinds getReservationKind() const {
|
|
|
|
return Kind_;
|
|
|
|
}
|
|
|
|
|
2009-08-12 20:31:53 +02:00
|
|
|
/// getNextCycles - returns the number of cycles from the start of
|
|
|
|
/// this stage to the start of the next stage in the itinerary
|
|
|
|
unsigned getNextCycles() const {
|
|
|
|
return (NextCycles_ >= 0) ? (unsigned)NextCycles_ : Cycles_;
|
|
|
|
}
|
2005-10-27 20:18:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-08-17 18:02:57 +02:00
|
|
|
/// Instruction itinerary - An itinerary represents the scheduling
|
|
|
|
/// information for an instruction. This includes a set of stages
|
|
|
|
/// occupies by the instruction, and the pipeline cycle in which
|
|
|
|
/// operands are read and written.
|
2008-11-20 23:09:52 +01:00
|
|
|
///
|
2005-10-27 20:18:05 +02:00
|
|
|
struct InstrItinerary {
|
2010-09-09 20:18:55 +02:00
|
|
|
unsigned NumMicroOps; ///< # of micro-ops, 0 means it's variable
|
2009-08-17 18:02:57 +02:00
|
|
|
unsigned FirstStage; ///< Index of first stage in itinerary
|
|
|
|
unsigned LastStage; ///< Index of last + 1 stage in itinerary
|
|
|
|
unsigned FirstOperandCycle; ///< Index of first operand rd/wr
|
|
|
|
unsigned LastOperandCycle; ///< Index of last + 1 operand rd/wr
|
2005-10-27 20:18:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-11-01 21:06:59 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-11-20 23:09:52 +01:00
|
|
|
/// Instruction itinerary Data - Itinerary data supplied by a subtarget to be
|
|
|
|
/// used by a target.
|
|
|
|
///
|
2010-06-12 17:46:56 +02:00
|
|
|
class InstrItineraryData {
|
|
|
|
public:
|
2008-11-20 23:09:52 +01:00
|
|
|
const InstrStage *Stages; ///< Array of stages selected
|
2009-08-17 18:02:57 +02:00
|
|
|
const unsigned *OperandCycles; ///< Array of operand cycles selected
|
2010-09-30 00:42:35 +02:00
|
|
|
const unsigned *Forwardings; ///< Array of pipeline forwarding pathes
|
2010-09-15 18:28:21 +02:00
|
|
|
const InstrItinerary *Itineraries; ///< Array of itineraries selected
|
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 IssueWidth; ///< Max issue per cycle. 0=Unknown.
|
2005-11-01 21:06:59 +01:00
|
|
|
|
2008-11-20 23:09:52 +01:00
|
|
|
/// Ctors.
|
|
|
|
///
|
2010-09-30 00:42:35 +02:00
|
|
|
InstrItineraryData() : Stages(0), OperandCycles(0), Forwardings(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
|
|
|
Itineraries(0), IssueWidth(0) {}
|
|
|
|
|
2009-08-17 18:02:57 +02:00
|
|
|
InstrItineraryData(const InstrStage *S, const unsigned *OS,
|
2010-09-30 00:42:35 +02:00
|
|
|
const unsigned *F, const InstrItinerary *I)
|
2011-06-01 19:19:08 +02:00
|
|
|
: Stages(S), OperandCycles(OS), Forwardings(F), Itineraries(I),
|
|
|
|
IssueWidth(0) {}
|
2010-12-24 05:28:06 +01:00
|
|
|
|
2008-11-20 23:09:52 +01:00
|
|
|
/// isEmpty - Returns true if there are no itineraries.
|
|
|
|
///
|
2010-09-15 18:28:21 +02:00
|
|
|
bool isEmpty() const { return Itineraries == 0; }
|
2009-08-19 18:08:58 +02:00
|
|
|
|
2009-09-24 22:22:50 +02:00
|
|
|
/// isEndMarker - Returns true if the index is for the end marker
|
|
|
|
/// itinerary.
|
|
|
|
///
|
|
|
|
bool isEndMarker(unsigned ItinClassIndx) const {
|
2010-09-15 18:28:21 +02:00
|
|
|
return ((Itineraries[ItinClassIndx].FirstStage == ~0U) &&
|
|
|
|
(Itineraries[ItinClassIndx].LastStage == ~0U));
|
2009-09-24 22:22:50 +02:00
|
|
|
}
|
|
|
|
|
2009-08-17 18:02:57 +02:00
|
|
|
/// beginStage - Return the first stage of the itinerary.
|
2010-12-24 05:28:06 +01:00
|
|
|
///
|
2009-08-17 18:02:57 +02:00
|
|
|
const InstrStage *beginStage(unsigned ItinClassIndx) const {
|
2010-09-15 18:28:21 +02:00
|
|
|
unsigned StageIdx = Itineraries[ItinClassIndx].FirstStage;
|
2005-11-01 21:06:59 +01:00
|
|
|
return Stages + StageIdx;
|
|
|
|
}
|
|
|
|
|
2009-08-17 18:02:57 +02:00
|
|
|
/// endStage - Return the last+1 stage of the itinerary.
|
2010-12-24 05:28:06 +01:00
|
|
|
///
|
2009-08-17 18:02:57 +02:00
|
|
|
const InstrStage *endStage(unsigned ItinClassIndx) const {
|
2010-09-15 18:28:21 +02:00
|
|
|
unsigned StageIdx = Itineraries[ItinClassIndx].LastStage;
|
2005-11-01 21:06:59 +01:00
|
|
|
return Stages + StageIdx;
|
|
|
|
}
|
2008-11-21 01:12:10 +01:00
|
|
|
|
2009-08-19 18:08:58 +02:00
|
|
|
/// getStageLatency - Return the total stage latency of the given
|
|
|
|
/// class. The latency is the maximum completion time for any stage
|
|
|
|
/// in the itinerary.
|
2008-11-21 01:12:10 +01:00
|
|
|
///
|
2009-08-19 18:08:58 +02:00
|
|
|
unsigned getStageLatency(unsigned ItinClassIndx) const {
|
2011-04-13 02:38:32 +02:00
|
|
|
// If the target doesn't provide itinerary information, use a simple
|
|
|
|
// non-zero default value for all instructions. Some target's provide a
|
|
|
|
// dummy (Generic) itinerary which should be handled as if it's itinerary is
|
|
|
|
// empty. We identify this by looking for a reference to stage zero (invalid
|
|
|
|
// stage). This is different from beginStage == endState != 0, which could
|
|
|
|
// be used for zero-latency pseudo ops.
|
|
|
|
if (isEmpty() || Itineraries[ItinClassIndx].FirstStage == 0)
|
2008-11-21 01:12:10 +01:00
|
|
|
return 1;
|
|
|
|
|
2009-08-19 18:08:58 +02:00
|
|
|
// Calculate the maximum completion time for any stage.
|
2009-08-12 20:31:53 +02:00
|
|
|
unsigned Latency = 0, StartCycle = 0;
|
2009-08-17 18:02:57 +02:00
|
|
|
for (const InstrStage *IS = beginStage(ItinClassIndx),
|
|
|
|
*E = endStage(ItinClassIndx); IS != E; ++IS) {
|
2009-08-12 20:31:53 +02:00
|
|
|
Latency = std::max(Latency, StartCycle + IS->getCycles());
|
|
|
|
StartCycle += IS->getNextCycles();
|
|
|
|
}
|
|
|
|
|
2008-11-21 01:12:10 +01:00
|
|
|
return Latency;
|
|
|
|
}
|
2009-08-19 18:08:58 +02:00
|
|
|
|
|
|
|
/// getOperandCycle - Return the cycle for the given class and
|
|
|
|
/// operand. Return -1 if no cycle is specified for the operand.
|
|
|
|
///
|
|
|
|
int getOperandCycle(unsigned ItinClassIndx, unsigned OperandIdx) const {
|
|
|
|
if (isEmpty())
|
|
|
|
return -1;
|
|
|
|
|
2010-09-15 18:28:21 +02:00
|
|
|
unsigned FirstIdx = Itineraries[ItinClassIndx].FirstOperandCycle;
|
|
|
|
unsigned LastIdx = Itineraries[ItinClassIndx].LastOperandCycle;
|
2009-08-19 18:08:58 +02:00
|
|
|
if ((FirstIdx + OperandIdx) >= LastIdx)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return (int)OperandCycles[FirstIdx + OperandIdx];
|
|
|
|
}
|
2010-09-10 03:29:16 +02:00
|
|
|
|
2010-09-30 00:42:35 +02:00
|
|
|
/// hasPipelineForwarding - Return true if there is a pipeline forwarding
|
|
|
|
/// between instructions of itinerary classes DefClass and UseClasses so that
|
|
|
|
/// value produced by an instruction of itinerary class DefClass, operand
|
|
|
|
/// index DefIdx can be bypassed when it's read by an instruction of
|
|
|
|
/// itinerary class UseClass, operand index UseIdx.
|
|
|
|
bool hasPipelineForwarding(unsigned DefClass, unsigned DefIdx,
|
|
|
|
unsigned UseClass, unsigned UseIdx) const {
|
|
|
|
unsigned FirstDefIdx = Itineraries[DefClass].FirstOperandCycle;
|
|
|
|
unsigned LastDefIdx = Itineraries[DefClass].LastOperandCycle;
|
|
|
|
if ((FirstDefIdx + DefIdx) >= LastDefIdx)
|
|
|
|
return false;
|
|
|
|
if (Forwardings[FirstDefIdx + DefIdx] == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned FirstUseIdx = Itineraries[UseClass].FirstOperandCycle;
|
|
|
|
unsigned LastUseIdx = Itineraries[UseClass].LastOperandCycle;
|
|
|
|
if ((FirstUseIdx + UseIdx) >= LastUseIdx)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return Forwardings[FirstDefIdx + DefIdx] ==
|
|
|
|
Forwardings[FirstUseIdx + UseIdx];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getOperandLatency - Compute and return the use operand latency of a given
|
|
|
|
/// itinerary class and operand index if the value is produced by an
|
|
|
|
/// instruction of the specified itinerary class and def operand index.
|
|
|
|
int getOperandLatency(unsigned DefClass, unsigned DefIdx,
|
|
|
|
unsigned UseClass, unsigned UseIdx) const {
|
|
|
|
if (isEmpty())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
int DefCycle = getOperandCycle(DefClass, DefIdx);
|
|
|
|
if (DefCycle == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
int UseCycle = getOperandCycle(UseClass, UseIdx);
|
|
|
|
if (UseCycle == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
UseCycle = DefCycle - UseCycle + 1;
|
|
|
|
if (UseCycle > 0 &&
|
|
|
|
hasPipelineForwarding(DefClass, DefIdx, UseClass, UseIdx))
|
|
|
|
// FIXME: This assumes one cycle benefit for every pipeline forwarding.
|
|
|
|
--UseCycle;
|
|
|
|
return UseCycle;
|
|
|
|
}
|
|
|
|
|
2010-09-10 03:29:16 +02:00
|
|
|
/// isMicroCoded - Return true if the instructions in the given class decode
|
|
|
|
/// to more than one micro-ops.
|
|
|
|
bool isMicroCoded(unsigned ItinClassIndx) const {
|
|
|
|
if (isEmpty())
|
|
|
|
return false;
|
2010-09-15 18:28:21 +02:00
|
|
|
return Itineraries[ItinClassIndx].NumMicroOps != 1;
|
2010-09-10 03:29:16 +02:00
|
|
|
}
|
2005-11-01 21:06:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-10-27 20:18:05 +02:00
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|