1//===-- PPC.td - Describe the PowerPC Target Machine -------*- tablegen -*-===//
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 is the top level entry point for the PowerPC target.
11//
12//===----------------------------------------------------------------------===//
13
14// Get the target-independent interfaces which we are implementing.
15//
16include "llvm/Target/Target.td"
17
18//===----------------------------------------------------------------------===//
19// PowerPC Subtarget features.
20//
21
22//===----------------------------------------------------------------------===//
23// CPU Directives                                                             //
24//===----------------------------------------------------------------------===//
25
26def Directive440 : SubtargetFeature<"", "DarwinDirective", "PPC::DIR_440", "">;
27def Directive601 : SubtargetFeature<"", "DarwinDirective", "PPC::DIR_601", "">;
28def Directive602 : SubtargetFeature<"", "DarwinDirective", "PPC::DIR_602", "">;
29def Directive603 : SubtargetFeature<"", "DarwinDirective", "PPC::DIR_603", "">;
30def Directive604 : SubtargetFeature<"", "DarwinDirective", "PPC::DIR_603", "">;
31def Directive620 : SubtargetFeature<"", "DarwinDirective", "PPC::DIR_603", "">;
32def Directive7400: SubtargetFeature<"", "DarwinDirective", "PPC::DIR_7400", "">;
33def Directive750 : SubtargetFeature<"", "DarwinDirective", "PPC::DIR_750", "">;
34def Directive970 : SubtargetFeature<"", "DarwinDirective", "PPC::DIR_970", "">;
35def Directive32  : SubtargetFeature<"", "DarwinDirective", "PPC::DIR_32", "">;
36def Directive64  : SubtargetFeature<"", "DarwinDirective", "PPC::DIR_64", "">;
37def DirectiveA2  : SubtargetFeature<"", "DarwinDirective", "PPC::DIR_A2", "">;
38def DirectiveE500mc : SubtargetFeature<"", "DarwinDirective",
39                                       "PPC::DIR_E500mc", "">;
40def DirectiveE5500  : SubtargetFeature<"", "DarwinDirective",
41                                       "PPC::DIR_E5500", "">;
42def DirectivePwr3: SubtargetFeature<"", "DarwinDirective", "PPC::DIR_PWR3", "">;
43def DirectivePwr4: SubtargetFeature<"", "DarwinDirective", "PPC::DIR_PWR4", "">;
44def DirectivePwr5: SubtargetFeature<"", "DarwinDirective", "PPC::DIR_PWR5", "">;
45def DirectivePwr5x: SubtargetFeature<"", "DarwinDirective", "PPC::DIR_PWR5X", "">;
46def DirectivePwr6: SubtargetFeature<"", "DarwinDirective", "PPC::DIR_PWR6", "">;
47def DirectivePwr6x: SubtargetFeature<"", "DarwinDirective", "PPC::DIR_PWR6X", "">;
48def DirectivePwr7: SubtargetFeature<"", "DarwinDirective", "PPC::DIR_PWR7", "">;
49def DirectivePwr8: SubtargetFeature<"", "DarwinDirective", "PPC::DIR_PWR8", "">;
50
51def Feature64Bit     : SubtargetFeature<"64bit","Has64BitSupport", "true",
52                                        "Enable 64-bit instructions">;
53def Feature64BitRegs : SubtargetFeature<"64bitregs","Use64BitRegs", "true",
54                              "Enable 64-bit registers usage for ppc32 [beta]">;
55def FeatureCRBits    : SubtargetFeature<"crbits", "UseCRBits", "true",
56                              "Use condition-register bits individually">;
57def FeatureAltivec   : SubtargetFeature<"altivec","HasAltivec", "true",
58                                        "Enable Altivec instructions">;
59def FeatureSPE       : SubtargetFeature<"spe","HasSPE", "true",
60                                        "Enable SPE instructions">;
61def FeatureMFOCRF    : SubtargetFeature<"mfocrf","HasMFOCRF", "true",
62                                        "Enable the MFOCRF instruction">;
63def FeatureFSqrt     : SubtargetFeature<"fsqrt","HasFSQRT", "true",
64                                        "Enable the fsqrt instruction">;
65def FeatureFCPSGN    : SubtargetFeature<"fcpsgn", "HasFCPSGN", "true",
66                                        "Enable the fcpsgn instruction">;
67def FeatureFRE       : SubtargetFeature<"fre", "HasFRE", "true",
68                                        "Enable the fre instruction">;
69def FeatureFRES      : SubtargetFeature<"fres", "HasFRES", "true",
70                                        "Enable the fres instruction">;
71def FeatureFRSQRTE   : SubtargetFeature<"frsqrte", "HasFRSQRTE", "true",
72                                        "Enable the frsqrte instruction">;
73def FeatureFRSQRTES  : SubtargetFeature<"frsqrtes", "HasFRSQRTES", "true",
74                                        "Enable the frsqrtes instruction">;
75def FeatureRecipPrec : SubtargetFeature<"recipprec", "HasRecipPrec", "true",
76                              "Assume higher precision reciprocal estimates">;
77def FeatureSTFIWX    : SubtargetFeature<"stfiwx","HasSTFIWX", "true",
78                                        "Enable the stfiwx instruction">;
79def FeatureLFIWAX    : SubtargetFeature<"lfiwax","HasLFIWAX", "true",
80                                        "Enable the lfiwax instruction">;
81def FeatureFPRND     : SubtargetFeature<"fprnd", "HasFPRND", "true",
82                                        "Enable the fri[mnpz] instructions">;
83def FeatureFPCVT     : SubtargetFeature<"fpcvt", "HasFPCVT", "true",
84  "Enable fc[ft]* (unsigned and single-precision) and lfiwzx instructions">;
85def FeatureISEL      : SubtargetFeature<"isel","HasISEL", "true",
86                                        "Enable the isel instruction">;
87def FeaturePOPCNTD   : SubtargetFeature<"popcntd","HasPOPCNTD", "true",
88                                        "Enable the popcnt[dw] instructions">;
89def FeatureBPERMD    : SubtargetFeature<"bpermd", "HasBPERMD", "true",
90                                        "Enable the bpermd instruction">;
91def FeatureExtDiv    : SubtargetFeature<"extdiv", "HasExtDiv", "true",
92                                        "Enable extended divide instructions">;
93def FeatureLDBRX     : SubtargetFeature<"ldbrx","HasLDBRX", "true",
94                                        "Enable the ldbrx instruction">;
95def FeatureCMPB      : SubtargetFeature<"cmpb", "HasCMPB", "true",
96                                        "Enable the cmpb instruction">;
97def FeatureICBT      : SubtargetFeature<"icbt","HasICBT", "true",
98                                        "Enable icbt instruction">;
99def FeatureBookE     : SubtargetFeature<"booke", "IsBookE", "true",
100                                        "Enable Book E instructions",
101                                        [FeatureICBT]>;
102def FeatureMSYNC     : SubtargetFeature<"msync", "HasOnlyMSYNC", "true",
103                              "Has only the msync instruction instead of sync",
104                              [FeatureBookE]>;
105def FeatureE500      : SubtargetFeature<"e500", "IsE500", "true",
106                                        "Enable E500/E500mc instructions">;
107def FeaturePPC4xx    : SubtargetFeature<"ppc4xx", "IsPPC4xx", "true",
108                                        "Enable PPC 4xx instructions">;
109def FeaturePPC6xx    : SubtargetFeature<"ppc6xx", "IsPPC6xx", "true",
110                                        "Enable PPC 6xx instructions">;
111def FeatureQPX       : SubtargetFeature<"qpx","HasQPX", "true",
112                                        "Enable QPX instructions">;
113def FeatureVSX       : SubtargetFeature<"vsx","HasVSX", "true",
114                                        "Enable VSX instructions",
115                                        [FeatureAltivec]>;
116def FeatureP8Altivec : SubtargetFeature<"power8-altivec", "HasP8Altivec", "true",
117                                        "Enable POWER8 Altivec instructions",
118                                        [FeatureAltivec]>;
119def FeatureP8Crypto : SubtargetFeature<"crypto", "HasP8Crypto", "true",
120                                       "Enable POWER8 Crypto instructions",
121                                       [FeatureP8Altivec]>;
122def FeatureP8Vector  : SubtargetFeature<"power8-vector", "HasP8Vector", "true",
123                                        "Enable POWER8 vector instructions",
124                                        [FeatureVSX, FeatureP8Altivec]>;
125def FeatureDirectMove :
126  SubtargetFeature<"direct-move", "HasDirectMove", "true",
127                   "Enable Power8 direct move instructions",
128                   [FeatureVSX]>;
129def FeaturePartwordAtomic : SubtargetFeature<"partword-atomics",
130                                             "HasPartwordAtomics", "true",
131                                             "Enable l[bh]arx and st[bh]cx.">;
132def FeatureInvariantFunctionDescriptors :
133  SubtargetFeature<"invariant-function-descriptors",
134                   "HasInvariantFunctionDescriptors", "true",
135                   "Assume function descriptors are invariant">;
136def FeatureHTM : SubtargetFeature<"htm", "HasHTM", "true",
137                                  "Enable Hardware Transactional Memory instructions">;
138def FeatureMFTB   : SubtargetFeature<"", "FeatureMFTB", "true",
139                                        "Implement mftb using the mfspr instruction">;
140def FeatureFusion : SubtargetFeature<"fusion", "HasFusion", "true",
141                                     "Target supports add/load integer fusion.">;
142
143def DeprecatedDST    : SubtargetFeature<"", "DeprecatedDST", "true",
144  "Treat vector data stream cache control instructions as deprecated">;
145
146/*  Since new processors generally contain a superset of features of those that
147    came before them, the idea is to make implementations of new processors
148    less error prone and easier to read.
149    Namely:
150        list<SubtargetFeature> Power8FeatureList = ...
151        list<SubtargetFeature> FutureProcessorSpecificFeatureList =
152            [ features that Power8 does not support ]
153        list<SubtargetFeature> FutureProcessorFeatureList =
154            !listconcat(Power8FeatureList, FutureProcessorSpecificFeatureList)
155
156    Makes it explicit and obvious what is new in FutureProcesor vs. Power8 as
157    well as providing a single point of definition if the feature set will be
158    used elsewhere.
159*/
160def ProcessorFeatures {
161  list<SubtargetFeature> Power7FeatureList =
162      [DirectivePwr7, FeatureAltivec, FeatureVSX,
163       FeatureMFOCRF, FeatureFCPSGN, FeatureFSqrt, FeatureFRE,
164       FeatureFRES, FeatureFRSQRTE, FeatureFRSQRTES,
165       FeatureRecipPrec, FeatureSTFIWX, FeatureLFIWAX,
166       FeatureFPRND, FeatureFPCVT, FeatureISEL,
167       FeaturePOPCNTD, FeatureCMPB, FeatureLDBRX,
168       Feature64Bit /*, Feature64BitRegs */,
169       FeatureBPERMD, FeatureExtDiv,
170       FeatureMFTB, DeprecatedDST];
171  list<SubtargetFeature> Power8SpecificFeatures =
172      [DirectivePwr8, FeatureP8Altivec, FeatureP8Vector, FeatureP8Crypto,
173       FeatureHTM, FeatureDirectMove, FeatureICBT, FeaturePartwordAtomic,
174       FeatureFusion];
175  list<SubtargetFeature> Power8FeatureList =
176      !listconcat(Power7FeatureList, Power8SpecificFeatures);
177}
178
179// Note: Future features to add when support is extended to more
180// recent ISA levels:
181//
182// DFP          p6, p6x, p7        decimal floating-point instructions
183// POPCNTB      p5 through p7      popcntb and related instructions
184
185//===----------------------------------------------------------------------===//
186// Classes used for relation maps.
187//===----------------------------------------------------------------------===//
188// RecFormRel - Filter class used to relate non-record-form instructions with
189// their record-form variants.
190class RecFormRel;
191
192// AltVSXFMARel - Filter class used to relate the primary addend-killing VSX
193// FMA instruction forms with their corresponding factor-killing forms.
194class AltVSXFMARel {
195  bit IsVSXFMAAlt = 0;
196}
197
198//===----------------------------------------------------------------------===//
199// Relation Map Definitions.
200//===----------------------------------------------------------------------===//
201
202def getRecordFormOpcode : InstrMapping {
203  let FilterClass = "RecFormRel";
204  // Instructions with the same BaseName and Interpretation64Bit values
205  // form a row.
206  let RowFields = ["BaseName", "Interpretation64Bit"];
207  // Instructions with the same RC value form a column.
208  let ColFields = ["RC"];
209  // The key column are the non-record-form instructions.
210  let KeyCol = ["0"];
211  // Value columns RC=1
212  let ValueCols = [["1"]];
213}
214
215def getNonRecordFormOpcode : InstrMapping {
216  let FilterClass = "RecFormRel";
217  // Instructions with the same BaseName and Interpretation64Bit values
218  // form a row.
219  let RowFields = ["BaseName", "Interpretation64Bit"];
220  // Instructions with the same RC value form a column.
221  let ColFields = ["RC"];
222  // The key column are the record-form instructions.
223  let KeyCol = ["1"];
224  // Value columns are RC=0
225  let ValueCols = [["0"]];
226}
227
228def getAltVSXFMAOpcode : InstrMapping {
229  let FilterClass = "AltVSXFMARel";
230  // Instructions with the same BaseName and Interpretation64Bit values
231  // form a row.
232  let RowFields = ["BaseName"];
233  // Instructions with the same RC value form a column.
234  let ColFields = ["IsVSXFMAAlt"];
235  // The key column are the (default) addend-killing instructions.
236  let KeyCol = ["0"];
237  // Value columns IsVSXFMAAlt=1
238  let ValueCols = [["1"]];
239}
240
241//===----------------------------------------------------------------------===//
242// Register File Description
243//===----------------------------------------------------------------------===//
244
245include "PPCRegisterInfo.td"
246include "PPCSchedule.td"
247include "PPCInstrInfo.td"
248
249//===----------------------------------------------------------------------===//
250// PowerPC processors supported.
251//
252
253def : Processor<"generic", G3Itineraries, [Directive32, FeatureMFTB]>;
254def : ProcessorModel<"440", PPC440Model, [Directive440, FeatureISEL,
255                                          FeatureFRES, FeatureFRSQRTE,
256                                          FeatureICBT, FeatureBookE,
257                                          FeatureMSYNC, FeatureMFTB]>;
258def : ProcessorModel<"450", PPC440Model, [Directive440, FeatureISEL,
259                                          FeatureFRES, FeatureFRSQRTE,
260                                          FeatureICBT, FeatureBookE,
261                                          FeatureMSYNC, FeatureMFTB]>;
262def : Processor<"601", G3Itineraries, [Directive601]>;
263def : Processor<"602", G3Itineraries, [Directive602,
264                                       FeatureMFTB]>;
265def : Processor<"603", G3Itineraries, [Directive603,
266                                       FeatureFRES, FeatureFRSQRTE,
267                                       FeatureMFTB]>;
268def : Processor<"603e", G3Itineraries, [Directive603,
269                                        FeatureFRES, FeatureFRSQRTE,
270                                        FeatureMFTB]>;
271def : Processor<"603ev", G3Itineraries, [Directive603,
272                                         FeatureFRES, FeatureFRSQRTE,
273                                         FeatureMFTB]>;
274def : Processor<"604", G3Itineraries, [Directive604,
275                                       FeatureFRES, FeatureFRSQRTE,
276                                       FeatureMFTB]>;
277def : Processor<"604e", G3Itineraries, [Directive604,
278                                        FeatureFRES, FeatureFRSQRTE,
279                                        FeatureMFTB]>;
280def : Processor<"620", G3Itineraries, [Directive620,
281                                       FeatureFRES, FeatureFRSQRTE,
282                                       FeatureMFTB]>;
283def : Processor<"750", G4Itineraries, [Directive750,
284                                       FeatureFRES, FeatureFRSQRTE,
285                                       FeatureMFTB]>;
286def : Processor<"g3", G3Itineraries, [Directive750,
287                                      FeatureFRES, FeatureFRSQRTE,
288                                      FeatureMFTB]>;
289def : Processor<"7400", G4Itineraries, [Directive7400, FeatureAltivec,
290                                        FeatureFRES, FeatureFRSQRTE,
291                                        FeatureMFTB]>;
292def : Processor<"g4", G4Itineraries, [Directive7400, FeatureAltivec,
293                                      FeatureFRES, FeatureFRSQRTE,
294                                      FeatureMFTB]>;
295def : Processor<"7450", G4PlusItineraries, [Directive7400, FeatureAltivec,
296                                            FeatureFRES, FeatureFRSQRTE,
297                                            FeatureMFTB]>;
298def : Processor<"g4+", G4PlusItineraries, [Directive7400, FeatureAltivec,
299                                           FeatureFRES, FeatureFRSQRTE,
300                                           FeatureMFTB]>;
301
302def : ProcessorModel<"970", G5Model,
303                  [Directive970, FeatureAltivec,
304                   FeatureMFOCRF, FeatureFSqrt,
305                   FeatureFRES, FeatureFRSQRTE, FeatureSTFIWX,
306                   Feature64Bit /*, Feature64BitRegs */,
307                   FeatureMFTB]>;
308def : ProcessorModel<"g5", G5Model,
309                  [Directive970, FeatureAltivec,
310                   FeatureMFOCRF, FeatureFSqrt, FeatureSTFIWX,
311                   FeatureFRES, FeatureFRSQRTE,
312                   Feature64Bit /*, Feature64BitRegs */,
313                   FeatureMFTB, DeprecatedDST]>;
314def : ProcessorModel<"e500mc", PPCE500mcModel,
315                  [DirectiveE500mc, FeatureMFOCRF,
316                   FeatureSTFIWX, FeatureICBT, FeatureBookE,
317                   FeatureISEL, FeatureMFTB]>;
318def : ProcessorModel<"e5500", PPCE5500Model,
319                  [DirectiveE5500, FeatureMFOCRF, Feature64Bit,
320                   FeatureSTFIWX, FeatureICBT, FeatureBookE,
321                   FeatureISEL, FeatureMFTB]>;
322def : ProcessorModel<"a2", PPCA2Model,
323                  [DirectiveA2, FeatureICBT, FeatureBookE, FeatureMFOCRF,
324                   FeatureFCPSGN, FeatureFSqrt, FeatureFRE, FeatureFRES,
325                   FeatureFRSQRTE, FeatureFRSQRTES, FeatureRecipPrec,
326                   FeatureSTFIWX, FeatureLFIWAX,
327                   FeatureFPRND, FeatureFPCVT, FeatureISEL,
328                   FeaturePOPCNTD, FeatureCMPB, FeatureLDBRX, Feature64Bit
329               /*, Feature64BitRegs */, FeatureMFTB]>;
330def : ProcessorModel<"a2q", PPCA2Model,
331                  [DirectiveA2, FeatureICBT, FeatureBookE, FeatureMFOCRF,
332                   FeatureFCPSGN, FeatureFSqrt, FeatureFRE, FeatureFRES,
333                   FeatureFRSQRTE, FeatureFRSQRTES, FeatureRecipPrec,
334                   FeatureSTFIWX, FeatureLFIWAX,
335                   FeatureFPRND, FeatureFPCVT, FeatureISEL,
336                   FeaturePOPCNTD, FeatureCMPB, FeatureLDBRX, Feature64Bit
337               /*, Feature64BitRegs */, FeatureQPX, FeatureMFTB]>;
338def : ProcessorModel<"pwr3", G5Model,
339                  [DirectivePwr3, FeatureAltivec,
340                   FeatureFRES, FeatureFRSQRTE, FeatureMFOCRF,
341                   FeatureSTFIWX, Feature64Bit]>;
342def : ProcessorModel<"pwr4", G5Model,
343                  [DirectivePwr4, FeatureAltivec, FeatureMFOCRF,
344                   FeatureFSqrt, FeatureFRES, FeatureFRSQRTE,
345                   FeatureSTFIWX, Feature64Bit, FeatureMFTB]>;
346def : ProcessorModel<"pwr5", G5Model,
347                  [DirectivePwr5, FeatureAltivec, FeatureMFOCRF,
348                   FeatureFSqrt, FeatureFRE, FeatureFRES,
349                   FeatureFRSQRTE, FeatureFRSQRTES,
350                   FeatureSTFIWX, Feature64Bit,
351                   FeatureMFTB, DeprecatedDST]>;
352def : ProcessorModel<"pwr5x", G5Model,
353                  [DirectivePwr5x, FeatureAltivec, FeatureMFOCRF,
354                   FeatureFSqrt, FeatureFRE, FeatureFRES,
355                   FeatureFRSQRTE, FeatureFRSQRTES,
356                   FeatureSTFIWX, FeatureFPRND, Feature64Bit,
357                   FeatureMFTB, DeprecatedDST]>;
358def : ProcessorModel<"pwr6", G5Model,
359                  [DirectivePwr6, FeatureAltivec,
360                   FeatureMFOCRF, FeatureFCPSGN, FeatureFSqrt, FeatureFRE,
361                   FeatureFRES, FeatureFRSQRTE, FeatureFRSQRTES,
362                   FeatureRecipPrec, FeatureSTFIWX, FeatureLFIWAX, FeatureCMPB,
363                   FeatureFPRND, Feature64Bit /*, Feature64BitRegs */,
364                   FeatureMFTB, DeprecatedDST]>;
365def : ProcessorModel<"pwr6x", G5Model,
366                  [DirectivePwr5x, FeatureAltivec, FeatureMFOCRF,
367                   FeatureFCPSGN, FeatureFSqrt, FeatureFRE, FeatureFRES,
368                   FeatureFRSQRTE, FeatureFRSQRTES, FeatureRecipPrec,
369                   FeatureSTFIWX, FeatureLFIWAX, FeatureCMPB,
370                   FeatureFPRND, Feature64Bit,
371                   FeatureMFTB, DeprecatedDST]>;
372def : ProcessorModel<"pwr7", P7Model, ProcessorFeatures.Power7FeatureList>;
373def : ProcessorModel<"pwr8", P8Model, ProcessorFeatures.Power8FeatureList>;
374def : Processor<"ppc", G3Itineraries, [Directive32, FeatureMFTB]>;
375def : ProcessorModel<"ppc64", G5Model,
376                  [Directive64, FeatureAltivec,
377                   FeatureMFOCRF, FeatureFSqrt, FeatureFRES,
378                   FeatureFRSQRTE, FeatureSTFIWX,
379                   Feature64Bit /*, Feature64BitRegs */,
380                   FeatureMFTB]>;
381def : ProcessorModel<"ppc64le", P8Model, ProcessorFeatures.Power8FeatureList>;
382
383//===----------------------------------------------------------------------===//
384// Calling Conventions
385//===----------------------------------------------------------------------===//
386
387include "PPCCallingConv.td"
388
389def PPCInstrInfo : InstrInfo {
390  let isLittleEndianEncoding = 1;
391
392  // FIXME: Unset this when no longer needed!
393  let decodePositionallyEncodedOperands = 1;
394
395  let noNamedPositionallyEncodedOperands = 1;
396}
397
398def PPCAsmParser : AsmParser {
399  let ShouldEmitMatchRegisterName = 0;
400}
401
402def PPCAsmParserVariant : AsmParserVariant {
403  int Variant = 0;
404
405  // We do not use hard coded registers in asm strings.  However, some
406  // InstAlias definitions use immediate literals.  Set RegisterPrefix
407  // so that those are not misinterpreted as registers.
408  string RegisterPrefix = "%";
409  string BreakCharacters = ".";
410}
411
412def PPC : Target {
413  // Information about the instructions.
414  let InstructionSet = PPCInstrInfo;
415
416  let AssemblyParsers = [PPCAsmParser];
417  let AssemblyParserVariants = [PPCAsmParserVariant];
418}
419