LLVM  4.0.0
HexagonMCInstrInfo.h
Go to the documentation of this file.
1 //===- HexagonMCInstrInfo.cpp - Utility functions on Hexagon MCInsts ------===//
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 // Utility functions for Hexagon specific MCInst queries
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H
15 #define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H
16 
17 #include "HexagonMCExpr.h"
18 #include "llvm/MC/MCInst.h"
19 
20 namespace llvm {
21 class HexagonMCChecker;
22 class MCContext;
23 class MCInstrDesc;
24 class MCInstrInfo;
25 class MCInst;
26 class MCOperand;
27 class MCSubtargetInfo;
28 namespace HexagonII {
29 enum class MemAccessSize;
30 }
32 public:
34  DuplexCandidate(unsigned i, unsigned j, unsigned iClass)
35  : packetIndexI(i), packetIndexJ(j), iClass(iClass) {}
36 };
37 namespace HexagonMCInstrInfo {
38 size_t const innerLoopOffset = 0;
39 int64_t const innerLoopMask = 1 << innerLoopOffset;
40 
41 size_t const outerLoopOffset = 1;
42 int64_t const outerLoopMask = 1 << outerLoopOffset;
43 
44 // do not reorder memory load/stores by default load/stores are re-ordered
45 // and by default loads can be re-ordered
46 size_t const memReorderDisabledOffset = 2;
48 
49 // allow re-ordering of memory stores by default stores cannot be re-ordered
52 
53 size_t const bundleInstructionsOffset = 1;
54 
55 void addConstant(MCInst &MI, uint64_t Value, MCContext &Context);
56 void addConstExtender(MCContext &Context, MCInstrInfo const &MCII, MCInst &MCB,
57  MCInst const &MCI);
58 
59 // Returns a iterator range of instructions in this bundle
61 
62 // Returns the number of instructions in the bundle
63 size_t bundleSize(MCInst const &MCI);
64 
65 // Put the packet in to canonical form, compound, duplex, pad, and shuffle
66 bool canonicalizePacket(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
67  MCContext &Context, MCInst &MCB,
68  HexagonMCChecker *Checker);
69 
70 // Clamp off upper 26 bits of extendable operand for emission
71 void clampExtended(MCInstrInfo const &MCII, MCContext &Context, MCInst &MCI);
72 
74 
75 // Return the extender for instruction at Index or nullptr if none
76 MCInst const *extenderForIndex(MCInst const &MCB, size_t Index);
77 void extendIfNeeded(MCContext &Context, MCInstrInfo const &MCII, MCInst &MCB,
78  MCInst const &MCI);
79 
80 // Create a duplex instruction given the two subinsts
81 MCInst *deriveDuplex(MCContext &Context, unsigned iClass, MCInst const &inst0,
82  MCInst const &inst1);
83 MCInst deriveExtender(MCInstrInfo const &MCII, MCInst const &Inst,
84  MCOperand const &MO);
85 
86 // Convert this instruction in to a duplex subinst
87 MCInst deriveSubInst(MCInst const &Inst);
88 
89 // Return the extender for instruction at Index or nullptr if none
90 MCInst const *extenderForIndex(MCInst const &MCB, size_t Index);
91 
92 // Return memory access size
94  MCInst const &MCI);
95 
96 // Return number of bits in the constant extended operand.
97 unsigned getBitCount(MCInstrInfo const &MCII, MCInst const &MCI);
98 
99 // Return constant extended operand number.
100 unsigned short getCExtOpNum(MCInstrInfo const &MCII, MCInst const &MCI);
101 
102 MCInstrDesc const &getDesc(MCInstrInfo const &MCII, MCInst const &MCI);
103 
104 // Return which duplex group this instruction belongs to
105 unsigned getDuplexCandidateGroup(MCInst const &MI);
106 
107 // Return a list of all possible instruction duplex combinations
109  MCInst const &MCB);
110 unsigned getDuplexRegisterNumbering(unsigned Reg);
111 
112 MCExpr const &getExpr(MCExpr const &Expr);
113 
114 // Return the index of the extendable operand
115 unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI);
116 
117 // Return a reference to the extendable operand
118 MCOperand const &getExtendableOperand(MCInstrInfo const &MCII,
119  MCInst const &MCI);
120 
121 // Return the implicit alignment of the extendable operand
122 unsigned getExtentAlignment(MCInstrInfo const &MCII, MCInst const &MCI);
123 
124 // Return the number of logical bits of the extendable operand
125 unsigned getExtentBits(MCInstrInfo const &MCII, MCInst const &MCI);
126 
127 // Return the max value that a constant extendable operand can have
128 // without being extended.
129 int getMaxValue(MCInstrInfo const &MCII, MCInst const &MCI);
130 
131 // Return the min value that a constant extendable operand can have
132 // without being extended.
133 int getMinValue(MCInstrInfo const &MCII, MCInst const &MCI);
134 
135 // Return instruction name
136 StringRef getName(MCInstrInfo const &MCII, MCInst const &MCI);
137 
138 // Return the operand index for the new value.
139 unsigned short getNewValueOp(MCInstrInfo const &MCII, MCInst const &MCI);
140 
141 // Return the operand that consumes or produces a new value.
142 MCOperand const &getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI);
143 unsigned short getNewValueOp2(MCInstrInfo const &MCII, MCInst const &MCI);
144 MCOperand const &getNewValueOperand2(MCInstrInfo const &MCII,
145  MCInst const &MCI);
146 
147 int getSubTarget(MCInstrInfo const &MCII, MCInst const &MCI);
148 
149 // Return the Hexagon ISA class for the insn.
150 unsigned getType(MCInstrInfo const &MCII, MCInst const &MCI);
151 
152 /// Return the slots used by the insn.
153 unsigned getUnits(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
154  MCInst const &MCI);
155 
156 // Does the packet have an extender for the instruction at Index
157 bool hasExtenderForIndex(MCInst const &MCB, size_t Index);
158 
159 bool hasImmExt(MCInst const &MCI);
160 
161 // Return whether the instruction is a legal new-value producer.
162 bool hasNewValue(MCInstrInfo const &MCII, MCInst const &MCI);
163 bool hasNewValue2(MCInstrInfo const &MCII, MCInst const &MCI);
164 
165 // Return the instruction at Index
166 MCInst const &instruction(MCInst const &MCB, size_t Index);
167 
168 // Returns whether this MCInst is a wellformed bundle
169 bool isBundle(MCInst const &MCI);
170 
171 // Return whether the insn is an actual insn.
172 bool isCanon(MCInstrInfo const &MCII, MCInst const &MCI);
173 bool isCofMax1(MCInstrInfo const &MCII, MCInst const &MCI);
174 bool isCompound(MCInstrInfo const &MCII, MCInst const &MCI);
175 
176 // Return the duplex iclass given the two duplex classes
177 unsigned iClassOfDuplexPair(unsigned Ga, unsigned Gb);
178 
179 int64_t minConstant(MCInst const &MCI, size_t Index);
180 template <unsigned N, unsigned S>
181 bool inRange(MCInst const &MCI, size_t Index) {
182  return isShiftedUInt<N, S>(minConstant(MCI, Index));
183 }
184 template <unsigned N, unsigned S>
185 bool inSRange(MCInst const &MCI, size_t Index) {
186  return isShiftedInt<N, S>(minConstant(MCI, Index));
187 }
188 template <unsigned N> bool inRange(MCInst const &MCI, size_t Index) {
189  return isUInt<N>(minConstant(MCI, Index));
190 }
191 
192 // Return whether the instruction needs to be constant extended.
193 bool isConstExtended(MCInstrInfo const &MCII, MCInst const &MCI);
194 
195 // Is this double register suitable for use in a duplex subinst
196 bool isDblRegForSubInst(unsigned Reg);
197 
198 // Is this a duplex instruction
199 bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI);
200 
201 // Can these instructions be duplexed
202 bool isDuplexPair(MCInst const &MIa, MCInst const &MIb);
203 
204 // Can these duplex classes be combine in to a duplex instruction
205 bool isDuplexPairMatch(unsigned Ga, unsigned Gb);
206 
207 // Return true if the insn may be extended based on the operand value.
208 bool isExtendable(MCInstrInfo const &MCII, MCInst const &MCI);
209 
210 // Return whether the instruction must be always extended.
211 bool isExtended(MCInstrInfo const &MCII, MCInst const &MCI);
212 
213 /// Return whether it is a floating-point insn.
214 bool isFloat(MCInstrInfo const &MCII, MCInst const &MCI);
215 
216 // Returns whether this instruction is an immediate extender
217 bool isImmext(MCInst const &MCI);
218 
219 // Returns whether this bundle is an endloop0
220 bool isInnerLoop(MCInst const &MCI);
221 
222 // Is this an integer register
223 bool isIntReg(unsigned Reg);
224 
225 // Is this register suitable for use in a duplex subinst
226 bool isIntRegForSubInst(unsigned Reg);
227 bool isMemReorderDisabled(MCInst const &MCI);
228 bool isMemStoreReorderEnabled(MCInst const &MCI);
229 
230 // Return whether the insn is a new-value consumer.
231 bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI);
232 
233 // Return true if the operand can be constant extended.
234 bool isOperandExtended(MCInstrInfo const &MCII, MCInst const &MCI,
235  unsigned short OperandNum);
236 
237 // Can these two instructions be duplexed
238 bool isOrderedDuplexPair(MCInstrInfo const &MCII, MCInst const &MIa,
239  bool ExtendedA, MCInst const &MIb, bool ExtendedB,
240  bool bisReversable);
241 
242 // Returns whether this bundle is an endloop1
243 bool isOuterLoop(MCInst const &MCI);
244 
245 // Return whether this instruction is predicated
246 bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI);
247 bool isPredicateLate(MCInstrInfo const &MCII, MCInst const &MCI);
248 bool isPredicatedNew(MCInstrInfo const &MCII, MCInst const &MCI);
249 
250 // Return whether the predicate sense is true
251 bool isPredicatedTrue(MCInstrInfo const &MCII, MCInst const &MCI);
252 
253 // Is this a predicate register
254 bool isPredReg(unsigned Reg);
255 
256 // Return whether the insn is a prefix.
257 bool isPrefix(MCInstrInfo const &MCII, MCInst const &MCI);
258 
259 // Return whether the insn is solo, i.e., cannot be in a packet.
260 bool isSolo(MCInstrInfo const &MCII, MCInst const &MCI);
261 
262 /// Return whether the insn can be packaged only with A and X-type insns.
263 bool isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI);
264 
265 /// Return whether the insn can be packaged only with an A-type insn in slot #1.
266 bool isSoloAin1(MCInstrInfo const &MCII, MCInst const &MCI);
267 bool isSubInstruction(MCInst const &MCI);
268 bool isVector(MCInstrInfo const &MCII, MCInst const &MCI);
269 bool mustExtend(MCExpr const &Expr);
270 bool mustNotExtend(MCExpr const &Expr);
271 
272 // Pad the bundle with nops to satisfy endloop requirements
273 void padEndloop(MCContext &Context, MCInst &MCI);
274 
275 bool prefersSlot3(MCInstrInfo const &MCII, MCInst const &MCI);
276 
277 // Replace the instructions inside MCB, represented by Candidate
278 void replaceDuplex(MCContext &Context, MCInst &MCB, DuplexCandidate Candidate);
279 
280 bool s23_2_reloc(MCExpr const &Expr);
281 // Marks a bundle as endloop0
282 void setInnerLoop(MCInst &MCI);
283 void setMemReorderDisabled(MCInst &MCI);
285 void setMustExtend(MCExpr const &Expr, bool Val = true);
286 void setMustNotExtend(MCExpr const &Expr, bool Val = true);
287 void setS23_2_reloc(MCExpr const &Expr, bool Val = true);
288 
289 // Marks a bundle as endloop1
290 void setOuterLoop(MCInst &MCI);
291 
292 // Would duplexing this instruction create a requirement to extend
293 bool subInstWouldBeExtended(MCInst const &potentialDuplex);
294 unsigned SubregisterBit(unsigned Consumer, unsigned Producer,
295  unsigned Producer2);
296 
297 // Attempt to find and replace compound pairs
298 void tryCompound(MCInstrInfo const &MCII, MCContext &Context, MCInst &MCI);
299 }
300 }
301 
302 #endif // LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H
bool isSoloAin1(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn can be packaged only with an A-type insn in slot #1.
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned short getNewValueOp(MCInstrInfo const &MCII, MCInst const &MCI)
bool subInstWouldBeExtended(MCInst const &potentialDuplex)
LLVMContext & Context
bool inSRange(MCInst const &MCI, size_t Index)
size_t i
MCInst const * extenderForIndex(MCInst const &MCB, size_t Index)
unsigned getBitCount(MCInstrInfo const &MCII, MCInst const &MCI)
void tryCompound(MCInstrInfo const &MCII, MCContext &Context, MCInst &MCI)
tryCompound - Given a bundle check for compound insns when one is found update the contents fo the bu...
bool isDuplexPair(MCInst const &MIa, MCInst const &MIb)
Symmetrical. See if these two instructions are fit for duplex pair.
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:163
bool isIntRegForSubInst(unsigned Reg)
bool isBundle(MCInst const &MCI)
bool isSolo(MCInstrInfo const &MCII, MCInst const &MCI)
bool isPredicatedNew(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn is newly predicated.
bool isSubInstruction(MCInst const &MCI)
bool isDblRegForSubInst(unsigned Reg)
MCInst deriveExtender(MCInstrInfo const &MCII, MCInst const &Inst, MCOperand const &MO)
bool isOuterLoop(MCInst const &MCI)
bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
bool isMemStoreReorderEnabled(MCInst const &MCI)
bool isImmext(MCInst const &MCI)
MCOperand const & getNewValueOperand2(MCInstrInfo const &MCII, MCInst const &MCI)
MCInst const & instruction(MCInst const &MCB, size_t Index)
bool isCofMax1(MCInstrInfo const &MCII, MCInst const &MCI)
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
Reg
All possible values of the reg field in the ModR/M byte.
DuplexCandidate(unsigned i, unsigned j, unsigned iClass)
void padEndloop(MCContext &Context, MCInst &MCI)
StringRef getName(MCInstrInfo const &MCII, MCInst const &MCI)
void replaceDuplex(MCContext &Context, MCInst &MCB, DuplexCandidate Candidate)
void setMemReorderDisabled(MCInst &MCI)
Context object for machine code objects.
Definition: MCContext.h:51
bool isOperandExtended(MCInstrInfo const &MCII, MCInst const &MCI, unsigned short OperandNum)
size_t const memReorderDisabledOffset
int getMaxValue(MCInstrInfo const &MCII, MCInst const &MCI)
void setS23_2_reloc(MCExpr const &Expr, bool Val=true)
bool canonicalizePacket(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCContext &Context, MCInst &MCB, HexagonMCChecker *Checker)
unsigned short getNewValueOp2(MCInstrInfo const &MCII, MCInst const &MCI)
Return the new value or the newly produced value.
bool hasNewValue2(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn produces a second value.
SmallVector< DuplexCandidate, 8 > getDuplexPossibilties(MCInstrInfo const &MCII, MCInst const &MCB)
void extendIfNeeded(MCContext &Context, MCInstrInfo const &MCII, MCInst &MCB, MCInst const &MCI)
bool s23_2_reloc(MCExpr const &Expr)
void setMustExtend(MCExpr const &Expr, bool Val=true)
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:150
bool isPrefix(MCInstrInfo const &MCII, MCInst const &MCI)
bool isDuplexPairMatch(unsigned Ga, unsigned Gb)
void setMemStoreReorderEnabled(MCInst &MCI)
bool inRange(MCInst const &MCI, size_t Index)
bool isCompound(MCInstrInfo const &MCII, MCInst const &MCI)
int getMinValue(MCInstrInfo const &MCII, MCInst const &MCI)
bool mustExtend(MCExpr const &Expr)
unsigned getDuplexCandidateGroup(MCInst const &MI)
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
int64_t const memReorderDisabledMask
MCExpr const & getExpr(MCExpr const &Expr)
iterator_range< MCInst::const_iterator > bundleInstructions(MCInst const &MCI)
unsigned SubregisterBit(unsigned Consumer, unsigned Producer, unsigned Producer2)
void clampExtended(MCInstrInfo const &MCII, MCContext &Context, MCInst &MCI)
bool prefersSlot3(MCInstrInfo const &MCII, MCInst const &MCI)
bool isCanon(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI)
int64_t const memStoreReorderEnabledMask
size_t const bundleInstructionsOffset
bool isExtendable(MCInstrInfo const &MCII, MCInst const &MCI)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
bool isVector(MCInstrInfo const &MCII, MCInst const &MCI)
HexagonII::MemAccessSize getAccessSize(MCInstrInfo const &MCII, MCInst const &MCI)
int64_t minConstant(MCInst const &MCI, size_t Index)
bool isOrderedDuplexPair(MCInstrInfo const &MCII, MCInst const &MIa, bool ExtendedA, MCInst const &MIb, bool ExtendedB, bool bisReversable)
non-Symmetrical. See if these two instructions are fit for duplex pair.
A range adaptor for a pair of iterators.
bool isMemReorderDisabled(MCInst const &MCI)
bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI)
bool isExtended(MCInstrInfo const &MCII, MCInst const &MCI)
MCInst deriveSubInst(MCInst const &Inst)
bool isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn can be packaged only with A and X-type insns.
bool hasExtenderForIndex(MCInst const &MCB, size_t Index)
MCSubtargetInfo - Generic base class for all target subtargets.
MCInstrDesc const & getDesc(MCInstrInfo const &MCII, MCInst const &MCI)
void setMustNotExtend(MCExpr const &Expr, bool Val=true)
size_t bundleSize(MCInst const &MCI)
int getSubTarget(MCInstrInfo const &MCII, MCInst const &MCI)
size_t const memStoreReorderEnabledOffset
bool hasImmExt(MCInst const &MCI)
bool isInnerLoop(MCInst const &MCI)
bool isFloat(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether it is a floating-point insn.
bool isPredicateLate(MCInstrInfo const &MCII, MCInst const &MCI)
LLVM Value Representation.
Definition: Value.h:71
Check for a valid bundle.
void addConstExtender(MCContext &Context, MCInstrInfo const &MCII, MCInst &MCB, MCInst const &MCI)
unsigned getUnits(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCInst const &MCI)
Return the slots used by the insn.
bool isConstExtended(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getDuplexRegisterNumbering(unsigned Reg)
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
MCInst * deriveDuplex(MCContext &Context, unsigned iClass, MCInst const &inst0, MCInst const &inst1)
bool hasNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getType(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getExtentAlignment(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned short getCExtOpNum(MCInstrInfo const &MCII, MCInst const &MCI)
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:33
bool mustNotExtend(MCExpr const &Expr)
unsigned iClassOfDuplexPair(unsigned Ga, unsigned Gb)
bool isPredicatedTrue(MCInstrInfo const &MCII, MCInst const &MCI)
MCOperand const & getExtendableOperand(MCInstrInfo const &MCII, MCInst const &MCI)
void addConstant(MCInst &MI, uint64_t Value, MCContext &Context)
MCOperand const & getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getExtentBits(MCInstrInfo const &MCII, MCInst const &MCI)