blob: 2940612080344e407f6746d3f2ce32ed499da7a6 [file] [log] [blame]
Colin LeMahieuaf304e52015-02-19 19:00:00 +00001//===- HexagonMCInstrInfo.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 MCInstrInfo to allow Hexagon specific MCInstr queries
11//
12//===----------------------------------------------------------------------===//
13
Colin LeMahieub23c47b2015-05-31 21:57:09 +000014#include "HexagonMCInstrInfo.h"
15
Colin LeMahieu68d967d2015-05-29 14:44:13 +000016#include "Hexagon.h"
Colin LeMahieuaf304e52015-02-19 19:00:00 +000017#include "HexagonBaseInfo.h"
Colin LeMahieu7cd08922015-11-09 04:07:48 +000018#include "HexagonMCChecker.h"
Colin LeMahieub23c47b2015-05-31 21:57:09 +000019
Colin LeMahieube8c4532015-06-05 16:00:11 +000020#include "llvm/MC/MCContext.h"
Colin LeMahieu7cd08922015-11-09 04:07:48 +000021#include "llvm/MC/MCExpr.h"
Colin LeMahieube8c4532015-06-05 16:00:11 +000022#include "llvm/MC/MCInstrInfo.h"
Colin LeMahieub23c47b2015-05-31 21:57:09 +000023#include "llvm/MC/MCSubtargetInfo.h"
Colin LeMahieuaf304e52015-02-19 19:00:00 +000024
25namespace llvm {
Colin LeMahieu7cd08922015-11-09 04:07:48 +000026void HexagonMCInstrInfo::addConstant(MCInst &MI, uint64_t Value,
27 MCContext &Context) {
28 MI.addOperand(MCOperand::createExpr(MCConstantExpr::create(Value, Context)));
29}
30
31void HexagonMCInstrInfo::addConstExtender(MCInstrInfo const &MCII, MCInst &MCB,
32 MCInst const &MCI) {
33 assert(HexagonMCInstrInfo::isBundle(MCB));
34 MCOperand const &exOp =
35 MCI.getOperand(HexagonMCInstrInfo::getExtendableOp(MCII, MCI));
36
37 // Create the extender.
38 MCInst *XMCI =
39 new MCInst(HexagonMCInstrInfo::deriveExtender(MCII, MCI, exOp));
40
41 MCB.addOperand(MCOperand::createInst(XMCI));
42}
43
Colin LeMahieu68d967d2015-05-29 14:44:13 +000044iterator_range<MCInst::const_iterator>
45HexagonMCInstrInfo::bundleInstructions(MCInst const &MCI) {
46 assert(isBundle(MCI));
47 return iterator_range<MCInst::const_iterator>(
48 MCI.begin() + bundleInstructionsOffset, MCI.end());
49}
50
51size_t HexagonMCInstrInfo::bundleSize(MCInst const &MCI) {
52 if (HexagonMCInstrInfo::isBundle(MCI))
53 return (MCI.size() - bundleInstructionsOffset);
54 else
55 return (1);
Colin LeMahieu1174fea2015-02-19 21:10:50 +000056}
57
Colin LeMahieu7cd08922015-11-09 04:07:48 +000058bool HexagonMCInstrInfo::canonicalizePacket(MCInstrInfo const &MCII,
59 MCSubtargetInfo const &STI,
60 MCContext &Context, MCInst &MCB,
61 HexagonMCChecker *Check) {
62 // Examine the packet and convert pairs of instructions to compound
63 // instructions when possible.
64 if (!HexagonDisableCompound)
65 HexagonMCInstrInfo::tryCompound(MCII, Context, MCB);
66 // Check the bundle for errors.
67 bool CheckOk = Check ? Check->check() : true;
68 if (!CheckOk)
69 return false;
70 HexagonMCShuffle(MCII, STI, MCB);
71 // Examine the packet and convert pairs of instructions to duplex
72 // instructions when possible.
73 MCInst InstBundlePreDuplex = MCInst(MCB);
74 if (!HexagonDisableDuplex) {
75 SmallVector<DuplexCandidate, 8> possibleDuplexes;
76 possibleDuplexes = HexagonMCInstrInfo::getDuplexPossibilties(MCII, MCB);
77 HexagonMCShuffle(MCII, STI, Context, MCB, possibleDuplexes);
78 }
79 // Examines packet and pad the packet, if needed, when an
80 // end-loop is in the bundle.
81 HexagonMCInstrInfo::padEndloop(MCB);
82 // If compounding and duplexing didn't reduce the size below
83 // 4 or less we have a packet that is too big.
84 if (HexagonMCInstrInfo::bundleSize(MCB) > HEXAGON_PACKET_SIZE)
85 return false;
86 HexagonMCShuffle(MCII, STI, MCB);
87 return true;
88}
89
Colin LeMahieu8ab7e8e2015-11-10 00:02:27 +000090void HexagonMCInstrInfo::clampExtended(MCInstrInfo const &MCII,
91 MCContext &Context, MCInst &MCI) {
Colin LeMahieube99a022015-06-17 03:06:16 +000092 assert(HexagonMCInstrInfo::isExtendable(MCII, MCI) ||
93 HexagonMCInstrInfo::isExtended(MCII, MCI));
94 MCOperand &exOp =
95 MCI.getOperand(HexagonMCInstrInfo::getExtendableOp(MCII, MCI));
96 // If the extended value is a constant, then use it for the extended and
97 // for the extender instructions, masking off the lower 6 bits and
98 // including the assumed bits.
Colin LeMahieu8ab7e8e2015-11-10 00:02:27 +000099 int64_t Value;
100 if (exOp.getExpr()->evaluateAsAbsolute(Value)) {
Colin LeMahieube99a022015-06-17 03:06:16 +0000101 unsigned Shift = HexagonMCInstrInfo::getExtentAlignment(MCII, MCI);
Colin LeMahieu8ab7e8e2015-11-10 00:02:27 +0000102 exOp.setExpr(MCConstantExpr::create((Value & 0x3f) << Shift, Context));
Colin LeMahieube99a022015-06-17 03:06:16 +0000103 }
104}
105
Colin LeMahieube8c4532015-06-05 16:00:11 +0000106MCInst *HexagonMCInstrInfo::deriveDuplex(MCContext &Context, unsigned iClass,
107 MCInst const &inst0,
108 MCInst const &inst1) {
109 assert((iClass <= 0xf) && "iClass must have range of 0 to 0xf");
110 MCInst *duplexInst = new (Context) MCInst;
111 duplexInst->setOpcode(Hexagon::DuplexIClass0 + iClass);
112
113 MCInst *SubInst0 = new (Context) MCInst(deriveSubInst(inst0));
114 MCInst *SubInst1 = new (Context) MCInst(deriveSubInst(inst1));
115 duplexInst->addOperand(MCOperand::createInst(SubInst0));
116 duplexInst->addOperand(MCOperand::createInst(SubInst1));
117 return duplexInst;
118}
119
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000120MCInst HexagonMCInstrInfo::deriveExtender(MCInstrInfo const &MCII,
121 MCInst const &Inst,
122 MCOperand const &MO) {
123 assert(HexagonMCInstrInfo::isExtendable(MCII, Inst) ||
124 HexagonMCInstrInfo::isExtended(MCII, Inst));
125
126 MCInstrDesc const &Desc = HexagonMCInstrInfo::getDesc(MCII, Inst);
127 MCInst XMI;
128 XMI.setOpcode((Desc.isBranch() || Desc.isCall() ||
129 HexagonMCInstrInfo::getType(MCII, Inst) == HexagonII::TypeCR)
130 ? Hexagon::A4_ext_b
131 : Hexagon::A4_ext);
132 if (MO.isImm())
133 XMI.addOperand(MCOperand::createImm(MO.getImm() & (~0x3f)));
134 else if (MO.isExpr())
135 XMI.addOperand(MCOperand::createExpr(MO.getExpr()));
136 else
137 llvm_unreachable("invalid extendable operand");
138 return XMI;
139}
140
Colin LeMahieube8c4532015-06-05 16:00:11 +0000141MCInst const *HexagonMCInstrInfo::extenderForIndex(MCInst const &MCB,
142 size_t Index) {
143 assert(Index <= bundleSize(MCB));
144 if (Index == 0)
145 return nullptr;
146 MCInst const *Inst =
147 MCB.getOperand(Index + bundleInstructionsOffset - 1).getInst();
148 if (isImmext(*Inst))
149 return Inst;
150 return nullptr;
151}
152
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000153void HexagonMCInstrInfo::extendIfNeeded(MCInstrInfo const &MCII, MCInst &MCB,
154 MCInst const &MCI, bool MustExtend) {
155 if (isConstExtended(MCII, MCI) || MustExtend)
156 addConstExtender(MCII, MCB, MCI);
157}
158
Colin LeMahieub6625652015-05-01 21:14:21 +0000159HexagonII::MemAccessSize
160HexagonMCInstrInfo::getAccessSize(MCInstrInfo const &MCII, MCInst const &MCI) {
161 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
162
163 return (HexagonII::MemAccessSize((F >> HexagonII::MemAccessSizePos) &
164 HexagonII::MemAccesSizeMask));
165}
166
Colin LeMahieu745c4712015-02-19 19:49:27 +0000167unsigned HexagonMCInstrInfo::getBitCount(MCInstrInfo const &MCII,
168 MCInst const &MCI) {
169 uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
170 return ((F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask);
171}
172
Colin LeMahieu745c4712015-02-19 19:49:27 +0000173// Return constant extended operand number.
174unsigned short HexagonMCInstrInfo::getCExtOpNum(MCInstrInfo const &MCII,
175 MCInst const &MCI) {
176 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
177 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask);
178}
179
Colin LeMahieu1174fea2015-02-19 21:10:50 +0000180MCInstrDesc const &HexagonMCInstrInfo::getDesc(MCInstrInfo const &MCII,
181 MCInst const &MCI) {
182 return (MCII.get(MCI.getOpcode()));
183}
184
Colin LeMahieu86f218e2015-05-30 18:55:47 +0000185unsigned short HexagonMCInstrInfo::getExtendableOp(MCInstrInfo const &MCII,
186 MCInst const &MCI) {
187 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
188 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask);
189}
190
191MCOperand const &
192HexagonMCInstrInfo::getExtendableOperand(MCInstrInfo const &MCII,
193 MCInst const &MCI) {
194 unsigned O = HexagonMCInstrInfo::getExtendableOp(MCII, MCI);
195 MCOperand const &MO = MCI.getOperand(O);
196
197 assert((HexagonMCInstrInfo::isExtendable(MCII, MCI) ||
198 HexagonMCInstrInfo::isExtended(MCII, MCI)) &&
199 (MO.isImm() || MO.isExpr()));
200 return (MO);
201}
202
Colin LeMahieub6625652015-05-01 21:14:21 +0000203unsigned HexagonMCInstrInfo::getExtentAlignment(MCInstrInfo const &MCII,
204 MCInst const &MCI) {
205 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
206 return ((F >> HexagonII::ExtentAlignPos) & HexagonII::ExtentAlignMask);
207}
208
209unsigned HexagonMCInstrInfo::getExtentBits(MCInstrInfo const &MCII,
210 MCInst const &MCI) {
211 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
212 return ((F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask);
213}
214
Colin LeMahieuaf304e52015-02-19 19:00:00 +0000215// Return the max value that a constant extendable operand can have
216// without being extended.
217int HexagonMCInstrInfo::getMaxValue(MCInstrInfo const &MCII,
218 MCInst const &MCI) {
Colin LeMahieu745c4712015-02-19 19:49:27 +0000219 uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
Colin LeMahieuaf304e52015-02-19 19:00:00 +0000220 unsigned isSigned =
221 (F >> HexagonII::ExtentSignedPos) & HexagonII::ExtentSignedMask;
222 unsigned bits = (F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask;
223
224 if (isSigned) // if value is signed
225 return ~(-1U << (bits - 1));
226 else
227 return ~(-1U << bits);
228}
Colin LeMahieu745c4712015-02-19 19:49:27 +0000229
230// Return the min value that a constant extendable operand can have
231// without being extended.
232int HexagonMCInstrInfo::getMinValue(MCInstrInfo const &MCII,
233 MCInst const &MCI) {
234 uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
235 unsigned isSigned =
236 (F >> HexagonII::ExtentSignedPos) & HexagonII::ExtentSignedMask;
237 unsigned bits = (F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask;
238
239 if (isSigned) // if value is signed
240 return -1U << (bits - 1);
241 else
242 return 0;
243}
244
Colin LeMahieub6625652015-05-01 21:14:21 +0000245char const *HexagonMCInstrInfo::getName(MCInstrInfo const &MCII,
246 MCInst const &MCI) {
247 return MCII.getName(MCI.getOpcode());
248}
249
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000250unsigned short HexagonMCInstrInfo::getNewValueOp(MCInstrInfo const &MCII,
Colin LeMahieu745c4712015-02-19 19:49:27 +0000251 MCInst const &MCI) {
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000252 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
253 return ((F >> HexagonII::NewValueOpPos) & HexagonII::NewValueOpMask);
254}
255
256MCOperand const &HexagonMCInstrInfo::getNewValueOperand(MCInstrInfo const &MCII,
257 MCInst const &MCI) {
Colin LeMahieu745c4712015-02-19 19:49:27 +0000258 uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
259 unsigned const O =
260 (F >> HexagonII::NewValueOpPos) & HexagonII::NewValueOpMask;
261 MCOperand const &MCO = MCI.getOperand(O);
262
263 assert((HexagonMCInstrInfo::isNewValue(MCII, MCI) ||
264 HexagonMCInstrInfo::hasNewValue(MCII, MCI)) &&
265 MCO.isReg());
266 return (MCO);
267}
268
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000269/// Return the new value or the newly produced value.
270unsigned short HexagonMCInstrInfo::getNewValueOp2(MCInstrInfo const &MCII,
271 MCInst const &MCI) {
272 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
273 return ((F >> HexagonII::NewValueOpPos2) & HexagonII::NewValueOpMask2);
274}
275
276MCOperand const &
277HexagonMCInstrInfo::getNewValueOperand2(MCInstrInfo const &MCII,
278 MCInst const &MCI) {
279 unsigned O = HexagonMCInstrInfo::getNewValueOp2(MCII, MCI);
280 MCOperand const &MCO = MCI.getOperand(O);
281
282 assert((HexagonMCInstrInfo::isNewValue(MCII, MCI) ||
283 HexagonMCInstrInfo::hasNewValue2(MCII, MCI)) &&
284 MCO.isReg());
285 return (MCO);
286}
287
Colin LeMahieub23c47b2015-05-31 21:57:09 +0000288int HexagonMCInstrInfo::getSubTarget(MCInstrInfo const &MCII,
289 MCInst const &MCI) {
290 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
291
292 HexagonII::SubTarget Target = static_cast<HexagonII::SubTarget>(
293 (F >> HexagonII::validSubTargetPos) & HexagonII::validSubTargetMask);
294
295 switch (Target) {
296 default:
297 return Hexagon::ArchV4;
298 case HexagonII::HasV5SubT:
299 return Hexagon::ArchV5;
300 }
301}
302
Colin LeMahieu745c4712015-02-19 19:49:27 +0000303// Return the Hexagon ISA class for the insn.
304unsigned HexagonMCInstrInfo::getType(MCInstrInfo const &MCII,
305 MCInst const &MCI) {
306 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
307
308 return ((F >> HexagonII::TypePos) & HexagonII::TypeMask);
309}
310
Colin LeMahieub23c47b2015-05-31 21:57:09 +0000311unsigned HexagonMCInstrInfo::getUnits(MCInstrInfo const &MCII,
312 MCSubtargetInfo const &STI,
313 MCInst const &MCI) {
314
315 const InstrItinerary *II = STI.getSchedModel().InstrItineraries;
316 int SchedClass = HexagonMCInstrInfo::getDesc(MCII, MCI).getSchedClass();
317 return ((II[SchedClass].FirstStage + HexagonStages)->getUnits());
318}
319
320bool HexagonMCInstrInfo::hasImmExt(MCInst const &MCI) {
321 if (!HexagonMCInstrInfo::isBundle(MCI))
322 return false;
323
324 for (const auto &I : HexagonMCInstrInfo::bundleInstructions(MCI)) {
325 auto MI = I.getInst();
326 if (isImmext(*MI))
327 return true;
328 }
329
330 return false;
331}
332
Colin LeMahieube8c4532015-06-05 16:00:11 +0000333bool HexagonMCInstrInfo::hasExtenderForIndex(MCInst const &MCB, size_t Index) {
334 return extenderForIndex(MCB, Index) != nullptr;
335}
336
Colin LeMahieu745c4712015-02-19 19:49:27 +0000337// Return whether the instruction is a legal new-value producer.
338bool HexagonMCInstrInfo::hasNewValue(MCInstrInfo const &MCII,
339 MCInst const &MCI) {
340 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
341 return ((F >> HexagonII::hasNewValuePos) & HexagonII::hasNewValueMask);
342}
343
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000344/// Return whether the insn produces a second value.
345bool HexagonMCInstrInfo::hasNewValue2(MCInstrInfo const &MCII,
346 MCInst const &MCI) {
347 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
348 return ((F >> HexagonII::hasNewValuePos2) & HexagonII::hasNewValueMask2);
349}
350
Colin LeMahieu86f218e2015-05-30 18:55:47 +0000351MCInst const &HexagonMCInstrInfo::instruction(MCInst const &MCB, size_t Index) {
352 assert(isBundle(MCB));
353 assert(Index < HEXAGON_PACKET_SIZE);
354 return *MCB.getOperand(bundleInstructionsOffset + Index).getInst();
355}
356
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000357bool HexagonMCInstrInfo::isBundle(MCInst const &MCI) {
358 auto Result = Hexagon::BUNDLE == MCI.getOpcode();
359 assert(!Result || (MCI.size() > 0 && MCI.getOperand(0).isImm()));
360 return Result;
361}
362
Colin LeMahieu745c4712015-02-19 19:49:27 +0000363// Return whether the insn is an actual insn.
364bool HexagonMCInstrInfo::isCanon(MCInstrInfo const &MCII, MCInst const &MCI) {
365 return (!HexagonMCInstrInfo::getDesc(MCII, MCI).isPseudo() &&
366 !HexagonMCInstrInfo::isPrefix(MCII, MCI) &&
367 HexagonMCInstrInfo::getType(MCII, MCI) != HexagonII::TypeENDLOOP);
368}
369
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000370bool HexagonMCInstrInfo::isCompound(MCInstrInfo const &MCII,
371 MCInst const &MCI) {
372 return (getType(MCII, MCI) == HexagonII::TypeCOMPOUND);
373}
374
Colin LeMahieube8c4532015-06-05 16:00:11 +0000375bool HexagonMCInstrInfo::isDblRegForSubInst(unsigned Reg) {
376 return ((Reg >= Hexagon::D0 && Reg <= Hexagon::D3) ||
377 (Reg >= Hexagon::D8 && Reg <= Hexagon::D11));
378}
379
380bool HexagonMCInstrInfo::isDuplex(MCInstrInfo const &MCII, MCInst const &MCI) {
381 return HexagonII::TypeDUPLEX == HexagonMCInstrInfo::getType(MCII, MCI);
382}
383
Colin LeMahieu745c4712015-02-19 19:49:27 +0000384// Return whether the instruction needs to be constant extended.
385// 1) Always return true if the instruction has 'isExtended' flag set.
386//
387// isExtendable:
388// 2) For immediate extended operands, return true only if the value is
389// out-of-range.
390// 3) For global address, always return true.
391
392bool HexagonMCInstrInfo::isConstExtended(MCInstrInfo const &MCII,
393 MCInst const &MCI) {
394 if (HexagonMCInstrInfo::isExtended(MCII, MCI))
395 return true;
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000396 // Branch insns are handled as necessary by relaxation.
397 if ((HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeJ) ||
398 (HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeCOMPOUND &&
399 HexagonMCInstrInfo::getDesc(MCII, MCI).isBranch()) ||
400 (HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeNV &&
401 HexagonMCInstrInfo::getDesc(MCII, MCI).isBranch()))
402 return false;
403 // Otherwise loop instructions and other CR insts are handled by relaxation
404 else if ((HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeCR) &&
405 (MCI.getOpcode() != Hexagon::C4_addipc))
406 return false;
407 else if (!HexagonMCInstrInfo::isExtendable(MCII, MCI))
Colin LeMahieu745c4712015-02-19 19:49:27 +0000408 return false;
409
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000410 MCOperand const &MO = HexagonMCInstrInfo::getExtendableOperand(MCII, MCI);
Colin LeMahieu745c4712015-02-19 19:49:27 +0000411
412 // We could be using an instruction with an extendable immediate and shoehorn
413 // a global address into it. If it is a global address it will be constant
414 // extended. We do this for COMBINE.
415 // We currently only handle isGlobal() because it is the only kind of
416 // object we are going to end up with here for now.
417 // In the future we probably should add isSymbol(), etc.
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000418 assert(!MO.isImm());
419 int64_t Value;
420 if (!MO.getExpr()->evaluateAsAbsolute(Value))
Colin LeMahieu745c4712015-02-19 19:49:27 +0000421 return true;
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000422 int MinValue = HexagonMCInstrInfo::getMinValue(MCII, MCI);
423 int MaxValue = HexagonMCInstrInfo::getMaxValue(MCII, MCI);
424 return (MinValue > Value || Value > MaxValue);
Colin LeMahieu745c4712015-02-19 19:49:27 +0000425}
426
Colin LeMahieu745c4712015-02-19 19:49:27 +0000427bool HexagonMCInstrInfo::isExtendable(MCInstrInfo const &MCII,
428 MCInst const &MCI) {
429 uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
430 return (F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask;
431}
432
Colin LeMahieu745c4712015-02-19 19:49:27 +0000433bool HexagonMCInstrInfo::isExtended(MCInstrInfo const &MCII,
434 MCInst const &MCI) {
435 uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
436 return (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask;
437}
438
Colin LeMahieub23c47b2015-05-31 21:57:09 +0000439bool HexagonMCInstrInfo::isFloat(MCInstrInfo const &MCII, MCInst const &MCI) {
440 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
441 return ((F >> HexagonII::FPPos) & HexagonII::FPMask);
442}
443
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000444bool HexagonMCInstrInfo::isImmext(MCInst const &MCI) {
445 auto Op = MCI.getOpcode();
446 return (Op == Hexagon::A4_ext_b || Op == Hexagon::A4_ext_c ||
447 Op == Hexagon::A4_ext_g || Op == Hexagon::A4_ext);
448}
449
450bool HexagonMCInstrInfo::isInnerLoop(MCInst const &MCI) {
451 assert(isBundle(MCI));
452 int64_t Flags = MCI.getOperand(0).getImm();
453 return (Flags & innerLoopMask) != 0;
454}
455
Colin LeMahieube8c4532015-06-05 16:00:11 +0000456bool HexagonMCInstrInfo::isIntReg(unsigned Reg) {
457 return (Reg >= Hexagon::R0 && Reg <= Hexagon::R31);
458}
459
460bool HexagonMCInstrInfo::isIntRegForSubInst(unsigned Reg) {
461 return ((Reg >= Hexagon::R0 && Reg <= Hexagon::R7) ||
462 (Reg >= Hexagon::R16 && Reg <= Hexagon::R23));
463}
464
Colin LeMahieu745c4712015-02-19 19:49:27 +0000465// Return whether the insn is a new-value consumer.
466bool HexagonMCInstrInfo::isNewValue(MCInstrInfo const &MCII,
467 MCInst const &MCI) {
468 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
469 return ((F >> HexagonII::NewValuePos) & HexagonII::NewValueMask);
470}
471
472// Return whether the operand can be constant extended.
473bool HexagonMCInstrInfo::isOperandExtended(MCInstrInfo const &MCII,
474 MCInst const &MCI,
475 unsigned short OperandNum) {
476 uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
477 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask) ==
478 OperandNum;
479}
480
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000481bool HexagonMCInstrInfo::isOuterLoop(MCInst const &MCI) {
482 assert(isBundle(MCI));
483 int64_t Flags = MCI.getOperand(0).getImm();
484 return (Flags & outerLoopMask) != 0;
Colin LeMahieu1174fea2015-02-19 21:10:50 +0000485}
486
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000487bool HexagonMCInstrInfo::isPredicated(MCInstrInfo const &MCII,
488 MCInst const &MCI) {
489 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
490 return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask);
491}
492
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000493bool HexagonMCInstrInfo::isPredicateLate(MCInstrInfo const &MCII,
494 MCInst const &MCI) {
495 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
496 return (F >> HexagonII::PredicateLatePos & HexagonII::PredicateLateMask);
497}
498
499/// Return whether the insn is newly predicated.
500bool HexagonMCInstrInfo::isPredicatedNew(MCInstrInfo const &MCII,
501 MCInst const &MCI) {
502 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
503 return ((F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask);
504}
505
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000506bool HexagonMCInstrInfo::isPredicatedTrue(MCInstrInfo const &MCII,
507 MCInst const &MCI) {
508 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
509 return (
510 !((F >> HexagonII::PredicatedFalsePos) & HexagonII::PredicatedFalseMask));
Colin LeMahieu1174fea2015-02-19 21:10:50 +0000511}
512
Colin LeMahieube8c4532015-06-05 16:00:11 +0000513bool HexagonMCInstrInfo::isPredReg(unsigned Reg) {
514 return (Reg >= Hexagon::P0 && Reg <= Hexagon::P3_0);
515}
516
Colin LeMahieu745c4712015-02-19 19:49:27 +0000517bool HexagonMCInstrInfo::isPrefix(MCInstrInfo const &MCII, MCInst const &MCI) {
518 return (HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypePREFIX);
519}
520
Colin LeMahieu745c4712015-02-19 19:49:27 +0000521bool HexagonMCInstrInfo::isSolo(MCInstrInfo const &MCII, MCInst const &MCI) {
522 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
523 return ((F >> HexagonII::SoloPos) & HexagonII::SoloMask);
524}
Colin LeMahieu1174fea2015-02-19 21:10:50 +0000525
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000526bool HexagonMCInstrInfo::isMemReorderDisabled(MCInst const &MCI) {
527 assert(isBundle(MCI));
528 auto Flags = MCI.getOperand(0).getImm();
529 return (Flags & memReorderDisabledMask) != 0;
530}
531
532bool HexagonMCInstrInfo::isMemStoreReorderEnabled(MCInst const &MCI) {
533 assert(isBundle(MCI));
534 auto Flags = MCI.getOperand(0).getImm();
535 return (Flags & memStoreReorderEnabledMask) != 0;
536}
537
Colin LeMahieub23c47b2015-05-31 21:57:09 +0000538bool HexagonMCInstrInfo::isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI) {
539 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
540 return ((F >> HexagonII::SoloAXPos) & HexagonII::SoloAXMask);
541}
542
543bool HexagonMCInstrInfo::isSoloAin1(MCInstrInfo const &MCII,
544 MCInst const &MCI) {
545 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
546 return ((F >> HexagonII::SoloAin1Pos) & HexagonII::SoloAin1Mask);
547}
548
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000549bool HexagonMCInstrInfo::isVector(MCInstrInfo const &MCII, MCInst const &MCI) {
550 if ((getType(MCII, MCI) <= HexagonII::TypeCVI_LAST) &&
551 (getType(MCII, MCI) >= HexagonII::TypeCVI_FIRST))
552 return true;
553 return false;
554}
555
556int64_t HexagonMCInstrInfo::minConstant(MCInst const &MCI, size_t Index) {
557 auto Sentinal = static_cast<int64_t>(std::numeric_limits<uint32_t>::max())
558 << 8;
559 if (MCI.size() <= Index)
560 return Sentinal;
561 MCOperand const &MCO = MCI.getOperand(Index);
562 if (!MCO.isExpr())
563 return Sentinal;
564 int64_t Value;
565 if (!MCO.getExpr()->evaluateAsAbsolute(Value))
566 return Sentinal;
567 return Value;
568}
569
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000570void HexagonMCInstrInfo::padEndloop(MCInst &MCB) {
571 MCInst Nop;
572 Nop.setOpcode(Hexagon::A2_nop);
573 assert(isBundle(MCB));
574 while ((HexagonMCInstrInfo::isInnerLoop(MCB) &&
575 (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_INNER_SIZE)) ||
576 ((HexagonMCInstrInfo::isOuterLoop(MCB) &&
577 (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_OUTER_SIZE))))
578 MCB.addOperand(MCOperand::createInst(new MCInst(Nop)));
Colin LeMahieu1174fea2015-02-19 21:10:50 +0000579}
580
Colin LeMahieub23c47b2015-05-31 21:57:09 +0000581bool HexagonMCInstrInfo::prefersSlot3(MCInstrInfo const &MCII,
582 MCInst const &MCI) {
583 if (HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeCR)
584 return false;
585
586 unsigned SchedClass = HexagonMCInstrInfo::getDesc(MCII, MCI).getSchedClass();
587 switch (SchedClass) {
588 case Hexagon::Sched::ALU32_3op_tc_2_SLOT0123:
589 case Hexagon::Sched::ALU64_tc_2_SLOT23:
590 case Hexagon::Sched::ALU64_tc_3x_SLOT23:
591 case Hexagon::Sched::M_tc_2_SLOT23:
592 case Hexagon::Sched::M_tc_3x_SLOT23:
593 case Hexagon::Sched::S_2op_tc_2_SLOT23:
594 case Hexagon::Sched::S_3op_tc_2_SLOT23:
595 case Hexagon::Sched::S_3op_tc_3x_SLOT23:
596 return true;
597 }
598 return false;
599}
600
Colin LeMahieube8c4532015-06-05 16:00:11 +0000601void HexagonMCInstrInfo::replaceDuplex(MCContext &Context, MCInst &MCB,
602 DuplexCandidate Candidate) {
603 assert(Candidate.packetIndexI < MCB.size());
604 assert(Candidate.packetIndexJ < MCB.size());
605 assert(isBundle(MCB));
606 MCInst *Duplex =
607 deriveDuplex(Context, Candidate.iClass,
608 *MCB.getOperand(Candidate.packetIndexJ).getInst(),
609 *MCB.getOperand(Candidate.packetIndexI).getInst());
610 assert(Duplex != nullptr);
611 MCB.getOperand(Candidate.packetIndexI).setInst(Duplex);
612 MCB.erase(MCB.begin() + Candidate.packetIndexJ);
613}
614
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000615void HexagonMCInstrInfo::setInnerLoop(MCInst &MCI) {
616 assert(isBundle(MCI));
617 MCOperand &Operand = MCI.getOperand(0);
618 Operand.setImm(Operand.getImm() | innerLoopMask);
Colin LeMahieu1174fea2015-02-19 21:10:50 +0000619}
620
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000621void HexagonMCInstrInfo::setMemReorderDisabled(MCInst &MCI) {
622 assert(isBundle(MCI));
623 MCOperand &Operand = MCI.getOperand(0);
624 Operand.setImm(Operand.getImm() | memReorderDisabledMask);
625 assert(isMemReorderDisabled(MCI));
626}
627
628void HexagonMCInstrInfo::setMemStoreReorderEnabled(MCInst &MCI) {
629 assert(isBundle(MCI));
630 MCOperand &Operand = MCI.getOperand(0);
631 Operand.setImm(Operand.getImm() | memStoreReorderEnabledMask);
632 assert(isMemStoreReorderEnabled(MCI));
633}
634
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000635void HexagonMCInstrInfo::setOuterLoop(MCInst &MCI) {
636 assert(isBundle(MCI));
637 MCOperand &Operand = MCI.getOperand(0);
638 Operand.setImm(Operand.getImm() | outerLoopMask);
Colin LeMahieu1174fea2015-02-19 21:10:50 +0000639}
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000640}