1 //===-- llvm/MC/MCInstrItineraries.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
11 // itineraries, stages, and operand reads/writes.  This is used by
12 // schedulers to determine instruction stages and latencies.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_MC_MCINSTRITINERARIES_H
17 #define LLVM_MC_MCINSTRITINERARIES_H
18 
19 #include "llvm/MC/MCSchedule.h"
20 #include <algorithm>
21 
22 namespace llvm {
23 
24 //===----------------------------------------------------------------------===//
25 /// These values represent a non-pipelined step in
26 /// the execution of an instruction.  Cycles represents the number of
27 /// discrete time slots needed to complete the stage.  Units represent
28 /// the choice of functional units that can be used to complete the
29 /// stage.  Eg. IntUnit1, IntUnit2. NextCycles indicates how many
30 /// cycles should elapse from the start of this stage to the start of
31 /// the next stage in the itinerary. A value of -1 indicates that the
32 /// next stage should start immediately after the current one.
33 /// For example:
34 ///
35 ///   { 1, x, -1 }
36 ///      indicates that the stage occupies FU x for 1 cycle and that
37 ///      the next stage starts immediately after this one.
38 ///
39 ///   { 2, x|y, 1 }
40 ///      indicates that the stage occupies either FU x or FU y for 2
41 ///      consecutive cycles and that the next stage starts one cycle
42 ///      after this stage starts. That is, the stage requirements
43 ///      overlap in time.
44 ///
45 ///   { 1, x, 0 }
46 ///      indicates that the stage occupies FU x for 1 cycle and that
47 ///      the next stage starts in this same cycle. This can be used to
48 ///      indicate that the instruction requires multiple stages at the
49 ///      same time.
50 ///
51 /// FU reservation can be of two different kinds:
52 ///  - FUs which instruction actually requires
53 ///  - FUs which instruction just reserves. Reserved unit is not available for
54 ///    execution of other instruction. However, several instructions can reserve
55 ///    the same unit several times.
56 /// Such two types of units reservation is used to model instruction domain
57 /// change stalls, FUs using the same resource (e.g. same register file), etc.
58 
59 struct InstrStage {
60   enum ReservationKinds {
61     Required = 0,
62     Reserved = 1
63   };
64 
65   unsigned Cycles_;  ///< Length of stage in machine cycles
66   unsigned Units_;   ///< Choice of functional units
67   int NextCycles_;   ///< Number of machine cycles to next stage
68   ReservationKinds Kind_; ///< Kind of the FU reservation
69 
70   /// \brief Returns the choice of FUs.
getUnitsInstrStage71   unsigned getUnits() const {
72     return Units_;
73   }
74 };
75 
76 
77 //===----------------------------------------------------------------------===//
78 /// An itinerary represents the scheduling information for an instruction.
79 /// This includes a set of stages occupied by the instruction and the pipeline
80 /// cycle in which operands are read and written.
81 ///
82 struct InstrItinerary {
83   int      NumMicroOps;        ///< # of micro-ops, -1 means it's variable
84   unsigned FirstStage;         ///< Index of first stage in itinerary
85   unsigned LastStage;          ///< Index of last + 1 stage in itinerary
86   unsigned FirstOperandCycle;  ///< Index of first operand rd/wr
87   unsigned LastOperandCycle;   ///< Index of last + 1 operand rd/wr
88 };
89 
90 
91 //===----------------------------------------------------------------------===//
92 /// Itinerary data supplied by a subtarget to be used by a target.
93 ///
94 class InstrItineraryData {
95 public:
96   MCSchedModel          SchedModel;     ///< Basic machine properties.
97   const InstrStage     *Stages;         ///< Array of stages selected
98   const InstrItinerary *Itineraries;    ///< Array of itineraries selected
99 };
100 
101 } // End llvm namespace
102 
103 #endif
104