MCInstrDesc.h 25 KB

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