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