]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/include/llvm/Target/Target.td
MFC r234353:
[FreeBSD/stable/9.git] / contrib / llvm / include / llvm / Target / Target.td
1 //===- Target.td - Target Independent TableGen interface ---*- 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 file defines the target-independent interfaces which should be
11 // implemented by each target which is using a TableGen based code generator.
12 //
13 //===----------------------------------------------------------------------===//
14
15 // Include all information about LLVM intrinsics.
16 include "llvm/Intrinsics.td"
17
18 //===----------------------------------------------------------------------===//
19 // Register file description - These classes are used to fill in the target
20 // description classes.
21
22 class RegisterClass; // Forward def
23
24 // SubRegIndex - Use instances of SubRegIndex to identify subregisters.
25 class SubRegIndex<list<SubRegIndex> comps = []> {
26   string Namespace = "";
27
28   // ComposedOf - A list of two SubRegIndex instances, [A, B].
29   // This indicates that this SubRegIndex is the result of composing A and B.
30   list<SubRegIndex> ComposedOf = comps;
31 }
32
33 // RegAltNameIndex - The alternate name set to use for register operands of
34 // this register class when printing.
35 class RegAltNameIndex {
36   string Namespace = "";
37 }
38 def NoRegAltName : RegAltNameIndex;
39
40 // Register - You should define one instance of this class for each register
41 // in the target machine.  String n will become the "name" of the register.
42 class Register<string n, list<string> altNames = []> {
43   string Namespace = "";
44   string AsmName = n;
45   list<string> AltNames = altNames;
46
47   // Aliases - A list of registers that this register overlaps with.  A read or
48   // modification of this register can potentially read or modify the aliased
49   // registers.
50   list<Register> Aliases = [];
51
52   // SubRegs - A list of registers that are parts of this register. Note these
53   // are "immediate" sub-registers and the registers within the list do not
54   // themselves overlap. e.g. For X86, EAX's SubRegs list contains only [AX],
55   // not [AX, AH, AL].
56   list<Register> SubRegs = [];
57
58   // SubRegIndices - For each register in SubRegs, specify the SubRegIndex used
59   // to address it. Sub-sub-register indices are automatically inherited from
60   // SubRegs.
61   list<SubRegIndex> SubRegIndices = [];
62
63   // RegAltNameIndices - The alternate name indices which are valid for this
64   // register.
65   list<RegAltNameIndex> RegAltNameIndices = [];
66
67   // CompositeIndices - Specify subreg indices that don't correspond directly to
68   // a register in SubRegs and are not inherited. The following formats are
69   // supported:
70   //
71   // (a)     Identity  - Reg:a == Reg
72   // (a b)   Alias     - Reg:a == Reg:b
73   // (a b,c) Composite - Reg:a == (Reg:b):c
74   //
75   // This can be used to disambiguate a sub-sub-register that exists in more
76   // than one subregister and other weird stuff.
77   list<dag> CompositeIndices = [];
78
79   // DwarfNumbers - Numbers used internally by gcc/gdb to identify the register.
80   // These values can be determined by locating the <target>.h file in the
81   // directory llvmgcc/gcc/config/<target>/ and looking for REGISTER_NAMES.  The
82   // order of these names correspond to the enumeration used by gcc.  A value of
83   // -1 indicates that the gcc number is undefined and -2 that register number
84   // is invalid for this mode/flavour.
85   list<int> DwarfNumbers = [];
86
87   // CostPerUse - Additional cost of instructions using this register compared
88   // to other registers in its class. The register allocator will try to
89   // minimize the number of instructions using a register with a CostPerUse.
90   // This is used by the x86-64 and ARM Thumb targets where some registers
91   // require larger instruction encodings.
92   int CostPerUse = 0;
93
94   // CoveredBySubRegs - When this bit is set, the value of this register is
95   // completely determined by the value of its sub-registers.  For example, the
96   // x86 register AX is covered by its sub-registers AL and AH, but EAX is not
97   // covered by its sub-register AX.
98   bit CoveredBySubRegs = 0;
99 }
100
101 // RegisterWithSubRegs - This can be used to define instances of Register which
102 // need to specify sub-registers.
103 // List "subregs" specifies which registers are sub-registers to this one. This
104 // is used to populate the SubRegs and AliasSet fields of TargetRegisterDesc.
105 // This allows the code generator to be careful not to put two values with
106 // overlapping live ranges into registers which alias.
107 class RegisterWithSubRegs<string n, list<Register> subregs> : Register<n> {
108   let SubRegs = subregs;
109 }
110
111 // RegisterClass - Now that all of the registers are defined, and aliases
112 // between registers are defined, specify which registers belong to which
113 // register classes.  This also defines the default allocation order of
114 // registers by register allocators.
115 //
116 class RegisterClass<string namespace, list<ValueType> regTypes, int alignment,
117                     dag regList, RegAltNameIndex idx = NoRegAltName> {
118   string Namespace = namespace;
119
120   // RegType - Specify the list ValueType of the registers in this register
121   // class.  Note that all registers in a register class must have the same
122   // ValueTypes.  This is a list because some targets permit storing different
123   // types in same register, for example vector values with 128-bit total size,
124   // but different count/size of items, like SSE on x86.
125   //
126   list<ValueType> RegTypes = regTypes;
127
128   // Size - Specify the spill size in bits of the registers.  A default value of
129   // zero lets tablgen pick an appropriate size.
130   int Size = 0;
131
132   // Alignment - Specify the alignment required of the registers when they are
133   // stored or loaded to memory.
134   //
135   int Alignment = alignment;
136
137   // CopyCost - This value is used to specify the cost of copying a value
138   // between two registers in this register class. The default value is one
139   // meaning it takes a single instruction to perform the copying. A negative
140   // value means copying is extremely expensive or impossible.
141   int CopyCost = 1;
142
143   // MemberList - Specify which registers are in this class.  If the
144   // allocation_order_* method are not specified, this also defines the order of
145   // allocation used by the register allocator.
146   //
147   dag MemberList = regList;
148
149   // AltNameIndex - The alternate register name to use when printing operands
150   // of this register class. Every register in the register class must have
151   // a valid alternate name for the given index.
152   RegAltNameIndex altNameIndex = idx;
153
154   // SubRegClasses - Specify the register class of subregisters as a list of
155   // dags: (RegClass SubRegIndex, SubRegindex, ...)
156   list<dag> SubRegClasses = [];
157
158   // isAllocatable - Specify that the register class can be used for virtual
159   // registers and register allocation.  Some register classes are only used to
160   // model instruction operand constraints, and should have isAllocatable = 0.
161   bit isAllocatable = 1;
162
163   // AltOrders - List of alternative allocation orders. The default order is
164   // MemberList itself, and that is good enough for most targets since the
165   // register allocators automatically remove reserved registers and move
166   // callee-saved registers to the end.
167   list<dag> AltOrders = [];
168
169   // AltOrderSelect - The body of a function that selects the allocation order
170   // to use in a given machine function. The code will be inserted in a
171   // function like this:
172   //
173   //   static inline unsigned f(const MachineFunction &MF) { ... }
174   //
175   // The function should return 0 to select the default order defined by
176   // MemberList, 1 to select the first AltOrders entry and so on.
177   code AltOrderSelect = [{}];
178 }
179
180 // The memberList in a RegisterClass is a dag of set operations. TableGen
181 // evaluates these set operations and expand them into register lists. These
182 // are the most common operation, see test/TableGen/SetTheory.td for more
183 // examples of what is possible:
184 //
185 // (add R0, R1, R2) - Set Union. Each argument can be an individual register, a
186 // register class, or a sub-expression. This is also the way to simply list
187 // registers.
188 //
189 // (sub GPR, SP) - Set difference. Subtract the last arguments from the first.
190 //
191 // (and GPR, CSR) - Set intersection. All registers from the first set that are
192 // also in the second set.
193 //
194 // (sequence "R%u", 0, 15) -> [R0, R1, ..., R15]. Generate a sequence of
195 // numbered registers.
196 //
197 // (shl GPR, 4) - Remove the first N elements.
198 //
199 // (trunc GPR, 4) - Truncate after the first N elements.
200 //
201 // (rotl GPR, 1) - Rotate N places to the left.
202 //
203 // (rotr GPR, 1) - Rotate N places to the right.
204 //
205 // (decimate GPR, 2) - Pick every N'th element, starting with the first.
206 //
207 // (interleave A, B, ...) - Interleave the elements from each argument list.
208 //
209 // All of these operators work on ordered sets, not lists. That means
210 // duplicates are removed from sub-expressions.
211
212 // Set operators. The rest is defined in TargetSelectionDAG.td.
213 def sequence;
214 def decimate;
215 def interleave;
216
217 // RegisterTuples - Automatically generate super-registers by forming tuples of
218 // sub-registers. This is useful for modeling register sequence constraints
219 // with pseudo-registers that are larger than the architectural registers.
220 //
221 // The sub-register lists are zipped together:
222 //
223 //   def EvenOdd : RegisterTuples<[sube, subo], [(add R0, R2), (add R1, R3)]>;
224 //
225 // Generates the same registers as:
226 //
227 //   let SubRegIndices = [sube, subo] in {
228 //     def R0_R1 : RegisterWithSubRegs<"", [R0, R1]>;
229 //     def R2_R3 : RegisterWithSubRegs<"", [R2, R3]>;
230 //   }
231 //
232 // The generated pseudo-registers inherit super-classes and fields from their
233 // first sub-register. Most fields from the Register class are inferred, and
234 // the AsmName and Dwarf numbers are cleared.
235 //
236 // RegisterTuples instances can be used in other set operations to form
237 // register classes and so on. This is the only way of using the generated
238 // registers.
239 class RegisterTuples<list<SubRegIndex> Indices, list<dag> Regs> {
240   // SubRegs - N lists of registers to be zipped up. Super-registers are
241   // synthesized from the first element of each SubRegs list, the second
242   // element and so on.
243   list<dag> SubRegs = Regs;
244
245   // SubRegIndices - N SubRegIndex instances. This provides the names of the
246   // sub-registers in the synthesized super-registers.
247   list<SubRegIndex> SubRegIndices = Indices;
248
249   // Compose sub-register indices like in a normal Register.
250   list<dag> CompositeIndices = [];
251 }
252
253
254 //===----------------------------------------------------------------------===//
255 // DwarfRegNum - This class provides a mapping of the llvm register enumeration
256 // to the register numbering used by gcc and gdb.  These values are used by a
257 // debug information writer to describe where values may be located during
258 // execution.
259 class DwarfRegNum<list<int> Numbers> {
260   // DwarfNumbers - Numbers used internally by gcc/gdb to identify the register.
261   // These values can be determined by locating the <target>.h file in the
262   // directory llvmgcc/gcc/config/<target>/ and looking for REGISTER_NAMES.  The
263   // order of these names correspond to the enumeration used by gcc.  A value of
264   // -1 indicates that the gcc number is undefined and -2 that register number
265   // is invalid for this mode/flavour.
266   list<int> DwarfNumbers = Numbers;
267 }
268
269 // DwarfRegAlias - This class declares that a given register uses the same dwarf
270 // numbers as another one. This is useful for making it clear that the two
271 // registers do have the same number. It also lets us build a mapping
272 // from dwarf register number to llvm register.
273 class DwarfRegAlias<Register reg> {
274       Register DwarfAlias = reg;
275 }
276
277 //===----------------------------------------------------------------------===//
278 // Pull in the common support for scheduling
279 //
280 include "llvm/Target/TargetSchedule.td"
281
282 class Predicate; // Forward def
283
284 //===----------------------------------------------------------------------===//
285 // Instruction set description - These classes correspond to the C++ classes in
286 // the Target/TargetInstrInfo.h file.
287 //
288 class Instruction {
289   string Namespace = "";
290
291   dag OutOperandList;       // An dag containing the MI def operand list.
292   dag InOperandList;        // An dag containing the MI use operand list.
293   string AsmString = "";    // The .s format to print the instruction with.
294
295   // Pattern - Set to the DAG pattern for this instruction, if we know of one,
296   // otherwise, uninitialized.
297   list<dag> Pattern;
298
299   // The follow state will eventually be inferred automatically from the
300   // instruction pattern.
301
302   list<Register> Uses = []; // Default to using no non-operand registers
303   list<Register> Defs = []; // Default to modifying no non-operand registers
304
305   // Predicates - List of predicates which will be turned into isel matching
306   // code.
307   list<Predicate> Predicates = [];
308
309   // Size - Size of encoded instruction, or zero if the size cannot be determined
310   // from the opcode.
311   int Size = 0;
312
313   // DecoderNamespace - The "namespace" in which this instruction exists, on
314   // targets like ARM which multiple ISA namespaces exist.
315   string DecoderNamespace = "";
316
317   // Code size, for instruction selection.
318   // FIXME: What does this actually mean?
319   int CodeSize = 0;
320
321   // Added complexity passed onto matching pattern.
322   int AddedComplexity  = 0;
323
324   // These bits capture information about the high-level semantics of the
325   // instruction.
326   bit isReturn     = 0;     // Is this instruction a return instruction?
327   bit isBranch     = 0;     // Is this instruction a branch instruction?
328   bit isIndirectBranch = 0; // Is this instruction an indirect branch?
329   bit isCompare    = 0;     // Is this instruction a comparison instruction?
330   bit isMoveImm    = 0;     // Is this instruction a move immediate instruction?
331   bit isBitcast    = 0;     // Is this instruction a bitcast instruction?
332   bit isBarrier    = 0;     // Can control flow fall through this instruction?
333   bit isCall       = 0;     // Is this instruction a call instruction?
334   bit canFoldAsLoad = 0;    // Can this be folded as a simple memory operand?
335   bit mayLoad      = 0;     // Is it possible for this inst to read memory?
336   bit mayStore     = 0;     // Is it possible for this inst to write memory?
337   bit isConvertibleToThreeAddress = 0;  // Can this 2-addr instruction promote?
338   bit isCommutable = 0;     // Is this 3 operand instruction commutable?
339   bit isTerminator = 0;     // Is this part of the terminator for a basic block?
340   bit isReMaterializable = 0; // Is this instruction re-materializable?
341   bit isPredicable = 0;     // Is this instruction predicable?
342   bit hasDelaySlot = 0;     // Does this instruction have an delay slot?
343   bit usesCustomInserter = 0; // Pseudo instr needing special help.
344   bit hasPostISelHook = 0;  // To be *adjusted* after isel by target hook.
345   bit hasCtrlDep   = 0;     // Does this instruction r/w ctrl-flow chains?
346   bit isNotDuplicable = 0;  // Is it unsafe to duplicate this instruction?
347   bit isAsCheapAsAMove = 0; // As cheap (or cheaper) than a move instruction.
348   bit hasExtraSrcRegAllocReq = 0; // Sources have special regalloc requirement?
349   bit hasExtraDefRegAllocReq = 0; // Defs have special regalloc requirement?
350   bit isPseudo     = 0;     // Is this instruction a pseudo-instruction?
351                             // If so, won't have encoding information for
352                             // the [MC]CodeEmitter stuff.
353
354   // Side effect flags - When set, the flags have these meanings:
355   //
356   //  hasSideEffects - The instruction has side effects that are not
357   //    captured by any operands of the instruction or other flags.
358   //
359   //  neverHasSideEffects - Set on an instruction with no pattern if it has no
360   //    side effects.
361   bit hasSideEffects = 0;
362   bit neverHasSideEffects = 0;
363
364   // Is this instruction a "real" instruction (with a distinct machine
365   // encoding), or is it a pseudo instruction used for codegen modeling
366   // purposes.
367   // FIXME: For now this is distinct from isPseudo, above, as code-gen-only
368   // instructions can (and often do) still have encoding information
369   // associated with them. Once we've migrated all of them over to true
370   // pseudo-instructions that are lowered to real instructions prior to
371   // the printer/emitter, we can remove this attribute and just use isPseudo.
372   //
373   // The intended use is:
374   // isPseudo: Does not have encoding information and should be expanded,
375   //   at the latest, during lowering to MCInst.
376   //
377   // isCodeGenOnly: Does have encoding information and can go through to the
378   //   CodeEmitter unchanged, but duplicates a canonical instruction
379   //   definition's encoding and should be ignored when constructing the
380   //   assembler match tables.
381   bit isCodeGenOnly = 0;
382
383   // Is this instruction a pseudo instruction for use by the assembler parser.
384   bit isAsmParserOnly = 0;
385
386   InstrItinClass Itinerary = NoItinerary;// Execution steps used for scheduling.
387
388   string Constraints = "";  // OperandConstraint, e.g. $src = $dst.
389
390   /// DisableEncoding - List of operand names (e.g. "$op1,$op2") that should not
391   /// be encoded into the output machineinstr.
392   string DisableEncoding = "";
393
394   string PostEncoderMethod = "";
395   string DecoderMethod = "";
396
397   /// Target-specific flags. This becomes the TSFlags field in TargetInstrDesc.
398   bits<64> TSFlags = 0;
399
400   ///@name Assembler Parser Support
401   ///@{
402
403   string AsmMatchConverter = "";
404
405   ///@}
406 }
407
408 /// PseudoInstExpansion - Expansion information for a pseudo-instruction.
409 /// Which instruction it expands to and how the operands map from the
410 /// pseudo.
411 class PseudoInstExpansion<dag Result> {
412   dag ResultInst = Result;     // The instruction to generate.
413   bit isPseudo = 1;
414 }
415
416 /// Predicates - These are extra conditionals which are turned into instruction
417 /// selector matching code. Currently each predicate is just a string.
418 class Predicate<string cond> {
419   string CondString = cond;
420
421   /// AssemblerMatcherPredicate - If this feature can be used by the assembler
422   /// matcher, this is true.  Targets should set this by inheriting their
423   /// feature from the AssemblerPredicate class in addition to Predicate.
424   bit AssemblerMatcherPredicate = 0;
425
426   /// AssemblerCondString - Name of the subtarget feature being tested used
427   /// as alternative condition string used for assembler matcher.
428   /// e.g. "ModeThumb" is translated to "(Bits & ModeThumb) != 0".
429   ///      "!ModeThumb" is translated to "(Bits & ModeThumb) == 0".
430   /// It can also list multiple features separated by ",".
431   /// e.g. "ModeThumb,FeatureThumb2" is translated to
432   ///      "(Bits & ModeThumb) != 0 && (Bits & FeatureThumb2) != 0".
433   string AssemblerCondString = "";
434 }
435
436 /// NoHonorSignDependentRounding - This predicate is true if support for
437 /// sign-dependent-rounding is not enabled.
438 def NoHonorSignDependentRounding
439  : Predicate<"!TM.Options.HonorSignDependentRoundingFPMath()">;
440
441 class Requires<list<Predicate> preds> {
442   list<Predicate> Predicates = preds;
443 }
444
445 /// ops definition - This is just a simple marker used to identify the operand
446 /// list for an instruction. outs and ins are identical both syntactically and
447 /// semanticallyr; they are used to define def operands and use operands to
448 /// improve readibility. This should be used like this:
449 ///     (outs R32:$dst), (ins R32:$src1, R32:$src2) or something similar.
450 def ops;
451 def outs;
452 def ins;
453
454 /// variable_ops definition - Mark this instruction as taking a variable number
455 /// of operands.
456 def variable_ops;
457
458
459 /// PointerLikeRegClass - Values that are designed to have pointer width are
460 /// derived from this.  TableGen treats the register class as having a symbolic
461 /// type that it doesn't know, and resolves the actual regclass to use by using
462 /// the TargetRegisterInfo::getPointerRegClass() hook at codegen time.
463 class PointerLikeRegClass<int Kind> {
464   int RegClassKind = Kind;
465 }
466
467
468 /// ptr_rc definition - Mark this operand as being a pointer value whose
469 /// register class is resolved dynamically via a callback to TargetInstrInfo.
470 /// FIXME: We should probably change this to a class which contain a list of
471 /// flags. But currently we have but one flag.
472 def ptr_rc : PointerLikeRegClass<0>;
473
474 /// unknown definition - Mark this operand as being of unknown type, causing
475 /// it to be resolved by inference in the context it is used.
476 def unknown;
477
478 /// AsmOperandClass - Representation for the kinds of operands which the target
479 /// specific parser can create and the assembly matcher may need to distinguish.
480 ///
481 /// Operand classes are used to define the order in which instructions are
482 /// matched, to ensure that the instruction which gets matched for any
483 /// particular list of operands is deterministic.
484 ///
485 /// The target specific parser must be able to classify a parsed operand into a
486 /// unique class which does not partially overlap with any other classes. It can
487 /// match a subset of some other class, in which case the super class field
488 /// should be defined.
489 class AsmOperandClass {
490   /// The name to use for this class, which should be usable as an enum value.
491   string Name = ?;
492
493   /// The super classes of this operand.
494   list<AsmOperandClass> SuperClasses = [];
495
496   /// The name of the method on the target specific operand to call to test
497   /// whether the operand is an instance of this class. If not set, this will
498   /// default to "isFoo", where Foo is the AsmOperandClass name. The method
499   /// signature should be:
500   ///   bool isFoo() const;
501   string PredicateMethod = ?;
502
503   /// The name of the method on the target specific operand to call to add the
504   /// target specific operand to an MCInst. If not set, this will default to
505   /// "addFooOperands", where Foo is the AsmOperandClass name. The method
506   /// signature should be:
507   ///   void addFooOperands(MCInst &Inst, unsigned N) const;
508   string RenderMethod = ?;
509
510   /// The name of the method on the target specific operand to call to custom
511   /// handle the operand parsing. This is useful when the operands do not relate
512   /// to immediates or registers and are very instruction specific (as flags to
513   /// set in a processor register, coprocessor number, ...).
514   string ParserMethod = ?;
515 }
516
517 def ImmAsmOperand : AsmOperandClass {
518   let Name = "Imm";
519 }
520
521 /// Operand Types - These provide the built-in operand types that may be used
522 /// by a target.  Targets can optionally provide their own operand types as
523 /// needed, though this should not be needed for RISC targets.
524 class Operand<ValueType ty> {
525   ValueType Type = ty;
526   string PrintMethod = "printOperand";
527   string EncoderMethod = "";
528   string DecoderMethod = "";
529   string AsmOperandLowerMethod = ?;
530   string OperandType = "OPERAND_UNKNOWN";
531   dag MIOperandInfo = (ops);
532
533   // ParserMatchClass - The "match class" that operands of this type fit
534   // in. Match classes are used to define the order in which instructions are
535   // match, to ensure that which instructions gets matched is deterministic.
536   //
537   // The target specific parser must be able to classify an parsed operand into
538   // a unique class, which does not partially overlap with any other classes. It
539   // can match a subset of some other class, in which case the AsmOperandClass
540   // should declare the other operand as one of its super classes.
541   AsmOperandClass ParserMatchClass = ImmAsmOperand;
542 }
543
544 class RegisterOperand<RegisterClass regclass, string pm = "printOperand"> {
545   // RegClass - The register class of the operand.
546   RegisterClass RegClass = regclass;
547   // PrintMethod - The target method to call to print register operands of
548   // this type. The method normally will just use an alt-name index to look
549   // up the name to print. Default to the generic printOperand().
550   string PrintMethod = pm;
551   // ParserMatchClass - The "match class" that operands of this type fit
552   // in. Match classes are used to define the order in which instructions are
553   // match, to ensure that which instructions gets matched is deterministic.
554   //
555   // The target specific parser must be able to classify an parsed operand into
556   // a unique class, which does not partially overlap with any other classes. It
557   // can match a subset of some other class, in which case the AsmOperandClass
558   // should declare the other operand as one of its super classes.
559   AsmOperandClass ParserMatchClass;
560 }
561
562 let OperandType = "OPERAND_IMMEDIATE" in {
563 def i1imm  : Operand<i1>;
564 def i8imm  : Operand<i8>;
565 def i16imm : Operand<i16>;
566 def i32imm : Operand<i32>;
567 def i64imm : Operand<i64>;
568
569 def f32imm : Operand<f32>;
570 def f64imm : Operand<f64>;
571 }
572
573 /// zero_reg definition - Special node to stand for the zero register.
574 ///
575 def zero_reg;
576
577 /// PredicateOperand - This can be used to define a predicate operand for an
578 /// instruction.  OpTypes specifies the MIOperandInfo for the operand, and
579 /// AlwaysVal specifies the value of this predicate when set to "always
580 /// execute".
581 class PredicateOperand<ValueType ty, dag OpTypes, dag AlwaysVal>
582   : Operand<ty> {
583   let MIOperandInfo = OpTypes;
584   dag DefaultOps = AlwaysVal;
585 }
586
587 /// OptionalDefOperand - This is used to define a optional definition operand
588 /// for an instruction. DefaultOps is the register the operand represents if
589 /// none is supplied, e.g. zero_reg.
590 class OptionalDefOperand<ValueType ty, dag OpTypes, dag defaultops>
591   : Operand<ty> {
592   let MIOperandInfo = OpTypes;
593   dag DefaultOps = defaultops;
594 }
595
596
597 // InstrInfo - This class should only be instantiated once to provide parameters
598 // which are global to the target machine.
599 //
600 class InstrInfo {
601   // Target can specify its instructions in either big or little-endian formats.
602   // For instance, while both Sparc and PowerPC are big-endian platforms, the
603   // Sparc manual specifies its instructions in the format [31..0] (big), while
604   // PowerPC specifies them using the format [0..31] (little).
605   bit isLittleEndianEncoding = 0;
606 }
607
608 // Standard Pseudo Instructions.
609 // This list must match TargetOpcodes.h and CodeGenTarget.cpp.
610 // Only these instructions are allowed in the TargetOpcode namespace.
611 let isCodeGenOnly = 1, isPseudo = 1, Namespace = "TargetOpcode" in {
612 def PHI : Instruction {
613   let OutOperandList = (outs);
614   let InOperandList = (ins variable_ops);
615   let AsmString = "PHINODE";
616 }
617 def INLINEASM : Instruction {
618   let OutOperandList = (outs);
619   let InOperandList = (ins variable_ops);
620   let AsmString = "";
621   let neverHasSideEffects = 1;  // Note side effect is encoded in an operand.
622 }
623 def PROLOG_LABEL : Instruction {
624   let OutOperandList = (outs);
625   let InOperandList = (ins i32imm:$id);
626   let AsmString = "";
627   let hasCtrlDep = 1;
628   let isNotDuplicable = 1;
629 }
630 def EH_LABEL : Instruction {
631   let OutOperandList = (outs);
632   let InOperandList = (ins i32imm:$id);
633   let AsmString = "";
634   let hasCtrlDep = 1;
635   let isNotDuplicable = 1;
636 }
637 def GC_LABEL : Instruction {
638   let OutOperandList = (outs);
639   let InOperandList = (ins i32imm:$id);
640   let AsmString = "";
641   let hasCtrlDep = 1;
642   let isNotDuplicable = 1;
643 }
644 def KILL : Instruction {
645   let OutOperandList = (outs);
646   let InOperandList = (ins variable_ops);
647   let AsmString = "";
648   let neverHasSideEffects = 1;
649 }
650 def EXTRACT_SUBREG : Instruction {
651   let OutOperandList = (outs unknown:$dst);
652   let InOperandList = (ins unknown:$supersrc, i32imm:$subidx);
653   let AsmString = "";
654   let neverHasSideEffects = 1;
655 }
656 def INSERT_SUBREG : Instruction {
657   let OutOperandList = (outs unknown:$dst);
658   let InOperandList = (ins unknown:$supersrc, unknown:$subsrc, i32imm:$subidx);
659   let AsmString = "";
660   let neverHasSideEffects = 1;
661   let Constraints = "$supersrc = $dst";
662 }
663 def IMPLICIT_DEF : Instruction {
664   let OutOperandList = (outs unknown:$dst);
665   let InOperandList = (ins);
666   let AsmString = "";
667   let neverHasSideEffects = 1;
668   let isReMaterializable = 1;
669   let isAsCheapAsAMove = 1;
670 }
671 def SUBREG_TO_REG : Instruction {
672   let OutOperandList = (outs unknown:$dst);
673   let InOperandList = (ins unknown:$implsrc, unknown:$subsrc, i32imm:$subidx);
674   let AsmString = "";
675   let neverHasSideEffects = 1;
676 }
677 def COPY_TO_REGCLASS : Instruction {
678   let OutOperandList = (outs unknown:$dst);
679   let InOperandList = (ins unknown:$src, i32imm:$regclass);
680   let AsmString = "";
681   let neverHasSideEffects = 1;
682   let isAsCheapAsAMove = 1;
683 }
684 def DBG_VALUE : Instruction {
685   let OutOperandList = (outs);
686   let InOperandList = (ins variable_ops);
687   let AsmString = "DBG_VALUE";
688   let neverHasSideEffects = 1;
689 }
690 def REG_SEQUENCE : Instruction {
691   let OutOperandList = (outs unknown:$dst);
692   let InOperandList = (ins variable_ops);
693   let AsmString = "";
694   let neverHasSideEffects = 1;
695   let isAsCheapAsAMove = 1;
696 }
697 def COPY : Instruction {
698   let OutOperandList = (outs unknown:$dst);
699   let InOperandList = (ins unknown:$src);
700   let AsmString = "";
701   let neverHasSideEffects = 1;
702   let isAsCheapAsAMove = 1;
703 }
704 def BUNDLE : Instruction {
705   let OutOperandList = (outs);
706   let InOperandList = (ins variable_ops);
707   let AsmString = "BUNDLE";
708 }
709 }
710
711 //===----------------------------------------------------------------------===//
712 // AsmParser - This class can be implemented by targets that wish to implement
713 // .s file parsing.
714 //
715 // Subtargets can have multiple different assembly parsers (e.g. AT&T vs Intel
716 // syntax on X86 for example).
717 //
718 class AsmParser {
719   // AsmParserClassName - This specifies the suffix to use for the asmparser
720   // class.  Generated AsmParser classes are always prefixed with the target
721   // name.
722   string AsmParserClassName  = "AsmParser";
723
724   // AsmParserInstCleanup - If non-empty, this is the name of a custom member
725   // function of the AsmParser class to call on every matched instruction.
726   // This can be used to perform target specific instruction post-processing.
727   string AsmParserInstCleanup  = "";
728 }
729 def DefaultAsmParser : AsmParser;
730
731 //===----------------------------------------------------------------------===//
732 // AsmParserVariant - Subtargets can have multiple different assembly parsers 
733 // (e.g. AT&T vs Intel syntax on X86 for example). This class can be
734 // implemented by targets to describe such variants.
735 //
736 class AsmParserVariant {
737   // Variant - AsmParsers can be of multiple different variants.  Variants are
738   // used to support targets that need to parser multiple formats for the
739   // assembly language.
740   int Variant = 0;
741
742   // CommentDelimiter - If given, the delimiter string used to recognize
743   // comments which are hard coded in the .td assembler strings for individual
744   // instructions.
745   string CommentDelimiter = "";
746
747   // RegisterPrefix - If given, the token prefix which indicates a register
748   // token. This is used by the matcher to automatically recognize hard coded
749   // register tokens as constrained registers, instead of tokens, for the
750   // purposes of matching.
751   string RegisterPrefix = "";
752 }
753 def DefaultAsmParserVariant : AsmParserVariant;
754
755 /// AssemblerPredicate - This is a Predicate that can be used when the assembler
756 /// matches instructions and aliases.
757 class AssemblerPredicate<string cond> {
758   bit AssemblerMatcherPredicate = 1;
759   string AssemblerCondString = cond;
760 }
761
762 /// TokenAlias - This class allows targets to define assembler token
763 /// operand aliases. That is, a token literal operand which is equivalent
764 /// to another, canonical, token literal. For example, ARM allows:
765 ///   vmov.u32 s4, #0  -> vmov.i32, #0
766 /// 'u32' is a more specific designator for the 32-bit integer type specifier
767 /// and is legal for any instruction which accepts 'i32' as a datatype suffix.
768 ///   def : TokenAlias<".u32", ".i32">;
769 ///
770 /// This works by marking the match class of 'From' as a subclass of the
771 /// match class of 'To'.
772 class TokenAlias<string From, string To> {
773   string FromToken = From;
774   string ToToken = To;
775 }
776
777 /// MnemonicAlias - This class allows targets to define assembler mnemonic
778 /// aliases.  This should be used when all forms of one mnemonic are accepted
779 /// with a different mnemonic.  For example, X86 allows:
780 ///   sal %al, 1    -> shl %al, 1
781 ///   sal %ax, %cl  -> shl %ax, %cl
782 ///   sal %eax, %cl -> shl %eax, %cl
783 /// etc.  Though "sal" is accepted with many forms, all of them are directly
784 /// translated to a shl, so it can be handled with (in the case of X86, it
785 /// actually has one for each suffix as well):
786 ///   def : MnemonicAlias<"sal", "shl">;
787 ///
788 /// Mnemonic aliases are mapped before any other translation in the match phase,
789 /// and do allow Requires predicates, e.g.:
790 ///
791 ///  def : MnemonicAlias<"pushf", "pushfq">, Requires<[In64BitMode]>;
792 ///  def : MnemonicAlias<"pushf", "pushfl">, Requires<[In32BitMode]>;
793 ///
794 class MnemonicAlias<string From, string To> {
795   string FromMnemonic = From;
796   string ToMnemonic = To;
797
798   // Predicates - Predicates that must be true for this remapping to happen.
799   list<Predicate> Predicates = [];
800 }
801
802 /// InstAlias - This defines an alternate assembly syntax that is allowed to
803 /// match an instruction that has a different (more canonical) assembly
804 /// representation.
805 class InstAlias<string Asm, dag Result, bit Emit = 0b1> {
806   string AsmString = Asm;      // The .s format to match the instruction with.
807   dag ResultInst = Result;     // The MCInst to generate.
808   bit EmitAlias = Emit;        // Emit the alias instead of what's aliased.
809
810   // Predicates - Predicates that must be true for this to match.
811   list<Predicate> Predicates = [];
812 }
813
814 //===----------------------------------------------------------------------===//
815 // AsmWriter - This class can be implemented by targets that need to customize
816 // the format of the .s file writer.
817 //
818 // Subtargets can have multiple different asmwriters (e.g. AT&T vs Intel syntax
819 // on X86 for example).
820 //
821 class AsmWriter {
822   // AsmWriterClassName - This specifies the suffix to use for the asmwriter
823   // class.  Generated AsmWriter classes are always prefixed with the target
824   // name.
825   string AsmWriterClassName  = "AsmPrinter";
826
827   // Variant - AsmWriters can be of multiple different variants.  Variants are
828   // used to support targets that need to emit assembly code in ways that are
829   // mostly the same for different targets, but have minor differences in
830   // syntax.  If the asmstring contains {|} characters in them, this integer
831   // will specify which alternative to use.  For example "{x|y|z}" with Variant
832   // == 1, will expand to "y".
833   int Variant = 0;
834
835
836   // FirstOperandColumn/OperandSpacing - If the assembler syntax uses a columnar
837   // layout, the asmwriter can actually generate output in this columns (in
838   // verbose-asm mode).  These two values indicate the width of the first column
839   // (the "opcode" area) and the width to reserve for subsequent operands.  When
840   // verbose asm mode is enabled, operands will be indented to respect this.
841   int FirstOperandColumn = -1;
842
843   // OperandSpacing - Space between operand columns.
844   int OperandSpacing = -1;
845
846   // isMCAsmWriter - Is this assembly writer for an MC emitter? This controls
847   // generation of the printInstruction() method. For MC printers, it takes
848   // an MCInstr* operand, otherwise it takes a MachineInstr*.
849   bit isMCAsmWriter = 0;
850 }
851 def DefaultAsmWriter : AsmWriter;
852
853
854 //===----------------------------------------------------------------------===//
855 // Target - This class contains the "global" target information
856 //
857 class Target {
858   // InstructionSet - Instruction set description for this target.
859   InstrInfo InstructionSet;
860
861   // AssemblyParsers - The AsmParser instances available for this target.
862   list<AsmParser> AssemblyParsers = [DefaultAsmParser];
863
864   /// AssemblyParserVariants - The AsmParserVariant instances available for 
865   /// this target.
866   list<AsmParserVariant> AssemblyParserVariants = [DefaultAsmParserVariant];
867
868   // AssemblyWriters - The AsmWriter instances available for this target.
869   list<AsmWriter> AssemblyWriters = [DefaultAsmWriter];
870 }
871
872 //===----------------------------------------------------------------------===//
873 // SubtargetFeature - A characteristic of the chip set.
874 //
875 class SubtargetFeature<string n, string a,  string v, string d,
876                        list<SubtargetFeature> i = []> {
877   // Name - Feature name.  Used by command line (-mattr=) to determine the
878   // appropriate target chip.
879   //
880   string Name = n;
881
882   // Attribute - Attribute to be set by feature.
883   //
884   string Attribute = a;
885
886   // Value - Value the attribute to be set to by feature.
887   //
888   string Value = v;
889
890   // Desc - Feature description.  Used by command line (-mattr=) to display help
891   // information.
892   //
893   string Desc = d;
894
895   // Implies - Features that this feature implies are present. If one of those
896   // features isn't set, then this one shouldn't be set either.
897   //
898   list<SubtargetFeature> Implies = i;
899 }
900
901 //===----------------------------------------------------------------------===//
902 // Processor chip sets - These values represent each of the chip sets supported
903 // by the scheduler.  Each Processor definition requires corresponding
904 // instruction itineraries.
905 //
906 class Processor<string n, ProcessorItineraries pi, list<SubtargetFeature> f> {
907   // Name - Chip set name.  Used by command line (-mcpu=) to determine the
908   // appropriate target chip.
909   //
910   string Name = n;
911
912   // ProcItin - The scheduling information for the target processor.
913   //
914   ProcessorItineraries ProcItin = pi;
915
916   // Features - list of
917   list<SubtargetFeature> Features = f;
918 }
919
920 //===----------------------------------------------------------------------===//
921 // Pull in the common support for calling conventions.
922 //
923 include "llvm/Target/TargetCallingConv.td"
924
925 //===----------------------------------------------------------------------===//
926 // Pull in the common support for DAG isel generation.
927 //
928 include "llvm/Target/TargetSelectionDAG.td"