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