1 //===- HexagonMCInst.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 // This class extends MCInst to allow some Hexagon VLIW annotations.
12 //===----------------------------------------------------------------------===//
14 #include "HexagonInstrInfo.h"
15 #include "MCTargetDesc/HexagonBaseInfo.h"
16 #include "MCTargetDesc/HexagonMCInst.h"
17 #include "MCTargetDesc/HexagonMCTargetDesc.h"
21 // Return the slots used by the insn.
22 unsigned HexagonMCInst::getUnits(const HexagonTargetMachine* TM) const {
23 const HexagonInstrInfo *QII = TM->getSubtargetImpl()->getInstrInfo();
24 const InstrItineraryData *II =
25 TM->getSubtargetImpl()->getInstrItineraryData();
27 IS = II->beginStage(QII->get(this->getOpcode()).getSchedClass());
29 return (IS->getUnits());
32 // Return the Hexagon ISA class for the insn.
33 unsigned HexagonMCInst::getType() const {
34 const uint64_t F = MCID->TSFlags;
36 return ((F >> HexagonII::TypePos) & HexagonII::TypeMask);
39 // Return whether the insn is an actual insn.
40 bool HexagonMCInst::isCanon() const {
41 return (!MCID->isPseudo() &&
43 getType() != HexagonII::TypeENDLOOP);
46 // Return whether the insn is a prefix.
47 bool HexagonMCInst::isPrefix() const {
48 return (getType() == HexagonII::TypePREFIX);
51 // Return whether the insn is solo, i.e., cannot be in a packet.
52 bool HexagonMCInst::isSolo() const {
53 const uint64_t F = MCID->TSFlags;
54 return ((F >> HexagonII::SoloPos) & HexagonII::SoloMask);
57 // Return whether the insn is a new-value consumer.
58 bool HexagonMCInst::isNewValue() const {
59 const uint64_t F = MCID->TSFlags;
60 return ((F >> HexagonII::NewValuePos) & HexagonII::NewValueMask);
63 // Return whether the instruction is a legal new-value producer.
64 bool HexagonMCInst::hasNewValue() const {
65 const uint64_t F = MCID->TSFlags;
66 return ((F >> HexagonII::hasNewValuePos) & HexagonII::hasNewValueMask);
69 // Return the operand that consumes or produces a new value.
70 const MCOperand& HexagonMCInst::getNewValue() const {
71 const uint64_t F = MCID->TSFlags;
72 const unsigned O = (F >> HexagonII::NewValueOpPos) &
73 HexagonII::NewValueOpMask;
74 const MCOperand& MCO = getOperand(O);
76 assert ((isNewValue() || hasNewValue()) && MCO.isReg());
80 // Return whether the instruction needs to be constant extended.
81 // 1) Always return true if the instruction has 'isExtended' flag set.
84 // 2) For immediate extended operands, return true only if the value is
86 // 3) For global address, always return true.
88 bool HexagonMCInst::isConstExtended(void) const {
95 short ExtOpNum = getCExtOpNum();
96 int MinValue = getMinValue();
97 int MaxValue = getMaxValue();
98 const MCOperand& MO = getOperand(ExtOpNum);
100 // We could be using an instruction with an extendable immediate and shoehorn
101 // a global address into it. If it is a global address it will be constant
102 // extended. We do this for COMBINE.
103 // We currently only handle isGlobal() because it is the only kind of
104 // object we are going to end up with here for now.
105 // In the future we probably should add isSymbol(), etc.
109 // If the extendable operand is not 'Immediate' type, the instruction should
110 // have 'isExtended' flag set.
111 assert(MO.isImm() && "Extendable operand must be Immediate type");
113 int ImmValue = MO.getImm();
114 return (ImmValue < MinValue || ImmValue > MaxValue);
117 // Return whether the instruction must be always extended.
118 bool HexagonMCInst::isExtended(void) const {
119 const uint64_t F = MCID->TSFlags;
120 return (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask;
123 // Return true if the instruction may be extended based on the operand value.
124 bool HexagonMCInst::isExtendable(void) const {
125 const uint64_t F = MCID->TSFlags;
126 return (F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask;
129 // Return number of bits in the constant extended operand.
130 unsigned HexagonMCInst::getBitCount(void) const {
131 const uint64_t F = MCID->TSFlags;
132 return ((F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask);
135 // Return constant extended operand number.
136 unsigned short HexagonMCInst::getCExtOpNum(void) const {
137 const uint64_t F = MCID->TSFlags;
138 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask);
141 // Return whether the operand can be constant extended.
142 bool HexagonMCInst::isOperandExtended(const unsigned short OperandNum) const {
143 const uint64_t F = MCID->TSFlags;
144 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask)
148 // Return the min value that a constant extendable operand can have
149 // without being extended.
150 int HexagonMCInst::getMinValue(void) const {
151 const uint64_t F = MCID->TSFlags;
152 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
153 & HexagonII::ExtentSignedMask;
154 unsigned bits = (F >> HexagonII::ExtentBitsPos)
155 & HexagonII::ExtentBitsMask;
157 if (isSigned) // if value is signed
158 return -1 << (bits - 1);
163 // Return the max value that a constant extendable operand can have
164 // without being extended.
165 int HexagonMCInst::getMaxValue(void) const {
166 const uint64_t F = MCID->TSFlags;
167 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
168 & HexagonII::ExtentSignedMask;
169 unsigned bits = (F >> HexagonII::ExtentBitsPos)
170 & HexagonII::ExtentBitsMask;
172 if (isSigned) // if value is signed
173 return ~(-1 << (bits - 1));
175 return ~(-1 << bits);