blob: e83da50569af0555a63c139ca56a8642f2a49bff [file] [log] [blame]
Benjamin Kramerf3fd7ee2012-02-06 10:19:29 +00001//===- HexagonInstrInfo.cpp - Hexagon Instruction Information -------------===//
Tony Linthicumb4b54152011-12-12 21:14:40 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the Hexagon implementation of the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "HexagonRegisterInfo.h"
15#include "HexagonInstrInfo.h"
16#include "HexagonSubtarget.h"
17#include "Hexagon.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000018#include "llvm/ADT/STLExtras.h"
19#include "llvm/ADT/SmallVector.h"
Benjamin Kramerf3fd7ee2012-02-06 10:19:29 +000020#include "llvm/CodeGen/DFAPacketizer.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000021#include "llvm/CodeGen/MachineInstrBuilder.h"
22#include "llvm/CodeGen/MachineRegisterInfo.h"
23#include "llvm/CodeGen/MachineFrameInfo.h"
24#include "llvm/CodeGen/MachineMemOperand.h"
25#include "llvm/CodeGen/PseudoSourceValue.h"
Benjamin Kramerf3fd7ee2012-02-06 10:19:29 +000026#include "llvm/Support/MathExtras.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000027#define GET_INSTRINFO_CTOR
28#include "HexagonGenInstrInfo.inc"
Andrew Trickee498d32012-02-01 22:13:57 +000029#include "HexagonGenDFAPacketizer.inc"
Tony Linthicumb4b54152011-12-12 21:14:40 +000030
Tony Linthicumb4b54152011-12-12 21:14:40 +000031using namespace llvm;
32
33///
34/// Constants for Hexagon instructions.
35///
36const int Hexagon_MEMW_OFFSET_MAX = 4095;
37const int Hexagon_MEMW_OFFSET_MIN = 4096;
38const int Hexagon_MEMD_OFFSET_MAX = 8191;
39const int Hexagon_MEMD_OFFSET_MIN = 8192;
40const int Hexagon_MEMH_OFFSET_MAX = 2047;
41const int Hexagon_MEMH_OFFSET_MIN = 2048;
42const int Hexagon_MEMB_OFFSET_MAX = 1023;
43const int Hexagon_MEMB_OFFSET_MIN = 1024;
44const int Hexagon_ADDI_OFFSET_MAX = 32767;
45const int Hexagon_ADDI_OFFSET_MIN = 32768;
46const int Hexagon_MEMD_AUTOINC_MAX = 56;
47const int Hexagon_MEMD_AUTOINC_MIN = 64;
48const int Hexagon_MEMW_AUTOINC_MAX = 28;
49const int Hexagon_MEMW_AUTOINC_MIN = 32;
50const int Hexagon_MEMH_AUTOINC_MAX = 14;
51const int Hexagon_MEMH_AUTOINC_MIN = 16;
52const int Hexagon_MEMB_AUTOINC_MAX = 7;
53const int Hexagon_MEMB_AUTOINC_MIN = 8;
54
55
56
57HexagonInstrInfo::HexagonInstrInfo(HexagonSubtarget &ST)
58 : HexagonGenInstrInfo(Hexagon::ADJCALLSTACKDOWN, Hexagon::ADJCALLSTACKUP),
59 RI(ST, *this), Subtarget(ST) {
60}
61
62
63/// isLoadFromStackSlot - If the specified machine instruction is a direct
64/// load from a stack slot, return the virtual or physical register number of
65/// the destination along with the FrameIndex of the loaded stack slot. If
66/// not, return 0. This predicate must return 0 if the instruction has
67/// any side effects other than loading from the stack slot.
68unsigned HexagonInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
69 int &FrameIndex) const {
70
71
72 switch (MI->getOpcode()) {
73 case Hexagon::LDriw:
74 case Hexagon::LDrid:
75 case Hexagon::LDrih:
76 case Hexagon::LDrib:
77 case Hexagon::LDriub:
78 if (MI->getOperand(2).isFI() &&
79 MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) {
80 FrameIndex = MI->getOperand(2).getIndex();
81 return MI->getOperand(0).getReg();
82 }
83 break;
84
85 default:
86 break;
87 }
88
89 return 0;
90}
91
92
93/// isStoreToStackSlot - If the specified machine instruction is a direct
94/// store to a stack slot, return the virtual or physical register number of
95/// the source reg along with the FrameIndex of the loaded stack slot. If
96/// not, return 0. This predicate must return 0 if the instruction has
97/// any side effects other than storing to the stack slot.
98unsigned HexagonInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
99 int &FrameIndex) const {
100 switch (MI->getOpcode()) {
101 case Hexagon::STriw:
102 case Hexagon::STrid:
103 case Hexagon::STrih:
104 case Hexagon::STrib:
105 if (MI->getOperand(2).isFI() &&
106 MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) {
107 FrameIndex = MI->getOperand(2).getIndex();
108 return MI->getOperand(0).getReg();
109 }
110 break;
111
112 default:
113 break;
114 }
115
116 return 0;
117}
118
119
120unsigned
121HexagonInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB,
122 MachineBasicBlock *FBB,
123 const SmallVectorImpl<MachineOperand> &Cond,
124 DebugLoc DL) const{
125
126 int BOpc = Hexagon::JMP;
127 int BccOpc = Hexagon::JMP_Pred;
128
129 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
130
131 int regPos = 0;
132 // Check if ReverseBranchCondition has asked to reverse this branch
133 // If we want to reverse the branch an odd number of times, we want
134 // JMP_PredNot.
135 if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) {
136 BccOpc = Hexagon::JMP_PredNot;
137 regPos = 1;
138 }
139
140 if (FBB == 0) {
141 if (Cond.empty()) {
142 // Due to a bug in TailMerging/CFG Optimization, we need to add a
143 // special case handling of a predicated jump followed by an
144 // unconditional jump. If not, Tail Merging and CFG Optimization go
145 // into an infinite loop.
146 MachineBasicBlock *NewTBB, *NewFBB;
147 SmallVector<MachineOperand, 4> Cond;
148 MachineInstr *Term = MBB.getFirstTerminator();
149 if (isPredicated(Term) && !AnalyzeBranch(MBB, NewTBB, NewFBB, Cond,
150 false)) {
151 MachineBasicBlock *NextBB =
152 llvm::next(MachineFunction::iterator(&MBB));
153 if (NewTBB == NextBB) {
154 ReverseBranchCondition(Cond);
155 RemoveBranch(MBB);
156 return InsertBranch(MBB, TBB, 0, Cond, DL);
157 }
158 }
159 BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB);
160 } else {
161 BuildMI(&MBB, DL,
162 get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB);
163 }
164 return 1;
165 }
166
167 BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB);
168 BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB);
169
170 return 2;
171}
172
173
174bool HexagonInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
175 MachineBasicBlock *&TBB,
176 MachineBasicBlock *&FBB,
177 SmallVectorImpl<MachineOperand> &Cond,
178 bool AllowModify) const {
179 FBB = NULL;
180
181 // If the block has no terminators, it just falls into the block after it.
182 MachineBasicBlock::iterator I = MBB.end();
183 if (I == MBB.begin())
184 return false;
185
186 // A basic block may looks like this:
187 //
188 // [ insn
189 // EH_LABEL
190 // insn
191 // insn
192 // insn
193 // EH_LABEL
194 // insn ]
195 //
196 // It has two succs but does not have a terminator
197 // Don't know how to handle it.
198 do {
199 --I;
200 if (I->isEHLabel())
201 return true;
202 } while (I != MBB.begin());
203
204 I = MBB.end();
205 --I;
206
207 while (I->isDebugValue()) {
208 if (I == MBB.begin())
209 return false;
210 --I;
211 }
212 if (!isUnpredicatedTerminator(I))
213 return false;
214
215 // Get the last instruction in the block.
216 MachineInstr *LastInst = I;
217
218 // If there is only one terminator instruction, process it.
219 if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
220 if (LastInst->getOpcode() == Hexagon::JMP) {
221 TBB = LastInst->getOperand(0).getMBB();
222 return false;
223 }
224 if (LastInst->getOpcode() == Hexagon::JMP_Pred) {
225 // Block ends with fall-through true condbranch.
226 TBB = LastInst->getOperand(1).getMBB();
227 Cond.push_back(LastInst->getOperand(0));
228 return false;
229 }
230 if (LastInst->getOpcode() == Hexagon::JMP_PredNot) {
231 // Block ends with fall-through false condbranch.
232 TBB = LastInst->getOperand(1).getMBB();
233 Cond.push_back(MachineOperand::CreateImm(0));
234 Cond.push_back(LastInst->getOperand(0));
235 return false;
236 }
237 // Otherwise, don't know what this is.
238 return true;
239 }
240
241 // Get the instruction before it if it's a terminator.
242 MachineInstr *SecondLastInst = I;
243
244 // If there are three terminators, we don't know what sort of block this is.
245 if (SecondLastInst && I != MBB.begin() &&
246 isUnpredicatedTerminator(--I))
247 return true;
248
249 // If the block ends with Hexagon::BRCOND and Hexagon:JMP, handle it.
250 if (((SecondLastInst->getOpcode() == Hexagon::BRCOND) ||
251 (SecondLastInst->getOpcode() == Hexagon::JMP_Pred)) &&
252 LastInst->getOpcode() == Hexagon::JMP) {
253 TBB = SecondLastInst->getOperand(1).getMBB();
254 Cond.push_back(SecondLastInst->getOperand(0));
255 FBB = LastInst->getOperand(0).getMBB();
256 return false;
257 }
258
259 // If the block ends with Hexagon::JMP_PredNot and Hexagon:JMP, handle it.
260 if ((SecondLastInst->getOpcode() == Hexagon::JMP_PredNot) &&
261 LastInst->getOpcode() == Hexagon::JMP) {
262 TBB = SecondLastInst->getOperand(1).getMBB();
263 Cond.push_back(MachineOperand::CreateImm(0));
264 Cond.push_back(SecondLastInst->getOperand(0));
265 FBB = LastInst->getOperand(0).getMBB();
266 return false;
267 }
268
269 // If the block ends with two Hexagon:JMPs, handle it. The second one is not
270 // executed, so remove it.
271 if (SecondLastInst->getOpcode() == Hexagon::JMP &&
272 LastInst->getOpcode() == Hexagon::JMP) {
273 TBB = SecondLastInst->getOperand(0).getMBB();
274 I = LastInst;
275 if (AllowModify)
276 I->eraseFromParent();
277 return false;
278 }
279
280 // Otherwise, can't handle this.
281 return true;
282}
283
284
285unsigned HexagonInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
286 int BOpc = Hexagon::JMP;
287 int BccOpc = Hexagon::JMP_Pred;
288 int BccOpcNot = Hexagon::JMP_PredNot;
289
290 MachineBasicBlock::iterator I = MBB.end();
291 if (I == MBB.begin()) return 0;
292 --I;
293 if (I->getOpcode() != BOpc && I->getOpcode() != BccOpc &&
294 I->getOpcode() != BccOpcNot)
295 return 0;
296
297 // Remove the branch.
298 I->eraseFromParent();
299
300 I = MBB.end();
301
302 if (I == MBB.begin()) return 1;
303 --I;
304 if (I->getOpcode() != BccOpc && I->getOpcode() != BccOpcNot)
305 return 1;
306
307 // Remove the branch.
308 I->eraseFromParent();
309 return 2;
310}
311
312
313void HexagonInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
314 MachineBasicBlock::iterator I, DebugLoc DL,
315 unsigned DestReg, unsigned SrcReg,
316 bool KillSrc) const {
317 if (Hexagon::IntRegsRegClass.contains(SrcReg, DestReg)) {
318 BuildMI(MBB, I, DL, get(Hexagon::TFR), DestReg).addReg(SrcReg);
319 return;
320 }
321 if (Hexagon::DoubleRegsRegClass.contains(SrcReg, DestReg)) {
322 BuildMI(MBB, I, DL, get(Hexagon::TFR_64), DestReg).addReg(SrcReg);
323 return;
324 }
325 if (Hexagon::PredRegsRegClass.contains(SrcReg, DestReg)) {
326 // Map Pd = Ps to Pd = or(Ps, Ps).
327 BuildMI(MBB, I, DL, get(Hexagon::OR_pp),
328 DestReg).addReg(SrcReg).addReg(SrcReg);
329 return;
330 }
331 if (Hexagon::DoubleRegsRegClass.contains(DestReg, SrcReg)) {
332 // We can have an overlap between single and double reg: r1:0 = r0.
333 if(SrcReg == RI.getSubReg(DestReg, Hexagon::subreg_loreg)) {
334 // r1:0 = r0
335 BuildMI(MBB, I, DL, get(Hexagon::TFRI), (RI.getSubReg(DestReg,
336 Hexagon::subreg_hireg))).addImm(0);
337 } else {
338 // r1:0 = r1 or no overlap.
339 BuildMI(MBB, I, DL, get(Hexagon::TFR), (RI.getSubReg(DestReg,
340 Hexagon::subreg_loreg))).addReg(SrcReg);
341 BuildMI(MBB, I, DL, get(Hexagon::TFRI), (RI.getSubReg(DestReg,
342 Hexagon::subreg_hireg))).addImm(0);
343 }
344 return;
345 }
346 if (Hexagon::CRRegsRegClass.contains(DestReg, SrcReg)) {
347 BuildMI(MBB, I, DL, get(Hexagon::TFCR), DestReg).addReg(SrcReg);
348 return;
349 }
350
351 assert (0 && "Unimplemented");
352}
353
354
355void HexagonInstrInfo::
356storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
357 unsigned SrcReg, bool isKill, int FI,
358 const TargetRegisterClass *RC,
359 const TargetRegisterInfo *TRI) const {
360
361 DebugLoc DL = MBB.findDebugLoc(I);
362 MachineFunction &MF = *MBB.getParent();
363 MachineFrameInfo &MFI = *MF.getFrameInfo();
364 unsigned Align = MFI.getObjectAlignment(FI);
365
366 MachineMemOperand *MMO =
367 MF.getMachineMemOperand(
368 MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)),
369 MachineMemOperand::MOStore,
370 MFI.getObjectSize(FI),
371 Align);
372
373 if (Hexagon::IntRegsRegisterClass->hasSubClassEq(RC)) {
374 BuildMI(MBB, I, DL, get(Hexagon::STriw))
375 .addFrameIndex(FI).addImm(0)
376 .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
377 } else if (Hexagon::DoubleRegsRegisterClass->hasSubClassEq(RC)) {
378 BuildMI(MBB, I, DL, get(Hexagon::STrid))
379 .addFrameIndex(FI).addImm(0)
380 .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
381 } else if (Hexagon::PredRegsRegisterClass->hasSubClassEq(RC)) {
382 BuildMI(MBB, I, DL, get(Hexagon::STriw_pred))
383 .addFrameIndex(FI).addImm(0)
384 .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
385 } else {
386 assert(0 && "Unimplemented");
387 }
388}
389
390
391void HexagonInstrInfo::storeRegToAddr(
392 MachineFunction &MF, unsigned SrcReg,
393 bool isKill,
394 SmallVectorImpl<MachineOperand> &Addr,
395 const TargetRegisterClass *RC,
396 SmallVectorImpl<MachineInstr*> &NewMIs) const
397{
398 assert(0 && "Unimplemented");
399 return;
400}
401
402
403void HexagonInstrInfo::
404loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
405 unsigned DestReg, int FI,
406 const TargetRegisterClass *RC,
407 const TargetRegisterInfo *TRI) const {
408 DebugLoc DL = MBB.findDebugLoc(I);
409 MachineFunction &MF = *MBB.getParent();
410 MachineFrameInfo &MFI = *MF.getFrameInfo();
411 unsigned Align = MFI.getObjectAlignment(FI);
412
413 MachineMemOperand *MMO =
414 MF.getMachineMemOperand(
415 MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)),
416 MachineMemOperand::MOLoad,
417 MFI.getObjectSize(FI),
418 Align);
419
420 if (RC == Hexagon::IntRegsRegisterClass) {
421 BuildMI(MBB, I, DL, get(Hexagon::LDriw), DestReg)
422 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
423 } else if (RC == Hexagon::DoubleRegsRegisterClass) {
424 BuildMI(MBB, I, DL, get(Hexagon::LDrid), DestReg)
425 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
426 } else if (RC == Hexagon::PredRegsRegisterClass) {
427 BuildMI(MBB, I, DL, get(Hexagon::LDriw_pred), DestReg)
428 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
429 } else {
430 assert(0 && "Can't store this register to stack slot");
431 }
432}
433
434
435void HexagonInstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
436 SmallVectorImpl<MachineOperand> &Addr,
437 const TargetRegisterClass *RC,
438 SmallVectorImpl<MachineInstr*> &NewMIs) const {
439 assert(0 && "Unimplemented");
440}
441
442
443MachineInstr *HexagonInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
444 MachineInstr* MI,
445 const SmallVectorImpl<unsigned> &Ops,
446 int FI) const {
447 // Hexagon_TODO: Implement.
448 return(0);
449}
450
451
452unsigned HexagonInstrInfo::createVR(MachineFunction* MF, MVT VT) const {
453
454 MachineRegisterInfo &RegInfo = MF->getRegInfo();
455 const TargetRegisterClass *TRC;
456 if (VT == MVT::i1) {
457 TRC = Hexagon::PredRegsRegisterClass;
458 } else if (VT == MVT::i32) {
459 TRC = Hexagon::IntRegsRegisterClass;
460 } else if (VT == MVT::i64) {
461 TRC = Hexagon::DoubleRegsRegisterClass;
462 } else {
Benjamin Kramer27baab62011-12-27 11:41:05 +0000463 llvm_unreachable("Cannot handle this register class");
Tony Linthicumb4b54152011-12-12 21:14:40 +0000464 }
465
466 unsigned NewReg = RegInfo.createVirtualRegister(TRC);
467 return NewReg;
468}
469
470
Andrew Trickee498d32012-02-01 22:13:57 +0000471
Tony Linthicumb4b54152011-12-12 21:14:40 +0000472bool HexagonInstrInfo::isPredicable(MachineInstr *MI) const {
473 bool isPred = MI->getDesc().isPredicable();
474
475 if (!isPred)
476 return false;
477
478 const int Opc = MI->getOpcode();
479
480 switch(Opc) {
481 case Hexagon::TFRI:
482 return isInt<12>(MI->getOperand(1).getImm());
483
484 case Hexagon::STrid:
485 case Hexagon::STrid_indexed:
486 return isShiftedUInt<6,3>(MI->getOperand(1).getImm());
487
488 case Hexagon::STriw:
489 case Hexagon::STriw_indexed:
490 case Hexagon::STriw_nv_V4:
491 return isShiftedUInt<6,2>(MI->getOperand(1).getImm());
492
493 case Hexagon::STrih:
494 case Hexagon::STrih_indexed:
495 case Hexagon::STrih_nv_V4:
496 return isShiftedUInt<6,1>(MI->getOperand(1).getImm());
497
498 case Hexagon::STrib:
499 case Hexagon::STrib_indexed:
500 case Hexagon::STrib_nv_V4:
501 return isUInt<6>(MI->getOperand(1).getImm());
502
503 case Hexagon::LDrid:
504 case Hexagon::LDrid_indexed:
505 return isShiftedUInt<6,3>(MI->getOperand(2).getImm());
506
507 case Hexagon::LDriw:
508 case Hexagon::LDriw_indexed:
509 return isShiftedUInt<6,2>(MI->getOperand(2).getImm());
510
511 case Hexagon::LDrih:
512 case Hexagon::LDriuh:
513 case Hexagon::LDrih_indexed:
514 case Hexagon::LDriuh_indexed:
515 return isShiftedUInt<6,1>(MI->getOperand(2).getImm());
516
517 case Hexagon::LDrib:
518 case Hexagon::LDriub:
519 case Hexagon::LDrib_indexed:
520 case Hexagon::LDriub_indexed:
521 return isUInt<6>(MI->getOperand(2).getImm());
522
523 case Hexagon::POST_LDrid:
524 return isShiftedInt<4,3>(MI->getOperand(3).getImm());
525
526 case Hexagon::POST_LDriw:
527 return isShiftedInt<4,2>(MI->getOperand(3).getImm());
528
529 case Hexagon::POST_LDrih:
530 case Hexagon::POST_LDriuh:
531 return isShiftedInt<4,1>(MI->getOperand(3).getImm());
532
533 case Hexagon::POST_LDrib:
534 case Hexagon::POST_LDriub:
535 return isInt<4>(MI->getOperand(3).getImm());
536
537 case Hexagon::STrib_imm_V4:
538 case Hexagon::STrih_imm_V4:
539 case Hexagon::STriw_imm_V4:
540 return (isUInt<6>(MI->getOperand(1).getImm()) &&
541 isInt<6>(MI->getOperand(2).getImm()));
542
543 case Hexagon::ADD_ri:
544 return isInt<8>(MI->getOperand(2).getImm());
545
546 case Hexagon::ASLH:
547 case Hexagon::ASRH:
548 case Hexagon::SXTB:
549 case Hexagon::SXTH:
550 case Hexagon::ZXTB:
551 case Hexagon::ZXTH:
552 return Subtarget.getHexagonArchVersion() == HexagonSubtarget::V4;
553
554 case Hexagon::JMPR:
555 return false;
Tony Linthicumb4b54152011-12-12 21:14:40 +0000556 }
557
558 return true;
559}
560
561
Andrew Trickee498d32012-02-01 22:13:57 +0000562
Tony Linthicumb4b54152011-12-12 21:14:40 +0000563int HexagonInstrInfo::
564getMatchingCondBranchOpcode(int Opc, bool invertPredicate) const {
565 switch(Opc) {
566 case Hexagon::TFR:
567 return !invertPredicate ? Hexagon::TFR_cPt :
568 Hexagon::TFR_cNotPt;
569 case Hexagon::TFRI:
570 return !invertPredicate ? Hexagon::TFRI_cPt :
571 Hexagon::TFRI_cNotPt;
572 case Hexagon::JMP:
573 return !invertPredicate ? Hexagon::JMP_Pred :
574 Hexagon::JMP_PredNot;
575 case Hexagon::ADD_ri:
576 return !invertPredicate ? Hexagon::ADD_ri_cPt :
577 Hexagon::ADD_ri_cNotPt;
578 case Hexagon::ADD_rr:
579 return !invertPredicate ? Hexagon::ADD_rr_cPt :
580 Hexagon::ADD_rr_cNotPt;
581 case Hexagon::XOR_rr:
582 return !invertPredicate ? Hexagon::XOR_rr_cPt :
583 Hexagon::XOR_rr_cNotPt;
584 case Hexagon::AND_rr:
585 return !invertPredicate ? Hexagon::AND_rr_cPt :
586 Hexagon::AND_rr_cNotPt;
587 case Hexagon::OR_rr:
588 return !invertPredicate ? Hexagon::OR_rr_cPt :
589 Hexagon::OR_rr_cNotPt;
590 case Hexagon::SUB_rr:
591 return !invertPredicate ? Hexagon::SUB_rr_cPt :
592 Hexagon::SUB_rr_cNotPt;
593 case Hexagon::COMBINE_rr:
594 return !invertPredicate ? Hexagon::COMBINE_rr_cPt :
595 Hexagon::COMBINE_rr_cNotPt;
596 case Hexagon::ASLH:
597 return !invertPredicate ? Hexagon::ASLH_cPt_V4 :
598 Hexagon::ASLH_cNotPt_V4;
599 case Hexagon::ASRH:
600 return !invertPredicate ? Hexagon::ASRH_cPt_V4 :
601 Hexagon::ASRH_cNotPt_V4;
602 case Hexagon::SXTB:
603 return !invertPredicate ? Hexagon::SXTB_cPt_V4 :
604 Hexagon::SXTB_cNotPt_V4;
605 case Hexagon::SXTH:
606 return !invertPredicate ? Hexagon::SXTH_cPt_V4 :
607 Hexagon::SXTH_cNotPt_V4;
608 case Hexagon::ZXTB:
609 return !invertPredicate ? Hexagon::ZXTB_cPt_V4 :
610 Hexagon::ZXTB_cNotPt_V4;
611 case Hexagon::ZXTH:
612 return !invertPredicate ? Hexagon::ZXTH_cPt_V4 :
613 Hexagon::ZXTH_cNotPt_V4;
614
615 case Hexagon::JMPR:
616 return !invertPredicate ? Hexagon::JMPR_cPt :
617 Hexagon::JMPR_cNotPt;
618
619 // V4 indexed+scaled load.
620 case Hexagon::LDrid_indexed_V4:
621 return !invertPredicate ? Hexagon::LDrid_indexed_cPt_V4 :
622 Hexagon::LDrid_indexed_cNotPt_V4;
623 case Hexagon::LDrid_indexed_shl_V4:
624 return !invertPredicate ? Hexagon::LDrid_indexed_shl_cPt_V4 :
625 Hexagon::LDrid_indexed_shl_cNotPt_V4;
626 case Hexagon::LDrib_indexed_V4:
627 return !invertPredicate ? Hexagon::LDrib_indexed_cPt_V4 :
628 Hexagon::LDrib_indexed_cNotPt_V4;
629 case Hexagon::LDriub_indexed_V4:
630 return !invertPredicate ? Hexagon::LDriub_indexed_cPt_V4 :
631 Hexagon::LDriub_indexed_cNotPt_V4;
632 case Hexagon::LDriub_ae_indexed_V4:
633 return !invertPredicate ? Hexagon::LDriub_indexed_cPt_V4 :
634 Hexagon::LDriub_indexed_cNotPt_V4;
635 case Hexagon::LDrib_indexed_shl_V4:
636 return !invertPredicate ? Hexagon::LDrib_indexed_shl_cPt_V4 :
637 Hexagon::LDrib_indexed_shl_cNotPt_V4;
638 case Hexagon::LDriub_indexed_shl_V4:
639 return !invertPredicate ? Hexagon::LDriub_indexed_shl_cPt_V4 :
640 Hexagon::LDriub_indexed_shl_cNotPt_V4;
641 case Hexagon::LDriub_ae_indexed_shl_V4:
642 return !invertPredicate ? Hexagon::LDriub_indexed_shl_cPt_V4 :
643 Hexagon::LDriub_indexed_shl_cNotPt_V4;
644 case Hexagon::LDrih_indexed_V4:
645 return !invertPredicate ? Hexagon::LDrih_indexed_cPt_V4 :
646 Hexagon::LDrih_indexed_cNotPt_V4;
647 case Hexagon::LDriuh_indexed_V4:
648 return !invertPredicate ? Hexagon::LDriuh_indexed_cPt_V4 :
649 Hexagon::LDriuh_indexed_cNotPt_V4;
650 case Hexagon::LDriuh_ae_indexed_V4:
651 return !invertPredicate ? Hexagon::LDriuh_indexed_cPt_V4 :
652 Hexagon::LDriuh_indexed_cNotPt_V4;
653 case Hexagon::LDrih_indexed_shl_V4:
654 return !invertPredicate ? Hexagon::LDrih_indexed_shl_cPt_V4 :
655 Hexagon::LDrih_indexed_shl_cNotPt_V4;
656 case Hexagon::LDriuh_indexed_shl_V4:
657 return !invertPredicate ? Hexagon::LDriuh_indexed_shl_cPt_V4 :
658 Hexagon::LDriuh_indexed_shl_cNotPt_V4;
659 case Hexagon::LDriuh_ae_indexed_shl_V4:
660 return !invertPredicate ? Hexagon::LDriuh_indexed_shl_cPt_V4 :
661 Hexagon::LDriuh_indexed_shl_cNotPt_V4;
662 case Hexagon::LDriw_indexed_V4:
663 return !invertPredicate ? Hexagon::LDriw_indexed_cPt_V4 :
664 Hexagon::LDriw_indexed_cNotPt_V4;
665 case Hexagon::LDriw_indexed_shl_V4:
666 return !invertPredicate ? Hexagon::LDriw_indexed_shl_cPt_V4 :
667 Hexagon::LDriw_indexed_shl_cNotPt_V4;
668 // Byte.
669 case Hexagon::POST_STbri:
670 return !invertPredicate ? Hexagon::POST_STbri_cPt :
671 Hexagon::POST_STbri_cNotPt;
672 case Hexagon::STrib:
673 return !invertPredicate ? Hexagon::STrib_cPt :
674 Hexagon::STrib_cNotPt;
675 case Hexagon::STrib_indexed:
676 return !invertPredicate ? Hexagon::STrib_indexed_cPt :
677 Hexagon::STrib_indexed_cNotPt;
678 case Hexagon::STrib_imm_V4:
679 return !invertPredicate ? Hexagon::STrib_imm_cPt_V4 :
680 Hexagon::STrib_imm_cNotPt_V4;
681 case Hexagon::STrib_indexed_shl_V4:
682 return !invertPredicate ? Hexagon::STrib_indexed_shl_cPt_V4 :
683 Hexagon::STrib_indexed_shl_cNotPt_V4;
684 // Halfword.
685 case Hexagon::POST_SThri:
686 return !invertPredicate ? Hexagon::POST_SThri_cPt :
687 Hexagon::POST_SThri_cNotPt;
688 case Hexagon::STrih:
689 return !invertPredicate ? Hexagon::STrih_cPt :
690 Hexagon::STrih_cNotPt;
691 case Hexagon::STrih_indexed:
692 return !invertPredicate ? Hexagon::STrih_indexed_cPt :
693 Hexagon::STrih_indexed_cNotPt;
694 case Hexagon::STrih_imm_V4:
695 return !invertPredicate ? Hexagon::STrih_imm_cPt_V4 :
696 Hexagon::STrih_imm_cNotPt_V4;
697 case Hexagon::STrih_indexed_shl_V4:
698 return !invertPredicate ? Hexagon::STrih_indexed_shl_cPt_V4 :
699 Hexagon::STrih_indexed_shl_cNotPt_V4;
700 // Word.
701 case Hexagon::POST_STwri:
702 return !invertPredicate ? Hexagon::POST_STwri_cPt :
703 Hexagon::POST_STwri_cNotPt;
704 case Hexagon::STriw:
705 return !invertPredicate ? Hexagon::STriw_cPt :
706 Hexagon::STriw_cNotPt;
707 case Hexagon::STriw_indexed:
708 return !invertPredicate ? Hexagon::STriw_indexed_cPt :
709 Hexagon::STriw_indexed_cNotPt;
710 case Hexagon::STriw_indexed_shl_V4:
711 return !invertPredicate ? Hexagon::STriw_indexed_shl_cPt_V4 :
712 Hexagon::STriw_indexed_shl_cNotPt_V4;
713 case Hexagon::STriw_imm_V4:
714 return !invertPredicate ? Hexagon::STriw_imm_cPt_V4 :
715 Hexagon::STriw_imm_cNotPt_V4;
716 // Double word.
717 case Hexagon::POST_STdri:
718 return !invertPredicate ? Hexagon::POST_STdri_cPt :
719 Hexagon::POST_STdri_cNotPt;
720 case Hexagon::STrid:
721 return !invertPredicate ? Hexagon::STrid_cPt :
722 Hexagon::STrid_cNotPt;
723 case Hexagon::STrid_indexed:
724 return !invertPredicate ? Hexagon::STrid_indexed_cPt :
725 Hexagon::STrid_indexed_cNotPt;
726 case Hexagon::STrid_indexed_shl_V4:
727 return !invertPredicate ? Hexagon::STrid_indexed_shl_cPt_V4 :
728 Hexagon::STrid_indexed_shl_cNotPt_V4;
729 // Load.
730 case Hexagon::LDrid:
731 return !invertPredicate ? Hexagon::LDrid_cPt :
732 Hexagon::LDrid_cNotPt;
733 case Hexagon::LDriw:
734 return !invertPredicate ? Hexagon::LDriw_cPt :
735 Hexagon::LDriw_cNotPt;
736 case Hexagon::LDrih:
737 return !invertPredicate ? Hexagon::LDrih_cPt :
738 Hexagon::LDrih_cNotPt;
739 case Hexagon::LDriuh:
740 return !invertPredicate ? Hexagon::LDriuh_cPt :
741 Hexagon::LDriuh_cNotPt;
742 case Hexagon::LDrib:
743 return !invertPredicate ? Hexagon::LDrib_cPt :
744 Hexagon::LDrib_cNotPt;
745 case Hexagon::LDriub:
746 return !invertPredicate ? Hexagon::LDriub_cPt :
747 Hexagon::LDriub_cNotPt;
748 case Hexagon::LDriubit:
749 return !invertPredicate ? Hexagon::LDriub_cPt :
750 Hexagon::LDriub_cNotPt;
751 // Load Indexed.
752 case Hexagon::LDrid_indexed:
753 return !invertPredicate ? Hexagon::LDrid_indexed_cPt :
754 Hexagon::LDrid_indexed_cNotPt;
755 case Hexagon::LDriw_indexed:
756 return !invertPredicate ? Hexagon::LDriw_indexed_cPt :
757 Hexagon::LDriw_indexed_cNotPt;
758 case Hexagon::LDrih_indexed:
759 return !invertPredicate ? Hexagon::LDrih_indexed_cPt :
760 Hexagon::LDrih_indexed_cNotPt;
761 case Hexagon::LDriuh_indexed:
762 return !invertPredicate ? Hexagon::LDriuh_indexed_cPt :
763 Hexagon::LDriuh_indexed_cNotPt;
764 case Hexagon::LDrib_indexed:
765 return !invertPredicate ? Hexagon::LDrib_indexed_cPt :
766 Hexagon::LDrib_indexed_cNotPt;
767 case Hexagon::LDriub_indexed:
768 return !invertPredicate ? Hexagon::LDriub_indexed_cPt :
769 Hexagon::LDriub_indexed_cNotPt;
770 // Post Increment Load.
771 case Hexagon::POST_LDrid:
772 return !invertPredicate ? Hexagon::POST_LDrid_cPt :
773 Hexagon::POST_LDrid_cNotPt;
774 case Hexagon::POST_LDriw:
775 return !invertPredicate ? Hexagon::POST_LDriw_cPt :
776 Hexagon::POST_LDriw_cNotPt;
777 case Hexagon::POST_LDrih:
778 return !invertPredicate ? Hexagon::POST_LDrih_cPt :
779 Hexagon::POST_LDrih_cNotPt;
780 case Hexagon::POST_LDriuh:
781 return !invertPredicate ? Hexagon::POST_LDriuh_cPt :
782 Hexagon::POST_LDriuh_cNotPt;
783 case Hexagon::POST_LDrib:
784 return !invertPredicate ? Hexagon::POST_LDrib_cPt :
785 Hexagon::POST_LDrib_cNotPt;
786 case Hexagon::POST_LDriub:
787 return !invertPredicate ? Hexagon::POST_LDriub_cPt :
788 Hexagon::POST_LDriub_cNotPt;
789 // DEALLOC_RETURN.
790 case Hexagon::DEALLOC_RET_V4:
791 return !invertPredicate ? Hexagon::DEALLOC_RET_cPt_V4 :
792 Hexagon::DEALLOC_RET_cNotPt_V4;
Tony Linthicumb4b54152011-12-12 21:14:40 +0000793 }
Benjamin Kramer27baab62011-12-27 11:41:05 +0000794 llvm_unreachable("Unexpected predicable instruction");
Tony Linthicumb4b54152011-12-12 21:14:40 +0000795}
796
797
798bool HexagonInstrInfo::
799PredicateInstruction(MachineInstr *MI,
800 const SmallVectorImpl<MachineOperand> &Cond) const {
801 int Opc = MI->getOpcode();
802 assert (isPredicable(MI) && "Expected predicable instruction");
803 bool invertJump = (!Cond.empty() && Cond[0].isImm() &&
804 (Cond[0].getImm() == 0));
805 MI->setDesc(get(getMatchingCondBranchOpcode(Opc, invertJump)));
806 //
807 // This assumes that the predicate is always the first operand
808 // in the set of inputs.
809 //
810 MI->addOperand(MI->getOperand(MI->getNumOperands()-1));
811 int oper;
812 for (oper = MI->getNumOperands() - 3; oper >= 0; --oper) {
813 MachineOperand MO = MI->getOperand(oper);
814 if ((MO.isReg() && !MO.isUse() && !MO.isImplicit())) {
815 break;
816 }
817
818 if (MO.isReg()) {
819 MI->getOperand(oper+1).ChangeToRegister(MO.getReg(), MO.isDef(),
820 MO.isImplicit(), MO.isKill(),
821 MO.isDead(), MO.isUndef(),
822 MO.isDebug());
823 } else if (MO.isImm()) {
824 MI->getOperand(oper+1).ChangeToImmediate(MO.getImm());
825 } else {
826 assert(false && "Unexpected operand type");
827 }
828 }
829
830 int regPos = invertJump ? 1 : 0;
831 MachineOperand PredMO = Cond[regPos];
832 MI->getOperand(oper+1).ChangeToRegister(PredMO.getReg(), PredMO.isDef(),
833 PredMO.isImplicit(), PredMO.isKill(),
834 PredMO.isDead(), PredMO.isUndef(),
835 PredMO.isDebug());
836
837 return true;
838}
839
840
841bool
842HexagonInstrInfo::
843isProfitableToIfCvt(MachineBasicBlock &MBB,
844 unsigned NumCyles,
845 unsigned ExtraPredCycles,
846 const BranchProbability &Probability) const {
847 return true;
848}
849
850
851bool
852HexagonInstrInfo::
853isProfitableToIfCvt(MachineBasicBlock &TMBB,
854 unsigned NumTCycles,
855 unsigned ExtraTCycles,
856 MachineBasicBlock &FMBB,
857 unsigned NumFCycles,
858 unsigned ExtraFCycles,
859 const BranchProbability &Probability) const {
860 return true;
861}
862
863
864bool HexagonInstrInfo::isPredicated(const MachineInstr *MI) const {
865 switch (MI->getOpcode()) {
866 case Hexagon::TFR_cPt:
867 case Hexagon::TFR_cNotPt:
868 case Hexagon::TFRI_cPt:
869 case Hexagon::TFRI_cNotPt:
870 case Hexagon::TFR_cdnPt:
871 case Hexagon::TFR_cdnNotPt:
872 case Hexagon::TFRI_cdnPt:
873 case Hexagon::TFRI_cdnNotPt:
874 return true;
875
876 case Hexagon::JMP_Pred:
877 case Hexagon::JMP_PredNot:
878 case Hexagon::BRCOND:
879 case Hexagon::JMP_PredPt:
880 case Hexagon::JMP_PredNotPt:
881 case Hexagon::JMP_PredPnt:
882 case Hexagon::JMP_PredNotPnt:
883 return true;
884
885 case Hexagon::LDrid_indexed_cPt_V4 :
886 case Hexagon::LDrid_indexed_cdnPt_V4 :
887 case Hexagon::LDrid_indexed_cNotPt_V4 :
888 case Hexagon::LDrid_indexed_cdnNotPt_V4 :
889 case Hexagon::LDrid_indexed_shl_cPt_V4 :
890 case Hexagon::LDrid_indexed_shl_cdnPt_V4 :
891 case Hexagon::LDrid_indexed_shl_cNotPt_V4 :
892 case Hexagon::LDrid_indexed_shl_cdnNotPt_V4 :
893 case Hexagon::LDrib_indexed_cPt_V4 :
894 case Hexagon::LDrib_indexed_cdnPt_V4 :
895 case Hexagon::LDrib_indexed_cNotPt_V4 :
896 case Hexagon::LDrib_indexed_cdnNotPt_V4 :
897 case Hexagon::LDrib_indexed_shl_cPt_V4 :
898 case Hexagon::LDrib_indexed_shl_cdnPt_V4 :
899 case Hexagon::LDrib_indexed_shl_cNotPt_V4 :
900 case Hexagon::LDrib_indexed_shl_cdnNotPt_V4 :
901 case Hexagon::LDriub_indexed_cPt_V4 :
902 case Hexagon::LDriub_indexed_cdnPt_V4 :
903 case Hexagon::LDriub_indexed_cNotPt_V4 :
904 case Hexagon::LDriub_indexed_cdnNotPt_V4 :
905 case Hexagon::LDriub_indexed_shl_cPt_V4 :
906 case Hexagon::LDriub_indexed_shl_cdnPt_V4 :
907 case Hexagon::LDriub_indexed_shl_cNotPt_V4 :
908 case Hexagon::LDriub_indexed_shl_cdnNotPt_V4 :
909 case Hexagon::LDrih_indexed_cPt_V4 :
910 case Hexagon::LDrih_indexed_cdnPt_V4 :
911 case Hexagon::LDrih_indexed_cNotPt_V4 :
912 case Hexagon::LDrih_indexed_cdnNotPt_V4 :
913 case Hexagon::LDrih_indexed_shl_cPt_V4 :
914 case Hexagon::LDrih_indexed_shl_cdnPt_V4 :
915 case Hexagon::LDrih_indexed_shl_cNotPt_V4 :
916 case Hexagon::LDrih_indexed_shl_cdnNotPt_V4 :
917 case Hexagon::LDriuh_indexed_cPt_V4 :
918 case Hexagon::LDriuh_indexed_cdnPt_V4 :
919 case Hexagon::LDriuh_indexed_cNotPt_V4 :
920 case Hexagon::LDriuh_indexed_cdnNotPt_V4 :
921 case Hexagon::LDriuh_indexed_shl_cPt_V4 :
922 case Hexagon::LDriuh_indexed_shl_cdnPt_V4 :
923 case Hexagon::LDriuh_indexed_shl_cNotPt_V4 :
924 case Hexagon::LDriuh_indexed_shl_cdnNotPt_V4 :
925 case Hexagon::LDriw_indexed_cPt_V4 :
926 case Hexagon::LDriw_indexed_cdnPt_V4 :
927 case Hexagon::LDriw_indexed_cNotPt_V4 :
928 case Hexagon::LDriw_indexed_cdnNotPt_V4 :
929 case Hexagon::LDriw_indexed_shl_cPt_V4 :
930 case Hexagon::LDriw_indexed_shl_cdnPt_V4 :
931 case Hexagon::LDriw_indexed_shl_cNotPt_V4 :
932 case Hexagon::LDriw_indexed_shl_cdnNotPt_V4 :
933 return true;
934
935 case Hexagon::LDrid_cPt :
936 case Hexagon::LDrid_cNotPt :
937 case Hexagon::LDrid_indexed_cPt :
938 case Hexagon::LDrid_indexed_cNotPt :
939 case Hexagon::POST_LDrid_cPt :
940 case Hexagon::POST_LDrid_cNotPt :
941 case Hexagon::LDriw_cPt :
942 case Hexagon::LDriw_cNotPt :
943 case Hexagon::LDriw_indexed_cPt :
944 case Hexagon::LDriw_indexed_cNotPt :
945 case Hexagon::POST_LDriw_cPt :
946 case Hexagon::POST_LDriw_cNotPt :
947 case Hexagon::LDrih_cPt :
948 case Hexagon::LDrih_cNotPt :
949 case Hexagon::LDrih_indexed_cPt :
950 case Hexagon::LDrih_indexed_cNotPt :
951 case Hexagon::POST_LDrih_cPt :
952 case Hexagon::POST_LDrih_cNotPt :
953 case Hexagon::LDrib_cPt :
954 case Hexagon::LDrib_cNotPt :
955 case Hexagon::LDrib_indexed_cPt :
956 case Hexagon::LDrib_indexed_cNotPt :
957 case Hexagon::POST_LDrib_cPt :
958 case Hexagon::POST_LDrib_cNotPt :
959 case Hexagon::LDriuh_cPt :
960 case Hexagon::LDriuh_cNotPt :
961 case Hexagon::LDriuh_indexed_cPt :
962 case Hexagon::LDriuh_indexed_cNotPt :
963 case Hexagon::POST_LDriuh_cPt :
964 case Hexagon::POST_LDriuh_cNotPt :
965 case Hexagon::LDriub_cPt :
966 case Hexagon::LDriub_cNotPt :
967 case Hexagon::LDriub_indexed_cPt :
968 case Hexagon::LDriub_indexed_cNotPt :
969 case Hexagon::POST_LDriub_cPt :
970 case Hexagon::POST_LDriub_cNotPt :
971 return true;
972
973 case Hexagon::LDrid_cdnPt :
974 case Hexagon::LDrid_cdnNotPt :
975 case Hexagon::LDrid_indexed_cdnPt :
976 case Hexagon::LDrid_indexed_cdnNotPt :
977 case Hexagon::POST_LDrid_cdnPt_V4 :
978 case Hexagon::POST_LDrid_cdnNotPt_V4 :
979 case Hexagon::LDriw_cdnPt :
980 case Hexagon::LDriw_cdnNotPt :
981 case Hexagon::LDriw_indexed_cdnPt :
982 case Hexagon::LDriw_indexed_cdnNotPt :
983 case Hexagon::POST_LDriw_cdnPt_V4 :
984 case Hexagon::POST_LDriw_cdnNotPt_V4 :
985 case Hexagon::LDrih_cdnPt :
986 case Hexagon::LDrih_cdnNotPt :
987 case Hexagon::LDrih_indexed_cdnPt :
988 case Hexagon::LDrih_indexed_cdnNotPt :
989 case Hexagon::POST_LDrih_cdnPt_V4 :
990 case Hexagon::POST_LDrih_cdnNotPt_V4 :
991 case Hexagon::LDrib_cdnPt :
992 case Hexagon::LDrib_cdnNotPt :
993 case Hexagon::LDrib_indexed_cdnPt :
994 case Hexagon::LDrib_indexed_cdnNotPt :
995 case Hexagon::POST_LDrib_cdnPt_V4 :
996 case Hexagon::POST_LDrib_cdnNotPt_V4 :
997 case Hexagon::LDriuh_cdnPt :
998 case Hexagon::LDriuh_cdnNotPt :
999 case Hexagon::LDriuh_indexed_cdnPt :
1000 case Hexagon::LDriuh_indexed_cdnNotPt :
1001 case Hexagon::POST_LDriuh_cdnPt_V4 :
1002 case Hexagon::POST_LDriuh_cdnNotPt_V4 :
1003 case Hexagon::LDriub_cdnPt :
1004 case Hexagon::LDriub_cdnNotPt :
1005 case Hexagon::LDriub_indexed_cdnPt :
1006 case Hexagon::LDriub_indexed_cdnNotPt :
1007 case Hexagon::POST_LDriub_cdnPt_V4 :
1008 case Hexagon::POST_LDriub_cdnNotPt_V4 :
1009 return true;
1010
1011 case Hexagon::ADD_ri_cPt:
1012 case Hexagon::ADD_ri_cNotPt:
1013 case Hexagon::ADD_ri_cdnPt:
1014 case Hexagon::ADD_ri_cdnNotPt:
1015 case Hexagon::ADD_rr_cPt:
1016 case Hexagon::ADD_rr_cNotPt:
1017 case Hexagon::ADD_rr_cdnPt:
1018 case Hexagon::ADD_rr_cdnNotPt:
1019 case Hexagon::XOR_rr_cPt:
1020 case Hexagon::XOR_rr_cNotPt:
1021 case Hexagon::XOR_rr_cdnPt:
1022 case Hexagon::XOR_rr_cdnNotPt:
1023 case Hexagon::AND_rr_cPt:
1024 case Hexagon::AND_rr_cNotPt:
1025 case Hexagon::AND_rr_cdnPt:
1026 case Hexagon::AND_rr_cdnNotPt:
1027 case Hexagon::OR_rr_cPt:
1028 case Hexagon::OR_rr_cNotPt:
1029 case Hexagon::OR_rr_cdnPt:
1030 case Hexagon::OR_rr_cdnNotPt:
1031 case Hexagon::SUB_rr_cPt:
1032 case Hexagon::SUB_rr_cNotPt:
1033 case Hexagon::SUB_rr_cdnPt:
1034 case Hexagon::SUB_rr_cdnNotPt:
1035 case Hexagon::COMBINE_rr_cPt:
1036 case Hexagon::COMBINE_rr_cNotPt:
1037 case Hexagon::COMBINE_rr_cdnPt:
1038 case Hexagon::COMBINE_rr_cdnNotPt:
1039 return true;
1040
1041 case Hexagon::ASLH_cPt_V4:
1042 case Hexagon::ASLH_cNotPt_V4:
1043 case Hexagon::ASRH_cPt_V4:
1044 case Hexagon::ASRH_cNotPt_V4:
1045 case Hexagon::SXTB_cPt_V4:
1046 case Hexagon::SXTB_cNotPt_V4:
1047 case Hexagon::SXTH_cPt_V4:
1048 case Hexagon::SXTH_cNotPt_V4:
1049 case Hexagon::ZXTB_cPt_V4:
1050 case Hexagon::ZXTB_cNotPt_V4:
1051 case Hexagon::ZXTH_cPt_V4:
1052 case Hexagon::ZXTH_cNotPt_V4:
1053 return true;
1054
1055 case Hexagon::ASLH_cdnPt_V4:
1056 case Hexagon::ASLH_cdnNotPt_V4:
1057 case Hexagon::ASRH_cdnPt_V4:
1058 case Hexagon::ASRH_cdnNotPt_V4:
1059 case Hexagon::SXTB_cdnPt_V4:
1060 case Hexagon::SXTB_cdnNotPt_V4:
1061 case Hexagon::SXTH_cdnPt_V4:
1062 case Hexagon::SXTH_cdnNotPt_V4:
1063 case Hexagon::ZXTB_cdnPt_V4:
1064 case Hexagon::ZXTB_cdnNotPt_V4:
1065 case Hexagon::ZXTH_cdnPt_V4:
1066 case Hexagon::ZXTH_cdnNotPt_V4:
1067 return true;
1068
1069 default:
1070 return false;
1071 }
1072}
1073
1074
1075bool
1076HexagonInstrInfo::DefinesPredicate(MachineInstr *MI,
1077 std::vector<MachineOperand> &Pred) const {
1078 for (unsigned oper = 0; oper < MI->getNumOperands(); ++oper) {
1079 MachineOperand MO = MI->getOperand(oper);
1080 if (MO.isReg() && MO.isDef()) {
1081 const TargetRegisterClass* RC = RI.getMinimalPhysRegClass(MO.getReg());
1082 if (RC == Hexagon::PredRegsRegisterClass) {
1083 Pred.push_back(MO);
1084 return true;
1085 }
1086 }
1087 }
1088 return false;
1089}
1090
1091
1092bool
1093HexagonInstrInfo::
1094SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
1095 const SmallVectorImpl<MachineOperand> &Pred2) const {
1096 // TODO: Fix this
1097 return false;
1098}
1099
1100
1101//
1102// We indicate that we want to reverse the branch by
1103// inserting a 0 at the beginning of the Cond vector.
1104//
1105bool HexagonInstrInfo::
1106ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
1107 if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) {
1108 Cond.erase(Cond.begin());
1109 } else {
1110 Cond.insert(Cond.begin(), MachineOperand::CreateImm(0));
1111 }
1112 return false;
1113}
1114
1115
1116bool HexagonInstrInfo::
1117isProfitableToDupForIfCvt(MachineBasicBlock &MBB,unsigned NumInstrs,
1118 const BranchProbability &Probability) const {
1119 return (NumInstrs <= 4);
1120}
1121
1122bool HexagonInstrInfo::isDeallocRet(const MachineInstr *MI) const {
1123 switch (MI->getOpcode()) {
1124 case Hexagon::DEALLOC_RET_V4 :
1125 case Hexagon::DEALLOC_RET_cPt_V4 :
1126 case Hexagon::DEALLOC_RET_cNotPt_V4 :
1127 case Hexagon::DEALLOC_RET_cdnPnt_V4 :
1128 case Hexagon::DEALLOC_RET_cNotdnPnt_V4 :
1129 case Hexagon::DEALLOC_RET_cdnPt_V4 :
1130 case Hexagon::DEALLOC_RET_cNotdnPt_V4 :
1131 return true;
1132 }
1133 return false;
1134}
1135
1136
1137bool HexagonInstrInfo::
1138isValidOffset(const int Opcode, const int Offset) const {
1139 // This function is to check whether the "Offset" is in the correct range of
1140 // the given "Opcode". If "Offset" is not in the correct range, "ADD_ri" is
1141 // inserted to calculate the final address. Due to this reason, the function
1142 // assumes that the "Offset" has correct alignment.
1143
1144 switch(Opcode) {
1145
1146 case Hexagon::LDriw:
1147 case Hexagon::STriw:
1148 case Hexagon::STriwt:
1149 assert((Offset % 4 == 0) && "Offset has incorrect alignment");
1150 return (Offset >= Hexagon_MEMW_OFFSET_MIN) &&
1151 (Offset <= Hexagon_MEMW_OFFSET_MAX);
1152
1153 case Hexagon::LDrid:
1154 case Hexagon::STrid:
1155 assert((Offset % 8 == 0) && "Offset has incorrect alignment");
1156 return (Offset >= Hexagon_MEMD_OFFSET_MIN) &&
1157 (Offset <= Hexagon_MEMD_OFFSET_MAX);
1158
1159 case Hexagon::LDrih:
1160 case Hexagon::LDriuh:
1161 case Hexagon::STrih:
1162 case Hexagon::LDrih_ae:
1163 assert((Offset % 2 == 0) && "Offset has incorrect alignment");
1164 return (Offset >= Hexagon_MEMH_OFFSET_MIN) &&
1165 (Offset <= Hexagon_MEMH_OFFSET_MAX);
1166
1167 case Hexagon::LDrib:
1168 case Hexagon::STrib:
1169 case Hexagon::LDriub:
1170 case Hexagon::LDriubit:
1171 case Hexagon::LDrib_ae:
1172 case Hexagon::LDriub_ae:
1173 return (Offset >= Hexagon_MEMB_OFFSET_MIN) &&
1174 (Offset <= Hexagon_MEMB_OFFSET_MAX);
1175
1176 case Hexagon::ADD_ri:
1177 case Hexagon::TFR_FI:
1178 return (Offset >= Hexagon_ADDI_OFFSET_MIN) &&
1179 (Offset <= Hexagon_ADDI_OFFSET_MAX);
1180
1181 case Hexagon::MEMw_ADDSUBi_indexed_MEM_V4 :
1182 case Hexagon::MEMw_ADDi_indexed_MEM_V4 :
1183 case Hexagon::MEMw_SUBi_indexed_MEM_V4 :
1184 case Hexagon::MEMw_ADDr_indexed_MEM_V4 :
1185 case Hexagon::MEMw_SUBr_indexed_MEM_V4 :
1186 case Hexagon::MEMw_ANDr_indexed_MEM_V4 :
1187 case Hexagon::MEMw_ORr_indexed_MEM_V4 :
1188 case Hexagon::MEMw_ADDSUBi_MEM_V4 :
1189 case Hexagon::MEMw_ADDi_MEM_V4 :
1190 case Hexagon::MEMw_SUBi_MEM_V4 :
1191 case Hexagon::MEMw_ADDr_MEM_V4 :
1192 case Hexagon::MEMw_SUBr_MEM_V4 :
1193 case Hexagon::MEMw_ANDr_MEM_V4 :
1194 case Hexagon::MEMw_ORr_MEM_V4 :
1195 assert ((Offset % 4) == 0 && "MEMOPw offset is not aligned correctly." );
1196 return (0 <= Offset && Offset <= 255);
1197
1198 case Hexagon::MEMh_ADDSUBi_indexed_MEM_V4 :
1199 case Hexagon::MEMh_ADDi_indexed_MEM_V4 :
1200 case Hexagon::MEMh_SUBi_indexed_MEM_V4 :
1201 case Hexagon::MEMh_ADDr_indexed_MEM_V4 :
1202 case Hexagon::MEMh_SUBr_indexed_MEM_V4 :
1203 case Hexagon::MEMh_ANDr_indexed_MEM_V4 :
1204 case Hexagon::MEMh_ORr_indexed_MEM_V4 :
1205 case Hexagon::MEMh_ADDSUBi_MEM_V4 :
1206 case Hexagon::MEMh_ADDi_MEM_V4 :
1207 case Hexagon::MEMh_SUBi_MEM_V4 :
1208 case Hexagon::MEMh_ADDr_MEM_V4 :
1209 case Hexagon::MEMh_SUBr_MEM_V4 :
1210 case Hexagon::MEMh_ANDr_MEM_V4 :
1211 case Hexagon::MEMh_ORr_MEM_V4 :
1212 assert ((Offset % 2) == 0 && "MEMOPh offset is not aligned correctly." );
1213 return (0 <= Offset && Offset <= 127);
1214
1215 case Hexagon::MEMb_ADDSUBi_indexed_MEM_V4 :
1216 case Hexagon::MEMb_ADDi_indexed_MEM_V4 :
1217 case Hexagon::MEMb_SUBi_indexed_MEM_V4 :
1218 case Hexagon::MEMb_ADDr_indexed_MEM_V4 :
1219 case Hexagon::MEMb_SUBr_indexed_MEM_V4 :
1220 case Hexagon::MEMb_ANDr_indexed_MEM_V4 :
1221 case Hexagon::MEMb_ORr_indexed_MEM_V4 :
1222 case Hexagon::MEMb_ADDSUBi_MEM_V4 :
1223 case Hexagon::MEMb_ADDi_MEM_V4 :
1224 case Hexagon::MEMb_SUBi_MEM_V4 :
1225 case Hexagon::MEMb_ADDr_MEM_V4 :
1226 case Hexagon::MEMb_SUBr_MEM_V4 :
1227 case Hexagon::MEMb_ANDr_MEM_V4 :
1228 case Hexagon::MEMb_ORr_MEM_V4 :
1229 return (0 <= Offset && Offset <= 63);
1230
1231 // LDri_pred and STriw_pred are pseudo operations, so it has to take offset of
1232 // any size. Later pass knows how to handle it.
1233 case Hexagon::STriw_pred:
1234 case Hexagon::LDriw_pred:
1235 return true;
1236
1237 // INLINEASM is very special.
1238 case Hexagon::INLINEASM:
1239 return true;
1240 }
1241
Benjamin Kramer27baab62011-12-27 11:41:05 +00001242 llvm_unreachable("No offset range is defined for this opcode. "
1243 "Please define it in the above switch statement!");
Tony Linthicumb4b54152011-12-12 21:14:40 +00001244}
1245
1246
1247//
1248// Check if the Offset is a valid auto-inc imm by Load/Store Type.
1249//
1250bool HexagonInstrInfo::
1251isValidAutoIncImm(const EVT VT, const int Offset) const {
1252
1253 if (VT == MVT::i64) {
1254 return (Offset >= Hexagon_MEMD_AUTOINC_MIN &&
1255 Offset <= Hexagon_MEMD_AUTOINC_MAX &&
1256 (Offset & 0x7) == 0);
1257 }
1258 if (VT == MVT::i32) {
1259 return (Offset >= Hexagon_MEMW_AUTOINC_MIN &&
1260 Offset <= Hexagon_MEMW_AUTOINC_MAX &&
1261 (Offset & 0x3) == 0);
1262 }
1263 if (VT == MVT::i16) {
1264 return (Offset >= Hexagon_MEMH_AUTOINC_MIN &&
1265 Offset <= Hexagon_MEMH_AUTOINC_MAX &&
1266 (Offset & 0x1) == 0);
1267 }
1268 if (VT == MVT::i8) {
1269 return (Offset >= Hexagon_MEMB_AUTOINC_MIN &&
1270 Offset <= Hexagon_MEMB_AUTOINC_MAX);
1271 }
1272
1273 assert(0 && "Not an auto-inc opc!");
1274
1275 return false;
1276}
1277
1278
1279bool HexagonInstrInfo::
1280isMemOp(const MachineInstr *MI) const {
1281 switch (MI->getOpcode())
1282 {
1283 case Hexagon::MEMw_ADDSUBi_indexed_MEM_V4 :
1284 case Hexagon::MEMw_ADDi_indexed_MEM_V4 :
1285 case Hexagon::MEMw_SUBi_indexed_MEM_V4 :
1286 case Hexagon::MEMw_ADDr_indexed_MEM_V4 :
1287 case Hexagon::MEMw_SUBr_indexed_MEM_V4 :
1288 case Hexagon::MEMw_ANDr_indexed_MEM_V4 :
1289 case Hexagon::MEMw_ORr_indexed_MEM_V4 :
1290 case Hexagon::MEMw_ADDSUBi_MEM_V4 :
1291 case Hexagon::MEMw_ADDi_MEM_V4 :
1292 case Hexagon::MEMw_SUBi_MEM_V4 :
1293 case Hexagon::MEMw_ADDr_MEM_V4 :
1294 case Hexagon::MEMw_SUBr_MEM_V4 :
1295 case Hexagon::MEMw_ANDr_MEM_V4 :
1296 case Hexagon::MEMw_ORr_MEM_V4 :
1297 case Hexagon::MEMh_ADDSUBi_indexed_MEM_V4 :
1298 case Hexagon::MEMh_ADDi_indexed_MEM_V4 :
1299 case Hexagon::MEMh_SUBi_indexed_MEM_V4 :
1300 case Hexagon::MEMh_ADDr_indexed_MEM_V4 :
1301 case Hexagon::MEMh_SUBr_indexed_MEM_V4 :
1302 case Hexagon::MEMh_ANDr_indexed_MEM_V4 :
1303 case Hexagon::MEMh_ORr_indexed_MEM_V4 :
1304 case Hexagon::MEMh_ADDSUBi_MEM_V4 :
1305 case Hexagon::MEMh_ADDi_MEM_V4 :
1306 case Hexagon::MEMh_SUBi_MEM_V4 :
1307 case Hexagon::MEMh_ADDr_MEM_V4 :
1308 case Hexagon::MEMh_SUBr_MEM_V4 :
1309 case Hexagon::MEMh_ANDr_MEM_V4 :
1310 case Hexagon::MEMh_ORr_MEM_V4 :
1311 case Hexagon::MEMb_ADDSUBi_indexed_MEM_V4 :
1312 case Hexagon::MEMb_ADDi_indexed_MEM_V4 :
1313 case Hexagon::MEMb_SUBi_indexed_MEM_V4 :
1314 case Hexagon::MEMb_ADDr_indexed_MEM_V4 :
1315 case Hexagon::MEMb_SUBr_indexed_MEM_V4 :
1316 case Hexagon::MEMb_ANDr_indexed_MEM_V4 :
1317 case Hexagon::MEMb_ORr_indexed_MEM_V4 :
1318 case Hexagon::MEMb_ADDSUBi_MEM_V4 :
1319 case Hexagon::MEMb_ADDi_MEM_V4 :
1320 case Hexagon::MEMb_SUBi_MEM_V4 :
1321 case Hexagon::MEMb_ADDr_MEM_V4 :
1322 case Hexagon::MEMb_SUBr_MEM_V4 :
1323 case Hexagon::MEMb_ANDr_MEM_V4 :
1324 case Hexagon::MEMb_ORr_MEM_V4 :
1325 return true;
1326 }
1327 return false;
1328}
1329
1330
1331bool HexagonInstrInfo::
1332isSpillPredRegOp(const MachineInstr *MI) const {
1333 switch (MI->getOpcode())
1334 {
1335 case Hexagon::STriw_pred :
1336 case Hexagon::LDriw_pred :
1337 return true;
1338 }
1339 return false;
1340}
1341
1342
1343bool HexagonInstrInfo::isConditionalALU32 (const MachineInstr* MI) const {
1344 const HexagonRegisterInfo& QRI = getRegisterInfo();
1345 switch (MI->getOpcode())
1346 {
1347 case Hexagon::ADD_ri_cPt:
1348 case Hexagon::ADD_ri_cNotPt:
1349 case Hexagon::ADD_rr_cPt:
1350 case Hexagon::ADD_rr_cNotPt:
1351 case Hexagon::XOR_rr_cPt:
1352 case Hexagon::XOR_rr_cNotPt:
1353 case Hexagon::AND_rr_cPt:
1354 case Hexagon::AND_rr_cNotPt:
1355 case Hexagon::OR_rr_cPt:
1356 case Hexagon::OR_rr_cNotPt:
1357 case Hexagon::SUB_rr_cPt:
1358 case Hexagon::SUB_rr_cNotPt:
1359 case Hexagon::COMBINE_rr_cPt:
1360 case Hexagon::COMBINE_rr_cNotPt:
1361 return true;
1362 case Hexagon::ASLH_cPt_V4:
1363 case Hexagon::ASLH_cNotPt_V4:
1364 case Hexagon::ASRH_cPt_V4:
1365 case Hexagon::ASRH_cNotPt_V4:
1366 case Hexagon::SXTB_cPt_V4:
1367 case Hexagon::SXTB_cNotPt_V4:
1368 case Hexagon::SXTH_cPt_V4:
1369 case Hexagon::SXTH_cNotPt_V4:
1370 case Hexagon::ZXTB_cPt_V4:
1371 case Hexagon::ZXTB_cNotPt_V4:
1372 case Hexagon::ZXTH_cPt_V4:
1373 case Hexagon::ZXTH_cNotPt_V4:
1374 return QRI.Subtarget.getHexagonArchVersion() == HexagonSubtarget::V4;
1375
1376 default:
1377 return false;
1378 }
Tony Linthicumb4b54152011-12-12 21:14:40 +00001379}
1380
1381
1382bool HexagonInstrInfo::
1383isConditionalLoad (const MachineInstr* MI) const {
1384 const HexagonRegisterInfo& QRI = getRegisterInfo();
1385 switch (MI->getOpcode())
1386 {
1387 case Hexagon::LDrid_cPt :
1388 case Hexagon::LDrid_cNotPt :
1389 case Hexagon::LDrid_indexed_cPt :
1390 case Hexagon::LDrid_indexed_cNotPt :
1391 case Hexagon::LDriw_cPt :
1392 case Hexagon::LDriw_cNotPt :
1393 case Hexagon::LDriw_indexed_cPt :
1394 case Hexagon::LDriw_indexed_cNotPt :
1395 case Hexagon::LDrih_cPt :
1396 case Hexagon::LDrih_cNotPt :
1397 case Hexagon::LDrih_indexed_cPt :
1398 case Hexagon::LDrih_indexed_cNotPt :
1399 case Hexagon::LDrib_cPt :
1400 case Hexagon::LDrib_cNotPt :
1401 case Hexagon::LDrib_indexed_cPt :
1402 case Hexagon::LDrib_indexed_cNotPt :
1403 case Hexagon::LDriuh_cPt :
1404 case Hexagon::LDriuh_cNotPt :
1405 case Hexagon::LDriuh_indexed_cPt :
1406 case Hexagon::LDriuh_indexed_cNotPt :
1407 case Hexagon::LDriub_cPt :
1408 case Hexagon::LDriub_cNotPt :
1409 case Hexagon::LDriub_indexed_cPt :
1410 case Hexagon::LDriub_indexed_cNotPt :
1411 return true;
1412 case Hexagon::POST_LDrid_cPt :
1413 case Hexagon::POST_LDrid_cNotPt :
1414 case Hexagon::POST_LDriw_cPt :
1415 case Hexagon::POST_LDriw_cNotPt :
1416 case Hexagon::POST_LDrih_cPt :
1417 case Hexagon::POST_LDrih_cNotPt :
1418 case Hexagon::POST_LDrib_cPt :
1419 case Hexagon::POST_LDrib_cNotPt :
1420 case Hexagon::POST_LDriuh_cPt :
1421 case Hexagon::POST_LDriuh_cNotPt :
1422 case Hexagon::POST_LDriub_cPt :
1423 case Hexagon::POST_LDriub_cNotPt :
1424 return QRI.Subtarget.getHexagonArchVersion() == HexagonSubtarget::V4;
1425 case Hexagon::LDrid_indexed_cPt_V4 :
1426 case Hexagon::LDrid_indexed_cNotPt_V4 :
1427 case Hexagon::LDrid_indexed_shl_cPt_V4 :
1428 case Hexagon::LDrid_indexed_shl_cNotPt_V4 :
1429 case Hexagon::LDrib_indexed_cPt_V4 :
1430 case Hexagon::LDrib_indexed_cNotPt_V4 :
1431 case Hexagon::LDrib_indexed_shl_cPt_V4 :
1432 case Hexagon::LDrib_indexed_shl_cNotPt_V4 :
1433 case Hexagon::LDriub_indexed_cPt_V4 :
1434 case Hexagon::LDriub_indexed_cNotPt_V4 :
1435 case Hexagon::LDriub_indexed_shl_cPt_V4 :
1436 case Hexagon::LDriub_indexed_shl_cNotPt_V4 :
1437 case Hexagon::LDrih_indexed_cPt_V4 :
1438 case Hexagon::LDrih_indexed_cNotPt_V4 :
1439 case Hexagon::LDrih_indexed_shl_cPt_V4 :
1440 case Hexagon::LDrih_indexed_shl_cNotPt_V4 :
1441 case Hexagon::LDriuh_indexed_cPt_V4 :
1442 case Hexagon::LDriuh_indexed_cNotPt_V4 :
1443 case Hexagon::LDriuh_indexed_shl_cPt_V4 :
1444 case Hexagon::LDriuh_indexed_shl_cNotPt_V4 :
1445 case Hexagon::LDriw_indexed_cPt_V4 :
1446 case Hexagon::LDriw_indexed_cNotPt_V4 :
1447 case Hexagon::LDriw_indexed_shl_cPt_V4 :
1448 case Hexagon::LDriw_indexed_shl_cNotPt_V4 :
1449 return QRI.Subtarget.getHexagonArchVersion() == HexagonSubtarget::V4;
1450 default:
1451 return false;
1452 }
Tony Linthicumb4b54152011-12-12 21:14:40 +00001453}
Andrew Trickee498d32012-02-01 22:13:57 +00001454
1455DFAPacketizer *HexagonInstrInfo::
1456CreateTargetScheduleState(const TargetMachine *TM,
1457 const ScheduleDAG *DAG) const {
1458 const InstrItineraryData *II = TM->getInstrItineraryData();
1459 return TM->getSubtarget<HexagonGenSubtargetInfo>().createDFAPacketizer(II);
1460}
1461
1462bool HexagonInstrInfo::isSchedulingBoundary(const MachineInstr *MI,
1463 const MachineBasicBlock *MBB,
1464 const MachineFunction &MF) const {
1465 // Debug info is never a scheduling boundary. It's necessary to be explicit
1466 // due to the special treatment of IT instructions below, otherwise a
1467 // dbg_value followed by an IT will result in the IT instruction being
1468 // considered a scheduling hazard, which is wrong. It should be the actual
1469 // instruction preceding the dbg_value instruction(s), just like it is
1470 // when debug info is not present.
1471 if (MI->isDebugValue())
1472 return false;
1473
1474 // Terminators and labels can't be scheduled around.
1475 if (MI->getDesc().isTerminator() || MI->isLabel() || MI->isInlineAsm())
1476 return true;
1477
1478 return false;
1479}