LLVM 24.0.0git
HexagonInstrInfo.cpp
Go to the documentation of this file.
1//===- HexagonInstrInfo.cpp - Hexagon Instruction Information -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the Hexagon implementation of the TargetInstrInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "HexagonInstrInfo.h"
17#include "HexagonRegisterInfo.h"
18#include "HexagonSubtarget.h"
19#include "llvm/ADT/ArrayRef.h"
23#include "llvm/ADT/StringRef.h"
43#include "llvm/IR/DebugLoc.h"
45#include "llvm/MC/MCAsmInfo.h"
47#include "llvm/MC/MCInstrDesc.h"
51#include "llvm/Support/Debug.h"
56#include <cassert>
57#include <cstdint>
58#include <cstring>
59#include <iterator>
60#include <optional>
61#include <string>
62#include <utility>
63
64using namespace llvm;
65
66#define DEBUG_TYPE "hexagon-instrinfo"
67
68#define GET_INSTRINFO_CTOR_DTOR
69#define GET_INSTRMAP_INFO
71#include "HexagonGenDFAPacketizer.inc"
72#include "HexagonGenInstrInfo.inc"
73
74cl::opt<bool> ScheduleInlineAsm("hexagon-sched-inline-asm", cl::Hidden,
75 cl::init(false), cl::desc("Do not consider inline-asm a scheduling/"
76 "packetization boundary."));
77
78static cl::opt<bool> EnableBranchPrediction("hexagon-enable-branch-prediction",
79 cl::Hidden, cl::init(true), cl::desc("Enable branch prediction"));
80
82 "disable-hexagon-nv-schedule", cl::Hidden,
83 cl::desc("Disable schedule adjustment for new value stores."));
84
86 "enable-timing-class-latency", cl::Hidden, cl::init(false),
87 cl::desc("Enable timing class latency"));
88
90 "enable-alu-forwarding", cl::Hidden, cl::init(true),
91 cl::desc("Enable vec alu forwarding"));
92
94 "enable-acc-forwarding", cl::Hidden, cl::init(true),
95 cl::desc("Enable vec acc forwarding"));
96
97static cl::opt<bool> BranchRelaxAsmLarge("branch-relax-asm-large",
98 cl::init(true), cl::Hidden,
99 cl::desc("branch relax asm"));
100
101static cl::opt<bool>
102 UseDFAHazardRec("dfa-hazard-rec", cl::init(true), cl::Hidden,
103 cl::desc("Use the DFA based hazard recognizer."));
104
105/// Constants for Hexagon instructions.
106const int Hexagon_MEMW_OFFSET_MAX = 4095;
107const int Hexagon_MEMW_OFFSET_MIN = -4096;
108const int Hexagon_MEMD_OFFSET_MAX = 8191;
109const int Hexagon_MEMD_OFFSET_MIN = -8192;
110const int Hexagon_MEMH_OFFSET_MAX = 2047;
111const int Hexagon_MEMH_OFFSET_MIN = -2048;
112const int Hexagon_MEMB_OFFSET_MAX = 1023;
113const int Hexagon_MEMB_OFFSET_MIN = -1024;
114const int Hexagon_ADDI_OFFSET_MAX = 32767;
115const int Hexagon_ADDI_OFFSET_MIN = -32768;
116
117// Pin the vtable to this file.
118void HexagonInstrInfo::anchor() {}
119
121 : HexagonGenInstrInfo(ST, RegInfo, Hexagon::ADJCALLSTACKDOWN,
122 Hexagon::ADJCALLSTACKUP),
123 RegInfo(ST.getHwMode()), Subtarget(ST) {}
124
125namespace llvm {
126namespace HexagonFUnits {
127 bool isSlot0Only(unsigned units);
128}
129}
130
132 return (Reg >= Hexagon::R0 && Reg <= Hexagon::R7) ||
133 (Reg >= Hexagon::R16 && Reg <= Hexagon::R23);
134}
135
137 return isIntRegForSubInst(HRI.getSubReg(Reg, Hexagon::isub_lo)) &&
138 isIntRegForSubInst(HRI.getSubReg(Reg, Hexagon::isub_hi));
139}
140
141/// Calculate number of instructions excluding the debug instructions.
144 unsigned Count = 0;
145 for (; MIB != MIE; ++MIB) {
146 if (!MIB->isDebugInstr())
147 ++Count;
148 }
149 return Count;
150}
151
152// Check if the A2_tfrsi instruction is cheap or not. If the operand has
153// to be constant-extendend it is not cheap since it occupies two slots
154// in a packet.
156 // Enable the following steps only at Os/Oz
157 if (!(MI.getMF()->getFunction().hasOptSize()))
158 return MI.isAsCheapAsAMove();
159
160 if (MI.getOpcode() == Hexagon::A2_tfrsi) {
161 auto Op = MI.getOperand(1);
162 // If the instruction has a global address as operand, it is not cheap
163 // since the operand will be constant extended.
164 if (Op.isGlobal())
165 return false;
166 // If the instruction has an operand of size > 16bits, its will be
167 // const-extended and hence, it is not cheap.
168 if (Op.isImm()) {
169 int64_t Imm = Op.getImm();
170 if (!isInt<16>(Imm))
171 return false;
172 }
173 }
174 return MI.isAsCheapAsAMove();
175}
176
177// Do not sink floating point instructions that updates USR register.
178// Example:
179// feclearexcept
180// F2_conv_w2sf
181// fetestexcept
182// MachineSink sinks F2_conv_w2sf and we are not able to catch exceptions.
183// TODO: On some of these floating point instructions, USR is marked as Use.
184// In reality, these instructions also Def the USR. If USR is marked as Def,
185// some of the assumptions in assembler packetization are broken.
187 // Assumption: A floating point instruction that reads the USR will write
188 // the USR as well.
189 if (isFloat(MI) && MI.hasRegisterImplicitUseOperand(Hexagon::USR))
190 return false;
191 return true;
192}
193
194/// Find the hardware loop instruction used to set-up the specified loop.
195/// On Hexagon, we have two instructions used to set-up the hardware loop
196/// (LOOP0, LOOP1) with corresponding endloop (ENDLOOP0, ENDLOOP1) instructions
197/// to indicate the end of a loop.
199 unsigned EndLoopOp, MachineBasicBlock *TargetBB,
201 unsigned LOOPi;
202 unsigned LOOPr;
203 if (EndLoopOp == Hexagon::ENDLOOP0) {
204 LOOPi = Hexagon::J2_loop0i;
205 LOOPr = Hexagon::J2_loop0r;
206 } else { // EndLoopOp == Hexagon::EndLOOP1
207 LOOPi = Hexagon::J2_loop1i;
208 LOOPr = Hexagon::J2_loop1r;
209 }
210
211 // The loop set-up instruction will be in a predecessor block
212 for (MachineBasicBlock *PB : BB->predecessors()) {
213 // If this has been visited, already skip it.
214 if (!Visited.insert(PB).second)
215 continue;
216 if (PB == BB)
217 continue;
218 for (MachineInstr &I : llvm::reverse(PB->instrs())) {
219 unsigned Opc = I.getOpcode();
220 if (Opc == LOOPi || Opc == LOOPr)
221 return &I;
222 // We've reached a different loop, which means the loop01 has been
223 // removed.
224 if (Opc == EndLoopOp && I.getOperand(0).getMBB() != TargetBB)
225 return nullptr;
226 }
227 // Check the predecessors for the LOOP instruction.
228 if (MachineInstr *Loop = findLoopInstr(PB, EndLoopOp, TargetBB, Visited))
229 return Loop;
230 }
231 return nullptr;
232}
233
234/// Gather register def/uses from MI.
235/// This treats possible (predicated) defs as actually happening ones
236/// (conservatively).
237static inline void parseOperands(const MachineInstr &MI,
239 Defs.clear();
240 Uses.clear();
241
242 for (const MachineOperand &MO : MI.operands()) {
243 if (!MO.isReg())
244 continue;
245
246 Register Reg = MO.getReg();
247 if (!Reg)
248 continue;
249
250 if (MO.isUse())
251 Uses.push_back(MO.getReg());
252
253 if (MO.isDef())
254 Defs.push_back(MO.getReg());
255 }
256}
257
258// Position dependent, so check twice for swap.
259static bool isDuplexPairMatch(unsigned Ga, unsigned Gb) {
260 switch (Ga) {
262 default:
263 return false;
265 return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_A);
267 return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_L2 ||
268 Gb == HexagonII::HSIG_A);
270 return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_L2 ||
273 return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_L2 ||
274 Gb == HexagonII::HSIG_S1 || Gb == HexagonII::HSIG_S2 ||
275 Gb == HexagonII::HSIG_A);
277 return (Gb == HexagonII::HSIG_A);
279 return (Gb == HexagonII::HSIG_Compound);
280 }
281 return false;
282}
283
284/// isLoadFromStackSlot - If the specified machine instruction is a direct
285/// load from a stack slot, return the virtual or physical register number of
286/// the destination along with the FrameIndex of the loaded stack slot. If
287/// not, return 0. This predicate must return 0 if the instruction has
288/// any side effects other than loading from the stack slot.
290 int &FrameIndex) const {
291 switch (MI.getOpcode()) {
292 default:
293 break;
294 case Hexagon::L2_loadri_io:
295 case Hexagon::L2_loadrd_io:
296 case Hexagon::V6_vL32b_ai:
297 case Hexagon::V6_vL32b_nt_ai:
298 case Hexagon::V6_vL32Ub_ai:
299 case Hexagon::LDriw_pred:
300 case Hexagon::LDriw_ctr:
301 case Hexagon::PS_vloadrq_ai:
302 case Hexagon::PS_vloadrw_ai:
303 case Hexagon::PS_vloadrw_nt_ai:
304 case Hexagon::PS_loadrl:
305 case Hexagon::PS_loadrll: {
306 const MachineOperand OpFI = MI.getOperand(1);
307 if (!OpFI.isFI())
308 return 0;
309 const MachineOperand OpOff = MI.getOperand(2);
310 if (!OpOff.isImm() || OpOff.getImm() != 0)
311 return 0;
312 FrameIndex = OpFI.getIndex();
313 return MI.getOperand(0).getReg();
314 }
315
316 case Hexagon::L2_ploadrit_io:
317 case Hexagon::L2_ploadrif_io:
318 case Hexagon::L2_ploadrdt_io:
319 case Hexagon::L2_ploadrdf_io: {
320 const MachineOperand OpFI = MI.getOperand(2);
321 if (!OpFI.isFI())
322 return 0;
323 const MachineOperand OpOff = MI.getOperand(3);
324 if (!OpOff.isImm() || OpOff.getImm() != 0)
325 return 0;
326 FrameIndex = OpFI.getIndex();
327 return MI.getOperand(0).getReg();
328 }
329 }
330
331 return 0;
332}
333
334/// isStoreToStackSlot - If the specified machine instruction is a direct
335/// store to a stack slot, return the virtual or physical register number of
336/// the source reg along with the FrameIndex of the loaded stack slot. If
337/// not, return 0. This predicate must return 0 if the instruction has
338/// any side effects other than storing to the stack slot.
340 int &FrameIndex) const {
341 switch (MI.getOpcode()) {
342 default:
343 break;
344 case Hexagon::S2_storerb_io:
345 case Hexagon::S2_storerh_io:
346 case Hexagon::S2_storeri_io:
347 case Hexagon::S2_storerd_io:
348 case Hexagon::V6_vS32b_ai:
349 case Hexagon::V6_vS32Ub_ai:
350 case Hexagon::STriw_pred:
351 case Hexagon::STriw_ctr:
352 case Hexagon::PS_vstorerq_ai:
353 case Hexagon::PS_vstorerw_ai:
354 case Hexagon::PS_storerl:
355 case Hexagon::PS_storerll: {
356 const MachineOperand &OpFI = MI.getOperand(0);
357 if (!OpFI.isFI())
358 return 0;
359 const MachineOperand &OpOff = MI.getOperand(1);
360 if (!OpOff.isImm() || OpOff.getImm() != 0)
361 return 0;
362 FrameIndex = OpFI.getIndex();
363 return MI.getOperand(2).getReg();
364 }
365
366 case Hexagon::S2_pstorerbt_io:
367 case Hexagon::S2_pstorerbf_io:
368 case Hexagon::S2_pstorerht_io:
369 case Hexagon::S2_pstorerhf_io:
370 case Hexagon::S2_pstorerit_io:
371 case Hexagon::S2_pstorerif_io:
372 case Hexagon::S2_pstorerdt_io:
373 case Hexagon::S2_pstorerdf_io: {
374 const MachineOperand &OpFI = MI.getOperand(1);
375 if (!OpFI.isFI())
376 return 0;
377 const MachineOperand &OpOff = MI.getOperand(2);
378 if (!OpOff.isImm() || OpOff.getImm() != 0)
379 return 0;
380 FrameIndex = OpFI.getIndex();
381 return MI.getOperand(3).getReg();
382 }
383 }
384
385 return 0;
386}
387
388/// This function checks if the instruction or bundle of instructions
389/// has load from stack slot and returns frameindex and machine memory
390/// operand of that instruction if true.
392 const MachineInstr &MI,
394 if (MI.isBundle()) {
395 const MachineBasicBlock *MBB = MI.getParent();
397 for (++MII; MII != MBB->instr_end() && MII->isInsideBundle(); ++MII)
399 return true;
400 return false;
401 }
402
404}
405
406/// This function checks if the instruction or bundle of instructions
407/// has store to stack slot and returns frameindex and machine memory
408/// operand of that instruction if true.
410 const MachineInstr &MI,
412 if (MI.isBundle()) {
413 const MachineBasicBlock *MBB = MI.getParent();
415 for (++MII; MII != MBB->instr_end() && MII->isInsideBundle(); ++MII)
417 return true;
418 return false;
419 }
420
422}
423
424/// This function can analyze one/two way branching only and should (mostly) be
425/// called by target independent side.
426/// First entry is always the opcode of the branching instruction, except when
427/// the Cond vector is supposed to be empty, e.g., when analyzeBranch fails, a
428/// BB with only unconditional jump. Subsequent entries depend upon the opcode,
429/// e.g. Jump_c p will have
430/// Cond[0] = Jump_c
431/// Cond[1] = p
432/// HW-loop ENDLOOP:
433/// Cond[0] = ENDLOOP
434/// Cond[1] = MBB
435/// New value jump:
436/// Cond[0] = Hexagon::CMPEQri_f_Jumpnv_t_V4 -- specific opcode
437/// Cond[1] = R
438/// Cond[2] = Imm
441 MachineBasicBlock *&FBB,
443 bool AllowModify) const {
444 TBB = nullptr;
445 FBB = nullptr;
446 Cond.clear();
447
448 // If the block has no terminators, it just falls into the block after it.
450 if (I == MBB.instr_begin())
451 return false;
452
453 // A basic block may looks like this:
454 //
455 // [ insn
456 // EH_LABEL
457 // insn
458 // insn
459 // insn
460 // EH_LABEL
461 // insn ]
462 //
463 // It has two succs but does not have a terminator
464 // Don't know how to handle it.
465 do {
466 --I;
467 if (I->isEHLabel())
468 // Don't analyze EH branches.
469 return true;
470 } while (I != MBB.instr_begin());
471
472 I = MBB.instr_end();
473 --I;
474
475 while (I->isDebugInstr()) {
476 if (I == MBB.instr_begin())
477 return false;
478 --I;
479 }
480
481 bool JumpToBlock = I->getOpcode() == Hexagon::J2_jump &&
482 I->getOperand(0).isMBB();
483 // Delete the J2_jump if it's equivalent to a fall-through.
484 if (AllowModify && JumpToBlock &&
485 MBB.isLayoutSuccessor(I->getOperand(0).getMBB())) {
486 LLVM_DEBUG(dbgs() << "\nErasing the jump to successor block\n";);
487 I->eraseFromParent();
488 I = MBB.instr_end();
489 if (I == MBB.instr_begin())
490 return false;
491 --I;
492 }
493 if (!isUnpredicatedTerminator(*I))
494 return false;
495
496 // Get the last instruction in the block.
497 MachineInstr *LastInst = &*I;
498 MachineInstr *SecondLastInst = nullptr;
499 // Find one more terminator if present.
500 while (true) {
501 if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(*I)) {
502 if (!SecondLastInst)
503 SecondLastInst = &*I;
504 else
505 // This is a third branch.
506 return true;
507 }
508 if (I == MBB.instr_begin())
509 break;
510 --I;
511 }
512
513 int LastOpcode = LastInst->getOpcode();
514 int SecLastOpcode = SecondLastInst ? SecondLastInst->getOpcode() : 0;
515 // If the branch target is not a basic block, it could be a tail call.
516 // (It is, if the target is a function.)
517 if (LastOpcode == Hexagon::J2_jump && !LastInst->getOperand(0).isMBB())
518 return true;
519 if (SecLastOpcode == Hexagon::J2_jump &&
520 !SecondLastInst->getOperand(0).isMBB())
521 return true;
522
523 bool LastOpcodeHasJMP_c = PredOpcodeHasJMP_c(LastOpcode);
524 bool LastOpcodeHasNVJump = isNewValueJump(*LastInst);
525
526 if (LastOpcodeHasJMP_c && !LastInst->getOperand(1).isMBB())
527 return true;
528
529 // If there is only one terminator instruction, process it.
530 if (LastInst && !SecondLastInst) {
531 if (LastOpcode == Hexagon::J2_jump) {
532 TBB = LastInst->getOperand(0).getMBB();
533 return false;
534 }
535 if (isEndLoopN(LastOpcode)) {
536 TBB = LastInst->getOperand(0).getMBB();
537 Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode()));
538 Cond.push_back(LastInst->getOperand(0));
539 return false;
540 }
541 if (LastOpcodeHasJMP_c) {
542 TBB = LastInst->getOperand(1).getMBB();
543 Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode()));
544 Cond.push_back(LastInst->getOperand(0));
545 return false;
546 }
547 // Only supporting rr/ri versions of new-value jumps.
548 if (LastOpcodeHasNVJump && (LastInst->getNumExplicitOperands() == 3)) {
549 TBB = LastInst->getOperand(2).getMBB();
550 Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode()));
551 Cond.push_back(LastInst->getOperand(0));
552 Cond.push_back(LastInst->getOperand(1));
553 return false;
554 }
555 LLVM_DEBUG(dbgs() << "\nCant analyze " << printMBBReference(MBB)
556 << " with one jump\n";);
557 // Otherwise, don't know what this is.
558 return true;
559 }
560
561 bool SecLastOpcodeHasJMP_c = PredOpcodeHasJMP_c(SecLastOpcode);
562 bool SecLastOpcodeHasNVJump = isNewValueJump(*SecondLastInst);
563 if (SecLastOpcodeHasJMP_c && (LastOpcode == Hexagon::J2_jump)) {
564 if (!SecondLastInst->getOperand(1).isMBB())
565 return true;
566 TBB = SecondLastInst->getOperand(1).getMBB();
567 Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode()));
568 Cond.push_back(SecondLastInst->getOperand(0));
569 FBB = LastInst->getOperand(0).getMBB();
570 return false;
571 }
572
573 // Only supporting rr/ri versions of new-value jumps.
574 if (SecLastOpcodeHasNVJump &&
575 (SecondLastInst->getNumExplicitOperands() == 3) &&
576 (LastOpcode == Hexagon::J2_jump)) {
577 TBB = SecondLastInst->getOperand(2).getMBB();
578 Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode()));
579 Cond.push_back(SecondLastInst->getOperand(0));
580 Cond.push_back(SecondLastInst->getOperand(1));
581 FBB = LastInst->getOperand(0).getMBB();
582 return false;
583 }
584
585 // If the block ends with two Hexagon:JMPs, handle it. The second one is not
586 // executed, so remove it.
587 if (SecLastOpcode == Hexagon::J2_jump && LastOpcode == Hexagon::J2_jump) {
588 TBB = SecondLastInst->getOperand(0).getMBB();
589 I = LastInst->getIterator();
590 if (AllowModify)
591 I->eraseFromParent();
592 return false;
593 }
594
595 // If the block ends with an ENDLOOP, and J2_jump, handle it.
596 if (isEndLoopN(SecLastOpcode) && LastOpcode == Hexagon::J2_jump) {
597 TBB = SecondLastInst->getOperand(0).getMBB();
598 Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode()));
599 Cond.push_back(SecondLastInst->getOperand(0));
600 FBB = LastInst->getOperand(0).getMBB();
601 return false;
602 }
603 LLVM_DEBUG(dbgs() << "\nCant analyze " << printMBBReference(MBB)
604 << " with two jumps";);
605 // Otherwise, can't handle this.
606 return true;
607}
608
610 int *BytesRemoved) const {
611 assert(!BytesRemoved && "code size not handled");
612
613 LLVM_DEBUG(dbgs() << "\nRemoving branches out of " << printMBBReference(MBB));
615 unsigned Count = 0;
616 while (I != MBB.begin()) {
617 --I;
618 if (I->isDebugInstr())
619 continue;
620 // Only removing branches from end of MBB.
621 if (!I->isBranch())
622 return Count;
623 if (Count && (I->getOpcode() == Hexagon::J2_jump))
624 llvm_unreachable("Malformed basic block: unconditional branch not last");
625 MBB.erase(&MBB.back());
626 I = MBB.end();
627 ++Count;
628 }
629 return Count;
630}
631
636 const DebugLoc &DL,
637 int *BytesAdded) const {
638 unsigned BOpc = Hexagon::J2_jump;
639 unsigned BccOpc = Hexagon::J2_jumpt;
640 assert(validateBranchCond(Cond) && "Invalid branching condition");
641 assert(TBB && "insertBranch must not be told to insert a fallthrough");
642 assert(!BytesAdded && "code size not handled");
643
644 // Check if reverseBranchCondition has asked to reverse this branch
645 // If we want to reverse the branch an odd number of times, we want
646 // J2_jumpf.
647 if (!Cond.empty() && Cond[0].isImm())
648 BccOpc = Cond[0].getImm();
649
650 if (!FBB) {
651 if (Cond.empty()) {
652 // Due to a bug in TailMerging/CFG Optimization, we need to add a
653 // special case handling of a predicated jump followed by an
654 // unconditional jump. If not, Tail Merging and CFG Optimization go
655 // into an infinite loop.
656 MachineBasicBlock *NewTBB, *NewFBB;
658 auto Term = MBB.getFirstTerminator();
659 if (Term != MBB.end() && isPredicated(*Term) &&
660 !analyzeBranch(MBB, NewTBB, NewFBB, Cond, false) &&
661 MachineFunction::iterator(NewTBB) == ++MBB.getIterator()) {
664 return insertBranch(MBB, TBB, nullptr, Cond, DL);
665 }
666 BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB);
667 } else if (isEndLoopN(Cond[0].getImm())) {
668 int EndLoopOp = Cond[0].getImm();
669 assert(Cond[1].isMBB());
670 // Since we're adding an ENDLOOP, there better be a LOOP instruction.
671 // Check for it, and change the BB target if needed.
673 MachineInstr *Loop = findLoopInstr(TBB, EndLoopOp, Cond[1].getMBB(),
674 VisitedBBs);
675 assert(Loop != nullptr && "Inserting an ENDLOOP without a LOOP");
676 Loop->getOperand(0).setMBB(TBB);
677 // Add the ENDLOOP after the finding the LOOP0.
678 BuildMI(&MBB, DL, get(EndLoopOp)).addMBB(TBB);
679 } else if (isNewValueJump(Cond[0].getImm())) {
680 assert((Cond.size() == 3) && "Only supporting rr/ri version of nvjump");
681 // New value jump
682 // (ins IntRegs:$src1, IntRegs:$src2, brtarget:$offset)
683 // (ins IntRegs:$src1, u5Imm:$src2, brtarget:$offset)
684 RegState Flags1 = getUndefRegState(Cond[1].isUndef());
685 LLVM_DEBUG(dbgs() << "\nInserting NVJump for "
687 if (Cond[2].isReg()) {
688 RegState Flags2 = getUndefRegState(Cond[2].isUndef());
689 BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[1].getReg(), Flags1).
690 addReg(Cond[2].getReg(), Flags2).addMBB(TBB);
691 } else if(Cond[2].isImm()) {
692 BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[1].getReg(), Flags1).
693 addImm(Cond[2].getImm()).addMBB(TBB);
694 } else
695 llvm_unreachable("Invalid condition for branching");
696 } else {
697 assert((Cond.size() == 2) && "Malformed cond vector");
698 const MachineOperand &RO = Cond[1];
699 RegState Flags = getUndefRegState(RO.isUndef());
700 BuildMI(&MBB, DL, get(BccOpc)).addReg(RO.getReg(), Flags).addMBB(TBB);
701 }
702 return 1;
703 }
704 assert((!Cond.empty()) &&
705 "Cond. cannot be empty when multiple branchings are required");
706 assert((!isNewValueJump(Cond[0].getImm())) &&
707 "NV-jump cannot be inserted with another branch");
708 // Special case for hardware loops. The condition is a basic block.
709 if (isEndLoopN(Cond[0].getImm())) {
710 int EndLoopOp = Cond[0].getImm();
711 assert(Cond[1].isMBB());
712 // Since we're adding an ENDLOOP, there better be a LOOP instruction.
713 // Check for it, and change the BB target if needed.
715 MachineInstr *Loop = findLoopInstr(TBB, EndLoopOp, Cond[1].getMBB(),
716 VisitedBBs);
717 assert(Loop != nullptr && "Inserting an ENDLOOP without a LOOP");
718 Loop->getOperand(0).setMBB(TBB);
719 // Add the ENDLOOP after the finding the LOOP0.
720 BuildMI(&MBB, DL, get(EndLoopOp)).addMBB(TBB);
721 } else {
722 const MachineOperand &RO = Cond[1];
723 RegState Flags = getUndefRegState(RO.isUndef());
724 BuildMI(&MBB, DL, get(BccOpc)).addReg(RO.getReg(), Flags).addMBB(TBB);
725 }
726 BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB);
727
728 return 2;
729}
730
731namespace {
732class HexagonPipelinerLoopInfo : public TargetInstrInfo::PipelinerLoopInfo {
733 MachineInstr *Loop, *EndLoop;
734 MachineFunction *MF;
735 const HexagonInstrInfo *TII;
736 int64_t TripCount;
737 Register LoopCount;
738 DebugLoc DL;
739
740public:
741 HexagonPipelinerLoopInfo(MachineInstr *Loop, MachineInstr *EndLoop)
742 : Loop(Loop), EndLoop(EndLoop), MF(Loop->getParent()->getParent()),
743 TII(MF->getSubtarget<HexagonSubtarget>().getInstrInfo()),
744 DL(Loop->getDebugLoc()) {
745 // Inspect the Loop instruction up-front, as it may be deleted when we call
746 // createTripCountGreaterCondition.
747 TripCount = Loop->getOpcode() == Hexagon::J2_loop0r
748 ? -1
749 : Loop->getOperand(1).getImm();
750 if (TripCount == -1)
751 LoopCount = Loop->getOperand(1).getReg();
752 }
753
754 bool shouldIgnoreForPipelining(const MachineInstr *MI) const override {
755 // Only ignore the terminator.
756 return MI == EndLoop || TII->isHMXActivateInstr(*MI) ||
757 TII->isHMXWeightInstr(*MI);
758 }
759
760 std::optional<bool> createTripCountGreaterCondition(
761 int TC, MachineBasicBlock &MBB,
762 SmallVectorImpl<MachineOperand> &Cond) override {
763 if (TripCount == -1) {
764 // Check if we're done with the loop.
765 Register Done = TII->createVR(MF, MVT::i1);
766 MachineInstr *NewCmp = BuildMI(&MBB, DL,
767 TII->get(Hexagon::C2_cmpgtui), Done)
768 .addReg(LoopCount)
769 .addImm(TC);
770 Cond.push_back(MachineOperand::CreateImm(Hexagon::J2_jumpf));
771 Cond.push_back(NewCmp->getOperand(0));
772 return {};
773 }
774
775 return TripCount > TC;
776 }
777
778 void setPreheader(MachineBasicBlock *NewPreheader) override {
779 NewPreheader->splice(NewPreheader->getFirstTerminator(), Loop->getParent(),
780 Loop);
781 }
782
783 void adjustTripCount(int TripCountAdjust) override {
784 // If the loop trip count is a compile-time value, then just change the
785 // value.
786 if (Loop->getOpcode() == Hexagon::J2_loop0i ||
787 Loop->getOpcode() == Hexagon::J2_loop1i) {
788 int64_t TripCount = Loop->getOperand(1).getImm() + TripCountAdjust;
789 assert(TripCount > 0 && "Can't create an empty or negative loop!");
790 Loop->getOperand(1).setImm(TripCount);
791 return;
792 }
793
794 // The loop trip count is a run-time value. We generate code to subtract
795 // one from the trip count, and update the loop instruction.
796 Register LoopCount = Loop->getOperand(1).getReg();
797 Register NewLoopCount = TII->createVR(MF, MVT::i32);
798 BuildMI(*Loop->getParent(), Loop, Loop->getDebugLoc(),
799 TII->get(Hexagon::A2_addi), NewLoopCount)
800 .addReg(LoopCount)
801 .addImm(TripCountAdjust);
802 Loop->getOperand(1).setReg(NewLoopCount);
803 }
804
805 void disposed(LiveIntervals *LIS) override {
806 if (LIS)
808 Loop->eraseFromParent();
809 }
810};
811} // namespace
812
813std::unique_ptr<TargetInstrInfo::PipelinerLoopInfo>
815 // We really "analyze" only hardware loops right now.
817
818 if (I != LoopBB->end() && isEndLoopN(I->getOpcode())) {
820 MachineInstr *LoopInst = findLoopInstr(
821 LoopBB, I->getOpcode(), I->getOperand(0).getMBB(), VisitedBBs);
822 if (LoopInst)
823 return std::make_unique<HexagonPipelinerLoopInfo>(LoopInst, &*I);
824 }
825 return nullptr;
826}
827
829 unsigned NumCycles, unsigned ExtraPredCycles,
830 BranchProbability Probability) const {
831 return nonDbgBBSize(&MBB) <= 3;
832}
833
835 unsigned NumTCycles, unsigned ExtraTCycles, MachineBasicBlock &FMBB,
836 unsigned NumFCycles, unsigned ExtraFCycles, BranchProbability Probability)
837 const {
838 return nonDbgBBSize(&TMBB) <= 3 && nonDbgBBSize(&FMBB) <= 3;
839}
840
842 unsigned NumInstrs, BranchProbability Probability) const {
843 return NumInstrs <= 4;
844}
845
846static void getLiveInRegsAt(LivePhysRegs &Regs, const MachineInstr &MI) {
848 const MachineBasicBlock &B = *MI.getParent();
849 Regs.addLiveIns(B);
850 auto E = MachineBasicBlock::const_iterator(MI.getIterator());
851 for (auto I = B.begin(); I != E; ++I) {
852 Clobbers.clear();
853 Regs.stepForward(*I, Clobbers);
854 }
855}
856
857static void getLiveOutRegsAt(LivePhysRegs &Regs, const MachineInstr &MI) {
858 const MachineBasicBlock &B = *MI.getParent();
859 Regs.addLiveOuts(B);
860 auto E = ++MachineBasicBlock::const_iterator(MI.getIterator()).getReverse();
861 for (auto I = B.rbegin(); I != E; ++I)
862 Regs.stepBackward(*I);
863}
864
867 const DebugLoc &DL, Register DestReg,
868 Register SrcReg, bool KillSrc,
869 bool RenamableDest,
870 bool RenamableSrc) const {
871 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
872 RegState KillFlag = getKillRegState(KillSrc);
873
874 if (Hexagon::IntRegsRegClass.contains(SrcReg, DestReg)) {
875 BuildMI(MBB, I, DL, get(Hexagon::A2_tfr), DestReg)
876 .addReg(SrcReg, KillFlag);
877 return;
878 }
879 if (Hexagon::DoubleRegsRegClass.contains(SrcReg, DestReg)) {
880 BuildMI(MBB, I, DL, get(Hexagon::A2_tfrp), DestReg)
881 .addReg(SrcReg, KillFlag);
882 return;
883 }
884 if (Hexagon::PredRegsRegClass.contains(SrcReg, DestReg)) {
885 // Map Pd = Ps to Pd = or(Ps, Ps).
886 BuildMI(MBB, I, DL, get(Hexagon::C2_or), DestReg)
887 .addReg(SrcReg).addReg(SrcReg, KillFlag);
888 return;
889 }
890 if (Hexagon::CtrRegsRegClass.contains(DestReg) &&
891 Hexagon::IntRegsRegClass.contains(SrcReg)) {
892 BuildMI(MBB, I, DL, get(Hexagon::A2_tfrrcr), DestReg)
893 .addReg(SrcReg, KillFlag);
894 return;
895 }
896 if (Hexagon::IntRegsRegClass.contains(DestReg) &&
897 Hexagon::CtrRegsRegClass.contains(SrcReg)) {
898 BuildMI(MBB, I, DL, get(Hexagon::A2_tfrcrr), DestReg)
899 .addReg(SrcReg, KillFlag);
900 return;
901 }
902 if (Hexagon::ModRegsRegClass.contains(DestReg) &&
903 Hexagon::IntRegsRegClass.contains(SrcReg)) {
904 BuildMI(MBB, I, DL, get(Hexagon::A2_tfrrcr), DestReg)
905 .addReg(SrcReg, KillFlag);
906 return;
907 }
908 if (Hexagon::PredRegsRegClass.contains(SrcReg) &&
909 Hexagon::IntRegsRegClass.contains(DestReg)) {
910 BuildMI(MBB, I, DL, get(Hexagon::C2_tfrpr), DestReg)
911 .addReg(SrcReg, KillFlag);
912 return;
913 }
914 if (Hexagon::IntRegsRegClass.contains(SrcReg) &&
915 Hexagon::PredRegsRegClass.contains(DestReg)) {
916 BuildMI(MBB, I, DL, get(Hexagon::C2_tfrrp), DestReg)
917 .addReg(SrcReg, KillFlag);
918 return;
919 }
920 if (Hexagon::PredRegsRegClass.contains(SrcReg) &&
921 Hexagon::IntRegsRegClass.contains(DestReg)) {
922 BuildMI(MBB, I, DL, get(Hexagon::C2_tfrpr), DestReg)
923 .addReg(SrcReg, KillFlag);
924 return;
925 }
926 if (Hexagon::HvxVRRegClass.contains(SrcReg, DestReg)) {
927 BuildMI(MBB, I, DL, get(Hexagon::V6_vassign), DestReg).
928 addReg(SrcReg, KillFlag);
929 return;
930 }
931 if (Hexagon::HvxWRRegClass.contains(SrcReg, DestReg)) {
932 LivePhysRegs LiveAtMI(HRI);
933 getLiveInRegsAt(LiveAtMI, *I);
934 Register SrcLo = HRI.getSubReg(SrcReg, Hexagon::vsub_lo);
935 Register SrcHi = HRI.getSubReg(SrcReg, Hexagon::vsub_hi);
936 RegState UndefLo = getUndefRegState(!LiveAtMI.contains(SrcLo));
937 RegState UndefHi = getUndefRegState(!LiveAtMI.contains(SrcHi));
938 BuildMI(MBB, I, DL, get(Hexagon::V6_vcombine), DestReg)
939 .addReg(SrcHi, KillFlag | UndefHi)
940 .addReg(SrcLo, KillFlag | UndefLo);
941 return;
942 }
943 if (Hexagon::HvxQRRegClass.contains(SrcReg, DestReg)) {
944 BuildMI(MBB, I, DL, get(Hexagon::V6_pred_and), DestReg)
945 .addReg(SrcReg)
946 .addReg(SrcReg, KillFlag);
947 return;
948 }
949 if (Hexagon::HvxQRRegClass.contains(SrcReg) &&
950 Hexagon::HvxVRRegClass.contains(DestReg)) {
951 llvm_unreachable("Unimplemented pred to vec");
952 return;
953 }
954 if (Hexagon::HvxQRRegClass.contains(DestReg) &&
955 Hexagon::HvxVRRegClass.contains(SrcReg)) {
956 llvm_unreachable("Unimplemented vec to pred");
957 return;
958 }
959 if (Hexagon::HlxLRRegClass.contains(SrcReg, DestReg)) {
960 BuildMI(MBB, I, DL, get(Hexagon::LX_assign), DestReg)
961 .addReg(SrcReg, KillFlag);
962 return;
963 }
964 if (Hexagon::HlxLLRRegClass.contains(SrcReg, DestReg)) {
965 BuildMI(MBB, I, DL, get(Hexagon::LX_assign_w), DestReg)
966 .addReg(SrcReg, KillFlag);
967 return;
968 }
969
970#ifndef NDEBUG
971 // Show the invalid registers to ease debugging.
972 dbgs() << "Invalid registers for copy in " << printMBBReference(MBB) << ": "
973 << printReg(DestReg, &HRI) << " = " << printReg(SrcReg, &HRI) << '\n';
974#endif
975 llvm_unreachable("Unimplemented");
976}
977
980 Register SrcReg, bool isKill, int FI,
981 const TargetRegisterClass *RC,
982 Register VReg,
983 MachineInstr::MIFlag Flags) const {
984 DebugLoc DL = MBB.findDebugLoc(I);
985 MachineFunction &MF = *MBB.getParent();
986 MachineFrameInfo &MFI = MF.getFrameInfo();
987 auto &HMFI = *MF.getInfo<HexagonMachineFunctionInfo>();
988 RegState KillFlag = getKillRegState(isKill);
989
990 int MFIIndex = FI;
991 MachineFrameInfo *MMFI = &MFI;
992 if (HMFI.isVTCMStackIndex(FI)) {
993 MFIIndex = HMFI.getMappedVTCMObjectIndex(FI);
994 MMFI = &HMFI.getVTCMFrameInfo();
995 }
998 MMFI->getObjectSize(MFIIndex), MMFI->getObjectAlign(MFIIndex));
999
1000 if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) {
1001 BuildMI(MBB, I, DL, get(Hexagon::S2_storeri_io))
1002 .addFrameIndex(FI).addImm(0)
1003 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
1004 } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) {
1005 BuildMI(MBB, I, DL, get(Hexagon::S2_storerd_io))
1006 .addFrameIndex(FI).addImm(0)
1007 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
1008 } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) {
1009 BuildMI(MBB, I, DL, get(Hexagon::STriw_pred))
1010 .addFrameIndex(FI).addImm(0)
1011 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
1012 } else if (Hexagon::ModRegsRegClass.hasSubClassEq(RC)) {
1013 BuildMI(MBB, I, DL, get(Hexagon::STriw_ctr))
1014 .addFrameIndex(FI).addImm(0)
1015 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
1016 } else if (Hexagon::CircRegsRegClass.hasSubClassEq(RC)) {
1017 BuildMI(MBB, I, DL, get(Hexagon::STriw_circ))
1018 .addFrameIndex(FI)
1019 .addReg(SrcReg, KillFlag)
1020 .addMemOperand(MMO);
1021 } else if (Hexagon::HvxQRRegClass.hasSubClassEq(RC)) {
1022 BuildMI(MBB, I, DL, get(Hexagon::PS_vstorerq_ai))
1023 .addFrameIndex(FI).addImm(0)
1024 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
1025 } else if (Hexagon::HvxVRRegClass.hasSubClassEq(RC)) {
1026 BuildMI(MBB, I, DL, get(Hexagon::PS_vstorerv_ai))
1027 .addFrameIndex(FI).addImm(0)
1028 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
1029 } else if (Hexagon::HvxWRRegClass.hasSubClassEq(RC)) {
1030 BuildMI(MBB, I, DL, get(Hexagon::PS_vstorerw_ai))
1031 .addFrameIndex(FI).addImm(0)
1032 .addReg(SrcReg, KillFlag).addMemOperand(MMO);
1033 } else if (Hexagon::HlxLRRegClass.hasSubClassEq(RC)) {
1034 BuildMI(MBB, I, DL, get(Hexagon::PS_storerl))
1035 .addFrameIndex(FI)
1036 .addImm(0)
1037 .addReg(SrcReg, KillFlag)
1038 .addMemOperand(MMO);
1039 } else if (Hexagon::HlxLLRRegClass.hasSubClassEq(RC)) {
1040 BuildMI(MBB, I, DL, get(Hexagon::PS_storerll))
1041 .addFrameIndex(FI)
1042 .addImm(0)
1043 .addReg(SrcReg, KillFlag)
1044 .addMemOperand(MMO);
1045 } else {
1046 llvm_unreachable("Unimplemented");
1047 }
1048}
1049
1052 Register DestReg, int FI,
1053 const TargetRegisterClass *RC,
1054 Register VReg, unsigned SubReg,
1055 MachineInstr::MIFlag Flags) const {
1056 DebugLoc DL = MBB.findDebugLoc(I);
1057 MachineFunction &MF = *MBB.getParent();
1058 MachineFrameInfo &MFI = MF.getFrameInfo();
1059 auto &HMFI = *MF.getInfo<HexagonMachineFunctionInfo>();
1060
1061 int MFIIndex = FI;
1062 MachineFrameInfo *MMFI = &MFI;
1063 if (HMFI.isVTCMStackIndex(FI)) {
1064 MFIIndex = HMFI.getMappedVTCMObjectIndex(FI);
1065 MMFI = &HMFI.getVTCMFrameInfo();
1066 }
1069 MMFI->getObjectSize(MFIIndex), MMFI->getObjectAlign(MFIIndex));
1070
1071 if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) {
1072 BuildMI(MBB, I, DL, get(Hexagon::L2_loadri_io), DestReg)
1073 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1074 } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) {
1075 BuildMI(MBB, I, DL, get(Hexagon::L2_loadrd_io), DestReg)
1076 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1077 } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) {
1078 BuildMI(MBB, I, DL, get(Hexagon::LDriw_pred), DestReg)
1079 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1080 } else if (Hexagon::ModRegsRegClass.hasSubClassEq(RC)) {
1081 BuildMI(MBB, I, DL, get(Hexagon::LDriw_ctr), DestReg)
1082 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1083 } else if (Hexagon::CircRegsRegClass.hasSubClassEq(RC)) {
1084 BuildMI(MBB, I, DL, get(Hexagon::LDriw_circ), DestReg)
1085 .addFrameIndex(FI)
1086 .addMemOperand(MMO);
1087 } else if (Hexagon::HvxQRRegClass.hasSubClassEq(RC)) {
1088 BuildMI(MBB, I, DL, get(Hexagon::PS_vloadrq_ai), DestReg)
1089 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1090 } else if (Hexagon::HvxVRRegClass.hasSubClassEq(RC)) {
1091 BuildMI(MBB, I, DL, get(Hexagon::PS_vloadrv_ai), DestReg)
1092 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1093 } else if (Hexagon::HvxWRRegClass.hasSubClassEq(RC)) {
1094 BuildMI(MBB, I, DL, get(Hexagon::PS_vloadrw_ai), DestReg)
1095 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
1096 } else if (Hexagon::HlxLRRegClass.hasSubClassEq(RC)) {
1097 BuildMI(MBB, I, DL, get(Hexagon::PS_loadrl), DestReg)
1098 .addFrameIndex(FI)
1099 .addImm(0)
1100 .addMemOperand(MMO);
1101 } else if (Hexagon::HlxLLRRegClass.hasSubClassEq(RC)) {
1102 BuildMI(MBB, I, DL, get(Hexagon::PS_loadrll), DestReg)
1103 .addFrameIndex(FI)
1104 .addImm(0)
1105 .addMemOperand(MMO);
1106 } else {
1107 llvm_unreachable("Can't store this register to stack slot");
1108 }
1109}
1110
1111/// expandPostRAPseudo - This function is called for all pseudo instructions
1112/// that remain after register allocation. Many pseudo instructions are
1113/// created to help register allocation. This is the place to convert them
1114/// into real instructions. The target can edit MI in place, or it can insert
1115/// new instructions and erase MI. The function should return true if
1116/// anything was changed.
1118 MachineBasicBlock &MBB = *MI.getParent();
1119 MachineFunction &MF = *MBB.getParent();
1121 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
1122 LivePhysRegs LiveIn(HRI), LiveOut(HRI);
1123 DebugLoc DL = MI.getDebugLoc();
1124 unsigned Opc = MI.getOpcode();
1125
1126 auto RealCirc = [&](unsigned Opc, bool HasImm, unsigned MxOp) {
1127 Register M_CSx = MI.getOperand(MxOp).getReg();
1128 Register Mx = HRI.getSubReg(M_CSx, Hexagon::isub_hi);
1129 unsigned CSOp = HasImm ? 5 : 4;
1130 auto MIB = BuildMI(MBB, MI, DL, get(Opc));
1131 for (unsigned i = 0; i != CSOp; ++i)
1132 if (i == MxOp)
1133 MIB.addReg(Mx);
1134 else
1135 MIB.add(MI.getOperand(i));
1136 Register CSx = (M_CSx == Hexagon::CS_M0 ? Hexagon::CS0 : Hexagon::CS1);
1137 MIB.addReg(CSx, RegState::Implicit);
1138 MBB.erase(MI);
1139 return true;
1140 };
1141
1142 auto UseAligned = [&](const MachineInstr &MI, Align NeedAlign) {
1143 if (MI.memoperands().empty())
1144 return false;
1145 return all_of(MI.memoperands(), [NeedAlign](const MachineMemOperand *MMO) {
1146 return MMO->getAlign() >= NeedAlign;
1147 });
1148 };
1149
1150 switch (Opc) {
1151 case Hexagon::PS_call_instrprof_custom: {
1152 auto Op0 = MI.getOperand(0);
1153 assert(Op0.isGlobal() &&
1154 "First operand must be a global containing handler name.");
1155 const GlobalValue *NameVar = Op0.getGlobal();
1156 const GlobalVariable *GV = dyn_cast<GlobalVariable>(NameVar);
1157 auto *Arr = cast<ConstantDataArray>(GV->getInitializer());
1158 StringRef NameStr = Arr->isCString() ? Arr->getAsCString() : Arr->getAsString();
1159
1160 MachineOperand &Op1 = MI.getOperand(1);
1161 // Set R0 with the imm value to be passed to the custom profiling handler.
1162 BuildMI(MBB, MI, DL, get(Hexagon::A2_tfrsi), Hexagon::R0)
1163 .addImm(Op1.getImm());
1164 // The call to the custom handler is being treated as a special one as the
1165 // callee is responsible for saving and restoring all the registers
1166 // (including caller saved registers) it needs to modify. This is
1167 // done to reduce the impact of instrumentation on the code being
1168 // instrumented/profiled.
1169 // NOTE: R14, R15 and R28 are reserved for PLT handling. These registers
1170 // are in the Def list of the Hexagon::PS_call_instrprof_custom and
1171 // therefore will be handled appropriately duing register allocation.
1172
1173 // TODO: It may be a good idea to add a separate pseudo instruction for
1174 // static relocation which doesn't need to reserve r14, r15 and r28.
1175
1176 auto MIB = BuildMI(MBB, MI, DL, get(Hexagon::J2_call))
1178 .addDef(Hexagon::R29, RegState::ImplicitDefine)
1179 .addDef(Hexagon::R30, RegState::ImplicitDefine)
1180 .addDef(Hexagon::R14, RegState::ImplicitDefine)
1181 .addDef(Hexagon::R15, RegState::ImplicitDefine)
1182 .addDef(Hexagon::R28, RegState::ImplicitDefine);
1183 const char *cstr = MF.createExternalSymbolName(NameStr);
1184 MIB.addExternalSymbol(cstr);
1185 MBB.erase(MI);
1186 return true;
1187 }
1188 case TargetOpcode::COPY: {
1189 MachineOperand &MD = MI.getOperand(0);
1190 MachineOperand &MS = MI.getOperand(1);
1191 MachineBasicBlock::iterator MBBI = MI.getIterator();
1192 if (MD.getReg() != MS.getReg() && !MS.isUndef()) {
1193 copyPhysReg(MBB, MI, DL, MD.getReg(), MS.getReg(), MS.isKill());
1194 std::prev(MBBI)->copyImplicitOps(*MBB.getParent(), MI);
1195 }
1196 MBB.erase(MBBI);
1197 return true;
1198 }
1199 case Hexagon::PS_aligna:
1200 BuildMI(MBB, MI, DL, get(Hexagon::A2_andir), MI.getOperand(0).getReg())
1201 .addReg(HRI.getFrameRegister())
1202 .addImm(-MI.getOperand(1).getImm());
1203 MBB.erase(MI);
1204 return true;
1205 case Hexagon::V6_vassignp: {
1206 Register SrcReg = MI.getOperand(1).getReg();
1207 Register DstReg = MI.getOperand(0).getReg();
1208 Register SrcLo = HRI.getSubReg(SrcReg, Hexagon::vsub_lo);
1209 Register SrcHi = HRI.getSubReg(SrcReg, Hexagon::vsub_hi);
1210 getLiveInRegsAt(LiveIn, MI);
1211 RegState UndefLo = getUndefRegState(!LiveIn.contains(SrcLo));
1212 RegState UndefHi = getUndefRegState(!LiveIn.contains(SrcHi));
1213 RegState Kill = getKillRegState(MI.getOperand(1).isKill());
1214 BuildMI(MBB, MI, DL, get(Hexagon::V6_vcombine), DstReg)
1215 .addReg(SrcHi, UndefHi)
1216 .addReg(SrcLo, Kill | UndefLo);
1217 MBB.erase(MI);
1218 return true;
1219 }
1220 case Hexagon::V6_lo:
1221 case Hexagon::LX_lo: {
1222 Register SrcReg = MI.getOperand(1).getReg();
1223 Register DstReg = MI.getOperand(0).getReg();
1224 Register SrcSubLo = HRI.getSubReg(SrcReg, Hexagon::vsub_lo);
1225 copyPhysReg(MBB, MI, DL, DstReg, SrcSubLo, MI.getOperand(1).isKill());
1226 MBB.erase(MI);
1227 return true;
1228 }
1229 case Hexagon::V6_hi:
1230 case Hexagon::LX_hi: {
1231 Register SrcReg = MI.getOperand(1).getReg();
1232 Register DstReg = MI.getOperand(0).getReg();
1233 Register SrcSubHi = HRI.getSubReg(SrcReg, Hexagon::vsub_hi);
1234 copyPhysReg(MBB, MI, DL, DstReg, SrcSubHi, MI.getOperand(1).isKill());
1235 MBB.erase(MI);
1236 return true;
1237 }
1238 case Hexagon::PS_vloadrv_ai: {
1239 Register DstReg = MI.getOperand(0).getReg();
1240 const MachineOperand &BaseOp = MI.getOperand(1);
1241 assert(BaseOp.getSubReg() == 0);
1242 int Offset = MI.getOperand(2).getImm();
1243 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
1244 unsigned NewOpc = UseAligned(MI, NeedAlign) ? Hexagon::V6_vL32b_ai
1245 : Hexagon::V6_vL32Ub_ai;
1246 BuildMI(MBB, MI, DL, get(NewOpc), DstReg)
1247 .addReg(BaseOp.getReg(), getRegState(BaseOp))
1248 .addImm(Offset)
1249 .cloneMemRefs(MI);
1250 MBB.erase(MI);
1251 return true;
1252 }
1253 case Hexagon::PS_loadrl: {
1254 Register DstReg = MI.getOperand(0).getReg();
1255 const MachineOperand &BaseOp = MI.getOperand(1);
1256 assert(BaseOp.getSubReg() == 0);
1257 int Offset = MI.getOperand(2).getImm();
1258 Register BaseReg = BaseOp.getReg();
1259 BuildMI(MBB, MI, DL, get(Hexagon::A2_addi), BaseReg)
1260 .addReg(BaseReg, getRegState(BaseOp) | RegState::Kill)
1261 .addImm(Offset);
1262 BuildMI(MBB, MI, DL, get(Hexagon::LX_L16b_pseudo), DstReg)
1263 .addReg(BaseReg, getRegState(BaseOp))
1264 .addReg(Hexagon::VSP, RegState::Implicit)
1265 .cloneMemRefs(MI);
1266 MBB.erase(MI);
1267 return true;
1268 }
1269 case Hexagon::PS_vloadrw_ai: {
1270 Register DstReg = MI.getOperand(0).getReg();
1271 const MachineOperand &BaseOp = MI.getOperand(1);
1272 assert(BaseOp.getSubReg() == 0);
1273 int Offset = MI.getOperand(2).getImm();
1274 unsigned VecOffset = HRI.getSpillSize(Hexagon::HvxVRRegClass);
1275 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
1276 unsigned NewOpc = UseAligned(MI, NeedAlign) ? Hexagon::V6_vL32b_ai
1277 : Hexagon::V6_vL32Ub_ai;
1278 BuildMI(MBB, MI, DL, get(NewOpc),
1279 HRI.getSubReg(DstReg, Hexagon::vsub_lo))
1280 .addReg(BaseOp.getReg(), getRegState(BaseOp) & ~RegState::Kill)
1281 .addImm(Offset)
1282 .cloneMemRefs(MI);
1283 BuildMI(MBB, MI, DL, get(NewOpc),
1284 HRI.getSubReg(DstReg, Hexagon::vsub_hi))
1285 .addReg(BaseOp.getReg(), getRegState(BaseOp))
1286 .addImm(Offset + VecOffset)
1287 .cloneMemRefs(MI);
1288 MBB.erase(MI);
1289 return true;
1290 }
1291 case Hexagon::PS_vstorerv_ai: {
1292 const MachineOperand &SrcOp = MI.getOperand(2);
1293 assert(SrcOp.getSubReg() == 0);
1294 const MachineOperand &BaseOp = MI.getOperand(0);
1295 assert(BaseOp.getSubReg() == 0);
1296 int Offset = MI.getOperand(1).getImm();
1297 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
1298 unsigned NewOpc = UseAligned(MI, NeedAlign) ? Hexagon::V6_vS32b_ai
1299 : Hexagon::V6_vS32Ub_ai;
1300 BuildMI(MBB, MI, DL, get(NewOpc))
1301 .addReg(BaseOp.getReg(), getRegState(BaseOp))
1302 .addImm(Offset)
1304 .cloneMemRefs(MI);
1305 MBB.erase(MI);
1306 return true;
1307 }
1308 case Hexagon::PS_storerl: {
1309 const MachineOperand &SrcOp = MI.getOperand(2);
1310 assert(SrcOp.getSubReg() == 0);
1311 const MachineOperand &BaseOp = MI.getOperand(0);
1312 assert(BaseOp.getSubReg() == 0);
1313 Register BaseReg = BaseOp.getReg();
1314 int Offset = MI.getOperand(1).getImm();
1315 BuildMI(MBB, MI, DL, get(Hexagon::A2_addi), BaseReg)
1316 .addReg(BaseReg, getRegState(BaseOp) | RegState::Kill)
1317 .addImm(Offset);
1318 BuildMI(MBB, MI, DL, get(Hexagon::LX_S16b_pseudo))
1319 .addReg(BaseReg, getRegState(BaseOp))
1321 .addReg(Hexagon::VSP, RegState::Implicit)
1322 .cloneMemRefs(MI);
1323 MBB.erase(MI);
1324 return true;
1325 }
1326 case Hexagon::PS_vstorerw_ai: {
1327 Register SrcReg = MI.getOperand(2).getReg();
1328 const MachineOperand &BaseOp = MI.getOperand(0);
1329 assert(BaseOp.getSubReg() == 0);
1330 int Offset = MI.getOperand(1).getImm();
1331 unsigned VecOffset = HRI.getSpillSize(Hexagon::HvxVRRegClass);
1332 Align NeedAlign = HRI.getSpillAlign(Hexagon::HvxVRRegClass);
1333 unsigned NewOpc = UseAligned(MI, NeedAlign) ? Hexagon::V6_vS32b_ai
1334 : Hexagon::V6_vS32Ub_ai;
1335 BuildMI(MBB, MI, DL, get(NewOpc))
1336 .addReg(BaseOp.getReg(), getRegState(BaseOp) & ~RegState::Kill)
1337 .addImm(Offset)
1338 .addReg(HRI.getSubReg(SrcReg, Hexagon::vsub_lo))
1339 .cloneMemRefs(MI);
1340 BuildMI(MBB, MI, DL, get(NewOpc))
1341 .addReg(BaseOp.getReg(), getRegState(BaseOp))
1342 .addImm(Offset + VecOffset)
1343 .addReg(HRI.getSubReg(SrcReg, Hexagon::vsub_hi))
1344 .cloneMemRefs(MI);
1345 MBB.erase(MI);
1346 return true;
1347 }
1348 case Hexagon::PS_true: {
1349 Register Reg = MI.getOperand(0).getReg();
1350 BuildMI(MBB, MI, DL, get(Hexagon::C2_orn), Reg)
1351 .addReg(Reg, RegState::Undef)
1352 .addReg(Reg, RegState::Undef);
1353 MBB.erase(MI);
1354 return true;
1355 }
1356 case Hexagon::PS_false: {
1357 Register Reg = MI.getOperand(0).getReg();
1358 BuildMI(MBB, MI, DL, get(Hexagon::C2_andn), Reg)
1359 .addReg(Reg, RegState::Undef)
1360 .addReg(Reg, RegState::Undef);
1361 MBB.erase(MI);
1362 return true;
1363 }
1364 case Hexagon::PS_qtrue: {
1365 BuildMI(MBB, MI, DL, get(Hexagon::V6_veqw), MI.getOperand(0).getReg())
1366 .addReg(Hexagon::V0, RegState::Undef)
1367 .addReg(Hexagon::V0, RegState::Undef);
1368 MBB.erase(MI);
1369 return true;
1370 }
1371 case Hexagon::PS_qfalse: {
1372 BuildMI(MBB, MI, DL, get(Hexagon::V6_vgtw), MI.getOperand(0).getReg())
1373 .addReg(Hexagon::V0, RegState::Undef)
1374 .addReg(Hexagon::V0, RegState::Undef);
1375 MBB.erase(MI);
1376 return true;
1377 }
1378 case Hexagon::PS_vdd0: {
1379 Register Vd = MI.getOperand(0).getReg();
1380 BuildMI(MBB, MI, DL, get(Hexagon::V6_vsubw_dv), Vd)
1382 .addReg(Vd, RegState::Undef);
1383 MBB.erase(MI);
1384 return true;
1385 }
1386 case Hexagon::PS_vmulw: {
1387 // Expand a 64-bit vector multiply into 2 32-bit scalar multiplies.
1388 Register DstReg = MI.getOperand(0).getReg();
1389 Register Src1Reg = MI.getOperand(1).getReg();
1390 Register Src2Reg = MI.getOperand(2).getReg();
1391 Register Src1SubHi = HRI.getSubReg(Src1Reg, Hexagon::isub_hi);
1392 Register Src1SubLo = HRI.getSubReg(Src1Reg, Hexagon::isub_lo);
1393 Register Src2SubHi = HRI.getSubReg(Src2Reg, Hexagon::isub_hi);
1394 Register Src2SubLo = HRI.getSubReg(Src2Reg, Hexagon::isub_lo);
1395 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_mpyi),
1396 HRI.getSubReg(DstReg, Hexagon::isub_hi))
1397 .addReg(Src1SubHi)
1398 .addReg(Src2SubHi);
1399 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_mpyi),
1400 HRI.getSubReg(DstReg, Hexagon::isub_lo))
1401 .addReg(Src1SubLo)
1402 .addReg(Src2SubLo);
1403 MBB.erase(MI);
1404 return true;
1405 }
1406 case Hexagon::PS_vmulw_acc: {
1407 // Expand 64-bit vector multiply with addition into 2 scalar multiplies.
1408 Register DstReg = MI.getOperand(0).getReg();
1409 Register Src1Reg = MI.getOperand(1).getReg();
1410 Register Src2Reg = MI.getOperand(2).getReg();
1411 Register Src3Reg = MI.getOperand(3).getReg();
1412 Register Src1SubHi = HRI.getSubReg(Src1Reg, Hexagon::isub_hi);
1413 Register Src1SubLo = HRI.getSubReg(Src1Reg, Hexagon::isub_lo);
1414 Register Src2SubHi = HRI.getSubReg(Src2Reg, Hexagon::isub_hi);
1415 Register Src2SubLo = HRI.getSubReg(Src2Reg, Hexagon::isub_lo);
1416 Register Src3SubHi = HRI.getSubReg(Src3Reg, Hexagon::isub_hi);
1417 Register Src3SubLo = HRI.getSubReg(Src3Reg, Hexagon::isub_lo);
1418 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_maci),
1419 HRI.getSubReg(DstReg, Hexagon::isub_hi))
1420 .addReg(Src1SubHi)
1421 .addReg(Src2SubHi)
1422 .addReg(Src3SubHi);
1423 BuildMI(MBB, MI, MI.getDebugLoc(), get(Hexagon::M2_maci),
1424 HRI.getSubReg(DstReg, Hexagon::isub_lo))
1425 .addReg(Src1SubLo)
1426 .addReg(Src2SubLo)
1427 .addReg(Src3SubLo);
1428 MBB.erase(MI);
1429 return true;
1430 }
1431 case Hexagon::PS_pselect: {
1432 const MachineOperand &Op0 = MI.getOperand(0);
1433 const MachineOperand &Op1 = MI.getOperand(1);
1434 const MachineOperand &Op2 = MI.getOperand(2);
1435 const MachineOperand &Op3 = MI.getOperand(3);
1436 Register Rd = Op0.getReg();
1437 Register Pu = Op1.getReg();
1438 Register Rs = Op2.getReg();
1439 Register Rt = Op3.getReg();
1440 DebugLoc DL = MI.getDebugLoc();
1441 RegState K1 = getKillRegState(Op1.isKill());
1442 RegState K2 = getKillRegState(Op2.isKill());
1443 RegState K3 = getKillRegState(Op3.isKill());
1444 if (Rd != Rs)
1445 BuildMI(MBB, MI, DL, get(Hexagon::A2_tfrpt), Rd)
1446 .addReg(Pu, (Rd == Rt) ? K1 : RegState::NoFlags)
1447 .addReg(Rs, K2);
1448 if (Rd != Rt)
1449 BuildMI(MBB, MI, DL, get(Hexagon::A2_tfrpf), Rd)
1450 .addReg(Pu, K1)
1451 .addReg(Rt, K3);
1452 MBB.erase(MI);
1453 return true;
1454 }
1455 case Hexagon::PS_vselect: {
1456 const MachineOperand &Op0 = MI.getOperand(0);
1457 const MachineOperand &Op1 = MI.getOperand(1);
1458 const MachineOperand &Op2 = MI.getOperand(2);
1459 const MachineOperand &Op3 = MI.getOperand(3);
1460 getLiveOutRegsAt(LiveOut, MI);
1461 bool IsDestLive = !LiveOut.available(MRI, Op0.getReg());
1462 Register PReg = Op1.getReg();
1463 assert(Op1.getSubReg() == 0);
1464 RegState PState = getRegState(Op1);
1465
1466 if (Op0.getReg() != Op2.getReg()) {
1467 RegState S =
1468 Op0.getReg() != Op3.getReg() ? PState & ~RegState::Kill : PState;
1469 auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vcmov))
1470 .add(Op0)
1471 .addReg(PReg, S)
1472 .add(Op2);
1473 if (IsDestLive)
1474 T.addReg(Op0.getReg(), RegState::Implicit);
1475 IsDestLive = true;
1476 }
1477 if (Op0.getReg() != Op3.getReg()) {
1478 auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vncmov))
1479 .add(Op0)
1480 .addReg(PReg, PState)
1481 .add(Op3);
1482 if (IsDestLive)
1483 T.addReg(Op0.getReg(), RegState::Implicit);
1484 }
1485 MBB.erase(MI);
1486 return true;
1487 }
1488 case Hexagon::PS_wselect: {
1489 MachineOperand &Op0 = MI.getOperand(0);
1490 MachineOperand &Op1 = MI.getOperand(1);
1491 MachineOperand &Op2 = MI.getOperand(2);
1492 MachineOperand &Op3 = MI.getOperand(3);
1493 getLiveOutRegsAt(LiveOut, MI);
1494 bool IsDestLive = !LiveOut.available(MRI, Op0.getReg());
1495 Register PReg = Op1.getReg();
1496 assert(Op1.getSubReg() == 0);
1497 RegState PState = getRegState(Op1);
1498
1499 if (Op0.getReg() != Op2.getReg()) {
1500 RegState S =
1501 Op0.getReg() != Op3.getReg() ? PState & ~RegState::Kill : PState;
1502 Register SrcLo = HRI.getSubReg(Op2.getReg(), Hexagon::vsub_lo);
1503 Register SrcHi = HRI.getSubReg(Op2.getReg(), Hexagon::vsub_hi);
1504 auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vccombine))
1505 .add(Op0)
1506 .addReg(PReg, S)
1507 .addReg(SrcHi)
1508 .addReg(SrcLo);
1509 if (IsDestLive)
1510 T.addReg(Op0.getReg(), RegState::Implicit);
1511 IsDestLive = true;
1512 }
1513 if (Op0.getReg() != Op3.getReg()) {
1514 Register SrcLo = HRI.getSubReg(Op3.getReg(), Hexagon::vsub_lo);
1515 Register SrcHi = HRI.getSubReg(Op3.getReg(), Hexagon::vsub_hi);
1516 auto T = BuildMI(MBB, MI, DL, get(Hexagon::V6_vnccombine))
1517 .add(Op0)
1518 .addReg(PReg, PState)
1519 .addReg(SrcHi)
1520 .addReg(SrcLo);
1521 if (IsDestLive)
1522 T.addReg(Op0.getReg(), RegState::Implicit);
1523 }
1524 MBB.erase(MI);
1525 return true;
1526 }
1527
1528 case Hexagon::PS_crash: {
1529 // Generate a misaligned load that is guaranteed to cause a crash.
1530 class CrashPseudoSourceValue : public PseudoSourceValue {
1531 public:
1532 CrashPseudoSourceValue(const TargetMachine &TM)
1533 : PseudoSourceValue(TargetCustom, TM) {}
1534
1535 bool isConstant(const MachineFrameInfo *) const override {
1536 return false;
1537 }
1538 bool isAliased(const MachineFrameInfo *) const override {
1539 return false;
1540 }
1541 bool mayAlias(const MachineFrameInfo *) const override {
1542 return false;
1543 }
1544 void printCustom(raw_ostream &OS) const override {
1545 OS << "MisalignedCrash";
1546 }
1547 };
1548
1549 static const CrashPseudoSourceValue CrashPSV(MF.getTarget());
1551 MachinePointerInfo(&CrashPSV),
1553 Align(1));
1554 BuildMI(MBB, MI, DL, get(Hexagon::PS_loadrdabs), Hexagon::D13)
1555 .addImm(0xBADC0FEE) // Misaligned load.
1556 .addMemOperand(MMO);
1557 MBB.erase(MI);
1558 return true;
1559 }
1560
1561 case Hexagon::PS_tailcall_i:
1562 MI.setDesc(get(Hexagon::J2_jump));
1563 return true;
1564 case Hexagon::PS_tailcall_r:
1565 case Hexagon::PS_jmpret:
1566 MI.setDesc(get(Hexagon::J2_jumpr));
1567 return true;
1568 case Hexagon::PS_jmprett:
1569 MI.setDesc(get(Hexagon::J2_jumprt));
1570 return true;
1571 case Hexagon::PS_jmpretf:
1572 MI.setDesc(get(Hexagon::J2_jumprf));
1573 return true;
1574 case Hexagon::PS_jmprettnewpt:
1575 MI.setDesc(get(Hexagon::J2_jumprtnewpt));
1576 return true;
1577 case Hexagon::PS_jmpretfnewpt:
1578 MI.setDesc(get(Hexagon::J2_jumprfnewpt));
1579 return true;
1580 case Hexagon::PS_jmprettnew:
1581 MI.setDesc(get(Hexagon::J2_jumprtnew));
1582 return true;
1583 case Hexagon::PS_jmpretfnew:
1584 MI.setDesc(get(Hexagon::J2_jumprfnew));
1585 return true;
1586
1587 case Hexagon::PS_loadrub_pci:
1588 return RealCirc(Hexagon::L2_loadrub_pci, /*HasImm*/true, /*MxOp*/4);
1589 case Hexagon::PS_loadrb_pci:
1590 return RealCirc(Hexagon::L2_loadrb_pci, /*HasImm*/true, /*MxOp*/4);
1591 case Hexagon::PS_loadruh_pci:
1592 return RealCirc(Hexagon::L2_loadruh_pci, /*HasImm*/true, /*MxOp*/4);
1593 case Hexagon::PS_loadrh_pci:
1594 return RealCirc(Hexagon::L2_loadrh_pci, /*HasImm*/true, /*MxOp*/4);
1595 case Hexagon::PS_loadri_pci:
1596 return RealCirc(Hexagon::L2_loadri_pci, /*HasImm*/true, /*MxOp*/4);
1597 case Hexagon::PS_loadrd_pci:
1598 return RealCirc(Hexagon::L2_loadrd_pci, /*HasImm*/true, /*MxOp*/4);
1599 case Hexagon::PS_loadrub_pcr:
1600 return RealCirc(Hexagon::L2_loadrub_pcr, /*HasImm*/false, /*MxOp*/3);
1601 case Hexagon::PS_loadrb_pcr:
1602 return RealCirc(Hexagon::L2_loadrb_pcr, /*HasImm*/false, /*MxOp*/3);
1603 case Hexagon::PS_loadruh_pcr:
1604 return RealCirc(Hexagon::L2_loadruh_pcr, /*HasImm*/false, /*MxOp*/3);
1605 case Hexagon::PS_loadrh_pcr:
1606 return RealCirc(Hexagon::L2_loadrh_pcr, /*HasImm*/false, /*MxOp*/3);
1607 case Hexagon::PS_loadri_pcr:
1608 return RealCirc(Hexagon::L2_loadri_pcr, /*HasImm*/false, /*MxOp*/3);
1609 case Hexagon::PS_loadrd_pcr:
1610 return RealCirc(Hexagon::L2_loadrd_pcr, /*HasImm*/false, /*MxOp*/3);
1611 case Hexagon::PS_storerb_pci:
1612 return RealCirc(Hexagon::S2_storerb_pci, /*HasImm*/true, /*MxOp*/3);
1613 case Hexagon::PS_storerh_pci:
1614 return RealCirc(Hexagon::S2_storerh_pci, /*HasImm*/true, /*MxOp*/3);
1615 case Hexagon::PS_storerf_pci:
1616 return RealCirc(Hexagon::S2_storerf_pci, /*HasImm*/true, /*MxOp*/3);
1617 case Hexagon::PS_storeri_pci:
1618 return RealCirc(Hexagon::S2_storeri_pci, /*HasImm*/true, /*MxOp*/3);
1619 case Hexagon::PS_storerd_pci:
1620 return RealCirc(Hexagon::S2_storerd_pci, /*HasImm*/true, /*MxOp*/3);
1621 case Hexagon::PS_storerb_pcr:
1622 return RealCirc(Hexagon::S2_storerb_pcr, /*HasImm*/false, /*MxOp*/2);
1623 case Hexagon::PS_storerh_pcr:
1624 return RealCirc(Hexagon::S2_storerh_pcr, /*HasImm*/false, /*MxOp*/2);
1625 case Hexagon::PS_storerf_pcr:
1626 return RealCirc(Hexagon::S2_storerf_pcr, /*HasImm*/false, /*MxOp*/2);
1627 case Hexagon::PS_storeri_pcr:
1628 return RealCirc(Hexagon::S2_storeri_pcr, /*HasImm*/false, /*MxOp*/2);
1629 case Hexagon::PS_storerd_pcr:
1630 return RealCirc(Hexagon::S2_storerd_pcr, /*HasImm*/false, /*MxOp*/2);
1631 }
1632
1633 return false;
1634}
1635
1638 MachineBasicBlock &MBB = *MI.getParent();
1639 const DebugLoc &DL = MI.getDebugLoc();
1640 unsigned Opc = MI.getOpcode();
1642
1643 switch (Opc) {
1644 case Hexagon::V6_vgather_vscatter_mh_pseudo:
1645 // This is mainly a place holder. It will be extended.
1646 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermh))
1647 .add(MI.getOperand(2))
1648 .add(MI.getOperand(3))
1649 .add(MI.getOperand(4));
1650 BuildMI(MBB, MI, DL, get(Hexagon::V6_vscattermh))
1651 .add(MI.getOperand(2))
1652 .add(MI.getOperand(3))
1653 .add(MI.getOperand(4))
1654 .addReg(Hexagon::VTMP);
1655 MBB.erase(MI);
1656 return First.getInstrIterator();
1657 case Hexagon::V6_vgathermh_pseudo:
1658 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermh))
1659 .add(MI.getOperand(2))
1660 .add(MI.getOperand(3))
1661 .add(MI.getOperand(4));
1662 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1663 .add(MI.getOperand(0))
1664 .addImm(MI.getOperand(1).getImm())
1665 .addReg(Hexagon::VTMP);
1666 MBB.erase(MI);
1667 return First.getInstrIterator();
1668
1669 case Hexagon::V6_vgathermw_pseudo:
1670 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermw))
1671 .add(MI.getOperand(2))
1672 .add(MI.getOperand(3))
1673 .add(MI.getOperand(4));
1674 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1675 .add(MI.getOperand(0))
1676 .addImm(MI.getOperand(1).getImm())
1677 .addReg(Hexagon::VTMP);
1678 MBB.erase(MI);
1679 return First.getInstrIterator();
1680
1681 case Hexagon::V6_vgathermhw_pseudo:
1682 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermhw))
1683 .add(MI.getOperand(2))
1684 .add(MI.getOperand(3))
1685 .add(MI.getOperand(4));
1686 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1687 .add(MI.getOperand(0))
1688 .addImm(MI.getOperand(1).getImm())
1689 .addReg(Hexagon::VTMP);
1690 MBB.erase(MI);
1691 return First.getInstrIterator();
1692
1693 case Hexagon::V6_vgathermhq_pseudo:
1694 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermhq))
1695 .add(MI.getOperand(2))
1696 .add(MI.getOperand(3))
1697 .add(MI.getOperand(4))
1698 .add(MI.getOperand(5));
1699 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1700 .add(MI.getOperand(0))
1701 .addImm(MI.getOperand(1).getImm())
1702 .addReg(Hexagon::VTMP);
1703 MBB.erase(MI);
1704 return First.getInstrIterator();
1705
1706 case Hexagon::V6_vgathermwq_pseudo:
1707 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermwq))
1708 .add(MI.getOperand(2))
1709 .add(MI.getOperand(3))
1710 .add(MI.getOperand(4))
1711 .add(MI.getOperand(5));
1712 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1713 .add(MI.getOperand(0))
1714 .addImm(MI.getOperand(1).getImm())
1715 .addReg(Hexagon::VTMP);
1716 MBB.erase(MI);
1717 return First.getInstrIterator();
1718
1719 case Hexagon::V6_vgathermhwq_pseudo:
1720 First = BuildMI(MBB, MI, DL, get(Hexagon::V6_vgathermhwq))
1721 .add(MI.getOperand(2))
1722 .add(MI.getOperand(3))
1723 .add(MI.getOperand(4))
1724 .add(MI.getOperand(5));
1725 BuildMI(MBB, MI, DL, get(Hexagon::V6_vS32b_new_ai))
1726 .add(MI.getOperand(0))
1727 .addImm(MI.getOperand(1).getImm())
1728 .addReg(Hexagon::VTMP);
1729 MBB.erase(MI);
1730 return First.getInstrIterator();
1731 }
1732
1733 return MI.getIterator();
1734}
1735
1736// We indicate that we want to reverse the branch by
1737// inserting the reversed branching opcode.
1740 if (Cond.empty())
1741 return true;
1742 assert(Cond[0].isImm() && "First entry in the cond vector not imm-val");
1743 unsigned opcode = Cond[0].getImm();
1744 //unsigned temp;
1745 assert(get(opcode).isBranch() && "Should be a branching condition.");
1746 if (isEndLoopN(opcode))
1747 return true;
1748 unsigned NewOpcode = getInvertedPredicatedOpcode(opcode);
1749 Cond[0].setImm(NewOpcode);
1750 return false;
1751}
1752
1758
1762
1764 unsigned BasePos, OffsetPos;
1765 if (!getBaseAndOffsetPosition(MI, BasePos, OffsetPos))
1766 return false;
1767 return isPostIncrement(MI) && MI.getOperand(OffsetPos).isImm();
1768}
1769
1770// Returns true if an instruction is predicated irrespective of the predicate
1771// sense. For example, all of the following will return true.
1772// if (p0) R1 = add(R2, R3)
1773// if (!p0) R1 = add(R2, R3)
1774// if (p0.new) R1 = add(R2, R3)
1775// if (!p0.new) R1 = add(R2, R3)
1776// Note: New-value stores are not included here as in the current
1777// implementation, we don't need to check their predicate sense.
1779 const uint64_t F = MI.getDesc().TSFlags;
1781}
1782
1785 if (Cond.empty() || isNewValueJump(Cond[0].getImm()) ||
1786 isEndLoopN(Cond[0].getImm())) {
1787 LLVM_DEBUG(dbgs() << "\nCannot predicate:"; MI.dump(););
1788 return false;
1789 }
1790 int Opc = MI.getOpcode();
1791 assert (isPredicable(MI) && "Expected predicable instruction");
1792 bool invertJump = predOpcodeHasNot(Cond);
1793
1794 // We have to predicate MI "in place", i.e. after this function returns,
1795 // MI will need to be transformed into a predicated form. To avoid com-
1796 // plicated manipulations with the operands (handling tied operands,
1797 // etc.), build a new temporary instruction, then overwrite MI with it.
1798
1799 MachineBasicBlock &B = *MI.getParent();
1800 DebugLoc DL = MI.getDebugLoc();
1801 unsigned PredOpc = getCondOpcode(Opc, invertJump);
1802 MachineInstrBuilder T = BuildMI(B, MI, DL, get(PredOpc));
1803 unsigned NOp = 0, NumOps = MI.getNumOperands();
1804 while (NOp < NumOps) {
1805 MachineOperand &Op = MI.getOperand(NOp);
1806 if (!Op.isReg() || !Op.isDef() || Op.isImplicit())
1807 break;
1808 T.add(Op);
1809 NOp++;
1810 }
1811
1812 Register PredReg;
1813 unsigned PredRegPos;
1814 RegState PredRegFlags = {};
1815 bool GotPredReg = getPredReg(Cond, PredReg, PredRegPos, PredRegFlags);
1816 (void)GotPredReg;
1817 assert(GotPredReg);
1818 T.addReg(PredReg, PredRegFlags);
1819 while (NOp < NumOps)
1820 T.add(MI.getOperand(NOp++));
1821
1822 MI.setDesc(get(PredOpc));
1823 while (unsigned n = MI.getNumOperands())
1824 MI.removeOperand(n-1);
1825 for (unsigned i = 0, n = T->getNumOperands(); i < n; ++i)
1826 MI.addOperand(T->getOperand(i));
1827
1828 MachineBasicBlock::instr_iterator TI = T->getIterator();
1829 B.erase(TI);
1830
1831 MachineRegisterInfo &MRI = B.getParent()->getRegInfo();
1832 MRI.clearKillFlags(PredReg);
1833 return true;
1834}
1835
1837 ArrayRef<MachineOperand> Pred2) const {
1838 // TODO: Fix this
1839 return false;
1840}
1841
1843 std::vector<MachineOperand> &Pred,
1844 bool SkipDead) const {
1845 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
1846
1847 for (const MachineOperand &MO : MI.operands()) {
1848 if (MO.isReg()) {
1849 if (!MO.isDef())
1850 continue;
1851 const TargetRegisterClass* RC = HRI.getMinimalPhysRegClass(MO.getReg());
1852 if (RC == &Hexagon::PredRegsRegClass) {
1853 Pred.push_back(MO);
1854 return true;
1855 }
1856 continue;
1857 } else if (MO.isRegMask()) {
1858 for (Register PR : Hexagon::PredRegsRegClass) {
1859 if (!MI.modifiesRegister(PR, &HRI))
1860 continue;
1861 Pred.push_back(MO);
1862 return true;
1863 }
1864 }
1865 }
1866 return false;
1867}
1868
1870 if (!MI.getDesc().isPredicable())
1871 return false;
1872
1873 if (MI.isCall() || isTailCall(MI)) {
1874 if (!Subtarget.usePredicatedCalls())
1875 return false;
1876 }
1877
1878 // HVX loads are not predicable on v60, but are on v62.
1879 if (!Subtarget.hasV62Ops()) {
1880 switch (MI.getOpcode()) {
1881 case Hexagon::V6_vL32b_ai:
1882 case Hexagon::V6_vL32b_pi:
1883 case Hexagon::V6_vL32b_ppu:
1884 case Hexagon::V6_vL32b_cur_ai:
1885 case Hexagon::V6_vL32b_cur_pi:
1886 case Hexagon::V6_vL32b_cur_ppu:
1887 case Hexagon::V6_vL32b_nt_ai:
1888 case Hexagon::V6_vL32b_nt_pi:
1889 case Hexagon::V6_vL32b_nt_ppu:
1890 case Hexagon::V6_vL32b_tmp_ai:
1891 case Hexagon::V6_vL32b_tmp_pi:
1892 case Hexagon::V6_vL32b_tmp_ppu:
1893 case Hexagon::V6_vL32b_nt_cur_ai:
1894 case Hexagon::V6_vL32b_nt_cur_pi:
1895 case Hexagon::V6_vL32b_nt_cur_ppu:
1896 case Hexagon::V6_vL32b_nt_tmp_ai:
1897 case Hexagon::V6_vL32b_nt_tmp_pi:
1898 case Hexagon::V6_vL32b_nt_tmp_ppu:
1899 return false;
1900 }
1901 }
1902 return true;
1903}
1904
1906 bool Invert) const {
1907 if (Invert)
1908 return false;
1909
1910 switch (Inst.getOpcode()) {
1911 // TODO: Add more instructions to be handled by MachineCombiner.
1912 case Hexagon::F2_sfadd:
1914 default:
1915 return false;
1916 }
1917}
1918
1920 const MachineBasicBlock *MBB,
1921 const MachineFunction &MF) const {
1922 // Debug info is never a scheduling boundary. It's necessary to be explicit
1923 // due to the special treatment of IT instructions below, otherwise a
1924 // dbg_value followed by an IT will result in the IT instruction being
1925 // considered a scheduling hazard, which is wrong. It should be the actual
1926 // instruction preceding the dbg_value instruction(s), just like it is
1927 // when debug info is not present.
1928 if (MI.isDebugInstr())
1929 return false;
1930
1931 // Throwing call is a boundary.
1932 if (MI.isCall()) {
1933 // Don't mess around with no return calls.
1934 if (doesNotReturn(MI))
1935 return true;
1936 // If any of the block's successors is a landing pad, this could be a
1937 // throwing call.
1938 for (auto *I : MBB->successors())
1939 if (I->isEHPad())
1940 return true;
1941 }
1942
1943 // Terminators and labels can't be scheduled around.
1944 if (MI.getDesc().isTerminator() || MI.isPosition())
1945 return true;
1946
1947 // INLINEASM_BR can jump to another block
1948 if (MI.getOpcode() == TargetOpcode::INLINEASM_BR)
1949 return true;
1950
1951 if (MI.isInlineAsm() && !ScheduleInlineAsm)
1952 return true;
1953
1954 return false;
1955}
1956
1957/// Measure the specified inline asm to determine an approximation of its
1958/// length.
1959/// Comments (which run till the next SeparatorString or newline) do not
1960/// count as an instruction.
1961/// Any other non-whitespace text is considered an instruction, with
1962/// multiple instructions separated by SeparatorString or newlines.
1963/// Variable-length instructions are not handled here; this function
1964/// may be overloaded in the target code to do that.
1965/// Hexagon counts the number of ##'s and adjust for that many
1966/// constant exenders.
1968 const MCAsmInfo &MAI,
1969 const TargetSubtargetInfo *STI) const {
1970 StringRef AStr(Str);
1971 // Count the number of instructions in the asm.
1972 bool atInsnStart = true;
1973 unsigned Length = 0;
1974 const unsigned MaxInstLength = MAI.getMaxInstLength(STI);
1975 for (; *Str; ++Str) {
1976 if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(),
1977 strlen(MAI.getSeparatorString())) == 0)
1978 atInsnStart = true;
1979 if (atInsnStart && !isSpace(static_cast<unsigned char>(*Str))) {
1980 Length += MaxInstLength;
1981 atInsnStart = false;
1982 }
1983 if (atInsnStart && strncmp(Str, MAI.getCommentString().data(),
1984 MAI.getCommentString().size()) == 0)
1985 atInsnStart = false;
1986 }
1987
1988 // Add to size number of constant extenders seen * 4.
1989 StringRef Occ("##");
1990 Length += AStr.count(Occ)*4;
1991 return Length;
1992}
1993
2001
2002/// For a comparison instruction, return the source registers in
2003/// \p SrcReg and \p SrcReg2 if having two register operands, and the value it
2004/// compares against in CmpValue. Return true if the comparison instruction
2005/// can be analyzed.
2007 Register &SrcReg2, int64_t &Mask,
2008 int64_t &Value) const {
2009 unsigned Opc = MI.getOpcode();
2010
2011 // Set mask and the first source register.
2012 switch (Opc) {
2013 case Hexagon::C2_cmpeq:
2014 case Hexagon::C2_cmpeqp:
2015 case Hexagon::C2_cmpgt:
2016 case Hexagon::C2_cmpgtp:
2017 case Hexagon::C2_cmpgtu:
2018 case Hexagon::C2_cmpgtup:
2019 case Hexagon::C4_cmpneq:
2020 case Hexagon::C4_cmplte:
2021 case Hexagon::C4_cmplteu:
2022 case Hexagon::C2_cmpeqi:
2023 case Hexagon::C2_cmpgti:
2024 case Hexagon::C2_cmpgtui:
2025 case Hexagon::C4_cmpneqi:
2026 case Hexagon::C4_cmplteui:
2027 case Hexagon::C4_cmpltei:
2028 SrcReg = MI.getOperand(1).getReg();
2029 Mask = ~0;
2030 break;
2031 case Hexagon::A4_cmpbeq:
2032 case Hexagon::A4_cmpbgt:
2033 case Hexagon::A4_cmpbgtu:
2034 case Hexagon::A4_cmpbeqi:
2035 case Hexagon::A4_cmpbgti:
2036 case Hexagon::A4_cmpbgtui:
2037 SrcReg = MI.getOperand(1).getReg();
2038 Mask = 0xFF;
2039 break;
2040 case Hexagon::A4_cmpheq:
2041 case Hexagon::A4_cmphgt:
2042 case Hexagon::A4_cmphgtu:
2043 case Hexagon::A4_cmpheqi:
2044 case Hexagon::A4_cmphgti:
2045 case Hexagon::A4_cmphgtui:
2046 SrcReg = MI.getOperand(1).getReg();
2047 Mask = 0xFFFF;
2048 break;
2049 }
2050
2051 // Set the value/second source register.
2052 switch (Opc) {
2053 case Hexagon::C2_cmpeq:
2054 case Hexagon::C2_cmpeqp:
2055 case Hexagon::C2_cmpgt:
2056 case Hexagon::C2_cmpgtp:
2057 case Hexagon::C2_cmpgtu:
2058 case Hexagon::C2_cmpgtup:
2059 case Hexagon::A4_cmpbeq:
2060 case Hexagon::A4_cmpbgt:
2061 case Hexagon::A4_cmpbgtu:
2062 case Hexagon::A4_cmpheq:
2063 case Hexagon::A4_cmphgt:
2064 case Hexagon::A4_cmphgtu:
2065 case Hexagon::C4_cmpneq:
2066 case Hexagon::C4_cmplte:
2067 case Hexagon::C4_cmplteu:
2068 SrcReg2 = MI.getOperand(2).getReg();
2069 Value = 0;
2070 return true;
2071
2072 case Hexagon::C2_cmpeqi:
2073 case Hexagon::C2_cmpgtui:
2074 case Hexagon::C2_cmpgti:
2075 case Hexagon::C4_cmpneqi:
2076 case Hexagon::C4_cmplteui:
2077 case Hexagon::C4_cmpltei:
2078 case Hexagon::A4_cmpbeqi:
2079 case Hexagon::A4_cmpbgti:
2080 case Hexagon::A4_cmpbgtui:
2081 case Hexagon::A4_cmpheqi:
2082 case Hexagon::A4_cmphgti:
2083 case Hexagon::A4_cmphgtui: {
2084 SrcReg2 = 0;
2085 const MachineOperand &Op2 = MI.getOperand(2);
2086 if (!Op2.isImm())
2087 return false;
2088 Value = MI.getOperand(2).getImm();
2089 return true;
2090 }
2091 }
2092
2093 return false;
2094}
2095
2097 const MachineInstr &MI,
2098 unsigned *PredCost) const {
2099 return getInstrTimingClassLatency(ItinData, MI);
2100}
2101
2103 const TargetSubtargetInfo &STI) const {
2105 return static_cast<const HexagonSubtarget&>(STI).createDFAPacketizer(II);
2106}
2107
2108// Inspired by this pair:
2109// %r13 = L2_loadri_io %r29, 136; mem:LD4[FixedStack0]
2110// S2_storeri_io %r29, 132, killed %r1; flags: mem:ST4[FixedStack1]
2111// Currently AA considers the addresses in these instructions to be aliasing.
2113 const MachineInstr &MIa, const MachineInstr &MIb) const {
2116 return false;
2117
2118 // Instructions that are pure loads, not loads and stores like memops are not
2119 // dependent.
2120 if (MIa.mayLoad() && !isMemOp(MIa) && MIb.mayLoad() && !isMemOp(MIb))
2121 return true;
2122
2123 // Get the base register in MIa.
2124 unsigned BasePosA, OffsetPosA;
2125 if (!getBaseAndOffsetPosition(MIa, BasePosA, OffsetPosA))
2126 return false;
2127 const MachineOperand &BaseA = MIa.getOperand(BasePosA);
2128 Register BaseRegA = BaseA.getReg();
2129 unsigned BaseSubA = BaseA.getSubReg();
2130
2131 // Get the base register in MIb.
2132 unsigned BasePosB, OffsetPosB;
2133 if (!getBaseAndOffsetPosition(MIb, BasePosB, OffsetPosB))
2134 return false;
2135 const MachineOperand &BaseB = MIb.getOperand(BasePosB);
2136 Register BaseRegB = BaseB.getReg();
2137 unsigned BaseSubB = BaseB.getSubReg();
2138
2139 if (BaseRegA != BaseRegB || BaseSubA != BaseSubB)
2140 return false;
2141
2142 // Get the access sizes.
2143 unsigned SizeA = getMemAccessSize(MIa);
2144 unsigned SizeB = getMemAccessSize(MIb);
2145
2146 // Get the offsets. Handle immediates only for now.
2147 const MachineOperand &OffA = MIa.getOperand(OffsetPosA);
2148 const MachineOperand &OffB = MIb.getOperand(OffsetPosB);
2149 if (!MIa.getOperand(OffsetPosA).isImm() ||
2150 !MIb.getOperand(OffsetPosB).isImm())
2151 return false;
2152 int OffsetA = isPostIncrement(MIa) ? 0 : OffA.getImm();
2153 int OffsetB = isPostIncrement(MIb) ? 0 : OffB.getImm();
2154
2155 // This is a mem access with the same base register and known offsets from it.
2156 // Reason about it.
2157 if (OffsetA > OffsetB) {
2158 uint64_t OffDiff = (uint64_t)((int64_t)OffsetA - (int64_t)OffsetB);
2159 return SizeB <= OffDiff;
2160 }
2161 if (OffsetA < OffsetB) {
2162 uint64_t OffDiff = (uint64_t)((int64_t)OffsetB - (int64_t)OffsetA);
2163 return SizeA <= OffDiff;
2164 }
2165
2166 return false;
2167}
2168
2169/// If the instruction is an increment of a constant value, return the amount.
2171 int &Value) const {
2172 if (isPostIncrement(MI)) {
2173 unsigned BasePos = 0, OffsetPos = 0;
2174 if (!getBaseAndOffsetPosition(MI, BasePos, OffsetPos))
2175 return false;
2176 const MachineOperand &OffsetOp = MI.getOperand(OffsetPos);
2177 if (OffsetOp.isImm()) {
2178 Value = OffsetOp.getImm();
2179 return true;
2180 }
2181 } else if (MI.getOpcode() == Hexagon::A2_addi) {
2182 const MachineOperand &AddOp = MI.getOperand(2);
2183 if (AddOp.isImm()) {
2184 Value = AddOp.getImm();
2185 return true;
2186 }
2187 }
2188
2189 return false;
2190}
2191
2192std::pair<unsigned, unsigned>
2194 return std::make_pair(TF & ~HexagonII::MO_Bitmasks,
2196}
2197
2200 using namespace HexagonII;
2201
2202 static const std::pair<unsigned, const char*> Flags[] = {
2203 {MO_PCREL, "hexagon-pcrel"},
2204 {MO_GOT, "hexagon-got"},
2205 {MO_LO16, "hexagon-lo16"},
2206 {MO_HI16, "hexagon-hi16"},
2207 {MO_GPREL, "hexagon-gprel"},
2208 {MO_GDGOT, "hexagon-gdgot"},
2209 {MO_GDPLT, "hexagon-gdplt"},
2210 {MO_IE, "hexagon-ie"},
2211 {MO_IEGOT, "hexagon-iegot"},
2212 {MO_TPREL, "hexagon-tprel"}
2213 };
2214 return ArrayRef(Flags);
2215}
2216
2219 using namespace HexagonII;
2220
2221 static const std::pair<unsigned, const char*> Flags[] = {
2222 {HMOTF_ConstExtended, "hexagon-ext"}
2223 };
2224 return ArrayRef(Flags);
2225}
2226
2229 const TargetRegisterClass *TRC;
2230 if (VT == MVT::i1) {
2231 TRC = &Hexagon::PredRegsRegClass;
2232 } else if (VT == MVT::i32 || VT == MVT::f32) {
2233 TRC = &Hexagon::IntRegsRegClass;
2234 } else if (VT == MVT::i64 || VT == MVT::f64) {
2235 TRC = &Hexagon::DoubleRegsRegClass;
2236 } else {
2237 llvm_unreachable("Cannot handle this register class");
2238 }
2239
2240 Register NewReg = MRI.createVirtualRegister(TRC);
2241 return NewReg;
2242}
2243
2247
2249 const uint64_t F = MI.getDesc().TSFlags;
2251}
2252
2256
2258 return !isTC1(MI) && !isTC2Early(MI) && !MI.getDesc().mayLoad() &&
2259 !MI.getDesc().mayStore() &&
2260 MI.getDesc().getOpcode() != Hexagon::S2_allocframe &&
2261 MI.getDesc().getOpcode() != Hexagon::L2_deallocframe &&
2262 !isMemOp(MI) && !MI.isBranch() && !MI.isReturn() && !MI.isCall();
2263}
2264
2265// Return true if the instruction is a compound branch instruction.
2267 return getType(MI) == HexagonII::TypeCJ && MI.isBranch();
2268}
2269
2270// TODO: In order to have isExtendable for fpimm/f32Ext, we need to handle
2271// isFPImm and later getFPImm as well.
2273 const uint64_t F = MI.getDesc().TSFlags;
2275 if (isExtended) // Instruction must be extended.
2276 return true;
2277
2278 unsigned isExtendable =
2280 if (!isExtendable)
2281 return false;
2282
2283 if (MI.isCall())
2284 return false;
2285
2286 short ExtOpNum = getCExtOpNum(MI);
2287 const MachineOperand &MO = MI.getOperand(ExtOpNum);
2288 // Use MO operand flags to determine if MO
2289 // has the HMOTF_ConstExtended flag set.
2291 return true;
2292 // If this is a Machine BB address we are talking about, and it is
2293 // not marked as extended, say so.
2294 if (MO.isMBB())
2295 return false;
2296
2297 // We could be using an instruction with an extendable immediate and shoehorn
2298 // a global address into it. If it is a global address it will be constant
2299 // extended. We do this for COMBINE.
2300 if (MO.isGlobal() || MO.isSymbol() || MO.isBlockAddress() ||
2301 MO.isJTI() || MO.isCPI() || MO.isFPImm())
2302 return true;
2303
2304 // If the extendable operand is not 'Immediate' type, the instruction should
2305 // have 'isExtended' flag set.
2306 assert(MO.isImm() && "Extendable operand must be Immediate type");
2307
2308 int64_t Value = MO.getImm();
2310 int32_t SValue = Value;
2311 int32_t MinValue = getMinValue(MI);
2312 int32_t MaxValue = getMaxValue(MI);
2313 return SValue < MinValue || SValue > MaxValue;
2314 }
2315 uint32_t UValue = Value;
2316 uint32_t MinValue = getMinValue(MI);
2317 uint32_t MaxValue = getMaxValue(MI);
2318 return UValue < MinValue || UValue > MaxValue;
2319}
2320
2322 switch (MI.getOpcode()) {
2323 case Hexagon::L4_return:
2324 case Hexagon::L4_return_t:
2325 case Hexagon::L4_return_f:
2326 case Hexagon::L4_return_tnew_pnt:
2327 case Hexagon::L4_return_fnew_pnt:
2328 case Hexagon::L4_return_tnew_pt:
2329 case Hexagon::L4_return_fnew_pt:
2330 return true;
2331 }
2332 return false;
2333}
2334
2335// Return true when ConsMI uses a register defined by ProdMI.
2337 const MachineInstr &ConsMI) const {
2338 if (!ProdMI.getDesc().getNumDefs())
2339 return false;
2340 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
2341
2346
2347 parseOperands(ProdMI, DefsA, UsesA);
2348 parseOperands(ConsMI, DefsB, UsesB);
2349
2350 for (auto &RegA : DefsA)
2351 for (auto &RegB : UsesB) {
2352 // True data dependency.
2353 if (RegA == RegB)
2354 return true;
2355
2356 if (RegA.isPhysical() && llvm::is_contained(HRI.subregs(RegA), RegB))
2357 return true;
2358
2359 if (RegB.isPhysical() && llvm::is_contained(HRI.subregs(RegB), RegA))
2360 return true;
2361 }
2362
2363 return false;
2364}
2365
2366// Returns true if the instruction is already a .cur.
2368 switch (MI.getOpcode()) {
2369 case Hexagon::V6_vL32b_cur_pi:
2370 case Hexagon::V6_vL32b_cur_ai:
2371 return true;
2372 }
2373 return false;
2374}
2375
2376// Returns true, if any one of the operands is a dot new
2377// insn, whether it is predicated dot new or register dot new.
2380 return true;
2381
2382 return false;
2383}
2384
2385/// Symmetrical. See if these two instructions are fit for duplex pair.
2387 const MachineInstr &MIb) const {
2390 return (isDuplexPairMatch(MIaG, MIbG) || isDuplexPairMatch(MIbG, MIaG));
2391}
2392
2396
2400
2402 const MachineInstr &MIb) const {
2403 return (isHMXActivateInstr(MIa) && isHMXWeightInstr(MIb)) ||
2404 (isHMXWeightInstr(MIa) && isHMXActivateInstr(MIb));
2405}
2406
2407bool HexagonInstrInfo::isEndLoopN(unsigned Opcode) const {
2408 return (Opcode == Hexagon::ENDLOOP0 ||
2409 Opcode == Hexagon::ENDLOOP1);
2410}
2411
2412bool HexagonInstrInfo::isExpr(unsigned OpType) const {
2413 switch(OpType) {
2420 return true;
2421 default:
2422 return false;
2423 }
2424}
2425
2427 const MCInstrDesc &MID = MI.getDesc();
2428 const uint64_t F = MID.TSFlags;
2430 return true;
2431
2432 // TODO: This is largely obsolete now. Will need to be removed
2433 // in consecutive patches.
2434 switch (MI.getOpcode()) {
2435 // PS_fi and PS_fia remain special cases.
2436 case Hexagon::PS_fi:
2437 case Hexagon::PS_fia:
2438 return true;
2439 default:
2440 return false;
2441 }
2442 return false;
2443}
2444
2445// This returns true in two cases:
2446// - The OP code itself indicates that this is an extended instruction.
2447// - One of MOs has been marked with HMOTF_ConstExtended flag.
2449 // First check if this is permanently extended op code.
2450 const uint64_t F = MI.getDesc().TSFlags;
2452 return true;
2453 // Use MO operand flags to determine if one of MI's operands
2454 // has HMOTF_ConstExtended flag set.
2455 for (const MachineOperand &MO : MI.operands())
2456 if (MO.getTargetFlags() & HexagonII::HMOTF_ConstExtended)
2457 return true;
2458 return false;
2459}
2460
2462 unsigned Opcode = MI.getOpcode();
2463 const uint64_t F = get(Opcode).TSFlags;
2464 return (F >> HexagonII::FPPos) & HexagonII::FPMask;
2465}
2466
2467// No V60 HVX VMEM with A_INDIRECT.
2469 const MachineInstr &J) const {
2470 if (!isHVXVec(I))
2471 return false;
2472 if (!I.mayLoad() && !I.mayStore())
2473 return false;
2474 return J.isIndirectBranch() || isIndirectCall(J) || isIndirectL4Return(J);
2475}
2476
2478 switch (MI.getOpcode()) {
2479 case Hexagon::J2_callr:
2480 case Hexagon::J2_callrf:
2481 case Hexagon::J2_callrt:
2482 case Hexagon::PS_call_nr:
2483 return true;
2484 }
2485 return false;
2486}
2487
2489 switch (MI.getOpcode()) {
2490 case Hexagon::L4_return:
2491 case Hexagon::L4_return_t:
2492 case Hexagon::L4_return_f:
2493 case Hexagon::L4_return_fnew_pnt:
2494 case Hexagon::L4_return_fnew_pt:
2495 case Hexagon::L4_return_tnew_pnt:
2496 case Hexagon::L4_return_tnew_pt:
2497 return true;
2498 }
2499 return false;
2500}
2501
2503 switch (MI.getOpcode()) {
2504 case Hexagon::J2_jumpr:
2505 case Hexagon::J2_jumprt:
2506 case Hexagon::J2_jumprf:
2507 case Hexagon::J2_jumprtnewpt:
2508 case Hexagon::J2_jumprfnewpt:
2509 case Hexagon::J2_jumprtnew:
2510 case Hexagon::J2_jumprfnew:
2511 return true;
2512 }
2513 return false;
2514}
2515
2516// Return true if a given MI can accommodate given offset.
2517// Use abs estimate as oppose to the exact number.
2518// TODO: This will need to be changed to use MC level
2519// definition of instruction extendable field size.
2521 unsigned offset) const {
2522 // This selection of jump instructions matches to that what
2523 // analyzeBranch can parse, plus NVJ.
2524 if (isNewValueJump(MI)) // r9:2
2525 return isInt<11>(offset);
2526
2527 switch (MI.getOpcode()) {
2528 // Still missing Jump to address condition on register value.
2529 default:
2530 return false;
2531 case Hexagon::J2_jump: // bits<24> dst; // r22:2
2532 case Hexagon::J2_call:
2533 case Hexagon::PS_call_nr:
2534 return isInt<24>(offset);
2535 case Hexagon::J2_jumpt: //bits<17> dst; // r15:2
2536 case Hexagon::J2_jumpf:
2537 case Hexagon::J2_jumptnew:
2538 case Hexagon::J2_jumptnewpt:
2539 case Hexagon::J2_jumpfnew:
2540 case Hexagon::J2_jumpfnewpt:
2541 case Hexagon::J2_callt:
2542 case Hexagon::J2_callf:
2543 return isInt<17>(offset);
2544 case Hexagon::J2_loop0i:
2545 case Hexagon::J2_loop0iext:
2546 case Hexagon::J2_loop0r:
2547 case Hexagon::J2_loop0rext:
2548 case Hexagon::J2_loop1i:
2549 case Hexagon::J2_loop1iext:
2550 case Hexagon::J2_loop1r:
2551 case Hexagon::J2_loop1rext:
2552 return isInt<9>(offset);
2553 // TODO: Add all the compound branches here. Can we do this in Relation model?
2554 case Hexagon::J4_cmpeqi_tp0_jump_nt:
2555 case Hexagon::J4_cmpeqi_tp1_jump_nt:
2556 case Hexagon::J4_cmpeqn1_tp0_jump_nt:
2557 case Hexagon::J4_cmpeqn1_tp1_jump_nt:
2558 return isInt<11>(offset);
2559 }
2560}
2561
2563 // Instructions with iclass A_CVI_VX and attribute A_CVI_LATE uses a multiply
2564 // resource, but all operands can be received late like an ALU instruction.
2566}
2567
2569 unsigned Opcode = MI.getOpcode();
2570 return Opcode == Hexagon::J2_loop0i ||
2571 Opcode == Hexagon::J2_loop0r ||
2572 Opcode == Hexagon::J2_loop0iext ||
2573 Opcode == Hexagon::J2_loop0rext ||
2574 Opcode == Hexagon::J2_loop1i ||
2575 Opcode == Hexagon::J2_loop1r ||
2576 Opcode == Hexagon::J2_loop1iext ||
2577 Opcode == Hexagon::J2_loop1rext;
2578}
2579
2581 switch (MI.getOpcode()) {
2582 default: return false;
2583 case Hexagon::L4_iadd_memopw_io:
2584 case Hexagon::L4_isub_memopw_io:
2585 case Hexagon::L4_add_memopw_io:
2586 case Hexagon::L4_sub_memopw_io:
2587 case Hexagon::L4_and_memopw_io:
2588 case Hexagon::L4_or_memopw_io:
2589 case Hexagon::L4_iadd_memoph_io:
2590 case Hexagon::L4_isub_memoph_io:
2591 case Hexagon::L4_add_memoph_io:
2592 case Hexagon::L4_sub_memoph_io:
2593 case Hexagon::L4_and_memoph_io:
2594 case Hexagon::L4_or_memoph_io:
2595 case Hexagon::L4_iadd_memopb_io:
2596 case Hexagon::L4_isub_memopb_io:
2597 case Hexagon::L4_add_memopb_io:
2598 case Hexagon::L4_sub_memopb_io:
2599 case Hexagon::L4_and_memopb_io:
2600 case Hexagon::L4_or_memopb_io:
2601 case Hexagon::L4_ior_memopb_io:
2602 case Hexagon::L4_ior_memoph_io:
2603 case Hexagon::L4_ior_memopw_io:
2604 case Hexagon::L4_iand_memopb_io:
2605 case Hexagon::L4_iand_memoph_io:
2606 case Hexagon::L4_iand_memopw_io:
2607 return true;
2608 }
2609 return false;
2610}
2611
2613 const uint64_t F = MI.getDesc().TSFlags;
2615}
2616
2617bool HexagonInstrInfo::isNewValue(unsigned Opcode) const {
2618 const uint64_t F = get(Opcode).TSFlags;
2620}
2621
2625
2627 return isNewValue(MI) && MI.isBranch();
2628}
2629
2630bool HexagonInstrInfo::isNewValueJump(unsigned Opcode) const {
2631 return isNewValue(Opcode) && get(Opcode).isBranch() && isPredicated(Opcode);
2632}
2633
2635 const uint64_t F = MI.getDesc().TSFlags;
2637}
2638
2639bool HexagonInstrInfo::isNewValueStore(unsigned Opcode) const {
2640 const uint64_t F = get(Opcode).TSFlags;
2642}
2643
2644// Returns true if a particular operand is extendable for an instruction.
2646 unsigned OperandNum) const {
2647 const uint64_t F = MI.getDesc().TSFlags;
2649 == OperandNum;
2650}
2651
2653 const uint64_t F = MI.getDesc().TSFlags;
2656}
2657
2658bool HexagonInstrInfo::isPredicatedNew(unsigned Opcode) const {
2659 const uint64_t F = get(Opcode).TSFlags;
2660 assert(isPredicated(Opcode));
2662}
2663
2665 const uint64_t F = MI.getDesc().TSFlags;
2666 return !((F >> HexagonII::PredicatedFalsePos) &
2668}
2669
2670bool HexagonInstrInfo::isPredicatedTrue(unsigned Opcode) const {
2671 const uint64_t F = get(Opcode).TSFlags;
2672 // Make sure that the instruction is predicated.
2674 return !((F >> HexagonII::PredicatedFalsePos) &
2676}
2677
2678bool HexagonInstrInfo::isPredicated(unsigned Opcode) const {
2679 const uint64_t F = get(Opcode).TSFlags;
2681}
2682
2683bool HexagonInstrInfo::isPredicateLate(unsigned Opcode) const {
2684 const uint64_t F = get(Opcode).TSFlags;
2686}
2687
2688bool HexagonInstrInfo::isPredictedTaken(unsigned Opcode) const {
2689 const uint64_t F = get(Opcode).TSFlags;
2690 assert(get(Opcode).isBranch() &&
2691 (isPredicatedNew(Opcode) || isNewValue(Opcode)));
2693}
2694
2696 return MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4 ||
2697 MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4_EXT ||
2698 MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4_PIC ||
2699 MI.getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4_EXT_PIC;
2700}
2701
2703 switch (MI.getOpcode()) {
2704 // Byte
2705 case Hexagon::L2_loadrb_io:
2706 case Hexagon::L4_loadrb_ur:
2707 case Hexagon::L4_loadrb_ap:
2708 case Hexagon::L2_loadrb_pr:
2709 case Hexagon::L2_loadrb_pbr:
2710 case Hexagon::L2_loadrb_pi:
2711 case Hexagon::L2_loadrb_pci:
2712 case Hexagon::L2_loadrb_pcr:
2713 case Hexagon::L2_loadbsw2_io:
2714 case Hexagon::L4_loadbsw2_ur:
2715 case Hexagon::L4_loadbsw2_ap:
2716 case Hexagon::L2_loadbsw2_pr:
2717 case Hexagon::L2_loadbsw2_pbr:
2718 case Hexagon::L2_loadbsw2_pi:
2719 case Hexagon::L2_loadbsw2_pci:
2720 case Hexagon::L2_loadbsw2_pcr:
2721 case Hexagon::L2_loadbsw4_io:
2722 case Hexagon::L4_loadbsw4_ur:
2723 case Hexagon::L4_loadbsw4_ap:
2724 case Hexagon::L2_loadbsw4_pr:
2725 case Hexagon::L2_loadbsw4_pbr:
2726 case Hexagon::L2_loadbsw4_pi:
2727 case Hexagon::L2_loadbsw4_pci:
2728 case Hexagon::L2_loadbsw4_pcr:
2729 case Hexagon::L4_loadrb_rr:
2730 case Hexagon::L2_ploadrbt_io:
2731 case Hexagon::L2_ploadrbt_pi:
2732 case Hexagon::L2_ploadrbf_io:
2733 case Hexagon::L2_ploadrbf_pi:
2734 case Hexagon::L2_ploadrbtnew_io:
2735 case Hexagon::L2_ploadrbfnew_io:
2736 case Hexagon::L4_ploadrbt_rr:
2737 case Hexagon::L4_ploadrbf_rr:
2738 case Hexagon::L4_ploadrbtnew_rr:
2739 case Hexagon::L4_ploadrbfnew_rr:
2740 case Hexagon::L2_ploadrbtnew_pi:
2741 case Hexagon::L2_ploadrbfnew_pi:
2742 case Hexagon::L4_ploadrbt_abs:
2743 case Hexagon::L4_ploadrbf_abs:
2744 case Hexagon::L4_ploadrbtnew_abs:
2745 case Hexagon::L4_ploadrbfnew_abs:
2746 case Hexagon::L2_loadrbgp:
2747 // Half
2748 case Hexagon::L2_loadrh_io:
2749 case Hexagon::L4_loadrh_ur:
2750 case Hexagon::L4_loadrh_ap:
2751 case Hexagon::L2_loadrh_pr:
2752 case Hexagon::L2_loadrh_pbr:
2753 case Hexagon::L2_loadrh_pi:
2754 case Hexagon::L2_loadrh_pci:
2755 case Hexagon::L2_loadrh_pcr:
2756 case Hexagon::L4_loadrh_rr:
2757 case Hexagon::L2_ploadrht_io:
2758 case Hexagon::L2_ploadrht_pi:
2759 case Hexagon::L2_ploadrhf_io:
2760 case Hexagon::L2_ploadrhf_pi:
2761 case Hexagon::L2_ploadrhtnew_io:
2762 case Hexagon::L2_ploadrhfnew_io:
2763 case Hexagon::L4_ploadrht_rr:
2764 case Hexagon::L4_ploadrhf_rr:
2765 case Hexagon::L4_ploadrhtnew_rr:
2766 case Hexagon::L4_ploadrhfnew_rr:
2767 case Hexagon::L2_ploadrhtnew_pi:
2768 case Hexagon::L2_ploadrhfnew_pi:
2769 case Hexagon::L4_ploadrht_abs:
2770 case Hexagon::L4_ploadrhf_abs:
2771 case Hexagon::L4_ploadrhtnew_abs:
2772 case Hexagon::L4_ploadrhfnew_abs:
2773 case Hexagon::L2_loadrhgp:
2774 return true;
2775 default:
2776 return false;
2777 }
2778}
2779
2781 const uint64_t F = MI.getDesc().TSFlags;
2783}
2784
2786 switch (MI.getOpcode()) {
2787 case Hexagon::STriw_pred:
2788 case Hexagon::LDriw_pred:
2789 return true;
2790 default:
2791 return false;
2792 }
2793}
2794
2796 if (!MI.isBranch())
2797 return false;
2798
2799 for (auto &Op : MI.operands())
2800 if (Op.isGlobal() || Op.isSymbol())
2801 return true;
2802 return false;
2803}
2804
2805// Returns true when SU has a timing class TC1.
2807 unsigned SchedClass = MI.getDesc().getSchedClass();
2808 return is_TC1(SchedClass);
2809}
2810
2812 unsigned SchedClass = MI.getDesc().getSchedClass();
2813 return is_TC2(SchedClass);
2814}
2815
2817 unsigned SchedClass = MI.getDesc().getSchedClass();
2818 return is_TC2early(SchedClass);
2819}
2820
2822 unsigned SchedClass = MI.getDesc().getSchedClass();
2823 return is_TC4x(SchedClass);
2824}
2825
2826// Schedule this ASAP.
2828 const MachineInstr &MI2) const {
2829 if (mayBeCurLoad(MI1)) {
2830 // if (result of SU is used in Next) return true;
2831 Register DstReg = MI1.getOperand(0).getReg();
2832 int N = MI2.getNumOperands();
2833 for (int I = 0; I < N; I++)
2834 if (MI2.getOperand(I).isReg() && DstReg == MI2.getOperand(I).getReg())
2835 return true;
2836 }
2837 if (mayBeNewStore(MI2))
2838 if (MI2.getOpcode() == Hexagon::V6_vS32b_pi)
2839 if (MI1.getOperand(0).isReg() && MI2.getOperand(3).isReg() &&
2840 MI1.getOperand(0).getReg() == MI2.getOperand(3).getReg())
2841 return true;
2842 return false;
2843}
2844
2846 const uint64_t V = getType(MI);
2848}
2849
2851 return (MI.getDesc().TSFlags >> HexagonII::isHLXPos) & HexagonII::isHLXMask;
2852}
2853
2854// Check if the Offset is a valid auto-inc imm by Load/Store Type.
2856 int Size = VT.getSizeInBits() / 8;
2857 if (Offset % Size != 0)
2858 return false;
2859 int Count = Offset / Size;
2860
2861 switch (VT.getSimpleVT().SimpleTy) {
2862 // For scalars the auto-inc is s4
2863 case MVT::i8:
2864 case MVT::i16:
2865 case MVT::i32:
2866 case MVT::i64:
2867 case MVT::f32:
2868 case MVT::f64:
2869 case MVT::v2i16:
2870 case MVT::v2i32:
2871 case MVT::v4i8:
2872 case MVT::v4i16:
2873 case MVT::v8i8:
2874 return isInt<4>(Count);
2875 // For HVX vectors the auto-inc is s3
2876 case MVT::v64i8:
2877 case MVT::v32i16:
2878 case MVT::v16i32:
2879 case MVT::v8i64:
2880 case MVT::v128i8:
2881 case MVT::v64i16:
2882 case MVT::v32i32:
2883 case MVT::v16i64:
2884 return isInt<3>(Count);
2885 default:
2886 break;
2887 }
2888
2889 llvm_unreachable("Not an valid type!");
2890}
2891
2892bool HexagonInstrInfo::isValidOffset(unsigned Opcode, int Offset,
2893 bool Extend) const {
2894 // This function is to check whether the "Offset" is in the correct range of
2895 // the given "Opcode". If "Offset" is not in the correct range, "A2_addi" is
2896 // inserted to calculate the final address. Due to this reason, the function
2897 // assumes that the "Offset" has correct alignment.
2898 // We used to assert if the offset was not properly aligned, however,
2899 // there are cases where a misaligned pointer recast can cause this
2900 // problem, and we need to allow for it. The front end warns of such
2901 // misaligns with respect to load size.
2902 switch (Opcode) {
2903 case Hexagon::PS_vstorerq_ai:
2904 case Hexagon::PS_vstorerv_ai:
2905 case Hexagon::PS_vstorerw_ai:
2906 case Hexagon::PS_vstorerw_nt_ai:
2907 case Hexagon::PS_vloadrq_ai:
2908 case Hexagon::PS_vloadrv_ai:
2909 case Hexagon::PS_vloadrw_ai:
2910 case Hexagon::PS_vloadrw_nt_ai:
2911 case Hexagon::V6_vL32b_ai:
2912 case Hexagon::V6_vS32b_ai:
2913 case Hexagon::V6_vS32b_pred_ai:
2914 case Hexagon::V6_vS32b_npred_ai:
2915 case Hexagon::V6_vS32b_qpred_ai:
2916 case Hexagon::V6_vS32b_nqpred_ai:
2917 case Hexagon::V6_vS32b_new_ai:
2918 case Hexagon::V6_vS32b_new_pred_ai:
2919 case Hexagon::V6_vS32b_new_npred_ai:
2920 case Hexagon::V6_vS32b_nt_pred_ai:
2921 case Hexagon::V6_vS32b_nt_npred_ai:
2922 case Hexagon::V6_vS32b_nt_new_ai:
2923 case Hexagon::V6_vS32b_nt_new_pred_ai:
2924 case Hexagon::V6_vS32b_nt_new_npred_ai:
2925 case Hexagon::V6_vS32b_nt_qpred_ai:
2926 case Hexagon::V6_vS32b_nt_nqpred_ai:
2927 case Hexagon::V6_vL32b_nt_ai:
2928 case Hexagon::V6_vS32b_nt_ai:
2929 case Hexagon::V6_vL32Ub_ai:
2930 case Hexagon::V6_vS32Ub_ai:
2931 case Hexagon::V6_vL32b_cur_ai:
2932 case Hexagon::V6_vL32b_tmp_ai:
2933 case Hexagon::V6_vL32b_pred_ai:
2934 case Hexagon::V6_vL32b_npred_ai:
2935 case Hexagon::V6_vL32b_cur_pred_ai:
2936 case Hexagon::V6_vL32b_cur_npred_ai:
2937 case Hexagon::V6_vL32b_tmp_pred_ai:
2938 case Hexagon::V6_vL32b_tmp_npred_ai:
2939 case Hexagon::V6_vL32b_nt_cur_ai:
2940 case Hexagon::V6_vL32b_nt_tmp_ai:
2941 case Hexagon::V6_vL32b_nt_pred_ai:
2942 case Hexagon::V6_vL32b_nt_npred_ai:
2943 case Hexagon::V6_vL32b_nt_cur_pred_ai:
2944 case Hexagon::V6_vL32b_nt_cur_npred_ai:
2945 case Hexagon::V6_vL32b_nt_tmp_pred_ai:
2946 case Hexagon::V6_vL32b_nt_tmp_npred_ai:
2947 case Hexagon::V6_vS32Ub_pred_ai:
2948 case Hexagon::V6_vS32Ub_npred_ai:
2949 case Hexagon::V6_vgathermh_pseudo:
2950 case Hexagon::V6_vgather_vscatter_mh_pseudo:
2951 case Hexagon::V6_vgathermw_pseudo:
2952 case Hexagon::V6_vgathermhw_pseudo:
2953 case Hexagon::V6_vgathermhq_pseudo:
2954 case Hexagon::V6_vgathermwq_pseudo:
2955 case Hexagon::V6_vgathermhwq_pseudo: {
2956 unsigned VectorSize = RegInfo.getSpillSize(Hexagon::HvxVRRegClass);
2957 assert(isPowerOf2_32(VectorSize));
2958 if (Offset & (VectorSize-1))
2959 return false;
2960 return isInt<4>(Offset >> Log2_32(VectorSize));
2961 }
2962
2963 case Hexagon::J2_loop0i:
2964 case Hexagon::J2_loop1i:
2965 return isUInt<10>(Offset);
2966
2967 case Hexagon::S4_storeirb_io:
2968 case Hexagon::S4_storeirbt_io:
2969 case Hexagon::S4_storeirbf_io:
2970 return isUInt<6>(Offset);
2971
2972 case Hexagon::S4_storeirh_io:
2973 case Hexagon::S4_storeirht_io:
2974 case Hexagon::S4_storeirhf_io:
2975 return isShiftedUInt<6,1>(Offset);
2976
2977 case Hexagon::S4_storeiri_io:
2978 case Hexagon::S4_storeirit_io:
2979 case Hexagon::S4_storeirif_io:
2980 return isShiftedUInt<6,2>(Offset);
2981 // Handle these two compare instructions that are not extendable.
2982 case Hexagon::A4_cmpbeqi:
2983 return isUInt<8>(Offset);
2984 case Hexagon::A4_cmpbgti:
2985 return isInt<8>(Offset);
2986 }
2987
2988 if (Extend)
2989 return true;
2990
2991 switch (Opcode) {
2992 case Hexagon::L2_loadri_io:
2993 case Hexagon::S2_storeri_io:
2994 return (Offset >= Hexagon_MEMW_OFFSET_MIN) &&
2996
2997 case Hexagon::L2_loadrd_io:
2998 case Hexagon::S2_storerd_io:
2999 return (Offset >= Hexagon_MEMD_OFFSET_MIN) &&
3001
3002 case Hexagon::L2_loadrh_io:
3003 case Hexagon::L2_loadruh_io:
3004 case Hexagon::S2_storerh_io:
3005 case Hexagon::S2_storerf_io:
3006 return (Offset >= Hexagon_MEMH_OFFSET_MIN) &&
3008
3009 case Hexagon::L2_loadrb_io:
3010 case Hexagon::L2_loadrub_io:
3011 case Hexagon::S2_storerb_io:
3012 return (Offset >= Hexagon_MEMB_OFFSET_MIN) &&
3014
3015 case Hexagon::A2_addi:
3016 return (Offset >= Hexagon_ADDI_OFFSET_MIN) &&
3018
3019 case Hexagon::L4_iadd_memopw_io:
3020 case Hexagon::L4_isub_memopw_io:
3021 case Hexagon::L4_add_memopw_io:
3022 case Hexagon::L4_sub_memopw_io:
3023 case Hexagon::L4_iand_memopw_io:
3024 case Hexagon::L4_ior_memopw_io:
3025 case Hexagon::L4_and_memopw_io:
3026 case Hexagon::L4_or_memopw_io:
3027 return (0 <= Offset && Offset <= 255);
3028
3029 case Hexagon::L4_iadd_memoph_io:
3030 case Hexagon::L4_isub_memoph_io:
3031 case Hexagon::L4_add_memoph_io:
3032 case Hexagon::L4_sub_memoph_io:
3033 case Hexagon::L4_iand_memoph_io:
3034 case Hexagon::L4_ior_memoph_io:
3035 case Hexagon::L4_and_memoph_io:
3036 case Hexagon::L4_or_memoph_io:
3037 return (0 <= Offset && Offset <= 127);
3038
3039 case Hexagon::L4_iadd_memopb_io:
3040 case Hexagon::L4_isub_memopb_io:
3041 case Hexagon::L4_add_memopb_io:
3042 case Hexagon::L4_sub_memopb_io:
3043 case Hexagon::L4_iand_memopb_io:
3044 case Hexagon::L4_ior_memopb_io:
3045 case Hexagon::L4_and_memopb_io:
3046 case Hexagon::L4_or_memopb_io:
3047 return (0 <= Offset && Offset <= 63);
3048
3049 // LDriw_xxx and STriw_xxx are pseudo operations, so it has to take offset of
3050 // any size. Later pass knows how to handle it.
3051 case Hexagon::STriw_pred:
3052 case Hexagon::LDriw_pred:
3053 case Hexagon::STriw_ctr:
3054 case Hexagon::LDriw_ctr:
3055 return true;
3056
3057 case Hexagon::PS_fi:
3058 case Hexagon::PS_fia:
3059 case Hexagon::INLINEASM:
3060 return true;
3061
3062 case Hexagon::L2_ploadrbt_io:
3063 case Hexagon::L2_ploadrbf_io:
3064 case Hexagon::L2_ploadrubt_io:
3065 case Hexagon::L2_ploadrubf_io:
3066 case Hexagon::S2_pstorerbt_io:
3067 case Hexagon::S2_pstorerbf_io:
3068 return isUInt<6>(Offset);
3069
3070 case Hexagon::L2_ploadrht_io:
3071 case Hexagon::L2_ploadrhf_io:
3072 case Hexagon::L2_ploadruht_io:
3073 case Hexagon::L2_ploadruhf_io:
3074 case Hexagon::S2_pstorerht_io:
3075 case Hexagon::S2_pstorerhf_io:
3076 case Hexagon::S2_pstorerft_io:
3077 case Hexagon::S2_pstorerff_io:
3078 return isShiftedUInt<6,1>(Offset);
3079
3080 case Hexagon::L2_ploadrit_io:
3081 case Hexagon::L2_ploadrif_io:
3082 case Hexagon::S2_pstorerit_io:
3083 case Hexagon::S2_pstorerif_io:
3084 return isShiftedUInt<6,2>(Offset);
3085
3086 case Hexagon::L2_ploadrdt_io:
3087 case Hexagon::L2_ploadrdf_io:
3088 case Hexagon::S2_pstorerdt_io:
3089 case Hexagon::S2_pstorerdf_io:
3090 return isShiftedUInt<6,3>(Offset);
3091
3092 case Hexagon::L2_loadbsw2_io:
3093 case Hexagon::L2_loadbzw2_io:
3094 return isShiftedInt<11,1>(Offset);
3095
3096 case Hexagon::L2_loadbsw4_io:
3097 case Hexagon::L2_loadbzw4_io:
3098 return isShiftedInt<11,2>(Offset);
3099 } // switch
3100
3101 dbgs() << "Failed Opcode is : " << Opcode << " (" << getName(Opcode)
3102 << ")\n";
3103 llvm_unreachable("No offset range is defined for this opcode. "
3104 "Please define it in the above switch statement!");
3105}
3106
3108 return isHVXVec(MI) && isAccumulator(MI);
3109}
3110
3112 const uint64_t F = get(MI.getOpcode()).TSFlags;
3113 const uint64_t V = ((F >> HexagonII::TypePos) & HexagonII::TypeMask);
3114 return
3115 V == HexagonII::TypeCVI_VA ||
3117}
3118
3120 const MachineInstr &ConsMI) const {
3121 if (EnableACCForwarding && isVecAcc(ProdMI) && isVecAcc(ConsMI))
3122 return true;
3123
3124 if (EnableALUForwarding && (isVecALU(ConsMI) || isLateSourceInstr(ConsMI)))
3125 return true;
3126
3127 if (mayBeNewStore(ConsMI))
3128 return true;
3129
3130 return false;
3131}
3132
3134 switch (MI.getOpcode()) {
3135 // Byte
3136 case Hexagon::L2_loadrub_io:
3137 case Hexagon::L4_loadrub_ur:
3138 case Hexagon::L4_loadrub_ap:
3139 case Hexagon::L2_loadrub_pr:
3140 case Hexagon::L2_loadrub_pbr:
3141 case Hexagon::L2_loadrub_pi:
3142 case Hexagon::L2_loadrub_pci:
3143 case Hexagon::L2_loadrub_pcr:
3144 case Hexagon::L2_loadbzw2_io:
3145 case Hexagon::L4_loadbzw2_ur:
3146 case Hexagon::L4_loadbzw2_ap:
3147 case Hexagon::L2_loadbzw2_pr:
3148 case Hexagon::L2_loadbzw2_pbr:
3149 case Hexagon::L2_loadbzw2_pi:
3150 case Hexagon::L2_loadbzw2_pci:
3151 case Hexagon::L2_loadbzw2_pcr:
3152 case Hexagon::L2_loadbzw4_io:
3153 case Hexagon::L4_loadbzw4_ur:
3154 case Hexagon::L4_loadbzw4_ap:
3155 case Hexagon::L2_loadbzw4_pr:
3156 case Hexagon::L2_loadbzw4_pbr:
3157 case Hexagon::L2_loadbzw4_pi:
3158 case Hexagon::L2_loadbzw4_pci:
3159 case Hexagon::L2_loadbzw4_pcr:
3160 case Hexagon::L4_loadrub_rr:
3161 case Hexagon::L2_ploadrubt_io:
3162 case Hexagon::L2_ploadrubt_pi:
3163 case Hexagon::L2_ploadrubf_io:
3164 case Hexagon::L2_ploadrubf_pi:
3165 case Hexagon::L2_ploadrubtnew_io:
3166 case Hexagon::L2_ploadrubfnew_io:
3167 case Hexagon::L4_ploadrubt_rr:
3168 case Hexagon::L4_ploadrubf_rr:
3169 case Hexagon::L4_ploadrubtnew_rr:
3170 case Hexagon::L4_ploadrubfnew_rr:
3171 case Hexagon::L2_ploadrubtnew_pi:
3172 case Hexagon::L2_ploadrubfnew_pi:
3173 case Hexagon::L4_ploadrubt_abs:
3174 case Hexagon::L4_ploadrubf_abs:
3175 case Hexagon::L4_ploadrubtnew_abs:
3176 case Hexagon::L4_ploadrubfnew_abs:
3177 case Hexagon::L2_loadrubgp:
3178 // Half
3179 case Hexagon::L2_loadruh_io:
3180 case Hexagon::L4_loadruh_ur:
3181 case Hexagon::L4_loadruh_ap:
3182 case Hexagon::L2_loadruh_pr:
3183 case Hexagon::L2_loadruh_pbr:
3184 case Hexagon::L2_loadruh_pi:
3185 case Hexagon::L2_loadruh_pci:
3186 case Hexagon::L2_loadruh_pcr:
3187 case Hexagon::L4_loadruh_rr:
3188 case Hexagon::L2_ploadruht_io:
3189 case Hexagon::L2_ploadruht_pi:
3190 case Hexagon::L2_ploadruhf_io:
3191 case Hexagon::L2_ploadruhf_pi:
3192 case Hexagon::L2_ploadruhtnew_io:
3193 case Hexagon::L2_ploadruhfnew_io:
3194 case Hexagon::L4_ploadruht_rr:
3195 case Hexagon::L4_ploadruhf_rr:
3196 case Hexagon::L4_ploadruhtnew_rr:
3197 case Hexagon::L4_ploadruhfnew_rr:
3198 case Hexagon::L2_ploadruhtnew_pi:
3199 case Hexagon::L2_ploadruhfnew_pi:
3200 case Hexagon::L4_ploadruht_abs:
3201 case Hexagon::L4_ploadruhf_abs:
3202 case Hexagon::L4_ploadruhtnew_abs:
3203 case Hexagon::L4_ploadruhfnew_abs:
3204 case Hexagon::L2_loadruhgp:
3205 return true;
3206 default:
3207 return false;
3208 }
3209}
3210
3211// Add latency to instruction.
3213 const MachineInstr &MI2) const {
3214 if (isHVXVec(MI1) && isHVXVec(MI2))
3215 if (!isVecUsableNextPacket(MI1, MI2))
3216 return true;
3217 return false;
3218}
3219
3220/// Get the base register and byte offset of a load/store instr.
3223 int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width) const {
3224 OffsetIsScalable = false;
3225 const MachineOperand *BaseOp = getBaseAndOffset(LdSt, Offset, Width);
3226 if (!BaseOp || !BaseOp->isReg())
3227 return false;
3228 BaseOps.push_back(BaseOp);
3229 return true;
3230}
3231
3232/// Can these instructions execute at the same time in a bundle.
3234 const MachineInstr &Second) const {
3235 if (Second.mayStore() && First.getOpcode() == Hexagon::S2_allocframe) {
3236 const MachineOperand &Op = Second.getOperand(0);
3237 if (Op.isReg() && Op.isUse() && Op.getReg() == Hexagon::R29)
3238 return true;
3239 }
3241 return false;
3242 if (mayBeNewStore(Second)) {
3243 // Make sure the definition of the first instruction is the value being
3244 // stored.
3245 const MachineOperand &Stored =
3246 Second.getOperand(Second.getNumOperands() - 1);
3247 if (!Stored.isReg())
3248 return false;
3249 for (unsigned i = 0, e = First.getNumOperands(); i < e; ++i) {
3250 const MachineOperand &Op = First.getOperand(i);
3251 if (Op.isReg() && Op.isDef() && Op.getReg() == Stored.getReg())
3252 return true;
3253 }
3254 }
3255 return false;
3256}
3257
3259 unsigned Opc = CallMI.getOpcode();
3260 return Opc == Hexagon::PS_call_nr || Opc == Hexagon::PS_callr_nr;
3261}
3262
3264 for (auto &I : *B)
3265 if (I.isEHLabel())
3266 return true;
3267 return false;
3268}
3269
3270// Returns true if an instruction can be converted into a non-extended
3271// equivalent instruction.
3273 short NonExtOpcode;
3274 // Check if the instruction has a register form that uses register in place
3275 // of the extended operand, if so return that as the non-extended form.
3276 if (Hexagon::getRegForm(MI.getOpcode()) >= 0)
3277 return true;
3278
3279 if (MI.getDesc().mayLoad() || MI.getDesc().mayStore()) {
3280 // Check addressing mode and retrieve non-ext equivalent instruction.
3281
3282 switch (getAddrMode(MI)) {
3284 // Load/store with absolute addressing mode can be converted into
3285 // base+offset mode.
3286 NonExtOpcode = Hexagon::changeAddrMode_abs_io(MI.getOpcode());
3287 break;
3289 // Load/store with base+offset addressing mode can be converted into
3290 // base+register offset addressing mode. However left shift operand should
3291 // be set to 0.
3292 NonExtOpcode = Hexagon::changeAddrMode_io_rr(MI.getOpcode());
3293 break;
3295 NonExtOpcode = Hexagon::changeAddrMode_ur_rr(MI.getOpcode());
3296 break;
3297 default:
3298 return false;
3299 }
3300 if (NonExtOpcode < 0)
3301 return false;
3302 return true;
3303 }
3304 return false;
3305}
3306
3308 const {
3309 MachineBasicBlock::const_iterator I = B->getFirstTerminator(), E = B->end();
3310 while (I != E) {
3311 if (I->isBarrier())
3312 return true;
3313 ++I;
3314 }
3315 return false;
3316}
3317
3318// Returns true, if a LD insn can be promoted to a cur load.
3320 const uint64_t F = MI.getDesc().TSFlags;
3322 Subtarget.hasV60Ops();
3323}
3324
3325// Returns true, if a ST insn can be promoted to a new-value store.
3327 if (MI.mayStore() && !Subtarget.useNewValueStores())
3328 return false;
3329
3330 const uint64_t F = MI.getDesc().TSFlags;
3332}
3333
3335 return MI.getOpcode() == Hexagon::LX_L16b_pseudo;
3336}
3337
3339 return MI.getOpcode() == Hexagon::LX_S16b_pseudo;
3340}
3341
3343 const MachineInstr &ConsMI) const {
3344 // There is no stall when ProdMI is not a V60 vector.
3345 if (!isHVXVec(ProdMI))
3346 return false;
3347
3348 // There is no stall when ProdMI and ConsMI are not dependent.
3349 if (!isDependent(ProdMI, ConsMI))
3350 return false;
3351
3352 // When Forward Scheduling is enabled, there is no stall if ProdMI and ConsMI
3353 // are scheduled in consecutive packets.
3354 if (isVecUsableNextPacket(ProdMI, ConsMI))
3355 return false;
3356
3357 return true;
3358}
3359
3362 // There is no stall when I is not a V60 vector.
3363 if (!isHVXVec(MI))
3364 return false;
3365
3367 MachineBasicBlock::const_instr_iterator MIE = MII->getParent()->instr_end();
3368
3369 if (!MII->isBundle())
3370 return producesStall(*MII, MI);
3371
3372 for (++MII; MII != MIE && MII->isInsideBundle(); ++MII) {
3373 const MachineInstr &J = *MII;
3374 if (producesStall(J, MI))
3375 return true;
3376 }
3377 return false;
3378}
3379
3381 Register PredReg) const {
3382 for (const MachineOperand &MO : MI.operands()) {
3383 // Predicate register must be explicitly defined.
3384 if (MO.isRegMask() && MO.clobbersPhysReg(PredReg))
3385 return false;
3386 if (MO.isReg() && MO.isDef() && MO.isImplicit() && (MO.getReg() == PredReg))
3387 return false;
3388 }
3389
3390 // Instruction that produce late predicate cannot be used as sources of
3391 // dot-new.
3392 switch (MI.getOpcode()) {
3393 case Hexagon::A4_addp_c:
3394 case Hexagon::A4_subp_c:
3395 case Hexagon::A4_tlbmatch:
3396 case Hexagon::A5_ACS:
3397 case Hexagon::F2_sfinvsqrta:
3398 case Hexagon::F2_sfrecipa:
3399 case Hexagon::J2_endloop0:
3400 case Hexagon::J2_endloop01:
3401 case Hexagon::J2_ploop1si:
3402 case Hexagon::J2_ploop1sr:
3403 case Hexagon::J2_ploop2si:
3404 case Hexagon::J2_ploop2sr:
3405 case Hexagon::J2_ploop3si:
3406 case Hexagon::J2_ploop3sr:
3407 case Hexagon::S2_cabacdecbin:
3408 case Hexagon::S2_storew_locked:
3409 case Hexagon::S4_stored_locked:
3410 return false;
3411 }
3412 return true;
3413}
3414
3415bool HexagonInstrInfo::PredOpcodeHasJMP_c(unsigned Opcode) const {
3416 return Opcode == Hexagon::J2_jumpt ||
3417 Opcode == Hexagon::J2_jumptpt ||
3418 Opcode == Hexagon::J2_jumpf ||
3419 Opcode == Hexagon::J2_jumpfpt ||
3420 Opcode == Hexagon::J2_jumptnew ||
3421 Opcode == Hexagon::J2_jumpfnew ||
3422 Opcode == Hexagon::J2_jumptnewpt ||
3423 Opcode == Hexagon::J2_jumpfnewpt;
3424}
3425
3427 if (Cond.empty() || !isPredicated(Cond[0].getImm()))
3428 return false;
3429 return !isPredicatedTrue(Cond[0].getImm());
3430}
3431
3433 const uint64_t F = MI.getDesc().TSFlags;
3435}
3436
3437// Returns the base register in a memory access (load/store). The offset is
3438// returned in Offset and the access size is returned in AccessSize.
3439// If the base operand has a subregister or the offset field does not contain
3440// an immediate value, return nullptr.
3443 LocationSize &AccessSize) const {
3444 // Return if it is not a base+offset type instruction or a MemOp.
3448 return nullptr;
3449
3451
3452 unsigned BasePos = 0, OffsetPos = 0;
3453 if (!getBaseAndOffsetPosition(MI, BasePos, OffsetPos))
3454 return nullptr;
3455
3456 // Post increment updates its EA after the mem access,
3457 // so we need to treat its offset as zero.
3458 if (isPostIncrement(MI)) {
3459 Offset = 0;
3460 } else {
3461 const MachineOperand &OffsetOp = MI.getOperand(OffsetPos);
3462 if (!OffsetOp.isImm())
3463 return nullptr;
3464 Offset = OffsetOp.getImm();
3465 }
3466
3467 const MachineOperand &BaseOp = MI.getOperand(BasePos);
3468 if (BaseOp.getSubReg() != 0)
3469 return nullptr;
3470 return &const_cast<MachineOperand&>(BaseOp);
3471}
3472
3473/// Return the position of the base and offset operands for this instruction.
3475 unsigned &BasePos, unsigned &OffsetPos) const {
3477 return false;
3478
3479 // Deal with memops first.
3480 if (isMemOp(MI)) {
3481 BasePos = 0;
3482 OffsetPos = 1;
3483 } else if (MI.mayStore()) {
3484 BasePos = 0;
3485 OffsetPos = 1;
3486 } else if (MI.mayLoad()) {
3487 BasePos = 1;
3488 OffsetPos = 2;
3489 } else
3490 return false;
3491
3492 if (isPredicated(MI)) {
3493 BasePos++;
3494 OffsetPos++;
3495 }
3496 if (isPostIncrement(MI)) {
3497 BasePos++;
3498 OffsetPos++;
3499 }
3500
3501 if (!MI.getOperand(BasePos).isReg() || !MI.getOperand(OffsetPos).isImm())
3502 return false;
3503
3504 return true;
3505}
3506
3507// Inserts branching instructions in reverse order of their occurrence.
3508// e.g. jump_t t1 (i1)
3509// jump t2 (i2)
3510// Jumpers = {i2, i1}
3512 MachineBasicBlock& MBB) const {
3514 // If the block has no terminators, it just falls into the block after it.
3516 if (I == MBB.instr_begin())
3517 return Jumpers;
3518
3519 // A basic block may looks like this:
3520 //
3521 // [ insn
3522 // EH_LABEL
3523 // insn
3524 // insn
3525 // insn
3526 // EH_LABEL
3527 // insn ]
3528 //
3529 // It has two succs but does not have a terminator
3530 // Don't know how to handle it.
3531 do {
3532 --I;
3533 if (I->isEHLabel())
3534 return Jumpers;
3535 } while (I != MBB.instr_begin());
3536
3537 I = MBB.instr_end();
3538 --I;
3539
3540 while (I->isDebugInstr()) {
3541 if (I == MBB.instr_begin())
3542 return Jumpers;
3543 --I;
3544 }
3545 if (!isUnpredicatedTerminator(*I))
3546 return Jumpers;
3547
3548 // Get the last instruction in the block.
3549 MachineInstr *LastInst = &*I;
3550 Jumpers.push_back(LastInst);
3551 MachineInstr *SecondLastInst = nullptr;
3552 // Find one more terminator if present.
3553 do {
3554 if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(*I)) {
3555 if (!SecondLastInst) {
3556 SecondLastInst = &*I;
3557 Jumpers.push_back(SecondLastInst);
3558 } else // This is a third branch.
3559 return Jumpers;
3560 }
3561 if (I == MBB.instr_begin())
3562 break;
3563 --I;
3564 } while (true);
3565 return Jumpers;
3566}
3567
3568// Returns Operand Index for the constant extended instruction.
3570 const uint64_t F = MI.getDesc().TSFlags;
3572}
3573
3574// See if instruction could potentially be a duplex candidate.
3575// If so, return its group. Zero otherwise.
3577 const MachineInstr &MI) const {
3578 Register DstReg, SrcReg, Src1Reg, Src2Reg;
3579
3580 switch (MI.getOpcode()) {
3581 default:
3582 return HexagonII::HCG_None;
3583 //
3584 // Compound pairs.
3585 // "p0=cmp.eq(Rs16,Rt16); if (p0.new) jump:nt #r9:2"
3586 // "Rd16=#U6 ; jump #r9:2"
3587 // "Rd16=Rs16 ; jump #r9:2"
3588 //
3589 case Hexagon::C2_cmpeq:
3590 case Hexagon::C2_cmpgt:
3591 case Hexagon::C2_cmpgtu:
3592 DstReg = MI.getOperand(0).getReg();
3593 Src1Reg = MI.getOperand(1).getReg();
3594 Src2Reg = MI.getOperand(2).getReg();
3595 if (Hexagon::PredRegsRegClass.contains(DstReg) &&
3596 (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) &&
3597 isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg))
3598 return HexagonII::HCG_A;
3599 break;
3600 case Hexagon::C2_cmpeqi:
3601 case Hexagon::C2_cmpgti:
3602 case Hexagon::C2_cmpgtui:
3603 // P0 = cmp.eq(Rs,#u2)
3604 DstReg = MI.getOperand(0).getReg();
3605 SrcReg = MI.getOperand(1).getReg();
3606 if (Hexagon::PredRegsRegClass.contains(DstReg) &&
3607 (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) &&
3608 isIntRegForSubInst(SrcReg) && MI.getOperand(2).isImm() &&
3609 ((isUInt<5>(MI.getOperand(2).getImm())) ||
3610 (MI.getOperand(2).getImm() == -1)))
3611 return HexagonII::HCG_A;
3612 break;
3613 case Hexagon::A2_tfr:
3614 // Rd = Rs
3615 DstReg = MI.getOperand(0).getReg();
3616 SrcReg = MI.getOperand(1).getReg();
3617 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg))
3618 return HexagonII::HCG_A;
3619 break;
3620 case Hexagon::A2_tfrsi:
3621 // Rd = #u6
3622 // Do not test for #u6 size since the const is getting extended
3623 // regardless and compound could be formed.
3624 DstReg = MI.getOperand(0).getReg();
3625 if (isIntRegForSubInst(DstReg))
3626 return HexagonII::HCG_A;
3627 break;
3628 case Hexagon::S2_tstbit_i:
3629 DstReg = MI.getOperand(0).getReg();
3630 Src1Reg = MI.getOperand(1).getReg();
3631 if (Hexagon::PredRegsRegClass.contains(DstReg) &&
3632 (Hexagon::P0 == DstReg || Hexagon::P1 == DstReg) &&
3633 MI.getOperand(2).isImm() &&
3634 isIntRegForSubInst(Src1Reg) && (MI.getOperand(2).getImm() == 0))
3635 return HexagonII::HCG_A;
3636 break;
3637 // The fact that .new form is used pretty much guarantees
3638 // that predicate register will match. Nevertheless,
3639 // there could be some false positives without additional
3640 // checking.
3641 case Hexagon::J2_jumptnew:
3642 case Hexagon::J2_jumpfnew:
3643 case Hexagon::J2_jumptnewpt:
3644 case Hexagon::J2_jumpfnewpt:
3645 Src1Reg = MI.getOperand(0).getReg();
3646 if (Hexagon::PredRegsRegClass.contains(Src1Reg) &&
3647 (Hexagon::P0 == Src1Reg || Hexagon::P1 == Src1Reg))
3648 return HexagonII::HCG_B;
3649 break;
3650 // Transfer and jump:
3651 // Rd=#U6 ; jump #r9:2
3652 // Rd=Rs ; jump #r9:2
3653 // Do not test for jump range here.
3654 case Hexagon::J2_jump:
3655 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4:
3656 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC:
3657 return HexagonII::HCG_C;
3658 }
3659
3660 return HexagonII::HCG_None;
3661}
3662
3663// Returns -1 when there is no opcode found.
3665 const MachineInstr &GB) const {
3668 if ((GA.getOpcode() != Hexagon::C2_cmpeqi) ||
3669 (GB.getOpcode() != Hexagon::J2_jumptnew))
3670 return -1u;
3671 Register DestReg = GA.getOperand(0).getReg();
3672 if (!GB.readsRegister(DestReg, /*TRI=*/nullptr))
3673 return -1u;
3674 if (DestReg != Hexagon::P0 && DestReg != Hexagon::P1)
3675 return -1u;
3676 // The value compared against must be either u5 or -1.
3677 const MachineOperand &CmpOp = GA.getOperand(2);
3678 if (!CmpOp.isImm())
3679 return -1u;
3680 int V = CmpOp.getImm();
3681 if (V == -1)
3682 return DestReg == Hexagon::P0 ? Hexagon::J4_cmpeqn1_tp0_jump_nt
3683 : Hexagon::J4_cmpeqn1_tp1_jump_nt;
3684 if (!isUInt<5>(V))
3685 return -1u;
3686 return DestReg == Hexagon::P0 ? Hexagon::J4_cmpeqi_tp0_jump_nt
3687 : Hexagon::J4_cmpeqi_tp1_jump_nt;
3688}
3689
3690// Returns -1 if there is no opcode found.
3692 bool ForBigCore) const {
3693 // Static table to switch the opcodes across Tiny Core and Big Core.
3694 // dup_ opcodes are Big core opcodes.
3695 // NOTE: There are special instructions that need to handled later.
3696 // L4_return* instructions, they will only occupy SLOT0 (on big core too).
3697 // PS_jmpret - This pseudo translates to J2_jumpr which occupies only SLOT2.
3698 // The compiler need to base the root instruction to L6_return_map_to_raw
3699 // which can go any slot.
3700 static const std::map<unsigned, unsigned> DupMap = {
3701 {Hexagon::A2_add, Hexagon::dup_A2_add},
3702 {Hexagon::A2_addi, Hexagon::dup_A2_addi},
3703 {Hexagon::A2_andir, Hexagon::dup_A2_andir},
3704 {Hexagon::A2_combineii, Hexagon::dup_A2_combineii},
3705 {Hexagon::A2_sxtb, Hexagon::dup_A2_sxtb},
3706 {Hexagon::A2_sxth, Hexagon::dup_A2_sxth},
3707 {Hexagon::A2_tfr, Hexagon::dup_A2_tfr},
3708 {Hexagon::A2_tfrsi, Hexagon::dup_A2_tfrsi},
3709 {Hexagon::A2_zxtb, Hexagon::dup_A2_zxtb},
3710 {Hexagon::A2_zxth, Hexagon::dup_A2_zxth},
3711 {Hexagon::A4_combineii, Hexagon::dup_A4_combineii},
3712 {Hexagon::A4_combineir, Hexagon::dup_A4_combineir},
3713 {Hexagon::A4_combineri, Hexagon::dup_A4_combineri},
3714 {Hexagon::C2_cmoveif, Hexagon::dup_C2_cmoveif},
3715 {Hexagon::C2_cmoveit, Hexagon::dup_C2_cmoveit},
3716 {Hexagon::C2_cmovenewif, Hexagon::dup_C2_cmovenewif},
3717 {Hexagon::C2_cmovenewit, Hexagon::dup_C2_cmovenewit},
3718 {Hexagon::C2_cmpeqi, Hexagon::dup_C2_cmpeqi},
3719 {Hexagon::L2_deallocframe, Hexagon::dup_L2_deallocframe},
3720 {Hexagon::L2_loadrb_io, Hexagon::dup_L2_loadrb_io},
3721 {Hexagon::L2_loadrd_io, Hexagon::dup_L2_loadrd_io},
3722 {Hexagon::L2_loadrh_io, Hexagon::dup_L2_loadrh_io},
3723 {Hexagon::L2_loadri_io, Hexagon::dup_L2_loadri_io},
3724 {Hexagon::L2_loadrub_io, Hexagon::dup_L2_loadrub_io},
3725 {Hexagon::L2_loadruh_io, Hexagon::dup_L2_loadruh_io},
3726 {Hexagon::S2_allocframe, Hexagon::dup_S2_allocframe},
3727 {Hexagon::S2_storerb_io, Hexagon::dup_S2_storerb_io},
3728 {Hexagon::S2_storerd_io, Hexagon::dup_S2_storerd_io},
3729 {Hexagon::S2_storerh_io, Hexagon::dup_S2_storerh_io},
3730 {Hexagon::S2_storeri_io, Hexagon::dup_S2_storeri_io},
3731 {Hexagon::S4_storeirb_io, Hexagon::dup_S4_storeirb_io},
3732 {Hexagon::S4_storeiri_io, Hexagon::dup_S4_storeiri_io},
3733 };
3734 unsigned OpNum = MI.getOpcode();
3735 // Conversion to Big core.
3736 if (ForBigCore) {
3737 auto Iter = DupMap.find(OpNum);
3738 if (Iter != DupMap.end())
3739 return Iter->second;
3740 } else { // Conversion to Tiny core.
3741 for (const auto &Iter : DupMap)
3742 if (Iter.second == OpNum)
3743 return Iter.first;
3744 }
3745 return -1;
3746}
3747
3748int HexagonInstrInfo::getCondOpcode(int Opc, bool invertPredicate) const {
3749 enum Hexagon::PredSense inPredSense;
3750 inPredSense = invertPredicate ? Hexagon::PredSense_false :
3751 Hexagon::PredSense_true;
3752 int CondOpcode = Hexagon::getPredOpcode(Opc, inPredSense);
3753 if (CondOpcode >= 0) // Valid Conditional opcode/instruction
3754 return CondOpcode;
3755
3756 llvm_unreachable("Unexpected predicable instruction");
3757}
3758
3759// Return the cur value instruction for a given store.
3761 switch (MI.getOpcode()) {
3762 default: llvm_unreachable("Unknown .cur type");
3763 case Hexagon::V6_vL32b_pi:
3764 return Hexagon::V6_vL32b_cur_pi;
3765 case Hexagon::V6_vL32b_ai:
3766 return Hexagon::V6_vL32b_cur_ai;
3767 case Hexagon::V6_vL32b_nt_pi:
3768 return Hexagon::V6_vL32b_nt_cur_pi;
3769 case Hexagon::V6_vL32b_nt_ai:
3770 return Hexagon::V6_vL32b_nt_cur_ai;
3771 case Hexagon::V6_vL32b_ppu:
3772 return Hexagon::V6_vL32b_cur_ppu;
3773 case Hexagon::V6_vL32b_nt_ppu:
3774 return Hexagon::V6_vL32b_nt_cur_ppu;
3775 }
3776 return 0;
3777}
3778
3779// Return the regular version of the .cur instruction.
3781 switch (MI.getOpcode()) {
3782 default: llvm_unreachable("Unknown .cur type");
3783 case Hexagon::V6_vL32b_cur_pi:
3784 return Hexagon::V6_vL32b_pi;
3785 case Hexagon::V6_vL32b_cur_ai:
3786 return Hexagon::V6_vL32b_ai;
3787 case Hexagon::V6_vL32b_nt_cur_pi:
3788 return Hexagon::V6_vL32b_nt_pi;
3789 case Hexagon::V6_vL32b_nt_cur_ai:
3790 return Hexagon::V6_vL32b_nt_ai;
3791 case Hexagon::V6_vL32b_cur_ppu:
3792 return Hexagon::V6_vL32b_ppu;
3793 case Hexagon::V6_vL32b_nt_cur_ppu:
3794 return Hexagon::V6_vL32b_nt_ppu;
3795 }
3796 return 0;
3797}
3798
3799// The diagram below shows the steps involved in the conversion of a predicated
3800// store instruction to its .new predicated new-value form.
3801//
3802// Note: It doesn't include conditional new-value stores as they can't be
3803// converted to .new predicate.
3804//
3805// p.new NV store [ if(p0.new)memw(R0+#0)=R2.new ]
3806// ^ ^
3807// / \ (not OK. it will cause new-value store to be
3808// / X conditional on p0.new while R2 producer is
3809// / \ on p0)
3810// / \.
3811// p.new store p.old NV store
3812// [if(p0.new)memw(R0+#0)=R2] [if(p0)memw(R0+#0)=R2.new]
3813// ^ ^
3814// \ /
3815// \ /
3816// \ /
3817// p.old store
3818// [if (p0)memw(R0+#0)=R2]
3819//
3820// The following set of instructions further explains the scenario where
3821// conditional new-value store becomes invalid when promoted to .new predicate
3822// form.
3823//
3824// { 1) if (p0) r0 = add(r1, r2)
3825// 2) p0 = cmp.eq(r3, #0) }
3826//
3827// 3) if (p0) memb(r1+#0) = r0 --> this instruction can't be grouped with
3828// the first two instructions because in instr 1, r0 is conditional on old value
3829// of p0 but its use in instr 3 is conditional on p0 modified by instr 2 which
3830// is not valid for new-value stores.
3831// Predicated new value stores (i.e. if (p0) memw(..)=r0.new) are excluded
3832// from the "Conditional Store" list. Because a predicated new value store
3833// would NOT be promoted to a double dot new store. See diagram below:
3834// This function returns yes for those stores that are predicated but not
3835// yet promoted to predicate dot new instructions.
3836//
3837// +---------------------+
3838// /-----| if (p0) memw(..)=r0 |---------\~
3839// || +---------------------+ ||
3840// promote || /\ /\ || promote
3841// || /||\ /||\ ||
3842// \||/ demote || \||/
3843// \/ || || \/
3844// +-------------------------+ || +-------------------------+
3845// | if (p0.new) memw(..)=r0 | || | if (p0) memw(..)=r0.new |
3846// +-------------------------+ || +-------------------------+
3847// || || ||
3848// || demote \||/
3849// promote || \/ NOT possible
3850// || || /\~
3851// \||/ || /||\~
3852// \/ || ||
3853// +-----------------------------+
3854// | if (p0.new) memw(..)=r0.new |
3855// +-----------------------------+
3856// Double Dot New Store
3857//
3858// Returns the most basic instruction for the .new predicated instructions and
3859// new-value stores.
3860// For example, all of the following instructions will be converted back to the
3861// same instruction:
3862// 1) if (p0.new) memw(R0+#0) = R1.new --->
3863// 2) if (p0) memw(R0+#0)= R1.new -------> if (p0) memw(R0+#0) = R1
3864// 3) if (p0.new) memw(R0+#0) = R1 --->
3865//
3866// To understand the translation of instruction 1 to its original form, consider
3867// a packet with 3 instructions.
3868// { p0 = cmp.eq(R0,R1)
3869// if (p0.new) R2 = add(R3, R4)
3870// R5 = add (R3, R1)
3871// }
3872// if (p0) memw(R5+#0) = R2 <--- trying to include it in the previous packet
3873//
3874// This instruction can be part of the previous packet only if both p0 and R2
3875// are promoted to .new values. This promotion happens in steps, first
3876// predicate register is promoted to .new and in the next iteration R2 is
3877// promoted. Therefore, in case of dependence check failure (due to R5) during
3878// next iteration, it should be converted back to its most basic form.
3879
3880// Return the new value instruction for a given store.
3882 int NVOpcode = Hexagon::getNewValueOpcode(MI.getOpcode());
3883 if (NVOpcode >= 0) // Valid new-value store instruction.
3884 return NVOpcode;
3885
3886 switch (MI.getOpcode()) {
3887 default:
3888 report_fatal_error(Twine("Unknown .new type: ") +
3889 std::to_string(MI.getOpcode()));
3890 case Hexagon::S4_storerb_ur:
3891 return Hexagon::S4_storerbnew_ur;
3892
3893 case Hexagon::S2_storerb_pci:
3894 return Hexagon::S2_storerb_pci;
3895
3896 case Hexagon::S2_storeri_pci:
3897 return Hexagon::S2_storeri_pci;
3898
3899 case Hexagon::S2_storerh_pci:
3900 return Hexagon::S2_storerh_pci;
3901
3902 case Hexagon::S2_storerd_pci:
3903 return Hexagon::S2_storerd_pci;
3904
3905 case Hexagon::S2_storerf_pci:
3906 return Hexagon::S2_storerf_pci;
3907
3908 case Hexagon::V6_vS32b_ai:
3909 return Hexagon::V6_vS32b_new_ai;
3910
3911 case Hexagon::V6_vS32b_pi:
3912 return Hexagon::V6_vS32b_new_pi;
3913 }
3914 return 0;
3915}
3916
3917// Returns the opcode to use when converting MI, which is a conditional jump,
3918// into a conditional instruction which uses the .new value of the predicate.
3919// We also use branch probabilities to add a hint to the jump.
3920// If MBPI is null, all edges will be treated as equally likely for the
3921// purposes of establishing a predication hint.
3923 const MachineBranchProbabilityInfo *MBPI) const {
3924 // We assume that block can have at most two successors.
3925 const MachineBasicBlock *Src = MI.getParent();
3926 const MachineOperand &BrTarget = MI.getOperand(1);
3927 bool Taken = false;
3928 const BranchProbability OneHalf(1, 2);
3929
3930 auto getEdgeProbability = [MBPI] (const MachineBasicBlock *Src,
3931 const MachineBasicBlock *Dst) {
3932 if (MBPI)
3933 return MBPI->getEdgeProbability(Src, Dst);
3934 return BranchProbability(1, Src->succ_size());
3935 };
3936
3937 if (BrTarget.isMBB()) {
3938 const MachineBasicBlock *Dst = BrTarget.getMBB();
3939 Taken = getEdgeProbability(Src, Dst) >= OneHalf;
3940 } else {
3941 // The branch target is not a basic block (most likely a function).
3942 // Since BPI only gives probabilities for targets that are basic blocks,
3943 // try to identify another target of this branch (potentially a fall-
3944 // -through) and check the probability of that target.
3945 //
3946 // The only handled branch combinations are:
3947 // - one conditional branch,
3948 // - one conditional branch followed by one unconditional branch.
3949 // Otherwise, assume not-taken.
3950 assert(MI.isConditionalBranch());
3951 const MachineBasicBlock &B = *MI.getParent();
3952 bool SawCond = false, Bad = false;
3953 for (const MachineInstr &I : B) {
3954 if (!I.isBranch())
3955 continue;
3956 if (I.isConditionalBranch()) {
3957 SawCond = true;
3958 if (&I != &MI) {
3959 Bad = true;
3960 break;
3961 }
3962 }
3963 if (I.isUnconditionalBranch() && !SawCond) {
3964 Bad = true;
3965 break;
3966 }
3967 }
3968 if (!Bad) {
3970 MachineBasicBlock::const_instr_iterator NextIt = std::next(It);
3971 if (NextIt == B.instr_end()) {
3972 // If this branch is the last, look for the fall-through block.
3973 for (const MachineBasicBlock *SB : B.successors()) {
3974 if (!B.isLayoutSuccessor(SB))
3975 continue;
3976 Taken = getEdgeProbability(Src, SB) < OneHalf;
3977 break;
3978 }
3979 } else {
3980 assert(NextIt->isUnconditionalBranch());
3981 // Find the first MBB operand and assume it's the target.
3982 const MachineBasicBlock *BT = nullptr;
3983 for (const MachineOperand &Op : NextIt->operands()) {
3984 if (!Op.isMBB())
3985 continue;
3986 BT = Op.getMBB();
3987 break;
3988 }
3989 Taken = BT && getEdgeProbability(Src, BT) < OneHalf;
3990 }
3991 } // if (!Bad)
3992 }
3993
3994 // The Taken flag should be set to something reasonable by this point.
3995
3996 switch (MI.getOpcode()) {
3997 case Hexagon::J2_jumpt:
3998 return Taken ? Hexagon::J2_jumptnewpt : Hexagon::J2_jumptnew;
3999 case Hexagon::J2_jumpf:
4000 return Taken ? Hexagon::J2_jumpfnewpt : Hexagon::J2_jumpfnew;
4001
4002 default:
4003 llvm_unreachable("Unexpected jump instruction.");
4004 }
4005}
4006
4007// Return .new predicate version for an instruction.
4009 const MachineBranchProbabilityInfo *MBPI) const {
4010 switch (MI.getOpcode()) {
4011 // Conditional Jumps
4012 case Hexagon::J2_jumpt:
4013 case Hexagon::J2_jumpf:
4014 return getDotNewPredJumpOp(MI, MBPI);
4015 }
4016
4017 int NewOpcode = Hexagon::getPredNewOpcode(MI.getOpcode());
4018 if (NewOpcode >= 0)
4019 return NewOpcode;
4020 return 0;
4021}
4022
4024 int NewOp = MI.getOpcode();
4025 if (isPredicated(NewOp) && isPredicatedNew(NewOp)) { // Get predicate old form
4026 NewOp = Hexagon::getPredOldOpcode(NewOp);
4027 // All Hexagon architectures have prediction bits on dot-new branches,
4028 // but only Hexagon V60+ has prediction bits on dot-old ones. Make sure
4029 // to pick the right opcode when converting back to dot-old.
4030 if (!Subtarget.hasFeature(Hexagon::ArchV60)) {
4031 switch (NewOp) {
4032 case Hexagon::J2_jumptpt:
4033 NewOp = Hexagon::J2_jumpt;
4034 break;
4035 case Hexagon::J2_jumpfpt:
4036 NewOp = Hexagon::J2_jumpf;
4037 break;
4038 case Hexagon::J2_jumprtpt:
4039 NewOp = Hexagon::J2_jumprt;
4040 break;
4041 case Hexagon::J2_jumprfpt:
4042 NewOp = Hexagon::J2_jumprf;
4043 break;
4044 }
4045 }
4046 assert(NewOp >= 0 &&
4047 "Couldn't change predicate new instruction to its old form.");
4048 }
4049
4050 if (isNewValueStore(NewOp)) { // Convert into non-new-value format
4051 NewOp = Hexagon::getNonNVStore(NewOp);
4052 assert(NewOp >= 0 && "Couldn't change new-value store to its old form.");
4053 }
4054
4055 if (Subtarget.hasV60Ops())
4056 return NewOp;
4057
4058 // Subtargets prior to V60 didn't support 'taken' forms of predicated jumps.
4059 switch (NewOp) {
4060 case Hexagon::J2_jumpfpt:
4061 return Hexagon::J2_jumpf;
4062 case Hexagon::J2_jumptpt:
4063 return Hexagon::J2_jumpt;
4064 case Hexagon::J2_jumprfpt:
4065 return Hexagon::J2_jumprf;
4066 case Hexagon::J2_jumprtpt:
4067 return Hexagon::J2_jumprt;
4068 }
4069 return NewOp;
4070}
4071
4072// See if instruction could potentially be a duplex candidate.
4073// If so, return its group. Zero otherwise.
4075 const MachineInstr &MI) const {
4076 Register DstReg, SrcReg, Src1Reg, Src2Reg;
4077 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
4078
4079 switch (MI.getOpcode()) {
4080 default:
4081 return HexagonII::HSIG_None;
4082 //
4083 // Group L1:
4084 //
4085 // Rd = memw(Rs+#u4:2)
4086 // Rd = memub(Rs+#u4:0)
4087 case Hexagon::L2_loadri_io:
4088 case Hexagon::dup_L2_loadri_io:
4089 DstReg = MI.getOperand(0).getReg();
4090 SrcReg = MI.getOperand(1).getReg();
4091 // Special case this one from Group L2.
4092 // Rd = memw(r29+#u5:2)
4093 if (isIntRegForSubInst(DstReg)) {
4094 if (Hexagon::IntRegsRegClass.contains(SrcReg) &&
4095 HRI.getStackRegister() == SrcReg &&
4096 MI.getOperand(2).isImm() &&
4097 isShiftedUInt<5,2>(MI.getOperand(2).getImm()))
4098 return HexagonII::HSIG_L2;
4099 // Rd = memw(Rs+#u4:2)
4100 if (isIntRegForSubInst(SrcReg) &&
4101 (MI.getOperand(2).isImm() &&
4102 isShiftedUInt<4,2>(MI.getOperand(2).getImm())))
4103 return HexagonII::HSIG_L1;
4104 }
4105 break;
4106 case Hexagon::L2_loadrub_io:
4107 case Hexagon::dup_L2_loadrub_io:
4108 // Rd = memub(Rs+#u4:0)
4109 DstReg = MI.getOperand(0).getReg();
4110 SrcReg = MI.getOperand(1).getReg();
4111 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
4112 MI.getOperand(2).isImm() && isUInt<4>(MI.getOperand(2).getImm()))
4113 return HexagonII::HSIG_L1;
4114 break;
4115 //
4116 // Group L2:
4117 //
4118 // Rd = memh/memuh(Rs+#u3:1)
4119 // Rd = memb(Rs+#u3:0)
4120 // Rd = memw(r29+#u5:2) - Handled above.
4121 // Rdd = memd(r29+#u5:3)
4122 // deallocframe
4123 // [if ([!]p0[.new])] dealloc_return
4124 // [if ([!]p0[.new])] jumpr r31
4125 case Hexagon::L2_loadrh_io:
4126 case Hexagon::L2_loadruh_io:
4127 case Hexagon::dup_L2_loadrh_io:
4128 case Hexagon::dup_L2_loadruh_io:
4129 // Rd = memh/memuh(Rs+#u3:1)
4130 DstReg = MI.getOperand(0).getReg();
4131 SrcReg = MI.getOperand(1).getReg();
4132 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
4133 MI.getOperand(2).isImm() &&
4134 isShiftedUInt<3,1>(MI.getOperand(2).getImm()))
4135 return HexagonII::HSIG_L2;
4136 break;
4137 case Hexagon::L2_loadrb_io:
4138 case Hexagon::dup_L2_loadrb_io:
4139 // Rd = memb(Rs+#u3:0)
4140 DstReg = MI.getOperand(0).getReg();
4141 SrcReg = MI.getOperand(1).getReg();
4142 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
4143 MI.getOperand(2).isImm() &&
4144 isUInt<3>(MI.getOperand(2).getImm()))
4145 return HexagonII::HSIG_L2;
4146 break;
4147 case Hexagon::L2_loadrd_io:
4148 case Hexagon::dup_L2_loadrd_io:
4149 // Rdd = memd(r29+#u5:3)
4150 DstReg = MI.getOperand(0).getReg();
4151 SrcReg = MI.getOperand(1).getReg();
4152 if (isDblRegForSubInst(DstReg, HRI) &&
4153 Hexagon::IntRegsRegClass.contains(SrcReg) &&
4154 HRI.getStackRegister() == SrcReg &&
4155 MI.getOperand(2).isImm() &&
4156 isShiftedUInt<5,3>(MI.getOperand(2).getImm()))
4157 return HexagonII::HSIG_L2;
4158 break;
4159 // dealloc_return is not documented in Hexagon Manual, but marked
4160 // with A_SUBINSN attribute in iset_v4classic.py.
4161 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4:
4162 case Hexagon::RESTORE_DEALLOC_RET_JMP_V4_PIC:
4163 case Hexagon::L4_return:
4164 case Hexagon::L2_deallocframe:
4165 case Hexagon::dup_L2_deallocframe:
4166 return HexagonII::HSIG_L2;
4167 case Hexagon::EH_RETURN_JMPR:
4168 case Hexagon::PS_jmpret:
4169 case Hexagon::SL2_jumpr31:
4170 // jumpr r31
4171 // Actual form JMPR implicit-def %pc, implicit %r31, implicit internal %r0
4172 DstReg = MI.getOperand(0).getReg();
4173 if (Hexagon::IntRegsRegClass.contains(DstReg) && (Hexagon::R31 == DstReg))
4174 return HexagonII::HSIG_L2;
4175 break;
4176 case Hexagon::PS_jmprett:
4177 case Hexagon::PS_jmpretf:
4178 case Hexagon::PS_jmprettnewpt:
4179 case Hexagon::PS_jmpretfnewpt:
4180 case Hexagon::PS_jmprettnew:
4181 case Hexagon::PS_jmpretfnew:
4182 case Hexagon::SL2_jumpr31_t:
4183 case Hexagon::SL2_jumpr31_f:
4184 case Hexagon::SL2_jumpr31_tnew:
4185 case Hexagon::SL2_jumpr31_fnew:
4186 DstReg = MI.getOperand(1).getReg();
4187 SrcReg = MI.getOperand(0).getReg();
4188 // [if ([!]p0[.new])] jumpr r31
4189 if ((Hexagon::PredRegsRegClass.contains(SrcReg) &&
4190 (Hexagon::P0 == SrcReg)) &&
4191 (Hexagon::IntRegsRegClass.contains(DstReg) && (Hexagon::R31 == DstReg)))
4192 return HexagonII::HSIG_L2;
4193 break;
4194 case Hexagon::L4_return_t:
4195 case Hexagon::L4_return_f:
4196 case Hexagon::L4_return_tnew_pnt:
4197 case Hexagon::L4_return_fnew_pnt:
4198 case Hexagon::L4_return_tnew_pt:
4199 case Hexagon::L4_return_fnew_pt:
4200 // [if ([!]p0[.new])] dealloc_return
4201 SrcReg = MI.getOperand(0).getReg();
4202 if (Hexagon::PredRegsRegClass.contains(SrcReg) && (Hexagon::P0 == SrcReg))
4203 return HexagonII::HSIG_L2;
4204 break;
4205 //
4206 // Group S1:
4207 //
4208 // memw(Rs+#u4:2) = Rt
4209 // memb(Rs+#u4:0) = Rt
4210 case Hexagon::S2_storeri_io:
4211 case Hexagon::dup_S2_storeri_io:
4212 // Special case this one from Group S2.
4213 // memw(r29+#u5:2) = Rt
4214 Src1Reg = MI.getOperand(0).getReg();
4215 Src2Reg = MI.getOperand(2).getReg();
4216 if (Hexagon::IntRegsRegClass.contains(Src1Reg) &&
4217 isIntRegForSubInst(Src2Reg) &&
4218 HRI.getStackRegister() == Src1Reg && MI.getOperand(1).isImm() &&
4219 isShiftedUInt<5,2>(MI.getOperand(1).getImm()))
4220 return HexagonII::HSIG_S2;
4221 // memw(Rs+#u4:2) = Rt
4222 if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) &&
4223 MI.getOperand(1).isImm() &&
4224 isShiftedUInt<4,2>(MI.getOperand(1).getImm()))
4225 return HexagonII::HSIG_S1;
4226 break;
4227 case Hexagon::S2_storerb_io:
4228 case Hexagon::dup_S2_storerb_io:
4229 // memb(Rs+#u4:0) = Rt
4230 Src1Reg = MI.getOperand(0).getReg();
4231 Src2Reg = MI.getOperand(2).getReg();
4232 if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) &&
4233 MI.getOperand(1).isImm() && isUInt<4>(MI.getOperand(1).getImm()))
4234 return HexagonII::HSIG_S1;
4235 break;
4236 //
4237 // Group S2:
4238 //
4239 // memh(Rs+#u3:1) = Rt
4240 // memw(r29+#u5:2) = Rt
4241 // memd(r29+#s6:3) = Rtt
4242 // memw(Rs+#u4:2) = #U1
4243 // memb(Rs+#u4) = #U1
4244 // allocframe(#u5:3)
4245 case Hexagon::S2_storerh_io:
4246 case Hexagon::dup_S2_storerh_io:
4247 // memh(Rs+#u3:1) = Rt
4248 Src1Reg = MI.getOperand(0).getReg();
4249 Src2Reg = MI.getOperand(2).getReg();
4250 if (isIntRegForSubInst(Src1Reg) && isIntRegForSubInst(Src2Reg) &&
4251 MI.getOperand(1).isImm() &&
4252 isShiftedUInt<3,1>(MI.getOperand(1).getImm()))
4253 return HexagonII::HSIG_S1;
4254 break;
4255 case Hexagon::S2_storerd_io:
4256 case Hexagon::dup_S2_storerd_io:
4257 // memd(r29+#s6:3) = Rtt
4258 Src1Reg = MI.getOperand(0).getReg();
4259 Src2Reg = MI.getOperand(2).getReg();
4260 if (isDblRegForSubInst(Src2Reg, HRI) &&
4261 Hexagon::IntRegsRegClass.contains(Src1Reg) &&
4262 HRI.getStackRegister() == Src1Reg && MI.getOperand(1).isImm() &&
4263 isShiftedInt<6,3>(MI.getOperand(1).getImm()))
4264 return HexagonII::HSIG_S2;
4265 break;
4266 case Hexagon::S4_storeiri_io:
4267 case Hexagon::dup_S4_storeiri_io:
4268 // memw(Rs+#u4:2) = #U1
4269 Src1Reg = MI.getOperand(0).getReg();
4270 if (isIntRegForSubInst(Src1Reg) && MI.getOperand(1).isImm() &&
4271 isShiftedUInt<4,2>(MI.getOperand(1).getImm()) &&
4272 MI.getOperand(2).isImm() && isUInt<1>(MI.getOperand(2).getImm()))
4273 return HexagonII::HSIG_S2;
4274 break;
4275 case Hexagon::S4_storeirb_io:
4276 case Hexagon::dup_S4_storeirb_io:
4277 // memb(Rs+#u4) = #U1
4278 Src1Reg = MI.getOperand(0).getReg();
4279 if (isIntRegForSubInst(Src1Reg) &&
4280 MI.getOperand(1).isImm() && isUInt<4>(MI.getOperand(1).getImm()) &&
4281 MI.getOperand(2).isImm() && isUInt<1>(MI.getOperand(2).getImm()))
4282 return HexagonII::HSIG_S2;
4283 break;
4284 case Hexagon::S2_allocframe:
4285 case Hexagon::dup_S2_allocframe:
4286 if (MI.getOperand(2).isImm() &&
4287 isShiftedUInt<5,3>(MI.getOperand(2).getImm()))
4288 return HexagonII::HSIG_S1;
4289 break;
4290 //
4291 // Group A:
4292 //
4293 // Rx = add(Rx,#s7)
4294 // Rd = Rs
4295 // Rd = #u6
4296 // Rd = #-1
4297 // if ([!]P0[.new]) Rd = #0
4298 // Rd = add(r29,#u6:2)
4299 // Rx = add(Rx,Rs)
4300 // P0 = cmp.eq(Rs,#u2)
4301 // Rdd = combine(#0,Rs)
4302 // Rdd = combine(Rs,#0)
4303 // Rdd = combine(#u2,#U2)
4304 // Rd = add(Rs,#1)
4305 // Rd = add(Rs,#-1)
4306 // Rd = sxth/sxtb/zxtb/zxth(Rs)
4307 // Rd = and(Rs,#1)
4308 case Hexagon::A2_addi:
4309 case Hexagon::dup_A2_addi:
4310 DstReg = MI.getOperand(0).getReg();
4311 SrcReg = MI.getOperand(1).getReg();
4312 if (isIntRegForSubInst(DstReg)) {
4313 // Rd = add(r29,#u6:2)
4314 if (Hexagon::IntRegsRegClass.contains(SrcReg) &&
4315 HRI.getStackRegister() == SrcReg && MI.getOperand(2).isImm() &&
4316 isShiftedUInt<6,2>(MI.getOperand(2).getImm()))
4317 return HexagonII::HSIG_A;
4318 // Rx = add(Rx,#s7)
4319 if ((DstReg == SrcReg) && MI.getOperand(2).isImm() &&
4320 isInt<7>(MI.getOperand(2).getImm()))
4321 return HexagonII::HSIG_A;
4322 // Rd = add(Rs,#1)
4323 // Rd = add(Rs,#-1)
4324 if (isIntRegForSubInst(SrcReg) && MI.getOperand(2).isImm() &&
4325 ((MI.getOperand(2).getImm() == 1) ||
4326 (MI.getOperand(2).getImm() == -1)))
4327 return HexagonII::HSIG_A;
4328 }
4329 break;
4330 case Hexagon::A2_add:
4331 case Hexagon::dup_A2_add:
4332 // Rx = add(Rx,Rs)
4333 DstReg = MI.getOperand(0).getReg();
4334 Src1Reg = MI.getOperand(1).getReg();
4335 Src2Reg = MI.getOperand(2).getReg();
4336 if (isIntRegForSubInst(DstReg) && (DstReg == Src1Reg) &&
4337 isIntRegForSubInst(Src2Reg))
4338 return HexagonII::HSIG_A;
4339 break;
4340 case Hexagon::A2_andir:
4341 case Hexagon::dup_A2_andir:
4342 // Same as zxtb.
4343 // Rd16=and(Rs16,#255)
4344 // Rd16=and(Rs16,#1)
4345 DstReg = MI.getOperand(0).getReg();
4346 SrcReg = MI.getOperand(1).getReg();
4347 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg) &&
4348 MI.getOperand(2).isImm() &&
4349 ((MI.getOperand(2).getImm() == 1) ||
4350 (MI.getOperand(2).getImm() == 255)))
4351 return HexagonII::HSIG_A;
4352 break;
4353 case Hexagon::A2_tfr:
4354 case Hexagon::dup_A2_tfr:
4355 // Rd = Rs
4356 DstReg = MI.getOperand(0).getReg();
4357 SrcReg = MI.getOperand(1).getReg();
4358 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg))
4359 return HexagonII::HSIG_A;
4360 break;
4361 case Hexagon::A2_tfrsi:
4362 case Hexagon::dup_A2_tfrsi:
4363 // Rd = #u6
4364 // Do not test for #u6 size since the const is getting extended
4365 // regardless and compound could be formed.
4366 // Rd = #-1
4367 DstReg = MI.getOperand(0).getReg();
4368 if (isIntRegForSubInst(DstReg))
4369 return HexagonII::HSIG_A;
4370 break;
4371 case Hexagon::C2_cmoveit:
4372 case Hexagon::C2_cmovenewit:
4373 case Hexagon::C2_cmoveif:
4374 case Hexagon::C2_cmovenewif:
4375 case Hexagon::dup_C2_cmoveit:
4376 case Hexagon::dup_C2_cmovenewit:
4377 case Hexagon::dup_C2_cmoveif:
4378 case Hexagon::dup_C2_cmovenewif:
4379 // if ([!]P0[.new]) Rd = #0
4380 // Actual form:
4381 // %r16 = C2_cmovenewit internal %p0, 0, implicit undef %r16;
4382 DstReg = MI.getOperand(0).getReg();
4383 SrcReg = MI.getOperand(1).getReg();
4384 if (isIntRegForSubInst(DstReg) &&
4385 Hexagon::PredRegsRegClass.contains(SrcReg) && Hexagon::P0 == SrcReg &&
4386 MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0)
4387 return HexagonII::HSIG_A;
4388 break;
4389 case Hexagon::C2_cmpeqi:
4390 case Hexagon::dup_C2_cmpeqi:
4391 // P0 = cmp.eq(Rs,#u2)
4392 DstReg = MI.getOperand(0).getReg();
4393 SrcReg = MI.getOperand(1).getReg();
4394 if (Hexagon::PredRegsRegClass.contains(DstReg) &&
4395 Hexagon::P0 == DstReg && isIntRegForSubInst(SrcReg) &&
4396 MI.getOperand(2).isImm() && isUInt<2>(MI.getOperand(2).getImm()))
4397 return HexagonII::HSIG_A;
4398 break;
4399 case Hexagon::A2_combineii:
4400 case Hexagon::A4_combineii:
4401 case Hexagon::dup_A2_combineii:
4402 case Hexagon::dup_A4_combineii:
4403 // Rdd = combine(#u2,#U2)
4404 DstReg = MI.getOperand(0).getReg();
4405 if (isDblRegForSubInst(DstReg, HRI) &&
4406 ((MI.getOperand(1).isImm() && isUInt<2>(MI.getOperand(1).getImm())) ||
4407 (MI.getOperand(1).isGlobal() &&
4408 isUInt<2>(MI.getOperand(1).getOffset()))) &&
4409 ((MI.getOperand(2).isImm() && isUInt<2>(MI.getOperand(2).getImm())) ||
4410 (MI.getOperand(2).isGlobal() &&
4411 isUInt<2>(MI.getOperand(2).getOffset()))))
4412 return HexagonII::HSIG_A;
4413 break;
4414 case Hexagon::A4_combineri:
4415 case Hexagon::dup_A4_combineri:
4416 // Rdd = combine(Rs,#0)
4417 // Rdd = combine(Rs,#0)
4418 DstReg = MI.getOperand(0).getReg();
4419 SrcReg = MI.getOperand(1).getReg();
4420 if (isDblRegForSubInst(DstReg, HRI) && isIntRegForSubInst(SrcReg) &&
4421 ((MI.getOperand(2).isImm() && MI.getOperand(2).getImm() == 0) ||
4422 (MI.getOperand(2).isGlobal() && MI.getOperand(2).getOffset() == 0)))
4423 return HexagonII::HSIG_A;
4424 break;
4425 case Hexagon::A4_combineir:
4426 case Hexagon::dup_A4_combineir:
4427 // Rdd = combine(#0,Rs)
4428 DstReg = MI.getOperand(0).getReg();
4429 SrcReg = MI.getOperand(2).getReg();
4430 if (isDblRegForSubInst(DstReg, HRI) && isIntRegForSubInst(SrcReg) &&
4431 ((MI.getOperand(1).isImm() && MI.getOperand(1).getImm() == 0) ||
4432 (MI.getOperand(1).isGlobal() && MI.getOperand(1).getOffset() == 0)))
4433 return HexagonII::HSIG_A;
4434 break;
4435 case Hexagon::A2_sxtb:
4436 case Hexagon::A2_sxth:
4437 case Hexagon::A2_zxtb:
4438 case Hexagon::A2_zxth:
4439 case Hexagon::dup_A2_sxtb:
4440 case Hexagon::dup_A2_sxth:
4441 case Hexagon::dup_A2_zxtb:
4442 case Hexagon::dup_A2_zxth:
4443 // Rd = sxth/sxtb/zxtb/zxth(Rs)
4444 DstReg = MI.getOperand(0).getReg();
4445 SrcReg = MI.getOperand(1).getReg();
4446 if (isIntRegForSubInst(DstReg) && isIntRegForSubInst(SrcReg))
4447 return HexagonII::HSIG_A;
4448 break;
4449 }
4450
4451 return HexagonII::HSIG_None;
4452}
4453
4455 const InstrItineraryData *ItinData, const MachineInstr &MI) const {
4456 // Default to one cycle for no itinerary. However, an "empty" itinerary may
4457 // still have a MinLatency property, which getStageLatency checks.
4458 if (!ItinData)
4459 return getInstrLatency(ItinData, MI);
4460
4461 if (MI.isTransient())
4462 return 0;
4463 return ItinData->getStageLatency(MI.getDesc().getSchedClass());
4464}
4465
4466/// getOperandLatency - Compute and return the use operand latency of a given
4467/// pair of def and use.
4468/// In most cases, the static scheduling itinerary was enough to determine the
4469/// operand latency. But it may not be possible for instructions with variable
4470/// number of defs / uses.
4471///
4472/// This is a raw interface to the itinerary that may be directly overridden by
4473/// a target. Use computeOperandLatency to get the best estimate of latency.
4475 const InstrItineraryData *ItinData, const MachineInstr &DefMI,
4476 unsigned DefIdx, const MachineInstr &UseMI, unsigned UseIdx) const {
4477 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
4478
4479 // Get DefIdx and UseIdx for super registers.
4480 const MachineOperand &DefMO = DefMI.getOperand(DefIdx);
4481
4482 if (DefMO.isReg() && DefMO.getReg().isPhysical()) {
4483 if (DefMO.isImplicit()) {
4484 for (MCPhysReg SR : HRI.superregs(DefMO.getReg())) {
4485 int Idx = DefMI.findRegisterDefOperandIdx(SR, &HRI, false, false);
4486 if (Idx != -1) {
4487 DefIdx = Idx;
4488 break;
4489 }
4490 }
4491 }
4492
4493 const MachineOperand &UseMO = UseMI.getOperand(UseIdx);
4494 if (UseMO.isImplicit()) {
4495 for (MCPhysReg SR : HRI.superregs(UseMO.getReg())) {
4496 int Idx = UseMI.findRegisterUseOperandIdx(SR, &HRI, false);
4497 if (Idx != -1) {
4498 UseIdx = Idx;
4499 break;
4500 }
4501 }
4502 }
4503 }
4504
4505 std::optional<unsigned> Latency = TargetInstrInfo::getOperandLatency(
4506 ItinData, DefMI, DefIdx, UseMI, UseIdx);
4507 if (Latency == 0)
4508 // We should never have 0 cycle latency between two instructions unless
4509 // they can be packetized together. However, this decision can't be made
4510 // here.
4511 Latency = 1;
4512 return Latency;
4513}
4514
4515// inverts the predication logic.
4516// p -> NotP
4517// NotP -> P
4520 if (Cond.empty())
4521 return false;
4522 unsigned Opc = getInvertedPredicatedOpcode(Cond[0].getImm());
4523 Cond[0].setImm(Opc);
4524 return true;
4525}
4526
4528 int InvPredOpcode;
4529 InvPredOpcode = isPredicatedTrue(Opc) ? Hexagon::getFalsePredOpcode(Opc)
4530 : Hexagon::getTruePredOpcode(Opc);
4531 if (InvPredOpcode >= 0) // Valid instruction with the inverted predicate.
4532 return InvPredOpcode;
4533
4534 llvm_unreachable("Unexpected predicated instruction");
4535}
4536
4537// Returns the max value that doesn't need to be extended.
4539 const uint64_t F = MI.getDesc().TSFlags;
4540 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
4542 unsigned bits = (F >> HexagonII::ExtentBitsPos)
4544
4545 if (isSigned) // if value is signed
4546 return ~(-1U << (bits - 1));
4547 else
4548 return ~(-1U << bits);
4549}
4550
4551
4553 switch (MI.getOpcode()) {
4554 case Hexagon::L2_loadrbgp:
4555 case Hexagon::L2_loadrdgp:
4556 case Hexagon::L2_loadrhgp:
4557 case Hexagon::L2_loadrigp:
4558 case Hexagon::L2_loadrubgp:
4559 case Hexagon::L2_loadruhgp:
4560 case Hexagon::S2_storerbgp:
4561 case Hexagon::S2_storerbnewgp:
4562 case Hexagon::S2_storerhgp:
4563 case Hexagon::S2_storerhnewgp:
4564 case Hexagon::S2_storerigp:
4565 case Hexagon::S2_storerinewgp:
4566 case Hexagon::S2_storerdgp:
4567 case Hexagon::S2_storerfgp:
4568 return true;
4569 }
4570 const uint64_t F = MI.getDesc().TSFlags;
4571 unsigned addrMode =
4573 // Disallow any base+offset instruction. The assembler does not yet reorder
4574 // based up any zero offset instruction.
4575 return (addrMode == HexagonII::BaseRegOffset ||
4576 addrMode == HexagonII::BaseImmOffset ||
4577 addrMode == HexagonII::BaseLongOffset);
4578}
4579
4581 // Workaround for the Global Scheduler. Sometimes, it creates
4582 // A4_ext as a Pseudo instruction and calls this function to see if
4583 // it can be added to an existing bundle. Since the instruction doesn't
4584 // belong to any BB yet, we can't use getUnits API.
4585 if (MI.getOpcode() == Hexagon::A4_ext)
4586 return false;
4587
4588 unsigned FuncUnits = getUnits(MI);
4589 return HexagonFUnits::isSlot0Only(FuncUnits);
4590}
4591
4593 const uint64_t F = MI.getDesc().TSFlags;
4596}
4597
4599 bool ToBigInstrs) const {
4600 int Opcode = -1;
4601 if (ToBigInstrs) { // To BigCore Instr.
4602 // Check if the instruction can form a Duplex.
4603 if (getDuplexCandidateGroup(*MII))
4604 // Get the opcode marked "dup_*" tag.
4605 Opcode = getDuplexOpcode(*MII, ToBigInstrs);
4606 } else // To TinyCore Instr.
4607 Opcode = getDuplexOpcode(*MII, ToBigInstrs);
4608
4609 // Change the opcode of the instruction.
4610 if (Opcode >= 0)
4611 MII->setDesc(get(Opcode));
4612}
4613
4614// This function is used to translate instructions to facilitate generating
4615// Duplexes on TinyCore.
4617 bool ToBigInstrs) const {
4618 for (auto &MB : MF)
4619 for (MachineBasicBlock::instr_iterator Instr = MB.instr_begin(),
4620 End = MB.instr_end();
4621 Instr != End; ++Instr)
4622 changeDuplexOpcode(Instr, ToBigInstrs);
4623}
4624
4625// This is a specialized form of above function.
4627 MachineBasicBlock::instr_iterator MII, bool ToBigInstrs) const {
4628 MachineBasicBlock *MBB = MII->getParent();
4629 while ((MII != MBB->instr_end()) && MII->isInsideBundle()) {
4630 changeDuplexOpcode(MII, ToBigInstrs);
4631 ++MII;
4632 }
4633}
4634
4636 using namespace HexagonII;
4637
4638 const uint64_t F = MI.getDesc().TSFlags;
4639 unsigned S = (F >> MemAccessSizePos) & MemAccesSizeMask;
4640 unsigned Size = getMemAccessSizeInBytes(MemAccessSize(S));
4641 if (Size != 0)
4642 return Size;
4643 // Y2_dcfetchbo is special
4644 if (MI.getOpcode() == Hexagon::Y2_dcfetchbo)
4646
4647 // Handle vector access sizes.
4648 const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo();
4649 switch (S) {
4651 return HRI.getSpillSize(Hexagon::HvxVRRegClass);
4653 return HRI.getSpillSize(Hexagon::HlxLRRegClass);
4654 default:
4655 llvm_unreachable("Unexpected instruction");
4656 }
4657}
4658
4659// Returns the min value that doesn't need to be extended.
4661 const uint64_t F = MI.getDesc().TSFlags;
4662 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
4664 unsigned bits = (F >> HexagonII::ExtentBitsPos)
4666
4667 if (isSigned) // if value is signed
4668 return -1U << (bits - 1);
4669 else
4670 return 0;
4671}
4672
4673// Returns opcode of the non-extended equivalent instruction.
4675 // Check if the instruction has a register form that uses register in place
4676 // of the extended operand, if so return that as the non-extended form.
4677 short NonExtOpcode = Hexagon::getRegForm(MI.getOpcode());
4678 if (NonExtOpcode >= 0)
4679 return NonExtOpcode;
4680
4681 if (MI.getDesc().mayLoad() || MI.getDesc().mayStore()) {
4682 // Check addressing mode and retrieve non-ext equivalent instruction.
4683 switch (getAddrMode(MI)) {
4685 return Hexagon::changeAddrMode_abs_io(MI.getOpcode());
4687 return Hexagon::changeAddrMode_io_rr(MI.getOpcode());
4689 return Hexagon::changeAddrMode_ur_rr(MI.getOpcode());
4690
4691 default:
4692 return -1;
4693 }
4694 }
4695 return -1;
4696}
4697
4699 Register &PredReg, unsigned &PredRegPos,
4700 RegState &PredRegFlags) const {
4701 if (Cond.empty())
4702 return false;
4703 assert(Cond.size() == 2);
4704 if (isNewValueJump(Cond[0].getImm()) || Cond[1].isMBB()) {
4705 LLVM_DEBUG(dbgs() << "No predregs for new-value jumps/endloop");
4706 return false;
4707 }
4708 PredReg = Cond[1].getReg();
4709 PredRegPos = 1;
4710 // See IfConversion.cpp why we add RegState::Implicit | RegState::Undef
4711 PredRegFlags = {};
4712 if (Cond[1].isImplicit())
4713 PredRegFlags = RegState::Implicit;
4714 if (Cond[1].isUndef())
4715 PredRegFlags |= RegState::Undef;
4716 return true;
4717}
4718
4720 return Hexagon::getRegForm(MI.getOpcode());
4721}
4722
4723// Return the number of bytes required to encode the instruction.
4724// Hexagon instructions are fixed length, 4 bytes, unless they
4725// use a constant extender, which requires another 4 bytes.
4726// For debug instructions and prolog labels, return 0.
4728 if (MI.isDebugInstr() || MI.isPosition())
4729 return 0;
4730
4731 unsigned Size = MI.getDesc().getSize();
4732 if (!Size)
4733 // Assume the default insn size in case it cannot be determined
4734 // for whatever reason.
4736
4739
4740 // Try and compute number of instructions in asm.
4741 if (BranchRelaxAsmLarge && MI.getOpcode() == Hexagon::INLINEASM) {
4742 const MachineBasicBlock &MBB = *MI.getParent();
4743 const MachineFunction *MF = MBB.getParent();
4744 const MCAsmInfo &MAI = MF->getTarget().getMCAsmInfo();
4745
4746 // Count the number of register definitions to find the asm string.
4747 unsigned NumDefs = 0;
4748 for (; MI.getOperand(NumDefs).isReg() && MI.getOperand(NumDefs).isDef();
4749 ++NumDefs)
4750 assert(NumDefs != MI.getNumOperands()-2 && "No asm string?");
4751
4752 assert(MI.getOperand(NumDefs).isSymbol() && "No asm string?");
4753 // Disassemble the AsmStr and approximate number of instructions.
4754 const char *AsmStr = MI.getOperand(NumDefs).getSymbolName();
4755 Size = getInlineAsmLength(AsmStr, MAI);
4756 }
4757
4758 return Size;
4759}
4760
4762 const uint64_t F = MI.getDesc().TSFlags;
4764}
4765
4767 const InstrItineraryData &II = *Subtarget.getInstrItineraryData();
4768 const InstrStage &IS = *II.beginStage(MI.getDesc().getSchedClass());
4769
4770 return IS.getUnits();
4771}
4772
4773// Calculate size of the basic block without debug instructions.
4775 return nonDbgMICount(BB->instr_begin(), BB->instr_end());
4776}
4777
4779 MachineBasicBlock::const_iterator BundleHead) const {
4780 assert(BundleHead->isBundle() && "Not a bundle header");
4781 auto MII = BundleHead.getInstrIterator();
4782 // Skip the bundle header.
4783 return nonDbgMICount(++MII, getBundleEnd(BundleHead.getInstrIterator()));
4784}
4785
4786/// immediateExtend - Changes the instruction in place to one using an immediate
4787/// extender.
4790 "Instruction must be extendable");
4791 // Find which operand is extendable.
4792 short ExtOpNum = getCExtOpNum(MI);
4793 MachineOperand &MO = MI.getOperand(ExtOpNum);
4794 // This needs to be something we understand.
4795 assert((MO.isMBB() || MO.isImm()) &&
4796 "Branch with unknown extendable field type");
4797 // Mark given operand as extended.
4799}
4800
4802 MachineInstr &MI, MachineBasicBlock *NewTarget) const {
4803 LLVM_DEBUG(dbgs() << "\n[invertAndChangeJumpTarget] to "
4804 << printMBBReference(*NewTarget);
4805 MI.dump(););
4806 assert(MI.isBranch());
4807 unsigned NewOpcode = getInvertedPredicatedOpcode(MI.getOpcode());
4808 int TargetPos = MI.getNumOperands() - 1;
4809 // In general branch target is the last operand,
4810 // but some implicit defs added at the end might change it.
4811 while ((TargetPos > -1) && !MI.getOperand(TargetPos).isMBB())
4812 --TargetPos;
4813 assert((TargetPos >= 0) && MI.getOperand(TargetPos).isMBB());
4814 MI.getOperand(TargetPos).setMBB(NewTarget);
4816 NewOpcode = reversePrediction(NewOpcode);
4817 }
4818 MI.setDesc(get(NewOpcode));
4819 return true;
4820}
4821
4823 /* +++ The code below is used to generate complete set of Hexagon Insn +++ */
4825 MachineBasicBlock &B = *A;
4827 DebugLoc DL = I->getDebugLoc();
4828 MachineInstr *NewMI;
4829
4830 for (unsigned insn = TargetOpcode::GENERIC_OP_END+1;
4831 insn < Hexagon::INSTRUCTION_LIST_END; ++insn) {
4832 NewMI = BuildMI(B, I, DL, get(insn));
4833 LLVM_DEBUG(dbgs() << "\n"
4834 << getName(NewMI->getOpcode())
4835 << " Class: " << NewMI->getDesc().getSchedClass());
4836 NewMI->eraseFromParent();
4837 }
4838 /* --- The code above is used to generate complete set of Hexagon Insn --- */
4839}
4840
4841// inverts the predication logic.
4842// p -> NotP
4843// NotP -> P
4845 LLVM_DEBUG(dbgs() << "\nTrying to reverse pred. sense of:"; MI.dump());
4846 MI.setDesc(get(getInvertedPredicatedOpcode(MI.getOpcode())));
4847 return true;
4848}
4849
4850// Reverse the branch prediction.
4851unsigned HexagonInstrInfo::reversePrediction(unsigned Opcode) const {
4852 int PredRevOpcode = -1;
4853 if (isPredictedTaken(Opcode))
4854 PredRevOpcode = Hexagon::notTakenBranchPrediction(Opcode);
4855 else
4856 PredRevOpcode = Hexagon::takenBranchPrediction(Opcode);
4857 assert(PredRevOpcode > 0);
4858 return PredRevOpcode;
4859}
4860
4861// TODO: Add more rigorous validation.
4863 const {
4864 return Cond.empty() || (Cond[0].isImm() && (Cond.size() != 1));
4865}
4866
4869 assert(MIB->isBundle());
4870 MachineOperand &Operand = MIB->getOperand(0);
4871 if (Operand.isImm())
4872 Operand.setImm(Operand.getImm() | memShufDisabledMask);
4873 else
4874 MIB->addOperand(MachineOperand::CreateImm(memShufDisabledMask));
4875}
4876
4878 assert(MIB.isBundle());
4879 const MachineOperand &Operand = MIB.getOperand(0);
4880 return (Operand.isImm() && (Operand.getImm() & memShufDisabledMask) != 0);
4881}
4882
4884 return (MI->getOpcode() == Hexagon::V6_vmpy_qf16_hf ||
4885 MI->getOpcode() == Hexagon::V6_vmpy_qf16_mix_hf ||
4886 MI->getOpcode() == Hexagon::V6_vmpy_qf32_hf ||
4887 MI->getOpcode() == Hexagon::V6_vmpy_qf32_mix_hf ||
4888 MI->getOpcode() == Hexagon::V6_vmpy_qf32_sf ||
4889 MI->getOpcode() == Hexagon::V6_vmpy_qf16_mix_hf ||
4890 MI->getOpcode() == Hexagon::V6_vmpy_qf16 ||
4891 MI->getOpcode() == Hexagon::V6_vmpy_qf32_mix_hf ||
4892 MI->getOpcode() == Hexagon::V6_vmpy_qf32_qf16 ||
4893 MI->getOpcode() == Hexagon::V6_vmpy_qf32);
4894}
4895
4896namespace llvm::HexagonII {
4897
4900 RegType In3 = RegType::Unknown) {
4901 RegTypeInfo I;
4902 I.Output = Out;
4903 I.Input1 = In1;
4904 I.Input2 = In2;
4905 I.Input3 = In3;
4906 return I;
4907}
4908
4909RegTypeInfo getRegTypeInfo(unsigned Opcode) {
4910 switch (Opcode) {
4911 default:
4912 return {};
4913
4914 case Hexagon::V6_vabs_qf16_hf:
4915 return make(RegType::QF16);
4916 case Hexagon::V6_vabs_qf16_qf16:
4918 case Hexagon::V6_vabs_qf32_qf32:
4920 case Hexagon::V6_vabs_qf32_sf:
4921 return make(RegType::QF32);
4922 case Hexagon::V6_vadd_hf:
4923 return make(RegType::QF16);
4924 case Hexagon::V6_vadd_qf16:
4926 case Hexagon::V6_vadd_qf16_mix:
4928 case Hexagon::V6_vadd_qf32:
4930 case Hexagon::V6_vadd_qf32_mix:
4932 case Hexagon::V6_vadd_sf:
4933 return make(RegType::QF32);
4934 case Hexagon::V6_vconv_bf_qf32:
4936 case Hexagon::V6_vconv_f8_qf16:
4938 case Hexagon::V6_vconv_hf_qf16:
4940 case Hexagon::V6_vconv_hf_qf32:
4942 case Hexagon::V6_vconv_qf16_f8:
4943 return make(RegType::QF16);
4944 case Hexagon::V6_vconv_qf16_hf:
4945 return make(RegType::QF16);
4946 case Hexagon::V6_vconv_qf16_qf16:
4948 case Hexagon::V6_vconv_qf32_qf32:
4950 case Hexagon::V6_vconv_qf32_sf:
4951 return make(RegType::QF32);
4952 case Hexagon::V6_vconv_sf_qf32:
4954 case Hexagon::V6_vilog2_qf16:
4956 case Hexagon::V6_vilog2_qf32:
4958 case Hexagon::V6_vmpy_qf16:
4960 case Hexagon::V6_vmpy_qf16_hf:
4961 return make(RegType::QF16);
4962 case Hexagon::V6_vmpy_qf16_mix_hf:
4964 case Hexagon::V6_vmpy_qf32:
4966 case Hexagon::V6_vmpy_qf32_hf:
4967 return make(RegType::QF32);
4968 case Hexagon::V6_vmpy_qf32_mix_hf:
4970 case Hexagon::V6_vmpy_qf32_qf16:
4972 case Hexagon::V6_vmpy_qf32_sf:
4973 return make(RegType::QF32);
4974 case Hexagon::V6_vmpy_rt_hf:
4975 return make(RegType::QF16);
4976 case Hexagon::V6_vmpy_rt_qf16:
4978 case Hexagon::V6_vmpy_rt_sf:
4979 return make(RegType::QF32);
4980 case Hexagon::V6_vneg_qf16_hf:
4981 return make(RegType::QF16);
4982 case Hexagon::V6_vneg_qf16_qf16:
4984 case Hexagon::V6_vneg_qf32_qf32:
4986 case Hexagon::V6_vneg_qf32_sf:
4987 return make(RegType::QF32);
4988 case Hexagon::V6_vsub_hf:
4989 return make(RegType::QF16);
4990 case Hexagon::V6_vsub_qf16:
4992 case Hexagon::V6_vsub_qf16_mix:
4994 case Hexagon::V6_vsub_qf32:
4996 case Hexagon::V6_vsub_qf32_mix:
4998 case Hexagon::V6_vsub_sf:
4999 return make(RegType::QF32);
5000 case Hexagon::V6_vsub_sf_mix:
5002 case Hexagon::V6_vsub_hf_mix:
5004 }
5005}
5006
5007} // namespace llvm::HexagonII
5008
5010 auto Info = HexagonII::getRegTypeInfo(MI->getOpcode());
5011 switch (Index) {
5012 case 1:
5013 return Info.Input1 == HexagonII::RegType::QF32;
5014 case 2:
5015 return Info.Input2 == HexagonII::RegType::QF32;
5016 case 3:
5017 return Info.Input3 == HexagonII::RegType::QF32;
5018 case 0:
5019 return Info.Input1 == HexagonII::RegType::QF32 ||
5020 Info.Input2 == HexagonII::RegType::QF32 ||
5021 Info.Input3 == HexagonII::RegType::QF32;
5022 default: // No instruction with more than 3 operands uses QF32.
5023 return false;
5024 }
5025 return false;
5026}
5027
5029 auto Info = HexagonII::getRegTypeInfo(MI->getOpcode());
5030 switch (Index) {
5031 case 1:
5032 return Info.Input1 == HexagonII::RegType::QF16;
5033 case 2:
5034 return Info.Input2 == HexagonII::RegType::QF16;
5035 case 3:
5036 return Info.Input3 == HexagonII::RegType::QF16;
5037 case 0:
5038 return Info.Input1 == HexagonII::RegType::QF16 ||
5039 Info.Input2 == HexagonII::RegType::QF16 ||
5040 Info.Input3 == HexagonII::RegType::QF16;
5041 default: // No instruction with more than 3 operands uses QF16.
5042 return false;
5043 }
5044 return false;
5045}
5046
5048 return usesQF32Operand(MI, Index) || usesQF16Operand(MI, Index);
5049}
5050
5054
5058
5062
5063// Return true if the function contains any qf-generating instructions.
5065 for (const MachineBasicBlock &MBB : MF)
5066 for (const MachineInstr &MI : MBB)
5067 if (isQFPInstr(const_cast<MachineInstr *>(&MI)))
5068 return true;
5069 return false;
5070}
5071
5072// Returns true if A appears before B within the same basic block.
5074 const MachineInstr *B) const {
5075 if (!A || !B || A->getParent() != B->getParent())
5076 return false;
5077
5078 for (const MachineInstr &MI : *A->getParent()) {
5079 if (&MI == A)
5080 return true;
5081 if (&MI == B)
5082 return false;
5083 }
5084 return false;
5085}
5086
5087// Returns false if a call, or an instruction between MI and Second, changes a
5088// register MI reads, so MI cannot be copied to just after Second.
5090 const TargetRegisterInfo *TRI) {
5091 for (MachineInstr &Between :
5092 make_range(std::next(MI.getIterator()), Second.getIterator()))
5093 for (const MachineOperand &MO : MI.debug_operands())
5094 if (MO.isReg() && MO.getReg().isValid() &&
5095 (Between.isCall() || Between.modifiesRegister(MO.getReg(), TRI)))
5096 return false;
5097 return true;
5098}
5099
5101 MachineInstr &Second) const {
5102 MachineBasicBlock &MBB = *Second.getParent();
5103 MachineFunction &MF = *MBB.getParent();
5105 Register DefReg = First.getOperand(0).getReg();
5106 auto Gap = make_range(std::next(First.getIterator()), Second.getIterator());
5107
5108 // The variables with a value that reads DefReg. All values of these
5109 // variables are copied, so that their order holds.
5111 for (MachineInstr &MI : Gap)
5112 if (MI.isDebugValue() && !MI.isDebugEntryValue() &&
5113 MI.readsRegister(DefReg, TRI) &&
5114 !is_contained(Vars, MI.getDebugVariable()))
5115 Vars.push_back(MI.getDebugVariable());
5116
5118 for (MachineInstr &MI : Gap)
5119 if (MI.isDebugValue() && is_contained(Vars, MI.getDebugVariable()))
5120 Group.push_back(&MI);
5121
5122 bool CanMove = !Second.isTerminator();
5123 for (MachineInstr *MI : Group)
5124 CanMove = CanMove && canMoveDebugValue(*MI, Second, TRI);
5125
5126 // Computed once, so that the copies stay in order.
5127 MachineBasicBlock::iterator FinalPos = std::next(Second.getIterator());
5128 for (MachineInstr *MI : Group)
5129 if (CanMove)
5130 MBB.insert(FinalPos, MF.CloneMachineInstr(MI));
5131 for (MachineInstr *MI : Group)
5132 if (!MI->isDebugEntryValue() && MI->readsRegister(DefReg, TRI))
5133 MI->setDebugValueUndef();
5134}
5135
5136// Addressing mode relations.
5138 return Opc >= 0 ? Hexagon::changeAddrMode_abs_io(Opc) : Opc;
5139}
5140
5142 return Opc >= 0 ? Hexagon::changeAddrMode_io_abs(Opc) : Opc;
5143}
5144
5146 return Opc >= 0 ? Hexagon::changeAddrMode_io_pi(Opc) : Opc;
5147}
5148
5150 return Opc >= 0 ? Hexagon::changeAddrMode_io_rr(Opc) : Opc;
5151}
5152
5154 return Opc >= 0 ? Hexagon::changeAddrMode_pi_io(Opc) : Opc;
5155}
5156
5158 return Opc >= 0 ? Hexagon::changeAddrMode_rr_io(Opc) : Opc;
5159}
5160
5162 return Opc >= 0 ? Hexagon::changeAddrMode_rr_ur(Opc) : Opc;
5163}
5164
5166 return Opc >= 0 ? Hexagon::changeAddrMode_ur_rr(Opc) : Opc;
5167}
5168
5170 static const MCInst Nop = MCInstBuilder(Hexagon::A2_nop);
5171
5172 return MCInstBuilder(Hexagon::BUNDLE)
5173 .addImm(0)
5174 .addInst(&Nop);
5175}
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
static bool mayAlias(MachineInstr &MIa, SmallVectorImpl< MachineInstr * > &MemInsns, AliasAnalysis *AA)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t Imm
static bool isConstant(const MachineInstr &MI)
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static const Function * getParent(const Value *V)
BitTracker BT
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
DXIL Forward Handle Accesses
static bool isSigned(unsigned Opcode)
const HexagonInstrInfo * TII
static void parseOperands(MachineInstr *MI, SmallVector< unsigned, 4 > &Defs, SmallVector< unsigned, 8 > &Uses)
Gather register def/uses from MI.
static cl::opt< bool > DisableNVSchedule("disable-hexagon-nv-schedule", cl::Hidden, cl::desc("Disable schedule adjustment for new value stores."))
const int Hexagon_MEMH_OFFSET_MAX
const int Hexagon_MEMB_OFFSET_MAX
const int Hexagon_MEMH_OFFSET_MIN
const int Hexagon_MEMD_OFFSET_MAX
static cl::opt< bool > EnableTimingClassLatency("enable-timing-class-latency", cl::Hidden, cl::init(false), cl::desc("Enable timing class latency"))
const int Hexagon_MEMD_OFFSET_MIN
const int Hexagon_ADDI_OFFSET_MAX
static cl::opt< bool > EnableACCForwarding("enable-acc-forwarding", cl::Hidden, cl::init(true), cl::desc("Enable vec acc forwarding"))
static void getLiveInRegsAt(LivePhysRegs &Regs, const MachineInstr &MI)
const int Hexagon_MEMW_OFFSET_MAX
Constants for Hexagon instructions.
const int Hexagon_MEMW_OFFSET_MIN
cl::opt< bool > ScheduleInlineAsm("hexagon-sched-inline-asm", cl::Hidden, cl::init(false), cl::desc("Do not consider inline-asm a scheduling/" "packetization boundary."))
const int Hexagon_ADDI_OFFSET_MIN
static cl::opt< bool > BranchRelaxAsmLarge("branch-relax-asm-large", cl::init(true), cl::Hidden, cl::desc("branch relax asm"))
static cl::opt< bool > EnableALUForwarding("enable-alu-forwarding", cl::Hidden, cl::init(true), cl::desc("Enable vec alu forwarding"))
const int Hexagon_MEMB_OFFSET_MIN
static unsigned nonDbgMICount(MachineBasicBlock::const_instr_iterator MIB, MachineBasicBlock::const_instr_iterator MIE)
Calculate number of instructions excluding the debug instructions.
static cl::opt< bool > EnableBranchPrediction("hexagon-enable-branch-prediction", cl::Hidden, cl::init(true), cl::desc("Enable branch prediction"))
static bool isDblRegForSubInst(Register Reg, const HexagonRegisterInfo &HRI)
static void getLiveOutRegsAt(LivePhysRegs &Regs, const MachineInstr &MI)
static bool canMoveDebugValue(MachineInstr &MI, MachineInstr &Second, const TargetRegisterInfo *TRI)
static cl::opt< bool > UseDFAHazardRec("dfa-hazard-rec", cl::init(true), cl::Hidden, cl::desc("Use the DFA based hazard recognizer."))
static bool isIntRegForSubInst(Register Reg)
static bool isDuplexPairMatch(unsigned Ga, unsigned Gb)
#define HEXAGON_INSTR_SIZE
IRTranslator LLVM IR MI
std::pair< Instruction::BinaryOps, Value * > OffsetOp
Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first DebugLoc that has line number information, given a range of instructions.
static bool isUndef(const MachineInstr &MI)
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define T
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
uint64_t IntrinsicInst * II
PassBuilder PB(Mod->getContext(), Machine, PassOpts->PTO, std::nullopt, &PIC)
if(PassOpts->AAPipeline)
static StringRef getName(Value *V)
static bool isBranch(unsigned Opcode)
SmallVector< MachineOperand, 4 > Cond
MachineRegisterInfo & MRI
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
Remove Loads Into Fake Uses
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:479
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
#define LLVM_DEBUG(...)
Definition Debug.h:119
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A debug info location.
Definition DebugLoc.h:126
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool isTmpLoadPseudo(const MachineInstr &MI) const
int getDuplexOpcode(const MachineInstr &MI, bool ForBigCore=true) const
bool isHLXVec(const MachineInstr &MI) const
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
Remove the branching code at the end of the specific MBB.
bool isPredicated(const MachineInstr &MI) const override
Returns true if the instruction is already predicated.
bool isHVXMemWithAIndirect(const MachineInstr &I, const MachineInstr &J) const
short changeAddrMode_abs_io(short Opc) const
bool isRestrictNoSlot1Store(const MachineInstr &MI) const
short getRegForm(const MachineInstr &MI) const
bool isVecALU(const MachineInstr &MI) const
bool isCompoundBranchInstr(const MachineInstr &MI) const
bool isDuplexPair(const MachineInstr &MIa, const MachineInstr &MIb) const
Symmetrical. See if these two instructions are fit for duplex pair.
bool isJumpR(const MachineInstr &MI) const
ScheduleHazardRecognizer * CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II, const ScheduleDAG *DAG) const override
Allocate and return a hazard recognizer to use for this target when scheduling the machine instructio...
std::pair< unsigned, unsigned > decomposeMachineOperandsTargetFlags(unsigned TF) const override
Decompose the machine operand's target flags into two values - the direct target flag value and any o...
bool getMemOperandsWithOffsetWidth(const MachineInstr &LdSt, SmallVectorImpl< const MachineOperand * > &BaseOps, int64_t &Offset, bool &OffsetIsScalable, LocationSize &Width) const override
Get the base register and byte offset of a load/store instr.
bool producesStall(const MachineInstr &ProdMI, const MachineInstr &ConsMI) const
bool invertAndChangeJumpTarget(MachineInstr &MI, MachineBasicBlock *NewTarget) const
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
Store the specified register of the given register class to the specified stack frame index.
bool isPredictedTaken(unsigned Opcode) const
bool isSaveCalleeSavedRegsCall(const MachineInstr &MI) const
bool hasQFPInstrs(const MachineFunction &MF) const
Register isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
TargetInstrInfo overrides.
unsigned nonDbgBundleSize(MachineBasicBlock::const_iterator BundleHead) const
int getDotNewPredOp(const MachineInstr &MI, const MachineBranchProbabilityInfo *MBPI) const
bool isQFP32Instr(MachineInstr *MI) const
bool ClobbersPredicate(MachineInstr &MI, std::vector< MachineOperand > &Pred, bool SkipDead) const override
If the specified instruction defines any predicate or condition code register(s) used for predication...
unsigned getInvertedPredicatedOpcode(const int Opc) const
bool isPureSlot0(const MachineInstr &MI) const
bool doesNotReturn(const MachineInstr &CallMI) const
HexagonII::SubInstructionGroup getDuplexCandidateGroup(const MachineInstr &MI) const
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e....
bool usesQF16Operand(MachineInstr *MI, unsigned Index=0) const
bool isPredicatedNew(const MachineInstr &MI) const
bool isSignExtendingLoad(const MachineInstr &MI) const
bool isVecAcc(const MachineInstr &MI) const
bool reversePredSense(MachineInstr &MI) const
bool isPostIncWithImmOffset(const MachineInstr &MI) const
bool isQFPMul(const MachineInstr *MF) const
unsigned getAddrMode(const MachineInstr &MI) const
MCInst getNop() const override
bool isJumpWithinBranchRange(const MachineInstr &MI, unsigned offset) const
bool mayBeNewStore(const MachineInstr &MI) const
bool isOperandExtended(const MachineInstr &MI, unsigned OperandNum) const
bool canExecuteInBundle(const MachineInstr &First, const MachineInstr &Second) const
Can these instructions execute at the same time in a bundle.
bool isQFP16Instr(MachineInstr *MI) const
std::optional< unsigned > getOperandLatency(const InstrItineraryData *ItinData, const MachineInstr &DefMI, unsigned DefIdx, const MachineInstr &UseMI, unsigned UseIdx) const override
getOperandLatency - Compute and return the use operand latency of a given pair of def and use.
bool isAddrModeWithOffset(const MachineInstr &MI) const
bool isBaseImmOffset(const MachineInstr &MI) const
bool isAbsoluteSet(const MachineInstr &MI) const
short changeAddrMode_io_pi(short Opc) const
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, Register DestReg, Register SrcReg, bool KillSrc, bool RenamableDest=false, bool RenamableSrc=false) const override
Emit instructions to copy a pair of physical registers.
short changeAddrMode_pi_io(short Opc) const
bool analyzeCompare(const MachineInstr &MI, Register &SrcReg, Register &SrcReg2, int64_t &Mask, int64_t &Value) const override
For a comparison instruction, return the source registers in SrcReg and SrcReg2 if having two registe...
bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const override
Reverses the branch condition of the specified condition list, returning false on success and true if...
std::unique_ptr< PipelinerLoopInfo > analyzeLoopForPipelining(MachineBasicBlock *LoopBB) const override
Analyze loop L, which must be a single-basic-block loop, and if the conditions can be understood enou...
bool isLoopN(const MachineInstr &MI) const
bool isSpillPredRegOp(const MachineInstr &MI) const
bool hasStoreToStackSlot(const MachineInstr &MI, SmallVectorImpl< const MachineMemOperand * > &Accesses) const override
Check if the instruction or the bundle of instructions has store to stack slots.
ArrayRef< std::pair< unsigned, const char * > > getSerializableDirectMachineOperandTargetFlags() const override
Return an array that contains the direct target flag values and their names.
bool isIndirectCall(const MachineInstr &MI) const
short changeAddrMode_ur_rr(short Opc) const
bool isValidAutoIncImm(const EVT VT, const int Offset) const
bool hasNonExtEquivalent(const MachineInstr &MI) const
bool isConstExtended(const MachineInstr &MI) const
bool getIncrementValue(const MachineInstr &MI, int &Value) const override
If the instruction is an increment of a constant value, return the amount.
int getCondOpcode(int Opc, bool sense) const
void moveDependentDebugValues(MachineInstr &First, MachineInstr &Second) const
Copies the debug values of the variables that read the register First and Second define to just after...
MachineInstr * findLoopInstr(MachineBasicBlock *BB, unsigned EndLoopOp, MachineBasicBlock *TargetBB, SmallPtrSet< MachineBasicBlock *, 8 > &Visited) const
Find the hardware loop instruction used to set-up the specified loop.
unsigned getInstrTimingClassLatency(const InstrItineraryData *ItinData, const MachineInstr &MI) const
bool usesQF32Operand(MachineInstr *MI, unsigned Index=0) const
bool isAccumulator(const MachineInstr &MI) const
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const override
Insert branch code into the end of the specified MachineBasicBlock.
unsigned getInstrLatency(const InstrItineraryData *ItinData, const MachineInstr &MI, unsigned *PredCost=nullptr) const override
Compute the instruction latency of a given instruction.
bool PredOpcodeHasJMP_c(unsigned Opcode) const
bool isNewValue(const MachineInstr &MI) const
Register createVR(MachineFunction *MF, MVT VT) const
HexagonInstrInfo specifics.
bool isDotCurInst(const MachineInstr &MI) const
bool validateBranchCond(const ArrayRef< MachineOperand > &Cond) const
bool isExtended(const MachineInstr &MI) const
bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, unsigned ExtraPredCycles, BranchProbability Probability) const override
Return true if it's profitable to predicate instructions with accumulated instruction latency of "Num...
bool isAsCheapAsAMove(const MachineInstr &MI) const override
int getMaxValue(const MachineInstr &MI) const
bool isPredicateLate(unsigned Opcode) const
short changeAddrMode_rr_ur(short Opc) const
bool isNewValueInst(const MachineInstr &MI) const
bool isHMXWeightInstr(const MachineInstr &MI) const
unsigned getInlineAsmLength(const char *Str, const MCAsmInfo &MAI, const TargetSubtargetInfo *STI=nullptr) const override
Measure the specified inline asm to determine an approximation of its length.
bool areMemAccessesTriviallyDisjoint(const MachineInstr &MIa, const MachineInstr &MIb) const override
int getNonDotCurOp(const MachineInstr &MI) const
bool isIndirectL4Return(const MachineInstr &MI) const
unsigned reversePrediction(unsigned Opcode) const
ArrayRef< std::pair< unsigned, const char * > > getSerializableBitmaskMachineOperandTargetFlags() const override
Return an array that contains the bitmask target flag values and their names.
bool isAssociativeAndCommutative(const MachineInstr &Inst, bool Invert) const override
InstrStage::FuncUnits getUnits(const MachineInstr &MI) const
unsigned getMemAccessSize(const MachineInstr &MI) const
bool predOpcodeHasNot(ArrayRef< MachineOperand > Cond) const
bool isComplex(const MachineInstr &MI) const
bool isPostIncrement(const MachineInstr &MI) const override
Return true for post-incremented instructions.
void setBundleNoShuf(MachineBasicBlock::instr_iterator MIB) const
MachineBasicBlock::instr_iterator expandVGatherPseudo(MachineInstr &MI) const
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, Register VReg, unsigned SubReg=0, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
Load the specified register of the given register class from the specified stack frame index.
int getDotNewOp(const MachineInstr &MI) const
void changeDuplexOpcode(MachineBasicBlock::instr_iterator MII, bool ToBigInstrs) const
bool isMemOp(const MachineInstr &MI) const
int getDotOldOp(const MachineInstr &MI) const
bool hasUncondBranch(const MachineBasicBlock *B) const
short getNonExtOpcode(const MachineInstr &MI) const
bool isNewStorePseudo(const MachineInstr &MI) const
bool isTailCall(const MachineInstr &MI) const override
void insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
Insert a noop into the instruction stream at the specified point.
bool isDeallocRet(const MachineInstr &MI) const
HexagonInstrInfo(const HexagonSubtarget &ST)
unsigned getCExtOpNum(const MachineInstr &MI) const
bool isSolo(const MachineInstr &MI) const
DFAPacketizer * CreateTargetScheduleState(const TargetSubtargetInfo &STI) const override
Create machine specific model for scheduling.
bool isLateSourceInstr(const MachineInstr &MI) const
bool isDotNewInst(const MachineInstr &MI) const
void translateInstrsForDup(MachineFunction &MF, bool ToBigInstrs=true) const
bool isTC1(const MachineInstr &MI) const
bool isSchedulingBoundary(const MachineInstr &MI, const MachineBasicBlock *MBB, const MachineFunction &MF) const override
Test if the given instruction should be considered a scheduling boundary.
bool predCanBeUsedAsDotNew(const MachineInstr &MI, Register PredReg) const
unsigned getSize(const MachineInstr &MI) const
bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCycles, BranchProbability Probability) const override
Return true if it's profitable for if-converter to duplicate instructions of specified accumulated in...
short changeAddrMode_io_abs(short Opc) const
int getDotCurOp(const MachineInstr &MI) const
bool expandPostRAPseudo(MachineInstr &MI) const override
This function is called for all pseudo instructions that remain after register allocation.
bool isMIBefore(const MachineInstr *A, const MachineInstr *B) const
bool isExpr(unsigned OpType) const
void genAllInsnTimingClasses(MachineFunction &MF) const
bool isTC2Early(const MachineInstr &MI) const
bool hasEHLabel(const MachineBasicBlock *B) const
bool shouldSink(const MachineInstr &MI) const override
bool isZeroExtendingLoad(const MachineInstr &MI) const
short changeAddrMode_rr_io(short Opc) const
bool isHVXVec(const MachineInstr &MI) const
bool isDependent(const MachineInstr &ProdMI, const MachineInstr &ConsMI) const
short changeAddrMode_io_rr(short Opc) const
bool SubsumesPredicate(ArrayRef< MachineOperand > Pred1, ArrayRef< MachineOperand > Pred2) const override
Returns true if the first specified predicate subsumes the second, e.g.
bool mayBeCurLoad(const MachineInstr &MI) const
bool getBundleNoShuf(const MachineInstr &MIB) const
bool isNewValueJump(const MachineInstr &MI) const
bool isTC4x(const MachineInstr &MI) const
bool PredicateInstruction(MachineInstr &MI, ArrayRef< MachineOperand > Cond) const override
Convert the instruction into a predicated instruction.
bool getPredReg(ArrayRef< MachineOperand > Cond, Register &PredReg, unsigned &PredRegPos, RegState &PredRegFlags) const
bool isFloat(const MachineInstr &MI) const
bool isQFPInstr(MachineInstr *MI) const
bool isToBeScheduledASAP(const MachineInstr &MI1, const MachineInstr &MI2) const
MachineOperand * getBaseAndOffset(const MachineInstr &MI, int64_t &Offset, LocationSize &AccessSize) const
bool getInvertedPredSense(SmallVectorImpl< MachineOperand > &Cond) const
unsigned nonDbgBBSize(const MachineBasicBlock *BB) const
getInstrTimingClassLatency - Compute the instruction latency of a given instruction using Timing Clas...
uint64_t getType(const MachineInstr &MI) const
bool isEndLoopN(unsigned Opcode) const
bool getBaseAndOffsetPosition(const MachineInstr &MI, unsigned &BasePos, unsigned &OffsetPos) const override
For instructions with a base and offset, return the position of the base register and offset operands...
bool isPredicable(const MachineInstr &MI) const override
Return true if the specified instruction can be predicated.
bool isHMXActivateInstr(const MachineInstr &MI) const
bool isExtendable(const MachineInstr &MI) const
void immediateExtend(MachineInstr &MI) const
immediateExtend - Changes the instruction in place to one using an immediate extender.
bool isValidOffset(unsigned Opcode, int Offset, bool Extend=true) const
bool isActivateWeightPair(const MachineInstr &MIa, const MachineInstr &MIb) const
HexagonII::CompoundGroup getCompoundCandidateGroup(const MachineInstr &MI) const
bool hasLoadFromStackSlot(const MachineInstr &MI, SmallVectorImpl< const MachineMemOperand * > &Accesses) const override
Check if the instruction or the bundle of instructions has load from stack slots.
SmallVector< MachineInstr *, 2 > getBranchingInstrs(MachineBasicBlock &MBB) const
bool isPredicatedTrue(const MachineInstr &MI) const
bool isNewValueStore(const MachineInstr &MI) const
int getMinValue(const MachineInstr &MI) const
bool isVecUsableNextPacket(const MachineInstr &ProdMI, const MachineInstr &ConsMI) const
unsigned getCompoundOpcode(const MachineInstr &GA, const MachineInstr &GB) const
bool addLatencyToSchedule(const MachineInstr &MI1, const MachineInstr &MI2) const
Register isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
If the specified machine instruction is a direct store to a stack slot, return the virtual or physica...
int getDotNewPredJumpOp(const MachineInstr &MI, const MachineBranchProbabilityInfo *MBPI) const
bool usesQFOperand(MachineInstr *MI, unsigned Index=0) const
bool isTC2(const MachineInstr &MI) const
Hexagon target-specific information for each MachineFunction.
Register getFrameRegister(const MachineFunction &MF) const override
Itinerary data supplied by a subtarget to be used by a target.
unsigned getStageLatency(unsigned ItinClassIndx) const
Return the total stage latency of the given class.
void RemoveMachineInstrFromMaps(MachineInstr &MI)
A set of physical registers with utility functions to track liveness when walking backward/forward th...
LLVM_ABI void stepForward(const MachineInstr &MI, SmallVectorImpl< std::pair< MCPhysReg, const MachineOperand * > > &Clobbers)
Simulates liveness when stepping forward over an instruction(bundle).
LLVM_ABI void stepBackward(const MachineInstr &MI)
Simulates liveness when stepping backwards over an instruction(bundle).
LLVM_ABI void addLiveIns(const MachineBasicBlock &MBB)
Adds all live-in registers of basic block MBB.
LLVM_ABI bool available(const MachineRegisterInfo &MRI, MCRegister Reg) const
Returns true if register Reg and no aliasing register is in the set.
LLVM_ABI void addLiveOuts(const MachineBasicBlock &MBB)
Adds all live-out registers of basic block MBB.
bool contains(MCRegister Reg) const
Returns true if register Reg is contained in the set.
static LocationSize precise(uint64_t Value)
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:67
virtual unsigned getMaxInstLength(const MCSubtargetInfo *STI=nullptr) const
Returns the maximum possible encoded instruction size in bytes.
Definition MCAsmInfo.h:554
StringRef getCommentString() const
Definition MCAsmInfo.h:565
const char * getSeparatorString() const
Definition MCAsmInfo.h:560
MCInstBuilder & addInst(const MCInst *Val)
Add a new MCInst operand.
MCInstBuilder & addImm(int64_t Val)
Add a new integer immediate operand.
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
Describe properties that are true of each instruction in the target description file.
unsigned getSchedClass() const
Return the scheduling class for this instruction.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
Machine Value Type.
SimpleValueType SimpleTy
MachineInstrBundleIterator< const MachineInstr > const_iterator
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
Instructions::iterator instr_iterator
Instructions::const_iterator const_instr_iterator
iterator_range< pred_iterator > predecessors()
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI BranchProbability getEdgeProbability(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
const char * createExternalSymbolName(StringRef Name)
Allocate a string and populate it with the given external symbol name.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
BasicBlockListType::iterator iterator
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags F, LLT MemTy, Align BaseAlignment, const MMOMetadata &Metadata=MMOMetadata(), SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & addUse(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
const MachineInstrBuilder & cloneMemRefs(const MachineInstr &OtherMI) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
reverse_iterator getReverse() const
Get a reverse iterator to the same node.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
const MachineBasicBlock * getParent() const
bool readsRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr reads the specified register.
bool getFlag(MIFlag Flag) const
Return whether an MI flag is set.
bool isBundle() const
unsigned getNumOperands() const
Retuns the total number of operands.
LLVM_ABI unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
LLVM_ABI bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore,...
LLVM_ABI bool hasOrderedMemoryRef() const
Return true if this instruction may have an ordered or volatile memory reference, or if the informati...
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
bool isIndirectBranch(QueryType Type=AnyInBundle) const
Return true if this is an indirect branch, such as a branch through a register.
A description of a memory reference used in the backend.
@ MOVolatile
The memory access is volatile.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
void setImm(int64_t immVal)
int64_t getImm() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
unsigned getTargetFlags() const
static MachineOperand CreateImm(int64_t Val)
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
bool isBlockAddress() const
isBlockAddress - Tests if this is a MO_BlockAddress operand.
Register getReg() const
getReg - Returns the register number.
void addTargetFlag(unsigned F)
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_GlobalAddress
Address of a global value.
@ MO_BlockAddress
Address of a basic block.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
bool isFPImm() const
isFPImm - Tests if this is a MO_FPImmediate operand.
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Special value supplied for machine level alias analysis.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition Register.h:83
HazardRecognizer - This determines whether or not an instruction can be issued this cycle,...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Register getReg() const
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
size_t count(char C) const
Return the number of occurrences of C in the string.
Definition StringRef.h:471
Object returned by analyzeLoopForPipelining.
virtual ScheduleHazardRecognizer * CreateTargetPostRAHazardRecognizer(const InstrItineraryData *, const ScheduleDAG *DAG) const
Allocate and return a hazard recognizer to use for this target when scheduling the machine instructio...
virtual bool hasStoreToStackSlot(const MachineInstr &MI, SmallVectorImpl< const MachineMemOperand * > &Accesses) const
If the specified machine instruction has a store to a stack slot, return true along with the FrameInd...
virtual std::optional< unsigned > getOperandLatency(const InstrItineraryData *ItinData, SDNode *DefNode, unsigned DefIdx, SDNode *UseNode, unsigned UseIdx) const
virtual bool hasLoadFromStackSlot(const MachineInstr &MI, SmallVectorImpl< const MachineMemOperand * > &Accesses) const
If the specified machine instruction has a load from a stack slot, return true along with the FrameIn...
Primary interface to the complete machine description for the target machine.
const MCAsmInfo & getMCAsmInfo() const
Return target specific asm information.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
virtual const InstrItineraryData * getInstrItineraryData() const
getInstrItineraryData - Returns instruction itinerary data for the target or specific subtarget.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM Value Representation.
Definition Value.h:75
self_iterator getIterator()
Definition ilist_node.h:123
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isSlot0Only(unsigned units)
HexagonII - This namespace holds all of the target specific flags that instruction info tracks.
unsigned const TypeCVI_LAST
static constexpr RegTypeInfo make(RegType Out, RegType In1=RegType::Unknown, RegType In2=RegType::Unknown, RegType In3=RegType::Unknown)
unsigned const TypeCVI_FIRST
RegType getOpRegType(unsigned Opcode)
RegTypeInfo getRegTypeInfo(unsigned Opcode)
bool getTSFlag(const MCInstrDesc &MID, HexagonTSFlagsVal Pos)
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
@ Length
Definition DWP.cpp:577
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1755
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:166
RegState
Flags to represent properties of register accesses.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Kill
The last use of a register.
@ InternalRead
Register reads a value that is defined inside the same instruction or bundle.
@ Undef
Value of the register doesn't matter.
@ NoFlags
No Specific Flags.
constexpr RegState getKillRegState(bool B)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
@ Done
Definition Threading.h:60
bool is_TC1(unsigned SchedClass)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition MathExtras.h:326
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition MathExtras.h:280
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
MachineBasicBlock::instr_iterator getBundleEnd(MachineBasicBlock::instr_iterator I)
Returns an iterator pointing beyond the bundle containing I.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
RegState getRegState(const MachineOperand &RegOp)
Get all register state flags from machine operand RegOp.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
bool is_TC2(unsigned SchedClass)
bool is_TC2early(unsigned SchedClass)
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr bool isShiftedInt(int64_t x)
Checks if a signed integer is an N bit number shifted left by S.
Definition MathExtras.h:183
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
bool isSpace(char C)
Checks whether character C is whitespace in the "C" locale.
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
constexpr RegState getUndefRegState(bool B)
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
constexpr bool isShiftedUInt(uint64_t x)
Checks if a unsigned integer is an N bit number shifted left by S.
Definition MathExtras.h:199
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
bool is_TC4x(unsigned SchedClass)
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Extended Value Type.
Definition ValueTypes.h:35
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition ValueTypes.h:411
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition ValueTypes.h:354
These values represent a non-pipelined step in the execution of an instruction.
uint64_t FuncUnits
Bitmask representing a set of functional units.
This class contains a discriminated union of information about pointers in memory operands,...
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.