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