Coverage Report

Created: 2026-02-07 06:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/keystone/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp
Line
Count
Source
1
//===- 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
14
#include "HexagonMCInstrInfo.h"
15
16
#include "Hexagon.h"
17
#include "HexagonBaseInfo.h"
18
#include "HexagonMCChecker.h"
19
20
#include "llvm/MC/MCContext.h"
21
#include "llvm/MC/MCExpr.h"
22
#include "llvm/MC/MCInstrInfo.h"
23
#include "llvm/MC/MCSubtargetInfo.h"
24
25
namespace llvm_ks {
26
void HexagonMCInstrInfo::addConstant(MCInst &MI, uint64_t Value,
27
0
                                     MCContext &Context) {
28
0
  MI.addOperand(MCOperand::createExpr(MCConstantExpr::create(Value, Context)));
29
0
}
30
31
void HexagonMCInstrInfo::addConstExtender(MCContext &Context,
32
                                          MCInstrInfo const &MCII, MCInst &MCB,
33
3.69k
                                          MCInst const &MCI) {
34
3.69k
  assert(HexagonMCInstrInfo::isBundle(MCB));
35
3.69k
  MCOperand const &exOp =
36
3.69k
      MCI.getOperand(HexagonMCInstrInfo::getExtendableOp(MCII, MCI));
37
38
  // Create the extender.
39
3.69k
  MCInst *XMCI =
40
3.69k
      new (Context) MCInst(HexagonMCInstrInfo::deriveExtender(MCII, MCI, exOp));
41
42
3.69k
  MCB.addOperand(MCOperand::createInst(XMCI));
43
3.69k
}
44
45
iterator_range<MCInst::const_iterator>
46
34.5k
HexagonMCInstrInfo::bundleInstructions(MCInst const &MCI) {
47
34.5k
  assert(isBundle(MCI));
48
34.5k
  return make_range(MCI.begin() + bundleInstructionsOffset, MCI.end());
49
34.5k
}
50
51
27.4k
size_t HexagonMCInstrInfo::bundleSize(MCInst const &MCI) {
52
27.4k
  if (HexagonMCInstrInfo::isBundle(MCI))
53
27.4k
    return (MCI.size() - bundleInstructionsOffset);
54
0
  else
55
0
    return (1);
56
27.4k
}
57
58
bool HexagonMCInstrInfo::canonicalizePacket(MCInstrInfo const &MCII,
59
                                            MCSubtargetInfo const &STI,
60
                                            MCContext &Context, MCInst &MCB,
61
3.84k
                                            HexagonMCChecker *Check) {
62
  // Examine the packet and convert pairs of instructions to compound
63
  // instructions when possible.
64
3.84k
  if (!HexagonDisableCompound)
65
3.84k
    HexagonMCInstrInfo::tryCompound(MCII, Context, MCB);
66
  // Check the bundle for errors.
67
3.84k
  bool CheckOk = Check ? Check->check() : true;
68
3.84k
  if (!CheckOk)
69
359
    return false;
70
3.48k
  HexagonMCShuffle(MCII, STI, MCB);
71
  // Examine the packet and convert pairs of instructions to duplex
72
  // instructions when possible.
73
3.48k
  MCInst InstBundlePreDuplex = MCInst(MCB);
74
3.48k
  if (!HexagonDisableDuplex) {
75
3.48k
    SmallVector<DuplexCandidate, 8> possibleDuplexes;
76
3.48k
    possibleDuplexes = HexagonMCInstrInfo::getDuplexPossibilties(MCII, MCB);
77
3.48k
    HexagonMCShuffle(MCII, STI, Context, MCB, possibleDuplexes);
78
3.48k
  }
79
  // Examines packet and pad the packet, if needed, when an
80
  // end-loop is in the bundle.
81
3.48k
  HexagonMCInstrInfo::padEndloop(Context, 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
3.48k
  if (HexagonMCInstrInfo::bundleSize(MCB) > HEXAGON_PACKET_SIZE)
85
0
    return false;
86
3.48k
  HexagonMCShuffle(MCII, STI, MCB);
87
3.48k
  return true;
88
3.48k
}
89
90
void HexagonMCInstrInfo::clampExtended(MCInstrInfo const &MCII,
91
0
                                       MCContext &Context, MCInst &MCI) {
92
0
  assert(HexagonMCInstrInfo::isExtendable(MCII, MCI) ||
93
0
         HexagonMCInstrInfo::isExtended(MCII, MCI));
94
0
  MCOperand &exOp =
95
0
      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.
99
0
  int64_t Value;
100
0
  if (exOp.getExpr()->evaluateAsAbsolute(Value)) {
101
0
    unsigned Shift = HexagonMCInstrInfo::getExtentAlignment(MCII, MCI);
102
0
    exOp.setExpr(MCConstantExpr::create((Value & 0x3f) << Shift, Context));
103
0
  }
104
0
}
105
106
4.23k
MCInst HexagonMCInstrInfo::createBundle() {
107
4.23k
  MCInst Result;
108
4.23k
  Result.setOpcode(Hexagon::BUNDLE);
109
4.23k
  Result.addOperand(MCOperand::createImm(0));
110
4.23k
  return Result;
111
4.23k
}
112
113
MCInst *HexagonMCInstrInfo::deriveDuplex(MCContext &Context, unsigned iClass,
114
                                         MCInst const &inst0,
115
15
                                         MCInst const &inst1) {
116
15
  assert((iClass <= 0xf) && "iClass must have range of 0 to 0xf");
117
15
  MCInst *duplexInst = new (Context) MCInst;
118
15
  duplexInst->setOpcode(Hexagon::DuplexIClass0 + iClass);
119
120
15
  MCInst *SubInst0 = new (Context) MCInst(deriveSubInst(inst0));
121
15
  MCInst *SubInst1 = new (Context) MCInst(deriveSubInst(inst1));
122
15
  duplexInst->addOperand(MCOperand::createInst(SubInst0));
123
15
  duplexInst->addOperand(MCOperand::createInst(SubInst1));
124
15
  return duplexInst;
125
15
}
126
127
MCInst HexagonMCInstrInfo::deriveExtender(MCInstrInfo const &MCII,
128
                                          MCInst const &Inst,
129
3.86k
                                          MCOperand const &MO) {
130
3.86k
  assert(HexagonMCInstrInfo::isExtendable(MCII, Inst) ||
131
3.86k
         HexagonMCInstrInfo::isExtended(MCII, Inst));
132
133
3.86k
  MCInstrDesc const &Desc = HexagonMCInstrInfo::getDesc(MCII, Inst);
134
3.86k
  MCInst XMI;
135
3.86k
  XMI.setOpcode((Desc.isBranch() || Desc.isCall() ||
136
3.41k
                 HexagonMCInstrInfo::getType(MCII, Inst) == HexagonII::TypeCR)
137
3.86k
                    ? Hexagon::A4_ext_b
138
3.86k
                    : Hexagon::A4_ext);
139
3.86k
  if (MO.isImm())
140
0
    XMI.addOperand(MCOperand::createImm(MO.getImm() & (~0x3f)));
141
3.86k
  else if (MO.isExpr())
142
3.86k
    XMI.addOperand(MCOperand::createExpr(MO.getExpr()));
143
0
  else
144
0
    llvm_unreachable("invalid extendable operand");
145
3.86k
  return XMI;
146
3.86k
}
147
148
MCInst const *HexagonMCInstrInfo::extenderForIndex(MCInst const &MCB,
149
2.00k
                                                   size_t Index) {
150
2.00k
  assert(Index <= bundleSize(MCB));
151
2.00k
  if (Index == 0)
152
968
    return nullptr;
153
1.03k
  MCInst const *Inst =
154
1.03k
      MCB.getOperand(Index + bundleInstructionsOffset - 1).getInst();
155
1.03k
  if (isImmext(*Inst))
156
946
    return Inst;
157
90
  return nullptr;
158
1.03k
}
159
160
void HexagonMCInstrInfo::extendIfNeeded(MCContext &Context,
161
                                        MCInstrInfo const &MCII, MCInst &MCB,
162
7.29k
                                        MCInst const &MCI, bool MustExtend) {
163
7.29k
  if (isConstExtended(MCII, MCI) || MustExtend)
164
3.69k
    addConstExtender(Context, MCII, MCB, MCI);
165
7.29k
}
166
167
HexagonII::MemAccessSize
168
0
HexagonMCInstrInfo::getAccessSize(MCInstrInfo const &MCII, MCInst const &MCI) {
169
0
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
170
171
0
  return (HexagonII::MemAccessSize((F >> HexagonII::MemAccessSizePos) &
172
0
                                   HexagonII::MemAccesSizeMask));
173
0
}
174
175
unsigned HexagonMCInstrInfo::getBitCount(MCInstrInfo const &MCII,
176
0
                                         MCInst const &MCI) {
177
0
  uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
178
0
  return ((F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask);
179
0
}
180
181
// Return constant extended operand number.
182
unsigned short HexagonMCInstrInfo::getCExtOpNum(MCInstrInfo const &MCII,
183
0
                                                MCInst const &MCI) {
184
0
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
185
0
  return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask);
186
0
}
187
188
MCInstrDesc const &HexagonMCInstrInfo::getDesc(MCInstrInfo const &MCII,
189
501k
                                               MCInst const &MCI) {
190
501k
  return (MCII.get(MCI.getOpcode()));
191
501k
}
192
193
unsigned short HexagonMCInstrInfo::getExtendableOp(MCInstrInfo const &MCII,
194
7.49k
                                                   MCInst const &MCI) {
195
7.49k
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
196
7.49k
  return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask);
197
7.49k
}
198
199
MCOperand const &
200
HexagonMCInstrInfo::getExtendableOperand(MCInstrInfo const &MCII,
201
3.80k
                                         MCInst const &MCI) {
202
3.80k
  unsigned O = HexagonMCInstrInfo::getExtendableOp(MCII, MCI);
203
3.80k
  MCOperand const &MO = MCI.getOperand(O);
204
205
3.80k
  assert((HexagonMCInstrInfo::isExtendable(MCII, MCI) ||
206
3.80k
          HexagonMCInstrInfo::isExtended(MCII, MCI)) &&
207
3.80k
         (MO.isImm() || MO.isExpr()));
208
3.80k
  return (MO);
209
3.80k
}
210
211
unsigned HexagonMCInstrInfo::getExtentAlignment(MCInstrInfo const &MCII,
212
2.01k
                                                MCInst const &MCI) {
213
2.01k
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
214
2.01k
  return ((F >> HexagonII::ExtentAlignPos) & HexagonII::ExtentAlignMask);
215
2.01k
}
216
217
unsigned HexagonMCInstrInfo::getExtentBits(MCInstrInfo const &MCII,
218
2.01k
                                           MCInst const &MCI) {
219
2.01k
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
220
2.01k
  return ((F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask);
221
2.01k
}
222
223
// Return the max value that a constant extendable operand can have
224
// without being extended.
225
int HexagonMCInstrInfo::getMaxValue(MCInstrInfo const &MCII,
226
3.42k
                                    MCInst const &MCI) {
227
3.42k
  uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
228
3.42k
  unsigned isSigned =
229
3.42k
      (F >> HexagonII::ExtentSignedPos) & HexagonII::ExtentSignedMask;
230
3.42k
  unsigned bits = (F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask;
231
232
3.42k
  if (isSigned) // if value is signed
233
3.40k
    return ~(-1U << (bits - 1));
234
22
  else
235
22
    return ~(-1U << bits);
236
3.42k
}
237
238
// Return the min value that a constant extendable operand can have
239
// without being extended.
240
int HexagonMCInstrInfo::getMinValue(MCInstrInfo const &MCII,
241
3.42k
                                    MCInst const &MCI) {
242
3.42k
  uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
243
3.42k
  unsigned isSigned =
244
3.42k
      (F >> HexagonII::ExtentSignedPos) & HexagonII::ExtentSignedMask;
245
3.42k
  unsigned bits = (F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask;
246
247
3.42k
  if (isSigned) // if value is signed
248
3.40k
    return -1U << (bits - 1);
249
22
  else
250
22
    return 0;
251
3.42k
}
252
253
char const *HexagonMCInstrInfo::getName(MCInstrInfo const &MCII,
254
0
                                        MCInst const &MCI) {
255
0
  return MCII.getName(MCI.getOpcode());
256
0
}
257
258
unsigned short HexagonMCInstrInfo::getNewValueOp(MCInstrInfo const &MCII,
259
0
                                                 MCInst const &MCI) {
260
0
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
261
0
  return ((F >> HexagonII::NewValueOpPos) & HexagonII::NewValueOpMask);
262
0
}
263
264
MCOperand const &HexagonMCInstrInfo::getNewValueOperand(MCInstrInfo const &MCII,
265
3.47k
                                                        MCInst const &MCI) {
266
3.47k
  uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
267
3.47k
  unsigned const O =
268
3.47k
      (F >> HexagonII::NewValueOpPos) & HexagonII::NewValueOpMask;
269
3.47k
  MCOperand const &MCO = MCI.getOperand(O);
270
271
3.47k
  assert((HexagonMCInstrInfo::isNewValue(MCII, MCI) ||
272
3.47k
          HexagonMCInstrInfo::hasNewValue(MCII, MCI)) &&
273
3.47k
         MCO.isReg());
274
3.47k
  return (MCO);
275
3.47k
}
276
277
/// Return the new value or the newly produced value.
278
unsigned short HexagonMCInstrInfo::getNewValueOp2(MCInstrInfo const &MCII,
279
0
                                                  MCInst const &MCI) {
280
0
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
281
0
  return ((F >> HexagonII::NewValueOpPos2) & HexagonII::NewValueOpMask2);
282
0
}
283
284
MCOperand const &
285
HexagonMCInstrInfo::getNewValueOperand2(MCInstrInfo const &MCII,
286
0
                                        MCInst const &MCI) {
287
0
  unsigned O = HexagonMCInstrInfo::getNewValueOp2(MCII, MCI);
288
0
  MCOperand const &MCO = MCI.getOperand(O);
289
290
0
  assert((HexagonMCInstrInfo::isNewValue(MCII, MCI) ||
291
0
          HexagonMCInstrInfo::hasNewValue2(MCII, MCI)) &&
292
0
         MCO.isReg());
293
0
  return (MCO);
294
0
}
295
296
int HexagonMCInstrInfo::getSubTarget(MCInstrInfo const &MCII,
297
0
                                     MCInst const &MCI) {
298
0
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
299
300
0
  HexagonII::SubTarget Target = static_cast<HexagonII::SubTarget>(
301
0
      (F >> HexagonII::validSubTargetPos) & HexagonII::validSubTargetMask);
302
303
0
  switch (Target) {
304
0
  default:
305
0
    return Hexagon::ArchV4;
306
0
  case HexagonII::HasV5SubT:
307
0
    return Hexagon::ArchV5;
308
0
  }
309
0
}
310
311
// Return the Hexagon ISA class for the insn.
312
unsigned HexagonMCInstrInfo::getType(MCInstrInfo const &MCII,
313
152k
                                     MCInst const &MCI) {
314
152k
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
315
316
152k
  return ((F >> HexagonII::TypePos) & HexagonII::TypeMask);
317
152k
}
318
319
unsigned HexagonMCInstrInfo::getUnits(MCInstrInfo const &MCII,
320
                                      MCSubtargetInfo const &STI,
321
23.4k
                                      MCInst const &MCI) {
322
23.4k
  const InstrItinerary *II = STI.getSchedModel().InstrItineraries;
323
23.4k
  int SchedClass = HexagonMCInstrInfo::getDesc(MCII, MCI).getSchedClass();
324
23.4k
  return ((II[SchedClass].FirstStage + HexagonStages)->getUnits());
325
23.4k
}
326
327
0
bool HexagonMCInstrInfo::hasImmExt(MCInst const &MCI) {
328
0
  if (!HexagonMCInstrInfo::isBundle(MCI))
329
0
    return false;
330
331
0
  for (const auto &I : HexagonMCInstrInfo::bundleInstructions(MCI)) {
332
0
    auto MI = I.getInst();
333
0
    if (isImmext(*MI))
334
0
      return true;
335
0
  }
336
337
0
  return false;
338
0
}
339
340
2.00k
bool HexagonMCInstrInfo::hasExtenderForIndex(MCInst const &MCB, size_t Index) {
341
2.00k
  return extenderForIndex(MCB, Index) != nullptr;
342
2.00k
}
343
344
// Return whether the instruction is a legal new-value producer.
345
bool HexagonMCInstrInfo::hasNewValue(MCInstrInfo const &MCII,
346
13.8k
                                     MCInst const &MCI) {
347
13.8k
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
348
13.8k
  return ((F >> HexagonII::hasNewValuePos) & HexagonII::hasNewValueMask);
349
13.8k
}
350
351
/// Return whether the insn produces a second value.
352
bool HexagonMCInstrInfo::hasNewValue2(MCInstrInfo const &MCII,
353
7.75k
                                      MCInst const &MCI) {
354
7.75k
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
355
7.75k
  return ((F >> HexagonII::hasNewValuePos2) & HexagonII::hasNewValueMask2);
356
7.75k
}
357
358
509
MCInst const &HexagonMCInstrInfo::instruction(MCInst const &MCB, size_t Index) {
359
509
  assert(isBundle(MCB));
360
509
  assert(Index < HEXAGON_PACKET_SIZE);
361
509
  return *MCB.getOperand(bundleInstructionsOffset + Index).getInst();
362
509
}
363
364
156k
bool HexagonMCInstrInfo::isBundle(MCInst const &MCI) {
365
156k
  auto Result = Hexagon::BUNDLE == MCI.getOpcode();
366
156k
  assert(!Result || (MCI.size() > 0 && MCI.getOperand(0).isImm()));
367
156k
  return Result;
368
156k
}
369
370
// Return whether the insn is an actual insn.
371
0
bool HexagonMCInstrInfo::isCanon(MCInstrInfo const &MCII, MCInst const &MCI) {
372
0
  return (!HexagonMCInstrInfo::getDesc(MCII, MCI).isPseudo() &&
373
0
          !HexagonMCInstrInfo::isPrefix(MCII, MCI) &&
374
0
          HexagonMCInstrInfo::getType(MCII, MCI) != HexagonII::TypeENDLOOP);
375
0
}
376
377
bool HexagonMCInstrInfo::isCompound(MCInstrInfo const &MCII,
378
3.47k
                                    MCInst const &MCI) {
379
3.47k
  return (getType(MCII, MCI) == HexagonII::TypeCOMPOUND);
380
3.47k
}
381
382
0
bool HexagonMCInstrInfo::isDblRegForSubInst(unsigned Reg) {
383
0
  return ((Reg >= Hexagon::D0 && Reg <= Hexagon::D3) ||
384
0
          (Reg >= Hexagon::D8 && Reg <= Hexagon::D11));
385
0
}
386
387
11.0k
bool HexagonMCInstrInfo::isDuplex(MCInstrInfo const &MCII, MCInst const &MCI) {
388
11.0k
  return HexagonII::TypeDUPLEX == HexagonMCInstrInfo::getType(MCII, MCI);
389
11.0k
}
390
391
// Return whether the instruction needs to be constant extended.
392
// 1) Always return true if the instruction has 'isExtended' flag set.
393
//
394
// isExtendable:
395
// 2) For immediate extended operands, return true only if the value is
396
//    out-of-range.
397
// 3) For global address, always return true.
398
399
bool HexagonMCInstrInfo::isConstExtended(MCInstrInfo const &MCII,
400
7.29k
                                         MCInst const &MCI) {
401
7.29k
  if (HexagonMCInstrInfo::isExtended(MCII, MCI))
402
0
    return true;
403
  // Branch insns are handled as necessary by relaxation.
404
7.29k
  if ((HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeJ) ||
405
5.05k
      (HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeCOMPOUND &&
406
0
       HexagonMCInstrInfo::getDesc(MCII, MCI).isBranch()) ||
407
5.05k
      (HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeNV &&
408
0
       HexagonMCInstrInfo::getDesc(MCII, MCI).isBranch()))
409
2.23k
    return false;
410
  // Otherwise loop instructions and other CR insts are handled by relaxation
411
5.05k
  else if ((HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeCR) &&
412
365
           (MCI.getOpcode() != Hexagon::C4_addipc))
413
365
    return false;
414
4.69k
  else if (!HexagonMCInstrInfo::isExtendable(MCII, MCI))
415
1.06k
    return false;
416
417
3.63k
  MCOperand const &MO = HexagonMCInstrInfo::getExtendableOperand(MCII, MCI);
418
419
  // We could be using an instruction with an extendable immediate and shoehorn
420
  // a global address into it. If it is a global address it will be constant
421
  // extended. We do this for COMBINE.
422
  // We currently only handle isGlobal() because it is the only kind of
423
  // object we are going to end up with here for now.
424
  // In the future we probably should add isSymbol(), etc.
425
3.63k
  assert(!MO.isImm());
426
3.63k
  int64_t Value;
427
3.63k
  if (!MO.getExpr()->evaluateAsAbsolute(Value))
428
203
    return true;
429
3.42k
  int MinValue = HexagonMCInstrInfo::getMinValue(MCII, MCI);
430
3.42k
  int MaxValue = HexagonMCInstrInfo::getMaxValue(MCII, MCI);
431
3.42k
  return (MinValue > Value || Value > MaxValue);
432
3.63k
}
433
434
bool HexagonMCInstrInfo::isExtendable(MCInstrInfo const &MCII,
435
15.6k
                                      MCInst const &MCI) {
436
15.6k
  uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
437
15.6k
  return (F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask;
438
15.6k
}
439
440
bool HexagonMCInstrInfo::isExtended(MCInstrInfo const &MCII,
441
14.5k
                                    MCInst const &MCI) {
442
14.5k
  uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
443
14.5k
  return (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask;
444
14.5k
}
445
446
4.21k
bool HexagonMCInstrInfo::isFloat(MCInstrInfo const &MCII, MCInst const &MCI) {
447
4.21k
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
448
4.21k
  return ((F >> HexagonII::FPPos) & HexagonII::FPMask);
449
4.21k
}
450
451
79.9k
bool HexagonMCInstrInfo::isImmext(MCInst const &MCI) {
452
79.9k
  auto Op = MCI.getOpcode();
453
79.9k
  return (Op == Hexagon::A4_ext_b || Op == Hexagon::A4_ext_c ||
454
74.1k
          Op == Hexagon::A4_ext_g || Op == Hexagon::A4_ext);
455
79.9k
}
456
457
13.0k
bool HexagonMCInstrInfo::isInnerLoop(MCInst const &MCI) {
458
13.0k
  assert(isBundle(MCI));
459
13.0k
  int64_t Flags = MCI.getOperand(0).getImm();
460
13.0k
  return (Flags & innerLoopMask) != 0;
461
13.0k
}
462
463
0
bool HexagonMCInstrInfo::isIntReg(unsigned Reg) {
464
0
  return (Reg >= Hexagon::R0 && Reg <= Hexagon::R31);
465
0
}
466
467
742
bool HexagonMCInstrInfo::isIntRegForSubInst(unsigned Reg) {
468
742
  return ((Reg >= Hexagon::R0 && Reg <= Hexagon::R7) ||
469
173
          (Reg >= Hexagon::R16 && Reg <= Hexagon::R23));
470
742
}
471
472
// Return whether the insn is a new-value consumer.
473
bool HexagonMCInstrInfo::isNewValue(MCInstrInfo const &MCII,
474
20.1k
                                    MCInst const &MCI) {
475
20.1k
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
476
20.1k
  return ((F >> HexagonII::NewValuePos) & HexagonII::NewValueMask);
477
20.1k
}
478
479
// Return whether the operand can be constant extended.
480
bool HexagonMCInstrInfo::isOperandExtended(MCInstrInfo const &MCII,
481
                                           MCInst const &MCI,
482
0
                                           unsigned short OperandNum) {
483
0
  uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
484
0
  return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask) ==
485
0
         OperandNum;
486
0
}
487
488
10.1k
bool HexagonMCInstrInfo::isOuterLoop(MCInst const &MCI) {
489
10.1k
  assert(isBundle(MCI));
490
10.1k
  int64_t Flags = MCI.getOperand(0).getImm();
491
10.1k
  return (Flags & outerLoopMask) != 0;
492
10.1k
}
493
494
bool HexagonMCInstrInfo::isPredicated(MCInstrInfo const &MCII,
495
3.14k
                                      MCInst const &MCI) {
496
3.14k
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
497
3.14k
  return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask);
498
3.14k
}
499
500
bool HexagonMCInstrInfo::isPredicateLate(MCInstrInfo const &MCII,
501
4.28k
                                         MCInst const &MCI) {
502
4.28k
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
503
4.28k
  return (F >> HexagonII::PredicateLatePos & HexagonII::PredicateLateMask);
504
4.28k
}
505
506
/// Return whether the insn is newly predicated.
507
bool HexagonMCInstrInfo::isPredicatedNew(MCInstrInfo const &MCII,
508
12.5k
                                         MCInst const &MCI) {
509
12.5k
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
510
12.5k
  return ((F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask);
511
12.5k
}
512
513
bool HexagonMCInstrInfo::isPredicatedTrue(MCInstrInfo const &MCII,
514
3.48k
                                          MCInst const &MCI) {
515
3.48k
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
516
3.48k
  return (
517
3.48k
      !((F >> HexagonII::PredicatedFalsePos) & HexagonII::PredicatedFalseMask));
518
3.48k
}
519
520
0
bool HexagonMCInstrInfo::isPredReg(unsigned Reg) {
521
0
  return (Reg >= Hexagon::P0 && Reg <= Hexagon::P3_0);
522
0
}
523
524
0
bool HexagonMCInstrInfo::isPrefix(MCInstrInfo const &MCII, MCInst const &MCI) {
525
0
  return (HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypePREFIX);
526
0
}
527
528
20.7k
bool HexagonMCInstrInfo::isSolo(MCInstrInfo const &MCII, MCInst const &MCI) {
529
20.7k
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
530
20.7k
  return ((F >> HexagonII::SoloPos) & HexagonII::SoloMask);
531
20.7k
}
532
533
509
bool HexagonMCInstrInfo::isMemReorderDisabled(MCInst const &MCI) {
534
509
  assert(isBundle(MCI));
535
509
  auto Flags = MCI.getOperand(0).getImm();
536
509
  return (Flags & memReorderDisabledMask) != 0;
537
509
}
538
539
0
bool HexagonMCInstrInfo::isMemStoreReorderEnabled(MCInst const &MCI) {
540
0
  assert(isBundle(MCI));
541
0
  auto Flags = MCI.getOperand(0).getImm();
542
0
  return (Flags & memStoreReorderEnabledMask) != 0;
543
0
}
544
545
13.5k
bool HexagonMCInstrInfo::isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI) {
546
13.5k
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
547
13.5k
  return ((F >> HexagonII::SoloAXPos) & HexagonII::SoloAXMask);
548
13.5k
}
549
550
bool HexagonMCInstrInfo::isSoloAin1(MCInstrInfo const &MCII,
551
13.5k
                                    MCInst const &MCI) {
552
13.5k
  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
553
13.5k
  return ((F >> HexagonII::SoloAin1Pos) & HexagonII::SoloAin1Mask);
554
13.5k
}
555
556
0
bool HexagonMCInstrInfo::isVector(MCInstrInfo const &MCII, MCInst const &MCI) {
557
0
  if ((getType(MCII, MCI) <= HexagonII::TypeCVI_LAST) &&
558
0
      (getType(MCII, MCI) >= HexagonII::TypeCVI_FIRST))
559
0
    return true;
560
0
  return false;
561
0
}
562
563
476
int64_t HexagonMCInstrInfo::minConstant(MCInst const &MCI, size_t Index) {
564
476
  auto Sentinal = static_cast<int64_t>(std::numeric_limits<uint32_t>::max())
565
476
                  << 8;
566
476
  if (MCI.size() <= Index)
567
0
    return Sentinal;
568
476
  MCOperand const &MCO = MCI.getOperand(Index);
569
476
  if (!MCO.isExpr())
570
0
    return Sentinal;
571
476
  int64_t Value;
572
476
  if (!MCO.getExpr()->evaluateAsAbsolute(Value))
573
0
    return Sentinal;
574
476
  return Value;
575
476
}
576
577
3.48k
void HexagonMCInstrInfo::padEndloop(MCContext &Context, MCInst &MCB) {
578
3.48k
  MCInst Nop;
579
3.48k
  Nop.setOpcode(Hexagon::A2_nop);
580
3.48k
  assert(isBundle(MCB));
581
3.48k
  while ((HexagonMCInstrInfo::isInnerLoop(MCB) &&
582
0
          (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_INNER_SIZE)) ||
583
3.48k
         ((HexagonMCInstrInfo::isOuterLoop(MCB) &&
584
0
           (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_OUTER_SIZE))))
585
0
    MCB.addOperand(MCOperand::createInst(new (Context) MCInst(Nop)));
586
3.48k
}
587
588
bool HexagonMCInstrInfo::prefersSlot3(MCInstrInfo const &MCII,
589
13.5k
                                      MCInst const &MCI) {
590
13.5k
  if (HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeCR)
591
720
    return false;
592
593
12.8k
  unsigned SchedClass = HexagonMCInstrInfo::getDesc(MCII, MCI).getSchedClass();
594
12.8k
  switch (SchedClass) {
595
0
  case Hexagon::Sched::ALU32_3op_tc_2_SLOT0123:
596
0
  case Hexagon::Sched::ALU64_tc_2_SLOT23:
597
0
  case Hexagon::Sched::ALU64_tc_3x_SLOT23:
598
0
  case Hexagon::Sched::M_tc_2_SLOT23:
599
0
  case Hexagon::Sched::M_tc_3x_SLOT23:
600
0
  case Hexagon::Sched::S_2op_tc_2_SLOT23:
601
0
  case Hexagon::Sched::S_3op_tc_2_SLOT23:
602
0
  case Hexagon::Sched::S_3op_tc_3x_SLOT23:
603
0
    return true;
604
12.8k
  }
605
12.8k
  return false;
606
12.8k
}
607
608
void HexagonMCInstrInfo::replaceDuplex(MCContext &Context, MCInst &MCB,
609
15
                                       DuplexCandidate Candidate) {
610
15
  assert(Candidate.packetIndexI < MCB.size());
611
15
  assert(Candidate.packetIndexJ < MCB.size());
612
15
  assert(isBundle(MCB));
613
15
  MCInst *Duplex =
614
15
      deriveDuplex(Context, Candidate.iClass,
615
15
                   *MCB.getOperand(Candidate.packetIndexJ).getInst(),
616
15
                   *MCB.getOperand(Candidate.packetIndexI).getInst());
617
15
  assert(Duplex != nullptr);
618
15
  MCB.getOperand(Candidate.packetIndexI).setInst(Duplex);
619
15
  MCB.erase(MCB.begin() + Candidate.packetIndexJ);
620
15
}
621
622
0
void HexagonMCInstrInfo::setInnerLoop(MCInst &MCI) {
623
0
  assert(isBundle(MCI));
624
0
  MCOperand &Operand = MCI.getOperand(0);
625
0
  Operand.setImm(Operand.getImm() | innerLoopMask);
626
0
}
627
628
0
void HexagonMCInstrInfo::setMemReorderDisabled(MCInst &MCI) {
629
0
  assert(isBundle(MCI));
630
0
  MCOperand &Operand = MCI.getOperand(0);
631
0
  Operand.setImm(Operand.getImm() | memReorderDisabledMask);
632
0
  assert(isMemReorderDisabled(MCI));
633
0
}
634
635
0
void HexagonMCInstrInfo::setMemStoreReorderEnabled(MCInst &MCI) {
636
0
  assert(isBundle(MCI));
637
0
  MCOperand &Operand = MCI.getOperand(0);
638
0
  Operand.setImm(Operand.getImm() | memStoreReorderEnabledMask);
639
0
  assert(isMemStoreReorderEnabled(MCI));
640
0
}
641
642
0
void HexagonMCInstrInfo::setOuterLoop(MCInst &MCI) {
643
0
  assert(isBundle(MCI));
644
0
  MCOperand &Operand = MCI.getOperand(0);
645
0
  Operand.setImm(Operand.getImm() | outerLoopMask);
646
0
}
647
}