1 //===- HexagonMCInstrInfo.cpp - Hexagon sub-class of MCInst ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Utility functions for Hexagon specific MCInst queries
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H
15 #define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H
17 #include "llvm/MC/MCInst.h"
18 #include "llvm/MC/MCInstrInfo.h"
28 enum class MemAccessSize;
30 namespace HexagonMCInstrInfo {
31 size_t const innerLoopOffset = 0;
32 int64_t const innerLoopMask = 1 << innerLoopOffset;
34 size_t const outerLoopOffset = 1;
35 int64_t const outerLoopMask = 1 << outerLoopOffset;
37 size_t const bundleInstructionsOffset = 1;
39 // Returns the number of instructions in the bundle
40 size_t bundleSize(MCInst const &MCI);
42 // Returns a iterator range of instructions in this bundle
43 iterator_range<MCInst::const_iterator> bundleInstructions(MCInst const &MCI);
45 // Return memory access size
46 HexagonII::MemAccessSize getAccessSize(MCInstrInfo const &MCII,
49 // Return number of bits in the constant extended operand.
50 unsigned getBitCount(MCInstrInfo const &MCII, MCInst const &MCI);
52 // Return constant extended operand number.
53 unsigned short getCExtOpNum(MCInstrInfo const &MCII, MCInst const &MCI);
55 MCInstrDesc const &getDesc(MCInstrInfo const &MCII, MCInst const &MCI);
57 // Return the implicit alignment of the extendable operand
58 unsigned getExtentAlignment(MCInstrInfo const &MCII, MCInst const &MCI);
60 // Return the number of logical bits of the extendable operand
61 unsigned getExtentBits(MCInstrInfo const &MCII, MCInst const &MCI);
63 // Return the max value that a constant extendable operand can have
64 // without being extended.
65 int getMaxValue(MCInstrInfo const &MCII, MCInst const &MCI);
67 // Return the min value that a constant extendable operand can have
68 // without being extended.
69 int getMinValue(MCInstrInfo const &MCII, MCInst const &MCI);
71 // Return instruction name
72 char const *getName(MCInstrInfo const &MCII, MCInst const &MCI);
74 // Return the operand index for the new value.
75 unsigned short getNewValueOp(MCInstrInfo const &MCII, MCInst const &MCI);
77 // Return the operand that consumes or produces a new value.
78 MCOperand const &getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI);
80 // Return the Hexagon ISA class for the insn.
81 unsigned getType(MCInstrInfo const &MCII, MCInst const &MCI);
83 // Return whether the instruction is a legal new-value producer.
84 bool hasNewValue(MCInstrInfo const &MCII, MCInst const &MCI);
86 // Returns whether this MCInst is a wellformed bundle
87 bool isBundle(MCInst const &MCI);
89 // Return whether the insn is an actual insn.
90 bool isCanon(MCInstrInfo const &MCII, MCInst const &MCI);
92 // Return whether the instruction needs to be constant extended.
93 bool isConstExtended(MCInstrInfo const &MCII, MCInst const &MCI);
95 // Return true if the insn may be extended based on the operand value.
96 bool isExtendable(MCInstrInfo const &MCII, MCInst const &MCI);
98 // Return whether the instruction must be always extended.
99 bool isExtended(MCInstrInfo const &MCII, MCInst const &MCI);
101 // Returns whether this instruction is an immediate extender
102 bool isImmext(MCInst const &MCI);
104 // Returns whether this bundle is an endloop0
105 bool isInnerLoop(MCInst const &MCI);
107 // Return whether the insn is a new-value consumer.
108 bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI);
110 // Return true if the operand can be constant extended.
111 bool isOperandExtended(MCInstrInfo const &MCII, MCInst const &MCI,
112 unsigned short OperandNum);
114 // Returns whether this bundle is an endloop1
115 bool isOuterLoop(MCInst const &MCI);
117 // Return whether this instruction is predicated
118 bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI);
120 // Return whether the predicate sense is true
121 bool isPredicatedTrue(MCInstrInfo const &MCII, MCInst const &MCI);
123 // Return whether the insn is a prefix.
124 bool isPrefix(MCInstrInfo const &MCII, MCInst const &MCI);
126 // Return whether the insn is solo, i.e., cannot be in a packet.
127 bool isSolo(MCInstrInfo const &MCII, MCInst const &MCI);
129 // Pad the bundle with nops to satisfy endloop requirements
130 void padEndloop(MCInst &MCI);
132 // Marks a bundle as endloop0
133 void setInnerLoop(MCInst &MCI);
135 // Marks a bundle as endloop1
136 void setOuterLoop(MCInst &MCI);
140 #endif // LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H