pass the TargetTriple down from each target ctor to the
[oota-llvm.git] / include / llvm / Target / TargetInstrItineraries.h
1 //===-- llvm/Target/TargetInstrItineraries.h - Scheduling -------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the structures used for instruction itineraries and
11 // states.  This is used by schedulers to determine instruction states and
12 // latencies.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_TARGET_TARGETINSTRITINERARIES_H
17 #define LLVM_TARGET_TARGETINSTRITINERARIES_H
18
19 namespace llvm {
20
21 //===----------------------------------------------------------------------===//
22 /// Instruction stage - These values represent a step in the execution of an
23 /// instruction.  The latency represents the number of discrete time slots
24 /// needed to complete the stage.  Units represent the choice of functional 
25 /// units that can be used to complete the stage.  Eg. IntUnit1, IntUnit2.
26 ///
27 struct InstrStage {
28   unsigned Cycles;  ///< Length of stage in machine cycles
29   unsigned Units;   ///< Choice of functional units
30 };
31
32
33 //===----------------------------------------------------------------------===//
34 /// Instruction itinerary - An itinerary represents a sequential series of steps
35 /// required to complete an instruction.  Itineraries are represented as
36 /// sequences of instruction stages.
37 ///
38 struct InstrItinerary {
39   unsigned First;    ///< Index of first stage in itinerary
40   unsigned Last;     ///< Index of last + 1 stage in itinerary
41 };
42
43
44
45 //===----------------------------------------------------------------------===//
46 /// Instruction itinerary Data - Itinerary data supplied by a subtarget to be
47 /// used by a target.
48 ///
49 struct InstrItineraryData {
50   const InstrStage     *Stages;         ///< Array of stages selected
51   const InstrItinerary *Itineratries;   ///< Array of itineraries selected
52
53   /// Ctors.
54   ///
55   InstrItineraryData() : Stages(0), Itineratries(0) {}
56   InstrItineraryData(const InstrStage *S, const InstrItinerary *I)
57     : Stages(S), Itineratries(I) {}
58   
59   /// isEmpty - Returns true if there are no itineraries.
60   ///
61   bool isEmpty() const { return Itineratries == 0; }
62   
63   /// begin - Return the first stage of the itinerary.
64   /// 
65   const InstrStage *begin(unsigned ItinClassIndx) const {
66     unsigned StageIdx = Itineratries[ItinClassIndx].First;
67     return Stages + StageIdx;
68   }
69
70   /// end - Return the last+1 stage of the itinerary.
71   /// 
72   const InstrStage *end(unsigned ItinClassIndx) const {
73     unsigned StageIdx = Itineratries[ItinClassIndx].Last;
74     return Stages + StageIdx;
75   }
76
77   /// getLatency - Return the scheduling latency of the given class.  A
78   /// simple latency value for an instruction is an over-simplification
79   /// for some architectures, but it's a reasonable first approximation.
80   ///
81   unsigned getLatency(unsigned ItinClassIndx) const {
82     // If the target doesn't provide latency information, use a simple
83     // non-zero default value for all instructions.
84     if (isEmpty())
85       return 1;
86
87     // Just sum the cycle count for each stage. The assumption is that all
88     // inputs are consumed at the start of the first stage and that all
89     // outputs are produced at the end of the last stage.
90     unsigned Latency = 0;
91     for (const InstrStage *IS = begin(ItinClassIndx), *E = end(ItinClassIndx);
92          IS != E; ++IS)
93       Latency += IS->Cycles;
94     return Latency;
95   }
96 };
97
98
99 } // End llvm namespace
100
101 #endif