MCInstrDesc.h 26 KB

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