Skip to content

Commit 2661b41

Browse files
committed
I'm introducing a new machine model to simultaneously allow simple
subtarget CPU descriptions and support new features of MachineScheduler. MachineModel has three categories of data: 1) Basic properties for coarse grained instruction cost model. 2) Scheduler Read/Write resources for simple per-opcode and operand cost model (TBD). 3) Instruction itineraties for detailed per-cycle reservation tables. These will all live side-by-side. Any subtarget can use any combination of them. Instruction itineraries will not change in the near term. In the long run, I expect them to only be relevant for in-order VLIW machines that have complex contraints and require a precise scheduling/bundling model. Once itineraries are only actively used by VLIW-ish targets, they could be replaced by something more appropriate for those targets. This tablegen backend rewrite sets things up for introducing MachineModel type #2: per opcode/operand cost model. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159891 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 06495cd commit 2661b41

27 files changed

+904
-502
lines changed

include/llvm/MC/MCInstrItineraries.h

Lines changed: 12 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#ifndef LLVM_MC_MCINSTRITINERARIES_H
1717
#define LLVM_MC_MCINSTRITINERARIES_H
1818

19+
#include "llvm/MC/MCSchedule.h"
1920
#include <algorithm>
2021

2122
namespace llvm {
@@ -103,96 +104,28 @@ struct InstrItinerary {
103104
};
104105

105106

106-
//===----------------------------------------------------------------------===//
107-
/// Instruction itinerary properties - These properties provide general
108-
/// information about the microarchitecture to the scheduler.
109-
///
110-
struct InstrItineraryProps {
111-
// IssueWidth is the maximum number of instructions that may be scheduled in
112-
// the same per-cycle group.
113-
unsigned IssueWidth;
114-
static const unsigned DefaultIssueWidth = 1;
115-
116-
// MinLatency is the minimum latency between a register write
117-
// followed by a data dependent read. This determines which
118-
// instructions may be scheduled in the same per-cycle group. This
119-
// is distinct from *expected* latency, which determines the likely
120-
// critical path but does not guarantee a pipeline
121-
// hazard. MinLatency can always be overridden by the number of
122-
// InstrStage cycles.
123-
//
124-
// (-1) Standard in-order processor.
125-
// Use InstrItinerary OperandCycles as MinLatency.
126-
// If no OperandCycles exist, then use the cycle of the last InstrStage.
127-
//
128-
// (0) Out-of-order processor, or in-order with bundled dependencies.
129-
// RAW dependencies may be dispatched in the same cycle.
130-
// Optional InstrItinerary OperandCycles provides expected latency.
131-
//
132-
// (>0) In-order processor with variable latencies.
133-
// Use the greater of this value or the cycle of the last InstrStage.
134-
// Optional InstrItinerary OperandCycles provides expected latency.
135-
// TODO: can't yet specify both min and expected latency per operand.
136-
int MinLatency;
137-
static const unsigned DefaultMinLatency = -1;
138-
139-
// LoadLatency is the expected latency of load instructions.
140-
//
141-
// If MinLatency >= 0, this may be overriden for individual load opcodes by
142-
// InstrItinerary OperandCycles.
143-
unsigned LoadLatency;
144-
static const unsigned DefaultLoadLatency = 4;
145-
146-
// HighLatency is the expected latency of "very high latency" operations.
147-
// See TargetInstrInfo::isHighLatencyDef().
148-
// By default, this is set to an arbitrarily high number of cycles
149-
// likely to have some impact on scheduling heuristics.
150-
// If MinLatency >= 0, this may be overriden by InstrItinData OperandCycles.
151-
unsigned HighLatency;
152-
static const unsigned DefaultHighLatency = 10;
153-
154-
// Default's must be specified as static const literals so that tablegenerated
155-
// target code can use it in static initializers. The defaults need to be
156-
// initialized in this default ctor because some clients directly instantiate
157-
// InstrItineraryData instead of using a generated itinerary.
158-
InstrItineraryProps(): IssueWidth(DefaultMinLatency),
159-
MinLatency(DefaultMinLatency),
160-
LoadLatency(DefaultLoadLatency),
161-
HighLatency(DefaultHighLatency) {}
162-
163-
InstrItineraryProps(unsigned iw, int ml, unsigned ll, unsigned hl):
164-
IssueWidth(iw), MinLatency(ml), LoadLatency(ll), HighLatency(hl) {}
165-
};
166-
167-
//===----------------------------------------------------------------------===//
168-
/// Encapsulate all subtarget specific information for scheduling for use with
169-
/// SubtargetInfoKV.
170-
struct InstrItinerarySubtargetValue {
171-
const InstrItineraryProps *Props;
172-
const InstrItinerary *Itineraries;
173-
};
174-
175107
//===----------------------------------------------------------------------===//
176108
/// Instruction itinerary Data - Itinerary data supplied by a subtarget to be
177109
/// used by a target.
178110
///
179111
class InstrItineraryData {
180112
public:
181-
InstrItineraryProps Props;
113+
const MCSchedModel *SchedModel; ///< Basic machine properties.
182114
const InstrStage *Stages; ///< Array of stages selected
183115
const unsigned *OperandCycles; ///< Array of operand cycles selected
184116
const unsigned *Forwardings; ///< Array of pipeline forwarding pathes
185117
const InstrItinerary *Itineraries; ///< Array of itineraries selected
186118

187119
/// Ctors.
188120
///
189-
InstrItineraryData() : Stages(0), OperandCycles(0), Forwardings(0),
190-
Itineraries(0) {}
121+
InstrItineraryData() : SchedModel(&MCSchedModel::DefaultSchedModel),
122+
Stages(0), OperandCycles(0),
123+
Forwardings(0), Itineraries(0) {}
191124

192-
InstrItineraryData(const InstrItineraryProps *P, const InstrStage *S,
193-
const unsigned *OS, const unsigned *F,
194-
const InstrItinerary *I)
195-
: Props(*P), Stages(S), OperandCycles(OS), Forwardings(F), Itineraries(I) {}
125+
InstrItineraryData(const MCSchedModel *SM, const InstrStage *S,
126+
const unsigned *OS, const unsigned *F)
127+
: SchedModel(SM), Stages(S), OperandCycles(OS), Forwardings(F),
128+
Itineraries(SchedModel->InstrItineraries) {}
196129

197130
/// isEmpty - Returns true if there are no itineraries.
198131
///
@@ -232,13 +165,9 @@ class InstrItineraryData {
232165
/// then it defaults to one cycle.
233166
unsigned getStageLatency(unsigned ItinClassIndx) const {
234167
// If the target doesn't provide itinerary information, use a simple
235-
// non-zero default value for all instructions. Some target's provide a
236-
// dummy (Generic) itinerary which should be handled as if it's itinerary is
237-
// empty. We identify this by looking for a reference to stage zero (invalid
238-
// stage). This is different from beginStage == endStage != 0, which could
239-
// be used for zero-latency pseudo ops.
240-
if (isEmpty() || Itineraries[ItinClassIndx].FirstStage == 0)
241-
return (Props.MinLatency < 0) ? 1 : Props.MinLatency;
168+
// non-zero default value for all instructions.
169+
if (isEmpty())
170+
return SchedModel->MinLatency < 0 ? 1 : SchedModel->MinLatency;
242171

243172
// Calculate the maximum completion time for any stage.
244173
unsigned Latency = 0, StartCycle = 0;

include/llvm/MC/MCSchedule.h

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
//===-- llvm/MC/MCSchedule.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 defines the classes used to describe a subtarget's machine model
11+
// for scheduling and other instruction cost heuristics.
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#ifndef LLVM_MC_MCSCHEDMODEL_H
16+
#define LLVM_MC_MCSCHEDMODEL_H
17+
18+
#include "llvm/Support/DataTypes.h"
19+
20+
namespace llvm {
21+
22+
struct InstrItinerary;
23+
24+
/// Machine model for scheduling, bundling, and heuristics.
25+
///
26+
/// The machine model directly provides basic information about the
27+
/// microarchitecture to the scheduler in the form of properties. It also
28+
/// optionally refers to scheduler resources tables and itinerary
29+
/// tables. Scheduler resources tables model the latency and cost for each
30+
/// instruction type. Itinerary tables are an independant mechanism that
31+
/// provides a detailed reservation table describing each cycle of instruction
32+
/// execution. Subtargets may define any or all of the above categories of data
33+
/// depending on the type of CPU and selected scheduler.
34+
class MCSchedModel {
35+
public:
36+
static MCSchedModel DefaultSchedModel; // For unknown processors.
37+
38+
// IssueWidth is the maximum number of instructions that may be scheduled in
39+
// the same per-cycle group.
40+
unsigned IssueWidth;
41+
static const unsigned DefaultIssueWidth = 1;
42+
43+
// MinLatency is the minimum latency between a register write
44+
// followed by a data dependent read. This determines which
45+
// instructions may be scheduled in the same per-cycle group. This
46+
// is distinct from *expected* latency, which determines the likely
47+
// critical path but does not guarantee a pipeline
48+
// hazard. MinLatency can always be overridden by the number of
49+
// InstrStage cycles.
50+
//
51+
// (-1) Standard in-order processor.
52+
// Use InstrItinerary OperandCycles as MinLatency.
53+
// If no OperandCycles exist, then use the cycle of the last InstrStage.
54+
//
55+
// (0) Out-of-order processor, or in-order with bundled dependencies.
56+
// RAW dependencies may be dispatched in the same cycle.
57+
// Optional InstrItinerary OperandCycles provides expected latency.
58+
//
59+
// (>0) In-order processor with variable latencies.
60+
// Use the greater of this value or the cycle of the last InstrStage.
61+
// Optional InstrItinerary OperandCycles provides expected latency.
62+
// TODO: can't yet specify both min and expected latency per operand.
63+
int MinLatency;
64+
static const unsigned DefaultMinLatency = -1;
65+
66+
// LoadLatency is the expected latency of load instructions.
67+
//
68+
// If MinLatency >= 0, this may be overriden for individual load opcodes by
69+
// InstrItinerary OperandCycles.
70+
unsigned LoadLatency;
71+
static const unsigned DefaultLoadLatency = 4;
72+
73+
// HighLatency is the expected latency of "very high latency" operations.
74+
// See TargetInstrInfo::isHighLatencyDef().
75+
// By default, this is set to an arbitrarily high number of cycles
76+
// likely to have some impact on scheduling heuristics.
77+
// If MinLatency >= 0, this may be overriden by InstrItinData OperandCycles.
78+
unsigned HighLatency;
79+
static const unsigned DefaultHighLatency = 10;
80+
81+
private:
82+
// TODO: Add a reference to proc resource types and sched resource tables.
83+
84+
// Instruction itinerary tables used by InstrItineraryData.
85+
friend class InstrItineraryData;
86+
const InstrItinerary *InstrItineraries;
87+
88+
public:
89+
// Default's must be specified as static const literals so that tablegenerated
90+
// target code can use it in static initializers. The defaults need to be
91+
// initialized in this default ctor because some clients directly instantiate
92+
// MCSchedModel instead of using a generated itinerary.
93+
MCSchedModel(): IssueWidth(DefaultMinLatency),
94+
MinLatency(DefaultMinLatency),
95+
LoadLatency(DefaultLoadLatency),
96+
HighLatency(DefaultHighLatency),
97+
InstrItineraries(0) {}
98+
99+
// Table-gen driven ctor.
100+
MCSchedModel(unsigned iw, int ml, unsigned ll, unsigned hl,
101+
const InstrItinerary *ii):
102+
IssueWidth(iw), MinLatency(ml), LoadLatency(ll), HighLatency(hl),
103+
InstrItineraries(ii){}
104+
};
105+
106+
} // End llvm namespace
107+
108+
#endif

include/llvm/MC/MCSubtargetInfo.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class MCSubtargetInfo {
3030
std::string TargetTriple; // Target triple
3131
const SubtargetFeatureKV *ProcFeatures; // Processor feature list
3232
const SubtargetFeatureKV *ProcDesc; // Processor descriptions
33-
const SubtargetInfoKV *ProcItins; // Scheduling itineraries
34-
const InstrStage *Stages; // Instruction stages
35-
const unsigned *OperandCycles; // Operand cycles
33+
const SubtargetInfoKV *ProcSchedModel; // Scheduler machine model
34+
const InstrStage *Stages; // Instruction itinerary stages
35+
const unsigned *OperandCycles; // Itinerary operand cycles
3636
const unsigned *ForwardingPaths; // Forwarding paths
3737
unsigned NumFeatures; // Number of processor features
3838
unsigned NumProcs; // Number of processors
@@ -42,7 +42,8 @@ class MCSubtargetInfo {
4242
void InitMCSubtargetInfo(StringRef TT, StringRef CPU, StringRef FS,
4343
const SubtargetFeatureKV *PF,
4444
const SubtargetFeatureKV *PD,
45-
const SubtargetInfoKV *PI, const InstrStage *IS,
45+
const SubtargetInfoKV *ProcSched,
46+
const InstrStage *IS,
4647
const unsigned *OC, const unsigned *FP,
4748
unsigned NF, unsigned NP);
4849

@@ -69,6 +70,10 @@ class MCSubtargetInfo {
6970
/// bits. This version will also change all implied bits.
7071
uint64_t ToggleFeature(StringRef FS);
7172

73+
/// getSchedModelForCPU - Get the machine model of a CPU.
74+
///
75+
MCSchedModel *getSchedModelForCPU(StringRef CPU) const;
76+
7277
/// getInstrItineraryForCPU - Get scheduling itinerary of a CPU.
7378
///
7479
InstrItineraryData getInstrItineraryForCPU(StringRef CPU) const;

include/llvm/Target/Target.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,10 @@ class Processor<string n, ProcessorItineraries pi, list<SubtargetFeature> f> {
933933
//
934934
string Name = n;
935935

936+
// SchedModel - The machine model for scheduling and instruction cost.
937+
//
938+
SchedMachineModel SchedModel = NoSchedModel;
939+
936940
// ProcItin - The scheduling information for the target processor.
937941
//
938942
ProcessorItineraries ProcItin = pi;
@@ -941,6 +945,14 @@ class Processor<string n, ProcessorItineraries pi, list<SubtargetFeature> f> {
941945
list<SubtargetFeature> Features = f;
942946
}
943947

948+
// ProcessorModel allows subtargets to specify the more general
949+
// SchedMachineModel instead if a ProcessorItinerary. Subtargets will
950+
// gradually move to this newer form.
951+
class ProcessorModel<string n, SchedMachineModel m, list<SubtargetFeature> f>
952+
: Processor<n, NoItineraries, f> {
953+
let SchedModel = m;
954+
}
955+
944956
//===----------------------------------------------------------------------===//
945957
// Pull in the common support for calling conventions.
946958
//

0 commit comments

Comments
 (0)