blob: 6801467b4720c6e5da244d2ca63db6b9aff8993d [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +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
Tony Linthicumb4b54152011-12-12 21:14:40 +000014#include "HexagonInstrInfo.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000015#include "Hexagon.h"
Craig Topper79aa3412012-03-17 18:46:09 +000016#include "HexagonRegisterInfo.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000017#include "HexagonSubtarget.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/MachineFrameInfo.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000022#include "llvm/CodeGen/MachineInstrBuilder.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000023#include "llvm/CodeGen/MachineMemOperand.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000024#include "llvm/CodeGen/MachineRegisterInfo.h"
Tony Linthicumb4b54152011-12-12 21:14:40 +000025#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
Pranav Bhandarkar8aa138c2012-11-01 19:13:23 +000028#define GET_INSTRMAP_INFO
Tony Linthicumb4b54152011-12-12 21:14:40 +000029#include "HexagonGenInstrInfo.inc"
Andrew Trickee498d32012-02-01 22:13:57 +000030#include "HexagonGenDFAPacketizer.inc"
Tony Linthicumb4b54152011-12-12 21:14:40 +000031
Tony Linthicumb4b54152011-12-12 21:14:40 +000032using namespace llvm;
33
34///
35/// Constants for Hexagon instructions.
36///
37const int Hexagon_MEMW_OFFSET_MAX = 4095;
Sirish Pande26f61a12012-05-03 21:52:53 +000038const int Hexagon_MEMW_OFFSET_MIN = -4096;
Tony Linthicumb4b54152011-12-12 21:14:40 +000039const int Hexagon_MEMD_OFFSET_MAX = 8191;
Sirish Pande26f61a12012-05-03 21:52:53 +000040const int Hexagon_MEMD_OFFSET_MIN = -8192;
Tony Linthicumb4b54152011-12-12 21:14:40 +000041const int Hexagon_MEMH_OFFSET_MAX = 2047;
Sirish Pande26f61a12012-05-03 21:52:53 +000042const int Hexagon_MEMH_OFFSET_MIN = -2048;
Tony Linthicumb4b54152011-12-12 21:14:40 +000043const int Hexagon_MEMB_OFFSET_MAX = 1023;
Sirish Pande26f61a12012-05-03 21:52:53 +000044const int Hexagon_MEMB_OFFSET_MIN = -1024;
Tony Linthicumb4b54152011-12-12 21:14:40 +000045const int Hexagon_ADDI_OFFSET_MAX = 32767;
Sirish Pande26f61a12012-05-03 21:52:53 +000046const int Hexagon_ADDI_OFFSET_MIN = -32768;
Tony Linthicumb4b54152011-12-12 21:14:40 +000047const int Hexagon_MEMD_AUTOINC_MAX = 56;
Sirish Pande26f61a12012-05-03 21:52:53 +000048const int Hexagon_MEMD_AUTOINC_MIN = -64;
Tony Linthicumb4b54152011-12-12 21:14:40 +000049const int Hexagon_MEMW_AUTOINC_MAX = 28;
Sirish Pande26f61a12012-05-03 21:52:53 +000050const int Hexagon_MEMW_AUTOINC_MIN = -32;
Tony Linthicumb4b54152011-12-12 21:14:40 +000051const int Hexagon_MEMH_AUTOINC_MAX = 14;
Sirish Pande26f61a12012-05-03 21:52:53 +000052const int Hexagon_MEMH_AUTOINC_MIN = -16;
Tony Linthicumb4b54152011-12-12 21:14:40 +000053const int Hexagon_MEMB_AUTOINC_MAX = 7;
Sirish Pande26f61a12012-05-03 21:52:53 +000054const int Hexagon_MEMB_AUTOINC_MIN = -8;
Tony Linthicumb4b54152011-12-12 21:14:40 +000055
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()) {
Sirish Pande26f61a12012-05-03 21:52:53 +000073 default: break;
Tony Linthicumb4b54152011-12-12 21:14:40 +000074 case Hexagon::LDriw:
75 case Hexagon::LDrid:
76 case Hexagon::LDrih:
77 case Hexagon::LDrib:
78 case Hexagon::LDriub:
79 if (MI->getOperand(2).isFI() &&
80 MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) {
81 FrameIndex = MI->getOperand(2).getIndex();
82 return MI->getOperand(0).getReg();
83 }
84 break;
Tony Linthicumb4b54152011-12-12 21:14:40 +000085 }
Tony Linthicumb4b54152011-12-12 21:14:40 +000086 return 0;
87}
88
89
90/// isStoreToStackSlot - If the specified machine instruction is a direct
91/// store to a stack slot, return the virtual or physical register number of
92/// the source reg along with the FrameIndex of the loaded stack slot. If
93/// not, return 0. This predicate must return 0 if the instruction has
94/// any side effects other than storing to the stack slot.
95unsigned HexagonInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
96 int &FrameIndex) const {
97 switch (MI->getOpcode()) {
Sirish Pande26f61a12012-05-03 21:52:53 +000098 default: break;
Tony Linthicumb4b54152011-12-12 21:14:40 +000099 case Hexagon::STriw:
100 case Hexagon::STrid:
101 case Hexagon::STrih:
102 case Hexagon::STrib:
103 if (MI->getOperand(2).isFI() &&
104 MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) {
Sirish Pande2b38c122012-05-12 05:54:15 +0000105 FrameIndex = MI->getOperand(0).getIndex();
106 return MI->getOperand(2).getReg();
Tony Linthicumb4b54152011-12-12 21:14:40 +0000107 }
108 break;
Tony Linthicumb4b54152011-12-12 21:14:40 +0000109 }
Tony Linthicumb4b54152011-12-12 21:14:40 +0000110 return 0;
111}
112
113
114unsigned
115HexagonInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB,
116 MachineBasicBlock *FBB,
117 const SmallVectorImpl<MachineOperand> &Cond,
118 DebugLoc DL) const{
119
120 int BOpc = Hexagon::JMP;
Sirish Pandeab7955b2012-02-15 18:52:27 +0000121 int BccOpc = Hexagon::JMP_c;
Tony Linthicumb4b54152011-12-12 21:14:40 +0000122
123 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
124
125 int regPos = 0;
126 // Check if ReverseBranchCondition has asked to reverse this branch
127 // If we want to reverse the branch an odd number of times, we want
Sirish Pandeab7955b2012-02-15 18:52:27 +0000128 // JMP_cNot.
Tony Linthicumb4b54152011-12-12 21:14:40 +0000129 if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) {
Sirish Pandeab7955b2012-02-15 18:52:27 +0000130 BccOpc = Hexagon::JMP_cNot;
Tony Linthicumb4b54152011-12-12 21:14:40 +0000131 regPos = 1;
132 }
133
134 if (FBB == 0) {
135 if (Cond.empty()) {
136 // Due to a bug in TailMerging/CFG Optimization, we need to add a
137 // special case handling of a predicated jump followed by an
138 // unconditional jump. If not, Tail Merging and CFG Optimization go
139 // into an infinite loop.
140 MachineBasicBlock *NewTBB, *NewFBB;
141 SmallVector<MachineOperand, 4> Cond;
142 MachineInstr *Term = MBB.getFirstTerminator();
143 if (isPredicated(Term) && !AnalyzeBranch(MBB, NewTBB, NewFBB, Cond,
144 false)) {
145 MachineBasicBlock *NextBB =
146 llvm::next(MachineFunction::iterator(&MBB));
147 if (NewTBB == NextBB) {
148 ReverseBranchCondition(Cond);
149 RemoveBranch(MBB);
150 return InsertBranch(MBB, TBB, 0, Cond, DL);
151 }
152 }
153 BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB);
154 } else {
155 BuildMI(&MBB, DL,
156 get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB);
157 }
158 return 1;
159 }
160
161 BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB);
162 BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB);
163
164 return 2;
165}
166
167
168bool HexagonInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
169 MachineBasicBlock *&TBB,
170 MachineBasicBlock *&FBB,
171 SmallVectorImpl<MachineOperand> &Cond,
172 bool AllowModify) const {
Benjamin Kramer51b49c52012-05-13 15:13:22 +0000173 TBB = NULL;
Tony Linthicumb4b54152011-12-12 21:14:40 +0000174 FBB = NULL;
175
176 // If the block has no terminators, it just falls into the block after it.
177 MachineBasicBlock::iterator I = MBB.end();
178 if (I == MBB.begin())
179 return false;
180
181 // A basic block may looks like this:
182 //
183 // [ insn
184 // EH_LABEL
185 // insn
186 // insn
187 // insn
188 // EH_LABEL
189 // insn ]
190 //
191 // It has two succs but does not have a terminator
192 // Don't know how to handle it.
193 do {
194 --I;
195 if (I->isEHLabel())
196 return true;
197 } while (I != MBB.begin());
198
199 I = MBB.end();
200 --I;
201
202 while (I->isDebugValue()) {
203 if (I == MBB.begin())
204 return false;
205 --I;
206 }
207 if (!isUnpredicatedTerminator(I))
208 return false;
209
210 // Get the last instruction in the block.
211 MachineInstr *LastInst = I;
212
213 // If there is only one terminator instruction, process it.
214 if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
215 if (LastInst->getOpcode() == Hexagon::JMP) {
216 TBB = LastInst->getOperand(0).getMBB();
217 return false;
218 }
Sirish Pandeab7955b2012-02-15 18:52:27 +0000219 if (LastInst->getOpcode() == Hexagon::JMP_c) {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000220 // Block ends with fall-through true condbranch.
221 TBB = LastInst->getOperand(1).getMBB();
222 Cond.push_back(LastInst->getOperand(0));
223 return false;
224 }
Sirish Pandeab7955b2012-02-15 18:52:27 +0000225 if (LastInst->getOpcode() == Hexagon::JMP_cNot) {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000226 // Block ends with fall-through false condbranch.
227 TBB = LastInst->getOperand(1).getMBB();
228 Cond.push_back(MachineOperand::CreateImm(0));
229 Cond.push_back(LastInst->getOperand(0));
230 return false;
231 }
232 // Otherwise, don't know what this is.
233 return true;
234 }
235
236 // Get the instruction before it if it's a terminator.
237 MachineInstr *SecondLastInst = I;
238
239 // If there are three terminators, we don't know what sort of block this is.
240 if (SecondLastInst && I != MBB.begin() &&
241 isUnpredicatedTerminator(--I))
242 return true;
243
244 // If the block ends with Hexagon::BRCOND and Hexagon:JMP, handle it.
245 if (((SecondLastInst->getOpcode() == Hexagon::BRCOND) ||
Sirish Pandeab7955b2012-02-15 18:52:27 +0000246 (SecondLastInst->getOpcode() == Hexagon::JMP_c)) &&
Tony Linthicumb4b54152011-12-12 21:14:40 +0000247 LastInst->getOpcode() == Hexagon::JMP) {
248 TBB = SecondLastInst->getOperand(1).getMBB();
249 Cond.push_back(SecondLastInst->getOperand(0));
250 FBB = LastInst->getOperand(0).getMBB();
251 return false;
252 }
253
Sirish Pandeab7955b2012-02-15 18:52:27 +0000254 // If the block ends with Hexagon::JMP_cNot and Hexagon:JMP, handle it.
255 if ((SecondLastInst->getOpcode() == Hexagon::JMP_cNot) &&
Tony Linthicumb4b54152011-12-12 21:14:40 +0000256 LastInst->getOpcode() == Hexagon::JMP) {
257 TBB = SecondLastInst->getOperand(1).getMBB();
258 Cond.push_back(MachineOperand::CreateImm(0));
259 Cond.push_back(SecondLastInst->getOperand(0));
260 FBB = LastInst->getOperand(0).getMBB();
261 return false;
262 }
263
264 // If the block ends with two Hexagon:JMPs, handle it. The second one is not
265 // executed, so remove it.
266 if (SecondLastInst->getOpcode() == Hexagon::JMP &&
267 LastInst->getOpcode() == Hexagon::JMP) {
268 TBB = SecondLastInst->getOperand(0).getMBB();
269 I = LastInst;
270 if (AllowModify)
271 I->eraseFromParent();
272 return false;
273 }
274
275 // Otherwise, can't handle this.
276 return true;
277}
278
279
280unsigned HexagonInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
281 int BOpc = Hexagon::JMP;
Sirish Pandeab7955b2012-02-15 18:52:27 +0000282 int BccOpc = Hexagon::JMP_c;
283 int BccOpcNot = Hexagon::JMP_cNot;
Tony Linthicumb4b54152011-12-12 21:14:40 +0000284
285 MachineBasicBlock::iterator I = MBB.end();
286 if (I == MBB.begin()) return 0;
287 --I;
288 if (I->getOpcode() != BOpc && I->getOpcode() != BccOpc &&
289 I->getOpcode() != BccOpcNot)
290 return 0;
291
292 // Remove the branch.
293 I->eraseFromParent();
294
295 I = MBB.end();
296
297 if (I == MBB.begin()) return 1;
298 --I;
299 if (I->getOpcode() != BccOpc && I->getOpcode() != BccOpcNot)
300 return 1;
301
302 // Remove the branch.
303 I->eraseFromParent();
304 return 2;
305}
306
307
Krzysztof Parzyszekce55d912013-02-11 20:04:29 +0000308/// \brief For a comparison instruction, return the source registers in
309/// \p SrcReg and \p SrcReg2 if having two register operands, and the value it
310/// compares against in CmpValue. Return true if the comparison instruction
311/// can be analyzed.
312bool HexagonInstrInfo::analyzeCompare(const MachineInstr *MI,
313 unsigned &SrcReg, unsigned &SrcReg2,
314 int &Mask, int &Value) const {
315 unsigned Opc = MI->getOpcode();
316
317 // Set mask and the first source register.
318 switch (Opc) {
319 case Hexagon::CMPEHexagon4rr:
320 case Hexagon::CMPEQri:
321 case Hexagon::CMPEQrr:
322 case Hexagon::CMPGT64rr:
323 case Hexagon::CMPGTU64rr:
324 case Hexagon::CMPGTUri:
325 case Hexagon::CMPGTUrr:
326 case Hexagon::CMPGTri:
327 case Hexagon::CMPGTrr:
328 case Hexagon::CMPLTUrr:
329 case Hexagon::CMPLTrr:
330 SrcReg = MI->getOperand(1).getReg();
331 Mask = ~0;
332 break;
333 case Hexagon::CMPbEQri_V4:
334 case Hexagon::CMPbEQrr_sbsb_V4:
335 case Hexagon::CMPbEQrr_ubub_V4:
336 case Hexagon::CMPbGTUri_V4:
337 case Hexagon::CMPbGTUrr_V4:
338 case Hexagon::CMPbGTrr_V4:
339 SrcReg = MI->getOperand(1).getReg();
340 Mask = 0xFF;
341 break;
342 case Hexagon::CMPhEQri_V4:
343 case Hexagon::CMPhEQrr_shl_V4:
344 case Hexagon::CMPhEQrr_xor_V4:
345 case Hexagon::CMPhGTUri_V4:
346 case Hexagon::CMPhGTUrr_V4:
347 case Hexagon::CMPhGTrr_shl_V4:
348 SrcReg = MI->getOperand(1).getReg();
349 Mask = 0xFFFF;
350 break;
351 }
352
353 // Set the value/second source register.
354 switch (Opc) {
355 case Hexagon::CMPEHexagon4rr:
356 case Hexagon::CMPEQrr:
357 case Hexagon::CMPGT64rr:
358 case Hexagon::CMPGTU64rr:
359 case Hexagon::CMPGTUrr:
360 case Hexagon::CMPGTrr:
361 case Hexagon::CMPbEQrr_sbsb_V4:
362 case Hexagon::CMPbEQrr_ubub_V4:
363 case Hexagon::CMPbGTUrr_V4:
364 case Hexagon::CMPbGTrr_V4:
365 case Hexagon::CMPhEQrr_shl_V4:
366 case Hexagon::CMPhEQrr_xor_V4:
367 case Hexagon::CMPhGTUrr_V4:
368 case Hexagon::CMPhGTrr_shl_V4:
369 case Hexagon::CMPLTUrr:
370 case Hexagon::CMPLTrr:
371 SrcReg2 = MI->getOperand(2).getReg();
372 return true;
373
374 case Hexagon::CMPEQri:
375 case Hexagon::CMPGTUri:
376 case Hexagon::CMPGTri:
377 case Hexagon::CMPbEQri_V4:
378 case Hexagon::CMPbGTUri_V4:
379 case Hexagon::CMPhEQri_V4:
380 case Hexagon::CMPhGTUri_V4:
381 SrcReg2 = 0;
382 Value = MI->getOperand(2).getImm();
383 return true;
384 }
385
386 return false;
387}
388
389
Tony Linthicumb4b54152011-12-12 21:14:40 +0000390void HexagonInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
391 MachineBasicBlock::iterator I, DebugLoc DL,
392 unsigned DestReg, unsigned SrcReg,
393 bool KillSrc) const {
394 if (Hexagon::IntRegsRegClass.contains(SrcReg, DestReg)) {
395 BuildMI(MBB, I, DL, get(Hexagon::TFR), DestReg).addReg(SrcReg);
396 return;
397 }
398 if (Hexagon::DoubleRegsRegClass.contains(SrcReg, DestReg)) {
Jyotsna Vermab53b7912012-11-29 19:35:44 +0000399 BuildMI(MBB, I, DL, get(Hexagon::TFR64), DestReg).addReg(SrcReg);
Tony Linthicumb4b54152011-12-12 21:14:40 +0000400 return;
401 }
402 if (Hexagon::PredRegsRegClass.contains(SrcReg, DestReg)) {
403 // Map Pd = Ps to Pd = or(Ps, Ps).
404 BuildMI(MBB, I, DL, get(Hexagon::OR_pp),
405 DestReg).addReg(SrcReg).addReg(SrcReg);
406 return;
407 }
Sirish Pande2b38c122012-05-12 05:54:15 +0000408 if (Hexagon::DoubleRegsRegClass.contains(DestReg) &&
409 Hexagon::IntRegsRegClass.contains(SrcReg)) {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000410 // We can have an overlap between single and double reg: r1:0 = r0.
411 if(SrcReg == RI.getSubReg(DestReg, Hexagon::subreg_loreg)) {
412 // r1:0 = r0
413 BuildMI(MBB, I, DL, get(Hexagon::TFRI), (RI.getSubReg(DestReg,
414 Hexagon::subreg_hireg))).addImm(0);
415 } else {
416 // r1:0 = r1 or no overlap.
417 BuildMI(MBB, I, DL, get(Hexagon::TFR), (RI.getSubReg(DestReg,
418 Hexagon::subreg_loreg))).addReg(SrcReg);
419 BuildMI(MBB, I, DL, get(Hexagon::TFRI), (RI.getSubReg(DestReg,
420 Hexagon::subreg_hireg))).addImm(0);
421 }
422 return;
423 }
Sirish Pande2b38c122012-05-12 05:54:15 +0000424 if (Hexagon::CRRegsRegClass.contains(DestReg) &&
425 Hexagon::IntRegsRegClass.contains(SrcReg)) {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000426 BuildMI(MBB, I, DL, get(Hexagon::TFCR), DestReg).addReg(SrcReg);
427 return;
Sirish Pandeab7955b2012-02-15 18:52:27 +0000428 }
429
430 llvm_unreachable("Unimplemented");
Tony Linthicumb4b54152011-12-12 21:14:40 +0000431}
432
433
434void HexagonInstrInfo::
435storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
436 unsigned SrcReg, bool isKill, int FI,
437 const TargetRegisterClass *RC,
438 const TargetRegisterInfo *TRI) const {
439
440 DebugLoc DL = MBB.findDebugLoc(I);
441 MachineFunction &MF = *MBB.getParent();
442 MachineFrameInfo &MFI = *MF.getFrameInfo();
443 unsigned Align = MFI.getObjectAlignment(FI);
444
445 MachineMemOperand *MMO =
446 MF.getMachineMemOperand(
447 MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)),
448 MachineMemOperand::MOStore,
449 MFI.getObjectSize(FI),
450 Align);
451
Craig Topper420761a2012-04-20 07:30:17 +0000452 if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) {
Brendon Cahoon5262abb2012-05-14 19:35:42 +0000453 BuildMI(MBB, I, DL, get(Hexagon::STriw))
Tony Linthicumb4b54152011-12-12 21:14:40 +0000454 .addFrameIndex(FI).addImm(0)
455 .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
Craig Topper420761a2012-04-20 07:30:17 +0000456 } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000457 BuildMI(MBB, I, DL, get(Hexagon::STrid))
458 .addFrameIndex(FI).addImm(0)
459 .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
Craig Topper420761a2012-04-20 07:30:17 +0000460 } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000461 BuildMI(MBB, I, DL, get(Hexagon::STriw_pred))
462 .addFrameIndex(FI).addImm(0)
463 .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
464 } else {
Craig Topperbc219812012-02-07 02:50:20 +0000465 llvm_unreachable("Unimplemented");
Tony Linthicumb4b54152011-12-12 21:14:40 +0000466 }
467}
468
469
470void HexagonInstrInfo::storeRegToAddr(
471 MachineFunction &MF, unsigned SrcReg,
472 bool isKill,
473 SmallVectorImpl<MachineOperand> &Addr,
474 const TargetRegisterClass *RC,
475 SmallVectorImpl<MachineInstr*> &NewMIs) const
476{
Craig Topperbc219812012-02-07 02:50:20 +0000477 llvm_unreachable("Unimplemented");
Tony Linthicumb4b54152011-12-12 21:14:40 +0000478}
479
480
481void HexagonInstrInfo::
482loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
483 unsigned DestReg, int FI,
484 const TargetRegisterClass *RC,
485 const TargetRegisterInfo *TRI) const {
486 DebugLoc DL = MBB.findDebugLoc(I);
487 MachineFunction &MF = *MBB.getParent();
488 MachineFrameInfo &MFI = *MF.getFrameInfo();
489 unsigned Align = MFI.getObjectAlignment(FI);
490
491 MachineMemOperand *MMO =
492 MF.getMachineMemOperand(
493 MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)),
494 MachineMemOperand::MOLoad,
495 MFI.getObjectSize(FI),
496 Align);
Craig Topper420761a2012-04-20 07:30:17 +0000497 if (RC == &Hexagon::IntRegsRegClass) {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000498 BuildMI(MBB, I, DL, get(Hexagon::LDriw), DestReg)
499 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
Craig Topper420761a2012-04-20 07:30:17 +0000500 } else if (RC == &Hexagon::DoubleRegsRegClass) {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000501 BuildMI(MBB, I, DL, get(Hexagon::LDrid), DestReg)
502 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
Craig Topper420761a2012-04-20 07:30:17 +0000503 } else if (RC == &Hexagon::PredRegsRegClass) {
Tony Linthicumb4b54152011-12-12 21:14:40 +0000504 BuildMI(MBB, I, DL, get(Hexagon::LDriw_pred), DestReg)
505 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
506 } else {
Craig Topperbc219812012-02-07 02:50:20 +0000507 llvm_unreachable("Can't store this register to stack slot");
Tony Linthicumb4b54152011-12-12 21:14:40 +0000508 }
509}
510
511
512void HexagonInstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
513 SmallVectorImpl<MachineOperand> &Addr,
514 const TargetRegisterClass *RC,
515 SmallVectorImpl<MachineInstr*> &NewMIs) const {
Craig Topperbc219812012-02-07 02:50:20 +0000516 llvm_unreachable("Unimplemented");
Tony Linthicumb4b54152011-12-12 21:14:40 +0000517}
518
519
520MachineInstr *HexagonInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
521 MachineInstr* MI,
522 const SmallVectorImpl<unsigned> &Ops,
523 int FI) const {
524 // Hexagon_TODO: Implement.
525 return(0);
526}
527
528
529unsigned HexagonInstrInfo::createVR(MachineFunction* MF, MVT VT) const {
530
531 MachineRegisterInfo &RegInfo = MF->getRegInfo();
532 const TargetRegisterClass *TRC;
Sirish Pande7517bbc2012-05-10 20:20:25 +0000533 if (VT == MVT::i1) {
Craig Topper420761a2012-04-20 07:30:17 +0000534 TRC = &Hexagon::PredRegsRegClass;
Sirish Pande7517bbc2012-05-10 20:20:25 +0000535 } else if (VT == MVT::i32 || VT == MVT::f32) {
Craig Topper420761a2012-04-20 07:30:17 +0000536 TRC = &Hexagon::IntRegsRegClass;
Sirish Pande7517bbc2012-05-10 20:20:25 +0000537 } else if (VT == MVT::i64 || VT == MVT::f64) {
Craig Topper420761a2012-04-20 07:30:17 +0000538 TRC = &Hexagon::DoubleRegsRegClass;
Sirish Pande7517bbc2012-05-10 20:20:25 +0000539 } else {
Benjamin Kramer27baab62011-12-27 11:41:05 +0000540 llvm_unreachable("Cannot handle this register class");
Sirish Pande7517bbc2012-05-10 20:20:25 +0000541 }
Tony Linthicumb4b54152011-12-12 21:14:40 +0000542
543 unsigned NewReg = RegInfo.createVirtualRegister(TRC);
544 return NewReg;
545}
546
Sirish Pande26f61a12012-05-03 21:52:53 +0000547bool HexagonInstrInfo::isExtendable(const MachineInstr *MI) const {
548 switch(MI->getOpcode()) {
549 default: return false;
550 // JMP_EQri
551 case Hexagon::JMP_EQriPt_nv_V4:
552 case Hexagon::JMP_EQriPnt_nv_V4:
553 case Hexagon::JMP_EQriNotPt_nv_V4:
554 case Hexagon::JMP_EQriNotPnt_nv_V4:
Sirish Pande0dac3912012-04-23 17:49:20 +0000555
Sirish Pande26f61a12012-05-03 21:52:53 +0000556 // JMP_EQri - with -1
557 case Hexagon::JMP_EQriPtneg_nv_V4:
558 case Hexagon::JMP_EQriPntneg_nv_V4:
559 case Hexagon::JMP_EQriNotPtneg_nv_V4:
560 case Hexagon::JMP_EQriNotPntneg_nv_V4:
561
562 // JMP_EQrr
563 case Hexagon::JMP_EQrrPt_nv_V4:
564 case Hexagon::JMP_EQrrPnt_nv_V4:
565 case Hexagon::JMP_EQrrNotPt_nv_V4:
566 case Hexagon::JMP_EQrrNotPnt_nv_V4:
567
568 // JMP_GTri
569 case Hexagon::JMP_GTriPt_nv_V4:
570 case Hexagon::JMP_GTriPnt_nv_V4:
571 case Hexagon::JMP_GTriNotPt_nv_V4:
572 case Hexagon::JMP_GTriNotPnt_nv_V4:
573
574 // JMP_GTri - with -1
575 case Hexagon::JMP_GTriPtneg_nv_V4:
576 case Hexagon::JMP_GTriPntneg_nv_V4:
577 case Hexagon::JMP_GTriNotPtneg_nv_V4:
578 case Hexagon::JMP_GTriNotPntneg_nv_V4:
579
580 // JMP_GTrr
581 case Hexagon::JMP_GTrrPt_nv_V4:
582 case Hexagon::JMP_GTrrPnt_nv_V4:
583 case Hexagon::JMP_GTrrNotPt_nv_V4:
584 case Hexagon::JMP_GTrrNotPnt_nv_V4:
585
586 // JMP_GTrrdn
587 case Hexagon::JMP_GTrrdnPt_nv_V4:
588 case Hexagon::JMP_GTrrdnPnt_nv_V4:
589 case Hexagon::JMP_GTrrdnNotPt_nv_V4:
590 case Hexagon::JMP_GTrrdnNotPnt_nv_V4:
591
592 // JMP_GTUri
593 case Hexagon::JMP_GTUriPt_nv_V4:
594 case Hexagon::JMP_GTUriPnt_nv_V4:
595 case Hexagon::JMP_GTUriNotPt_nv_V4:
596 case Hexagon::JMP_GTUriNotPnt_nv_V4:
597
598 // JMP_GTUrr
599 case Hexagon::JMP_GTUrrPt_nv_V4:
600 case Hexagon::JMP_GTUrrPnt_nv_V4:
601 case Hexagon::JMP_GTUrrNotPt_nv_V4:
602 case Hexagon::JMP_GTUrrNotPnt_nv_V4:
603
604 // JMP_GTUrrdn
605 case Hexagon::JMP_GTUrrdnPt_nv_V4:
606 case Hexagon::JMP_GTUrrdnPnt_nv_V4:
607 case Hexagon::JMP_GTUrrdnNotPt_nv_V4:
608 case Hexagon::JMP_GTUrrdnNotPnt_nv_V4:
609
610 // TFR_FI
611 case Hexagon::TFR_FI:
612 return true;
613 }
614}
615
616bool HexagonInstrInfo::isExtended(const MachineInstr *MI) const {
617 switch(MI->getOpcode()) {
618 default: return false;
619 // JMP_EQri
620 case Hexagon::JMP_EQriPt_ie_nv_V4:
621 case Hexagon::JMP_EQriPnt_ie_nv_V4:
622 case Hexagon::JMP_EQriNotPt_ie_nv_V4:
623 case Hexagon::JMP_EQriNotPnt_ie_nv_V4:
624
625 // JMP_EQri - with -1
626 case Hexagon::JMP_EQriPtneg_ie_nv_V4:
627 case Hexagon::JMP_EQriPntneg_ie_nv_V4:
628 case Hexagon::JMP_EQriNotPtneg_ie_nv_V4:
629 case Hexagon::JMP_EQriNotPntneg_ie_nv_V4:
630
631 // JMP_EQrr
632 case Hexagon::JMP_EQrrPt_ie_nv_V4:
633 case Hexagon::JMP_EQrrPnt_ie_nv_V4:
634 case Hexagon::JMP_EQrrNotPt_ie_nv_V4:
635 case Hexagon::JMP_EQrrNotPnt_ie_nv_V4:
636
637 // JMP_GTri
638 case Hexagon::JMP_GTriPt_ie_nv_V4:
639 case Hexagon::JMP_GTriPnt_ie_nv_V4:
640 case Hexagon::JMP_GTriNotPt_ie_nv_V4:
641 case Hexagon::JMP_GTriNotPnt_ie_nv_V4:
642
643 // JMP_GTri - with -1
644 case Hexagon::JMP_GTriPtneg_ie_nv_V4:
645 case Hexagon::JMP_GTriPntneg_ie_nv_V4:
646 case Hexagon::JMP_GTriNotPtneg_ie_nv_V4:
647 case Hexagon::JMP_GTriNotPntneg_ie_nv_V4:
648
649 // JMP_GTrr
650 case Hexagon::JMP_GTrrPt_ie_nv_V4:
651 case Hexagon::JMP_GTrrPnt_ie_nv_V4:
652 case Hexagon::JMP_GTrrNotPt_ie_nv_V4:
653 case Hexagon::JMP_GTrrNotPnt_ie_nv_V4:
654
655 // JMP_GTrrdn
656 case Hexagon::JMP_GTrrdnPt_ie_nv_V4:
657 case Hexagon::JMP_GTrrdnPnt_ie_nv_V4:
658 case Hexagon::JMP_GTrrdnNotPt_ie_nv_V4:
659 case Hexagon::JMP_GTrrdnNotPnt_ie_nv_V4:
660
661 // JMP_GTUri
662 case Hexagon::JMP_GTUriPt_ie_nv_V4:
663 case Hexagon::JMP_GTUriPnt_ie_nv_V4:
664 case Hexagon::JMP_GTUriNotPt_ie_nv_V4:
665 case Hexagon::JMP_GTUriNotPnt_ie_nv_V4:
666
667 // JMP_GTUrr
668 case Hexagon::JMP_GTUrrPt_ie_nv_V4:
669 case Hexagon::JMP_GTUrrPnt_ie_nv_V4:
670 case Hexagon::JMP_GTUrrNotPt_ie_nv_V4:
671 case Hexagon::JMP_GTUrrNotPnt_ie_nv_V4:
672
673 // JMP_GTUrrdn
674 case Hexagon::JMP_GTUrrdnPt_ie_nv_V4:
675 case Hexagon::JMP_GTUrrdnPnt_ie_nv_V4:
676 case Hexagon::JMP_GTUrrdnNotPt_ie_nv_V4:
677 case Hexagon::JMP_GTUrrdnNotPnt_ie_nv_V4:
678
679 // V4 absolute set addressing.
680 case Hexagon::LDrid_abs_setimm_V4:
681 case Hexagon::LDriw_abs_setimm_V4:
682 case Hexagon::LDrih_abs_setimm_V4:
683 case Hexagon::LDrib_abs_setimm_V4:
684 case Hexagon::LDriuh_abs_setimm_V4:
685 case Hexagon::LDriub_abs_setimm_V4:
686
687 case Hexagon::STrid_abs_setimm_V4:
688 case Hexagon::STrib_abs_setimm_V4:
689 case Hexagon::STrih_abs_setimm_V4:
690 case Hexagon::STriw_abs_setimm_V4:
691
692 // V4 global address load.
Sirish Pande26f61a12012-05-03 21:52:53 +0000693 case Hexagon::LDd_GP_cPt_V4 :
694 case Hexagon::LDd_GP_cNotPt_V4 :
695 case Hexagon::LDd_GP_cdnPt_V4 :
696 case Hexagon::LDd_GP_cdnNotPt_V4 :
697 case Hexagon::LDb_GP_cPt_V4 :
698 case Hexagon::LDb_GP_cNotPt_V4 :
699 case Hexagon::LDb_GP_cdnPt_V4 :
700 case Hexagon::LDb_GP_cdnNotPt_V4 :
701 case Hexagon::LDub_GP_cPt_V4 :
702 case Hexagon::LDub_GP_cNotPt_V4 :
703 case Hexagon::LDub_GP_cdnPt_V4 :
704 case Hexagon::LDub_GP_cdnNotPt_V4 :
705 case Hexagon::LDh_GP_cPt_V4 :
706 case Hexagon::LDh_GP_cNotPt_V4 :
707 case Hexagon::LDh_GP_cdnPt_V4 :
708 case Hexagon::LDh_GP_cdnNotPt_V4 :
709 case Hexagon::LDuh_GP_cPt_V4 :
710 case Hexagon::LDuh_GP_cNotPt_V4 :
711 case Hexagon::LDuh_GP_cdnPt_V4 :
712 case Hexagon::LDuh_GP_cdnNotPt_V4 :
713 case Hexagon::LDw_GP_cPt_V4 :
714 case Hexagon::LDw_GP_cNotPt_V4 :
715 case Hexagon::LDw_GP_cdnPt_V4 :
716 case Hexagon::LDw_GP_cdnNotPt_V4 :
717
718 // V4 global address store.
Sirish Pande26f61a12012-05-03 21:52:53 +0000719 case Hexagon::STd_GP_cPt_V4 :
720 case Hexagon::STd_GP_cNotPt_V4 :
721 case Hexagon::STd_GP_cdnPt_V4 :
722 case Hexagon::STd_GP_cdnNotPt_V4 :
723 case Hexagon::STb_GP_cPt_V4 :
724 case Hexagon::STb_GP_cNotPt_V4 :
725 case Hexagon::STb_GP_cdnPt_V4 :
726 case Hexagon::STb_GP_cdnNotPt_V4 :
727 case Hexagon::STh_GP_cPt_V4 :
728 case Hexagon::STh_GP_cNotPt_V4 :
729 case Hexagon::STh_GP_cdnPt_V4 :
730 case Hexagon::STh_GP_cdnNotPt_V4 :
731 case Hexagon::STw_GP_cPt_V4 :
732 case Hexagon::STw_GP_cNotPt_V4 :
733 case Hexagon::STw_GP_cdnPt_V4 :
734 case Hexagon::STw_GP_cdnNotPt_V4 :
735
736 // V4 predicated global address new value store.
Sirish Pande26f61a12012-05-03 21:52:53 +0000737 case Hexagon::STb_GP_cPt_nv_V4 :
738 case Hexagon::STb_GP_cNotPt_nv_V4 :
739 case Hexagon::STb_GP_cdnPt_nv_V4 :
740 case Hexagon::STb_GP_cdnNotPt_nv_V4 :
741 case Hexagon::STh_GP_cPt_nv_V4 :
742 case Hexagon::STh_GP_cNotPt_nv_V4 :
743 case Hexagon::STh_GP_cdnPt_nv_V4 :
744 case Hexagon::STh_GP_cdnNotPt_nv_V4 :
745 case Hexagon::STw_GP_cPt_nv_V4 :
746 case Hexagon::STw_GP_cNotPt_nv_V4 :
747 case Hexagon::STw_GP_cdnPt_nv_V4 :
748 case Hexagon::STw_GP_cdnNotPt_nv_V4 :
749
750 // TFR_FI
751 case Hexagon::TFR_FI_immext_V4:
Sirish Pande26f61a12012-05-03 21:52:53 +0000752
Sirish Pande7517bbc2012-05-10 20:20:25 +0000753 // TFRI_F
754 case Hexagon::TFRI_f:
755 case Hexagon::TFRI_cPt_f:
756 case Hexagon::TFRI_cNotPt_f:
757 case Hexagon::CONST64_Float_Real:
758 return true;
Sirish Pande26f61a12012-05-03 21:52:53 +0000759 }
760}
761
762bool HexagonInstrInfo::isNewValueJump(const MachineInstr *MI) const {
763 switch (MI->getOpcode()) {
764 default: return false;
765 // JMP_EQri
766 case Hexagon::JMP_EQriPt_nv_V4:
767 case Hexagon::JMP_EQriPnt_nv_V4:
768 case Hexagon::JMP_EQriNotPt_nv_V4:
769 case Hexagon::JMP_EQriNotPnt_nv_V4:
770 case Hexagon::JMP_EQriPt_ie_nv_V4:
771 case Hexagon::JMP_EQriPnt_ie_nv_V4:
772 case Hexagon::JMP_EQriNotPt_ie_nv_V4:
773 case Hexagon::JMP_EQriNotPnt_ie_nv_V4:
774
775 // JMP_EQri - with -1
776 case Hexagon::JMP_EQriPtneg_nv_V4:
777 case Hexagon::JMP_EQriPntneg_nv_V4:
778 case Hexagon::JMP_EQriNotPtneg_nv_V4:
779 case Hexagon::JMP_EQriNotPntneg_nv_V4:
780 case Hexagon::JMP_EQriPtneg_ie_nv_V4:
781 case Hexagon::JMP_EQriPntneg_ie_nv_V4:
782 case Hexagon::JMP_EQriNotPtneg_ie_nv_V4:
783 case Hexagon::JMP_EQriNotPntneg_ie_nv_V4:
784
785 // JMP_EQrr
786 case Hexagon::JMP_EQrrPt_nv_V4:
787 case Hexagon::JMP_EQrrPnt_nv_V4:
788 case Hexagon::JMP_EQrrNotPt_nv_V4:
789 case Hexagon::JMP_EQrrNotPnt_nv_V4:
790 case Hexagon::JMP_EQrrPt_ie_nv_V4:
791 case Hexagon::JMP_EQrrPnt_ie_nv_V4:
792 case Hexagon::JMP_EQrrNotPt_ie_nv_V4:
793 case Hexagon::JMP_EQrrNotPnt_ie_nv_V4:
794
795 // JMP_GTri
796 case Hexagon::JMP_GTriPt_nv_V4:
797 case Hexagon::JMP_GTriPnt_nv_V4:
798 case Hexagon::JMP_GTriNotPt_nv_V4:
799 case Hexagon::JMP_GTriNotPnt_nv_V4:
800 case Hexagon::JMP_GTriPt_ie_nv_V4:
801 case Hexagon::JMP_GTriPnt_ie_nv_V4:
802 case Hexagon::JMP_GTriNotPt_ie_nv_V4:
803 case Hexagon::JMP_GTriNotPnt_ie_nv_V4:
804
805 // JMP_GTri - with -1
806 case Hexagon::JMP_GTriPtneg_nv_V4:
807 case Hexagon::JMP_GTriPntneg_nv_V4:
808 case Hexagon::JMP_GTriNotPtneg_nv_V4:
809 case Hexagon::JMP_GTriNotPntneg_nv_V4:
810 case Hexagon::JMP_GTriPtneg_ie_nv_V4:
811 case Hexagon::JMP_GTriPntneg_ie_nv_V4:
812 case Hexagon::JMP_GTriNotPtneg_ie_nv_V4:
813 case Hexagon::JMP_GTriNotPntneg_ie_nv_V4:
814
815 // JMP_GTrr
816 case Hexagon::JMP_GTrrPt_nv_V4:
817 case Hexagon::JMP_GTrrPnt_nv_V4:
818 case Hexagon::JMP_GTrrNotPt_nv_V4:
819 case Hexagon::JMP_GTrrNotPnt_nv_V4:
820 case Hexagon::JMP_GTrrPt_ie_nv_V4:
821 case Hexagon::JMP_GTrrPnt_ie_nv_V4:
822 case Hexagon::JMP_GTrrNotPt_ie_nv_V4:
823 case Hexagon::JMP_GTrrNotPnt_ie_nv_V4:
824
825 // JMP_GTrrdn
826 case Hexagon::JMP_GTrrdnPt_nv_V4:
827 case Hexagon::JMP_GTrrdnPnt_nv_V4:
828 case Hexagon::JMP_GTrrdnNotPt_nv_V4:
829 case Hexagon::JMP_GTrrdnNotPnt_nv_V4:
830 case Hexagon::JMP_GTrrdnPt_ie_nv_V4:
831 case Hexagon::JMP_GTrrdnPnt_ie_nv_V4:
832 case Hexagon::JMP_GTrrdnNotPt_ie_nv_V4:
833 case Hexagon::JMP_GTrrdnNotPnt_ie_nv_V4:
834
835 // JMP_GTUri
836 case Hexagon::JMP_GTUriPt_nv_V4:
837 case Hexagon::JMP_GTUriPnt_nv_V4:
838 case Hexagon::JMP_GTUriNotPt_nv_V4:
839 case Hexagon::JMP_GTUriNotPnt_nv_V4:
840 case Hexagon::JMP_GTUriPt_ie_nv_V4:
841 case Hexagon::JMP_GTUriPnt_ie_nv_V4:
842 case Hexagon::JMP_GTUriNotPt_ie_nv_V4:
843 case Hexagon::JMP_GTUriNotPnt_ie_nv_V4:
844
845 // JMP_GTUrr
846 case Hexagon::JMP_GTUrrPt_nv_V4:
847 case Hexagon::JMP_GTUrrPnt_nv_V4:
848 case Hexagon::JMP_GTUrrNotPt_nv_V4:
849 case Hexagon::JMP_GTUrrNotPnt_nv_V4:
850 case Hexagon::JMP_GTUrrPt_ie_nv_V4:
851 case Hexagon::JMP_GTUrrPnt_ie_nv_V4:
852 case Hexagon::JMP_GTUrrNotPt_ie_nv_V4:
853 case Hexagon::JMP_GTUrrNotPnt_ie_nv_V4:
854
855 // JMP_GTUrrdn
856 case Hexagon::JMP_GTUrrdnPt_nv_V4:
857 case Hexagon::JMP_GTUrrdnPnt_nv_V4:
858 case Hexagon::JMP_GTUrrdnNotPt_nv_V4:
859 case Hexagon::JMP_GTUrrdnNotPnt_nv_V4:
860 case Hexagon::JMP_GTUrrdnPt_ie_nv_V4:
861 case Hexagon::JMP_GTUrrdnPnt_ie_nv_V4:
862 case Hexagon::JMP_GTUrrdnNotPt_ie_nv_V4:
863 case Hexagon::JMP_GTUrrdnNotPnt_ie_nv_V4:
864 return true;
865 }
866}
867
868unsigned HexagonInstrInfo::getImmExtForm(const MachineInstr* MI) const {
869 switch(MI->getOpcode()) {
870 default: llvm_unreachable("Unknown type of instruction.");
871 // JMP_EQri
872 case Hexagon::JMP_EQriPt_nv_V4:
873 return Hexagon::JMP_EQriPt_ie_nv_V4;
874 case Hexagon::JMP_EQriNotPt_nv_V4:
875 return Hexagon::JMP_EQriNotPt_ie_nv_V4;
876 case Hexagon::JMP_EQriPnt_nv_V4:
877 return Hexagon::JMP_EQriPnt_ie_nv_V4;
878 case Hexagon::JMP_EQriNotPnt_nv_V4:
879 return Hexagon::JMP_EQriNotPnt_ie_nv_V4;
880
881 // JMP_EQri -- with -1
882 case Hexagon::JMP_EQriPtneg_nv_V4:
883 return Hexagon::JMP_EQriPtneg_ie_nv_V4;
884 case Hexagon::JMP_EQriNotPtneg_nv_V4:
885 return Hexagon::JMP_EQriNotPtneg_ie_nv_V4;
886 case Hexagon::JMP_EQriPntneg_nv_V4:
887 return Hexagon::JMP_EQriPntneg_ie_nv_V4;
888 case Hexagon::JMP_EQriNotPntneg_nv_V4:
889 return Hexagon::JMP_EQriNotPntneg_ie_nv_V4;
890
891 // JMP_EQrr
892 case Hexagon::JMP_EQrrPt_nv_V4:
893 return Hexagon::JMP_EQrrPt_ie_nv_V4;
894 case Hexagon::JMP_EQrrNotPt_nv_V4:
895 return Hexagon::JMP_EQrrNotPt_ie_nv_V4;
896 case Hexagon::JMP_EQrrPnt_nv_V4:
897 return Hexagon::JMP_EQrrPnt_ie_nv_V4;
898 case Hexagon::JMP_EQrrNotPnt_nv_V4:
899 return Hexagon::JMP_EQrrNotPnt_ie_nv_V4;
900
901 // JMP_GTri
902 case Hexagon::JMP_GTriPt_nv_V4:
903 return Hexagon::JMP_GTriPt_ie_nv_V4;
904 case Hexagon::JMP_GTriNotPt_nv_V4:
905 return Hexagon::JMP_GTriNotPt_ie_nv_V4;
906 case Hexagon::JMP_GTriPnt_nv_V4:
907 return Hexagon::JMP_GTriPnt_ie_nv_V4;
908 case Hexagon::JMP_GTriNotPnt_nv_V4:
909 return Hexagon::JMP_GTriNotPnt_ie_nv_V4;
910
911 // JMP_GTri -- with -1
912 case Hexagon::JMP_GTriPtneg_nv_V4:
913 return Hexagon::JMP_GTriPtneg_ie_nv_V4;
914 case Hexagon::JMP_GTriNotPtneg_nv_V4:
915 return Hexagon::JMP_GTriNotPtneg_ie_nv_V4;
916 case Hexagon::JMP_GTriPntneg_nv_V4:
917 return Hexagon::JMP_GTriPntneg_ie_nv_V4;
918 case Hexagon::JMP_GTriNotPntneg_nv_V4:
919 return Hexagon::JMP_GTriNotPntneg_ie_nv_V4;
920
921 // JMP_GTrr
922 case Hexagon::JMP_GTrrPt_nv_V4:
923 return Hexagon::JMP_GTrrPt_ie_nv_V4;
924 case Hexagon::JMP_GTrrNotPt_nv_V4:
925 return Hexagon::JMP_GTrrNotPt_ie_nv_V4;
926 case Hexagon::JMP_GTrrPnt_nv_V4:
927 return Hexagon::JMP_GTrrPnt_ie_nv_V4;
928 case Hexagon::JMP_GTrrNotPnt_nv_V4:
929 return Hexagon::JMP_GTrrNotPnt_ie_nv_V4;
930
931 // JMP_GTrrdn
932 case Hexagon::JMP_GTrrdnPt_nv_V4:
933 return Hexagon::JMP_GTrrdnPt_ie_nv_V4;
934 case Hexagon::JMP_GTrrdnNotPt_nv_V4:
935 return Hexagon::JMP_GTrrdnNotPt_ie_nv_V4;
936 case Hexagon::JMP_GTrrdnPnt_nv_V4:
937 return Hexagon::JMP_GTrrdnPnt_ie_nv_V4;
938 case Hexagon::JMP_GTrrdnNotPnt_nv_V4:
939 return Hexagon::JMP_GTrrdnNotPnt_ie_nv_V4;
940
941 // JMP_GTUri
942 case Hexagon::JMP_GTUriPt_nv_V4:
943 return Hexagon::JMP_GTUriPt_ie_nv_V4;
944 case Hexagon::JMP_GTUriNotPt_nv_V4:
945 return Hexagon::JMP_GTUriNotPt_ie_nv_V4;
946 case Hexagon::JMP_GTUriPnt_nv_V4:
947 return Hexagon::JMP_GTUriPnt_ie_nv_V4;
948 case Hexagon::JMP_GTUriNotPnt_nv_V4:
949 return Hexagon::JMP_GTUriNotPnt_ie_nv_V4;
950
951 // JMP_GTUrr
952 case Hexagon::JMP_GTUrrPt_nv_V4:
953 return Hexagon::JMP_GTUrrPt_ie_nv_V4;
954 case Hexagon::JMP_GTUrrNotPt_nv_V4:
955 return Hexagon::JMP_GTUrrNotPt_ie_nv_V4;
956 case Hexagon::JMP_GTUrrPnt_nv_V4:
957 return Hexagon::JMP_GTUrrPnt_ie_nv_V4;
958 case Hexagon::JMP_GTUrrNotPnt_nv_V4:
959 return Hexagon::JMP_GTUrrNotPnt_ie_nv_V4;
960
961 // JMP_GTUrrdn
962 case Hexagon::JMP_GTUrrdnPt_nv_V4:
963 return Hexagon::JMP_GTUrrdnPt_ie_nv_V4;
964 case Hexagon::JMP_GTUrrdnNotPt_nv_V4:
965 return Hexagon::JMP_GTUrrdnNotPt_ie_nv_V4;
966 case Hexagon::JMP_GTUrrdnPnt_nv_V4:
967 return Hexagon::JMP_GTUrrdnPnt_ie_nv_V4;
968 case Hexagon::JMP_GTUrrdnNotPnt_nv_V4:
969 return Hexagon::JMP_GTUrrdnNotPnt_ie_nv_V4;
970
971 case Hexagon::TFR_FI:
972 return Hexagon::TFR_FI_immext_V4;
973
Sirish Pande26f61a12012-05-03 21:52:53 +0000974 case Hexagon::MEMw_ADDi_indexed_MEM_V4 :
975 case Hexagon::MEMw_SUBi_indexed_MEM_V4 :
976 case Hexagon::MEMw_ADDr_indexed_MEM_V4 :
977 case Hexagon::MEMw_SUBr_indexed_MEM_V4 :
978 case Hexagon::MEMw_ANDr_indexed_MEM_V4 :
979 case Hexagon::MEMw_ORr_indexed_MEM_V4 :
Sirish Pande26f61a12012-05-03 21:52:53 +0000980 case Hexagon::MEMw_ADDi_MEM_V4 :
981 case Hexagon::MEMw_SUBi_MEM_V4 :
982 case Hexagon::MEMw_ADDr_MEM_V4 :
983 case Hexagon::MEMw_SUBr_MEM_V4 :
984 case Hexagon::MEMw_ANDr_MEM_V4 :
985 case Hexagon::MEMw_ORr_MEM_V4 :
Sirish Pande26f61a12012-05-03 21:52:53 +0000986 case Hexagon::MEMh_ADDi_indexed_MEM_V4 :
987 case Hexagon::MEMh_SUBi_indexed_MEM_V4 :
988 case Hexagon::MEMh_ADDr_indexed_MEM_V4 :
989 case Hexagon::MEMh_SUBr_indexed_MEM_V4 :
990 case Hexagon::MEMh_ANDr_indexed_MEM_V4 :
991 case Hexagon::MEMh_ORr_indexed_MEM_V4 :
Sirish Pande26f61a12012-05-03 21:52:53 +0000992 case Hexagon::MEMh_ADDi_MEM_V4 :
993 case Hexagon::MEMh_SUBi_MEM_V4 :
994 case Hexagon::MEMh_ADDr_MEM_V4 :
995 case Hexagon::MEMh_SUBr_MEM_V4 :
996 case Hexagon::MEMh_ANDr_MEM_V4 :
997 case Hexagon::MEMh_ORr_MEM_V4 :
Sirish Pande26f61a12012-05-03 21:52:53 +0000998 case Hexagon::MEMb_ADDi_indexed_MEM_V4 :
999 case Hexagon::MEMb_SUBi_indexed_MEM_V4 :
1000 case Hexagon::MEMb_ADDr_indexed_MEM_V4 :
1001 case Hexagon::MEMb_SUBr_indexed_MEM_V4 :
1002 case Hexagon::MEMb_ANDr_indexed_MEM_V4 :
1003 case Hexagon::MEMb_ORr_indexed_MEM_V4 :
Sirish Pande26f61a12012-05-03 21:52:53 +00001004 case Hexagon::MEMb_ADDi_MEM_V4 :
1005 case Hexagon::MEMb_SUBi_MEM_V4 :
1006 case Hexagon::MEMb_ADDr_MEM_V4 :
1007 case Hexagon::MEMb_SUBr_MEM_V4 :
1008 case Hexagon::MEMb_ANDr_MEM_V4 :
1009 case Hexagon::MEMb_ORr_MEM_V4 :
1010 llvm_unreachable("Needs implementing.");
1011 }
1012}
1013
1014unsigned HexagonInstrInfo::getNormalBranchForm(const MachineInstr* MI) const {
1015 switch(MI->getOpcode()) {
1016 default: llvm_unreachable("Unknown type of jump instruction.");
1017 // JMP_EQri
1018 case Hexagon::JMP_EQriPt_ie_nv_V4:
1019 return Hexagon::JMP_EQriPt_nv_V4;
1020 case Hexagon::JMP_EQriNotPt_ie_nv_V4:
1021 return Hexagon::JMP_EQriNotPt_nv_V4;
1022 case Hexagon::JMP_EQriPnt_ie_nv_V4:
1023 return Hexagon::JMP_EQriPnt_nv_V4;
1024 case Hexagon::JMP_EQriNotPnt_ie_nv_V4:
1025 return Hexagon::JMP_EQriNotPnt_nv_V4;
1026
1027 // JMP_EQri -- with -1
1028 case Hexagon::JMP_EQriPtneg_ie_nv_V4:
1029 return Hexagon::JMP_EQriPtneg_nv_V4;
1030 case Hexagon::JMP_EQriNotPtneg_ie_nv_V4:
1031 return Hexagon::JMP_EQriNotPtneg_nv_V4;
1032 case Hexagon::JMP_EQriPntneg_ie_nv_V4:
1033 return Hexagon::JMP_EQriPntneg_nv_V4;
1034 case Hexagon::JMP_EQriNotPntneg_ie_nv_V4:
1035 return Hexagon::JMP_EQriNotPntneg_nv_V4;
1036
1037 // JMP_EQrr
1038 case Hexagon::JMP_EQrrPt_ie_nv_V4:
1039 return Hexagon::JMP_EQrrPt_nv_V4;
1040 case Hexagon::JMP_EQrrNotPt_ie_nv_V4:
1041 return Hexagon::JMP_EQrrNotPt_nv_V4;
1042 case Hexagon::JMP_EQrrPnt_ie_nv_V4:
1043 return Hexagon::JMP_EQrrPnt_nv_V4;
1044 case Hexagon::JMP_EQrrNotPnt_ie_nv_V4:
1045 return Hexagon::JMP_EQrrNotPnt_nv_V4;
1046
1047 // JMP_GTri
1048 case Hexagon::JMP_GTriPt_ie_nv_V4:
1049 return Hexagon::JMP_GTriPt_nv_V4;
1050 case Hexagon::JMP_GTriNotPt_ie_nv_V4:
1051 return Hexagon::JMP_GTriNotPt_nv_V4;
1052 case Hexagon::JMP_GTriPnt_ie_nv_V4:
1053 return Hexagon::JMP_GTriPnt_nv_V4;
1054 case Hexagon::JMP_GTriNotPnt_ie_nv_V4:
1055 return Hexagon::JMP_GTriNotPnt_nv_V4;
1056
1057 // JMP_GTri -- with -1
1058 case Hexagon::JMP_GTriPtneg_ie_nv_V4:
1059 return Hexagon::JMP_GTriPtneg_nv_V4;
1060 case Hexagon::JMP_GTriNotPtneg_ie_nv_V4:
1061 return Hexagon::JMP_GTriNotPtneg_nv_V4;
1062 case Hexagon::JMP_GTriPntneg_ie_nv_V4:
1063 return Hexagon::JMP_GTriPntneg_nv_V4;
1064 case Hexagon::JMP_GTriNotPntneg_ie_nv_V4:
1065 return Hexagon::JMP_GTriNotPntneg_nv_V4;
1066
1067 // JMP_GTrr
1068 case Hexagon::JMP_GTrrPt_ie_nv_V4:
1069 return Hexagon::JMP_GTrrPt_nv_V4;
1070 case Hexagon::JMP_GTrrNotPt_ie_nv_V4:
1071 return Hexagon::JMP_GTrrNotPt_nv_V4;
1072 case Hexagon::JMP_GTrrPnt_ie_nv_V4:
1073 return Hexagon::JMP_GTrrPnt_nv_V4;
1074 case Hexagon::JMP_GTrrNotPnt_ie_nv_V4:
1075 return Hexagon::JMP_GTrrNotPnt_nv_V4;
1076
1077 // JMP_GTrrdn
1078 case Hexagon::JMP_GTrrdnPt_ie_nv_V4:
1079 return Hexagon::JMP_GTrrdnPt_nv_V4;
1080 case Hexagon::JMP_GTrrdnNotPt_ie_nv_V4:
1081 return Hexagon::JMP_GTrrdnNotPt_nv_V4;
1082 case Hexagon::JMP_GTrrdnPnt_ie_nv_V4:
1083 return Hexagon::JMP_GTrrdnPnt_nv_V4;
1084 case Hexagon::JMP_GTrrdnNotPnt_ie_nv_V4:
1085 return Hexagon::JMP_GTrrdnNotPnt_nv_V4;
1086
1087 // JMP_GTUri
1088 case Hexagon::JMP_GTUriPt_ie_nv_V4:
1089 return Hexagon::JMP_GTUriPt_nv_V4;
1090 case Hexagon::JMP_GTUriNotPt_ie_nv_V4:
1091 return Hexagon::JMP_GTUriNotPt_nv_V4;
1092 case Hexagon::JMP_GTUriPnt_ie_nv_V4:
1093 return Hexagon::JMP_GTUriPnt_nv_V4;
1094 case Hexagon::JMP_GTUriNotPnt_ie_nv_V4:
1095 return Hexagon::JMP_GTUriNotPnt_nv_V4;
1096
1097 // JMP_GTUrr
1098 case Hexagon::JMP_GTUrrPt_ie_nv_V4:
1099 return Hexagon::JMP_GTUrrPt_nv_V4;
1100 case Hexagon::JMP_GTUrrNotPt_ie_nv_V4:
1101 return Hexagon::JMP_GTUrrNotPt_nv_V4;
1102 case Hexagon::JMP_GTUrrPnt_ie_nv_V4:
1103 return Hexagon::JMP_GTUrrPnt_nv_V4;
1104 case Hexagon::JMP_GTUrrNotPnt_ie_nv_V4:
1105 return Hexagon::JMP_GTUrrNotPnt_nv_V4;
1106
1107 // JMP_GTUrrdn
1108 case Hexagon::JMP_GTUrrdnPt_ie_nv_V4:
1109 return Hexagon::JMP_GTUrrdnPt_nv_V4;
1110 case Hexagon::JMP_GTUrrdnNotPt_ie_nv_V4:
1111 return Hexagon::JMP_GTUrrdnNotPt_nv_V4;
1112 case Hexagon::JMP_GTUrrdnPnt_ie_nv_V4:
1113 return Hexagon::JMP_GTUrrdnPnt_nv_V4;
1114 case Hexagon::JMP_GTUrrdnNotPnt_ie_nv_V4:
1115 return Hexagon::JMP_GTUrrdnNotPnt_nv_V4;
1116 }
1117}
1118
1119
1120bool HexagonInstrInfo::isNewValueStore(const MachineInstr *MI) const {
1121 switch (MI->getOpcode()) {
1122 default: return false;
1123 // Store Byte
1124 case Hexagon::STrib_nv_V4:
1125 case Hexagon::STrib_indexed_nv_V4:
1126 case Hexagon::STrib_indexed_shl_nv_V4:
1127 case Hexagon::STrib_shl_nv_V4:
Sirish Pande26f61a12012-05-03 21:52:53 +00001128 case Hexagon::STb_GP_nv_V4:
1129 case Hexagon::POST_STbri_nv_V4:
1130 case Hexagon::STrib_cPt_nv_V4:
1131 case Hexagon::STrib_cdnPt_nv_V4:
1132 case Hexagon::STrib_cNotPt_nv_V4:
1133 case Hexagon::STrib_cdnNotPt_nv_V4:
1134 case Hexagon::STrib_indexed_cPt_nv_V4:
1135 case Hexagon::STrib_indexed_cdnPt_nv_V4:
1136 case Hexagon::STrib_indexed_cNotPt_nv_V4:
1137 case Hexagon::STrib_indexed_cdnNotPt_nv_V4:
1138 case Hexagon::STrib_indexed_shl_cPt_nv_V4:
1139 case Hexagon::STrib_indexed_shl_cdnPt_nv_V4:
1140 case Hexagon::STrib_indexed_shl_cNotPt_nv_V4:
1141 case Hexagon::STrib_indexed_shl_cdnNotPt_nv_V4:
1142 case Hexagon::POST_STbri_cPt_nv_V4:
1143 case Hexagon::POST_STbri_cdnPt_nv_V4:
1144 case Hexagon::POST_STbri_cNotPt_nv_V4:
1145 case Hexagon::POST_STbri_cdnNotPt_nv_V4:
1146 case Hexagon::STb_GP_cPt_nv_V4:
1147 case Hexagon::STb_GP_cNotPt_nv_V4:
1148 case Hexagon::STb_GP_cdnPt_nv_V4:
1149 case Hexagon::STb_GP_cdnNotPt_nv_V4:
Sirish Pande26f61a12012-05-03 21:52:53 +00001150 case Hexagon::STrib_abs_nv_V4:
1151 case Hexagon::STrib_abs_cPt_nv_V4:
1152 case Hexagon::STrib_abs_cdnPt_nv_V4:
1153 case Hexagon::STrib_abs_cNotPt_nv_V4:
1154 case Hexagon::STrib_abs_cdnNotPt_nv_V4:
1155 case Hexagon::STrib_imm_abs_nv_V4:
1156 case Hexagon::STrib_imm_abs_cPt_nv_V4:
1157 case Hexagon::STrib_imm_abs_cdnPt_nv_V4:
1158 case Hexagon::STrib_imm_abs_cNotPt_nv_V4:
1159 case Hexagon::STrib_imm_abs_cdnNotPt_nv_V4:
1160
1161 // Store Halfword
1162 case Hexagon::STrih_nv_V4:
1163 case Hexagon::STrih_indexed_nv_V4:
1164 case Hexagon::STrih_indexed_shl_nv_V4:
1165 case Hexagon::STrih_shl_nv_V4:
Sirish Pande26f61a12012-05-03 21:52:53 +00001166 case Hexagon::STh_GP_nv_V4:
1167 case Hexagon::POST_SThri_nv_V4:
1168 case Hexagon::STrih_cPt_nv_V4:
1169 case Hexagon::STrih_cdnPt_nv_V4:
1170 case Hexagon::STrih_cNotPt_nv_V4:
1171 case Hexagon::STrih_cdnNotPt_nv_V4:
1172 case Hexagon::STrih_indexed_cPt_nv_V4:
1173 case Hexagon::STrih_indexed_cdnPt_nv_V4:
1174 case Hexagon::STrih_indexed_cNotPt_nv_V4:
1175 case Hexagon::STrih_indexed_cdnNotPt_nv_V4:
1176 case Hexagon::STrih_indexed_shl_cPt_nv_V4:
1177 case Hexagon::STrih_indexed_shl_cdnPt_nv_V4:
1178 case Hexagon::STrih_indexed_shl_cNotPt_nv_V4:
1179 case Hexagon::STrih_indexed_shl_cdnNotPt_nv_V4:
1180 case Hexagon::POST_SThri_cPt_nv_V4:
1181 case Hexagon::POST_SThri_cdnPt_nv_V4:
1182 case Hexagon::POST_SThri_cNotPt_nv_V4:
1183 case Hexagon::POST_SThri_cdnNotPt_nv_V4:
1184 case Hexagon::STh_GP_cPt_nv_V4:
1185 case Hexagon::STh_GP_cNotPt_nv_V4:
1186 case Hexagon::STh_GP_cdnPt_nv_V4:
1187 case Hexagon::STh_GP_cdnNotPt_nv_V4:
Sirish Pande26f61a12012-05-03 21:52:53 +00001188 case Hexagon::STrih_abs_nv_V4:
1189 case Hexagon::STrih_abs_cPt_nv_V4:
1190 case Hexagon::STrih_abs_cdnPt_nv_V4:
1191 case Hexagon::STrih_abs_cNotPt_nv_V4:
1192 case Hexagon::STrih_abs_cdnNotPt_nv_V4:
1193 case Hexagon::STrih_imm_abs_nv_V4:
1194 case Hexagon::STrih_imm_abs_cPt_nv_V4:
1195 case Hexagon::STrih_imm_abs_cdnPt_nv_V4:
1196 case Hexagon::STrih_imm_abs_cNotPt_nv_V4:
1197 case Hexagon::STrih_imm_abs_cdnNotPt_nv_V4:
1198
1199 // Store Word
1200 case Hexagon::STriw_nv_V4:
1201 case Hexagon::STriw_indexed_nv_V4:
1202 case Hexagon::STriw_indexed_shl_nv_V4:
1203 case Hexagon::STriw_shl_nv_V4:
Sirish Pande26f61a12012-05-03 21:52:53 +00001204 case Hexagon::STw_GP_nv_V4:
1205 case Hexagon::POST_STwri_nv_V4:
1206 case Hexagon::STriw_cPt_nv_V4:
1207 case Hexagon::STriw_cdnPt_nv_V4:
1208 case Hexagon::STriw_cNotPt_nv_V4:
1209 case Hexagon::STriw_cdnNotPt_nv_V4:
1210 case Hexagon::STriw_indexed_cPt_nv_V4:
1211 case Hexagon::STriw_indexed_cdnPt_nv_V4:
1212 case Hexagon::STriw_indexed_cNotPt_nv_V4:
1213 case Hexagon::STriw_indexed_cdnNotPt_nv_V4:
1214 case Hexagon::STriw_indexed_shl_cPt_nv_V4:
1215 case Hexagon::STriw_indexed_shl_cdnPt_nv_V4:
1216 case Hexagon::STriw_indexed_shl_cNotPt_nv_V4:
1217 case Hexagon::STriw_indexed_shl_cdnNotPt_nv_V4:
1218 case Hexagon::POST_STwri_cPt_nv_V4:
1219 case Hexagon::POST_STwri_cdnPt_nv_V4:
1220 case Hexagon::POST_STwri_cNotPt_nv_V4:
1221 case Hexagon::POST_STwri_cdnNotPt_nv_V4:
1222 case Hexagon::STw_GP_cPt_nv_V4:
1223 case Hexagon::STw_GP_cNotPt_nv_V4:
1224 case Hexagon::STw_GP_cdnPt_nv_V4:
1225 case Hexagon::STw_GP_cdnNotPt_nv_V4:
Sirish Pande26f61a12012-05-03 21:52:53 +00001226 case Hexagon::STriw_abs_nv_V4:
1227 case Hexagon::STriw_abs_cPt_nv_V4:
1228 case Hexagon::STriw_abs_cdnPt_nv_V4:
1229 case Hexagon::STriw_abs_cNotPt_nv_V4:
1230 case Hexagon::STriw_abs_cdnNotPt_nv_V4:
1231 case Hexagon::STriw_imm_abs_nv_V4:
1232 case Hexagon::STriw_imm_abs_cPt_nv_V4:
1233 case Hexagon::STriw_imm_abs_cdnPt_nv_V4:
1234 case Hexagon::STriw_imm_abs_cNotPt_nv_V4:
1235 case Hexagon::STriw_imm_abs_cdnNotPt_nv_V4:
1236 return true;
1237 }
1238}
1239
1240bool HexagonInstrInfo::isPostIncrement (const MachineInstr* MI) const {
1241 switch (MI->getOpcode())
1242 {
1243 default: return false;
1244 // Load Byte
1245 case Hexagon::POST_LDrib:
1246 case Hexagon::POST_LDrib_cPt:
1247 case Hexagon::POST_LDrib_cNotPt:
1248 case Hexagon::POST_LDrib_cdnPt_V4:
1249 case Hexagon::POST_LDrib_cdnNotPt_V4:
1250
1251 // Load unsigned byte
1252 case Hexagon::POST_LDriub:
1253 case Hexagon::POST_LDriub_cPt:
1254 case Hexagon::POST_LDriub_cNotPt:
1255 case Hexagon::POST_LDriub_cdnPt_V4:
1256 case Hexagon::POST_LDriub_cdnNotPt_V4:
1257
1258 // Load halfword
1259 case Hexagon::POST_LDrih:
1260 case Hexagon::POST_LDrih_cPt:
1261 case Hexagon::POST_LDrih_cNotPt:
1262 case Hexagon::POST_LDrih_cdnPt_V4:
1263 case Hexagon::POST_LDrih_cdnNotPt_V4:
1264
1265 // Load unsigned halfword
1266 case Hexagon::POST_LDriuh:
1267 case Hexagon::POST_LDriuh_cPt:
1268 case Hexagon::POST_LDriuh_cNotPt:
1269 case Hexagon::POST_LDriuh_cdnPt_V4:
1270 case Hexagon::POST_LDriuh_cdnNotPt_V4:
1271
1272 // Load word
1273 case Hexagon::POST_LDriw:
1274 case Hexagon::POST_LDriw_cPt:
1275 case Hexagon::POST_LDriw_cNotPt:
1276 case Hexagon::POST_LDriw_cdnPt_V4:
1277 case Hexagon::POST_LDriw_cdnNotPt_V4:
1278
1279 // Load double word
1280 case Hexagon::POST_LDrid:
1281 case Hexagon::POST_LDrid_cPt:
1282 case Hexagon::POST_LDrid_cNotPt:
1283 case Hexagon::POST_LDrid_cdnPt_V4:
1284 case Hexagon::POST_LDrid_cdnNotPt_V4:
1285
1286 // Store byte
1287 case Hexagon::POST_STbri:
1288 case Hexagon::POST_STbri_cPt:
1289 case Hexagon::POST_STbri_cNotPt:
1290 case Hexagon::POST_STbri_cdnPt_V4:
1291 case Hexagon::POST_STbri_cdnNotPt_V4:
1292
1293 // Store halfword
1294 case Hexagon::POST_SThri:
1295 case Hexagon::POST_SThri_cPt:
1296 case Hexagon::POST_SThri_cNotPt:
1297 case Hexagon::POST_SThri_cdnPt_V4:
1298 case Hexagon::POST_SThri_cdnNotPt_V4:
1299
1300 // Store word
1301 case Hexagon::POST_STwri:
1302 case Hexagon::POST_STwri_cPt:
1303 case Hexagon::POST_STwri_cNotPt:
1304 case Hexagon::POST_STwri_cdnPt_V4:
1305 case Hexagon::POST_STwri_cdnNotPt_V4:
1306
1307 // Store double word
1308 case Hexagon::POST_STdri:
1309 case Hexagon::POST_STdri_cPt:
1310 case Hexagon::POST_STdri_cNotPt:
1311 case Hexagon::POST_STdri_cdnPt_V4:
1312 case Hexagon::POST_STdri_cdnNotPt_V4:
1313 return true;
1314 }
1315}
1316
1317bool HexagonInstrInfo::isSaveCalleeSavedRegsCall(const MachineInstr *MI) const {
1318 return MI->getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4;
1319}
Andrew Trickee498d32012-02-01 22:13:57 +00001320
Tony Linthicumb4b54152011-12-12 21:14:40 +00001321bool HexagonInstrInfo::isPredicable(MachineInstr *MI) const {
1322 bool isPred = MI->getDesc().isPredicable();
1323
1324 if (!isPred)
1325 return false;
1326
1327 const int Opc = MI->getOpcode();
1328
1329 switch(Opc) {
1330 case Hexagon::TFRI:
Brendon Cahoon5262abb2012-05-14 19:35:42 +00001331 return isInt<12>(MI->getOperand(1).getImm());
Tony Linthicumb4b54152011-12-12 21:14:40 +00001332
1333 case Hexagon::STrid:
1334 case Hexagon::STrid_indexed:
Brendon Cahoon5262abb2012-05-14 19:35:42 +00001335 return isShiftedUInt<6,3>(MI->getOperand(1).getImm());
Tony Linthicumb4b54152011-12-12 21:14:40 +00001336
1337 case Hexagon::STriw:
1338 case Hexagon::STriw_indexed:
1339 case Hexagon::STriw_nv_V4:
Brendon Cahoon5262abb2012-05-14 19:35:42 +00001340 return isShiftedUInt<6,2>(MI->getOperand(1).getImm());
Tony Linthicumb4b54152011-12-12 21:14:40 +00001341
1342 case Hexagon::STrih:
1343 case Hexagon::STrih_indexed:
1344 case Hexagon::STrih_nv_V4:
Brendon Cahoon5262abb2012-05-14 19:35:42 +00001345 return isShiftedUInt<6,1>(MI->getOperand(1).getImm());
Tony Linthicumb4b54152011-12-12 21:14:40 +00001346
1347 case Hexagon::STrib:
1348 case Hexagon::STrib_indexed:
1349 case Hexagon::STrib_nv_V4:
Brendon Cahoon5262abb2012-05-14 19:35:42 +00001350 return isUInt<6>(MI->getOperand(1).getImm());
Tony Linthicumb4b54152011-12-12 21:14:40 +00001351
1352 case Hexagon::LDrid:
1353 case Hexagon::LDrid_indexed:
Brendon Cahoon5262abb2012-05-14 19:35:42 +00001354 return isShiftedUInt<6,3>(MI->getOperand(2).getImm());
Tony Linthicumb4b54152011-12-12 21:14:40 +00001355
1356 case Hexagon::LDriw:
1357 case Hexagon::LDriw_indexed:
Brendon Cahoon5262abb2012-05-14 19:35:42 +00001358 return isShiftedUInt<6,2>(MI->getOperand(2).getImm());
Tony Linthicumb4b54152011-12-12 21:14:40 +00001359
1360 case Hexagon::LDrih:
1361 case Hexagon::LDriuh:
1362 case Hexagon::LDrih_indexed:
1363 case Hexagon::LDriuh_indexed:
Brendon Cahoon5262abb2012-05-14 19:35:42 +00001364 return isShiftedUInt<6,1>(MI->getOperand(2).getImm());
Tony Linthicumb4b54152011-12-12 21:14:40 +00001365
1366 case Hexagon::LDrib:
1367 case Hexagon::LDriub:
1368 case Hexagon::LDrib_indexed:
1369 case Hexagon::LDriub_indexed:
Brendon Cahoon5262abb2012-05-14 19:35:42 +00001370 return isUInt<6>(MI->getOperand(2).getImm());
Tony Linthicumb4b54152011-12-12 21:14:40 +00001371
1372 case Hexagon::POST_LDrid:
Brendon Cahoon5262abb2012-05-14 19:35:42 +00001373 return isShiftedInt<4,3>(MI->getOperand(3).getImm());
Tony Linthicumb4b54152011-12-12 21:14:40 +00001374
1375 case Hexagon::POST_LDriw:
Brendon Cahoon5262abb2012-05-14 19:35:42 +00001376 return isShiftedInt<4,2>(MI->getOperand(3).getImm());
Tony Linthicumb4b54152011-12-12 21:14:40 +00001377
1378 case Hexagon::POST_LDrih:
1379 case Hexagon::POST_LDriuh:
Brendon Cahoon5262abb2012-05-14 19:35:42 +00001380 return isShiftedInt<4,1>(MI->getOperand(3).getImm());
Tony Linthicumb4b54152011-12-12 21:14:40 +00001381
1382 case Hexagon::POST_LDrib:
1383 case Hexagon::POST_LDriub:
Brendon Cahoon5262abb2012-05-14 19:35:42 +00001384 return isInt<4>(MI->getOperand(3).getImm());
Tony Linthicumb4b54152011-12-12 21:14:40 +00001385
1386 case Hexagon::STrib_imm_V4:
1387 case Hexagon::STrih_imm_V4:
1388 case Hexagon::STriw_imm_V4:
Brendon Cahoon5262abb2012-05-14 19:35:42 +00001389 return (isUInt<6>(MI->getOperand(1).getImm()) &&
1390 isInt<6>(MI->getOperand(2).getImm()));
Tony Linthicumb4b54152011-12-12 21:14:40 +00001391
1392 case Hexagon::ADD_ri:
Brendon Cahoon5262abb2012-05-14 19:35:42 +00001393 return isInt<8>(MI->getOperand(2).getImm());
Tony Linthicumb4b54152011-12-12 21:14:40 +00001394
1395 case Hexagon::ASLH:
1396 case Hexagon::ASRH:
1397 case Hexagon::SXTB:
1398 case Hexagon::SXTH:
1399 case Hexagon::ZXTB:
1400 case Hexagon::ZXTH:
Sirish Pande2b38c122012-05-12 05:54:15 +00001401 return Subtarget.hasV4TOps();
Tony Linthicumb4b54152011-12-12 21:14:40 +00001402
1403 case Hexagon::JMPR:
1404 return false;
Tony Linthicumb4b54152011-12-12 21:14:40 +00001405 }
1406
1407 return true;
1408}
1409
Sirish Pande2b38c122012-05-12 05:54:15 +00001410// This function performs the following inversiones:
1411//
1412// cPt ---> cNotPt
1413// cNotPt ---> cPt
1414//
1415// however, these inversiones are NOT included:
1416//
1417// cdnPt -X-> cdnNotPt
1418// cdnNotPt -X-> cdnPt
1419// cPt_nv -X-> cNotPt_nv (new value stores)
1420// cNotPt_nv -X-> cPt_nv (new value stores)
1421//
1422// because only the following transformations are allowed:
1423//
1424// cNotPt ---> cdnNotPt
1425// cPt ---> cdnPt
1426// cNotPt ---> cNotPt_nv
1427// cPt ---> cPt_nv
Sirish Pandeab7955b2012-02-15 18:52:27 +00001428unsigned HexagonInstrInfo::getInvertedPredicatedOpcode(const int Opc) const {
1429 switch(Opc) {
Sirish Pande26f61a12012-05-03 21:52:53 +00001430 default: llvm_unreachable("Unexpected predicated instruction");
Sirish Pandeab7955b2012-02-15 18:52:27 +00001431 case Hexagon::TFR_cPt:
1432 return Hexagon::TFR_cNotPt;
1433 case Hexagon::TFR_cNotPt:
1434 return Hexagon::TFR_cPt;
1435
1436 case Hexagon::TFRI_cPt:
1437 return Hexagon::TFRI_cNotPt;
1438 case Hexagon::TFRI_cNotPt:
1439 return Hexagon::TFRI_cPt;
1440
1441 case Hexagon::JMP_c:
1442 return Hexagon::JMP_cNot;
1443 case Hexagon::JMP_cNot:
1444 return Hexagon::JMP_c;
1445
1446 case Hexagon::ADD_ri_cPt:
1447 return Hexagon::ADD_ri_cNotPt;
1448 case Hexagon::ADD_ri_cNotPt:
1449 return Hexagon::ADD_ri_cPt;
1450
1451 case Hexagon::ADD_rr_cPt:
1452 return Hexagon::ADD_rr_cNotPt;
1453 case Hexagon::ADD_rr_cNotPt:
1454 return Hexagon::ADD_rr_cPt;
1455
1456 case Hexagon::XOR_rr_cPt:
1457 return Hexagon::XOR_rr_cNotPt;
1458 case Hexagon::XOR_rr_cNotPt:
1459 return Hexagon::XOR_rr_cPt;
1460
1461 case Hexagon::AND_rr_cPt:
1462 return Hexagon::AND_rr_cNotPt;
1463 case Hexagon::AND_rr_cNotPt:
1464 return Hexagon::AND_rr_cPt;
1465
1466 case Hexagon::OR_rr_cPt:
1467 return Hexagon::OR_rr_cNotPt;
1468 case Hexagon::OR_rr_cNotPt:
1469 return Hexagon::OR_rr_cPt;
1470
1471 case Hexagon::SUB_rr_cPt:
1472 return Hexagon::SUB_rr_cNotPt;
1473 case Hexagon::SUB_rr_cNotPt:
1474 return Hexagon::SUB_rr_cPt;
1475
1476 case Hexagon::COMBINE_rr_cPt:
1477 return Hexagon::COMBINE_rr_cNotPt;
1478 case Hexagon::COMBINE_rr_cNotPt:
1479 return Hexagon::COMBINE_rr_cPt;
1480
1481 case Hexagon::ASLH_cPt_V4:
1482 return Hexagon::ASLH_cNotPt_V4;
1483 case Hexagon::ASLH_cNotPt_V4:
1484 return Hexagon::ASLH_cPt_V4;
1485
1486 case Hexagon::ASRH_cPt_V4:
1487 return Hexagon::ASRH_cNotPt_V4;
1488 case Hexagon::ASRH_cNotPt_V4:
1489 return Hexagon::ASRH_cPt_V4;
1490
1491 case Hexagon::SXTB_cPt_V4:
1492 return Hexagon::SXTB_cNotPt_V4;
1493 case Hexagon::SXTB_cNotPt_V4:
1494 return Hexagon::SXTB_cPt_V4;
1495
1496 case Hexagon::SXTH_cPt_V4:
1497 return Hexagon::SXTH_cNotPt_V4;
1498 case Hexagon::SXTH_cNotPt_V4:
1499 return Hexagon::SXTH_cPt_V4;
1500
1501 case Hexagon::ZXTB_cPt_V4:
1502 return Hexagon::ZXTB_cNotPt_V4;
1503 case Hexagon::ZXTB_cNotPt_V4:
1504 return Hexagon::ZXTB_cPt_V4;
1505
1506 case Hexagon::ZXTH_cPt_V4:
1507 return Hexagon::ZXTH_cNotPt_V4;
1508 case Hexagon::ZXTH_cNotPt_V4:
1509 return Hexagon::ZXTH_cPt_V4;
1510
1511
1512 case Hexagon::JMPR_cPt:
1513 return Hexagon::JMPR_cNotPt;
1514 case Hexagon::JMPR_cNotPt:
1515 return Hexagon::JMPR_cPt;
1516
1517 // V4 indexed+scaled load.
Sirish Pandeab7955b2012-02-15 18:52:27 +00001518 case Hexagon::LDrid_indexed_shl_cPt_V4:
1519 return Hexagon::LDrid_indexed_shl_cNotPt_V4;
1520 case Hexagon::LDrid_indexed_shl_cNotPt_V4:
1521 return Hexagon::LDrid_indexed_shl_cPt_V4;
1522
Sirish Pandeab7955b2012-02-15 18:52:27 +00001523 case Hexagon::LDrib_indexed_shl_cPt_V4:
1524 return Hexagon::LDrib_indexed_shl_cNotPt_V4;
1525 case Hexagon::LDrib_indexed_shl_cNotPt_V4:
1526 return Hexagon::LDrib_indexed_shl_cPt_V4;
1527
1528 case Hexagon::LDriub_indexed_shl_cPt_V4:
1529 return Hexagon::LDriub_indexed_shl_cNotPt_V4;
1530 case Hexagon::LDriub_indexed_shl_cNotPt_V4:
1531 return Hexagon::LDriub_indexed_shl_cPt_V4;
1532
Sirish Pandeab7955b2012-02-15 18:52:27 +00001533 case Hexagon::LDrih_indexed_shl_cPt_V4:
1534 return Hexagon::LDrih_indexed_shl_cNotPt_V4;
1535 case Hexagon::LDrih_indexed_shl_cNotPt_V4:
1536 return Hexagon::LDrih_indexed_shl_cPt_V4;
1537
1538 case Hexagon::LDriuh_indexed_shl_cPt_V4:
1539 return Hexagon::LDriuh_indexed_shl_cNotPt_V4;
1540 case Hexagon::LDriuh_indexed_shl_cNotPt_V4:
1541 return Hexagon::LDriuh_indexed_shl_cPt_V4;
1542
Sirish Pandeab7955b2012-02-15 18:52:27 +00001543 case Hexagon::LDriw_indexed_shl_cPt_V4:
1544 return Hexagon::LDriw_indexed_shl_cNotPt_V4;
1545 case Hexagon::LDriw_indexed_shl_cNotPt_V4:
1546 return Hexagon::LDriw_indexed_shl_cPt_V4;
1547
1548 // Byte.
1549 case Hexagon::POST_STbri_cPt:
1550 return Hexagon::POST_STbri_cNotPt;
1551 case Hexagon::POST_STbri_cNotPt:
1552 return Hexagon::POST_STbri_cPt;
1553
1554 case Hexagon::STrib_cPt:
1555 return Hexagon::STrib_cNotPt;
1556 case Hexagon::STrib_cNotPt:
1557 return Hexagon::STrib_cPt;
1558
1559 case Hexagon::STrib_indexed_cPt:
1560 return Hexagon::STrib_indexed_cNotPt;
1561 case Hexagon::STrib_indexed_cNotPt:
1562 return Hexagon::STrib_indexed_cPt;
1563
1564 case Hexagon::STrib_imm_cPt_V4:
1565 return Hexagon::STrib_imm_cNotPt_V4;
1566 case Hexagon::STrib_imm_cNotPt_V4:
1567 return Hexagon::STrib_imm_cPt_V4;
1568
1569 case Hexagon::STrib_indexed_shl_cPt_V4:
1570 return Hexagon::STrib_indexed_shl_cNotPt_V4;
1571 case Hexagon::STrib_indexed_shl_cNotPt_V4:
1572 return Hexagon::STrib_indexed_shl_cPt_V4;
1573
1574 // Halfword.
1575 case Hexagon::POST_SThri_cPt:
1576 return Hexagon::POST_SThri_cNotPt;
1577 case Hexagon::POST_SThri_cNotPt:
1578 return Hexagon::POST_SThri_cPt;
1579
1580 case Hexagon::STrih_cPt:
1581 return Hexagon::STrih_cNotPt;
1582 case Hexagon::STrih_cNotPt:
1583 return Hexagon::STrih_cPt;
1584
1585 case Hexagon::STrih_indexed_cPt:
1586 return Hexagon::STrih_indexed_cNotPt;
1587 case Hexagon::STrih_indexed_cNotPt:
1588 return Hexagon::STrih_indexed_cPt;
1589
1590 case Hexagon::STrih_imm_cPt_V4:
1591 return Hexagon::STrih_imm_cNotPt_V4;
1592 case Hexagon::STrih_imm_cNotPt_V4:
1593 return Hexagon::STrih_imm_cPt_V4;
1594
1595 case Hexagon::STrih_indexed_shl_cPt_V4:
1596 return Hexagon::STrih_indexed_shl_cNotPt_V4;
1597 case Hexagon::STrih_indexed_shl_cNotPt_V4:
1598 return Hexagon::STrih_indexed_shl_cPt_V4;
1599
1600 // Word.
1601 case Hexagon::POST_STwri_cPt:
1602 return Hexagon::POST_STwri_cNotPt;
1603 case Hexagon::POST_STwri_cNotPt:
1604 return Hexagon::POST_STwri_cPt;
1605
1606 case Hexagon::STriw_cPt:
1607 return Hexagon::STriw_cNotPt;
1608 case Hexagon::STriw_cNotPt:
1609 return Hexagon::STriw_cPt;
1610
1611 case Hexagon::STriw_indexed_cPt:
1612 return Hexagon::STriw_indexed_cNotPt;
1613 case Hexagon::STriw_indexed_cNotPt:
1614 return Hexagon::STriw_indexed_cPt;
1615
1616 case Hexagon::STriw_indexed_shl_cPt_V4:
1617 return Hexagon::STriw_indexed_shl_cNotPt_V4;
1618 case Hexagon::STriw_indexed_shl_cNotPt_V4:
1619 return Hexagon::STriw_indexed_shl_cPt_V4;
1620
1621 case Hexagon::STriw_imm_cPt_V4:
1622 return Hexagon::STriw_imm_cNotPt_V4;
1623 case Hexagon::STriw_imm_cNotPt_V4:
1624 return Hexagon::STriw_imm_cPt_V4;
1625
1626 // Double word.
1627 case Hexagon::POST_STdri_cPt:
1628 return Hexagon::POST_STdri_cNotPt;
1629 case Hexagon::POST_STdri_cNotPt:
1630 return Hexagon::POST_STdri_cPt;
1631
1632 case Hexagon::STrid_cPt:
1633 return Hexagon::STrid_cNotPt;
1634 case Hexagon::STrid_cNotPt:
1635 return Hexagon::STrid_cPt;
1636
1637 case Hexagon::STrid_indexed_cPt:
1638 return Hexagon::STrid_indexed_cNotPt;
1639 case Hexagon::STrid_indexed_cNotPt:
1640 return Hexagon::STrid_indexed_cPt;
1641
1642 case Hexagon::STrid_indexed_shl_cPt_V4:
1643 return Hexagon::STrid_indexed_shl_cNotPt_V4;
1644 case Hexagon::STrid_indexed_shl_cNotPt_V4:
1645 return Hexagon::STrid_indexed_shl_cPt_V4;
1646
Sirish Pande26f61a12012-05-03 21:52:53 +00001647 // V4 Store to global address.
1648 case Hexagon::STd_GP_cPt_V4:
1649 return Hexagon::STd_GP_cNotPt_V4;
1650 case Hexagon::STd_GP_cNotPt_V4:
1651 return Hexagon::STd_GP_cPt_V4;
1652
1653 case Hexagon::STb_GP_cPt_V4:
1654 return Hexagon::STb_GP_cNotPt_V4;
1655 case Hexagon::STb_GP_cNotPt_V4:
1656 return Hexagon::STb_GP_cPt_V4;
1657
1658 case Hexagon::STh_GP_cPt_V4:
1659 return Hexagon::STh_GP_cNotPt_V4;
1660 case Hexagon::STh_GP_cNotPt_V4:
1661 return Hexagon::STh_GP_cPt_V4;
1662
1663 case Hexagon::STw_GP_cPt_V4:
1664 return Hexagon::STw_GP_cNotPt_V4;
1665 case Hexagon::STw_GP_cNotPt_V4:
1666 return Hexagon::STw_GP_cPt_V4;
1667
Sirish Pandeab7955b2012-02-15 18:52:27 +00001668 // Load.
1669 case Hexagon::LDrid_cPt:
1670 return Hexagon::LDrid_cNotPt;
1671 case Hexagon::LDrid_cNotPt:
1672 return Hexagon::LDrid_cPt;
1673
1674 case Hexagon::LDriw_cPt:
1675 return Hexagon::LDriw_cNotPt;
1676 case Hexagon::LDriw_cNotPt:
1677 return Hexagon::LDriw_cPt;
1678
1679 case Hexagon::LDrih_cPt:
1680 return Hexagon::LDrih_cNotPt;
1681 case Hexagon::LDrih_cNotPt:
1682 return Hexagon::LDrih_cPt;
1683
1684 case Hexagon::LDriuh_cPt:
1685 return Hexagon::LDriuh_cNotPt;
1686 case Hexagon::LDriuh_cNotPt:
1687 return Hexagon::LDriuh_cPt;
1688
1689 case Hexagon::LDrib_cPt:
1690 return Hexagon::LDrib_cNotPt;
1691 case Hexagon::LDrib_cNotPt:
1692 return Hexagon::LDrib_cPt;
1693
1694 case Hexagon::LDriub_cPt:
1695 return Hexagon::LDriub_cNotPt;
1696 case Hexagon::LDriub_cNotPt:
1697 return Hexagon::LDriub_cPt;
1698
1699 // Load Indexed.
1700 case Hexagon::LDrid_indexed_cPt:
1701 return Hexagon::LDrid_indexed_cNotPt;
1702 case Hexagon::LDrid_indexed_cNotPt:
1703 return Hexagon::LDrid_indexed_cPt;
1704
1705 case Hexagon::LDriw_indexed_cPt:
1706 return Hexagon::LDriw_indexed_cNotPt;
1707 case Hexagon::LDriw_indexed_cNotPt:
1708 return Hexagon::LDriw_indexed_cPt;
1709
1710 case Hexagon::LDrih_indexed_cPt:
1711 return Hexagon::LDrih_indexed_cNotPt;
1712 case Hexagon::LDrih_indexed_cNotPt:
1713 return Hexagon::LDrih_indexed_cPt;
1714
1715 case Hexagon::LDriuh_indexed_cPt:
1716 return Hexagon::LDriuh_indexed_cNotPt;
1717 case Hexagon::LDriuh_indexed_cNotPt:
1718 return Hexagon::LDriuh_indexed_cPt;
1719
1720 case Hexagon::LDrib_indexed_cPt:
1721 return Hexagon::LDrib_indexed_cNotPt;
1722 case Hexagon::LDrib_indexed_cNotPt:
1723 return Hexagon::LDrib_indexed_cPt;
1724
1725 case Hexagon::LDriub_indexed_cPt:
1726 return Hexagon::LDriub_indexed_cNotPt;
1727 case Hexagon::LDriub_indexed_cNotPt:
1728 return Hexagon::LDriub_indexed_cPt;
1729
1730 // Post Inc Load.
1731 case Hexagon::POST_LDrid_cPt:
1732 return Hexagon::POST_LDrid_cNotPt;
1733 case Hexagon::POST_LDriw_cNotPt:
1734 return Hexagon::POST_LDriw_cPt;
1735
1736 case Hexagon::POST_LDrih_cPt:
1737 return Hexagon::POST_LDrih_cNotPt;
1738 case Hexagon::POST_LDrih_cNotPt:
1739 return Hexagon::POST_LDrih_cPt;
1740
1741 case Hexagon::POST_LDriuh_cPt:
1742 return Hexagon::POST_LDriuh_cNotPt;
1743 case Hexagon::POST_LDriuh_cNotPt:
1744 return Hexagon::POST_LDriuh_cPt;
1745
1746 case Hexagon::POST_LDrib_cPt:
1747 return Hexagon::POST_LDrib_cNotPt;
1748 case Hexagon::POST_LDrib_cNotPt:
1749 return Hexagon::POST_LDrib_cPt;
1750
1751 case Hexagon::POST_LDriub_cPt:
1752 return Hexagon::POST_LDriub_cNotPt;
1753 case Hexagon::POST_LDriub_cNotPt:
1754 return Hexagon::POST_LDriub_cPt;
1755
1756 // Dealloc_return.
1757 case Hexagon::DEALLOC_RET_cPt_V4:
1758 return Hexagon::DEALLOC_RET_cNotPt_V4;
1759 case Hexagon::DEALLOC_RET_cNotPt_V4:
1760 return Hexagon::DEALLOC_RET_cPt_V4;
1761
1762 // New Value Jump.
1763 // JMPEQ_ri - with -1.
1764 case Hexagon::JMP_EQriPtneg_nv_V4:
1765 return Hexagon::JMP_EQriNotPtneg_nv_V4;
1766 case Hexagon::JMP_EQriNotPtneg_nv_V4:
1767 return Hexagon::JMP_EQriPtneg_nv_V4;
1768
1769 case Hexagon::JMP_EQriPntneg_nv_V4:
1770 return Hexagon::JMP_EQriNotPntneg_nv_V4;
1771 case Hexagon::JMP_EQriNotPntneg_nv_V4:
1772 return Hexagon::JMP_EQriPntneg_nv_V4;
1773
1774 // JMPEQ_ri.
1775 case Hexagon::JMP_EQriPt_nv_V4:
1776 return Hexagon::JMP_EQriNotPt_nv_V4;
1777 case Hexagon::JMP_EQriNotPt_nv_V4:
1778 return Hexagon::JMP_EQriPt_nv_V4;
1779
1780 case Hexagon::JMP_EQriPnt_nv_V4:
1781 return Hexagon::JMP_EQriNotPnt_nv_V4;
1782 case Hexagon::JMP_EQriNotPnt_nv_V4:
1783 return Hexagon::JMP_EQriPnt_nv_V4;
1784
1785 // JMPEQ_rr.
1786 case Hexagon::JMP_EQrrPt_nv_V4:
1787 return Hexagon::JMP_EQrrNotPt_nv_V4;
1788 case Hexagon::JMP_EQrrNotPt_nv_V4:
1789 return Hexagon::JMP_EQrrPt_nv_V4;
1790
1791 case Hexagon::JMP_EQrrPnt_nv_V4:
1792 return Hexagon::JMP_EQrrNotPnt_nv_V4;
1793 case Hexagon::JMP_EQrrNotPnt_nv_V4:
1794 return Hexagon::JMP_EQrrPnt_nv_V4;
1795
1796 // JMPGT_ri - with -1.
1797 case Hexagon::JMP_GTriPtneg_nv_V4:
1798 return Hexagon::JMP_GTriNotPtneg_nv_V4;
1799 case Hexagon::JMP_GTriNotPtneg_nv_V4:
1800 return Hexagon::JMP_GTriPtneg_nv_V4;
1801
1802 case Hexagon::JMP_GTriPntneg_nv_V4:
1803 return Hexagon::JMP_GTriNotPntneg_nv_V4;
1804 case Hexagon::JMP_GTriNotPntneg_nv_V4:
1805 return Hexagon::JMP_GTriPntneg_nv_V4;
1806
1807 // JMPGT_ri.
1808 case Hexagon::JMP_GTriPt_nv_V4:
1809 return Hexagon::JMP_GTriNotPt_nv_V4;
1810 case Hexagon::JMP_GTriNotPt_nv_V4:
1811 return Hexagon::JMP_GTriPt_nv_V4;
1812
1813 case Hexagon::JMP_GTriPnt_nv_V4:
1814 return Hexagon::JMP_GTriNotPnt_nv_V4;
1815 case Hexagon::JMP_GTriNotPnt_nv_V4:
1816 return Hexagon::JMP_GTriPnt_nv_V4;
1817
1818 // JMPGT_rr.
1819 case Hexagon::JMP_GTrrPt_nv_V4:
1820 return Hexagon::JMP_GTrrNotPt_nv_V4;
1821 case Hexagon::JMP_GTrrNotPt_nv_V4:
1822 return Hexagon::JMP_GTrrPt_nv_V4;
1823
1824 case Hexagon::JMP_GTrrPnt_nv_V4:
1825 return Hexagon::JMP_GTrrNotPnt_nv_V4;
1826 case Hexagon::JMP_GTrrNotPnt_nv_V4:
1827 return Hexagon::JMP_GTrrPnt_nv_V4;
1828
1829 // JMPGT_rrdn.
1830 case Hexagon::JMP_GTrrdnPt_nv_V4:
1831 return Hexagon::JMP_GTrrdnNotPt_nv_V4;
1832 case Hexagon::JMP_GTrrdnNotPt_nv_V4:
1833 return Hexagon::JMP_GTrrdnPt_nv_V4;
1834
1835 case Hexagon::JMP_GTrrdnPnt_nv_V4:
1836 return Hexagon::JMP_GTrrdnNotPnt_nv_V4;
1837 case Hexagon::JMP_GTrrdnNotPnt_nv_V4:
1838 return Hexagon::JMP_GTrrdnPnt_nv_V4;
1839
1840 // JMPGTU_ri.
1841 case Hexagon::JMP_GTUriPt_nv_V4:
1842 return Hexagon::JMP_GTUriNotPt_nv_V4;
1843 case Hexagon::JMP_GTUriNotPt_nv_V4:
1844 return Hexagon::JMP_GTUriPt_nv_V4;
1845
1846 case Hexagon::JMP_GTUriPnt_nv_V4:
1847 return Hexagon::JMP_GTUriNotPnt_nv_V4;
1848 case Hexagon::JMP_GTUriNotPnt_nv_V4:
1849 return Hexagon::JMP_GTUriPnt_nv_V4;
1850
1851 // JMPGTU_rr.
1852 case Hexagon::JMP_GTUrrPt_nv_V4:
1853 return Hexagon::JMP_GTUrrNotPt_nv_V4;
1854 case Hexagon::JMP_GTUrrNotPt_nv_V4:
1855 return Hexagon::JMP_GTUrrPt_nv_V4;
1856
1857 case Hexagon::JMP_GTUrrPnt_nv_V4:
1858 return Hexagon::JMP_GTUrrNotPnt_nv_V4;
1859 case Hexagon::JMP_GTUrrNotPnt_nv_V4:
1860 return Hexagon::JMP_GTUrrPnt_nv_V4;
1861
1862 // JMPGTU_rrdn.
1863 case Hexagon::JMP_GTUrrdnPt_nv_V4:
1864 return Hexagon::JMP_GTUrrdnNotPt_nv_V4;
1865 case Hexagon::JMP_GTUrrdnNotPt_nv_V4:
1866 return Hexagon::JMP_GTUrrdnPt_nv_V4;
1867
1868 case Hexagon::JMP_GTUrrdnPnt_nv_V4:
1869 return Hexagon::JMP_GTUrrdnNotPnt_nv_V4;
1870 case Hexagon::JMP_GTUrrdnNotPnt_nv_V4:
1871 return Hexagon::JMP_GTUrrdnPnt_nv_V4;
Sirish Pandeab7955b2012-02-15 18:52:27 +00001872 }
1873}
Tony Linthicumb4b54152011-12-12 21:14:40 +00001874
Andrew Trickee498d32012-02-01 22:13:57 +00001875
Tony Linthicumb4b54152011-12-12 21:14:40 +00001876int HexagonInstrInfo::
1877getMatchingCondBranchOpcode(int Opc, bool invertPredicate) const {
Pranav Bhandarkar8aa138c2012-11-01 19:13:23 +00001878 enum Hexagon::PredSense inPredSense;
1879 inPredSense = invertPredicate ? Hexagon::PredSense_false :
1880 Hexagon::PredSense_true;
1881 int CondOpcode = Hexagon::getPredOpcode(Opc, inPredSense);
1882 if (CondOpcode >= 0) // Valid Conditional opcode/instruction
1883 return CondOpcode;
1884
1885 // This switch case will be removed once all the instructions have been
1886 // modified to use relation maps.
Tony Linthicumb4b54152011-12-12 21:14:40 +00001887 switch(Opc) {
1888 case Hexagon::TFR:
1889 return !invertPredicate ? Hexagon::TFR_cPt :
1890 Hexagon::TFR_cNotPt;
Sirish Pande7517bbc2012-05-10 20:20:25 +00001891 case Hexagon::TFRI_f:
1892 return !invertPredicate ? Hexagon::TFRI_cPt_f :
1893 Hexagon::TFRI_cNotPt_f;
Tony Linthicumb4b54152011-12-12 21:14:40 +00001894 case Hexagon::TFRI:
1895 return !invertPredicate ? Hexagon::TFRI_cPt :
1896 Hexagon::TFRI_cNotPt;
1897 case Hexagon::JMP:
Sirish Pandeab7955b2012-02-15 18:52:27 +00001898 return !invertPredicate ? Hexagon::JMP_c :
1899 Hexagon::JMP_cNot;
Sirish Pandeb3385702012-05-12 05:10:30 +00001900 case Hexagon::JMP_EQrrPt_nv_V4:
1901 return !invertPredicate ? Hexagon::JMP_EQrrPt_nv_V4 :
1902 Hexagon::JMP_EQrrNotPt_nv_V4;
1903 case Hexagon::JMP_EQriPt_nv_V4:
1904 return !invertPredicate ? Hexagon::JMP_EQriPt_nv_V4 :
1905 Hexagon::JMP_EQriNotPt_nv_V4;
Tony Linthicumb4b54152011-12-12 21:14:40 +00001906 case Hexagon::COMBINE_rr:
1907 return !invertPredicate ? Hexagon::COMBINE_rr_cPt :
1908 Hexagon::COMBINE_rr_cNotPt;
1909 case Hexagon::ASLH:
1910 return !invertPredicate ? Hexagon::ASLH_cPt_V4 :
1911 Hexagon::ASLH_cNotPt_V4;
1912 case Hexagon::ASRH:
1913 return !invertPredicate ? Hexagon::ASRH_cPt_V4 :
1914 Hexagon::ASRH_cNotPt_V4;
1915 case Hexagon::SXTB:
1916 return !invertPredicate ? Hexagon::SXTB_cPt_V4 :
1917 Hexagon::SXTB_cNotPt_V4;
1918 case Hexagon::SXTH:
1919 return !invertPredicate ? Hexagon::SXTH_cPt_V4 :
1920 Hexagon::SXTH_cNotPt_V4;
1921 case Hexagon::ZXTB:
1922 return !invertPredicate ? Hexagon::ZXTB_cPt_V4 :
1923 Hexagon::ZXTB_cNotPt_V4;
1924 case Hexagon::ZXTH:
1925 return !invertPredicate ? Hexagon::ZXTH_cPt_V4 :
1926 Hexagon::ZXTH_cNotPt_V4;
1927
1928 case Hexagon::JMPR:
1929 return !invertPredicate ? Hexagon::JMPR_cPt :
1930 Hexagon::JMPR_cNotPt;
1931
1932 // V4 indexed+scaled load.
Tony Linthicumb4b54152011-12-12 21:14:40 +00001933 case Hexagon::LDrid_indexed_shl_V4:
1934 return !invertPredicate ? Hexagon::LDrid_indexed_shl_cPt_V4 :
1935 Hexagon::LDrid_indexed_shl_cNotPt_V4;
Tony Linthicumb4b54152011-12-12 21:14:40 +00001936 case Hexagon::LDrib_indexed_shl_V4:
1937 return !invertPredicate ? Hexagon::LDrib_indexed_shl_cPt_V4 :
1938 Hexagon::LDrib_indexed_shl_cNotPt_V4;
1939 case Hexagon::LDriub_indexed_shl_V4:
1940 return !invertPredicate ? Hexagon::LDriub_indexed_shl_cPt_V4 :
1941 Hexagon::LDriub_indexed_shl_cNotPt_V4;
Tony Linthicumb4b54152011-12-12 21:14:40 +00001942 case Hexagon::LDrih_indexed_shl_V4:
1943 return !invertPredicate ? Hexagon::LDrih_indexed_shl_cPt_V4 :
1944 Hexagon::LDrih_indexed_shl_cNotPt_V4;
1945 case Hexagon::LDriuh_indexed_shl_V4:
1946 return !invertPredicate ? Hexagon::LDriuh_indexed_shl_cPt_V4 :
1947 Hexagon::LDriuh_indexed_shl_cNotPt_V4;
Tony Linthicumb4b54152011-12-12 21:14:40 +00001948 case Hexagon::LDriw_indexed_shl_V4:
1949 return !invertPredicate ? Hexagon::LDriw_indexed_shl_cPt_V4 :
1950 Hexagon::LDriw_indexed_shl_cNotPt_V4;
Sirish Pande26f61a12012-05-03 21:52:53 +00001951
1952 // V4 Load from global address
Sirish Pande26f61a12012-05-03 21:52:53 +00001953 case Hexagon::LDd_GP_V4:
1954 return !invertPredicate ? Hexagon::LDd_GP_cPt_V4 :
1955 Hexagon::LDd_GP_cNotPt_V4;
1956 case Hexagon::LDb_GP_V4:
1957 return !invertPredicate ? Hexagon::LDb_GP_cPt_V4 :
1958 Hexagon::LDb_GP_cNotPt_V4;
1959 case Hexagon::LDub_GP_V4:
1960 return !invertPredicate ? Hexagon::LDub_GP_cPt_V4 :
1961 Hexagon::LDub_GP_cNotPt_V4;
1962 case Hexagon::LDh_GP_V4:
1963 return !invertPredicate ? Hexagon::LDh_GP_cPt_V4 :
1964 Hexagon::LDh_GP_cNotPt_V4;
1965 case Hexagon::LDuh_GP_V4:
1966 return !invertPredicate ? Hexagon::LDuh_GP_cPt_V4 :
1967 Hexagon::LDuh_GP_cNotPt_V4;
1968 case Hexagon::LDw_GP_V4:
1969 return !invertPredicate ? Hexagon::LDw_GP_cPt_V4 :
1970 Hexagon::LDw_GP_cNotPt_V4;
1971
Tony Linthicumb4b54152011-12-12 21:14:40 +00001972 // Byte.
1973 case Hexagon::POST_STbri:
1974 return !invertPredicate ? Hexagon::POST_STbri_cPt :
1975 Hexagon::POST_STbri_cNotPt;
1976 case Hexagon::STrib:
1977 return !invertPredicate ? Hexagon::STrib_cPt :
1978 Hexagon::STrib_cNotPt;
1979 case Hexagon::STrib_indexed:
1980 return !invertPredicate ? Hexagon::STrib_indexed_cPt :
1981 Hexagon::STrib_indexed_cNotPt;
1982 case Hexagon::STrib_imm_V4:
1983 return !invertPredicate ? Hexagon::STrib_imm_cPt_V4 :
1984 Hexagon::STrib_imm_cNotPt_V4;
1985 case Hexagon::STrib_indexed_shl_V4:
1986 return !invertPredicate ? Hexagon::STrib_indexed_shl_cPt_V4 :
1987 Hexagon::STrib_indexed_shl_cNotPt_V4;
1988 // Halfword.
1989 case Hexagon::POST_SThri:
1990 return !invertPredicate ? Hexagon::POST_SThri_cPt :
1991 Hexagon::POST_SThri_cNotPt;
1992 case Hexagon::STrih:
1993 return !invertPredicate ? Hexagon::STrih_cPt :
1994 Hexagon::STrih_cNotPt;
1995 case Hexagon::STrih_indexed:
1996 return !invertPredicate ? Hexagon::STrih_indexed_cPt :
1997 Hexagon::STrih_indexed_cNotPt;
1998 case Hexagon::STrih_imm_V4:
1999 return !invertPredicate ? Hexagon::STrih_imm_cPt_V4 :
2000 Hexagon::STrih_imm_cNotPt_V4;
2001 case Hexagon::STrih_indexed_shl_V4:
2002 return !invertPredicate ? Hexagon::STrih_indexed_shl_cPt_V4 :
2003 Hexagon::STrih_indexed_shl_cNotPt_V4;
2004 // Word.
2005 case Hexagon::POST_STwri:
2006 return !invertPredicate ? Hexagon::POST_STwri_cPt :
2007 Hexagon::POST_STwri_cNotPt;
2008 case Hexagon::STriw:
2009 return !invertPredicate ? Hexagon::STriw_cPt :
2010 Hexagon::STriw_cNotPt;
2011 case Hexagon::STriw_indexed:
2012 return !invertPredicate ? Hexagon::STriw_indexed_cPt :
2013 Hexagon::STriw_indexed_cNotPt;
2014 case Hexagon::STriw_indexed_shl_V4:
2015 return !invertPredicate ? Hexagon::STriw_indexed_shl_cPt_V4 :
2016 Hexagon::STriw_indexed_shl_cNotPt_V4;
2017 case Hexagon::STriw_imm_V4:
2018 return !invertPredicate ? Hexagon::STriw_imm_cPt_V4 :
2019 Hexagon::STriw_imm_cNotPt_V4;
2020 // Double word.
2021 case Hexagon::POST_STdri:
2022 return !invertPredicate ? Hexagon::POST_STdri_cPt :
2023 Hexagon::POST_STdri_cNotPt;
2024 case Hexagon::STrid:
2025 return !invertPredicate ? Hexagon::STrid_cPt :
2026 Hexagon::STrid_cNotPt;
2027 case Hexagon::STrid_indexed:
2028 return !invertPredicate ? Hexagon::STrid_indexed_cPt :
2029 Hexagon::STrid_indexed_cNotPt;
2030 case Hexagon::STrid_indexed_shl_V4:
2031 return !invertPredicate ? Hexagon::STrid_indexed_shl_cPt_V4 :
2032 Hexagon::STrid_indexed_shl_cNotPt_V4;
Sirish Pande26f61a12012-05-03 21:52:53 +00002033
2034 // V4 Store to global address
Sirish Pande26f61a12012-05-03 21:52:53 +00002035 case Hexagon::STd_GP_V4:
2036 return !invertPredicate ? Hexagon::STd_GP_cPt_V4 :
2037 Hexagon::STd_GP_cNotPt_V4;
2038 case Hexagon::STb_GP_V4:
2039 return !invertPredicate ? Hexagon::STb_GP_cPt_V4 :
2040 Hexagon::STb_GP_cNotPt_V4;
2041 case Hexagon::STh_GP_V4:
2042 return !invertPredicate ? Hexagon::STh_GP_cPt_V4 :
2043 Hexagon::STh_GP_cNotPt_V4;
2044 case Hexagon::STw_GP_V4:
2045 return !invertPredicate ? Hexagon::STw_GP_cPt_V4 :
2046 Hexagon::STw_GP_cNotPt_V4;
2047
Tony Linthicumb4b54152011-12-12 21:14:40 +00002048 // Load.
2049 case Hexagon::LDrid:
2050 return !invertPredicate ? Hexagon::LDrid_cPt :
2051 Hexagon::LDrid_cNotPt;
2052 case Hexagon::LDriw:
2053 return !invertPredicate ? Hexagon::LDriw_cPt :
2054 Hexagon::LDriw_cNotPt;
2055 case Hexagon::LDrih:
2056 return !invertPredicate ? Hexagon::LDrih_cPt :
2057 Hexagon::LDrih_cNotPt;
2058 case Hexagon::LDriuh:
2059 return !invertPredicate ? Hexagon::LDriuh_cPt :
2060 Hexagon::LDriuh_cNotPt;
2061 case Hexagon::LDrib:
2062 return !invertPredicate ? Hexagon::LDrib_cPt :
2063 Hexagon::LDrib_cNotPt;
2064 case Hexagon::LDriub:
2065 return !invertPredicate ? Hexagon::LDriub_cPt :
2066 Hexagon::LDriub_cNotPt;
Tony Linthicumb4b54152011-12-12 21:14:40 +00002067 // Load Indexed.
2068 case Hexagon::LDrid_indexed:
2069 return !invertPredicate ? Hexagon::LDrid_indexed_cPt :
2070 Hexagon::LDrid_indexed_cNotPt;
2071 case Hexagon::LDriw_indexed:
2072 return !invertPredicate ? Hexagon::LDriw_indexed_cPt :
2073 Hexagon::LDriw_indexed_cNotPt;
2074 case Hexagon::LDrih_indexed:
2075 return !invertPredicate ? Hexagon::LDrih_indexed_cPt :
2076 Hexagon::LDrih_indexed_cNotPt;
2077 case Hexagon::LDriuh_indexed:
2078 return !invertPredicate ? Hexagon::LDriuh_indexed_cPt :
2079 Hexagon::LDriuh_indexed_cNotPt;
2080 case Hexagon::LDrib_indexed:
2081 return !invertPredicate ? Hexagon::LDrib_indexed_cPt :
2082 Hexagon::LDrib_indexed_cNotPt;
2083 case Hexagon::LDriub_indexed:
2084 return !invertPredicate ? Hexagon::LDriub_indexed_cPt :
2085 Hexagon::LDriub_indexed_cNotPt;
2086 // Post Increment Load.
2087 case Hexagon::POST_LDrid:
2088 return !invertPredicate ? Hexagon::POST_LDrid_cPt :
2089 Hexagon::POST_LDrid_cNotPt;
2090 case Hexagon::POST_LDriw:
2091 return !invertPredicate ? Hexagon::POST_LDriw_cPt :
2092 Hexagon::POST_LDriw_cNotPt;
2093 case Hexagon::POST_LDrih:
2094 return !invertPredicate ? Hexagon::POST_LDrih_cPt :
2095 Hexagon::POST_LDrih_cNotPt;
2096 case Hexagon::POST_LDriuh:
2097 return !invertPredicate ? Hexagon::POST_LDriuh_cPt :
2098 Hexagon::POST_LDriuh_cNotPt;
2099 case Hexagon::POST_LDrib:
2100 return !invertPredicate ? Hexagon::POST_LDrib_cPt :
2101 Hexagon::POST_LDrib_cNotPt;
2102 case Hexagon::POST_LDriub:
2103 return !invertPredicate ? Hexagon::POST_LDriub_cPt :
2104 Hexagon::POST_LDriub_cNotPt;
2105 // DEALLOC_RETURN.
2106 case Hexagon::DEALLOC_RET_V4:
2107 return !invertPredicate ? Hexagon::DEALLOC_RET_cPt_V4 :
2108 Hexagon::DEALLOC_RET_cNotPt_V4;
Tony Linthicumb4b54152011-12-12 21:14:40 +00002109 }
Benjamin Kramer27baab62011-12-27 11:41:05 +00002110 llvm_unreachable("Unexpected predicable instruction");
Tony Linthicumb4b54152011-12-12 21:14:40 +00002111}
2112
2113
2114bool HexagonInstrInfo::
2115PredicateInstruction(MachineInstr *MI,
2116 const SmallVectorImpl<MachineOperand> &Cond) const {
2117 int Opc = MI->getOpcode();
2118 assert (isPredicable(MI) && "Expected predicable instruction");
2119 bool invertJump = (!Cond.empty() && Cond[0].isImm() &&
2120 (Cond[0].getImm() == 0));
Tony Linthicumb4b54152011-12-12 21:14:40 +00002121
Jyotsna Verma6b8d2022013-02-12 16:06:23 +00002122 // This will change MI's opcode to its predicate version.
2123 // However, its operand list is still the old one, i.e. the
2124 // non-predicate one.
2125 MI->setDesc(get(getMatchingCondBranchOpcode(Opc, invertJump)));
2126
2127 int oper = -1;
2128 unsigned int GAIdx = 0;
2129
2130 // Indicates whether the current MI has a GlobalAddress operand
2131 bool hasGAOpnd = false;
2132 std::vector<MachineOperand> tmpOpnds;
2133
2134 // Indicates whether we need to shift operands to right.
2135 bool needShift = true;
2136
2137 // The predicate is ALWAYS the FIRST input operand !!!
2138 if (MI->getNumOperands() == 0) {
2139 // The non-predicate version of MI does not take any operands,
2140 // i.e. no outs and no ins. In this condition, the predicate
2141 // operand will be directly placed at Operands[0]. No operand
2142 // shift is needed.
2143 // Example: BARRIER
2144 needShift = false;
2145 oper = -1;
2146 }
2147 else if ( MI->getOperand(MI->getNumOperands()-1).isReg()
2148 && MI->getOperand(MI->getNumOperands()-1).isDef()
2149 && !MI->getOperand(MI->getNumOperands()-1).isImplicit()) {
2150 // The non-predicate version of MI does not have any input operands.
2151 // In this condition, we extend the length of Operands[] by one and
2152 // copy the original last operand to the newly allocated slot.
2153 // At this moment, it is just a place holder. Later, we will put
2154 // predicate operand directly into it. No operand shift is needed.
2155 // Example: r0=BARRIER (this is a faked insn used here for illustration)
2156 MI->addOperand(MI->getOperand(MI->getNumOperands()-1));
2157 needShift = false;
2158 oper = MI->getNumOperands() - 2;
2159 }
2160 else {
2161 // We need to right shift all input operands by one. Duplicate the
2162 // last operand into the newly allocated slot.
2163 MI->addOperand(MI->getOperand(MI->getNumOperands()-1));
2164 }
2165
2166 if (needShift)
2167 {
2168 // Operands[ MI->getNumOperands() - 2 ] has been copied into
2169 // Operands[ MI->getNumOperands() - 1 ], so we start from
2170 // Operands[ MI->getNumOperands() - 3 ].
2171 // oper is a signed int.
2172 // It is ok if "MI->getNumOperands()-3" is -3, -2, or -1.
2173 for (oper = MI->getNumOperands() - 3; oper >= 0; --oper)
2174 {
2175 MachineOperand &MO = MI->getOperand(oper);
2176
2177 // Opnd[0] Opnd[1] Opnd[2] Opnd[3] Opnd[4] Opnd[5] Opnd[6] Opnd[7]
2178 // <Def0> <Def1> <Use0> <Use1> <ImpDef0> <ImpDef1> <ImpUse0> <ImpUse1>
2179 // /\~
2180 // /||\~
2181 // ||
2182 // Predicate Operand here
2183 if (MO.isReg() && !MO.isUse() && !MO.isImplicit()) {
2184 break;
2185 }
2186 if (MO.isReg()) {
2187 MI->getOperand(oper+1).ChangeToRegister(MO.getReg(), MO.isDef(),
2188 MO.isImplicit(), MO.isKill(),
2189 MO.isDead(), MO.isUndef(),
2190 MO.isDebug());
2191 }
2192 else if (MO.isImm()) {
2193 MI->getOperand(oper+1).ChangeToImmediate(MO.getImm());
2194 }
2195 else if (MO.isGlobal()) {
2196 // MI can not have more than one GlobalAddress operand.
2197 assert(hasGAOpnd == false && "MI can only have one GlobalAddress opnd");
2198
2199 // There is no member function called "ChangeToGlobalAddress" in the
2200 // MachineOperand class (not like "ChangeToRegister" and
2201 // "ChangeToImmediate"). So we have to remove them from Operands[] list
2202 // first, and then add them back after we have inserted the predicate
2203 // operand. tmpOpnds[] is to remember these operands before we remove
2204 // them.
2205 tmpOpnds.push_back(MO);
2206
2207 // Operands[oper] is a GlobalAddress operand;
2208 // Operands[oper+1] has been copied into Operands[oper+2];
2209 hasGAOpnd = true;
2210 GAIdx = oper;
2211 continue;
2212 }
2213 else {
2214 assert(false && "Unexpected operand type");
2215 }
Tony Linthicumb4b54152011-12-12 21:14:40 +00002216 }
2217 }
2218
2219 int regPos = invertJump ? 1 : 0;
2220 MachineOperand PredMO = Cond[regPos];
Jyotsna Verma6b8d2022013-02-12 16:06:23 +00002221
2222 // [oper] now points to the last explicit Def. Predicate operand must be
2223 // located at [oper+1]. See diagram above.
2224 // This assumes that the predicate is always the first operand,
2225 // i.e. Operands[0+numResults], in the set of inputs
2226 // It is better to have an assert here to check this. But I don't know how
2227 // to write this assert because findFirstPredOperandIdx() would return -1
2228 if (oper < -1) oper = -1;
Tony Linthicumb4b54152011-12-12 21:14:40 +00002229 MI->getOperand(oper+1).ChangeToRegister(PredMO.getReg(), PredMO.isDef(),
2230 PredMO.isImplicit(), PredMO.isKill(),
2231 PredMO.isDead(), PredMO.isUndef(),
2232 PredMO.isDebug());
2233
Jyotsna Verma6b8d2022013-02-12 16:06:23 +00002234 if (hasGAOpnd)
2235 {
2236 unsigned int i;
2237
2238 // Operands[GAIdx] is the original GlobalAddress operand, which is
2239 // already copied into tmpOpnds[0].
2240 // Operands[GAIdx] now stores a copy of Operands[GAIdx-1]
2241 // Operands[GAIdx+1] has already been copied into Operands[GAIdx+2],
2242 // so we start from [GAIdx+2]
2243 for (i = GAIdx + 2; i < MI->getNumOperands(); ++i)
2244 tmpOpnds.push_back(MI->getOperand(i));
2245
2246 // Remove all operands in range [ (GAIdx+1) ... (MI->getNumOperands()-1) ]
2247 // It is very important that we always remove from the end of Operands[]
2248 // MI->getNumOperands() is at least 2 if program goes to here.
2249 for (i = MI->getNumOperands() - 1; i > GAIdx; --i)
2250 MI->RemoveOperand(i);
2251
2252 for (i = 0; i < tmpOpnds.size(); ++i)
2253 MI->addOperand(tmpOpnds[i]);
2254 }
2255
Tony Linthicumb4b54152011-12-12 21:14:40 +00002256 return true;
2257}
2258
2259
2260bool
2261HexagonInstrInfo::
2262isProfitableToIfCvt(MachineBasicBlock &MBB,
Kay Tiong Khoo575e90e2012-06-13 15:53:04 +00002263 unsigned NumCycles,
Tony Linthicumb4b54152011-12-12 21:14:40 +00002264 unsigned ExtraPredCycles,
2265 const BranchProbability &Probability) const {
2266 return true;
2267}
2268
2269
2270bool
2271HexagonInstrInfo::
2272isProfitableToIfCvt(MachineBasicBlock &TMBB,
2273 unsigned NumTCycles,
2274 unsigned ExtraTCycles,
2275 MachineBasicBlock &FMBB,
2276 unsigned NumFCycles,
2277 unsigned ExtraFCycles,
2278 const BranchProbability &Probability) const {
2279 return true;
2280}
2281
2282
2283bool HexagonInstrInfo::isPredicated(const MachineInstr *MI) const {
Brendon Cahoonc635ebd2012-02-08 18:25:47 +00002284 const uint64_t F = MI->getDesc().TSFlags;
Tony Linthicumb4b54152011-12-12 21:14:40 +00002285
Brendon Cahoonc635ebd2012-02-08 18:25:47 +00002286 return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask);
Tony Linthicumb4b54152011-12-12 21:14:40 +00002287}
2288
Tony Linthicumb4b54152011-12-12 21:14:40 +00002289bool
2290HexagonInstrInfo::DefinesPredicate(MachineInstr *MI,
2291 std::vector<MachineOperand> &Pred) const {
2292 for (unsigned oper = 0; oper < MI->getNumOperands(); ++oper) {
2293 MachineOperand MO = MI->getOperand(oper);
2294 if (MO.isReg() && MO.isDef()) {
2295 const TargetRegisterClass* RC = RI.getMinimalPhysRegClass(MO.getReg());
Craig Topper420761a2012-04-20 07:30:17 +00002296 if (RC == &Hexagon::PredRegsRegClass) {
Tony Linthicumb4b54152011-12-12 21:14:40 +00002297 Pred.push_back(MO);
2298 return true;
2299 }
2300 }
2301 }
2302 return false;
2303}
2304
2305
2306bool
2307HexagonInstrInfo::
2308SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
2309 const SmallVectorImpl<MachineOperand> &Pred2) const {
2310 // TODO: Fix this
2311 return false;
2312}
2313
2314
2315//
2316// We indicate that we want to reverse the branch by
2317// inserting a 0 at the beginning of the Cond vector.
2318//
2319bool HexagonInstrInfo::
2320ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
2321 if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) {
2322 Cond.erase(Cond.begin());
2323 } else {
2324 Cond.insert(Cond.begin(), MachineOperand::CreateImm(0));
2325 }
2326 return false;
2327}
2328
2329
2330bool HexagonInstrInfo::
2331isProfitableToDupForIfCvt(MachineBasicBlock &MBB,unsigned NumInstrs,
2332 const BranchProbability &Probability) const {
2333 return (NumInstrs <= 4);
2334}
2335
2336bool HexagonInstrInfo::isDeallocRet(const MachineInstr *MI) const {
2337 switch (MI->getOpcode()) {
Sirish Pande26f61a12012-05-03 21:52:53 +00002338 default: return false;
Tony Linthicumb4b54152011-12-12 21:14:40 +00002339 case Hexagon::DEALLOC_RET_V4 :
2340 case Hexagon::DEALLOC_RET_cPt_V4 :
2341 case Hexagon::DEALLOC_RET_cNotPt_V4 :
2342 case Hexagon::DEALLOC_RET_cdnPnt_V4 :
2343 case Hexagon::DEALLOC_RET_cNotdnPnt_V4 :
2344 case Hexagon::DEALLOC_RET_cdnPt_V4 :
2345 case Hexagon::DEALLOC_RET_cNotdnPt_V4 :
2346 return true;
2347 }
Tony Linthicumb4b54152011-12-12 21:14:40 +00002348}
2349
2350
2351bool HexagonInstrInfo::
2352isValidOffset(const int Opcode, const int Offset) const {
2353 // This function is to check whether the "Offset" is in the correct range of
2354 // the given "Opcode". If "Offset" is not in the correct range, "ADD_ri" is
2355 // inserted to calculate the final address. Due to this reason, the function
2356 // assumes that the "Offset" has correct alignment.
2357
2358 switch(Opcode) {
2359
2360 case Hexagon::LDriw:
Jyotsna Vermaa454ffd2013-01-17 18:42:37 +00002361 case Hexagon::LDriw_indexed:
Sirish Pande7517bbc2012-05-10 20:20:25 +00002362 case Hexagon::LDriw_f:
Jyotsna Vermaa454ffd2013-01-17 18:42:37 +00002363 case Hexagon::STriw_indexed:
Tony Linthicumb4b54152011-12-12 21:14:40 +00002364 case Hexagon::STriw:
Sirish Pande7517bbc2012-05-10 20:20:25 +00002365 case Hexagon::STriw_f:
Tony Linthicumb4b54152011-12-12 21:14:40 +00002366 assert((Offset % 4 == 0) && "Offset has incorrect alignment");
2367 return (Offset >= Hexagon_MEMW_OFFSET_MIN) &&
2368 (Offset <= Hexagon_MEMW_OFFSET_MAX);
2369
2370 case Hexagon::LDrid:
Jyotsna Vermaa454ffd2013-01-17 18:42:37 +00002371 case Hexagon::LDrid_indexed:
Sirish Pande7517bbc2012-05-10 20:20:25 +00002372 case Hexagon::LDrid_f:
Tony Linthicumb4b54152011-12-12 21:14:40 +00002373 case Hexagon::STrid:
Jyotsna Vermaa454ffd2013-01-17 18:42:37 +00002374 case Hexagon::STrid_indexed:
Sirish Pande7517bbc2012-05-10 20:20:25 +00002375 case Hexagon::STrid_f:
Tony Linthicumb4b54152011-12-12 21:14:40 +00002376 assert((Offset % 8 == 0) && "Offset has incorrect alignment");
2377 return (Offset >= Hexagon_MEMD_OFFSET_MIN) &&
2378 (Offset <= Hexagon_MEMD_OFFSET_MAX);
2379
2380 case Hexagon::LDrih:
2381 case Hexagon::LDriuh:
2382 case Hexagon::STrih:
Tony Linthicumb4b54152011-12-12 21:14:40 +00002383 assert((Offset % 2 == 0) && "Offset has incorrect alignment");
2384 return (Offset >= Hexagon_MEMH_OFFSET_MIN) &&
2385 (Offset <= Hexagon_MEMH_OFFSET_MAX);
2386
2387 case Hexagon::LDrib:
2388 case Hexagon::STrib:
2389 case Hexagon::LDriub:
Tony Linthicumb4b54152011-12-12 21:14:40 +00002390 return (Offset >= Hexagon_MEMB_OFFSET_MIN) &&
2391 (Offset <= Hexagon_MEMB_OFFSET_MAX);
2392
2393 case Hexagon::ADD_ri:
2394 case Hexagon::TFR_FI:
2395 return (Offset >= Hexagon_ADDI_OFFSET_MIN) &&
2396 (Offset <= Hexagon_ADDI_OFFSET_MAX);
2397
Tony Linthicumb4b54152011-12-12 21:14:40 +00002398 case Hexagon::MEMw_ADDi_indexed_MEM_V4 :
2399 case Hexagon::MEMw_SUBi_indexed_MEM_V4 :
2400 case Hexagon::MEMw_ADDr_indexed_MEM_V4 :
2401 case Hexagon::MEMw_SUBr_indexed_MEM_V4 :
2402 case Hexagon::MEMw_ANDr_indexed_MEM_V4 :
2403 case Hexagon::MEMw_ORr_indexed_MEM_V4 :
Tony Linthicumb4b54152011-12-12 21:14:40 +00002404 case Hexagon::MEMw_ADDi_MEM_V4 :
2405 case Hexagon::MEMw_SUBi_MEM_V4 :
2406 case Hexagon::MEMw_ADDr_MEM_V4 :
2407 case Hexagon::MEMw_SUBr_MEM_V4 :
2408 case Hexagon::MEMw_ANDr_MEM_V4 :
2409 case Hexagon::MEMw_ORr_MEM_V4 :
2410 assert ((Offset % 4) == 0 && "MEMOPw offset is not aligned correctly." );
2411 return (0 <= Offset && Offset <= 255);
2412
Tony Linthicumb4b54152011-12-12 21:14:40 +00002413 case Hexagon::MEMh_ADDi_indexed_MEM_V4 :
2414 case Hexagon::MEMh_SUBi_indexed_MEM_V4 :
2415 case Hexagon::MEMh_ADDr_indexed_MEM_V4 :
2416 case Hexagon::MEMh_SUBr_indexed_MEM_V4 :
2417 case Hexagon::MEMh_ANDr_indexed_MEM_V4 :
2418 case Hexagon::MEMh_ORr_indexed_MEM_V4 :
Tony Linthicumb4b54152011-12-12 21:14:40 +00002419 case Hexagon::MEMh_ADDi_MEM_V4 :
2420 case Hexagon::MEMh_SUBi_MEM_V4 :
2421 case Hexagon::MEMh_ADDr_MEM_V4 :
2422 case Hexagon::MEMh_SUBr_MEM_V4 :
2423 case Hexagon::MEMh_ANDr_MEM_V4 :
2424 case Hexagon::MEMh_ORr_MEM_V4 :
2425 assert ((Offset % 2) == 0 && "MEMOPh offset is not aligned correctly." );
2426 return (0 <= Offset && Offset <= 127);
2427
Tony Linthicumb4b54152011-12-12 21:14:40 +00002428 case Hexagon::MEMb_ADDi_indexed_MEM_V4 :
2429 case Hexagon::MEMb_SUBi_indexed_MEM_V4 :
2430 case Hexagon::MEMb_ADDr_indexed_MEM_V4 :
2431 case Hexagon::MEMb_SUBr_indexed_MEM_V4 :
2432 case Hexagon::MEMb_ANDr_indexed_MEM_V4 :
2433 case Hexagon::MEMb_ORr_indexed_MEM_V4 :
Tony Linthicumb4b54152011-12-12 21:14:40 +00002434 case Hexagon::MEMb_ADDi_MEM_V4 :
2435 case Hexagon::MEMb_SUBi_MEM_V4 :
2436 case Hexagon::MEMb_ADDr_MEM_V4 :
2437 case Hexagon::MEMb_SUBr_MEM_V4 :
2438 case Hexagon::MEMb_ANDr_MEM_V4 :
2439 case Hexagon::MEMb_ORr_MEM_V4 :
2440 return (0 <= Offset && Offset <= 63);
2441
2442 // LDri_pred and STriw_pred are pseudo operations, so it has to take offset of
2443 // any size. Later pass knows how to handle it.
2444 case Hexagon::STriw_pred:
2445 case Hexagon::LDriw_pred:
2446 return true;
2447
Krzysztof Parzyszek71490fa2013-02-11 21:37:55 +00002448 case Hexagon::LOOP0_i:
2449 return isUInt<10>(Offset);
2450
Tony Linthicumb4b54152011-12-12 21:14:40 +00002451 // INLINEASM is very special.
2452 case Hexagon::INLINEASM:
2453 return true;
2454 }
2455
Benjamin Kramer27baab62011-12-27 11:41:05 +00002456 llvm_unreachable("No offset range is defined for this opcode. "
2457 "Please define it in the above switch statement!");
Tony Linthicumb4b54152011-12-12 21:14:40 +00002458}
2459
2460
2461//
2462// Check if the Offset is a valid auto-inc imm by Load/Store Type.
2463//
2464bool HexagonInstrInfo::
2465isValidAutoIncImm(const EVT VT, const int Offset) const {
2466
2467 if (VT == MVT::i64) {
2468 return (Offset >= Hexagon_MEMD_AUTOINC_MIN &&
2469 Offset <= Hexagon_MEMD_AUTOINC_MAX &&
2470 (Offset & 0x7) == 0);
2471 }
2472 if (VT == MVT::i32) {
2473 return (Offset >= Hexagon_MEMW_AUTOINC_MIN &&
2474 Offset <= Hexagon_MEMW_AUTOINC_MAX &&
2475 (Offset & 0x3) == 0);
2476 }
2477 if (VT == MVT::i16) {
2478 return (Offset >= Hexagon_MEMH_AUTOINC_MIN &&
2479 Offset <= Hexagon_MEMH_AUTOINC_MAX &&
2480 (Offset & 0x1) == 0);
2481 }
2482 if (VT == MVT::i8) {
2483 return (Offset >= Hexagon_MEMB_AUTOINC_MIN &&
2484 Offset <= Hexagon_MEMB_AUTOINC_MAX);
2485 }
Craig Topperbc219812012-02-07 02:50:20 +00002486 llvm_unreachable("Not an auto-inc opc!");
Tony Linthicumb4b54152011-12-12 21:14:40 +00002487}
2488
2489
2490bool HexagonInstrInfo::
2491isMemOp(const MachineInstr *MI) const {
2492 switch (MI->getOpcode())
2493 {
Sirish Pande26f61a12012-05-03 21:52:53 +00002494 default: return false;
Tony Linthicumb4b54152011-12-12 21:14:40 +00002495 case Hexagon::MEMw_ADDi_indexed_MEM_V4 :
2496 case Hexagon::MEMw_SUBi_indexed_MEM_V4 :
2497 case Hexagon::MEMw_ADDr_indexed_MEM_V4 :
2498 case Hexagon::MEMw_SUBr_indexed_MEM_V4 :
2499 case Hexagon::MEMw_ANDr_indexed_MEM_V4 :
2500 case Hexagon::MEMw_ORr_indexed_MEM_V4 :
Tony Linthicumb4b54152011-12-12 21:14:40 +00002501 case Hexagon::MEMw_ADDi_MEM_V4 :
2502 case Hexagon::MEMw_SUBi_MEM_V4 :
2503 case Hexagon::MEMw_ADDr_MEM_V4 :
2504 case Hexagon::MEMw_SUBr_MEM_V4 :
2505 case Hexagon::MEMw_ANDr_MEM_V4 :
2506 case Hexagon::MEMw_ORr_MEM_V4 :
Tony Linthicumb4b54152011-12-12 21:14:40 +00002507 case Hexagon::MEMh_ADDi_indexed_MEM_V4 :
2508 case Hexagon::MEMh_SUBi_indexed_MEM_V4 :
2509 case Hexagon::MEMh_ADDr_indexed_MEM_V4 :
2510 case Hexagon::MEMh_SUBr_indexed_MEM_V4 :
2511 case Hexagon::MEMh_ANDr_indexed_MEM_V4 :
2512 case Hexagon::MEMh_ORr_indexed_MEM_V4 :
Tony Linthicumb4b54152011-12-12 21:14:40 +00002513 case Hexagon::MEMh_ADDi_MEM_V4 :
2514 case Hexagon::MEMh_SUBi_MEM_V4 :
2515 case Hexagon::MEMh_ADDr_MEM_V4 :
2516 case Hexagon::MEMh_SUBr_MEM_V4 :
2517 case Hexagon::MEMh_ANDr_MEM_V4 :
2518 case Hexagon::MEMh_ORr_MEM_V4 :
Tony Linthicumb4b54152011-12-12 21:14:40 +00002519 case Hexagon::MEMb_ADDi_indexed_MEM_V4 :
2520 case Hexagon::MEMb_SUBi_indexed_MEM_V4 :
2521 case Hexagon::MEMb_ADDr_indexed_MEM_V4 :
2522 case Hexagon::MEMb_SUBr_indexed_MEM_V4 :
2523 case Hexagon::MEMb_ANDr_indexed_MEM_V4 :
2524 case Hexagon::MEMb_ORr_indexed_MEM_V4 :
Tony Linthicumb4b54152011-12-12 21:14:40 +00002525 case Hexagon::MEMb_ADDi_MEM_V4 :
2526 case Hexagon::MEMb_SUBi_MEM_V4 :
2527 case Hexagon::MEMb_ADDr_MEM_V4 :
2528 case Hexagon::MEMb_SUBr_MEM_V4 :
2529 case Hexagon::MEMb_ANDr_MEM_V4 :
2530 case Hexagon::MEMb_ORr_MEM_V4 :
Sirish Pande26f61a12012-05-03 21:52:53 +00002531 return true;
Tony Linthicumb4b54152011-12-12 21:14:40 +00002532 }
Tony Linthicumb4b54152011-12-12 21:14:40 +00002533}
2534
2535
2536bool HexagonInstrInfo::
2537isSpillPredRegOp(const MachineInstr *MI) const {
Sirish Pande26f61a12012-05-03 21:52:53 +00002538 switch (MI->getOpcode()) {
2539 default: return false;
Tony Linthicumb4b54152011-12-12 21:14:40 +00002540 case Hexagon::STriw_pred :
2541 case Hexagon::LDriw_pred :
Sirish Pande26f61a12012-05-03 21:52:53 +00002542 return true;
Sirish Pande1bfd2482012-04-23 17:49:28 +00002543 }
Sirish Pandeb3385702012-05-12 05:10:30 +00002544}
2545
2546bool HexagonInstrInfo::isNewValueJumpCandidate(const MachineInstr *MI) const {
2547 switch (MI->getOpcode()) {
Sirish Pande2b38c122012-05-12 05:54:15 +00002548 default: return false;
Sirish Pandeb3385702012-05-12 05:10:30 +00002549 case Hexagon::CMPEQrr:
2550 case Hexagon::CMPEQri:
2551 case Hexagon::CMPLTrr:
2552 case Hexagon::CMPGTrr:
2553 case Hexagon::CMPGTri:
2554 case Hexagon::CMPLTUrr:
2555 case Hexagon::CMPGTUrr:
2556 case Hexagon::CMPGTUri:
2557 case Hexagon::CMPGEri:
2558 case Hexagon::CMPGEUri:
2559 return true;
Sirish Pandeb3385702012-05-12 05:10:30 +00002560 }
Sirish Pande1bfd2482012-04-23 17:49:28 +00002561}
2562
Sirish Pande26f61a12012-05-03 21:52:53 +00002563bool HexagonInstrInfo::
2564isConditionalTransfer (const MachineInstr *MI) const {
2565 switch (MI->getOpcode()) {
2566 default: return false;
2567 case Hexagon::TFR_cPt:
2568 case Hexagon::TFR_cNotPt:
2569 case Hexagon::TFRI_cPt:
2570 case Hexagon::TFRI_cNotPt:
2571 case Hexagon::TFR_cdnPt:
2572 case Hexagon::TFR_cdnNotPt:
2573 case Hexagon::TFRI_cdnPt:
2574 case Hexagon::TFRI_cdnNotPt:
2575 return true;
2576 }
2577}
Tony Linthicumb4b54152011-12-12 21:14:40 +00002578
2579bool HexagonInstrInfo::isConditionalALU32 (const MachineInstr* MI) const {
2580 const HexagonRegisterInfo& QRI = getRegisterInfo();
2581 switch (MI->getOpcode())
2582 {
Sirish Pande26f61a12012-05-03 21:52:53 +00002583 default: return false;
Tony Linthicumb4b54152011-12-12 21:14:40 +00002584 case Hexagon::ADD_ri_cPt:
2585 case Hexagon::ADD_ri_cNotPt:
2586 case Hexagon::ADD_rr_cPt:
2587 case Hexagon::ADD_rr_cNotPt:
2588 case Hexagon::XOR_rr_cPt:
2589 case Hexagon::XOR_rr_cNotPt:
2590 case Hexagon::AND_rr_cPt:
2591 case Hexagon::AND_rr_cNotPt:
2592 case Hexagon::OR_rr_cPt:
2593 case Hexagon::OR_rr_cNotPt:
2594 case Hexagon::SUB_rr_cPt:
2595 case Hexagon::SUB_rr_cNotPt:
2596 case Hexagon::COMBINE_rr_cPt:
2597 case Hexagon::COMBINE_rr_cNotPt:
2598 return true;
2599 case Hexagon::ASLH_cPt_V4:
2600 case Hexagon::ASLH_cNotPt_V4:
2601 case Hexagon::ASRH_cPt_V4:
2602 case Hexagon::ASRH_cNotPt_V4:
2603 case Hexagon::SXTB_cPt_V4:
2604 case Hexagon::SXTB_cNotPt_V4:
2605 case Hexagon::SXTH_cPt_V4:
2606 case Hexagon::SXTH_cNotPt_V4:
2607 case Hexagon::ZXTB_cPt_V4:
2608 case Hexagon::ZXTB_cNotPt_V4:
2609 case Hexagon::ZXTH_cPt_V4:
2610 case Hexagon::ZXTH_cNotPt_V4:
Sirish Pande26f61a12012-05-03 21:52:53 +00002611 return QRI.Subtarget.hasV4TOps();
Tony Linthicumb4b54152011-12-12 21:14:40 +00002612 }
Tony Linthicumb4b54152011-12-12 21:14:40 +00002613}
2614
Tony Linthicumb4b54152011-12-12 21:14:40 +00002615bool HexagonInstrInfo::
2616isConditionalLoad (const MachineInstr* MI) const {
2617 const HexagonRegisterInfo& QRI = getRegisterInfo();
2618 switch (MI->getOpcode())
2619 {
Sirish Pande26f61a12012-05-03 21:52:53 +00002620 default: return false;
Tony Linthicumb4b54152011-12-12 21:14:40 +00002621 case Hexagon::LDrid_cPt :
2622 case Hexagon::LDrid_cNotPt :
2623 case Hexagon::LDrid_indexed_cPt :
2624 case Hexagon::LDrid_indexed_cNotPt :
2625 case Hexagon::LDriw_cPt :
2626 case Hexagon::LDriw_cNotPt :
2627 case Hexagon::LDriw_indexed_cPt :
2628 case Hexagon::LDriw_indexed_cNotPt :
2629 case Hexagon::LDrih_cPt :
2630 case Hexagon::LDrih_cNotPt :
2631 case Hexagon::LDrih_indexed_cPt :
2632 case Hexagon::LDrih_indexed_cNotPt :
2633 case Hexagon::LDrib_cPt :
2634 case Hexagon::LDrib_cNotPt :
2635 case Hexagon::LDrib_indexed_cPt :
2636 case Hexagon::LDrib_indexed_cNotPt :
2637 case Hexagon::LDriuh_cPt :
2638 case Hexagon::LDriuh_cNotPt :
2639 case Hexagon::LDriuh_indexed_cPt :
2640 case Hexagon::LDriuh_indexed_cNotPt :
2641 case Hexagon::LDriub_cPt :
2642 case Hexagon::LDriub_cNotPt :
2643 case Hexagon::LDriub_indexed_cPt :
2644 case Hexagon::LDriub_indexed_cNotPt :
2645 return true;
2646 case Hexagon::POST_LDrid_cPt :
2647 case Hexagon::POST_LDrid_cNotPt :
2648 case Hexagon::POST_LDriw_cPt :
2649 case Hexagon::POST_LDriw_cNotPt :
2650 case Hexagon::POST_LDrih_cPt :
2651 case Hexagon::POST_LDrih_cNotPt :
2652 case Hexagon::POST_LDrib_cPt :
2653 case Hexagon::POST_LDrib_cNotPt :
2654 case Hexagon::POST_LDriuh_cPt :
2655 case Hexagon::POST_LDriuh_cNotPt :
2656 case Hexagon::POST_LDriub_cPt :
2657 case Hexagon::POST_LDriub_cNotPt :
Sirish Pande26f61a12012-05-03 21:52:53 +00002658 return QRI.Subtarget.hasV4TOps();
Tony Linthicumb4b54152011-12-12 21:14:40 +00002659 case Hexagon::LDrid_indexed_shl_cPt_V4 :
2660 case Hexagon::LDrid_indexed_shl_cNotPt_V4 :
Tony Linthicumb4b54152011-12-12 21:14:40 +00002661 case Hexagon::LDrib_indexed_shl_cPt_V4 :
2662 case Hexagon::LDrib_indexed_shl_cNotPt_V4 :
Tony Linthicumb4b54152011-12-12 21:14:40 +00002663 case Hexagon::LDriub_indexed_shl_cPt_V4 :
2664 case Hexagon::LDriub_indexed_shl_cNotPt_V4 :
Tony Linthicumb4b54152011-12-12 21:14:40 +00002665 case Hexagon::LDrih_indexed_shl_cPt_V4 :
2666 case Hexagon::LDrih_indexed_shl_cNotPt_V4 :
Tony Linthicumb4b54152011-12-12 21:14:40 +00002667 case Hexagon::LDriuh_indexed_shl_cPt_V4 :
2668 case Hexagon::LDriuh_indexed_shl_cNotPt_V4 :
Tony Linthicumb4b54152011-12-12 21:14:40 +00002669 case Hexagon::LDriw_indexed_shl_cPt_V4 :
2670 case Hexagon::LDriw_indexed_shl_cNotPt_V4 :
Sirish Pande26f61a12012-05-03 21:52:53 +00002671 return QRI.Subtarget.hasV4TOps();
Tony Linthicumb4b54152011-12-12 21:14:40 +00002672 }
Tony Linthicumb4b54152011-12-12 21:14:40 +00002673}
Andrew Trickee498d32012-02-01 22:13:57 +00002674
Sirish Pande26f61a12012-05-03 21:52:53 +00002675// Returns true if an instruction is a conditional store.
2676//
2677// Note: It doesn't include conditional new-value stores as they can't be
2678// converted to .new predicate.
2679//
2680// p.new NV store [ if(p0.new)memw(R0+#0)=R2.new ]
2681// ^ ^
2682// / \ (not OK. it will cause new-value store to be
2683// / X conditional on p0.new while R2 producer is
2684// / \ on p0)
2685// / \.
2686// p.new store p.old NV store
2687// [if(p0.new)memw(R0+#0)=R2] [if(p0)memw(R0+#0)=R2.new]
2688// ^ ^
2689// \ /
2690// \ /
2691// \ /
2692// p.old store
2693// [if (p0)memw(R0+#0)=R2]
2694//
2695// The above diagram shows the steps involoved in the conversion of a predicated
2696// store instruction to its .new predicated new-value form.
2697//
2698// The following set of instructions further explains the scenario where
2699// conditional new-value store becomes invalid when promoted to .new predicate
2700// form.
2701//
2702// { 1) if (p0) r0 = add(r1, r2)
2703// 2) p0 = cmp.eq(r3, #0) }
2704//
2705// 3) if (p0) memb(r1+#0) = r0 --> this instruction can't be grouped with
2706// the first two instructions because in instr 1, r0 is conditional on old value
2707// of p0 but its use in instr 3 is conditional on p0 modified by instr 2 which
2708// is not valid for new-value stores.
2709bool HexagonInstrInfo::
2710isConditionalStore (const MachineInstr* MI) const {
2711 const HexagonRegisterInfo& QRI = getRegisterInfo();
2712 switch (MI->getOpcode())
2713 {
2714 default: return false;
2715 case Hexagon::STrib_imm_cPt_V4 :
2716 case Hexagon::STrib_imm_cNotPt_V4 :
2717 case Hexagon::STrib_indexed_shl_cPt_V4 :
2718 case Hexagon::STrib_indexed_shl_cNotPt_V4 :
2719 case Hexagon::STrib_cPt :
2720 case Hexagon::STrib_cNotPt :
2721 case Hexagon::POST_STbri_cPt :
2722 case Hexagon::POST_STbri_cNotPt :
2723 case Hexagon::STrid_indexed_cPt :
2724 case Hexagon::STrid_indexed_cNotPt :
2725 case Hexagon::STrid_indexed_shl_cPt_V4 :
2726 case Hexagon::POST_STdri_cPt :
2727 case Hexagon::POST_STdri_cNotPt :
2728 case Hexagon::STrih_cPt :
2729 case Hexagon::STrih_cNotPt :
2730 case Hexagon::STrih_indexed_cPt :
2731 case Hexagon::STrih_indexed_cNotPt :
2732 case Hexagon::STrih_imm_cPt_V4 :
2733 case Hexagon::STrih_imm_cNotPt_V4 :
2734 case Hexagon::STrih_indexed_shl_cPt_V4 :
2735 case Hexagon::STrih_indexed_shl_cNotPt_V4 :
2736 case Hexagon::POST_SThri_cPt :
2737 case Hexagon::POST_SThri_cNotPt :
2738 case Hexagon::STriw_cPt :
2739 case Hexagon::STriw_cNotPt :
2740 case Hexagon::STriw_indexed_cPt :
2741 case Hexagon::STriw_indexed_cNotPt :
2742 case Hexagon::STriw_imm_cPt_V4 :
2743 case Hexagon::STriw_imm_cNotPt_V4 :
2744 case Hexagon::STriw_indexed_shl_cPt_V4 :
2745 case Hexagon::STriw_indexed_shl_cNotPt_V4 :
2746 case Hexagon::POST_STwri_cPt :
2747 case Hexagon::POST_STwri_cNotPt :
2748 return QRI.Subtarget.hasV4TOps();
2749
2750 // V4 global address store before promoting to dot new.
Sirish Pande26f61a12012-05-03 21:52:53 +00002751 case Hexagon::STd_GP_cPt_V4 :
2752 case Hexagon::STd_GP_cNotPt_V4 :
2753 case Hexagon::STb_GP_cPt_V4 :
2754 case Hexagon::STb_GP_cNotPt_V4 :
2755 case Hexagon::STh_GP_cPt_V4 :
2756 case Hexagon::STh_GP_cNotPt_V4 :
2757 case Hexagon::STw_GP_cPt_V4 :
2758 case Hexagon::STw_GP_cNotPt_V4 :
2759 return QRI.Subtarget.hasV4TOps();
2760
2761 // Predicated new value stores (i.e. if (p0) memw(..)=r0.new) are excluded
2762 // from the "Conditional Store" list. Because a predicated new value store
2763 // would NOT be promoted to a double dot new store. See diagram below:
2764 // This function returns yes for those stores that are predicated but not
2765 // yet promoted to predicate dot new instructions.
2766 //
2767 // +---------------------+
2768 // /-----| if (p0) memw(..)=r0 |---------\~
2769 // || +---------------------+ ||
2770 // promote || /\ /\ || promote
2771 // || /||\ /||\ ||
2772 // \||/ demote || \||/
2773 // \/ || || \/
2774 // +-------------------------+ || +-------------------------+
2775 // | if (p0.new) memw(..)=r0 | || | if (p0) memw(..)=r0.new |
2776 // +-------------------------+ || +-------------------------+
2777 // || || ||
2778 // || demote \||/
2779 // promote || \/ NOT possible
2780 // || || /\~
2781 // \||/ || /||\~
2782 // \/ || ||
2783 // +-----------------------------+
2784 // | if (p0.new) memw(..)=r0.new |
2785 // +-----------------------------+
2786 // Double Dot New Store
2787 //
2788 }
2789}
2790
2791
2792
Andrew Trickee498d32012-02-01 22:13:57 +00002793DFAPacketizer *HexagonInstrInfo::
2794CreateTargetScheduleState(const TargetMachine *TM,
2795 const ScheduleDAG *DAG) const {
2796 const InstrItineraryData *II = TM->getInstrItineraryData();
2797 return TM->getSubtarget<HexagonGenSubtargetInfo>().createDFAPacketizer(II);
2798}
2799
2800bool HexagonInstrInfo::isSchedulingBoundary(const MachineInstr *MI,
2801 const MachineBasicBlock *MBB,
2802 const MachineFunction &MF) const {
2803 // Debug info is never a scheduling boundary. It's necessary to be explicit
2804 // due to the special treatment of IT instructions below, otherwise a
2805 // dbg_value followed by an IT will result in the IT instruction being
2806 // considered a scheduling hazard, which is wrong. It should be the actual
2807 // instruction preceding the dbg_value instruction(s), just like it is
2808 // when debug info is not present.
2809 if (MI->isDebugValue())
2810 return false;
2811
2812 // Terminators and labels can't be scheduled around.
2813 if (MI->getDesc().isTerminator() || MI->isLabel() || MI->isInlineAsm())
2814 return true;
2815
2816 return false;
2817}