LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HexagonMCInst.cpp
Go to the documentation of this file.
1 //===- HexagonMCInst.cpp - Hexagon sub-class of MCInst --------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This class extends MCInst to allow some Hexagon VLIW annotations.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "HexagonInstrInfo.h"
18 
19 using namespace llvm;
20 
21 // Return the slots used by the insn.
23  const HexagonInstrInfo* QII = TM->getInstrInfo();
24  const InstrItineraryData* II = TM->getInstrItineraryData();
25  const InstrStage*
26  IS = II->beginStage(QII->get(this->getOpcode()).getSchedClass());
27 
28  return (IS->getUnits());
29 }
30 
31 // Return the Hexagon ISA class for the insn.
32 unsigned HexagonMCInst::getType() const {
33  const uint64_t F = MCID->TSFlags;
34 
35  return ((F >> HexagonII::TypePos) & HexagonII::TypeMask);
36 }
37 
38 // Return whether the insn is an actual insn.
39 bool HexagonMCInst::isCanon() const {
40  return (!MCID->isPseudo() &&
41  !isPrefix() &&
43 }
44 
45 // Return whether the insn is a prefix.
47  return (getType() == HexagonII::TypePREFIX);
48 }
49 
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);
54 }
55 
56 // Return whether the insn is a new-value consumer.
58  const uint64_t F = MCID->TSFlags;
60 }
61 
62 // Return whether the instruction is a legal new-value producer.
64  const uint64_t F = MCID->TSFlags;
66 }
67 
68 // Return the operand that consumes or produces a new value.
70  const uint64_t F = MCID->TSFlags;
71  const unsigned O = (F >> HexagonII::NewValueOpPos) &
73  const MCOperand& MCO = getOperand(O);
74 
75  assert ((isNewValue() || hasNewValue()) && MCO.isReg());
76  return (MCO);
77 }
78 
79 // Return whether the instruction needs to be constant extended.
80 // 1) Always return true if the instruction has 'isExtended' flag set.
81 //
82 // isExtendable:
83 // 2) For immediate extended operands, return true only if the value is
84 // out-of-range.
85 // 3) For global address, always return true.
86 
88  if (isExtended())
89  return true;
90 
91  if (!isExtendable())
92  return false;
93 
94  short ExtOpNum = getCExtOpNum();
95  int MinValue = getMinValue();
96  int MaxValue = getMaxValue();
97  const MCOperand& MO = getOperand(ExtOpNum);
98 
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.
105  if (MO.isExpr())
106  return true;
107 
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");
111 
112  int ImmValue = MO.getImm();
113  return (ImmValue < MinValue || ImmValue > MaxValue);
114 }
115 
116 // Return whether the instruction must be always extended.
117 bool HexagonMCInst::isExtended(void) const {
118  const uint64_t F = MCID->TSFlags;
120 }
121 
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;
126 }
127 
128 // Return number of bits in the constant extended operand.
129 unsigned HexagonMCInst::getBitCount(void) const {
130  const uint64_t F = MCID->TSFlags;
132 }
133 
134 // Return constant extended operand number.
135 unsigned short HexagonMCInst::getCExtOpNum(void) const {
136  const uint64_t F = MCID->TSFlags;
138 }
139 
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;
144  == OperandNum;
145 }
146 
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)
153  unsigned bits = (F >> HexagonII::ExtentBitsPos)
155 
156  if (isSigned) // if value is signed
157  return -1 << (bits - 1);
158  else
159  return 0;
160 }
161 
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)
168  unsigned bits = (F >> HexagonII::ExtentBitsPos)
170 
171  if (isSigned) // if value is signed
172  return ~(-1 << (bits - 1));
173  else
174  return ~(-1 << bits);
175 }
const MCOperand & getNewValue() const
bool hasNewValue() const
unsigned short getCExtOpNum(void) const
bool isReg() const
Definition: MCInst.h:56
F(f)
bool isConstExtended() const
const InstrStage * beginStage(unsigned ItinClassIndx) const
unsigned getUnits(const HexagonTargetMachine *TM) const
unsigned getUnits() const
getUnits - returns the choice of FUs
bool isSolo() const
bool isImm() const
Definition: MCInst.h:57
virtual const InstrItineraryData * getInstrItineraryData() const
bool isExpr() const
Definition: MCInst.h:59
bool isPseudo() const
Return true if this is a pseudo instruction that doesn't correspond to a real machine instruction...
Definition: MCInstrDesc.h:222
virtual const HexagonInstrInfo * getInstrInfo() const
unsigned getType() const
int64_t getImm() const
Definition: MCInst.h:74
bool isCanon() const
unsigned getBitCount(void) const
bool isPrefix() const
bool isNewValue() const
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:163