[Hexagon] Alphabetical ordering of functions, NFC.
[oota-llvm.git] / lib / Target / Hexagon / MCTargetDesc / HexagonMCInstrInfo.h
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 "llvm/MC/MCInst.h"
18
19 namespace llvm {
20 class MCContext;
21 class MCInstrDesc;
22 class MCInstrInfo;
23 class MCInst;
24 class MCOperand;
25 class MCSubtargetInfo;
26 namespace HexagonII {
27 enum class MemAccessSize;
28 }
29 class DuplexCandidate {
30 public:
31   unsigned packetIndexI, packetIndexJ, iClass;
32   DuplexCandidate(unsigned i, unsigned j, unsigned iClass)
33       : packetIndexI(i), packetIndexJ(j), iClass(iClass) {}
34 };
35 namespace HexagonMCInstrInfo {
36 size_t const innerLoopOffset = 0;
37 int64_t const innerLoopMask = 1 << innerLoopOffset;
38
39 size_t const outerLoopOffset = 1;
40 int64_t const outerLoopMask = 1 << outerLoopOffset;
41
42 size_t const bundleInstructionsOffset = 1;
43
44 // Returns a iterator range of instructions in this bundle
45 iterator_range<MCInst::const_iterator> bundleInstructions(MCInst const &MCI);
46
47 // Returns the number of instructions in the bundle
48 size_t bundleSize(MCInst const &MCI);
49
50 // Create a duplex instruction given the two subinsts
51 MCInst *deriveDuplex(MCContext &Context, unsigned iClass, MCInst const &inst0,
52                      MCInst const &inst1);
53
54 // Convert this instruction in to a duplex subinst
55 MCInst deriveSubInst(MCInst const &Inst);
56
57 // Return the extender for instruction at Index or nullptr if none
58 MCInst const *extenderForIndex(MCInst const &MCB, size_t Index);
59
60 // Return memory access size
61 HexagonII::MemAccessSize getAccessSize(MCInstrInfo const &MCII,
62                                        MCInst const &MCI);
63
64 // Return number of bits in the constant extended operand.
65 unsigned getBitCount(MCInstrInfo const &MCII, MCInst const &MCI);
66
67 // Return constant extended operand number.
68 unsigned short getCExtOpNum(MCInstrInfo const &MCII, MCInst const &MCI);
69
70 MCInstrDesc const &getDesc(MCInstrInfo const &MCII, MCInst const &MCI);
71
72 // Return which duplex group this instruction belongs to
73 unsigned getDuplexCandidateGroup(MCInst const &MI);
74
75 // Return a list of all possible instruction duplex combinations
76 SmallVector<DuplexCandidate, 8> getDuplexPossibilties(MCInstrInfo const &MCII,
77                                                       MCInst const &MCB);
78
79 // Return the index of the extendable operand
80 unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI);
81
82 // Return a reference to the extendable operand
83 MCOperand const &getExtendableOperand(MCInstrInfo const &MCII,
84                                       MCInst const &MCI);
85
86 // Return the implicit alignment of the extendable operand
87 unsigned getExtentAlignment(MCInstrInfo const &MCII, MCInst const &MCI);
88
89 // Return the number of logical bits of the extendable operand
90 unsigned getExtentBits(MCInstrInfo const &MCII, MCInst const &MCI);
91
92 // Return the max value that a constant extendable operand can have
93 // without being extended.
94 int getMaxValue(MCInstrInfo const &MCII, MCInst const &MCI);
95
96 // Return the min value that a constant extendable operand can have
97 // without being extended.
98 int getMinValue(MCInstrInfo const &MCII, MCInst const &MCI);
99
100 // Return instruction name
101 char const *getName(MCInstrInfo const &MCII, MCInst const &MCI);
102
103 // Return the operand index for the new value.
104 unsigned short getNewValueOp(MCInstrInfo const &MCII, MCInst const &MCI);
105
106 // Return the operand that consumes or produces a new value.
107 MCOperand const &getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI);
108
109 int getSubTarget(MCInstrInfo const &MCII, MCInst const &MCI);
110
111 // Return the Hexagon ISA class for the insn.
112 unsigned getType(MCInstrInfo const &MCII, MCInst const &MCI);
113
114 /// Return the slots used by the insn.
115 unsigned getUnits(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
116                   MCInst const &MCI);
117
118 // Does the packet have an extender for the instruction at Index
119 bool hasExtenderForIndex(MCInst const &MCB, size_t Index);
120
121 bool hasImmExt(MCInst const &MCI);
122
123 // Return whether the instruction is a legal new-value producer.
124 bool hasNewValue(MCInstrInfo const &MCII, MCInst const &MCI);
125
126 // Return the instruction at Index
127 MCInst const &instruction(MCInst const &MCB, size_t Index);
128
129 // Returns whether this MCInst is a wellformed bundle
130 bool isBundle(MCInst const &MCI);
131
132 // Return whether the insn is an actual insn.
133 bool isCanon(MCInstrInfo const &MCII, MCInst const &MCI);
134
135 // Return the duplex iclass given the two duplex classes
136 unsigned iClassOfDuplexPair(unsigned Ga, unsigned Gb);
137
138 // Return whether the instruction needs to be constant extended.
139 bool isConstExtended(MCInstrInfo const &MCII, MCInst const &MCI);
140
141 // Is this double register suitable for use in a duplex subinst
142 bool isDblRegForSubInst(unsigned Reg);
143
144 // Is this a duplex instruction
145 bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI);
146
147 // Can these instructions be duplexed
148 bool isDuplexPair(MCInst const &MIa, MCInst const &MIb);
149
150 // Can these duplex classes be combine in to a duplex instruction
151 bool isDuplexPairMatch(unsigned Ga, unsigned Gb);
152
153 // Return true if the insn may be extended based on the operand value.
154 bool isExtendable(MCInstrInfo const &MCII, MCInst const &MCI);
155
156 // Return whether the instruction must be always extended.
157 bool isExtended(MCInstrInfo const &MCII, MCInst const &MCI);
158
159 /// Return whether it is a floating-point insn.
160 bool isFloat(MCInstrInfo const &MCII, MCInst const &MCI);
161
162 // Returns whether this instruction is an immediate extender
163 bool isImmext(MCInst const &MCI);
164
165 // Returns whether this bundle is an endloop0
166 bool isInnerLoop(MCInst const &MCI);
167
168 // Is this an integer register
169 bool isIntReg(unsigned Reg);
170
171 // Is this register suitable for use in a duplex subinst
172 bool isIntRegForSubInst(unsigned Reg);
173
174 // Return whether the insn is a new-value consumer.
175 bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI);
176
177 // Return true if the operand can be constant extended.
178 bool isOperandExtended(MCInstrInfo const &MCII, MCInst const &MCI,
179                        unsigned short OperandNum);
180
181 // Can these two instructions be duplexed
182 bool isOrderedDuplexPair(MCInstrInfo const &MCII, MCInst const &MIa,
183                          bool ExtendedA, MCInst const &MIb, bool ExtendedB,
184                          bool bisReversable);
185
186 // Returns whether this bundle is an endloop1
187 bool isOuterLoop(MCInst const &MCI);
188
189 // Return whether this instruction is predicated
190 bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI);
191
192 // Return whether the predicate sense is true
193 bool isPredicatedTrue(MCInstrInfo const &MCII, MCInst const &MCI);
194
195 // Is this a predicate register
196 bool isPredReg(unsigned Reg);
197
198 // Return whether the insn is a prefix.
199 bool isPrefix(MCInstrInfo const &MCII, MCInst const &MCI);
200
201 // Return whether the insn is solo, i.e., cannot be in a packet.
202 bool isSolo(MCInstrInfo const &MCII, MCInst const &MCI);
203
204 /// Return whether the insn can be packaged only with A and X-type insns.
205 bool isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI);
206
207 /// Return whether the insn can be packaged only with an A-type insn in slot #1.
208 bool isSoloAin1(MCInstrInfo const &MCII, MCInst const &MCI);
209
210 // Pad the bundle with nops to satisfy endloop requirements
211 void padEndloop(MCInst &MCI);
212
213 bool prefersSlot3(MCInstrInfo const &MCII, MCInst const &MCI);
214
215 // Replace the instructions inside MCB, represented by Candidate
216 void replaceDuplex(MCContext &Context, MCInst &MCB, DuplexCandidate Candidate);
217
218 // Marks a bundle as endloop0
219 void setInnerLoop(MCInst &MCI);
220
221 // Marks a bundle as endloop1
222 void setOuterLoop(MCInst &MCI);
223
224 // Would duplexing this instruction create a requirement to extend
225 bool subInstWouldBeExtended(MCInst const &potentialDuplex);
226
227 // Attempt to find and replace compound pairs 
228 void tryCompound(MCInstrInfo const &MCII, MCContext &Context, MCInst &MCI);
229 }
230 }
231
232 #endif // LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H