LLVM API Documentation
00001 //===-- llvm/Target/TargetInstrItineraries.h - Scheduling -------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file describes the structures used for instruction 00011 // itineraries, stages, and operand reads/writes. This is used by 00012 // schedulers to determine instruction stages and latencies. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_TARGET_TARGETINSTRITINERARIES_H 00017 #define LLVM_TARGET_TARGETINSTRITINERARIES_H 00018 00019 #include <algorithm> 00020 00021 namespace llvm { 00022 00023 //===----------------------------------------------------------------------===// 00024 /// Instruction stage - These values represent a non-pipelined step in 00025 /// the execution of an instruction. Cycles represents the number of 00026 /// discrete time slots needed to complete the stage. Units represent 00027 /// the choice of functional units that can be used to complete the 00028 /// stage. Eg. IntUnit1, IntUnit2. NextCycles indicates how many 00029 /// cycles should elapse from the start of this stage to the start of 00030 /// the next stage in the itinerary. A value of -1 indicates that the 00031 /// next stage should start immediately after the current one. 00032 /// For example: 00033 /// 00034 /// { 1, x, -1 } 00035 /// indicates that the stage occupies FU x for 1 cycle and that 00036 /// the next stage starts immediately after this one. 00037 /// 00038 /// { 2, x|y, 1 } 00039 /// indicates that the stage occupies either FU x or FU y for 2 00040 /// consecuative cycles and that the next stage starts one cycle 00041 /// after this stage starts. That is, the stage requirements 00042 /// overlap in time. 00043 /// 00044 /// { 1, x, 0 } 00045 /// indicates that the stage occupies FU x for 1 cycle and that 00046 /// the next stage starts in this same cycle. This can be used to 00047 /// indicate that the instruction requires multiple stages at the 00048 /// same time. 00049 /// 00050 struct InstrStage { 00051 unsigned Cycles_; ///< Length of stage in machine cycles 00052 unsigned Units_; ///< Choice of functional units 00053 int NextCycles_; ///< Number of machine cycles to next stage 00054 00055 /// getCycles - returns the number of cycles the stage is occupied 00056 unsigned getCycles() const { 00057 return Cycles_; 00058 } 00059 00060 /// getUnits - returns the choice of FUs 00061 unsigned getUnits() const { 00062 return Units_; 00063 } 00064 00065 /// getNextCycles - returns the number of cycles from the start of 00066 /// this stage to the start of the next stage in the itinerary 00067 unsigned getNextCycles() const { 00068 return (NextCycles_ >= 0) ? (unsigned)NextCycles_ : Cycles_; 00069 } 00070 }; 00071 00072 00073 //===----------------------------------------------------------------------===// 00074 /// Instruction itinerary - An itinerary represents the scheduling 00075 /// information for an instruction. This includes a set of stages 00076 /// occupies by the instruction, and the pipeline cycle in which 00077 /// operands are read and written. 00078 /// 00079 struct InstrItinerary { 00080 unsigned FirstStage; ///< Index of first stage in itinerary 00081 unsigned LastStage; ///< Index of last + 1 stage in itinerary 00082 unsigned FirstOperandCycle; ///< Index of first operand rd/wr 00083 unsigned LastOperandCycle; ///< Index of last + 1 operand rd/wr 00084 }; 00085 00086 00087 //===----------------------------------------------------------------------===// 00088 /// Instruction itinerary Data - Itinerary data supplied by a subtarget to be 00089 /// used by a target. 00090 /// 00091 struct InstrItineraryData { 00092 const InstrStage *Stages; ///< Array of stages selected 00093 const unsigned *OperandCycles; ///< Array of operand cycles selected 00094 const InstrItinerary *Itineratries; ///< Array of itineraries selected 00095 00096 /// Ctors. 00097 /// 00098 InstrItineraryData() : Stages(0), OperandCycles(0), Itineratries(0) {} 00099 InstrItineraryData(const InstrStage *S, const unsigned *OS, 00100 const InstrItinerary *I) 00101 : Stages(S), OperandCycles(OS), Itineratries(I) {} 00102 00103 /// isEmpty - Returns true if there are no itineraries. 00104 /// 00105 bool isEmpty() const { return Itineratries == 0; } 00106 00107 /// beginStage - Return the first stage of the itinerary. 00108 /// 00109 const InstrStage *beginStage(unsigned ItinClassIndx) const { 00110 unsigned StageIdx = Itineratries[ItinClassIndx].FirstStage; 00111 return Stages + StageIdx; 00112 } 00113 00114 /// endStage - Return the last+1 stage of the itinerary. 00115 /// 00116 const InstrStage *endStage(unsigned ItinClassIndx) const { 00117 unsigned StageIdx = Itineratries[ItinClassIndx].LastStage; 00118 return Stages + StageIdx; 00119 } 00120 00121 /// getStageLatency - Return the total stage latency of the given 00122 /// class. The latency is the maximum completion time for any stage 00123 /// in the itinerary. 00124 /// 00125 unsigned getStageLatency(unsigned ItinClassIndx) const { 00126 // If the target doesn't provide itinerary information, use a 00127 // simple non-zero default value for all instructions. 00128 if (isEmpty()) 00129 return 1; 00130 00131 // Calculate the maximum completion time for any stage. 00132 unsigned Latency = 0, StartCycle = 0; 00133 for (const InstrStage *IS = beginStage(ItinClassIndx), 00134 *E = endStage(ItinClassIndx); IS != E; ++IS) { 00135 Latency = std::max(Latency, StartCycle + IS->getCycles()); 00136 StartCycle += IS->getNextCycles(); 00137 } 00138 00139 return Latency; 00140 } 00141 00142 /// getOperandCycle - Return the cycle for the given class and 00143 /// operand. Return -1 if no cycle is specified for the operand. 00144 /// 00145 int getOperandCycle(unsigned ItinClassIndx, unsigned OperandIdx) const { 00146 if (isEmpty()) 00147 return -1; 00148 00149 unsigned FirstIdx = Itineratries[ItinClassIndx].FirstOperandCycle; 00150 unsigned LastIdx = Itineratries[ItinClassIndx].LastOperandCycle; 00151 if ((FirstIdx + OperandIdx) >= LastIdx) 00152 return -1; 00153 00154 return (int)OperandCycles[FirstIdx + OperandIdx]; 00155 } 00156 }; 00157 00158 00159 } // End llvm namespace 00160 00161 #endif