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 itineraries and 00011 // states. This is used by schedulers to determine instruction states and 00012 // latencies. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_TARGET_TARGETINSTRITINERARIES_H 00017 #define LLVM_TARGET_TARGETINSTRITINERARIES_H 00018 00019 namespace llvm { 00020 00021 //===----------------------------------------------------------------------===// 00022 /// Instruction stage - These values represent a step in the execution of an 00023 /// instruction. The latency represents the number of discrete time slots used 00024 /// need to complete the stage. Units represent the choice of functional units 00025 /// that can be used to complete the stage. Eg. IntUnit1, IntUnit2. 00026 /// 00027 struct InstrStage { 00028 unsigned Cycles; ///< Length of stage in machine cycles 00029 unsigned Units; ///< Choice of functional units 00030 }; 00031 00032 00033 //===----------------------------------------------------------------------===// 00034 /// Instruction itinerary - An itinerary represents a sequential series of steps 00035 /// required to complete an instruction. Itineraries are represented as 00036 /// sequences of instruction stages. 00037 /// 00038 struct InstrItinerary { 00039 unsigned First; ///< Index of first stage in itinerary 00040 unsigned Last; ///< Index of last + 1 stage in itinerary 00041 }; 00042 00043 00044 00045 //===----------------------------------------------------------------------===// 00046 /// Instruction itinerary Data - Itinerary data supplied by a subtarget to be 00047 /// used by a target. 00048 /// 00049 struct InstrItineraryData { 00050 const InstrStage *Stages; ///< Array of stages selected 00051 const InstrItinerary *Itineratries; ///< Array of itineraries selected 00052 00053 /// Ctors. 00054 /// 00055 InstrItineraryData() : Stages(0), Itineratries(0) {} 00056 InstrItineraryData(const InstrStage *S, const InstrItinerary *I) 00057 : Stages(S), Itineratries(I) {} 00058 00059 /// isEmpty - Returns true if there are no itineraries. 00060 /// 00061 bool isEmpty() const { return Itineratries == 0; } 00062 00063 /// begin - Return the first stage of the itinerary. 00064 /// 00065 const InstrStage *begin(unsigned ItinClassIndx) const { 00066 unsigned StageIdx = Itineratries[ItinClassIndx].First; 00067 return Stages + StageIdx; 00068 } 00069 00070 /// end - Return the last+1 stage of the itinerary. 00071 /// 00072 const InstrStage *end(unsigned ItinClassIndx) const { 00073 unsigned StageIdx = Itineratries[ItinClassIndx].Last; 00074 return Stages + StageIdx; 00075 } 00076 00077 /// getLatency - Return the scheduling latency of the given class. A 00078 /// simple latency value for an instruction is an over-simplification 00079 /// for some architectures, but it's a reasonable first approximation. 00080 /// 00081 unsigned getLatency(unsigned ItinClassIndx) const { 00082 // If the target doesn't provide latency information, use a simple 00083 // non-zero default value for all instructions. 00084 if (isEmpty()) 00085 return 1; 00086 00087 // Just sum the cycle count for each stage. 00088 unsigned Latency = 0; 00089 for (const InstrStage *IS = begin(ItinClassIndx), *E = end(ItinClassIndx); 00090 IS != E; ++IS) 00091 Latency += IS->Cycles; 00092 return Latency; 00093 } 00094 }; 00095 00096 00097 } // End llvm namespace 00098 00099 #endif