1//===- Target.td - Target Independent TableGen interface ---*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the target-independent interfaces which should be
10// implemented by each target which is using a TableGen based code generator.
11//
12//===----------------------------------------------------------------------===//
13
14// Include all information about LLVM intrinsics.
15include "llvm/IR/Intrinsics.td"
16
17class Predicate; // Forward def
18
19//===----------------------------------------------------------------------===//
20// Register file description - These classes are used to fill in the target
21// description classes.
22
23class HwMode<string FS, list<Predicate> Ps> {
24  // A string representing subtarget features that turn on this HW mode.
25  // For example, "+feat1,-feat2" will indicate that the mode is active
26  // when "feat1" is enabled and "feat2" is disabled at the same time.
27  // Any other features are not checked.
28  // When multiple modes are used, they should be mutually exclusive,
29  // otherwise the results are unpredictable.
30  string Features = FS;
31
32  // A list of predicates that turn on this HW mode.
33  list<Predicate> Predicates = Ps;
34}
35
36// A special mode recognized by tablegen. This mode is considered active
37// when no other mode is active. For targets that do not use specific hw
38// modes, this is the only mode.
39def DefaultMode : HwMode<"", []>;
40
41// A class used to associate objects with HW modes. It is only intended to
42// be used as a base class, where the derived class should contain a member
43// "Objects", which is a list of the same length as the list of modes.
44// The n-th element on the Objects list will be associated with the n-th
45// element on the Modes list.
46class HwModeSelect<list<HwMode> Ms> {
47  list<HwMode> Modes = Ms;
48}
49
50// A common class that implements a counterpart of ValueType, which is
51// dependent on a HW mode. This class inherits from ValueType itself,
52// which makes it possible to use objects of this class where ValueType
53// objects could be used. This is specifically applicable to selection
54// patterns.
55class ValueTypeByHwMode<list<HwMode> Ms, list<ValueType> Ts>
56    : HwModeSelect<Ms>, ValueType<0, 0> {
57  // The length of this list must be the same as the length of Ms.
58  list<ValueType> Objects = Ts;
59}
60
61// A class that implements a counterpart of PtrValueType, which is
62// dependent on a HW mode. This class inherits from PtrValueType itself,
63// which makes it possible to use objects of this class where PtrValueType
64// or ValueType could be used. This is specifically applicable to selection
65// patterns.
66class PtrValueTypeByHwMode<ValueTypeByHwMode scalar, int addrspace>
67    : HwModeSelect<scalar.Modes>, PtrValueType<ValueType<0, 0>, addrspace> {
68  list<ValueType> Objects = scalar.Objects;
69}
70
71// A class representing the register size, spill size and spill alignment
72// in bits of a register.
73class RegInfo<int RS, int SS, int SA> {
74  int RegSize = RS;         // Register size in bits.
75  int SpillSize = SS;       // Spill slot size in bits.
76  int SpillAlignment = SA;  // Spill slot alignment in bits.
77}
78
79// The register size/alignment information, parameterized by a HW mode.
80class RegInfoByHwMode<list<HwMode> Ms = [], list<RegInfo> Ts = []>
81    : HwModeSelect<Ms> {
82  // The length of this list must be the same as the length of Ms.
83  list<RegInfo> Objects = Ts;
84}
85
86class SubRegRange<int size, int offset = 0> {
87  int Size = size;      // Sub register size in bits.
88  int Offset = offset;  // Offset of the first bit of the sub-reg index.
89}
90
91class SubRegRangeByHwMode<list<HwMode> Ms = [], list<SubRegRange> Ts = []>
92    : HwModeSelect<Ms> {
93  // The length of this list must be the same as the length of Ms.
94  list<SubRegRange> Objects = Ts;
95}
96
97// SubRegIndex - Use instances of SubRegIndex to identify subregisters.
98class SubRegIndex<int size, int offset = 0> {
99  string Namespace = "";
100
101  // The size/offset information, parameterized by a HW mode.
102  // If the HwModes provided for SubRegRanges does not include the DefaultMode,
103  // the/ Size and Offset fields below will be used for the default. Otherwise,
104  // the Size and Offset fields are ignored.
105  SubRegRangeByHwMode SubRegRanges;
106
107  // Size - Size (in bits) of the sub-registers represented by this index.
108  int Size = size;
109
110  // Offset - Offset of the first bit that is part of this sub-register index.
111  // Set it to -1 if the same index is used to represent sub-registers that can
112  // be at different offsets (for example when using an index to access an
113  // element in a register tuple).
114  int Offset = offset;
115
116  // ComposedOf - A list of two SubRegIndex instances, [A, B].
117  // This indicates that this SubRegIndex is the result of composing A and B.
118  // See ComposedSubRegIndex.
119  list<SubRegIndex> ComposedOf = [];
120
121  // CoveringSubRegIndices - A list of two or more sub-register indexes that
122  // cover this sub-register.
123  //
124  // This field should normally be left blank as TableGen can infer it.
125  //
126  // TableGen automatically detects sub-registers that straddle the registers
127  // in the SubRegs field of a Register definition. For example:
128  //
129  //   Q0    = dsub_0 -> D0, dsub_1 -> D1
130  //   Q1    = dsub_0 -> D2, dsub_1 -> D3
131  //   D1_D2 = dsub_0 -> D1, dsub_1 -> D2
132  //   QQ0   = qsub_0 -> Q0, qsub_1 -> Q1
133  //
134  // TableGen will infer that D1_D2 is a sub-register of QQ0. It will be given
135  // the synthetic index dsub_1_dsub_2 unless some SubRegIndex is defined with
136  // CoveringSubRegIndices = [dsub_1, dsub_2].
137  list<SubRegIndex> CoveringSubRegIndices = [];
138}
139
140// ComposedSubRegIndex - A sub-register that is the result of composing A and B.
141// Offset is set to the sum of A and B's Offsets. Size is set to B's Size.
142class ComposedSubRegIndex<SubRegIndex A, SubRegIndex B>
143  : SubRegIndex<B.Size, !cond(!eq(A.Offset, -1): -1,
144                              !eq(B.Offset, -1): -1,
145                              true:              !add(A.Offset, B.Offset))> {
146  // See SubRegIndex.
147  let ComposedOf = [A, B];
148}
149
150// RegAltNameIndex - The alternate name set to use for register operands of
151// this register class when printing.
152class RegAltNameIndex {
153  string Namespace = "";
154
155  // A set to be used if the name for a register is not defined in this set.
156  // This allows creating name sets with only a few alternative names.
157  RegAltNameIndex FallbackRegAltNameIndex = ?;
158}
159def NoRegAltName : RegAltNameIndex;
160
161// Register - You should define one instance of this class for each register
162// in the target machine.  String n will become the "name" of the register.
163class Register<string n, list<string> altNames = []> {
164  string Namespace = "";
165  string AsmName = n;
166  list<string> AltNames = altNames;
167
168  // Aliases - A list of registers that this register overlaps with.  A read or
169  // modification of this register can potentially read or modify the aliased
170  // registers.
171  list<Register> Aliases = [];
172
173  // SubRegs - A list of registers that are parts of this register. Note these
174  // are "immediate" sub-registers and the registers within the list do not
175  // themselves overlap. e.g. For X86, EAX's SubRegs list contains only [AX],
176  // not [AX, AH, AL].
177  list<Register> SubRegs = [];
178
179  // SubRegIndices - For each register in SubRegs, specify the SubRegIndex used
180  // to address it. Sub-sub-register indices are automatically inherited from
181  // SubRegs.
182  list<SubRegIndex> SubRegIndices = [];
183
184  // RegAltNameIndices - The alternate name indices which are valid for this
185  // register.
186  list<RegAltNameIndex> RegAltNameIndices = [];
187
188  // DwarfNumbers - Numbers used internally by gcc/gdb to identify the register.
189  // These values can be determined by locating the <target>.h file in the
190  // directory llvmgcc/gcc/config/<target>/ and looking for REGISTER_NAMES.  The
191  // order of these names correspond to the enumeration used by gcc.  A value of
192  // -1 indicates that the gcc number is undefined and -2 that register number
193  // is invalid for this mode/flavour.
194  list<int> DwarfNumbers = [];
195
196  // CostPerUse - Additional cost of instructions using this register compared
197  // to other registers in its class. The register allocator will try to
198  // minimize the number of instructions using a register with a CostPerUse.
199  // This is used by the ARC target, by the ARM Thumb and x86-64 targets, where
200  // some registers require larger instruction encodings, by the RISC-V target,
201  // where some registers preclude using some C instructions. By making it a
202  // list, targets can have multiple cost models associated with each register
203  // and can choose one specific cost model per Machine Function by overriding
204  // TargetRegisterInfo::getRegisterCostTableIndex. Every target register will
205  // finally have an equal number of cost values which is the max of costPerUse
206  // values specified. Any mismatch in the cost values for a register will be
207  // filled with zeros. Restricted the cost type to uint8_t in the
208  // generated table. It will considerably reduce the table size.
209  list<int> CostPerUse = [0];
210
211  // CoveredBySubRegs - When this bit is set, the value of this register is
212  // completely determined by the value of its sub-registers.  For example, the
213  // x86 register AX is covered by its sub-registers AL and AH, but EAX is not
214  // covered by its sub-register AX.
215  bit CoveredBySubRegs = false;
216
217  // HWEncoding - The target specific hardware encoding for this register.
218  bits<16> HWEncoding = 0;
219
220  bit isArtificial = false;
221
222  // isConstant - This register always holds a constant value (e.g. the zero
223  // register in architectures such as MIPS)
224  bit isConstant = false;
225
226  /// PositionOrder - Indicate tablegen to place the newly added register at a later
227  /// position to avoid iterations on them on unsupported target.
228  int PositionOrder = 0;
229}
230
231// RegisterWithSubRegs - This can be used to define instances of Register which
232// need to specify sub-registers.
233// List "subregs" specifies which registers are sub-registers to this one. This
234// is used to populate the SubRegs and AliasSet fields of TargetRegisterDesc.
235// This allows the code generator to be careful not to put two values with
236// overlapping live ranges into registers which alias.
237class RegisterWithSubRegs<string n, list<Register> subregs> : Register<n> {
238  let SubRegs = subregs;
239}
240
241// DAGOperand - An empty base class that unifies RegisterClass's and other forms
242// of Operand's that are legal as type qualifiers in DAG patterns.  This should
243// only ever be used for defining multiclasses that are polymorphic over both
244// RegisterClass's and other Operand's.
245class DAGOperand {
246  string OperandNamespace = "MCOI";
247  string DecoderMethod = "";
248}
249
250// RegisterClass - Now that all of the registers are defined, and aliases
251// between registers are defined, specify which registers belong to which
252// register classes.  This also defines the default allocation order of
253// registers by register allocators.
254//
255class RegisterClass<string namespace, list<ValueType> regTypes, int alignment,
256                    dag regList, RegAltNameIndex idx = NoRegAltName>
257  : DAGOperand {
258  string Namespace = namespace;
259
260  // The register size/alignment information, parameterized by a HW mode.
261  RegInfoByHwMode RegInfos;
262
263  // RegType - Specify the list ValueType of the registers in this register
264  // class.  Note that all registers in a register class must have the same
265  // ValueTypes.  This is a list because some targets permit storing different
266  // types in same register, for example vector values with 128-bit total size,
267  // but different count/size of items, like SSE on x86.
268  //
269  list<ValueType> RegTypes = regTypes;
270
271  // Size - Specify the spill size in bits of the registers.  A default value of
272  // zero lets tablegen pick an appropriate size.
273  int Size = 0;
274
275  // Alignment - Specify the alignment required of the registers when they are
276  // stored or loaded to memory.
277  //
278  int Alignment = alignment;
279
280  // CopyCost - This value is used to specify the cost of copying a value
281  // between two registers in this register class. The default value is one
282  // meaning it takes a single instruction to perform the copying. A negative
283  // value means copying is extremely expensive or impossible.
284  int CopyCost = 1;
285
286  // MemberList - Specify which registers are in this class.  If the
287  // allocation_order_* method are not specified, this also defines the order of
288  // allocation used by the register allocator.
289  //
290  dag MemberList = regList;
291
292  // AltNameIndex - The alternate register name to use when printing operands
293  // of this register class. Every register in the register class must have
294  // a valid alternate name for the given index.
295  RegAltNameIndex altNameIndex = idx;
296
297  // isAllocatable - Specify that the register class can be used for virtual
298  // registers and register allocation.  Some register classes are only used to
299  // model instruction operand constraints, and should have isAllocatable = 0.
300  bit isAllocatable = true;
301
302  // AltOrders - List of alternative allocation orders. The default order is
303  // MemberList itself, and that is good enough for most targets since the
304  // register allocators automatically remove reserved registers and move
305  // callee-saved registers to the end.
306  list<dag> AltOrders = [];
307
308  // AltOrderSelect - The body of a function that selects the allocation order
309  // to use in a given machine function. The code will be inserted in a
310  // function like this:
311  //
312  //   static inline unsigned f(const MachineFunction &MF) { ... }
313  //
314  // The function should return 0 to select the default order defined by
315  // MemberList, 1 to select the first AltOrders entry and so on.
316  code AltOrderSelect = [{}];
317
318  // Specify allocation priority for register allocators using a greedy
319  // heuristic. Classes with higher priority values are assigned first. This is
320  // useful as it is sometimes beneficial to assign registers to highly
321  // constrained classes first. The value has to be in the range [0,31].
322  int AllocationPriority = 0;
323
324  // Force register class to use greedy's global heuristic for all
325  // registers in this class. This should more aggressively try to
326  // avoid spilling in pathological cases.
327  bit GlobalPriority = false;
328
329  // Generate register pressure set for this register class and any class
330  // synthesized from it. Set to 0 to inhibit unneeded pressure sets.
331  bit GeneratePressureSet = true;
332
333  // Weight override for register pressure calculation. This is the value
334  // TargetRegisterClass::getRegClassWeight() will return. The weight is in
335  // units of pressure for this register class. If unset tablegen will
336  // calculate a weight based on a number of register units in this register
337  // class registers. The weight is per register.
338  int Weight = ?;
339
340  // The diagnostic type to present when referencing this operand in a match
341  // failure error message. If this is empty, the default Match_InvalidOperand
342  // diagnostic type will be used. If this is "<name>", a Match_<name> enum
343  // value will be generated and used for this operand type. The target
344  // assembly parser is responsible for converting this into a user-facing
345  // diagnostic message.
346  string DiagnosticType = "";
347
348  // A diagnostic message to emit when an invalid value is provided for this
349  // register class when it is being used as an assembly operand. If this is
350  // non-empty, an anonymous diagnostic type enum value will be generated, and
351  // the assembly matcher will provide a function to map from diagnostic types
352  // to message strings.
353  string DiagnosticString = "";
354
355  // Target-specific flags. This becomes the TSFlags field in TargetRegisterClass.
356  bits<8> TSFlags = 0;
357
358  // If set then consider this register class to be the base class for registers in
359  // its MemberList.  The base class for registers present in multiple base register
360  // classes will be resolved in the order defined by this value, with lower values
361  // taking precedence over higher ones.  Ties are resolved by enumeration order.
362  int BaseClassOrder = ?;
363}
364
365// The memberList in a RegisterClass is a dag of set operations. TableGen
366// evaluates these set operations and expand them into register lists. These
367// are the most common operation, see test/TableGen/SetTheory.td for more
368// examples of what is possible:
369//
370// (add R0, R1, R2) - Set Union. Each argument can be an individual register, a
371// register class, or a sub-expression. This is also the way to simply list
372// registers.
373//
374// (sub GPR, SP) - Set difference. Subtract the last arguments from the first.
375//
376// (and GPR, CSR) - Set intersection. All registers from the first set that are
377// also in the second set.
378//
379// (sequence "R%u", 0, 15) -> [R0, R1, ..., R15]. Generate a sequence of
380// numbered registers.  Takes an optional 4th operand which is a stride to use
381// when generating the sequence.
382//
383// (shl GPR, 4) - Remove the first N elements.
384//
385// (trunc GPR, 4) - Truncate after the first N elements.
386//
387// (rotl GPR, 1) - Rotate N places to the left.
388//
389// (rotr GPR, 1) - Rotate N places to the right.
390//
391// (decimate GPR, 2) - Pick every N'th element, starting with the first.
392//
393// (interleave A, B, ...) - Interleave the elements from each argument list.
394//
395// All of these operators work on ordered sets, not lists. That means
396// duplicates are removed from sub-expressions.
397
398// Set operators. The rest is defined in TargetSelectionDAG.td.
399def sequence;
400def decimate;
401def interleave;
402
403// RegisterTuples - Automatically generate super-registers by forming tuples of
404// sub-registers. This is useful for modeling register sequence constraints
405// with pseudo-registers that are larger than the architectural registers.
406//
407// The sub-register lists are zipped together:
408//
409//   def EvenOdd : RegisterTuples<[sube, subo], [(add R0, R2), (add R1, R3)]>;
410//
411// Generates the same registers as:
412//
413//   let SubRegIndices = [sube, subo] in {
414//     def R0_R1 : RegisterWithSubRegs<"", [R0, R1]>;
415//     def R2_R3 : RegisterWithSubRegs<"", [R2, R3]>;
416//   }
417//
418// The generated pseudo-registers inherit super-classes and fields from their
419// first sub-register. Most fields from the Register class are inferred, and
420// the AsmName and Dwarf numbers are cleared.
421//
422// RegisterTuples instances can be used in other set operations to form
423// register classes and so on. This is the only way of using the generated
424// registers.
425//
426// RegNames may be specified to supply asm names for the generated tuples.
427// If used must have the same size as the list of produced registers.
428class RegisterTuples<list<SubRegIndex> Indices, list<dag> Regs,
429                     list<string> RegNames = []> {
430  // SubRegs - N lists of registers to be zipped up. Super-registers are
431  // synthesized from the first element of each SubRegs list, the second
432  // element and so on.
433  list<dag> SubRegs = Regs;
434
435  // SubRegIndices - N SubRegIndex instances. This provides the names of the
436  // sub-registers in the synthesized super-registers.
437  list<SubRegIndex> SubRegIndices = Indices;
438
439  // List of asm names for the generated tuple registers.
440  list<string> RegAsmNames = RegNames;
441
442  // PositionOrder - Indicate tablegen to place the newly added register at a later
443  // position to avoid iterations on them on unsupported target.
444  int PositionOrder = 0;
445}
446
447// RegisterCategory - This class is a list of RegisterClasses that belong to a
448// general cateogry --- e.g. "general purpose" or "fixed" registers. This is
449// useful for identifying registers in a generic way instead of having
450// information about a specific target's registers.
451class RegisterCategory<list<RegisterClass> classes> {
452  // Classes - A list of register classes that fall within the category.
453  list<RegisterClass> Classes = classes;
454}
455
456//===----------------------------------------------------------------------===//
457// DwarfRegNum - This class provides a mapping of the llvm register enumeration
458// to the register numbering used by gcc and gdb.  These values are used by a
459// debug information writer to describe where values may be located during
460// execution.
461class DwarfRegNum<list<int> Numbers> {
462  // DwarfNumbers - Numbers used internally by gcc/gdb to identify the register.
463  // These values can be determined by locating the <target>.h file in the
464  // directory llvmgcc/gcc/config/<target>/ and looking for REGISTER_NAMES.  The
465  // order of these names correspond to the enumeration used by gcc.  A value of
466  // -1 indicates that the gcc number is undefined and -2 that register number
467  // is invalid for this mode/flavour.
468  list<int> DwarfNumbers = Numbers;
469}
470
471// DwarfRegAlias - This class declares that a given register uses the same dwarf
472// numbers as another one. This is useful for making it clear that the two
473// registers do have the same number. It also lets us build a mapping
474// from dwarf register number to llvm register.
475class DwarfRegAlias<Register reg> {
476      Register DwarfAlias = reg;
477}
478
479//===----------------------------------------------------------------------===//
480// SubtargetFeature - A characteristic of the chip set.
481//
482class SubtargetFeature<string n, string f, string v, string d,
483                       list<SubtargetFeature> i = []> {
484  // Name - Feature name.  Used by command line (-mattr=) to determine the
485  // appropriate target chip.
486  //
487  string Name = n;
488
489  // FieldName - Field in XXXSubtarget to be set by feature.
490  //
491  string FieldName = f;
492
493  // Value - Value the XXXSubtarget field to be set to by feature.
494  //
495  // A value of "true" or "false" implies the field is a bool. Otherwise,
496  // it is assumed to be an integer. the integer value may be the name of an
497  // enum constant. If multiple features use the same integer field, the
498  // field will be set to the maximum value of all enabled features that
499  // share the field.
500  //
501  string Value = v;
502
503  // Desc - Feature description.  Used by command line (-mattr=) to display help
504  // information.
505  //
506  string Desc = d;
507
508  // Implies - Features that this feature implies are present. If one of those
509  // features isn't set, then this one shouldn't be set either.
510  //
511  list<SubtargetFeature> Implies = i;
512}
513
514/// Specifies a Subtarget feature that this instruction is deprecated on.
515class Deprecated<SubtargetFeature dep> {
516  SubtargetFeature DeprecatedFeatureMask = dep;
517}
518
519/// A custom predicate used to determine if an instruction is
520/// deprecated or not.
521class ComplexDeprecationPredicate<string dep> {
522  string ComplexDeprecationPredicate = dep;
523}
524
525//===----------------------------------------------------------------------===//
526// Pull in the common support for MCPredicate (portable scheduling predicates).
527//
528include "llvm/Target/TargetInstrPredicate.td"
529
530//===----------------------------------------------------------------------===//
531// Pull in the common support for scheduling
532//
533include "llvm/Target/TargetSchedule.td"
534
535class InstructionEncoding {
536  // Size of encoded instruction.
537  int Size;
538
539  // The "namespace" in which this instruction exists, on targets like ARM
540  // which multiple ISA namespaces exist.
541  string DecoderNamespace = "";
542
543  // List of predicates which will be turned into isel matching code.
544  list<Predicate> Predicates = [];
545
546  string DecoderMethod = "";
547
548  // Is the instruction decoder method able to completely determine if the
549  // given instruction is valid or not. If the TableGen definition of the
550  // instruction specifies bitpattern A??B where A and B are static bits, the
551  // hasCompleteDecoder flag says whether the decoder method fully handles the
552  // ?? space, i.e. if it is a final arbiter for the instruction validity.
553  // If not then the decoder attempts to continue decoding when the decoder
554  // method fails.
555  //
556  // This allows to handle situations where the encoding is not fully
557  // orthogonal. Example:
558  // * InstA with bitpattern 0b0000????,
559  // * InstB with bitpattern 0b000000?? but the associated decoder method
560  //   DecodeInstB() returns Fail when ?? is 0b00 or 0b11.
561  //
562  // The decoder tries to decode a bitpattern that matches both InstA and
563  // InstB bitpatterns first as InstB (because it is the most specific
564  // encoding). In the default case (hasCompleteDecoder = 1), when
565  // DecodeInstB() returns Fail the bitpattern gets rejected. By setting
566  // hasCompleteDecoder = 0 in InstB, the decoder is informed that
567  // DecodeInstB() is not able to determine if all possible values of ?? are
568  // valid or not. If DecodeInstB() returns Fail the decoder will attempt to
569  // decode the bitpattern as InstA too.
570  bit hasCompleteDecoder = true;
571}
572
573// Allows specifying an InstructionEncoding by HwMode. If an Instruction specifies
574// an EncodingByHwMode, its Inst and Size members are ignored and Ts are used
575// to encode and decode based on HwMode.
576class EncodingByHwMode<list<HwMode> Ms = [], list<InstructionEncoding> Ts = []>
577    : HwModeSelect<Ms> {
578  // The length of this list must be the same as the length of Ms.
579  list<InstructionEncoding> Objects = Ts;
580}
581
582//===----------------------------------------------------------------------===//
583// Instruction set description - These classes correspond to the C++ classes in
584// the Target/TargetInstrInfo.h file.
585//
586class Instruction : InstructionEncoding {
587  string Namespace = "";
588
589  dag OutOperandList;       // An dag containing the MI def operand list.
590  dag InOperandList;        // An dag containing the MI use operand list.
591  string AsmString = "";    // The .s format to print the instruction with.
592
593  // Allows specifying a canonical InstructionEncoding by HwMode. If non-empty,
594  // the Inst member of this Instruction is ignored.
595  EncodingByHwMode EncodingInfos;
596
597  // Pattern - Set to the DAG pattern for this instruction, if we know of one,
598  // otherwise, uninitialized.
599  list<dag> Pattern;
600
601  // The follow state will eventually be inferred automatically from the
602  // instruction pattern.
603
604  list<Register> Uses = []; // Default to using no non-operand registers
605  list<Register> Defs = []; // Default to modifying no non-operand registers
606
607  // Predicates - List of predicates which will be turned into isel matching
608  // code.
609  list<Predicate> Predicates = [];
610
611  // Size - Size of encoded instruction, or zero if the size cannot be determined
612  // from the opcode.
613  int Size = 0;
614
615  // Code size, for instruction selection.
616  // FIXME: What does this actually mean?
617  int CodeSize = 0;
618
619  // Added complexity passed onto matching pattern.
620  int AddedComplexity  = 0;
621
622  // Indicates if this is a pre-isel opcode that should be
623  // legalized/regbankselected/selected.
624  bit isPreISelOpcode = false;
625
626  // These bits capture information about the high-level semantics of the
627  // instruction.
628  bit isReturn     = false;     // Is this instruction a return instruction?
629  bit isBranch     = false;     // Is this instruction a branch instruction?
630  bit isEHScopeReturn = false;  // Does this instruction end an EH scope?
631  bit isIndirectBranch = false; // Is this instruction an indirect branch?
632  bit isCompare    = false;     // Is this instruction a comparison instruction?
633  bit isMoveImm    = false;     // Is this instruction a move immediate instruction?
634  bit isMoveReg    = false;     // Is this instruction a move register instruction?
635  bit isBitcast    = false;     // Is this instruction a bitcast instruction?
636  bit isSelect     = false;     // Is this instruction a select instruction?
637  bit isBarrier    = false;     // Can control flow fall through this instruction?
638  bit isCall       = false;     // Is this instruction a call instruction?
639  bit isAdd        = false;     // Is this instruction an add instruction?
640  bit isTrap       = false;     // Is this instruction a trap instruction?
641  bit canFoldAsLoad = false;    // Can this be folded as a simple memory operand?
642  bit mayLoad      = ?;         // Is it possible for this inst to read memory?
643  bit mayStore     = ?;         // Is it possible for this inst to write memory?
644  bit mayRaiseFPException = false; // Can this raise a floating-point exception?
645  bit isConvertibleToThreeAddress = false;  // Can this 2-addr instruction promote?
646  bit isCommutable = false;     // Is this 3 operand instruction commutable?
647  bit isTerminator = false;     // Is this part of the terminator for a basic block?
648  bit isReMaterializable = false; // Is this instruction re-materializable?
649  bit isPredicable = false;     // 1 means this instruction is predicable
650                                // even if it does not have any operand
651                                // tablegen can identify as a predicate
652  bit isUnpredicable = false;   // 1 means this instruction is not predicable
653                                // even if it _does_ have a predicate operand
654  bit hasDelaySlot = false;     // Does this instruction have an delay slot?
655  bit usesCustomInserter = false; // Pseudo instr needing special help.
656  bit hasPostISelHook = false;  // To be *adjusted* after isel by target hook.
657  bit hasCtrlDep   = false;     // Does this instruction r/w ctrl-flow chains?
658  bit isNotDuplicable = false;  // Is it unsafe to duplicate this instruction?
659  bit isConvergent = false;     // Is this instruction convergent?
660  bit isAuthenticated = false;  // Does this instruction authenticate a pointer?
661  bit isAsCheapAsAMove = false; // As cheap (or cheaper) than a move instruction.
662  bit hasExtraSrcRegAllocReq = false; // Sources have special regalloc requirement?
663  bit hasExtraDefRegAllocReq = false; // Defs have special regalloc requirement?
664  bit isRegSequence = false;    // Is this instruction a kind of reg sequence?
665                                // If so, make sure to override
666                                // TargetInstrInfo::getRegSequenceLikeInputs.
667  bit isPseudo     = false;     // Is this instruction a pseudo-instruction?
668                                // If so, won't have encoding information for
669                                // the [MC]CodeEmitter stuff.
670  bit isMeta = false;           // Is this instruction a meta-instruction?
671                                // If so, won't produce any output in the form of
672                                // executable instructions
673  bit isExtractSubreg = false;  // Is this instruction a kind of extract subreg?
674                                // If so, make sure to override
675                                // TargetInstrInfo::getExtractSubregLikeInputs.
676  bit isInsertSubreg = false;   // Is this instruction a kind of insert subreg?
677                                // If so, make sure to override
678                                // TargetInstrInfo::getInsertSubregLikeInputs.
679  bit variadicOpsAreDefs = false; // Are variadic operands definitions?
680
681  // Does the instruction have side effects that are not captured by any
682  // operands of the instruction or other flags?
683  bit hasSideEffects = ?;
684
685  // Is this instruction a "real" instruction (with a distinct machine
686  // encoding), or is it a pseudo instruction used for codegen modeling
687  // purposes.
688  // FIXME: For now this is distinct from isPseudo, above, as code-gen-only
689  // instructions can (and often do) still have encoding information
690  // associated with them. Once we've migrated all of them over to true
691  // pseudo-instructions that are lowered to real instructions prior to
692  // the printer/emitter, we can remove this attribute and just use isPseudo.
693  //
694  // The intended use is:
695  // isPseudo: Does not have encoding information and should be expanded,
696  //   at the latest, during lowering to MCInst.
697  //
698  // isCodeGenOnly: Does have encoding information and can go through to the
699  //   CodeEmitter unchanged, but duplicates a canonical instruction
700  //   definition's encoding and should be ignored when constructing the
701  //   assembler match tables.
702  bit isCodeGenOnly = false;
703
704  // Is this instruction a pseudo instruction for use by the assembler parser.
705  bit isAsmParserOnly = false;
706
707  // This instruction is not expected to be queried for scheduling latencies
708  // and therefore needs no scheduling information even for a complete
709  // scheduling model.
710  bit hasNoSchedulingInfo = false;
711
712  InstrItinClass Itinerary = NoItinerary;// Execution steps used for scheduling.
713
714  // Scheduling information from TargetSchedule.td.
715  list<SchedReadWrite> SchedRW;
716
717  /// Support for operand constraints. There are currently two kinds:
718  /// "$src = $dst"
719  ///   Ensures that the operands are allocated to the same register.
720  ///
721  /// "@earlyclobber $rd"
722  ///   Ensures that LLVM will not use the same register for any inputs (other
723  ///   than an input tied to this output).
724  ///
725  /// See also:
726  /// - MC/MCInstrDesc.h:OperandConstraint::{TIED_TO, EARLY_CLOBBER}.
727  /// - CodeGen/MachineOperand.h:MachineOperand::{TiedTo, IsEarlyClobber}.
728  /// - The LLVM IR specification: Section `Output constraints` in the
729  ///   discussion of inline assembly constraint strings.
730  string Constraints = "";
731
732  /// DisableEncoding - List of operand names (e.g. "$op1,$op2") that should not
733  /// be encoded into the output machineinstr.
734  string DisableEncoding = "";
735
736  string PostEncoderMethod = "";
737
738  /// Target-specific flags. This becomes the TSFlags field in TargetInstrDesc.
739  bits<64> TSFlags = 0;
740
741  ///@name Assembler Parser Support
742  ///@{
743
744  string AsmMatchConverter = "";
745
746  /// TwoOperandAliasConstraint - Enable TableGen to auto-generate a
747  /// two-operand matcher inst-alias for a three operand instruction.
748  /// For example, the arm instruction "add r3, r3, r5" can be written
749  /// as "add r3, r5". The constraint is of the same form as a tied-operand
750  /// constraint. For example, "$Rn = $Rd".
751  string TwoOperandAliasConstraint = "";
752
753  /// Assembler variant name to use for this instruction. If specified then
754  /// instruction will be presented only in MatchTable for this variant. If
755  /// not specified then assembler variants will be determined based on
756  /// AsmString
757  string AsmVariantName = "";
758
759  ///@}
760
761  /// UseNamedOperandTable - If set, the operand indices of this instruction
762  /// can be queried via the getNamedOperandIdx() function which is generated
763  /// by TableGen.
764  bit UseNamedOperandTable = false;
765
766  /// Should generate helper functions that help you to map a logical operand's
767  /// index to the underlying MIOperand's index.
768  /// In most architectures logical operand indicies are equal to
769  /// MIOperand indicies, but for some CISC architectures, a logical operand
770  /// might be consist of multiple MIOperand (e.g. a logical operand that
771  /// uses complex address mode).
772  bit UseLogicalOperandMappings = false;
773
774  /// Should FastISel ignore this instruction. For certain ISAs, they have
775  /// instructions which map to the same ISD Opcode, value type operands and
776  /// instruction selection predicates. FastISel cannot handle such cases, but
777  /// SelectionDAG can.
778  bit FastISelShouldIgnore = false;
779
780  /// HasPositionOrder: Indicate tablegen to sort the instructions by record
781  /// ID, so that instruction that is defined earlier can be sorted earlier
782  /// in the assembly matching table.
783  bit HasPositionOrder = false;
784}
785
786/// Defines a Pat match between compressed and uncompressed instruction.
787/// The relationship and helper function generation are handled by
788/// CompressInstEmitter backend.
789class CompressPat<dag input, dag output, list<Predicate> predicates = []> {
790  /// Uncompressed instruction description.
791  dag Input = input;
792  /// Compressed instruction description.
793  dag Output = output;
794  /// Predicates that must be true for this to match.
795  list<Predicate> Predicates = predicates;
796  /// Duplicate match when tied operand is just different.
797  bit isCompressOnly = false;
798}
799
800/// Defines an additional encoding that disassembles to the given instruction
801/// Like Instruction, the Inst and SoftFail fields are omitted to allow targets
802// to specify their size.
803class AdditionalEncoding<Instruction I> : InstructionEncoding {
804  Instruction AliasOf = I;
805}
806
807/// PseudoInstExpansion - Expansion information for a pseudo-instruction.
808/// Which instruction it expands to and how the operands map from the
809/// pseudo.
810class PseudoInstExpansion<dag Result> {
811  dag ResultInst = Result;     // The instruction to generate.
812  bit isPseudo = true;
813}
814
815/// Predicates - These are extra conditionals which are turned into instruction
816/// selector matching code. Currently each predicate is just a string.
817class Predicate<string cond> {
818  string CondString = cond;
819
820  /// AssemblerMatcherPredicate - If this feature can be used by the assembler
821  /// matcher, this is true.  Targets should set this by inheriting their
822  /// feature from the AssemblerPredicate class in addition to Predicate.
823  bit AssemblerMatcherPredicate = false;
824
825  /// AssemblerCondDag - Set of subtarget features being tested used
826  /// as alternative condition string used for assembler matcher. Must be used
827  /// with (all_of) to indicate that all features must be present, or (any_of)
828  /// to indicate that at least one must be. The required lack of presence of
829  /// a feature can be tested using a (not) node including the feature.
830  /// e.g. "(all_of ModeThumb)" is translated to "(Bits & ModeThumb) != 0".
831  ///      "(all_of (not ModeThumb))" is translated to
832  ///      "(Bits & ModeThumb) == 0".
833  ///      "(all_of ModeThumb, FeatureThumb2)" is translated to
834  ///      "(Bits & ModeThumb) != 0 && (Bits & FeatureThumb2) != 0".
835  ///      "(any_of ModeTumb, FeatureThumb2)" is translated to
836  ///      "(Bits & ModeThumb) != 0 || (Bits & FeatureThumb2) != 0".
837  /// all_of and any_of cannot be combined in a single dag, instead multiple
838  /// predicates can be placed onto Instruction definitions.
839  dag AssemblerCondDag;
840
841  /// PredicateName - User-level name to use for the predicate. Mainly for use
842  /// in diagnostics such as missing feature errors in the asm matcher.
843  string PredicateName = "";
844
845  /// Setting this to '1' indicates that the predicate must be recomputed on
846  /// every function change. Most predicates can leave this at '0'.
847  ///
848  /// Ignored by SelectionDAG, it always recomputes the predicate on every use.
849  bit RecomputePerFunction = false;
850}
851
852/// NoHonorSignDependentRounding - This predicate is true if support for
853/// sign-dependent-rounding is not enabled.
854def NoHonorSignDependentRounding
855 : Predicate<"!TM.Options.HonorSignDependentRoundingFPMath()">;
856
857class Requires<list<Predicate> preds> {
858  list<Predicate> Predicates = preds;
859}
860
861/// ops definition - This is just a simple marker used to identify the operand
862/// list for an instruction. outs and ins are identical both syntactically and
863/// semantically; they are used to define def operands and use operands to
864/// improve readability. This should be used like this:
865///     (outs R32:$dst), (ins R32:$src1, R32:$src2) or something similar.
866def ops;
867def outs;
868def ins;
869
870/// variable_ops definition - Mark this instruction as taking a variable number
871/// of operands.
872def variable_ops;
873
874/// variable-length instruction encoding utilities.
875/// The `ascend` operator should be used like this:
876///     (ascend 0b0010, 0b1101)
877/// Which represent a seqence of encoding fragments placing from LSB to MSB.
878/// Thus, in this case the final encoding will be 0b1101_0010.
879/// The arguments for `ascend` can either be `bits` or another DAG.
880def ascend;
881/// In addition, we can use `descend` to describe an encoding that places
882/// its arguments (i.e. encoding fragments) from MSB to LSB. For instance:
883///     (descend 0b0010, 0b1101)
884/// This results in an encoding of 0b0010_1101.
885def descend;
886/// The `operand` operator should be used like this:
887///     (operand "$src", 4)
888/// Which represents a 4-bit encoding for an instruction operand named `$src`.
889def operand;
890/// Similar to `operand`, we can reference only part of the operand's encoding:
891///     (slice "$src", 6, 8)
892///     (slice "$src", 8, 6)
893/// Both DAG represent bit 6 to 8 (total of 3 bits) in the encoding of operand
894/// `$src`.
895def slice;
896/// You can use `encoder` or `decoder` to specify a custom encoder or decoder
897/// function for a specific `operand` or `slice` directive. For example:
898///     (operand "$src", 4, (encoder "encodeMyImm"))
899///     (slice "$src", 8, 6, (encoder "encodeMyReg"))
900///     (operand "$src", 4, (encoder "encodeMyImm"), (decoder "decodeMyImm"))
901/// The ordering of `encoder` and `decoder` in the same `operand` or `slice`
902/// doesn't matter.
903/// Note that currently we cannot assign different decoders in the same
904/// (instruction) operand.
905def encoder;
906def decoder;
907
908/// PointerLikeRegClass - Values that are designed to have pointer width are
909/// derived from this.  TableGen treats the register class as having a symbolic
910/// type that it doesn't know, and resolves the actual regclass to use by using
911/// the TargetRegisterInfo::getPointerRegClass() hook at codegen time.
912class PointerLikeRegClass<int Kind> {
913  int RegClassKind = Kind;
914}
915
916
917/// ptr_rc definition - Mark this operand as being a pointer value whose
918/// register class is resolved dynamically via a callback to TargetInstrInfo.
919/// FIXME: We should probably change this to a class which contain a list of
920/// flags. But currently we have but one flag.
921def ptr_rc : PointerLikeRegClass<0>;
922
923/// unknown definition - Mark this operand as being of unknown type, causing
924/// it to be resolved by inference in the context it is used.
925class unknown_class;
926def unknown : unknown_class;
927
928/// AsmOperandClass - Representation for the kinds of operands which the target
929/// specific parser can create and the assembly matcher may need to distinguish.
930///
931/// Operand classes are used to define the order in which instructions are
932/// matched, to ensure that the instruction which gets matched for any
933/// particular list of operands is deterministic.
934///
935/// The target specific parser must be able to classify a parsed operand into a
936/// unique class which does not partially overlap with any other classes. It can
937/// match a subset of some other class, in which case the super class field
938/// should be defined.
939class AsmOperandClass {
940  /// The name to use for this class, which should be usable as an enum value.
941  string Name = ?;
942
943  /// The super classes of this operand.
944  list<AsmOperandClass> SuperClasses = [];
945
946  /// The name of the method on the target specific operand to call to test
947  /// whether the operand is an instance of this class. If not set, this will
948  /// default to "isFoo", where Foo is the AsmOperandClass name. The method
949  /// signature should be:
950  ///   bool isFoo() const;
951  string PredicateMethod = ?;
952
953  /// The name of the method on the target specific operand to call to add the
954  /// target specific operand to an MCInst. If not set, this will default to
955  /// "addFooOperands", where Foo is the AsmOperandClass name. The method
956  /// signature should be:
957  ///   void addFooOperands(MCInst &Inst, unsigned N) const;
958  string RenderMethod = ?;
959
960  /// The name of the method on the target specific operand to call to custom
961  /// handle the operand parsing. This is useful when the operands do not relate
962  /// to immediates or registers and are very instruction specific (as flags to
963  /// set in a processor register, coprocessor number, ...).
964  string ParserMethod = ?;
965
966  // The diagnostic type to present when referencing this operand in a
967  // match failure error message. By default, use a generic "invalid operand"
968  // diagnostic. The target AsmParser maps these codes to text.
969  string DiagnosticType = "";
970
971  /// A diagnostic message to emit when an invalid value is provided for this
972  /// operand.
973  string DiagnosticString = "";
974
975  /// Set to 1 if this operand is optional and not always required. Typically,
976  /// the AsmParser will emit an error when it finishes parsing an
977  /// instruction if it hasn't matched all the operands yet.  However, this
978  /// error will be suppressed if all of the remaining unmatched operands are
979  /// marked as IsOptional.
980  bit IsOptional = false;
981
982  /// The name of the method on the target specific asm parser that returns the
983  /// default operand for this optional operand. This method is only used if
984  /// IsOptional == 1. If not set, this will default to "defaultFooOperands",
985  /// where Foo is the AsmOperandClass name. The method signature should be:
986  ///   std::unique_ptr<MCParsedAsmOperand> defaultFooOperands() const;
987  string DefaultMethod = ?;
988}
989
990def ImmAsmOperand : AsmOperandClass {
991  let Name = "Imm";
992}
993
994/// Operand Types - These provide the built-in operand types that may be used
995/// by a target.  Targets can optionally provide their own operand types as
996/// needed, though this should not be needed for RISC targets.
997class Operand<ValueType ty> : DAGOperand {
998  ValueType Type = ty;
999  string PrintMethod = "printOperand";
1000  string EncoderMethod = "";
1001  bit hasCompleteDecoder = true;
1002  string OperandType = "OPERAND_UNKNOWN";
1003  dag MIOperandInfo = (ops);
1004
1005  // MCOperandPredicate - Optionally, a code fragment operating on
1006  // const MCOperand &MCOp, and returning a bool, to indicate if
1007  // the value of MCOp is valid for the specific subclass of Operand
1008  code MCOperandPredicate;
1009
1010  // ParserMatchClass - The "match class" that operands of this type fit
1011  // in. Match classes are used to define the order in which instructions are
1012  // match, to ensure that which instructions gets matched is deterministic.
1013  //
1014  // The target specific parser must be able to classify an parsed operand into
1015  // a unique class, which does not partially overlap with any other classes. It
1016  // can match a subset of some other class, in which case the AsmOperandClass
1017  // should declare the other operand as one of its super classes.
1018  AsmOperandClass ParserMatchClass = ImmAsmOperand;
1019}
1020
1021class RegisterOperand<RegisterClass regclass, string pm = "printOperand">
1022  : DAGOperand {
1023  // RegClass - The register class of the operand.
1024  RegisterClass RegClass = regclass;
1025  // PrintMethod - The target method to call to print register operands of
1026  // this type. The method normally will just use an alt-name index to look
1027  // up the name to print. Default to the generic printOperand().
1028  string PrintMethod = pm;
1029
1030  // EncoderMethod - The target method name to call to encode this register
1031  // operand.
1032  string EncoderMethod = "";
1033
1034  // ParserMatchClass - The "match class" that operands of this type fit
1035  // in. Match classes are used to define the order in which instructions are
1036  // match, to ensure that which instructions gets matched is deterministic.
1037  //
1038  // The target specific parser must be able to classify an parsed operand into
1039  // a unique class, which does not partially overlap with any other classes. It
1040  // can match a subset of some other class, in which case the AsmOperandClass
1041  // should declare the other operand as one of its super classes.
1042  AsmOperandClass ParserMatchClass;
1043
1044  string OperandType = "OPERAND_REGISTER";
1045
1046  // When referenced in the result of a CodeGen pattern, GlobalISel will
1047  // normally copy the matched operand to the result. When this is set, it will
1048  // emit a special copy that will replace zero-immediates with the specified
1049  // zero-register.
1050  Register GIZeroRegister = ?;
1051}
1052
1053let OperandType = "OPERAND_IMMEDIATE" in {
1054def i1imm  : Operand<i1>;
1055def i8imm  : Operand<i8>;
1056def i16imm : Operand<i16>;
1057def i32imm : Operand<i32>;
1058def i64imm : Operand<i64>;
1059
1060def f32imm : Operand<f32>;
1061def f64imm : Operand<f64>;
1062}
1063
1064// Register operands for generic instructions don't have an MVT, but do have
1065// constraints linking the operands (e.g. all operands of a G_ADD must
1066// have the same LLT).
1067class TypedOperand<string Ty> : Operand<untyped> {
1068  let OperandType = Ty;
1069  bit IsPointer = false;
1070  bit IsImmediate = false;
1071}
1072
1073def type0 : TypedOperand<"OPERAND_GENERIC_0">;
1074def type1 : TypedOperand<"OPERAND_GENERIC_1">;
1075def type2 : TypedOperand<"OPERAND_GENERIC_2">;
1076def type3 : TypedOperand<"OPERAND_GENERIC_3">;
1077def type4 : TypedOperand<"OPERAND_GENERIC_4">;
1078def type5 : TypedOperand<"OPERAND_GENERIC_5">;
1079
1080let IsPointer = true in {
1081  def ptype0 : TypedOperand<"OPERAND_GENERIC_0">;
1082  def ptype1 : TypedOperand<"OPERAND_GENERIC_1">;
1083  def ptype2 : TypedOperand<"OPERAND_GENERIC_2">;
1084  def ptype3 : TypedOperand<"OPERAND_GENERIC_3">;
1085  def ptype4 : TypedOperand<"OPERAND_GENERIC_4">;
1086  def ptype5 : TypedOperand<"OPERAND_GENERIC_5">;
1087}
1088
1089// untyped_imm is for operands where isImm() will be true. It currently has no
1090// special behaviour and is only used for clarity.
1091def untyped_imm_0 : TypedOperand<"OPERAND_GENERIC_IMM_0"> {
1092  let IsImmediate = true;
1093}
1094
1095/// zero_reg definition - Special node to stand for the zero register.
1096///
1097def zero_reg;
1098
1099/// undef_tied_input - Special node to indicate an input register tied
1100/// to an output which defaults to IMPLICIT_DEF.
1101def undef_tied_input;
1102
1103/// All operands which the MC layer classifies as predicates should inherit from
1104/// this class in some manner. This is already handled for the most commonly
1105/// used PredicateOperand, but may be useful in other circumstances.
1106class PredicateOp;
1107
1108/// OperandWithDefaultOps - This Operand class can be used as the parent class
1109/// for an Operand that needs to be initialized with a default value if
1110/// no value is supplied in a pattern.  This class can be used to simplify the
1111/// pattern definitions for instructions that have target specific flags
1112/// encoded as immediate operands.
1113class OperandWithDefaultOps<ValueType ty, dag defaultops>
1114  : Operand<ty> {
1115  dag DefaultOps = defaultops;
1116}
1117
1118/// PredicateOperand - This can be used to define a predicate operand for an
1119/// instruction.  OpTypes specifies the MIOperandInfo for the operand, and
1120/// AlwaysVal specifies the value of this predicate when set to "always
1121/// execute".
1122class PredicateOperand<ValueType ty, dag OpTypes, dag AlwaysVal>
1123  : OperandWithDefaultOps<ty, AlwaysVal>, PredicateOp {
1124  let MIOperandInfo = OpTypes;
1125}
1126
1127/// OptionalDefOperand - This is used to define a optional definition operand
1128/// for an instruction. DefaultOps is the register the operand represents if
1129/// none is supplied, e.g. zero_reg.
1130class OptionalDefOperand<ValueType ty, dag OpTypes, dag defaultops>
1131  : OperandWithDefaultOps<ty, defaultops> {
1132  let MIOperandInfo = OpTypes;
1133}
1134
1135
1136// InstrInfo - This class should only be instantiated once to provide parameters
1137// which are global to the target machine.
1138//
1139class InstrInfo {
1140  // Target can specify its instructions in either big or little-endian formats.
1141  // For instance, while both Sparc and PowerPC are big-endian platforms, the
1142  // Sparc manual specifies its instructions in the format [31..0] (big), while
1143  // PowerPC specifies them using the format [0..31] (little).
1144  bit isLittleEndianEncoding = false;
1145
1146  // The instruction properties mayLoad, mayStore, and hasSideEffects are unset
1147  // by default, and TableGen will infer their value from the instruction
1148  // pattern when possible.
1149  //
1150  // Normally, TableGen will issue an error if it can't infer the value of a
1151  // property that hasn't been set explicitly. When guessInstructionProperties
1152  // is set, it will guess a safe value instead.
1153  //
1154  // This option is a temporary migration help. It will go away.
1155  bit guessInstructionProperties = true;
1156}
1157
1158// Standard Pseudo Instructions.
1159// This list must match TargetOpcodes.def.
1160// Only these instructions are allowed in the TargetOpcode namespace.
1161// Ensure mayLoad and mayStore have a default value, so as not to break
1162// targets that set guessInstructionProperties=0. Any local definition of
1163// mayLoad/mayStore takes precedence over these default values.
1164class StandardPseudoInstruction : Instruction {
1165  let mayLoad = false;
1166  let mayStore = false;
1167  let isCodeGenOnly = true;
1168  let isPseudo = true;
1169  let hasNoSchedulingInfo = true;
1170  let Namespace = "TargetOpcode";
1171}
1172def PHI : StandardPseudoInstruction {
1173  let OutOperandList = (outs unknown:$dst);
1174  let InOperandList = (ins variable_ops);
1175  let AsmString = "PHINODE";
1176  let hasSideEffects = false;
1177}
1178def INLINEASM : StandardPseudoInstruction {
1179  let OutOperandList = (outs);
1180  let InOperandList = (ins variable_ops);
1181  let AsmString = "";
1182  let hasSideEffects = false;  // Note side effect is encoded in an operand.
1183}
1184def INLINEASM_BR : StandardPseudoInstruction {
1185  let OutOperandList = (outs);
1186  let InOperandList = (ins variable_ops);
1187  let AsmString = "";
1188  // Unlike INLINEASM, this is always treated as having side-effects.
1189  let hasSideEffects = true;
1190  // Despite potentially branching, this instruction is intentionally _not_
1191  // marked as a terminator or a branch.
1192}
1193def CFI_INSTRUCTION : StandardPseudoInstruction {
1194  let OutOperandList = (outs);
1195  let InOperandList = (ins i32imm:$id);
1196  let AsmString = "";
1197  let hasCtrlDep = true;
1198  let hasSideEffects = false;
1199  let isNotDuplicable = true;
1200  let isMeta = true;
1201}
1202def EH_LABEL : StandardPseudoInstruction {
1203  let OutOperandList = (outs);
1204  let InOperandList = (ins i32imm:$id);
1205  let AsmString = "";
1206  let hasCtrlDep = true;
1207  let hasSideEffects = false;
1208  let isNotDuplicable = true;
1209  let isMeta = true;
1210}
1211def GC_LABEL : StandardPseudoInstruction {
1212  let OutOperandList = (outs);
1213  let InOperandList = (ins i32imm:$id);
1214  let AsmString = "";
1215  let hasCtrlDep = true;
1216  let hasSideEffects = false;
1217  let isNotDuplicable = true;
1218  let isMeta = true;
1219}
1220def ANNOTATION_LABEL : StandardPseudoInstruction {
1221  let OutOperandList = (outs);
1222  let InOperandList = (ins i32imm:$id);
1223  let AsmString = "";
1224  let hasCtrlDep = true;
1225  let hasSideEffects = false;
1226  let isNotDuplicable = true;
1227}
1228def KILL : StandardPseudoInstruction {
1229  let OutOperandList = (outs);
1230  let InOperandList = (ins variable_ops);
1231  let AsmString = "";
1232  let hasSideEffects = false;
1233  let isMeta = true;
1234}
1235def EXTRACT_SUBREG : StandardPseudoInstruction {
1236  let OutOperandList = (outs unknown:$dst);
1237  let InOperandList = (ins unknown:$supersrc, i32imm:$subidx);
1238  let AsmString = "";
1239  let hasSideEffects = false;
1240}
1241def INSERT_SUBREG : StandardPseudoInstruction {
1242  let OutOperandList = (outs unknown:$dst);
1243  let InOperandList = (ins unknown:$supersrc, unknown:$subsrc, i32imm:$subidx);
1244  let AsmString = "";
1245  let hasSideEffects = false;
1246  let Constraints = "$supersrc = $dst";
1247}
1248def IMPLICIT_DEF : StandardPseudoInstruction {
1249  let OutOperandList = (outs unknown:$dst);
1250  let InOperandList = (ins);
1251  let AsmString = "";
1252  let hasSideEffects = false;
1253  let isReMaterializable = true;
1254  let isAsCheapAsAMove = true;
1255  let isMeta = true;
1256}
1257def SUBREG_TO_REG : StandardPseudoInstruction {
1258  let OutOperandList = (outs unknown:$dst);
1259  let InOperandList = (ins unknown:$implsrc, unknown:$subsrc, i32imm:$subidx);
1260  let AsmString = "";
1261  let hasSideEffects = false;
1262}
1263def COPY_TO_REGCLASS : StandardPseudoInstruction {
1264  let OutOperandList = (outs unknown:$dst);
1265  let InOperandList = (ins unknown:$src, i32imm:$regclass);
1266  let AsmString = "";
1267  let hasSideEffects = false;
1268  let isAsCheapAsAMove = true;
1269}
1270def DBG_VALUE : StandardPseudoInstruction {
1271  let OutOperandList = (outs);
1272  let InOperandList = (ins variable_ops);
1273  let AsmString = "DBG_VALUE";
1274  let hasSideEffects = false;
1275  let isMeta = true;
1276}
1277def DBG_VALUE_LIST : StandardPseudoInstruction {
1278  let OutOperandList = (outs);
1279  let InOperandList = (ins variable_ops);
1280  let AsmString = "DBG_VALUE_LIST";
1281  let hasSideEffects = 0;
1282  let isMeta = true;
1283}
1284def DBG_INSTR_REF : StandardPseudoInstruction {
1285  let OutOperandList = (outs);
1286  let InOperandList = (ins variable_ops);
1287  let AsmString = "DBG_INSTR_REF";
1288  let hasSideEffects = false;
1289  let isMeta = true;
1290}
1291def DBG_PHI : StandardPseudoInstruction {
1292  let OutOperandList = (outs);
1293  let InOperandList = (ins variable_ops);
1294  let AsmString = "DBG_PHI";
1295  let hasSideEffects = 0;
1296  let isMeta = true;
1297}
1298def DBG_LABEL : StandardPseudoInstruction {
1299  let OutOperandList = (outs);
1300  let InOperandList = (ins unknown:$label);
1301  let AsmString = "DBG_LABEL";
1302  let hasSideEffects = false;
1303  let isMeta = true;
1304}
1305def REG_SEQUENCE : StandardPseudoInstruction {
1306  let OutOperandList = (outs unknown:$dst);
1307  let InOperandList = (ins unknown:$supersrc, variable_ops);
1308  let AsmString = "";
1309  let hasSideEffects = false;
1310  let isAsCheapAsAMove = true;
1311}
1312def COPY : StandardPseudoInstruction {
1313  let OutOperandList = (outs unknown:$dst);
1314  let InOperandList = (ins unknown:$src);
1315  let AsmString = "";
1316  let hasSideEffects = false;
1317  let isAsCheapAsAMove = true;
1318  let hasNoSchedulingInfo = false;
1319}
1320def BUNDLE : StandardPseudoInstruction {
1321  let OutOperandList = (outs);
1322  let InOperandList = (ins variable_ops);
1323  let AsmString = "BUNDLE";
1324  let hasSideEffects = false;
1325}
1326def LIFETIME_START : StandardPseudoInstruction {
1327  let OutOperandList = (outs);
1328  let InOperandList = (ins i32imm:$id);
1329  let AsmString = "LIFETIME_START";
1330  let hasSideEffects = false;
1331  let isMeta = true;
1332}
1333def LIFETIME_END : StandardPseudoInstruction {
1334  let OutOperandList = (outs);
1335  let InOperandList = (ins i32imm:$id);
1336  let AsmString = "LIFETIME_END";
1337  let hasSideEffects = false;
1338  let isMeta = true;
1339}
1340def PSEUDO_PROBE : StandardPseudoInstruction {
1341  let OutOperandList = (outs);
1342  let InOperandList = (ins i64imm:$guid, i64imm:$index, i8imm:$type, i32imm:$attr);
1343  let AsmString = "PSEUDO_PROBE";
1344  let hasSideEffects = 1;
1345  let isMeta = true;
1346}
1347def ARITH_FENCE : StandardPseudoInstruction {
1348  let OutOperandList = (outs unknown:$dst);
1349  let InOperandList = (ins unknown:$src);
1350  let AsmString = "";
1351  let hasSideEffects = false;
1352  let Constraints = "$src = $dst";
1353  let isMeta = true;
1354}
1355
1356def STACKMAP : StandardPseudoInstruction {
1357  let OutOperandList = (outs);
1358  let InOperandList = (ins i64imm:$id, i32imm:$nbytes, variable_ops);
1359  let hasSideEffects = true;
1360  let isCall = true;
1361  let mayLoad = true;
1362  let usesCustomInserter = true;
1363}
1364def PATCHPOINT : StandardPseudoInstruction {
1365  let OutOperandList = (outs unknown:$dst);
1366  let InOperandList = (ins i64imm:$id, i32imm:$nbytes, unknown:$callee,
1367                       i32imm:$nargs, i32imm:$cc, variable_ops);
1368  let hasSideEffects = true;
1369  let isCall = true;
1370  let mayLoad = true;
1371  let usesCustomInserter = true;
1372}
1373def STATEPOINT : StandardPseudoInstruction {
1374  let OutOperandList = (outs variable_ops);
1375  let InOperandList = (ins variable_ops);
1376  let usesCustomInserter = true;
1377  let mayLoad = true;
1378  let mayStore = true;
1379  let hasSideEffects = true;
1380  let isCall = true;
1381}
1382def LOAD_STACK_GUARD : StandardPseudoInstruction {
1383  let OutOperandList = (outs ptr_rc:$dst);
1384  let InOperandList = (ins);
1385  let mayLoad = true;
1386  bit isReMaterializable = true;
1387  let hasSideEffects = false;
1388  bit isPseudo = true;
1389}
1390def PREALLOCATED_SETUP : StandardPseudoInstruction {
1391  let OutOperandList = (outs);
1392  let InOperandList = (ins i32imm:$a);
1393  let usesCustomInserter = true;
1394  let hasSideEffects = true;
1395}
1396def PREALLOCATED_ARG : StandardPseudoInstruction {
1397  let OutOperandList = (outs ptr_rc:$loc);
1398  let InOperandList = (ins i32imm:$a, i32imm:$b);
1399  let usesCustomInserter = true;
1400  let hasSideEffects = true;
1401}
1402def LOCAL_ESCAPE : StandardPseudoInstruction {
1403  // This instruction is really just a label. It has to be part of the chain so
1404  // that it doesn't get dropped from the DAG, but it produces nothing and has
1405  // no side effects.
1406  let OutOperandList = (outs);
1407  let InOperandList = (ins ptr_rc:$symbol, i32imm:$id);
1408  let hasSideEffects = false;
1409  let hasCtrlDep = true;
1410}
1411def FAULTING_OP : StandardPseudoInstruction {
1412  let OutOperandList = (outs unknown:$dst);
1413  let InOperandList = (ins variable_ops);
1414  let usesCustomInserter = true;
1415  let hasSideEffects = true;
1416  let mayLoad = true;
1417  let mayStore = true;
1418  let isTerminator = true;
1419  let isBranch = true;
1420}
1421def PATCHABLE_OP : StandardPseudoInstruction {
1422  let OutOperandList = (outs);
1423  let InOperandList = (ins variable_ops);
1424  let usesCustomInserter = true;
1425  let mayLoad = true;
1426  let mayStore = true;
1427  let hasSideEffects = true;
1428}
1429def PATCHABLE_FUNCTION_ENTER : StandardPseudoInstruction {
1430  let OutOperandList = (outs);
1431  let InOperandList = (ins);
1432  let AsmString = "# XRay Function Enter.";
1433  let usesCustomInserter = true;
1434  let hasSideEffects = true;
1435}
1436def PATCHABLE_RET : StandardPseudoInstruction {
1437  let OutOperandList = (outs);
1438  let InOperandList = (ins variable_ops);
1439  let AsmString = "# XRay Function Patchable RET.";
1440  let usesCustomInserter = true;
1441  let hasSideEffects = true;
1442  let isTerminator = true;
1443  let isReturn = true;
1444}
1445def PATCHABLE_FUNCTION_EXIT : StandardPseudoInstruction {
1446  let OutOperandList = (outs);
1447  let InOperandList = (ins);
1448  let AsmString = "# XRay Function Exit.";
1449  let usesCustomInserter = true;
1450  let hasSideEffects = true;
1451  let isReturn = false; // Original return instruction will follow
1452}
1453def PATCHABLE_TAIL_CALL : StandardPseudoInstruction {
1454  let OutOperandList = (outs);
1455  let InOperandList = (ins variable_ops);
1456  let AsmString = "# XRay Tail Call Exit.";
1457  let usesCustomInserter = true;
1458  let hasSideEffects = true;
1459  let isReturn = true;
1460}
1461def PATCHABLE_EVENT_CALL : StandardPseudoInstruction {
1462  let OutOperandList = (outs);
1463  let InOperandList = (ins ptr_rc:$event, unknown:$size);
1464  let AsmString = "# XRay Custom Event Log.";
1465  let usesCustomInserter = true;
1466  let isCall = true;
1467  let mayLoad = true;
1468  let mayStore = true;
1469  let hasSideEffects = true;
1470}
1471def PATCHABLE_TYPED_EVENT_CALL : StandardPseudoInstruction {
1472  let OutOperandList = (outs);
1473  let InOperandList = (ins unknown:$type, ptr_rc:$event, unknown:$size);
1474  let AsmString = "# XRay Typed Event Log.";
1475  let usesCustomInserter = true;
1476  let isCall = true;
1477  let mayLoad = true;
1478  let mayStore = true;
1479  let hasSideEffects = true;
1480}
1481def FENTRY_CALL : StandardPseudoInstruction {
1482  let OutOperandList = (outs);
1483  let InOperandList = (ins);
1484  let AsmString = "# FEntry call";
1485  let usesCustomInserter = true;
1486  let isCall = true;
1487  let mayLoad = true;
1488  let mayStore = true;
1489  let hasSideEffects = true;
1490}
1491def ICALL_BRANCH_FUNNEL : StandardPseudoInstruction {
1492  let OutOperandList = (outs);
1493  let InOperandList = (ins variable_ops);
1494  let AsmString = "";
1495  let hasSideEffects = true;
1496}
1497def MEMBARRIER : StandardPseudoInstruction {
1498  let OutOperandList = (outs);
1499  let InOperandList = (ins);
1500  let AsmString = "";
1501  let hasSideEffects = true;
1502  let Size = 0;
1503  let isMeta = true;
1504}
1505def JUMP_TABLE_DEBUG_INFO : StandardPseudoInstruction {
1506  let OutOperandList = (outs);
1507  let InOperandList = (ins i64imm:$jti);
1508  let AsmString = "";
1509  let hasSideEffects = false;
1510  let Size = 0;
1511  let isMeta = true;
1512}
1513
1514let hasSideEffects = false, isMeta = true, isConvergent = true in {
1515def CONVERGENCECTRL_ANCHOR : StandardPseudoInstruction {
1516  let OutOperandList = (outs unknown:$dst);
1517  let InOperandList = (ins);
1518}
1519def CONVERGENCECTRL_ENTRY : StandardPseudoInstruction {
1520  let OutOperandList = (outs unknown:$dst);
1521  let InOperandList = (ins);
1522}
1523def CONVERGENCECTRL_LOOP : StandardPseudoInstruction {
1524  let OutOperandList = (outs unknown:$dst);
1525  let InOperandList = (ins unknown:$src);
1526}
1527def CONVERGENCECTRL_GLUE : StandardPseudoInstruction {
1528  let OutOperandList = (outs);
1529  let InOperandList = (ins unknown:$src);
1530}
1531}
1532
1533// Generic opcodes used in GlobalISel.
1534include "llvm/Target/GenericOpcodes.td"
1535
1536//===----------------------------------------------------------------------===//
1537// AsmParser - This class can be implemented by targets that wish to implement
1538// .s file parsing.
1539//
1540// Subtargets can have multiple different assembly parsers (e.g. AT&T vs Intel
1541// syntax on X86 for example).
1542//
1543class AsmParser {
1544  // AsmParserClassName - This specifies the suffix to use for the asmparser
1545  // class.  Generated AsmParser classes are always prefixed with the target
1546  // name.
1547  string AsmParserClassName  = "AsmParser";
1548
1549  // AsmParserInstCleanup - If non-empty, this is the name of a custom member
1550  // function of the AsmParser class to call on every matched instruction.
1551  // This can be used to perform target specific instruction post-processing.
1552  string AsmParserInstCleanup  = "";
1553
1554  // ShouldEmitMatchRegisterName - Set to false if the target needs a hand
1555  // written register name matcher
1556  bit ShouldEmitMatchRegisterName = true;
1557
1558  // Set to true if the target needs a generated 'alternative register name'
1559  // matcher.
1560  //
1561  // This generates a function which can be used to lookup registers from
1562  // their aliases. This function will fail when called on targets where
1563  // several registers share the same alias (i.e. not a 1:1 mapping).
1564  bit ShouldEmitMatchRegisterAltName = false;
1565
1566  // Set to true if MatchRegisterName and MatchRegisterAltName functions
1567  // should be generated even if there are duplicate register names. The
1568  // target is responsible for coercing aliased registers as necessary
1569  // (e.g. in validateTargetOperandClass), and there are no guarantees about
1570  // which numeric register identifier will be returned in the case of
1571  // multiple matches.
1572  bit AllowDuplicateRegisterNames = false;
1573
1574  // HasMnemonicFirst - Set to false if target instructions don't always
1575  // start with a mnemonic as the first token.
1576  bit HasMnemonicFirst = true;
1577
1578  // ReportMultipleNearMisses -
1579  // When 0, the assembly matcher reports an error for one encoding or operand
1580  // that did not match the parsed instruction.
1581  // When 1, the assembly matcher returns a list of encodings that were close
1582  // to matching the parsed instruction, so to allow more detailed error
1583  // messages.
1584  bit ReportMultipleNearMisses = false;
1585
1586  // OperandParserMethod - If non-empty, this is the name of a custom
1587  // member function of the AsmParser class to call for every instruction
1588  // operand to be parsed.
1589  string OperandParserMethod = "";
1590
1591  // CallCustomParserForAllOperands - Set to true if the custom parser
1592  // method shall be called for all operands as opposed to only those
1593  // that have their own specified custom parsers.
1594  bit CallCustomParserForAllOperands = false;
1595
1596  // PreferSmallerInstructions - Should the assembly matcher prefer the smaller
1597  // instructions.
1598  //
1599  // This is useful for the ARM instructions set where smaller encodings must
1600  // be preferentially selected.
1601  //
1602  // The preference order is:
1603  //    Instrution size (if this option is enabled, smallest first)
1604  //    Number of Operands (least first),
1605  //    Operand Classes (lexicographically by operand),
1606  //    (Optional) Instruction id (see AsmMatcherEmitter.cpp for details),
1607  //    Number of required features (least first)
1608  bit PreferSmallerInstructions = false;
1609}
1610def DefaultAsmParser : AsmParser;
1611
1612//===----------------------------------------------------------------------===//
1613// AsmParserVariant - Subtargets can have multiple different assembly parsers
1614// (e.g. AT&T vs Intel syntax on X86 for example). This class can be
1615// implemented by targets to describe such variants.
1616//
1617class AsmParserVariant {
1618  // Variant - AsmParsers can be of multiple different variants.  Variants are
1619  // used to support targets that need to parse multiple formats for the
1620  // assembly language.
1621  int Variant = 0;
1622
1623  // Name - The AsmParser variant name (e.g., AT&T vs Intel).
1624  string Name = "";
1625
1626  // CommentDelimiter - If given, the delimiter string used to recognize
1627  // comments which are hard coded in the .td assembler strings for individual
1628  // instructions.
1629  string CommentDelimiter = "";
1630
1631  // RegisterPrefix - If given, the token prefix which indicates a register
1632  // token. This is used by the matcher to automatically recognize hard coded
1633  // register tokens as constrained registers, instead of tokens, for the
1634  // purposes of matching.
1635  string RegisterPrefix = "";
1636
1637  // TokenizingCharacters - Characters that are standalone tokens
1638  string TokenizingCharacters = "[]*!";
1639
1640  // SeparatorCharacters - Characters that are not tokens
1641  string SeparatorCharacters = " \t,";
1642
1643  // BreakCharacters - Characters that start new identifiers
1644  string BreakCharacters = "";
1645}
1646def DefaultAsmParserVariant : AsmParserVariant;
1647
1648// Operators for combining SubtargetFeatures in AssemblerPredicates
1649def any_of;
1650def all_of;
1651
1652/// AssemblerPredicate - This is a Predicate that can be used when the assembler
1653/// matches instructions and aliases.
1654class AssemblerPredicate<dag cond, string name = ""> {
1655  bit AssemblerMatcherPredicate = true;
1656  dag AssemblerCondDag = cond;
1657  string PredicateName = name;
1658}
1659
1660/// TokenAlias - This class allows targets to define assembler token
1661/// operand aliases. That is, a token literal operand which is equivalent
1662/// to another, canonical, token literal. For example, ARM allows:
1663///   vmov.u32 s4, #0  -> vmov.i32, #0
1664/// 'u32' is a more specific designator for the 32-bit integer type specifier
1665/// and is legal for any instruction which accepts 'i32' as a datatype suffix.
1666///   def : TokenAlias<".u32", ".i32">;
1667///
1668/// This works by marking the match class of 'From' as a subclass of the
1669/// match class of 'To'.
1670class TokenAlias<string From, string To> {
1671  string FromToken = From;
1672  string ToToken = To;
1673}
1674
1675/// MnemonicAlias - This class allows targets to define assembler mnemonic
1676/// aliases.  This should be used when all forms of one mnemonic are accepted
1677/// with a different mnemonic.  For example, X86 allows:
1678///   sal %al, 1    -> shl %al, 1
1679///   sal %ax, %cl  -> shl %ax, %cl
1680///   sal %eax, %cl -> shl %eax, %cl
1681/// etc.  Though "sal" is accepted with many forms, all of them are directly
1682/// translated to a shl, so it can be handled with (in the case of X86, it
1683/// actually has one for each suffix as well):
1684///   def : MnemonicAlias<"sal", "shl">;
1685///
1686/// Mnemonic aliases are mapped before any other translation in the match phase,
1687/// and do allow Requires predicates, e.g.:
1688///
1689///  def : MnemonicAlias<"pushf", "pushfq">, Requires<[In64BitMode]>;
1690///  def : MnemonicAlias<"pushf", "pushfl">, Requires<[In32BitMode]>;
1691///
1692/// Mnemonic aliases can also be constrained to specific variants, e.g.:
1693///
1694///  def : MnemonicAlias<"pushf", "pushfq", "att">, Requires<[In64BitMode]>;
1695///
1696/// If no variant (e.g., "att" or "intel") is specified then the alias is
1697/// applied unconditionally.
1698class MnemonicAlias<string From, string To, string VariantName = ""> {
1699  string FromMnemonic = From;
1700  string ToMnemonic = To;
1701  string AsmVariantName = VariantName;
1702
1703  // Predicates - Predicates that must be true for this remapping to happen.
1704  list<Predicate> Predicates = [];
1705}
1706
1707/// InstAlias - This defines an alternate assembly syntax that is allowed to
1708/// match an instruction that has a different (more canonical) assembly
1709/// representation.
1710class InstAlias<string Asm, dag Result, int Emit = 1, string VariantName = ""> {
1711  string AsmString = Asm;      // The .s format to match the instruction with.
1712  dag ResultInst = Result;     // The MCInst to generate.
1713
1714  // This determines which order the InstPrinter detects aliases for
1715  // printing. A larger value makes the alias more likely to be
1716  // emitted. The Instruction's own definition is notionally 0.5, so 0
1717  // disables printing and 1 enables it if there are no conflicting aliases.
1718  int EmitPriority = Emit;
1719
1720  // Predicates - Predicates that must be true for this to match.
1721  list<Predicate> Predicates = [];
1722
1723  // If the instruction specified in Result has defined an AsmMatchConverter
1724  // then setting this to 1 will cause the alias to use the AsmMatchConverter
1725  // function when converting the OperandVector into an MCInst instead of the
1726  // function that is generated by the dag Result.
1727  // Setting this to 0 will cause the alias to ignore the Result instruction's
1728  // defined AsmMatchConverter and instead use the function generated by the
1729  // dag Result.
1730  bit UseInstAsmMatchConverter = true;
1731
1732  // Assembler variant name to use for this alias. If not specified then
1733  // assembler variants will be determined based on AsmString
1734  string AsmVariantName = VariantName;
1735}
1736
1737//===----------------------------------------------------------------------===//
1738// AsmWriter - This class can be implemented by targets that need to customize
1739// the format of the .s file writer.
1740//
1741// Subtargets can have multiple different asmwriters (e.g. AT&T vs Intel syntax
1742// on X86 for example).
1743//
1744class AsmWriter {
1745  // AsmWriterClassName - This specifies the suffix to use for the asmwriter
1746  // class.  Generated AsmWriter classes are always prefixed with the target
1747  // name.
1748  string AsmWriterClassName  = "InstPrinter";
1749
1750  // PassSubtarget - Determines whether MCSubtargetInfo should be passed to
1751  // the various print methods.
1752  // FIXME: Remove after all ports are updated.
1753  int PassSubtarget = 0;
1754
1755  // Variant - AsmWriters can be of multiple different variants.  Variants are
1756  // used to support targets that need to emit assembly code in ways that are
1757  // mostly the same for different targets, but have minor differences in
1758  // syntax.  If the asmstring contains {|} characters in them, this integer
1759  // will specify which alternative to use.  For example "{x|y|z}" with Variant
1760  // == 1, will expand to "y".
1761  int Variant = 0;
1762}
1763def DefaultAsmWriter : AsmWriter;
1764
1765
1766//===----------------------------------------------------------------------===//
1767// Target - This class contains the "global" target information
1768//
1769class Target {
1770  // InstructionSet - Instruction set description for this target.
1771  InstrInfo InstructionSet;
1772
1773  // AssemblyParsers - The AsmParser instances available for this target.
1774  list<AsmParser> AssemblyParsers = [DefaultAsmParser];
1775
1776  /// AssemblyParserVariants - The AsmParserVariant instances available for
1777  /// this target.
1778  list<AsmParserVariant> AssemblyParserVariants = [DefaultAsmParserVariant];
1779
1780  // AssemblyWriters - The AsmWriter instances available for this target.
1781  list<AsmWriter> AssemblyWriters = [DefaultAsmWriter];
1782
1783  // AllowRegisterRenaming - Controls whether this target allows
1784  // post-register-allocation renaming of registers.  This is done by
1785  // setting hasExtraDefRegAllocReq and hasExtraSrcRegAllocReq to 1
1786  // for all opcodes if this flag is set to 0.
1787  int AllowRegisterRenaming = 0;
1788}
1789
1790//===----------------------------------------------------------------------===//
1791// Processor chip sets - These values represent each of the chip sets supported
1792// by the scheduler.  Each Processor definition requires corresponding
1793// instruction itineraries.
1794//
1795class Processor<string n, ProcessorItineraries pi, list<SubtargetFeature> f,
1796                list<SubtargetFeature> tunef = []> {
1797  // Name - Chip set name.  Used by command line (-mcpu=) to determine the
1798  // appropriate target chip.
1799  //
1800  string Name = n;
1801
1802  // SchedModel - The machine model for scheduling and instruction cost.
1803  //
1804  SchedMachineModel SchedModel = NoSchedModel;
1805
1806  // ProcItin - The scheduling information for the target processor.
1807  //
1808  ProcessorItineraries ProcItin = pi;
1809
1810  // Features - list of
1811  list<SubtargetFeature> Features = f;
1812
1813  // TuneFeatures - list of features for tuning for this CPU. If the target
1814  // supports -mtune, this should contain the list of features used to make
1815  // microarchitectural optimization decisions for a given processor.  While
1816  // Features should contain the architectural features for the processor.
1817  list<SubtargetFeature> TuneFeatures = tunef;
1818}
1819
1820// ProcessorModel allows subtargets to specify the more general
1821// SchedMachineModel instead if a ProcessorItinerary. Subtargets will
1822// gradually move to this newer form.
1823//
1824// Although this class always passes NoItineraries to the Processor
1825// class, the SchedMachineModel may still define valid Itineraries.
1826class ProcessorModel<string n, SchedMachineModel m, list<SubtargetFeature> f,
1827                     list<SubtargetFeature> tunef = []>
1828  : Processor<n, NoItineraries, f, tunef> {
1829  let SchedModel = m;
1830}
1831
1832//===----------------------------------------------------------------------===//
1833// InstrMapping - This class is used to create mapping tables to relate
1834// instructions with each other based on the values specified in RowFields,
1835// ColFields, KeyCol and ValueCols.
1836//
1837class InstrMapping {
1838  // FilterClass - Used to limit search space only to the instructions that
1839  // define the relationship modeled by this InstrMapping record.
1840  string FilterClass;
1841
1842  // RowFields - List of fields/attributes that should be same for all the
1843  // instructions in a row of the relation table. Think of this as a set of
1844  // properties shared by all the instructions related by this relationship
1845  // model and is used to categorize instructions into subgroups. For instance,
1846  // if we want to define a relation that maps 'Add' instruction to its
1847  // predicated forms, we can define RowFields like this:
1848  //
1849  // let RowFields = BaseOp
1850  // All add instruction predicated/non-predicated will have to set their BaseOp
1851  // to the same value.
1852  //
1853  // def Add: { let BaseOp = 'ADD'; let predSense = 'nopred' }
1854  // def Add_predtrue: { let BaseOp = 'ADD'; let predSense = 'true' }
1855  // def Add_predfalse: { let BaseOp = 'ADD'; let predSense = 'false'  }
1856  list<string> RowFields = [];
1857
1858  // List of fields/attributes that are same for all the instructions
1859  // in a column of the relation table.
1860  // Ex: let ColFields = 'predSense' -- It means that the columns are arranged
1861  // based on the 'predSense' values. All the instruction in a specific
1862  // column have the same value and it is fixed for the column according
1863  // to the values set in 'ValueCols'.
1864  list<string> ColFields = [];
1865
1866  // Values for the fields/attributes listed in 'ColFields'.
1867  // Ex: let KeyCol = 'nopred' -- It means that the key instruction (instruction
1868  // that models this relation) should be non-predicated.
1869  // In the example above, 'Add' is the key instruction.
1870  list<string> KeyCol = [];
1871
1872  // List of values for the fields/attributes listed in 'ColFields', one for
1873  // each column in the relation table.
1874  //
1875  // Ex: let ValueCols = [['true'],['false']] -- It adds two columns in the
1876  // table. First column requires all the instructions to have predSense
1877  // set to 'true' and second column requires it to be 'false'.
1878  list<list<string> > ValueCols = [];
1879}
1880
1881//===----------------------------------------------------------------------===//
1882// Pull in the common support for calling conventions.
1883//
1884include "llvm/Target/TargetCallingConv.td"
1885
1886//===----------------------------------------------------------------------===//
1887// Pull in the common support for DAG isel generation.
1888//
1889include "llvm/Target/TargetSelectionDAG.td"
1890
1891//===----------------------------------------------------------------------===//
1892// Pull in the common support for Global ISel register bank info generation.
1893//
1894include "llvm/Target/GlobalISel/RegisterBank.td"
1895
1896//===----------------------------------------------------------------------===//
1897// Pull in the common support for DAG isel generation.
1898//
1899include "llvm/Target/GlobalISel/Target.td"
1900
1901//===----------------------------------------------------------------------===//
1902// Pull in the common support for the Global ISel DAG-based selector generation.
1903//
1904include "llvm/Target/GlobalISel/SelectionDAGCompat.td"
1905
1906//===----------------------------------------------------------------------===//
1907// Pull in the common support for Pfm Counters generation.
1908//
1909include "llvm/Target/TargetPfmCounters.td"
1910
1911//===----------------------------------------------------------------------===//
1912// Pull in the common support for macro fusion.
1913//
1914include "llvm/Target/TargetMacroFusion.td"
1915