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