1 //===-- llvm/MC/MCInstrDesc.h - Instruction Descriptors -*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file defines the MCOperandInfo and MCInstrDesc classes, which 10 // are used to describe target instructions and their operands. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_MC_MCINSTRDESC_H 15 #define LLVM_MC_MCINSTRDESC_H 16 17 #include "llvm/ADT/ArrayRef.h" 18 #include "llvm/ADT/iterator_range.h" 19 #include "llvm/MC/MCRegister.h" 20 #include "llvm/Support/Compiler.h" 21 22 namespace llvm { 23 class MCRegisterInfo; 24 25 class MCInst; 26 27 //===----------------------------------------------------------------------===// 28 // Machine Operand Flags and Description 29 //===----------------------------------------------------------------------===// 30 31 namespace MCOI { 32 /// Operand constraints. These are encoded in 16 bits with one of the 33 /// low-order 3 bits specifying that a constraint is present and the 34 /// corresponding high-order hex digit specifying the constraint value. 35 /// This allows for a maximum of 3 constraints. 36 enum OperandConstraint { 37 TIED_TO = 0, // Must be allocated the same register as specified value. 38 EARLY_CLOBBER // If present, operand is an early clobber register. 39 }; 40 41 // Define a macro to produce each constraint value. 42 #define MCOI_TIED_TO(op) \ 43 ((1 << MCOI::TIED_TO) | ((op) << (4 + MCOI::TIED_TO * 4))) 44 45 #define MCOI_EARLY_CLOBBER \ 46 (1 << MCOI::EARLY_CLOBBER) 47 48 /// These are flags set on operands, but should be considered 49 /// private, all access should go through the MCOperandInfo accessors. 50 /// See the accessors for a description of what these are. 51 enum OperandFlags { 52 LookupPtrRegClass = 0, 53 Predicate, 54 OptionalDef, 55 BranchTarget 56 }; 57 58 /// Operands are tagged with one of the values of this enum. 59 enum OperandType { 60 OPERAND_UNKNOWN = 0, 61 OPERAND_IMMEDIATE = 1, 62 OPERAND_REGISTER = 2, 63 OPERAND_MEMORY = 3, 64 OPERAND_PCREL = 4, 65 66 OPERAND_FIRST_GENERIC = 6, 67 OPERAND_GENERIC_0 = 6, 68 OPERAND_GENERIC_1 = 7, 69 OPERAND_GENERIC_2 = 8, 70 OPERAND_GENERIC_3 = 9, 71 OPERAND_GENERIC_4 = 10, 72 OPERAND_GENERIC_5 = 11, 73 OPERAND_LAST_GENERIC = 11, 74 75 OPERAND_FIRST_GENERIC_IMM = 12, 76 OPERAND_GENERIC_IMM_0 = 12, 77 OPERAND_LAST_GENERIC_IMM = 12, 78 79 OPERAND_FIRST_TARGET = 13, 80 }; 81 82 } // namespace MCOI 83 84 /// This holds information about one operand of a machine instruction, 85 /// indicating the register class for register operands, etc. 86 class MCOperandInfo { 87 public: 88 /// This specifies the register class enumeration of the operand 89 /// if the operand is a register. If isLookupPtrRegClass is set, then this is 90 /// an index that is passed to TargetRegisterInfo::getPointerRegClass(x) to 91 /// get a dynamic register class. 92 int16_t RegClass; 93 94 /// These are flags from the MCOI::OperandFlags enum. 95 uint8_t Flags; 96 97 /// Information about the type of the operand. 98 uint8_t OperandType; 99 100 /// Operand constraints (see OperandConstraint enum). 101 uint16_t Constraints; 102 103 /// Set if this operand is a pointer value and it requires a callback 104 /// to look up its register class. isLookupPtrRegClass()105 bool isLookupPtrRegClass() const { 106 return Flags & (1 << MCOI::LookupPtrRegClass); 107 } 108 109 /// Set if this is one of the operands that made up of the predicate 110 /// operand that controls an isPredicable() instruction. isPredicate()111 bool isPredicate() const { return Flags & (1 << MCOI::Predicate); } 112 113 /// Set if this operand is a optional def. isOptionalDef()114 bool isOptionalDef() const { return Flags & (1 << MCOI::OptionalDef); } 115 116 /// Set if this operand is a branch target. isBranchTarget()117 bool isBranchTarget() const { return Flags & (1 << MCOI::BranchTarget); } 118 isGenericType()119 bool isGenericType() const { 120 return OperandType >= MCOI::OPERAND_FIRST_GENERIC && 121 OperandType <= MCOI::OPERAND_LAST_GENERIC; 122 } 123 getGenericTypeIndex()124 unsigned getGenericTypeIndex() const { 125 assert(isGenericType() && "non-generic types don't have an index"); 126 return OperandType - MCOI::OPERAND_FIRST_GENERIC; 127 } 128 isGenericImm()129 bool isGenericImm() const { 130 return OperandType >= MCOI::OPERAND_FIRST_GENERIC_IMM && 131 OperandType <= MCOI::OPERAND_LAST_GENERIC_IMM; 132 } 133 getGenericImmIndex()134 unsigned getGenericImmIndex() const { 135 assert(isGenericImm() && "non-generic immediates don't have an index"); 136 return OperandType - MCOI::OPERAND_FIRST_GENERIC_IMM; 137 } 138 }; 139 140 //===----------------------------------------------------------------------===// 141 // Machine Instruction Flags and Description 142 //===----------------------------------------------------------------------===// 143 144 namespace MCID { 145 /// These should be considered private to the implementation of the 146 /// MCInstrDesc class. Clients should use the predicate methods on MCInstrDesc, 147 /// not use these directly. These all correspond to bitfields in the 148 /// MCInstrDesc::Flags field. 149 enum Flag { 150 PreISelOpcode = 0, 151 Variadic, 152 HasOptionalDef, 153 Pseudo, 154 Meta, 155 Return, 156 EHScopeReturn, 157 Call, 158 Barrier, 159 Terminator, 160 Branch, 161 IndirectBranch, 162 Compare, 163 MoveImm, 164 MoveReg, 165 Bitcast, 166 Select, 167 DelaySlot, 168 FoldableAsLoad, 169 MayLoad, 170 MayStore, 171 MayRaiseFPException, 172 Predicable, 173 NotDuplicable, 174 UnmodeledSideEffects, 175 Commutable, 176 ConvertibleTo3Addr, 177 UsesCustomInserter, 178 HasPostISelHook, 179 Rematerializable, 180 CheapAsAMove, 181 ExtraSrcRegAllocReq, 182 ExtraDefRegAllocReq, 183 RegSequence, 184 ExtractSubreg, 185 InsertSubreg, 186 Convergent, 187 Add, 188 Trap, 189 VariadicOpsAreDefs, 190 Authenticated, 191 }; 192 } // namespace MCID 193 194 /// Describe properties that are true of each instruction in the target 195 /// description file. This captures information about side effects, register 196 /// use and many other things. There is one instance of this struct for each 197 /// target instruction class, and the MachineInstr class points to this struct 198 /// directly to describe itself. 199 class MCInstrDesc { 200 public: 201 // FIXME: Disable copies and moves. 202 // Do not allow MCInstrDescs to be copied or moved. They should only exist in 203 // the <Target>Insts table because they rely on knowing their own address to 204 // find other information elsewhere in the same table. 205 206 unsigned short Opcode; // The opcode number 207 unsigned short NumOperands; // Num of args (may be more if variable_ops) 208 unsigned char NumDefs; // Num of args that are definitions 209 unsigned char Size; // Number of bytes in encoding. 210 unsigned short SchedClass; // enum identifying instr sched class 211 unsigned char NumImplicitUses; // Num of regs implicitly used 212 unsigned char NumImplicitDefs; // Num of regs implicitly defined 213 unsigned short OpInfoOffset; // Offset to info about operands 214 unsigned int ImplicitOffset; // Offset to start of implicit op list 215 uint64_t Flags; // Flags identifying machine instr class 216 uint64_t TSFlags; // Target Specific Flag values 217 218 /// Returns the value of the specified operand constraint if 219 /// it is present. Returns -1 if it is not present. getOperandConstraint(unsigned OpNum,MCOI::OperandConstraint Constraint)220 int getOperandConstraint(unsigned OpNum, 221 MCOI::OperandConstraint Constraint) const { 222 if (OpNum < NumOperands && 223 (operands()[OpNum].Constraints & (1 << Constraint))) { 224 unsigned ValuePos = 4 + Constraint * 4; 225 return (int)(operands()[OpNum].Constraints >> ValuePos) & 0x0f; 226 } 227 return -1; 228 } 229 230 /// Return the opcode number for this descriptor. getOpcode()231 unsigned getOpcode() const { return Opcode; } 232 233 /// Return the number of declared MachineOperands for this 234 /// MachineInstruction. Note that variadic (isVariadic() returns true) 235 /// instructions may have additional operands at the end of the list, and note 236 /// that the machine instruction may include implicit register def/uses as 237 /// well. getNumOperands()238 unsigned getNumOperands() const { return NumOperands; } 239 operands()240 ArrayRef<MCOperandInfo> operands() const { 241 auto OpInfo = reinterpret_cast<const MCOperandInfo *>(this + Opcode + 1); 242 return ArrayRef(OpInfo + OpInfoOffset, NumOperands); 243 } 244 245 /// Return the number of MachineOperands that are register 246 /// definitions. Register definitions always occur at the start of the 247 /// machine operand list. This is the number of "outs" in the .td file, 248 /// and does not include implicit defs. getNumDefs()249 unsigned getNumDefs() const { return NumDefs; } 250 251 /// Return flags of this instruction. getFlags()252 uint64_t getFlags() const { return Flags; } 253 254 /// \returns true if this instruction is emitted before instruction selection 255 /// and should be legalized/regbankselected/selected. isPreISelOpcode()256 bool isPreISelOpcode() const { return Flags & (1ULL << MCID::PreISelOpcode); } 257 258 /// Return true if this instruction can have a variable number of 259 /// operands. In this case, the variable operands will be after the normal 260 /// operands but before the implicit definitions and uses (if any are 261 /// present). isVariadic()262 bool isVariadic() const { return Flags & (1ULL << MCID::Variadic); } 263 264 /// Set if this instruction has an optional definition, e.g. 265 /// ARM instructions which can set condition code if 's' bit is set. hasOptionalDef()266 bool hasOptionalDef() const { return Flags & (1ULL << MCID::HasOptionalDef); } 267 268 /// Return true if this is a pseudo instruction that doesn't 269 /// correspond to a real machine instruction. isPseudo()270 bool isPseudo() const { return Flags & (1ULL << MCID::Pseudo); } 271 272 /// Return true if this is a meta instruction that doesn't 273 /// produce any output in the form of executable instructions. isMetaInstruction()274 bool isMetaInstruction() const { return Flags & (1ULL << MCID::Meta); } 275 276 /// Return true if the instruction is a return. isReturn()277 bool isReturn() const { return Flags & (1ULL << MCID::Return); } 278 279 /// Return true if the instruction is an add instruction. isAdd()280 bool isAdd() const { return Flags & (1ULL << MCID::Add); } 281 282 /// Return true if this instruction is a trap. isTrap()283 bool isTrap() const { return Flags & (1ULL << MCID::Trap); } 284 285 /// Return true if the instruction is a register to register move. isMoveReg()286 bool isMoveReg() const { return Flags & (1ULL << MCID::MoveReg); } 287 288 /// Return true if the instruction is a call. isCall()289 bool isCall() const { return Flags & (1ULL << MCID::Call); } 290 291 /// Returns true if the specified instruction stops control flow 292 /// from executing the instruction immediately following it. Examples include 293 /// unconditional branches and return instructions. isBarrier()294 bool isBarrier() const { return Flags & (1ULL << MCID::Barrier); } 295 296 /// Returns true if this instruction part of the terminator for 297 /// a basic block. Typically this is things like return and branch 298 /// instructions. 299 /// 300 /// Various passes use this to insert code into the bottom of a basic block, 301 /// but before control flow occurs. isTerminator()302 bool isTerminator() const { return Flags & (1ULL << MCID::Terminator); } 303 304 /// Returns true if this is a conditional, unconditional, or 305 /// indirect branch. Predicates below can be used to discriminate between 306 /// these cases, and the TargetInstrInfo::analyzeBranch method can be used to 307 /// get more information. isBranch()308 bool isBranch() const { return Flags & (1ULL << MCID::Branch); } 309 310 /// Return true if this is an indirect branch, such as a 311 /// branch through a register. isIndirectBranch()312 bool isIndirectBranch() const { return Flags & (1ULL << MCID::IndirectBranch); } 313 314 /// Return true if this is a branch which may fall 315 /// through to the next instruction or may transfer control flow to some other 316 /// block. The TargetInstrInfo::analyzeBranch method can be used to get more 317 /// information about this branch. isConditionalBranch()318 bool isConditionalBranch() const { 319 return isBranch() && !isBarrier() && !isIndirectBranch(); 320 } 321 322 /// Return true if this is a branch which always 323 /// transfers control flow to some other block. The 324 /// TargetInstrInfo::analyzeBranch method can be used to get more information 325 /// about this branch. isUnconditionalBranch()326 bool isUnconditionalBranch() const { 327 return isBranch() && isBarrier() && !isIndirectBranch(); 328 } 329 330 /// Return true if this is a branch or an instruction which directly 331 /// writes to the program counter. Considered 'may' affect rather than 332 /// 'does' affect as things like predication are not taken into account. 333 LLVM_ABI bool mayAffectControlFlow(const MCInst &MI, 334 const MCRegisterInfo &RI) const; 335 336 /// Return true if this instruction has a predicate operand 337 /// that controls execution. It may be set to 'always', or may be set to other 338 /// values. There are various methods in TargetInstrInfo that can be used to 339 /// control and modify the predicate in this instruction. isPredicable()340 bool isPredicable() const { return Flags & (1ULL << MCID::Predicable); } 341 342 /// Return true if this instruction is a comparison. isCompare()343 bool isCompare() const { return Flags & (1ULL << MCID::Compare); } 344 345 /// Return true if this instruction is a move immediate 346 /// (including conditional moves) instruction. isMoveImmediate()347 bool isMoveImmediate() const { return Flags & (1ULL << MCID::MoveImm); } 348 349 /// Return true if this instruction is a bitcast instruction. isBitcast()350 bool isBitcast() const { return Flags & (1ULL << MCID::Bitcast); } 351 352 /// Return true if this is a select instruction. isSelect()353 bool isSelect() const { return Flags & (1ULL << MCID::Select); } 354 355 /// Return true if this instruction cannot be safely 356 /// duplicated. For example, if the instruction has a unique labels attached 357 /// to it, duplicating it would cause multiple definition errors. isNotDuplicable()358 bool isNotDuplicable() const { return Flags & (1ULL << MCID::NotDuplicable); } 359 360 /// Returns true if the specified instruction has a delay slot which 361 /// must be filled by the code generator. hasDelaySlot()362 bool hasDelaySlot() const { return Flags & (1ULL << MCID::DelaySlot); } 363 364 /// Return true for instructions that can be folded as memory operands 365 /// in other instructions. The most common use for this is instructions that 366 /// are simple loads from memory that don't modify the loaded value in any 367 /// way, but it can also be used for instructions that can be expressed as 368 /// constant-pool loads, such as V_SETALLONES on x86, to allow them to be 369 /// folded when it is beneficial. This should only be set on instructions 370 /// that return a value in their only virtual register definition. canFoldAsLoad()371 bool canFoldAsLoad() const { return Flags & (1ULL << MCID::FoldableAsLoad); } 372 373 /// Return true if this instruction behaves 374 /// the same way as the generic REG_SEQUENCE instructions. 375 /// E.g., on ARM, 376 /// dX VMOVDRR rY, rZ 377 /// is equivalent to 378 /// dX = REG_SEQUENCE rY, ssub_0, rZ, ssub_1. 379 /// 380 /// Note that for the optimizers to be able to take advantage of 381 /// this property, TargetInstrInfo::getRegSequenceLikeInputs has to be 382 /// override accordingly. isRegSequenceLike()383 bool isRegSequenceLike() const { return Flags & (1ULL << MCID::RegSequence); } 384 385 /// Return true if this instruction behaves 386 /// the same way as the generic EXTRACT_SUBREG instructions. 387 /// E.g., on ARM, 388 /// rX, rY VMOVRRD dZ 389 /// is equivalent to two EXTRACT_SUBREG: 390 /// rX = EXTRACT_SUBREG dZ, ssub_0 391 /// rY = EXTRACT_SUBREG dZ, ssub_1 392 /// 393 /// Note that for the optimizers to be able to take advantage of 394 /// this property, TargetInstrInfo::getExtractSubregLikeInputs has to be 395 /// override accordingly. isExtractSubregLike()396 bool isExtractSubregLike() const { 397 return Flags & (1ULL << MCID::ExtractSubreg); 398 } 399 400 /// Return true if this instruction behaves 401 /// the same way as the generic INSERT_SUBREG instructions. 402 /// E.g., on ARM, 403 /// dX = VSETLNi32 dY, rZ, Imm 404 /// is equivalent to a INSERT_SUBREG: 405 /// dX = INSERT_SUBREG dY, rZ, translateImmToSubIdx(Imm) 406 /// 407 /// Note that for the optimizers to be able to take advantage of 408 /// this property, TargetInstrInfo::getInsertSubregLikeInputs has to be 409 /// override accordingly. isInsertSubregLike()410 bool isInsertSubregLike() const { return Flags & (1ULL << MCID::InsertSubreg); } 411 412 413 /// Return true if this instruction is convergent. 414 /// 415 /// Convergent instructions may not be made control-dependent on any 416 /// additional values. isConvergent()417 bool isConvergent() const { return Flags & (1ULL << MCID::Convergent); } 418 419 /// Return true if variadic operands of this instruction are definitions. variadicOpsAreDefs()420 bool variadicOpsAreDefs() const { 421 return Flags & (1ULL << MCID::VariadicOpsAreDefs); 422 } 423 424 /// Return true if this instruction authenticates a pointer (e.g. LDRAx/BRAx 425 /// from ARMv8.3, which perform loads/branches with authentication). 426 /// 427 /// An authenticated instruction may fail in an ABI-defined manner when 428 /// operating on an invalid signed pointer. isAuthenticated()429 bool isAuthenticated() const { 430 return Flags & (1ULL << MCID::Authenticated); 431 } 432 433 //===--------------------------------------------------------------------===// 434 // Side Effect Analysis 435 //===--------------------------------------------------------------------===// 436 437 /// Return true if this instruction could possibly read memory. 438 /// Instructions with this flag set are not necessarily simple load 439 /// instructions, they may load a value and modify it, for example. mayLoad()440 bool mayLoad() const { return Flags & (1ULL << MCID::MayLoad); } 441 442 /// Return true if this instruction could possibly modify memory. 443 /// Instructions with this flag set are not necessarily simple store 444 /// instructions, they may store a modified value based on their operands, or 445 /// may not actually modify anything, for example. mayStore()446 bool mayStore() const { return Flags & (1ULL << MCID::MayStore); } 447 448 /// Return true if this instruction may raise a floating-point exception. mayRaiseFPException()449 bool mayRaiseFPException() const { 450 return Flags & (1ULL << MCID::MayRaiseFPException); 451 } 452 453 /// Return true if this instruction has side 454 /// effects that are not modeled by other flags. This does not return true 455 /// for instructions whose effects are captured by: 456 /// 457 /// 1. Their operand list and implicit definition/use list. Register use/def 458 /// info is explicit for instructions. 459 /// 2. Memory accesses. Use mayLoad/mayStore. 460 /// 3. Calling, branching, returning: use isCall/isReturn/isBranch. 461 /// 462 /// Examples of side effects would be modifying 'invisible' machine state like 463 /// a control register, flushing a cache, modifying a register invisible to 464 /// LLVM, etc. hasUnmodeledSideEffects()465 bool hasUnmodeledSideEffects() const { 466 return Flags & (1ULL << MCID::UnmodeledSideEffects); 467 } 468 469 //===--------------------------------------------------------------------===// 470 // Flags that indicate whether an instruction can be modified by a method. 471 //===--------------------------------------------------------------------===// 472 473 /// Return true if this may be a 2- or 3-address instruction (of the 474 /// form "X = op Y, Z, ..."), which produces the same result if Y and Z are 475 /// exchanged. If this flag is set, then the 476 /// TargetInstrInfo::commuteInstruction method may be used to hack on the 477 /// instruction. 478 /// 479 /// Note that this flag may be set on instructions that are only commutable 480 /// sometimes. In these cases, the call to commuteInstruction will fail. 481 /// Also note that some instructions require non-trivial modification to 482 /// commute them. isCommutable()483 bool isCommutable() const { return Flags & (1ULL << MCID::Commutable); } 484 485 /// Return true if this is a 2-address instruction which can be changed 486 /// into a 3-address instruction if needed. Doing this transformation can be 487 /// profitable in the register allocator, because it means that the 488 /// instruction can use a 2-address form if possible, but degrade into a less 489 /// efficient form if the source and dest register cannot be assigned to the 490 /// same register. For example, this allows the x86 backend to turn a "shl 491 /// reg, 3" instruction into an LEA instruction, which is the same speed as 492 /// the shift but has bigger code size. 493 /// 494 /// If this returns true, then the target must implement the 495 /// TargetInstrInfo::convertToThreeAddress method for this instruction, which 496 /// is allowed to fail if the transformation isn't valid for this specific 497 /// instruction (e.g. shl reg, 4 on x86). 498 /// isConvertibleTo3Addr()499 bool isConvertibleTo3Addr() const { 500 return Flags & (1ULL << MCID::ConvertibleTo3Addr); 501 } 502 503 /// Return true if this instruction requires custom insertion support 504 /// when the DAG scheduler is inserting it into a machine basic block. If 505 /// this is true for the instruction, it basically means that it is a pseudo 506 /// instruction used at SelectionDAG time that is expanded out into magic code 507 /// by the target when MachineInstrs are formed. 508 /// 509 /// If this is true, the TargetLoweringInfo::InsertAtEndOfBasicBlock method 510 /// is used to insert this into the MachineBasicBlock. usesCustomInsertionHook()511 bool usesCustomInsertionHook() const { 512 return Flags & (1ULL << MCID::UsesCustomInserter); 513 } 514 515 /// Return true if this instruction requires *adjustment* after 516 /// instruction selection by calling a target hook. For example, this can be 517 /// used to fill in ARM 's' optional operand depending on whether the 518 /// conditional flag register is used. hasPostISelHook()519 bool hasPostISelHook() const { return Flags & (1ULL << MCID::HasPostISelHook); } 520 521 /// Returns true if this instruction is a candidate for remat. This 522 /// flag is only used in TargetInstrInfo method isTriviallyRematerializable. 523 /// 524 /// If this flag is set, the isReallyTriviallyReMaterializable() method is 525 /// called to verify the instruction is really rematerializable. isRematerializable()526 bool isRematerializable() const { 527 return Flags & (1ULL << MCID::Rematerializable); 528 } 529 530 /// Returns true if this instruction has the same cost (or less) than a 531 /// move instruction. This is useful during certain types of optimizations 532 /// (e.g., remat during two-address conversion or machine licm) where we would 533 /// like to remat or hoist the instruction, but not if it costs more than 534 /// moving the instruction into the appropriate register. Note, we are not 535 /// marking copies from and to the same register class with this flag. 536 /// 537 /// This method could be called by interface TargetInstrInfo::isAsCheapAsAMove 538 /// for different subtargets. isAsCheapAsAMove()539 bool isAsCheapAsAMove() const { return Flags & (1ULL << MCID::CheapAsAMove); } 540 541 /// Returns true if this instruction source operands have special 542 /// register allocation requirements that are not captured by the operand 543 /// register classes. e.g. ARM::STRD's two source registers must be an even / 544 /// odd pair, ARM::STM registers have to be in ascending order. Post-register 545 /// allocation passes should not attempt to change allocations for sources of 546 /// instructions with this flag. hasExtraSrcRegAllocReq()547 bool hasExtraSrcRegAllocReq() const { 548 return Flags & (1ULL << MCID::ExtraSrcRegAllocReq); 549 } 550 551 /// Returns true if this instruction def operands have special register 552 /// allocation requirements that are not captured by the operand register 553 /// classes. e.g. ARM::LDRD's two def registers must be an even / odd pair, 554 /// ARM::LDM registers have to be in ascending order. Post-register 555 /// allocation passes should not attempt to change allocations for definitions 556 /// of instructions with this flag. hasExtraDefRegAllocReq()557 bool hasExtraDefRegAllocReq() const { 558 return Flags & (1ULL << MCID::ExtraDefRegAllocReq); 559 } 560 561 /// Return a list of registers that are potentially read by any 562 /// instance of this machine instruction. For example, on X86, the "adc" 563 /// instruction adds two register operands and adds the carry bit in from the 564 /// flags register. In this case, the instruction is marked as implicitly 565 /// reading the flags. Likewise, the variable shift instruction on X86 is 566 /// marked as implicitly reading the 'CL' register, which it always does. implicit_uses()567 ArrayRef<MCPhysReg> implicit_uses() const { 568 auto ImplicitOps = 569 reinterpret_cast<const MCPhysReg *>(this + Opcode + 1) + ImplicitOffset; 570 return {ImplicitOps, NumImplicitUses}; 571 } 572 573 /// Return a list of registers that are potentially written by any 574 /// instance of this machine instruction. For example, on X86, many 575 /// instructions implicitly set the flags register. In this case, they are 576 /// marked as setting the FLAGS. Likewise, many instructions always deposit 577 /// their result in a physical register. For example, the X86 divide 578 /// instruction always deposits the quotient and remainder in the EAX/EDX 579 /// registers. For that instruction, this will return a list containing the 580 /// EAX/EDX/EFLAGS registers. implicit_defs()581 ArrayRef<MCPhysReg> implicit_defs() const { 582 auto ImplicitOps = 583 reinterpret_cast<const MCPhysReg *>(this + Opcode + 1) + ImplicitOffset; 584 return {ImplicitOps + NumImplicitUses, NumImplicitDefs}; 585 } 586 587 /// Return true if this instruction implicitly 588 /// uses the specified physical register. hasImplicitUseOfPhysReg(MCRegister Reg)589 bool hasImplicitUseOfPhysReg(MCRegister Reg) const { 590 return is_contained(implicit_uses(), Reg); 591 } 592 593 /// Return true if this instruction implicitly 594 /// defines the specified physical register. 595 LLVM_ABI bool 596 hasImplicitDefOfPhysReg(MCRegister Reg, 597 const MCRegisterInfo *MRI = nullptr) const; 598 599 /// Return the scheduling class for this instruction. The 600 /// scheduling class is an index into the InstrItineraryData table. This 601 /// returns zero if there is no known scheduling information for the 602 /// instruction. getSchedClass()603 unsigned getSchedClass() const { return SchedClass; } 604 605 /// Return the number of bytes in the encoding of this instruction, 606 /// or zero if the encoding size cannot be known from the opcode. getSize()607 unsigned getSize() const { return Size; } 608 609 /// Find the index of the first operand in the 610 /// operand list that is used to represent the predicate. It returns -1 if 611 /// none is found. findFirstPredOperandIdx()612 int findFirstPredOperandIdx() const { 613 if (isPredicable()) { 614 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) 615 if (operands()[i].isPredicate()) 616 return i; 617 } 618 return -1; 619 } 620 621 /// Return true if this instruction defines the specified physical 622 /// register, either explicitly or implicitly. 623 LLVM_ABI bool hasDefOfPhysReg(const MCInst &MI, MCRegister Reg, 624 const MCRegisterInfo &RI) const; 625 }; 626 627 } // end namespace llvm 628 629 #endif 630