1 //===-- llvm/Target/TargetInstrItineraries.h - Scheduling -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the structures used for instruction
11 // itineraries, stages, and operand reads/writes. This is used by
12 // schedulers to determine instruction stages and latencies.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TARGET_TARGETINSTRITINERARIES_H
17 #define LLVM_TARGET_TARGETINSTRITINERARIES_H
23 //===----------------------------------------------------------------------===//
24 /// Instruction stage - These values represent a non-pipelined step in
25 /// the execution of an instruction. Cycles represents the number of
26 /// discrete time slots needed to complete the stage. Units represent
27 /// the choice of functional units that can be used to complete the
28 /// stage. Eg. IntUnit1, IntUnit2. NextCycles indicates how many
29 /// cycles should elapse from the start of this stage to the start of
30 /// the next stage in the itinerary. A value of -1 indicates that the
31 /// next stage should start immediately after the current one.
35 /// indicates that the stage occupies FU x for 1 cycle and that
36 /// the next stage starts immediately after this one.
39 /// indicates that the stage occupies either FU x or FU y for 2
40 /// consecuative cycles and that the next stage starts one cycle
41 /// after this stage starts. That is, the stage requirements
45 /// indicates that the stage occupies FU x for 1 cycle and that
46 /// the next stage starts in this same cycle. This can be used to
47 /// indicate that the instruction requires multiple stages at the
51 unsigned Cycles_; ///< Length of stage in machine cycles
52 unsigned Units_; ///< Choice of functional units
53 int NextCycles_; ///< Number of machine cycles to next stage
55 /// getCycles - returns the number of cycles the stage is occupied
56 unsigned getCycles() const {
60 /// getUnits - returns the choice of FUs
61 unsigned getUnits() const {
65 /// getNextCycles - returns the number of cycles from the start of
66 /// this stage to the start of the next stage in the itinerary
67 unsigned getNextCycles() const {
68 return (NextCycles_ >= 0) ? (unsigned)NextCycles_ : Cycles_;
73 //===----------------------------------------------------------------------===//
74 /// Instruction itinerary - An itinerary represents the scheduling
75 /// information for an instruction. This includes a set of stages
76 /// occupies by the instruction, and the pipeline cycle in which
77 /// operands are read and written.
79 struct InstrItinerary {
80 unsigned FirstStage; ///< Index of first stage in itinerary
81 unsigned LastStage; ///< Index of last + 1 stage in itinerary
82 unsigned FirstOperandCycle; ///< Index of first operand rd/wr
83 unsigned LastOperandCycle; ///< Index of last + 1 operand rd/wr
87 //===----------------------------------------------------------------------===//
88 /// Instruction itinerary Data - Itinerary data supplied by a subtarget to be
91 struct InstrItineraryData {
92 const InstrStage *Stages; ///< Array of stages selected
93 const unsigned *OperandCycles; ///< Array of operand cycles selected
94 const InstrItinerary *Itineratries; ///< Array of itineraries selected
98 InstrItineraryData() : Stages(0), OperandCycles(0), Itineratries(0) {}
99 InstrItineraryData(const InstrStage *S, const unsigned *OS,
100 const InstrItinerary *I)
101 : Stages(S), OperandCycles(OS), Itineratries(I) {}
103 /// isEmpty - Returns true if there are no itineraries.
105 bool isEmpty() const { return Itineratries == 0; }
107 /// beginStage - Return the first stage of the itinerary.
109 const InstrStage *beginStage(unsigned ItinClassIndx) const {
110 unsigned StageIdx = Itineratries[ItinClassIndx].FirstStage;
111 return Stages + StageIdx;
114 /// endStage - Return the last+1 stage of the itinerary.
116 const InstrStage *endStage(unsigned ItinClassIndx) const {
117 unsigned StageIdx = Itineratries[ItinClassIndx].LastStage;
118 return Stages + StageIdx;
121 /// getLatency - Return the scheduling latency of the given class. A
122 /// simple latency value for an instruction is an over-simplification
123 /// for some architectures, but it's a reasonable first approximation.
125 unsigned getLatency(unsigned ItinClassIndx) const {
126 // If the target doesn't provide latency information, use a simple
127 // non-zero default value for all instructions.
131 // Caclulate the maximum completion time for any stage. The
132 // assumption is that all inputs are consumed at the start of the
133 // first stage and that all outputs are produced at the end of the
134 // latest completing last stage.
135 unsigned Latency = 0, StartCycle = 0;
136 for (const InstrStage *IS = beginStage(ItinClassIndx),
137 *E = endStage(ItinClassIndx); IS != E; ++IS) {
138 Latency = std::max(Latency, StartCycle + IS->getCycles());
139 StartCycle += IS->getNextCycles();
147 } // End llvm namespace