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->getInstrInfo();
24 const InstrItineraryData* II = TM->getInstrItineraryData();
26 IS = II->beginStage(QII->get(this->getOpcode()).getSchedClass());
28 return (IS->getUnits());
31 // Return the Hexagon ISA class for the insn.
32 unsigned HexagonMCInst::getType() const {
33 const uint64_t F = MCID->TSFlags;
35 return ((F >> HexagonII::TypePos) & HexagonII::TypeMask);
38 // Return whether the insn is an actual insn.
39 bool HexagonMCInst::isCanon() const {
40 return (!MCID->isPseudo() &&
42 getType() != HexagonII::TypeENDLOOP);
45 // Return whether the insn is a prefix.
46 bool HexagonMCInst::isPrefix() const {
47 return (getType() == HexagonII::TypePREFIX);
50 // Return whether the insn is solo, i.e., cannot be in a packet.
51 bool HexagonMCInst::isSolo() const {
52 const uint64_t F = MCID->TSFlags;
53 return ((F >> HexagonII::SoloPos) & HexagonII::SoloMask);
56 // Return whether the insn is a new-value consumer.
57 bool HexagonMCInst::isNewValue() const {
58 const uint64_t F = MCID->TSFlags;
59 return ((F >> HexagonII::NewValuePos) & HexagonII::NewValueMask);
62 // Return whether the instruction is a legal new-value producer.
63 bool HexagonMCInst::hasNewValue() const {
64 const uint64_t F = MCID->TSFlags;
65 return ((F >> HexagonII::hasNewValuePos) & HexagonII::hasNewValueMask);
68 // Return the operand that consumes or produces a new value.
69 const MCOperand& HexagonMCInst::getNewValue() const {
70 const uint64_t F = MCID->TSFlags;
71 const unsigned O = (F >> HexagonII::NewValueOpPos) &
72 HexagonII::NewValueOpMask;
73 const MCOperand& MCO = getOperand(O);
75 assert ((isNewValue() || hasNewValue()) && MCO.isReg());
79 // Return whether the instruction needs to be constant extended.
80 // 1) Always return true if the instruction has 'isExtended' flag set.
83 // 2) For immediate extended operands, return true only if the value is
85 // 3) For global address, always return true.
87 bool HexagonMCInst::isConstExtended(void) const {
94 short ExtOpNum = getCExtOpNum();
95 int MinValue = getMinValue();
96 int MaxValue = getMaxValue();
97 const MCOperand& MO = getOperand(ExtOpNum);
99 // We could be using an instruction with an extendable immediate and shoehorn
100 // a global address into it. If it is a global address it will be constant
101 // extended. We do this for COMBINE.
102 // We currently only handle isGlobal() because it is the only kind of
103 // object we are going to end up with here for now.
104 // In the future we probably should add isSymbol(), etc.
108 // If the extendable operand is not 'Immediate' type, the instruction should
109 // have 'isExtended' flag set.
110 assert(MO.isImm() && "Extendable operand must be Immediate type");
112 int ImmValue = MO.getImm();
113 return (ImmValue < MinValue || ImmValue > MaxValue);
116 // Return whether the instruction must be always extended.
117 bool HexagonMCInst::isExtended(void) const {
118 const uint64_t F = MCID->TSFlags;
119 return (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask;
122 // Return true if the instruction may be extended based on the operand value.
123 bool HexagonMCInst::isExtendable(void) const {
124 const uint64_t F = MCID->TSFlags;
125 return (F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask;
128 // Return number of bits in the constant extended operand.
129 unsigned HexagonMCInst::getBitCount(void) const {
130 const uint64_t F = MCID->TSFlags;
131 return ((F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask);
134 // Return constant extended operand number.
135 unsigned short HexagonMCInst::getCExtOpNum(void) const {
136 const uint64_t F = MCID->TSFlags;
137 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask);
140 // Return whether the operand can be constant extended.
141 bool HexagonMCInst::isOperandExtended(const unsigned short OperandNum) const {
142 const uint64_t F = MCID->TSFlags;
143 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask)
147 // Return the min value that a constant extendable operand can have
148 // without being extended.
149 int HexagonMCInst::getMinValue(void) const {
150 const uint64_t F = MCID->TSFlags;
151 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
152 & HexagonII::ExtentSignedMask;
153 unsigned bits = (F >> HexagonII::ExtentBitsPos)
154 & HexagonII::ExtentBitsMask;
156 if (isSigned) // if value is signed
157 return -1 << (bits - 1);
162 // Return the max value that a constant extendable operand can have
163 // without being extended.
164 int HexagonMCInst::getMaxValue(void) const {
165 const uint64_t F = MCID->TSFlags;
166 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
167 & HexagonII::ExtentSignedMask;
168 unsigned bits = (F >> HexagonII::ExtentBitsPos)
169 & HexagonII::ExtentBitsMask;
171 if (isSigned) // if value is signed
172 return ~(-1 << (bits - 1));
174 return ~(-1 << bits);