1 //===- Target.td - Target Independent TableGen interface ---*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the target-independent interfaces which should be
11 // implemented by each target which is using a TableGen based code generator.
13 //===----------------------------------------------------------------------===//
15 // Include all information about LLVM intrinsics.
16 include "llvm/IR/Intrinsics.td"
18 //===----------------------------------------------------------------------===//
19 // Register file description - These classes are used to fill in the target
20 // description classes.
22 class RegisterClass; // Forward def
24 // SubRegIndex - Use instances of SubRegIndex to identify subregisters.
25 class SubRegIndex<int size, int offset = 0> {
26 string Namespace = "";
28 // Size - Size (in bits) of the sub-registers represented by this index.
31 // Offset - Offset of the first bit that is part of this sub-register index.
32 // Set it to -1 if the same index is used to represent sub-registers that can
33 // be at different offsets (for example when using an index to access an
34 // element in a register tuple).
37 // ComposedOf - A list of two SubRegIndex instances, [A, B].
38 // This indicates that this SubRegIndex is the result of composing A and B.
39 // See ComposedSubRegIndex.
40 list<SubRegIndex> ComposedOf = [];
42 // CoveringSubRegIndices - A list of two or more sub-register indexes that
43 // cover this sub-register.
45 // This field should normally be left blank as TableGen can infer it.
47 // TableGen automatically detects sub-registers that straddle the registers
48 // in the SubRegs field of a Register definition. For example:
50 // Q0 = dsub_0 -> D0, dsub_1 -> D1
51 // Q1 = dsub_0 -> D2, dsub_1 -> D3
52 // D1_D2 = dsub_0 -> D1, dsub_1 -> D2
53 // QQ0 = qsub_0 -> Q0, qsub_1 -> Q1
55 // TableGen will infer that D1_D2 is a sub-register of QQ0. It will be given
56 // the synthetic index dsub_1_dsub_2 unless some SubRegIndex is defined with
57 // CoveringSubRegIndices = [dsub_1, dsub_2].
58 list<SubRegIndex> CoveringSubRegIndices = [];
61 // ComposedSubRegIndex - A sub-register that is the result of composing A and B.
62 // Offset is set to the sum of A and B's Offsets. Size is set to B's Size.
63 class ComposedSubRegIndex<SubRegIndex A, SubRegIndex B>
64 : SubRegIndex<B.Size, !if(!eq(A.Offset, -1), -1,
65 !if(!eq(B.Offset, -1), -1,
66 !add(A.Offset, B.Offset)))> {
68 let ComposedOf = [A, B];
71 // RegAltNameIndex - The alternate name set to use for register operands of
72 // this register class when printing.
73 class RegAltNameIndex {
74 string Namespace = "";
76 def NoRegAltName : RegAltNameIndex;
78 // Register - You should define one instance of this class for each register
79 // in the target machine. String n will become the "name" of the register.
80 class Register<string n, list<string> altNames = []> {
81 string Namespace = "";
83 list<string> AltNames = altNames;
85 // Aliases - A list of registers that this register overlaps with. A read or
86 // modification of this register can potentially read or modify the aliased
88 list<Register> Aliases = [];
90 // SubRegs - A list of registers that are parts of this register. Note these
91 // are "immediate" sub-registers and the registers within the list do not
92 // themselves overlap. e.g. For X86, EAX's SubRegs list contains only [AX],
94 list<Register> SubRegs = [];
96 // SubRegIndices - For each register in SubRegs, specify the SubRegIndex used
97 // to address it. Sub-sub-register indices are automatically inherited from
99 list<SubRegIndex> SubRegIndices = [];
101 // RegAltNameIndices - The alternate name indices which are valid for this
103 list<RegAltNameIndex> RegAltNameIndices = [];
105 // DwarfNumbers - Numbers used internally by gcc/gdb to identify the register.
106 // These values can be determined by locating the <target>.h file in the
107 // directory llvmgcc/gcc/config/<target>/ and looking for REGISTER_NAMES. The
108 // order of these names correspond to the enumeration used by gcc. A value of
109 // -1 indicates that the gcc number is undefined and -2 that register number
110 // is invalid for this mode/flavour.
111 list<int> DwarfNumbers = [];
113 // CostPerUse - Additional cost of instructions using this register compared
114 // to other registers in its class. The register allocator will try to
115 // minimize the number of instructions using a register with a CostPerUse.
116 // This is used by the x86-64 and ARM Thumb targets where some registers
117 // require larger instruction encodings.
120 // CoveredBySubRegs - When this bit is set, the value of this register is
121 // completely determined by the value of its sub-registers. For example, the
122 // x86 register AX is covered by its sub-registers AL and AH, but EAX is not
123 // covered by its sub-register AX.
124 bit CoveredBySubRegs = 0;
126 // HWEncoding - The target specific hardware encoding for this register.
127 bits<16> HWEncoding = 0;
130 // RegisterWithSubRegs - This can be used to define instances of Register which
131 // need to specify sub-registers.
132 // List "subregs" specifies which registers are sub-registers to this one. This
133 // is used to populate the SubRegs and AliasSet fields of TargetRegisterDesc.
134 // This allows the code generator to be careful not to put two values with
135 // overlapping live ranges into registers which alias.
136 class RegisterWithSubRegs<string n, list<Register> subregs> : Register<n> {
137 let SubRegs = subregs;
140 // DAGOperand - An empty base class that unifies RegisterClass's and other forms
141 // of Operand's that are legal as type qualifiers in DAG patterns. This should
142 // only ever be used for defining multiclasses that are polymorphic over both
143 // RegisterClass's and other Operand's.
146 // RegisterClass - Now that all of the registers are defined, and aliases
147 // between registers are defined, specify which registers belong to which
148 // register classes. This also defines the default allocation order of
149 // registers by register allocators.
151 class RegisterClass<string namespace, list<ValueType> regTypes, int alignment,
152 dag regList, RegAltNameIndex idx = NoRegAltName>
154 string Namespace = namespace;
156 // RegType - Specify the list ValueType of the registers in this register
157 // class. Note that all registers in a register class must have the same
158 // ValueTypes. This is a list because some targets permit storing different
159 // types in same register, for example vector values with 128-bit total size,
160 // but different count/size of items, like SSE on x86.
162 list<ValueType> RegTypes = regTypes;
164 // Size - Specify the spill size in bits of the registers. A default value of
165 // zero lets tablgen pick an appropriate size.
168 // Alignment - Specify the alignment required of the registers when they are
169 // stored or loaded to memory.
171 int Alignment = alignment;
173 // CopyCost - This value is used to specify the cost of copying a value
174 // between two registers in this register class. The default value is one
175 // meaning it takes a single instruction to perform the copying. A negative
176 // value means copying is extremely expensive or impossible.
179 // MemberList - Specify which registers are in this class. If the
180 // allocation_order_* method are not specified, this also defines the order of
181 // allocation used by the register allocator.
183 dag MemberList = regList;
185 // AltNameIndex - The alternate register name to use when printing operands
186 // of this register class. Every register in the register class must have
187 // a valid alternate name for the given index.
188 RegAltNameIndex altNameIndex = idx;
190 // isAllocatable - Specify that the register class can be used for virtual
191 // registers and register allocation. Some register classes are only used to
192 // model instruction operand constraints, and should have isAllocatable = 0.
193 bit isAllocatable = 1;
195 // AltOrders - List of alternative allocation orders. The default order is
196 // MemberList itself, and that is good enough for most targets since the
197 // register allocators automatically remove reserved registers and move
198 // callee-saved registers to the end.
199 list<dag> AltOrders = [];
201 // AltOrderSelect - The body of a function that selects the allocation order
202 // to use in a given machine function. The code will be inserted in a
203 // function like this:
205 // static inline unsigned f(const MachineFunction &MF) { ... }
207 // The function should return 0 to select the default order defined by
208 // MemberList, 1 to select the first AltOrders entry and so on.
209 code AltOrderSelect = [{}];
212 // The memberList in a RegisterClass is a dag of set operations. TableGen
213 // evaluates these set operations and expand them into register lists. These
214 // are the most common operation, see test/TableGen/SetTheory.td for more
215 // examples of what is possible:
217 // (add R0, R1, R2) - Set Union. Each argument can be an individual register, a
218 // register class, or a sub-expression. This is also the way to simply list
221 // (sub GPR, SP) - Set difference. Subtract the last arguments from the first.
223 // (and GPR, CSR) - Set intersection. All registers from the first set that are
224 // also in the second set.
226 // (sequence "R%u", 0, 15) -> [R0, R1, ..., R15]. Generate a sequence of
227 // numbered registers. Takes an optional 4th operand which is a stride to use
228 // when generating the sequence.
230 // (shl GPR, 4) - Remove the first N elements.
232 // (trunc GPR, 4) - Truncate after the first N elements.
234 // (rotl GPR, 1) - Rotate N places to the left.
236 // (rotr GPR, 1) - Rotate N places to the right.
238 // (decimate GPR, 2) - Pick every N'th element, starting with the first.
240 // (interleave A, B, ...) - Interleave the elements from each argument list.
242 // All of these operators work on ordered sets, not lists. That means
243 // duplicates are removed from sub-expressions.
245 // Set operators. The rest is defined in TargetSelectionDAG.td.
250 // RegisterTuples - Automatically generate super-registers by forming tuples of
251 // sub-registers. This is useful for modeling register sequence constraints
252 // with pseudo-registers that are larger than the architectural registers.
254 // The sub-register lists are zipped together:
256 // def EvenOdd : RegisterTuples<[sube, subo], [(add R0, R2), (add R1, R3)]>;
258 // Generates the same registers as:
260 // let SubRegIndices = [sube, subo] in {
261 // def R0_R1 : RegisterWithSubRegs<"", [R0, R1]>;
262 // def R2_R3 : RegisterWithSubRegs<"", [R2, R3]>;
265 // The generated pseudo-registers inherit super-classes and fields from their
266 // first sub-register. Most fields from the Register class are inferred, and
267 // the AsmName and Dwarf numbers are cleared.
269 // RegisterTuples instances can be used in other set operations to form
270 // register classes and so on. This is the only way of using the generated
272 class RegisterTuples<list<SubRegIndex> Indices, list<dag> Regs> {
273 // SubRegs - N lists of registers to be zipped up. Super-registers are
274 // synthesized from the first element of each SubRegs list, the second
275 // element and so on.
276 list<dag> SubRegs = Regs;
278 // SubRegIndices - N SubRegIndex instances. This provides the names of the
279 // sub-registers in the synthesized super-registers.
280 list<SubRegIndex> SubRegIndices = Indices;
284 //===----------------------------------------------------------------------===//
285 // DwarfRegNum - This class provides a mapping of the llvm register enumeration
286 // to the register numbering used by gcc and gdb. These values are used by a
287 // debug information writer to describe where values may be located during
289 class DwarfRegNum<list<int> Numbers> {
290 // DwarfNumbers - Numbers used internally by gcc/gdb to identify the register.
291 // These values can be determined by locating the <target>.h file in the
292 // directory llvmgcc/gcc/config/<target>/ and looking for REGISTER_NAMES. The
293 // order of these names correspond to the enumeration used by gcc. A value of
294 // -1 indicates that the gcc number is undefined and -2 that register number
295 // is invalid for this mode/flavour.
296 list<int> DwarfNumbers = Numbers;
299 // DwarfRegAlias - This class declares that a given register uses the same dwarf
300 // numbers as another one. This is useful for making it clear that the two
301 // registers do have the same number. It also lets us build a mapping
302 // from dwarf register number to llvm register.
303 class DwarfRegAlias<Register reg> {
304 Register DwarfAlias = reg;
307 //===----------------------------------------------------------------------===//
308 // Pull in the common support for scheduling
310 include "llvm/Target/TargetSchedule.td"
312 class Predicate; // Forward def
314 //===----------------------------------------------------------------------===//
315 // Instruction set description - These classes correspond to the C++ classes in
316 // the Target/TargetInstrInfo.h file.
319 string Namespace = "";
321 dag OutOperandList; // An dag containing the MI def operand list.
322 dag InOperandList; // An dag containing the MI use operand list.
323 string AsmString = ""; // The .s format to print the instruction with.
325 // Pattern - Set to the DAG pattern for this instruction, if we know of one,
326 // otherwise, uninitialized.
329 // The follow state will eventually be inferred automatically from the
330 // instruction pattern.
332 list<Register> Uses = []; // Default to using no non-operand registers
333 list<Register> Defs = []; // Default to modifying no non-operand registers
335 // Predicates - List of predicates which will be turned into isel matching
337 list<Predicate> Predicates = [];
339 // Size - Size of encoded instruction, or zero if the size cannot be determined
343 // DecoderNamespace - The "namespace" in which this instruction exists, on
344 // targets like ARM which multiple ISA namespaces exist.
345 string DecoderNamespace = "";
347 // Code size, for instruction selection.
348 // FIXME: What does this actually mean?
351 // Added complexity passed onto matching pattern.
352 int AddedComplexity = 0;
354 // These bits capture information about the high-level semantics of the
356 bit isReturn = 0; // Is this instruction a return instruction?
357 bit isBranch = 0; // Is this instruction a branch instruction?
358 bit isIndirectBranch = 0; // Is this instruction an indirect branch?
359 bit isCompare = 0; // Is this instruction a comparison instruction?
360 bit isMoveImm = 0; // Is this instruction a move immediate instruction?
361 bit isBitcast = 0; // Is this instruction a bitcast instruction?
362 bit isSelect = 0; // Is this instruction a select instruction?
363 bit isBarrier = 0; // Can control flow fall through this instruction?
364 bit isCall = 0; // Is this instruction a call instruction?
365 bit canFoldAsLoad = 0; // Can this be folded as a simple memory operand?
366 bit mayLoad = ?; // Is it possible for this inst to read memory?
367 bit mayStore = ?; // Is it possible for this inst to write memory?
368 bit isConvertibleToThreeAddress = 0; // Can this 2-addr instruction promote?
369 bit isCommutable = 0; // Is this 3 operand instruction commutable?
370 bit isTerminator = 0; // Is this part of the terminator for a basic block?
371 bit isReMaterializable = 0; // Is this instruction re-materializable?
372 bit isPredicable = 0; // Is this instruction predicable?
373 bit hasDelaySlot = 0; // Does this instruction have an delay slot?
374 bit usesCustomInserter = 0; // Pseudo instr needing special help.
375 bit hasPostISelHook = 0; // To be *adjusted* after isel by target hook.
376 bit hasCtrlDep = 0; // Does this instruction r/w ctrl-flow chains?
377 bit isNotDuplicable = 0; // Is it unsafe to duplicate this instruction?
378 bit isAsCheapAsAMove = 0; // As cheap (or cheaper) than a move instruction.
379 bit hasExtraSrcRegAllocReq = 0; // Sources have special regalloc requirement?
380 bit hasExtraDefRegAllocReq = 0; // Defs have special regalloc requirement?
381 bit isRegSequence = 0; // Is this instruction a kind of reg sequence?
382 // If so, make sure to override
383 // TargetInstrInfo::getRegSequenceLikeInputs.
384 bit isPseudo = 0; // Is this instruction a pseudo-instruction?
385 // If so, won't have encoding information for
386 // the [MC]CodeEmitter stuff.
387 bit isExtractSubreg = 0; // Is this instruction a kind of extract subreg?
388 // If so, make sure to override
389 // TargetInstrInfo::getExtractSubregLikeInputs.
391 // Side effect flags - When set, the flags have these meanings:
393 // hasSideEffects - The instruction has side effects that are not
394 // captured by any operands of the instruction or other flags.
396 // neverHasSideEffects (deprecated) - Set on an instruction with no pattern
397 // if it has no side effects. This is now equivalent to setting
398 // "hasSideEffects = 0".
399 bit hasSideEffects = ?;
400 bit neverHasSideEffects = 0;
402 // Is this instruction a "real" instruction (with a distinct machine
403 // encoding), or is it a pseudo instruction used for codegen modeling
405 // FIXME: For now this is distinct from isPseudo, above, as code-gen-only
406 // instructions can (and often do) still have encoding information
407 // associated with them. Once we've migrated all of them over to true
408 // pseudo-instructions that are lowered to real instructions prior to
409 // the printer/emitter, we can remove this attribute and just use isPseudo.
411 // The intended use is:
412 // isPseudo: Does not have encoding information and should be expanded,
413 // at the latest, during lowering to MCInst.
415 // isCodeGenOnly: Does have encoding information and can go through to the
416 // CodeEmitter unchanged, but duplicates a canonical instruction
417 // definition's encoding and should be ignored when constructing the
418 // assembler match tables.
419 bit isCodeGenOnly = 0;
421 // Is this instruction a pseudo instruction for use by the assembler parser.
422 bit isAsmParserOnly = 0;
424 InstrItinClass Itinerary = NoItinerary;// Execution steps used for scheduling.
426 // Scheduling information from TargetSchedule.td.
427 list<SchedReadWrite> SchedRW;
429 string Constraints = ""; // OperandConstraint, e.g. $src = $dst.
431 /// DisableEncoding - List of operand names (e.g. "$op1,$op2") that should not
432 /// be encoded into the output machineinstr.
433 string DisableEncoding = "";
435 string PostEncoderMethod = "";
436 string DecoderMethod = "";
438 /// Target-specific flags. This becomes the TSFlags field in TargetInstrDesc.
439 bits<64> TSFlags = 0;
441 ///@name Assembler Parser Support
444 string AsmMatchConverter = "";
446 /// TwoOperandAliasConstraint - Enable TableGen to auto-generate a
447 /// two-operand matcher inst-alias for a three operand instruction.
448 /// For example, the arm instruction "add r3, r3, r5" can be written
449 /// as "add r3, r5". The constraint is of the same form as a tied-operand
450 /// constraint. For example, "$Rn = $Rd".
451 string TwoOperandAliasConstraint = "";
455 /// UseNamedOperandTable - If set, the operand indices of this instruction
456 /// can be queried via the getNamedOperandIdx() function which is generated
458 bit UseNamedOperandTable = 0;
461 /// PseudoInstExpansion - Expansion information for a pseudo-instruction.
462 /// Which instruction it expands to and how the operands map from the
464 class PseudoInstExpansion<dag Result> {
465 dag ResultInst = Result; // The instruction to generate.
469 /// Predicates - These are extra conditionals which are turned into instruction
470 /// selector matching code. Currently each predicate is just a string.
471 class Predicate<string cond> {
472 string CondString = cond;
474 /// AssemblerMatcherPredicate - If this feature can be used by the assembler
475 /// matcher, this is true. Targets should set this by inheriting their
476 /// feature from the AssemblerPredicate class in addition to Predicate.
477 bit AssemblerMatcherPredicate = 0;
479 /// AssemblerCondString - Name of the subtarget feature being tested used
480 /// as alternative condition string used for assembler matcher.
481 /// e.g. "ModeThumb" is translated to "(Bits & ModeThumb) != 0".
482 /// "!ModeThumb" is translated to "(Bits & ModeThumb) == 0".
483 /// It can also list multiple features separated by ",".
484 /// e.g. "ModeThumb,FeatureThumb2" is translated to
485 /// "(Bits & ModeThumb) != 0 && (Bits & FeatureThumb2) != 0".
486 string AssemblerCondString = "";
488 /// PredicateName - User-level name to use for the predicate. Mainly for use
489 /// in diagnostics such as missing feature errors in the asm matcher.
490 string PredicateName = "";
493 /// NoHonorSignDependentRounding - This predicate is true if support for
494 /// sign-dependent-rounding is not enabled.
495 def NoHonorSignDependentRounding
496 : Predicate<"!TM.Options.HonorSignDependentRoundingFPMath()">;
498 class Requires<list<Predicate> preds> {
499 list<Predicate> Predicates = preds;
502 /// ops definition - This is just a simple marker used to identify the operand
503 /// list for an instruction. outs and ins are identical both syntactically and
504 /// semanticallyr; they are used to define def operands and use operands to
505 /// improve readibility. This should be used like this:
506 /// (outs R32:$dst), (ins R32:$src1, R32:$src2) or something similar.
511 /// variable_ops definition - Mark this instruction as taking a variable number
516 /// PointerLikeRegClass - Values that are designed to have pointer width are
517 /// derived from this. TableGen treats the register class as having a symbolic
518 /// type that it doesn't know, and resolves the actual regclass to use by using
519 /// the TargetRegisterInfo::getPointerRegClass() hook at codegen time.
520 class PointerLikeRegClass<int Kind> {
521 int RegClassKind = Kind;
525 /// ptr_rc definition - Mark this operand as being a pointer value whose
526 /// register class is resolved dynamically via a callback to TargetInstrInfo.
527 /// FIXME: We should probably change this to a class which contain a list of
528 /// flags. But currently we have but one flag.
529 def ptr_rc : PointerLikeRegClass<0>;
531 /// unknown definition - Mark this operand as being of unknown type, causing
532 /// it to be resolved by inference in the context it is used.
534 def unknown : unknown_class;
536 /// AsmOperandClass - Representation for the kinds of operands which the target
537 /// specific parser can create and the assembly matcher may need to distinguish.
539 /// Operand classes are used to define the order in which instructions are
540 /// matched, to ensure that the instruction which gets matched for any
541 /// particular list of operands is deterministic.
543 /// The target specific parser must be able to classify a parsed operand into a
544 /// unique class which does not partially overlap with any other classes. It can
545 /// match a subset of some other class, in which case the super class field
546 /// should be defined.
547 class AsmOperandClass {
548 /// The name to use for this class, which should be usable as an enum value.
551 /// The super classes of this operand.
552 list<AsmOperandClass> SuperClasses = [];
554 /// The name of the method on the target specific operand to call to test
555 /// whether the operand is an instance of this class. If not set, this will
556 /// default to "isFoo", where Foo is the AsmOperandClass name. The method
557 /// signature should be:
558 /// bool isFoo() const;
559 string PredicateMethod = ?;
561 /// The name of the method on the target specific operand to call to add the
562 /// target specific operand to an MCInst. If not set, this will default to
563 /// "addFooOperands", where Foo is the AsmOperandClass name. The method
564 /// signature should be:
565 /// void addFooOperands(MCInst &Inst, unsigned N) const;
566 string RenderMethod = ?;
568 /// The name of the method on the target specific operand to call to custom
569 /// handle the operand parsing. This is useful when the operands do not relate
570 /// to immediates or registers and are very instruction specific (as flags to
571 /// set in a processor register, coprocessor number, ...).
572 string ParserMethod = ?;
574 // The diagnostic type to present when referencing this operand in a
575 // match failure error message. By default, use a generic "invalid operand"
576 // diagnostic. The target AsmParser maps these codes to text.
577 string DiagnosticType = "";
580 def ImmAsmOperand : AsmOperandClass {
584 /// Operand Types - These provide the built-in operand types that may be used
585 /// by a target. Targets can optionally provide their own operand types as
586 /// needed, though this should not be needed for RISC targets.
587 class Operand<ValueType ty> : DAGOperand {
589 string PrintMethod = "printOperand";
590 string EncoderMethod = "";
591 string DecoderMethod = "";
592 string AsmOperandLowerMethod = ?;
593 string OperandType = "OPERAND_UNKNOWN";
594 dag MIOperandInfo = (ops);
596 // MCOperandPredicate - Optionally, a code fragment operating on
597 // const MCOperand &MCOp, and returning a bool, to indicate if
598 // the value of MCOp is valid for the specific subclass of Operand
599 code MCOperandPredicate;
601 // ParserMatchClass - The "match class" that operands of this type fit
602 // in. Match classes are used to define the order in which instructions are
603 // match, to ensure that which instructions gets matched is deterministic.
605 // The target specific parser must be able to classify an parsed operand into
606 // a unique class, which does not partially overlap with any other classes. It
607 // can match a subset of some other class, in which case the AsmOperandClass
608 // should declare the other operand as one of its super classes.
609 AsmOperandClass ParserMatchClass = ImmAsmOperand;
612 class RegisterOperand<RegisterClass regclass, string pm = "printOperand">
614 // RegClass - The register class of the operand.
615 RegisterClass RegClass = regclass;
616 // PrintMethod - The target method to call to print register operands of
617 // this type. The method normally will just use an alt-name index to look
618 // up the name to print. Default to the generic printOperand().
619 string PrintMethod = pm;
620 // ParserMatchClass - The "match class" that operands of this type fit
621 // in. Match classes are used to define the order in which instructions are
622 // match, to ensure that which instructions gets matched is deterministic.
624 // The target specific parser must be able to classify an parsed operand into
625 // a unique class, which does not partially overlap with any other classes. It
626 // can match a subset of some other class, in which case the AsmOperandClass
627 // should declare the other operand as one of its super classes.
628 AsmOperandClass ParserMatchClass;
631 let OperandType = "OPERAND_IMMEDIATE" in {
632 def i1imm : Operand<i1>;
633 def i8imm : Operand<i8>;
634 def i16imm : Operand<i16>;
635 def i32imm : Operand<i32>;
636 def i64imm : Operand<i64>;
638 def f32imm : Operand<f32>;
639 def f64imm : Operand<f64>;
642 /// zero_reg definition - Special node to stand for the zero register.
646 /// All operands which the MC layer classifies as predicates should inherit from
647 /// this class in some manner. This is already handled for the most commonly
648 /// used PredicateOperand, but may be useful in other circumstances.
651 /// OperandWithDefaultOps - This Operand class can be used as the parent class
652 /// for an Operand that needs to be initialized with a default value if
653 /// no value is supplied in a pattern. This class can be used to simplify the
654 /// pattern definitions for instructions that have target specific flags
655 /// encoded as immediate operands.
656 class OperandWithDefaultOps<ValueType ty, dag defaultops>
658 dag DefaultOps = defaultops;
661 /// PredicateOperand - This can be used to define a predicate operand for an
662 /// instruction. OpTypes specifies the MIOperandInfo for the operand, and
663 /// AlwaysVal specifies the value of this predicate when set to "always
665 class PredicateOperand<ValueType ty, dag OpTypes, dag AlwaysVal>
666 : OperandWithDefaultOps<ty, AlwaysVal>, PredicateOp {
667 let MIOperandInfo = OpTypes;
670 /// OptionalDefOperand - This is used to define a optional definition operand
671 /// for an instruction. DefaultOps is the register the operand represents if
672 /// none is supplied, e.g. zero_reg.
673 class OptionalDefOperand<ValueType ty, dag OpTypes, dag defaultops>
674 : OperandWithDefaultOps<ty, defaultops> {
675 let MIOperandInfo = OpTypes;
679 // InstrInfo - This class should only be instantiated once to provide parameters
680 // which are global to the target machine.
683 // Target can specify its instructions in either big or little-endian formats.
684 // For instance, while both Sparc and PowerPC are big-endian platforms, the
685 // Sparc manual specifies its instructions in the format [31..0] (big), while
686 // PowerPC specifies them using the format [0..31] (little).
687 bit isLittleEndianEncoding = 0;
689 // The instruction properties mayLoad, mayStore, and hasSideEffects are unset
690 // by default, and TableGen will infer their value from the instruction
691 // pattern when possible.
693 // Normally, TableGen will issue an error it it can't infer the value of a
694 // property that hasn't been set explicitly. When guessInstructionProperties
695 // is set, it will guess a safe value instead.
697 // This option is a temporary migration help. It will go away.
698 bit guessInstructionProperties = 1;
700 // TableGen's instruction encoder generator has support for matching operands
701 // to bit-field variables both by name and by position. While matching by
702 // name is preferred, this is currently not possible for complex operands,
703 // and some targets still reply on the positional encoding rules. When
704 // generating a decoder for such targets, the positional encoding rules must
705 // be used by the decoder generator as well.
707 // This option is temporary; it will go away once the TableGen decoder
708 // generator has better support for complex operands and targets have
709 // migrated away from using positionally encoded operands.
710 bit decodePositionallyEncodedOperands = 0;
712 // When set, this indicates that there will be no overlap between those
713 // operands that are matched by ordering (positional operands) and those
716 // This option is temporary; it will go away once the TableGen decoder
717 // generator has better support for complex operands and targets have
718 // migrated away from using positionally encoded operands.
719 bit noNamedPositionallyEncodedOperands = 0;
722 // Standard Pseudo Instructions.
723 // This list must match TargetOpcodes.h and CodeGenTarget.cpp.
724 // Only these instructions are allowed in the TargetOpcode namespace.
725 let isCodeGenOnly = 1, isPseudo = 1, Namespace = "TargetOpcode" in {
726 def PHI : Instruction {
727 let OutOperandList = (outs);
728 let InOperandList = (ins variable_ops);
729 let AsmString = "PHINODE";
731 def INLINEASM : Instruction {
732 let OutOperandList = (outs);
733 let InOperandList = (ins variable_ops);
735 let neverHasSideEffects = 1; // Note side effect is encoded in an operand.
737 def CFI_INSTRUCTION : Instruction {
738 let OutOperandList = (outs);
739 let InOperandList = (ins i32imm:$id);
742 let isNotDuplicable = 1;
744 def EH_LABEL : Instruction {
745 let OutOperandList = (outs);
746 let InOperandList = (ins i32imm:$id);
749 let isNotDuplicable = 1;
751 def GC_LABEL : Instruction {
752 let OutOperandList = (outs);
753 let InOperandList = (ins i32imm:$id);
756 let isNotDuplicable = 1;
758 def KILL : Instruction {
759 let OutOperandList = (outs);
760 let InOperandList = (ins variable_ops);
762 let neverHasSideEffects = 1;
764 def EXTRACT_SUBREG : Instruction {
765 let OutOperandList = (outs unknown:$dst);
766 let InOperandList = (ins unknown:$supersrc, i32imm:$subidx);
768 let neverHasSideEffects = 1;
770 def INSERT_SUBREG : Instruction {
771 let OutOperandList = (outs unknown:$dst);
772 let InOperandList = (ins unknown:$supersrc, unknown:$subsrc, i32imm:$subidx);
774 let neverHasSideEffects = 1;
775 let Constraints = "$supersrc = $dst";
777 def IMPLICIT_DEF : Instruction {
778 let OutOperandList = (outs unknown:$dst);
779 let InOperandList = (ins);
781 let neverHasSideEffects = 1;
782 let isReMaterializable = 1;
783 let isAsCheapAsAMove = 1;
785 def SUBREG_TO_REG : Instruction {
786 let OutOperandList = (outs unknown:$dst);
787 let InOperandList = (ins unknown:$implsrc, unknown:$subsrc, i32imm:$subidx);
789 let neverHasSideEffects = 1;
791 def COPY_TO_REGCLASS : Instruction {
792 let OutOperandList = (outs unknown:$dst);
793 let InOperandList = (ins unknown:$src, i32imm:$regclass);
795 let neverHasSideEffects = 1;
796 let isAsCheapAsAMove = 1;
798 def DBG_VALUE : Instruction {
799 let OutOperandList = (outs);
800 let InOperandList = (ins variable_ops);
801 let AsmString = "DBG_VALUE";
802 let neverHasSideEffects = 1;
804 def REG_SEQUENCE : Instruction {
805 let OutOperandList = (outs unknown:$dst);
806 let InOperandList = (ins variable_ops);
808 let neverHasSideEffects = 1;
809 let isAsCheapAsAMove = 1;
811 def COPY : Instruction {
812 let OutOperandList = (outs unknown:$dst);
813 let InOperandList = (ins unknown:$src);
815 let neverHasSideEffects = 1;
816 let isAsCheapAsAMove = 1;
818 def BUNDLE : Instruction {
819 let OutOperandList = (outs);
820 let InOperandList = (ins variable_ops);
821 let AsmString = "BUNDLE";
823 def LIFETIME_START : Instruction {
824 let OutOperandList = (outs);
825 let InOperandList = (ins i32imm:$id);
826 let AsmString = "LIFETIME_START";
827 let neverHasSideEffects = 1;
829 def LIFETIME_END : Instruction {
830 let OutOperandList = (outs);
831 let InOperandList = (ins i32imm:$id);
832 let AsmString = "LIFETIME_END";
833 let neverHasSideEffects = 1;
835 def STACKMAP : Instruction {
836 let OutOperandList = (outs);
837 let InOperandList = (ins i64imm:$id, i32imm:$nbytes, variable_ops);
840 let usesCustomInserter = 1;
842 def PATCHPOINT : Instruction {
843 let OutOperandList = (outs unknown:$dst);
844 let InOperandList = (ins i64imm:$id, i32imm:$nbytes, unknown:$callee,
845 i32imm:$nargs, i32imm:$cc, variable_ops);
848 let usesCustomInserter = 1;
850 def LOAD_STACK_GUARD : Instruction {
851 let OutOperandList = (outs ptr_rc:$dst);
852 let InOperandList = (ins);
854 bit isReMaterializable = 1;
855 let hasSideEffects = 0;
860 //===----------------------------------------------------------------------===//
861 // AsmParser - This class can be implemented by targets that wish to implement
864 // Subtargets can have multiple different assembly parsers (e.g. AT&T vs Intel
865 // syntax on X86 for example).
868 // AsmParserClassName - This specifies the suffix to use for the asmparser
869 // class. Generated AsmParser classes are always prefixed with the target
871 string AsmParserClassName = "AsmParser";
873 // AsmParserInstCleanup - If non-empty, this is the name of a custom member
874 // function of the AsmParser class to call on every matched instruction.
875 // This can be used to perform target specific instruction post-processing.
876 string AsmParserInstCleanup = "";
878 // ShouldEmitMatchRegisterName - Set to false if the target needs a hand
879 // written register name matcher
880 bit ShouldEmitMatchRegisterName = 1;
882 /// Does the instruction mnemonic allow '.'
883 bit MnemonicContainsDot = 0;
885 def DefaultAsmParser : AsmParser;
887 //===----------------------------------------------------------------------===//
888 // AsmParserVariant - Subtargets can have multiple different assembly parsers
889 // (e.g. AT&T vs Intel syntax on X86 for example). This class can be
890 // implemented by targets to describe such variants.
892 class AsmParserVariant {
893 // Variant - AsmParsers can be of multiple different variants. Variants are
894 // used to support targets that need to parser multiple formats for the
895 // assembly language.
898 // Name - The AsmParser variant name (e.g., AT&T vs Intel).
901 // CommentDelimiter - If given, the delimiter string used to recognize
902 // comments which are hard coded in the .td assembler strings for individual
904 string CommentDelimiter = "";
906 // RegisterPrefix - If given, the token prefix which indicates a register
907 // token. This is used by the matcher to automatically recognize hard coded
908 // register tokens as constrained registers, instead of tokens, for the
909 // purposes of matching.
910 string RegisterPrefix = "";
912 def DefaultAsmParserVariant : AsmParserVariant;
914 /// AssemblerPredicate - This is a Predicate that can be used when the assembler
915 /// matches instructions and aliases.
916 class AssemblerPredicate<string cond, string name = ""> {
917 bit AssemblerMatcherPredicate = 1;
918 string AssemblerCondString = cond;
919 string PredicateName = name;
922 /// TokenAlias - This class allows targets to define assembler token
923 /// operand aliases. That is, a token literal operand which is equivalent
924 /// to another, canonical, token literal. For example, ARM allows:
925 /// vmov.u32 s4, #0 -> vmov.i32, #0
926 /// 'u32' is a more specific designator for the 32-bit integer type specifier
927 /// and is legal for any instruction which accepts 'i32' as a datatype suffix.
928 /// def : TokenAlias<".u32", ".i32">;
930 /// This works by marking the match class of 'From' as a subclass of the
931 /// match class of 'To'.
932 class TokenAlias<string From, string To> {
933 string FromToken = From;
937 /// MnemonicAlias - This class allows targets to define assembler mnemonic
938 /// aliases. This should be used when all forms of one mnemonic are accepted
939 /// with a different mnemonic. For example, X86 allows:
940 /// sal %al, 1 -> shl %al, 1
941 /// sal %ax, %cl -> shl %ax, %cl
942 /// sal %eax, %cl -> shl %eax, %cl
943 /// etc. Though "sal" is accepted with many forms, all of them are directly
944 /// translated to a shl, so it can be handled with (in the case of X86, it
945 /// actually has one for each suffix as well):
946 /// def : MnemonicAlias<"sal", "shl">;
948 /// Mnemonic aliases are mapped before any other translation in the match phase,
949 /// and do allow Requires predicates, e.g.:
951 /// def : MnemonicAlias<"pushf", "pushfq">, Requires<[In64BitMode]>;
952 /// def : MnemonicAlias<"pushf", "pushfl">, Requires<[In32BitMode]>;
954 /// Mnemonic aliases can also be constrained to specific variants, e.g.:
956 /// def : MnemonicAlias<"pushf", "pushfq", "att">, Requires<[In64BitMode]>;
958 /// If no variant (e.g., "att" or "intel") is specified then the alias is
959 /// applied unconditionally.
960 class MnemonicAlias<string From, string To, string VariantName = ""> {
961 string FromMnemonic = From;
962 string ToMnemonic = To;
963 string AsmVariantName = VariantName;
965 // Predicates - Predicates that must be true for this remapping to happen.
966 list<Predicate> Predicates = [];
969 /// InstAlias - This defines an alternate assembly syntax that is allowed to
970 /// match an instruction that has a different (more canonical) assembly
972 class InstAlias<string Asm, dag Result, int Emit = 1> {
973 string AsmString = Asm; // The .s format to match the instruction with.
974 dag ResultInst = Result; // The MCInst to generate.
976 // This determines which order the InstPrinter detects aliases for
977 // printing. A larger value makes the alias more likely to be
978 // emitted. The Instruction's own definition is notionally 0.5, so 0
979 // disables printing and 1 enables it if there are no conflicting aliases.
980 int EmitPriority = Emit;
982 // Predicates - Predicates that must be true for this to match.
983 list<Predicate> Predicates = [];
986 //===----------------------------------------------------------------------===//
987 // AsmWriter - This class can be implemented by targets that need to customize
988 // the format of the .s file writer.
990 // Subtargets can have multiple different asmwriters (e.g. AT&T vs Intel syntax
991 // on X86 for example).
994 // AsmWriterClassName - This specifies the suffix to use for the asmwriter
995 // class. Generated AsmWriter classes are always prefixed with the target
997 string AsmWriterClassName = "InstPrinter";
999 // Variant - AsmWriters can be of multiple different variants. Variants are
1000 // used to support targets that need to emit assembly code in ways that are
1001 // mostly the same for different targets, but have minor differences in
1002 // syntax. If the asmstring contains {|} characters in them, this integer
1003 // will specify which alternative to use. For example "{x|y|z}" with Variant
1004 // == 1, will expand to "y".
1007 // OperandSpacing - Space between operand columns.
1008 int OperandSpacing = -1;
1010 def DefaultAsmWriter : AsmWriter;
1013 //===----------------------------------------------------------------------===//
1014 // Target - This class contains the "global" target information
1017 // InstructionSet - Instruction set description for this target.
1018 InstrInfo InstructionSet;
1020 // AssemblyParsers - The AsmParser instances available for this target.
1021 list<AsmParser> AssemblyParsers = [DefaultAsmParser];
1023 /// AssemblyParserVariants - The AsmParserVariant instances available for
1025 list<AsmParserVariant> AssemblyParserVariants = [DefaultAsmParserVariant];
1027 // AssemblyWriters - The AsmWriter instances available for this target.
1028 list<AsmWriter> AssemblyWriters = [DefaultAsmWriter];
1031 //===----------------------------------------------------------------------===//
1032 // SubtargetFeature - A characteristic of the chip set.
1034 class SubtargetFeature<string n, string a, string v, string d,
1035 list<SubtargetFeature> i = []> {
1036 // Name - Feature name. Used by command line (-mattr=) to determine the
1037 // appropriate target chip.
1041 // Attribute - Attribute to be set by feature.
1043 string Attribute = a;
1045 // Value - Value the attribute to be set to by feature.
1049 // Desc - Feature description. Used by command line (-mattr=) to display help
1054 // Implies - Features that this feature implies are present. If one of those
1055 // features isn't set, then this one shouldn't be set either.
1057 list<SubtargetFeature> Implies = i;
1060 /// Specifies a Subtarget feature that this instruction is deprecated on.
1061 class Deprecated<SubtargetFeature dep> {
1062 SubtargetFeature DeprecatedFeatureMask = dep;
1065 /// A custom predicate used to determine if an instruction is
1066 /// deprecated or not.
1067 class ComplexDeprecationPredicate<string dep> {
1068 string ComplexDeprecationPredicate = dep;
1071 //===----------------------------------------------------------------------===//
1072 // Processor chip sets - These values represent each of the chip sets supported
1073 // by the scheduler. Each Processor definition requires corresponding
1074 // instruction itineraries.
1076 class Processor<string n, ProcessorItineraries pi, list<SubtargetFeature> f> {
1077 // Name - Chip set name. Used by command line (-mcpu=) to determine the
1078 // appropriate target chip.
1082 // SchedModel - The machine model for scheduling and instruction cost.
1084 SchedMachineModel SchedModel = NoSchedModel;
1086 // ProcItin - The scheduling information for the target processor.
1088 ProcessorItineraries ProcItin = pi;
1090 // Features - list of
1091 list<SubtargetFeature> Features = f;
1094 // ProcessorModel allows subtargets to specify the more general
1095 // SchedMachineModel instead if a ProcessorItinerary. Subtargets will
1096 // gradually move to this newer form.
1098 // Although this class always passes NoItineraries to the Processor
1099 // class, the SchedMachineModel may still define valid Itineraries.
1100 class ProcessorModel<string n, SchedMachineModel m, list<SubtargetFeature> f>
1101 : Processor<n, NoItineraries, f> {
1105 //===----------------------------------------------------------------------===//
1106 // InstrMapping - This class is used to create mapping tables to relate
1107 // instructions with each other based on the values specified in RowFields,
1108 // ColFields, KeyCol and ValueCols.
1110 class InstrMapping {
1111 // FilterClass - Used to limit search space only to the instructions that
1112 // define the relationship modeled by this InstrMapping record.
1115 // RowFields - List of fields/attributes that should be same for all the
1116 // instructions in a row of the relation table. Think of this as a set of
1117 // properties shared by all the instructions related by this relationship
1118 // model and is used to categorize instructions into subgroups. For instance,
1119 // if we want to define a relation that maps 'Add' instruction to its
1120 // predicated forms, we can define RowFields like this:
1122 // let RowFields = BaseOp
1123 // All add instruction predicated/non-predicated will have to set their BaseOp
1124 // to the same value.
1126 // def Add: { let BaseOp = 'ADD'; let predSense = 'nopred' }
1127 // def Add_predtrue: { let BaseOp = 'ADD'; let predSense = 'true' }
1128 // def Add_predfalse: { let BaseOp = 'ADD'; let predSense = 'false' }
1129 list<string> RowFields = [];
1131 // List of fields/attributes that are same for all the instructions
1132 // in a column of the relation table.
1133 // Ex: let ColFields = 'predSense' -- It means that the columns are arranged
1134 // based on the 'predSense' values. All the instruction in a specific
1135 // column have the same value and it is fixed for the column according
1136 // to the values set in 'ValueCols'.
1137 list<string> ColFields = [];
1139 // Values for the fields/attributes listed in 'ColFields'.
1140 // Ex: let KeyCol = 'nopred' -- It means that the key instruction (instruction
1141 // that models this relation) should be non-predicated.
1142 // In the example above, 'Add' is the key instruction.
1143 list<string> KeyCol = [];
1145 // List of values for the fields/attributes listed in 'ColFields', one for
1146 // each column in the relation table.
1148 // Ex: let ValueCols = [['true'],['false']] -- It adds two columns in the
1149 // table. First column requires all the instructions to have predSense
1150 // set to 'true' and second column requires it to be 'false'.
1151 list<list<string> > ValueCols = [];
1154 //===----------------------------------------------------------------------===//
1155 // Pull in the common support for calling conventions.
1157 include "llvm/Target/TargetCallingConv.td"
1159 //===----------------------------------------------------------------------===//
1160 // Pull in the common support for DAG isel generation.
1162 include "llvm/Target/TargetSelectionDAG.td"