MCInstrDesc.h 26 KB

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