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