blob: 31c1937951be1425eca6c849a87ae3ea674d0596 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- HexagonInstrInfo.cpp - Hexagon Instruction Information ------------===//
Tony Linthicum1213a7a2011-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 Linthicum1213a7a2011-12-12 21:14:40 +000014#include "HexagonInstrInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000015#include "Hexagon.h"
Craig Topperb25fda92012-03-17 18:46:09 +000016#include "HexagonRegisterInfo.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000017#include "HexagonSubtarget.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000018#include "llvm/ADT/STLExtras.h"
19#include "llvm/ADT/SmallVector.h"
Benjamin Kramerae87d7b2012-02-06 10:19:29 +000020#include "llvm/CodeGen/DFAPacketizer.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000021#include "llvm/CodeGen/MachineFrameInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000022#include "llvm/CodeGen/MachineInstrBuilder.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000023#include "llvm/CodeGen/MachineMemOperand.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/CodeGen/MachineRegisterInfo.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000025#include "llvm/CodeGen/PseudoSourceValue.h"
Jyotsna Verma5ed51812013-05-01 21:37:34 +000026#include "llvm/Support/Debug.h"
Benjamin Kramerae87d7b2012-02-06 10:19:29 +000027#include "llvm/Support/MathExtras.h"
Reid Kleckner1c76f1552013-05-03 00:54:56 +000028#include "llvm/Support/raw_ostream.h"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000029#define GET_INSTRINFO_CTOR
Pranav Bhandarkar34b60182012-11-01 19:13:23 +000030#define GET_INSTRMAP_INFO
Tony Linthicum1213a7a2011-12-12 21:14:40 +000031#include "HexagonGenInstrInfo.inc"
Andrew Trickd06df962012-02-01 22:13:57 +000032#include "HexagonGenDFAPacketizer.inc"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000033
Tony Linthicum1213a7a2011-12-12 21:14:40 +000034using namespace llvm;
35
36///
37/// Constants for Hexagon instructions.
38///
39const int Hexagon_MEMW_OFFSET_MAX = 4095;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000040const int Hexagon_MEMW_OFFSET_MIN = -4096;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000041const int Hexagon_MEMD_OFFSET_MAX = 8191;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000042const int Hexagon_MEMD_OFFSET_MIN = -8192;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000043const int Hexagon_MEMH_OFFSET_MAX = 2047;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000044const int Hexagon_MEMH_OFFSET_MIN = -2048;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000045const int Hexagon_MEMB_OFFSET_MAX = 1023;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000046const int Hexagon_MEMB_OFFSET_MIN = -1024;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000047const int Hexagon_ADDI_OFFSET_MAX = 32767;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000048const int Hexagon_ADDI_OFFSET_MIN = -32768;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000049const int Hexagon_MEMD_AUTOINC_MAX = 56;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000050const int Hexagon_MEMD_AUTOINC_MIN = -64;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000051const int Hexagon_MEMW_AUTOINC_MAX = 28;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000052const int Hexagon_MEMW_AUTOINC_MIN = -32;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000053const int Hexagon_MEMH_AUTOINC_MAX = 14;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000054const int Hexagon_MEMH_AUTOINC_MIN = -16;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000055const int Hexagon_MEMB_AUTOINC_MAX = 7;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000056const int Hexagon_MEMB_AUTOINC_MIN = -8;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000057
58
59HexagonInstrInfo::HexagonInstrInfo(HexagonSubtarget &ST)
60 : HexagonGenInstrInfo(Hexagon::ADJCALLSTACKDOWN, Hexagon::ADJCALLSTACKUP),
61 RI(ST, *this), Subtarget(ST) {
62}
63
64
65/// isLoadFromStackSlot - If the specified machine instruction is a direct
66/// load from a stack slot, return the virtual or physical register number of
67/// the destination along with the FrameIndex of the loaded stack slot. If
68/// not, return 0. This predicate must return 0 if the instruction has
69/// any side effects other than loading from the stack slot.
70unsigned HexagonInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
71 int &FrameIndex) const {
72
73
74 switch (MI->getOpcode()) {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000075 default: break;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000076 case Hexagon::LDriw:
77 case Hexagon::LDrid:
78 case Hexagon::LDrih:
79 case Hexagon::LDrib:
80 case Hexagon::LDriub:
81 if (MI->getOperand(2).isFI() &&
82 MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) {
83 FrameIndex = MI->getOperand(2).getIndex();
84 return MI->getOperand(0).getReg();
85 }
86 break;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000087 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +000088 return 0;
89}
90
91
92/// isStoreToStackSlot - If the specified machine instruction is a direct
93/// store to a stack slot, return the virtual or physical register number of
94/// the source reg along with the FrameIndex of the loaded stack slot. If
95/// not, return 0. This predicate must return 0 if the instruction has
96/// any side effects other than storing to the stack slot.
97unsigned HexagonInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
98 int &FrameIndex) const {
99 switch (MI->getOpcode()) {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000100 default: break;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000101 case Hexagon::STriw:
102 case Hexagon::STrid:
103 case Hexagon::STrih:
104 case Hexagon::STrib:
105 if (MI->getOperand(2).isFI() &&
106 MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) {
Sirish Pande8bb97452012-05-12 05:54:15 +0000107 FrameIndex = MI->getOperand(0).getIndex();
108 return MI->getOperand(2).getReg();
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000109 }
110 break;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000111 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000112 return 0;
113}
114
115
116unsigned
117HexagonInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB,
118 MachineBasicBlock *FBB,
119 const SmallVectorImpl<MachineOperand> &Cond,
120 DebugLoc DL) const{
121
122 int BOpc = Hexagon::JMP;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000123 int BccOpc = Hexagon::JMP_t;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000124
125 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
126
127 int regPos = 0;
128 // Check if ReverseBranchCondition has asked to reverse this branch
129 // If we want to reverse the branch an odd number of times, we want
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000130 // JMP_f.
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000131 if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) {
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000132 BccOpc = Hexagon::JMP_f;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000133 regPos = 1;
134 }
135
136 if (FBB == 0) {
137 if (Cond.empty()) {
138 // Due to a bug in TailMerging/CFG Optimization, we need to add a
139 // special case handling of a predicated jump followed by an
140 // unconditional jump. If not, Tail Merging and CFG Optimization go
141 // into an infinite loop.
142 MachineBasicBlock *NewTBB, *NewFBB;
143 SmallVector<MachineOperand, 4> Cond;
144 MachineInstr *Term = MBB.getFirstTerminator();
145 if (isPredicated(Term) && !AnalyzeBranch(MBB, NewTBB, NewFBB, Cond,
146 false)) {
147 MachineBasicBlock *NextBB =
148 llvm::next(MachineFunction::iterator(&MBB));
149 if (NewTBB == NextBB) {
150 ReverseBranchCondition(Cond);
151 RemoveBranch(MBB);
152 return InsertBranch(MBB, TBB, 0, Cond, DL);
153 }
154 }
155 BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB);
156 } else {
157 BuildMI(&MBB, DL,
158 get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB);
159 }
160 return 1;
161 }
162
163 BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB);
164 BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB);
165
166 return 2;
167}
168
169
170bool HexagonInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
171 MachineBasicBlock *&TBB,
172 MachineBasicBlock *&FBB,
173 SmallVectorImpl<MachineOperand> &Cond,
174 bool AllowModify) const {
Benjamin Kramer0b03cbd2012-05-13 15:13:22 +0000175 TBB = NULL;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000176 FBB = NULL;
177
178 // If the block has no terminators, it just falls into the block after it.
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000179 MachineBasicBlock::instr_iterator I = MBB.instr_end();
180 if (I == MBB.instr_begin())
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000181 return false;
182
183 // A basic block may looks like this:
184 //
185 // [ insn
186 // EH_LABEL
187 // insn
188 // insn
189 // insn
190 // EH_LABEL
191 // insn ]
192 //
193 // It has two succs but does not have a terminator
194 // Don't know how to handle it.
195 do {
196 --I;
197 if (I->isEHLabel())
198 return true;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000199 } while (I != MBB.instr_begin());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000200
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000201 I = MBB.instr_end();
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000202 --I;
203
204 while (I->isDebugValue()) {
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000205 if (I == MBB.instr_begin())
206 return false;
207 --I;
208 }
209
210 // Delete the JMP if it's equivalent to a fall-through.
211 if (AllowModify && I->getOpcode() == Hexagon::JMP &&
212 MBB.isLayoutSuccessor(I->getOperand(0).getMBB())) {
213 DEBUG(dbgs()<< "\nErasing the jump to successor block\n";);
214 I->eraseFromParent();
215 I = MBB.instr_end();
216 if (I == MBB.instr_begin())
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000217 return false;
218 --I;
219 }
220 if (!isUnpredicatedTerminator(I))
221 return false;
222
223 // Get the last instruction in the block.
224 MachineInstr *LastInst = I;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000225 MachineInstr *SecondLastInst = NULL;
226 // Find one more terminator if present.
227 do {
228 if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(I)) {
229 if (!SecondLastInst)
230 SecondLastInst = I;
231 else
232 // This is a third branch.
233 return true;
234 }
235 if (I == MBB.instr_begin())
236 break;
237 --I;
238 } while(I);
239
240 int LastOpcode = LastInst->getOpcode();
241
242 bool LastOpcodeHasJMP_c = PredOpcodeHasJMP_c(LastOpcode);
243 bool LastOpcodeHasNot = PredOpcodeHasNot(LastOpcode);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000244
245 // If there is only one terminator instruction, process it.
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000246 if (LastInst && !SecondLastInst) {
247 if (LastOpcode == Hexagon::JMP) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000248 TBB = LastInst->getOperand(0).getMBB();
249 return false;
250 }
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000251 if (LastOpcode == Hexagon::ENDLOOP0) {
252 TBB = LastInst->getOperand(0).getMBB();
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000253 Cond.push_back(LastInst->getOperand(0));
254 return false;
255 }
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000256 if (LastOpcodeHasJMP_c) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000257 TBB = LastInst->getOperand(1).getMBB();
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000258 if (LastOpcodeHasNot) {
259 Cond.push_back(MachineOperand::CreateImm(0));
260 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000261 Cond.push_back(LastInst->getOperand(0));
262 return false;
263 }
264 // Otherwise, don't know what this is.
265 return true;
266 }
267
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000268 int SecLastOpcode = SecondLastInst->getOpcode();
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000269
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000270 bool SecLastOpcodeHasJMP_c = PredOpcodeHasJMP_c(SecLastOpcode);
271 bool SecLastOpcodeHasNot = PredOpcodeHasNot(SecLastOpcode);
272 if (SecLastOpcodeHasJMP_c && (LastOpcode == Hexagon::JMP)) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000273 TBB = SecondLastInst->getOperand(1).getMBB();
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000274 if (SecLastOpcodeHasNot)
275 Cond.push_back(MachineOperand::CreateImm(0));
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000276 Cond.push_back(SecondLastInst->getOperand(0));
277 FBB = LastInst->getOperand(0).getMBB();
278 return false;
279 }
280
281 // If the block ends with two Hexagon:JMPs, handle it. The second one is not
282 // executed, so remove it.
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000283 if (SecLastOpcode == Hexagon::JMP && LastOpcode == Hexagon::JMP) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000284 TBB = SecondLastInst->getOperand(0).getMBB();
285 I = LastInst;
286 if (AllowModify)
287 I->eraseFromParent();
288 return false;
289 }
290
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000291 // If the block ends with an ENDLOOP, and JMP, handle it.
292 if (SecLastOpcode == Hexagon::ENDLOOP0 &&
293 LastOpcode == Hexagon::JMP) {
294 TBB = SecondLastInst->getOperand(0).getMBB();
295 Cond.push_back(SecondLastInst->getOperand(0));
296 FBB = LastInst->getOperand(0).getMBB();
297 return false;
298 }
299
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000300 // Otherwise, can't handle this.
301 return true;
302}
303
304
305unsigned HexagonInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
306 int BOpc = Hexagon::JMP;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000307 int BccOpc = Hexagon::JMP_t;
308 int BccOpcNot = Hexagon::JMP_f;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000309
310 MachineBasicBlock::iterator I = MBB.end();
311 if (I == MBB.begin()) return 0;
312 --I;
313 if (I->getOpcode() != BOpc && I->getOpcode() != BccOpc &&
314 I->getOpcode() != BccOpcNot)
315 return 0;
316
317 // Remove the branch.
318 I->eraseFromParent();
319
320 I = MBB.end();
321
322 if (I == MBB.begin()) return 1;
323 --I;
324 if (I->getOpcode() != BccOpc && I->getOpcode() != BccOpcNot)
325 return 1;
326
327 // Remove the branch.
328 I->eraseFromParent();
329 return 2;
330}
331
332
Krzysztof Parzyszekcfe285e2013-02-11 20:04:29 +0000333/// \brief For a comparison instruction, return the source registers in
334/// \p SrcReg and \p SrcReg2 if having two register operands, and the value it
335/// compares against in CmpValue. Return true if the comparison instruction
336/// can be analyzed.
337bool HexagonInstrInfo::analyzeCompare(const MachineInstr *MI,
338 unsigned &SrcReg, unsigned &SrcReg2,
339 int &Mask, int &Value) const {
340 unsigned Opc = MI->getOpcode();
341
342 // Set mask and the first source register.
343 switch (Opc) {
344 case Hexagon::CMPEHexagon4rr:
345 case Hexagon::CMPEQri:
346 case Hexagon::CMPEQrr:
347 case Hexagon::CMPGT64rr:
348 case Hexagon::CMPGTU64rr:
349 case Hexagon::CMPGTUri:
350 case Hexagon::CMPGTUrr:
351 case Hexagon::CMPGTri:
352 case Hexagon::CMPGTrr:
Krzysztof Parzyszekcfe285e2013-02-11 20:04:29 +0000353 SrcReg = MI->getOperand(1).getReg();
354 Mask = ~0;
355 break;
356 case Hexagon::CMPbEQri_V4:
357 case Hexagon::CMPbEQrr_sbsb_V4:
358 case Hexagon::CMPbEQrr_ubub_V4:
359 case Hexagon::CMPbGTUri_V4:
360 case Hexagon::CMPbGTUrr_V4:
361 case Hexagon::CMPbGTrr_V4:
362 SrcReg = MI->getOperand(1).getReg();
363 Mask = 0xFF;
364 break;
365 case Hexagon::CMPhEQri_V4:
366 case Hexagon::CMPhEQrr_shl_V4:
367 case Hexagon::CMPhEQrr_xor_V4:
368 case Hexagon::CMPhGTUri_V4:
369 case Hexagon::CMPhGTUrr_V4:
370 case Hexagon::CMPhGTrr_shl_V4:
371 SrcReg = MI->getOperand(1).getReg();
372 Mask = 0xFFFF;
373 break;
374 }
375
376 // Set the value/second source register.
377 switch (Opc) {
378 case Hexagon::CMPEHexagon4rr:
379 case Hexagon::CMPEQrr:
380 case Hexagon::CMPGT64rr:
381 case Hexagon::CMPGTU64rr:
382 case Hexagon::CMPGTUrr:
383 case Hexagon::CMPGTrr:
384 case Hexagon::CMPbEQrr_sbsb_V4:
385 case Hexagon::CMPbEQrr_ubub_V4:
386 case Hexagon::CMPbGTUrr_V4:
387 case Hexagon::CMPbGTrr_V4:
388 case Hexagon::CMPhEQrr_shl_V4:
389 case Hexagon::CMPhEQrr_xor_V4:
390 case Hexagon::CMPhGTUrr_V4:
391 case Hexagon::CMPhGTrr_shl_V4:
Krzysztof Parzyszekcfe285e2013-02-11 20:04:29 +0000392 SrcReg2 = MI->getOperand(2).getReg();
393 return true;
394
395 case Hexagon::CMPEQri:
396 case Hexagon::CMPGTUri:
397 case Hexagon::CMPGTri:
398 case Hexagon::CMPbEQri_V4:
399 case Hexagon::CMPbGTUri_V4:
400 case Hexagon::CMPhEQri_V4:
401 case Hexagon::CMPhGTUri_V4:
402 SrcReg2 = 0;
403 Value = MI->getOperand(2).getImm();
404 return true;
405 }
406
407 return false;
408}
409
410
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000411void HexagonInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
412 MachineBasicBlock::iterator I, DebugLoc DL,
413 unsigned DestReg, unsigned SrcReg,
414 bool KillSrc) const {
415 if (Hexagon::IntRegsRegClass.contains(SrcReg, DestReg)) {
416 BuildMI(MBB, I, DL, get(Hexagon::TFR), DestReg).addReg(SrcReg);
417 return;
418 }
419 if (Hexagon::DoubleRegsRegClass.contains(SrcReg, DestReg)) {
Jyotsna Vermae95559f2012-11-29 19:35:44 +0000420 BuildMI(MBB, I, DL, get(Hexagon::TFR64), DestReg).addReg(SrcReg);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000421 return;
422 }
423 if (Hexagon::PredRegsRegClass.contains(SrcReg, DestReg)) {
424 // Map Pd = Ps to Pd = or(Ps, Ps).
425 BuildMI(MBB, I, DL, get(Hexagon::OR_pp),
426 DestReg).addReg(SrcReg).addReg(SrcReg);
427 return;
428 }
Sirish Pande8bb97452012-05-12 05:54:15 +0000429 if (Hexagon::DoubleRegsRegClass.contains(DestReg) &&
430 Hexagon::IntRegsRegClass.contains(SrcReg)) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000431 // We can have an overlap between single and double reg: r1:0 = r0.
432 if(SrcReg == RI.getSubReg(DestReg, Hexagon::subreg_loreg)) {
433 // r1:0 = r0
434 BuildMI(MBB, I, DL, get(Hexagon::TFRI), (RI.getSubReg(DestReg,
435 Hexagon::subreg_hireg))).addImm(0);
436 } else {
437 // r1:0 = r1 or no overlap.
438 BuildMI(MBB, I, DL, get(Hexagon::TFR), (RI.getSubReg(DestReg,
439 Hexagon::subreg_loreg))).addReg(SrcReg);
440 BuildMI(MBB, I, DL, get(Hexagon::TFRI), (RI.getSubReg(DestReg,
441 Hexagon::subreg_hireg))).addImm(0);
442 }
443 return;
444 }
Sirish Pande8bb97452012-05-12 05:54:15 +0000445 if (Hexagon::CRRegsRegClass.contains(DestReg) &&
446 Hexagon::IntRegsRegClass.contains(SrcReg)) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000447 BuildMI(MBB, I, DL, get(Hexagon::TFCR), DestReg).addReg(SrcReg);
448 return;
Sirish Pande30804c22012-02-15 18:52:27 +0000449 }
Anshuman Dasguptae96f8042013-02-13 22:56:34 +0000450 if (Hexagon::PredRegsRegClass.contains(SrcReg) &&
451 Hexagon::IntRegsRegClass.contains(DestReg)) {
452 BuildMI(MBB, I, DL, get(Hexagon::TFR_RsPd), DestReg).
453 addReg(SrcReg, getKillRegState(KillSrc));
454 return;
455 }
456 if (Hexagon::IntRegsRegClass.contains(SrcReg) &&
457 Hexagon::PredRegsRegClass.contains(DestReg)) {
458 BuildMI(MBB, I, DL, get(Hexagon::TFR_PdRs), DestReg).
459 addReg(SrcReg, getKillRegState(KillSrc));
460 return;
461 }
Sirish Pande30804c22012-02-15 18:52:27 +0000462
463 llvm_unreachable("Unimplemented");
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000464}
465
466
467void HexagonInstrInfo::
468storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
469 unsigned SrcReg, bool isKill, int FI,
470 const TargetRegisterClass *RC,
471 const TargetRegisterInfo *TRI) const {
472
473 DebugLoc DL = MBB.findDebugLoc(I);
474 MachineFunction &MF = *MBB.getParent();
475 MachineFrameInfo &MFI = *MF.getFrameInfo();
476 unsigned Align = MFI.getObjectAlignment(FI);
477
478 MachineMemOperand *MMO =
479 MF.getMachineMemOperand(
480 MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)),
481 MachineMemOperand::MOStore,
482 MFI.getObjectSize(FI),
483 Align);
484
Craig Topperc7242e02012-04-20 07:30:17 +0000485 if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) {
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000486 BuildMI(MBB, I, DL, get(Hexagon::STriw))
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000487 .addFrameIndex(FI).addImm(0)
488 .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
Craig Topperc7242e02012-04-20 07:30:17 +0000489 } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000490 BuildMI(MBB, I, DL, get(Hexagon::STrid))
491 .addFrameIndex(FI).addImm(0)
492 .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
Craig Topperc7242e02012-04-20 07:30:17 +0000493 } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000494 BuildMI(MBB, I, DL, get(Hexagon::STriw_pred))
495 .addFrameIndex(FI).addImm(0)
496 .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
497 } else {
Craig Toppere55c5562012-02-07 02:50:20 +0000498 llvm_unreachable("Unimplemented");
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000499 }
500}
501
502
503void HexagonInstrInfo::storeRegToAddr(
504 MachineFunction &MF, unsigned SrcReg,
505 bool isKill,
506 SmallVectorImpl<MachineOperand> &Addr,
507 const TargetRegisterClass *RC,
508 SmallVectorImpl<MachineInstr*> &NewMIs) const
509{
Craig Toppere55c5562012-02-07 02:50:20 +0000510 llvm_unreachable("Unimplemented");
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000511}
512
513
514void HexagonInstrInfo::
515loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
516 unsigned DestReg, int FI,
517 const TargetRegisterClass *RC,
518 const TargetRegisterInfo *TRI) const {
519 DebugLoc DL = MBB.findDebugLoc(I);
520 MachineFunction &MF = *MBB.getParent();
521 MachineFrameInfo &MFI = *MF.getFrameInfo();
522 unsigned Align = MFI.getObjectAlignment(FI);
523
524 MachineMemOperand *MMO =
525 MF.getMachineMemOperand(
526 MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)),
527 MachineMemOperand::MOLoad,
528 MFI.getObjectSize(FI),
529 Align);
Craig Topperc7242e02012-04-20 07:30:17 +0000530 if (RC == &Hexagon::IntRegsRegClass) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000531 BuildMI(MBB, I, DL, get(Hexagon::LDriw), DestReg)
532 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
Craig Topperc7242e02012-04-20 07:30:17 +0000533 } else if (RC == &Hexagon::DoubleRegsRegClass) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000534 BuildMI(MBB, I, DL, get(Hexagon::LDrid), DestReg)
535 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
Craig Topperc7242e02012-04-20 07:30:17 +0000536 } else if (RC == &Hexagon::PredRegsRegClass) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000537 BuildMI(MBB, I, DL, get(Hexagon::LDriw_pred), DestReg)
538 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
539 } else {
Craig Toppere55c5562012-02-07 02:50:20 +0000540 llvm_unreachable("Can't store this register to stack slot");
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000541 }
542}
543
544
545void HexagonInstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
546 SmallVectorImpl<MachineOperand> &Addr,
547 const TargetRegisterClass *RC,
548 SmallVectorImpl<MachineInstr*> &NewMIs) const {
Craig Toppere55c5562012-02-07 02:50:20 +0000549 llvm_unreachable("Unimplemented");
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000550}
551
552
553MachineInstr *HexagonInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
554 MachineInstr* MI,
555 const SmallVectorImpl<unsigned> &Ops,
556 int FI) const {
557 // Hexagon_TODO: Implement.
558 return(0);
559}
560
Jyotsna Vermaadd82b32013-03-29 21:09:53 +0000561MachineInstr*
562HexagonInstrInfo::emitFrameIndexDebugValue(MachineFunction &MF,
563 int FrameIx, uint64_t Offset,
564 const MDNode *MDPtr,
565 DebugLoc DL) const {
566 MachineInstrBuilder MIB = BuildMI(MF, DL, get(Hexagon::DBG_VALUE))
567 .addImm(0).addImm(Offset).addMetadata(MDPtr);
568 return &*MIB;
569}
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000570
571unsigned HexagonInstrInfo::createVR(MachineFunction* MF, MVT VT) const {
572
573 MachineRegisterInfo &RegInfo = MF->getRegInfo();
574 const TargetRegisterClass *TRC;
Sirish Pande69295b82012-05-10 20:20:25 +0000575 if (VT == MVT::i1) {
Craig Topperc7242e02012-04-20 07:30:17 +0000576 TRC = &Hexagon::PredRegsRegClass;
Sirish Pande69295b82012-05-10 20:20:25 +0000577 } else if (VT == MVT::i32 || VT == MVT::f32) {
Craig Topperc7242e02012-04-20 07:30:17 +0000578 TRC = &Hexagon::IntRegsRegClass;
Sirish Pande69295b82012-05-10 20:20:25 +0000579 } else if (VT == MVT::i64 || VT == MVT::f64) {
Craig Topperc7242e02012-04-20 07:30:17 +0000580 TRC = &Hexagon::DoubleRegsRegClass;
Sirish Pande69295b82012-05-10 20:20:25 +0000581 } else {
Benjamin Kramerb6684012011-12-27 11:41:05 +0000582 llvm_unreachable("Cannot handle this register class");
Sirish Pande69295b82012-05-10 20:20:25 +0000583 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000584
585 unsigned NewReg = RegInfo.createVirtualRegister(TRC);
586 return NewReg;
587}
588
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000589bool HexagonInstrInfo::isExtendable(const MachineInstr *MI) const {
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000590 // Constant extenders are allowed only for V4 and above.
591 if (!Subtarget.hasV4TOps())
592 return false;
593
594 const MCInstrDesc &MID = MI->getDesc();
595 const uint64_t F = MID.TSFlags;
596 if ((F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask)
597 return true;
598
599 // TODO: This is largely obsolete now. Will need to be removed
600 // in consecutive patches.
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000601 switch(MI->getOpcode()) {
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000602 // TFR_FI Remains a special case.
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000603 case Hexagon::TFR_FI:
604 return true;
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000605 default:
606 return false;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000607 }
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000608 return false;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000609}
610
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000611// This returns true in two cases:
612// - The OP code itself indicates that this is an extended instruction.
613// - One of MOs has been marked with HMOTF_ConstExtended flag.
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000614bool HexagonInstrInfo::isExtended(const MachineInstr *MI) const {
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000615 // First check if this is permanently extended op code.
616 const uint64_t F = MI->getDesc().TSFlags;
617 if ((F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask)
618 return true;
619 // Use MO operand flags to determine if one of MI's operands
620 // has HMOTF_ConstExtended flag set.
621 for (MachineInstr::const_mop_iterator I = MI->operands_begin(),
622 E = MI->operands_end(); I != E; ++I) {
623 if (I->getTargetFlags() && HexagonII::HMOTF_ConstExtended)
Sirish Pande69295b82012-05-10 20:20:25 +0000624 return true;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000625 }
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000626 return false;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000627}
628
Jyotsna Vermaa841af72013-05-02 22:10:59 +0000629bool HexagonInstrInfo::isNewValueJump(const MachineInstr *MI) const {
630 switch (MI->getOpcode()) {
631 default: return false;
632 // JMP_EQri
633 case Hexagon::JMP_EQriPt_nv_V4:
634 case Hexagon::JMP_EQriPnt_nv_V4:
635 case Hexagon::JMP_EQriNotPt_nv_V4:
636 case Hexagon::JMP_EQriNotPnt_nv_V4:
637 case Hexagon::JMP_EQriPt_ie_nv_V4:
638 case Hexagon::JMP_EQriPnt_ie_nv_V4:
639 case Hexagon::JMP_EQriNotPt_ie_nv_V4:
640 case Hexagon::JMP_EQriNotPnt_ie_nv_V4:
641
642 // JMP_EQri - with -1
643 case Hexagon::JMP_EQriPtneg_nv_V4:
644 case Hexagon::JMP_EQriPntneg_nv_V4:
645 case Hexagon::JMP_EQriNotPtneg_nv_V4:
646 case Hexagon::JMP_EQriNotPntneg_nv_V4:
647 case Hexagon::JMP_EQriPtneg_ie_nv_V4:
648 case Hexagon::JMP_EQriPntneg_ie_nv_V4:
649 case Hexagon::JMP_EQriNotPtneg_ie_nv_V4:
650 case Hexagon::JMP_EQriNotPntneg_ie_nv_V4:
651
652 // JMP_EQrr
653 case Hexagon::JMP_EQrrPt_nv_V4:
654 case Hexagon::JMP_EQrrPnt_nv_V4:
655 case Hexagon::JMP_EQrrNotPt_nv_V4:
656 case Hexagon::JMP_EQrrNotPnt_nv_V4:
657 case Hexagon::JMP_EQrrPt_ie_nv_V4:
658 case Hexagon::JMP_EQrrPnt_ie_nv_V4:
659 case Hexagon::JMP_EQrrNotPt_ie_nv_V4:
660 case Hexagon::JMP_EQrrNotPnt_ie_nv_V4:
661
662 // JMP_GTri
663 case Hexagon::JMP_GTriPt_nv_V4:
664 case Hexagon::JMP_GTriPnt_nv_V4:
665 case Hexagon::JMP_GTriNotPt_nv_V4:
666 case Hexagon::JMP_GTriNotPnt_nv_V4:
667 case Hexagon::JMP_GTriPt_ie_nv_V4:
668 case Hexagon::JMP_GTriPnt_ie_nv_V4:
669 case Hexagon::JMP_GTriNotPt_ie_nv_V4:
670 case Hexagon::JMP_GTriNotPnt_ie_nv_V4:
671
672 // JMP_GTri - with -1
673 case Hexagon::JMP_GTriPtneg_nv_V4:
674 case Hexagon::JMP_GTriPntneg_nv_V4:
675 case Hexagon::JMP_GTriNotPtneg_nv_V4:
676 case Hexagon::JMP_GTriNotPntneg_nv_V4:
677 case Hexagon::JMP_GTriPtneg_ie_nv_V4:
678 case Hexagon::JMP_GTriPntneg_ie_nv_V4:
679 case Hexagon::JMP_GTriNotPtneg_ie_nv_V4:
680 case Hexagon::JMP_GTriNotPntneg_ie_nv_V4:
681
682 // JMP_GTrr
683 case Hexagon::JMP_GTrrPt_nv_V4:
684 case Hexagon::JMP_GTrrPnt_nv_V4:
685 case Hexagon::JMP_GTrrNotPt_nv_V4:
686 case Hexagon::JMP_GTrrNotPnt_nv_V4:
687 case Hexagon::JMP_GTrrPt_ie_nv_V4:
688 case Hexagon::JMP_GTrrPnt_ie_nv_V4:
689 case Hexagon::JMP_GTrrNotPt_ie_nv_V4:
690 case Hexagon::JMP_GTrrNotPnt_ie_nv_V4:
691
692 // JMP_GTrrdn
693 case Hexagon::JMP_GTrrdnPt_nv_V4:
694 case Hexagon::JMP_GTrrdnPnt_nv_V4:
695 case Hexagon::JMP_GTrrdnNotPt_nv_V4:
696 case Hexagon::JMP_GTrrdnNotPnt_nv_V4:
697 case Hexagon::JMP_GTrrdnPt_ie_nv_V4:
698 case Hexagon::JMP_GTrrdnPnt_ie_nv_V4:
699 case Hexagon::JMP_GTrrdnNotPt_ie_nv_V4:
700 case Hexagon::JMP_GTrrdnNotPnt_ie_nv_V4:
701
702 // JMP_GTUri
703 case Hexagon::JMP_GTUriPt_nv_V4:
704 case Hexagon::JMP_GTUriPnt_nv_V4:
705 case Hexagon::JMP_GTUriNotPt_nv_V4:
706 case Hexagon::JMP_GTUriNotPnt_nv_V4:
707 case Hexagon::JMP_GTUriPt_ie_nv_V4:
708 case Hexagon::JMP_GTUriPnt_ie_nv_V4:
709 case Hexagon::JMP_GTUriNotPt_ie_nv_V4:
710 case Hexagon::JMP_GTUriNotPnt_ie_nv_V4:
711
712 // JMP_GTUrr
713 case Hexagon::JMP_GTUrrPt_nv_V4:
714 case Hexagon::JMP_GTUrrPnt_nv_V4:
715 case Hexagon::JMP_GTUrrNotPt_nv_V4:
716 case Hexagon::JMP_GTUrrNotPnt_nv_V4:
717 case Hexagon::JMP_GTUrrPt_ie_nv_V4:
718 case Hexagon::JMP_GTUrrPnt_ie_nv_V4:
719 case Hexagon::JMP_GTUrrNotPt_ie_nv_V4:
720 case Hexagon::JMP_GTUrrNotPnt_ie_nv_V4:
721
722 // JMP_GTUrrdn
723 case Hexagon::JMP_GTUrrdnPt_nv_V4:
724 case Hexagon::JMP_GTUrrdnPnt_nv_V4:
725 case Hexagon::JMP_GTUrrdnNotPt_nv_V4:
726 case Hexagon::JMP_GTUrrdnNotPnt_nv_V4:
727 case Hexagon::JMP_GTUrrdnPt_ie_nv_V4:
728 case Hexagon::JMP_GTUrrdnPnt_ie_nv_V4:
729 case Hexagon::JMP_GTUrrdnNotPt_ie_nv_V4:
730 case Hexagon::JMP_GTUrrdnNotPnt_ie_nv_V4:
731 return true;
732 }
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000733}
734
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000735bool HexagonInstrInfo::isNewValueStore(const MachineInstr *MI) const {
736 switch (MI->getOpcode()) {
737 default: return false;
738 // Store Byte
739 case Hexagon::STrib_nv_V4:
740 case Hexagon::STrib_indexed_nv_V4:
741 case Hexagon::STrib_indexed_shl_nv_V4:
742 case Hexagon::STrib_shl_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000743 case Hexagon::STb_GP_nv_V4:
744 case Hexagon::POST_STbri_nv_V4:
745 case Hexagon::STrib_cPt_nv_V4:
746 case Hexagon::STrib_cdnPt_nv_V4:
747 case Hexagon::STrib_cNotPt_nv_V4:
748 case Hexagon::STrib_cdnNotPt_nv_V4:
749 case Hexagon::STrib_indexed_cPt_nv_V4:
750 case Hexagon::STrib_indexed_cdnPt_nv_V4:
751 case Hexagon::STrib_indexed_cNotPt_nv_V4:
752 case Hexagon::STrib_indexed_cdnNotPt_nv_V4:
753 case Hexagon::STrib_indexed_shl_cPt_nv_V4:
754 case Hexagon::STrib_indexed_shl_cdnPt_nv_V4:
755 case Hexagon::STrib_indexed_shl_cNotPt_nv_V4:
756 case Hexagon::STrib_indexed_shl_cdnNotPt_nv_V4:
757 case Hexagon::POST_STbri_cPt_nv_V4:
758 case Hexagon::POST_STbri_cdnPt_nv_V4:
759 case Hexagon::POST_STbri_cNotPt_nv_V4:
760 case Hexagon::POST_STbri_cdnNotPt_nv_V4:
761 case Hexagon::STb_GP_cPt_nv_V4:
762 case Hexagon::STb_GP_cNotPt_nv_V4:
763 case Hexagon::STb_GP_cdnPt_nv_V4:
764 case Hexagon::STb_GP_cdnNotPt_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000765 case Hexagon::STrib_abs_nv_V4:
766 case Hexagon::STrib_abs_cPt_nv_V4:
767 case Hexagon::STrib_abs_cdnPt_nv_V4:
768 case Hexagon::STrib_abs_cNotPt_nv_V4:
769 case Hexagon::STrib_abs_cdnNotPt_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000770
771 // Store Halfword
772 case Hexagon::STrih_nv_V4:
773 case Hexagon::STrih_indexed_nv_V4:
774 case Hexagon::STrih_indexed_shl_nv_V4:
775 case Hexagon::STrih_shl_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000776 case Hexagon::STh_GP_nv_V4:
777 case Hexagon::POST_SThri_nv_V4:
778 case Hexagon::STrih_cPt_nv_V4:
779 case Hexagon::STrih_cdnPt_nv_V4:
780 case Hexagon::STrih_cNotPt_nv_V4:
781 case Hexagon::STrih_cdnNotPt_nv_V4:
782 case Hexagon::STrih_indexed_cPt_nv_V4:
783 case Hexagon::STrih_indexed_cdnPt_nv_V4:
784 case Hexagon::STrih_indexed_cNotPt_nv_V4:
785 case Hexagon::STrih_indexed_cdnNotPt_nv_V4:
786 case Hexagon::STrih_indexed_shl_cPt_nv_V4:
787 case Hexagon::STrih_indexed_shl_cdnPt_nv_V4:
788 case Hexagon::STrih_indexed_shl_cNotPt_nv_V4:
789 case Hexagon::STrih_indexed_shl_cdnNotPt_nv_V4:
790 case Hexagon::POST_SThri_cPt_nv_V4:
791 case Hexagon::POST_SThri_cdnPt_nv_V4:
792 case Hexagon::POST_SThri_cNotPt_nv_V4:
793 case Hexagon::POST_SThri_cdnNotPt_nv_V4:
794 case Hexagon::STh_GP_cPt_nv_V4:
795 case Hexagon::STh_GP_cNotPt_nv_V4:
796 case Hexagon::STh_GP_cdnPt_nv_V4:
797 case Hexagon::STh_GP_cdnNotPt_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000798 case Hexagon::STrih_abs_nv_V4:
799 case Hexagon::STrih_abs_cPt_nv_V4:
800 case Hexagon::STrih_abs_cdnPt_nv_V4:
801 case Hexagon::STrih_abs_cNotPt_nv_V4:
802 case Hexagon::STrih_abs_cdnNotPt_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000803
804 // Store Word
805 case Hexagon::STriw_nv_V4:
806 case Hexagon::STriw_indexed_nv_V4:
807 case Hexagon::STriw_indexed_shl_nv_V4:
808 case Hexagon::STriw_shl_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000809 case Hexagon::STw_GP_nv_V4:
810 case Hexagon::POST_STwri_nv_V4:
811 case Hexagon::STriw_cPt_nv_V4:
812 case Hexagon::STriw_cdnPt_nv_V4:
813 case Hexagon::STriw_cNotPt_nv_V4:
814 case Hexagon::STriw_cdnNotPt_nv_V4:
815 case Hexagon::STriw_indexed_cPt_nv_V4:
816 case Hexagon::STriw_indexed_cdnPt_nv_V4:
817 case Hexagon::STriw_indexed_cNotPt_nv_V4:
818 case Hexagon::STriw_indexed_cdnNotPt_nv_V4:
819 case Hexagon::STriw_indexed_shl_cPt_nv_V4:
820 case Hexagon::STriw_indexed_shl_cdnPt_nv_V4:
821 case Hexagon::STriw_indexed_shl_cNotPt_nv_V4:
822 case Hexagon::STriw_indexed_shl_cdnNotPt_nv_V4:
823 case Hexagon::POST_STwri_cPt_nv_V4:
824 case Hexagon::POST_STwri_cdnPt_nv_V4:
825 case Hexagon::POST_STwri_cNotPt_nv_V4:
826 case Hexagon::POST_STwri_cdnNotPt_nv_V4:
827 case Hexagon::STw_GP_cPt_nv_V4:
828 case Hexagon::STw_GP_cNotPt_nv_V4:
829 case Hexagon::STw_GP_cdnPt_nv_V4:
830 case Hexagon::STw_GP_cdnNotPt_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000831 case Hexagon::STriw_abs_nv_V4:
832 case Hexagon::STriw_abs_cPt_nv_V4:
833 case Hexagon::STriw_abs_cdnPt_nv_V4:
834 case Hexagon::STriw_abs_cNotPt_nv_V4:
835 case Hexagon::STriw_abs_cdnNotPt_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000836 return true;
837 }
838}
839
840bool HexagonInstrInfo::isPostIncrement (const MachineInstr* MI) const {
841 switch (MI->getOpcode())
842 {
843 default: return false;
844 // Load Byte
845 case Hexagon::POST_LDrib:
846 case Hexagon::POST_LDrib_cPt:
847 case Hexagon::POST_LDrib_cNotPt:
848 case Hexagon::POST_LDrib_cdnPt_V4:
849 case Hexagon::POST_LDrib_cdnNotPt_V4:
850
851 // Load unsigned byte
852 case Hexagon::POST_LDriub:
853 case Hexagon::POST_LDriub_cPt:
854 case Hexagon::POST_LDriub_cNotPt:
855 case Hexagon::POST_LDriub_cdnPt_V4:
856 case Hexagon::POST_LDriub_cdnNotPt_V4:
857
858 // Load halfword
859 case Hexagon::POST_LDrih:
860 case Hexagon::POST_LDrih_cPt:
861 case Hexagon::POST_LDrih_cNotPt:
862 case Hexagon::POST_LDrih_cdnPt_V4:
863 case Hexagon::POST_LDrih_cdnNotPt_V4:
864
865 // Load unsigned halfword
866 case Hexagon::POST_LDriuh:
867 case Hexagon::POST_LDriuh_cPt:
868 case Hexagon::POST_LDriuh_cNotPt:
869 case Hexagon::POST_LDriuh_cdnPt_V4:
870 case Hexagon::POST_LDriuh_cdnNotPt_V4:
871
872 // Load word
873 case Hexagon::POST_LDriw:
874 case Hexagon::POST_LDriw_cPt:
875 case Hexagon::POST_LDriw_cNotPt:
876 case Hexagon::POST_LDriw_cdnPt_V4:
877 case Hexagon::POST_LDriw_cdnNotPt_V4:
878
879 // Load double word
880 case Hexagon::POST_LDrid:
881 case Hexagon::POST_LDrid_cPt:
882 case Hexagon::POST_LDrid_cNotPt:
883 case Hexagon::POST_LDrid_cdnPt_V4:
884 case Hexagon::POST_LDrid_cdnNotPt_V4:
885
886 // Store byte
887 case Hexagon::POST_STbri:
888 case Hexagon::POST_STbri_cPt:
889 case Hexagon::POST_STbri_cNotPt:
890 case Hexagon::POST_STbri_cdnPt_V4:
891 case Hexagon::POST_STbri_cdnNotPt_V4:
892
893 // Store halfword
894 case Hexagon::POST_SThri:
895 case Hexagon::POST_SThri_cPt:
896 case Hexagon::POST_SThri_cNotPt:
897 case Hexagon::POST_SThri_cdnPt_V4:
898 case Hexagon::POST_SThri_cdnNotPt_V4:
899
900 // Store word
901 case Hexagon::POST_STwri:
902 case Hexagon::POST_STwri_cPt:
903 case Hexagon::POST_STwri_cNotPt:
904 case Hexagon::POST_STwri_cdnPt_V4:
905 case Hexagon::POST_STwri_cdnNotPt_V4:
906
907 // Store double word
908 case Hexagon::POST_STdri:
909 case Hexagon::POST_STdri_cPt:
910 case Hexagon::POST_STdri_cNotPt:
911 case Hexagon::POST_STdri_cdnPt_V4:
912 case Hexagon::POST_STdri_cdnNotPt_V4:
913 return true;
914 }
915}
916
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000917bool HexagonInstrInfo::isNewValueInst(const MachineInstr *MI) const {
918 if (isNewValueJump(MI))
919 return true;
920
921 if (isNewValueStore(MI))
922 return true;
923
924 return false;
925}
926
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000927bool HexagonInstrInfo::isSaveCalleeSavedRegsCall(const MachineInstr *MI) const {
928 return MI->getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4;
929}
Andrew Trickd06df962012-02-01 22:13:57 +0000930
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000931bool HexagonInstrInfo::isPredicable(MachineInstr *MI) const {
932 bool isPred = MI->getDesc().isPredicable();
933
934 if (!isPred)
935 return false;
936
937 const int Opc = MI->getOpcode();
938
939 switch(Opc) {
940 case Hexagon::TFRI:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000941 return isInt<12>(MI->getOperand(1).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000942
943 case Hexagon::STrid:
944 case Hexagon::STrid_indexed:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000945 return isShiftedUInt<6,3>(MI->getOperand(1).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000946
947 case Hexagon::STriw:
948 case Hexagon::STriw_indexed:
949 case Hexagon::STriw_nv_V4:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000950 return isShiftedUInt<6,2>(MI->getOperand(1).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000951
952 case Hexagon::STrih:
953 case Hexagon::STrih_indexed:
954 case Hexagon::STrih_nv_V4:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000955 return isShiftedUInt<6,1>(MI->getOperand(1).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000956
957 case Hexagon::STrib:
958 case Hexagon::STrib_indexed:
959 case Hexagon::STrib_nv_V4:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000960 return isUInt<6>(MI->getOperand(1).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000961
962 case Hexagon::LDrid:
963 case Hexagon::LDrid_indexed:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000964 return isShiftedUInt<6,3>(MI->getOperand(2).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000965
966 case Hexagon::LDriw:
967 case Hexagon::LDriw_indexed:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000968 return isShiftedUInt<6,2>(MI->getOperand(2).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000969
970 case Hexagon::LDrih:
971 case Hexagon::LDriuh:
972 case Hexagon::LDrih_indexed:
973 case Hexagon::LDriuh_indexed:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000974 return isShiftedUInt<6,1>(MI->getOperand(2).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000975
976 case Hexagon::LDrib:
977 case Hexagon::LDriub:
978 case Hexagon::LDrib_indexed:
979 case Hexagon::LDriub_indexed:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000980 return isUInt<6>(MI->getOperand(2).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000981
982 case Hexagon::POST_LDrid:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000983 return isShiftedInt<4,3>(MI->getOperand(3).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000984
985 case Hexagon::POST_LDriw:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000986 return isShiftedInt<4,2>(MI->getOperand(3).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000987
988 case Hexagon::POST_LDrih:
989 case Hexagon::POST_LDriuh:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000990 return isShiftedInt<4,1>(MI->getOperand(3).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000991
992 case Hexagon::POST_LDrib:
993 case Hexagon::POST_LDriub:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000994 return isInt<4>(MI->getOperand(3).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000995
996 case Hexagon::STrib_imm_V4:
997 case Hexagon::STrih_imm_V4:
998 case Hexagon::STriw_imm_V4:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000999 return (isUInt<6>(MI->getOperand(1).getImm()) &&
1000 isInt<6>(MI->getOperand(2).getImm()));
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001001
1002 case Hexagon::ADD_ri:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +00001003 return isInt<8>(MI->getOperand(2).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001004
1005 case Hexagon::ASLH:
1006 case Hexagon::ASRH:
1007 case Hexagon::SXTB:
1008 case Hexagon::SXTH:
1009 case Hexagon::ZXTB:
1010 case Hexagon::ZXTH:
Sirish Pande8bb97452012-05-12 05:54:15 +00001011 return Subtarget.hasV4TOps();
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001012 }
1013
1014 return true;
1015}
1016
Sirish Pande8bb97452012-05-12 05:54:15 +00001017// This function performs the following inversiones:
1018//
1019// cPt ---> cNotPt
1020// cNotPt ---> cPt
1021//
1022// however, these inversiones are NOT included:
1023//
1024// cdnPt -X-> cdnNotPt
1025// cdnNotPt -X-> cdnPt
1026// cPt_nv -X-> cNotPt_nv (new value stores)
1027// cNotPt_nv -X-> cPt_nv (new value stores)
1028//
1029// because only the following transformations are allowed:
1030//
1031// cNotPt ---> cdnNotPt
1032// cPt ---> cdnPt
1033// cNotPt ---> cNotPt_nv
1034// cPt ---> cPt_nv
Sirish Pande30804c22012-02-15 18:52:27 +00001035unsigned HexagonInstrInfo::getInvertedPredicatedOpcode(const int Opc) const {
1036 switch(Opc) {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001037 default: llvm_unreachable("Unexpected predicated instruction");
Sirish Pande30804c22012-02-15 18:52:27 +00001038 case Hexagon::TFR_cPt:
1039 return Hexagon::TFR_cNotPt;
1040 case Hexagon::TFR_cNotPt:
1041 return Hexagon::TFR_cPt;
1042
1043 case Hexagon::TFRI_cPt:
1044 return Hexagon::TFRI_cNotPt;
1045 case Hexagon::TFRI_cNotPt:
1046 return Hexagon::TFRI_cPt;
1047
Jyotsna Verma5ed51812013-05-01 21:37:34 +00001048 case Hexagon::JMP_t:
1049 return Hexagon::JMP_f;
1050 case Hexagon::JMP_f:
1051 return Hexagon::JMP_t;
Sirish Pande30804c22012-02-15 18:52:27 +00001052
1053 case Hexagon::ADD_ri_cPt:
1054 return Hexagon::ADD_ri_cNotPt;
1055 case Hexagon::ADD_ri_cNotPt:
1056 return Hexagon::ADD_ri_cPt;
1057
1058 case Hexagon::ADD_rr_cPt:
1059 return Hexagon::ADD_rr_cNotPt;
1060 case Hexagon::ADD_rr_cNotPt:
1061 return Hexagon::ADD_rr_cPt;
1062
1063 case Hexagon::XOR_rr_cPt:
1064 return Hexagon::XOR_rr_cNotPt;
1065 case Hexagon::XOR_rr_cNotPt:
1066 return Hexagon::XOR_rr_cPt;
1067
1068 case Hexagon::AND_rr_cPt:
1069 return Hexagon::AND_rr_cNotPt;
1070 case Hexagon::AND_rr_cNotPt:
1071 return Hexagon::AND_rr_cPt;
1072
1073 case Hexagon::OR_rr_cPt:
1074 return Hexagon::OR_rr_cNotPt;
1075 case Hexagon::OR_rr_cNotPt:
1076 return Hexagon::OR_rr_cPt;
1077
1078 case Hexagon::SUB_rr_cPt:
1079 return Hexagon::SUB_rr_cNotPt;
1080 case Hexagon::SUB_rr_cNotPt:
1081 return Hexagon::SUB_rr_cPt;
1082
1083 case Hexagon::COMBINE_rr_cPt:
1084 return Hexagon::COMBINE_rr_cNotPt;
1085 case Hexagon::COMBINE_rr_cNotPt:
1086 return Hexagon::COMBINE_rr_cPt;
1087
1088 case Hexagon::ASLH_cPt_V4:
1089 return Hexagon::ASLH_cNotPt_V4;
1090 case Hexagon::ASLH_cNotPt_V4:
1091 return Hexagon::ASLH_cPt_V4;
1092
1093 case Hexagon::ASRH_cPt_V4:
1094 return Hexagon::ASRH_cNotPt_V4;
1095 case Hexagon::ASRH_cNotPt_V4:
1096 return Hexagon::ASRH_cPt_V4;
1097
1098 case Hexagon::SXTB_cPt_V4:
1099 return Hexagon::SXTB_cNotPt_V4;
1100 case Hexagon::SXTB_cNotPt_V4:
1101 return Hexagon::SXTB_cPt_V4;
1102
1103 case Hexagon::SXTH_cPt_V4:
1104 return Hexagon::SXTH_cNotPt_V4;
1105 case Hexagon::SXTH_cNotPt_V4:
1106 return Hexagon::SXTH_cPt_V4;
1107
1108 case Hexagon::ZXTB_cPt_V4:
1109 return Hexagon::ZXTB_cNotPt_V4;
1110 case Hexagon::ZXTB_cNotPt_V4:
1111 return Hexagon::ZXTB_cPt_V4;
1112
1113 case Hexagon::ZXTH_cPt_V4:
1114 return Hexagon::ZXTH_cNotPt_V4;
1115 case Hexagon::ZXTH_cNotPt_V4:
1116 return Hexagon::ZXTH_cPt_V4;
1117
1118
Jyotsna Verma5ed51812013-05-01 21:37:34 +00001119 case Hexagon::JMPR_t:
1120 return Hexagon::JMPR_f;
1121 case Hexagon::JMPR_f:
1122 return Hexagon::JMPR_t;
Sirish Pande30804c22012-02-15 18:52:27 +00001123
1124 // V4 indexed+scaled load.
Sirish Pande30804c22012-02-15 18:52:27 +00001125 case Hexagon::LDrid_indexed_shl_cPt_V4:
1126 return Hexagon::LDrid_indexed_shl_cNotPt_V4;
1127 case Hexagon::LDrid_indexed_shl_cNotPt_V4:
1128 return Hexagon::LDrid_indexed_shl_cPt_V4;
1129
Sirish Pande30804c22012-02-15 18:52:27 +00001130 case Hexagon::LDrib_indexed_shl_cPt_V4:
1131 return Hexagon::LDrib_indexed_shl_cNotPt_V4;
1132 case Hexagon::LDrib_indexed_shl_cNotPt_V4:
1133 return Hexagon::LDrib_indexed_shl_cPt_V4;
1134
1135 case Hexagon::LDriub_indexed_shl_cPt_V4:
1136 return Hexagon::LDriub_indexed_shl_cNotPt_V4;
1137 case Hexagon::LDriub_indexed_shl_cNotPt_V4:
1138 return Hexagon::LDriub_indexed_shl_cPt_V4;
1139
Sirish Pande30804c22012-02-15 18:52:27 +00001140 case Hexagon::LDrih_indexed_shl_cPt_V4:
1141 return Hexagon::LDrih_indexed_shl_cNotPt_V4;
1142 case Hexagon::LDrih_indexed_shl_cNotPt_V4:
1143 return Hexagon::LDrih_indexed_shl_cPt_V4;
1144
1145 case Hexagon::LDriuh_indexed_shl_cPt_V4:
1146 return Hexagon::LDriuh_indexed_shl_cNotPt_V4;
1147 case Hexagon::LDriuh_indexed_shl_cNotPt_V4:
1148 return Hexagon::LDriuh_indexed_shl_cPt_V4;
1149
Sirish Pande30804c22012-02-15 18:52:27 +00001150 case Hexagon::LDriw_indexed_shl_cPt_V4:
1151 return Hexagon::LDriw_indexed_shl_cNotPt_V4;
1152 case Hexagon::LDriw_indexed_shl_cNotPt_V4:
1153 return Hexagon::LDriw_indexed_shl_cPt_V4;
1154
1155 // Byte.
1156 case Hexagon::POST_STbri_cPt:
1157 return Hexagon::POST_STbri_cNotPt;
1158 case Hexagon::POST_STbri_cNotPt:
1159 return Hexagon::POST_STbri_cPt;
1160
1161 case Hexagon::STrib_cPt:
1162 return Hexagon::STrib_cNotPt;
1163 case Hexagon::STrib_cNotPt:
1164 return Hexagon::STrib_cPt;
1165
1166 case Hexagon::STrib_indexed_cPt:
1167 return Hexagon::STrib_indexed_cNotPt;
1168 case Hexagon::STrib_indexed_cNotPt:
1169 return Hexagon::STrib_indexed_cPt;
1170
1171 case Hexagon::STrib_imm_cPt_V4:
1172 return Hexagon::STrib_imm_cNotPt_V4;
1173 case Hexagon::STrib_imm_cNotPt_V4:
1174 return Hexagon::STrib_imm_cPt_V4;
1175
1176 case Hexagon::STrib_indexed_shl_cPt_V4:
1177 return Hexagon::STrib_indexed_shl_cNotPt_V4;
1178 case Hexagon::STrib_indexed_shl_cNotPt_V4:
1179 return Hexagon::STrib_indexed_shl_cPt_V4;
1180
1181 // Halfword.
1182 case Hexagon::POST_SThri_cPt:
1183 return Hexagon::POST_SThri_cNotPt;
1184 case Hexagon::POST_SThri_cNotPt:
1185 return Hexagon::POST_SThri_cPt;
1186
1187 case Hexagon::STrih_cPt:
1188 return Hexagon::STrih_cNotPt;
1189 case Hexagon::STrih_cNotPt:
1190 return Hexagon::STrih_cPt;
1191
1192 case Hexagon::STrih_indexed_cPt:
1193 return Hexagon::STrih_indexed_cNotPt;
1194 case Hexagon::STrih_indexed_cNotPt:
1195 return Hexagon::STrih_indexed_cPt;
1196
1197 case Hexagon::STrih_imm_cPt_V4:
1198 return Hexagon::STrih_imm_cNotPt_V4;
1199 case Hexagon::STrih_imm_cNotPt_V4:
1200 return Hexagon::STrih_imm_cPt_V4;
1201
1202 case Hexagon::STrih_indexed_shl_cPt_V4:
1203 return Hexagon::STrih_indexed_shl_cNotPt_V4;
1204 case Hexagon::STrih_indexed_shl_cNotPt_V4:
1205 return Hexagon::STrih_indexed_shl_cPt_V4;
1206
1207 // Word.
1208 case Hexagon::POST_STwri_cPt:
1209 return Hexagon::POST_STwri_cNotPt;
1210 case Hexagon::POST_STwri_cNotPt:
1211 return Hexagon::POST_STwri_cPt;
1212
1213 case Hexagon::STriw_cPt:
1214 return Hexagon::STriw_cNotPt;
1215 case Hexagon::STriw_cNotPt:
1216 return Hexagon::STriw_cPt;
1217
1218 case Hexagon::STriw_indexed_cPt:
1219 return Hexagon::STriw_indexed_cNotPt;
1220 case Hexagon::STriw_indexed_cNotPt:
1221 return Hexagon::STriw_indexed_cPt;
1222
1223 case Hexagon::STriw_indexed_shl_cPt_V4:
1224 return Hexagon::STriw_indexed_shl_cNotPt_V4;
1225 case Hexagon::STriw_indexed_shl_cNotPt_V4:
1226 return Hexagon::STriw_indexed_shl_cPt_V4;
1227
1228 case Hexagon::STriw_imm_cPt_V4:
1229 return Hexagon::STriw_imm_cNotPt_V4;
1230 case Hexagon::STriw_imm_cNotPt_V4:
1231 return Hexagon::STriw_imm_cPt_V4;
1232
1233 // Double word.
1234 case Hexagon::POST_STdri_cPt:
1235 return Hexagon::POST_STdri_cNotPt;
1236 case Hexagon::POST_STdri_cNotPt:
1237 return Hexagon::POST_STdri_cPt;
1238
1239 case Hexagon::STrid_cPt:
1240 return Hexagon::STrid_cNotPt;
1241 case Hexagon::STrid_cNotPt:
1242 return Hexagon::STrid_cPt;
1243
1244 case Hexagon::STrid_indexed_cPt:
1245 return Hexagon::STrid_indexed_cNotPt;
1246 case Hexagon::STrid_indexed_cNotPt:
1247 return Hexagon::STrid_indexed_cPt;
1248
1249 case Hexagon::STrid_indexed_shl_cPt_V4:
1250 return Hexagon::STrid_indexed_shl_cNotPt_V4;
1251 case Hexagon::STrid_indexed_shl_cNotPt_V4:
1252 return Hexagon::STrid_indexed_shl_cPt_V4;
1253
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001254 // V4 Store to global address.
1255 case Hexagon::STd_GP_cPt_V4:
1256 return Hexagon::STd_GP_cNotPt_V4;
1257 case Hexagon::STd_GP_cNotPt_V4:
1258 return Hexagon::STd_GP_cPt_V4;
1259
1260 case Hexagon::STb_GP_cPt_V4:
1261 return Hexagon::STb_GP_cNotPt_V4;
1262 case Hexagon::STb_GP_cNotPt_V4:
1263 return Hexagon::STb_GP_cPt_V4;
1264
1265 case Hexagon::STh_GP_cPt_V4:
1266 return Hexagon::STh_GP_cNotPt_V4;
1267 case Hexagon::STh_GP_cNotPt_V4:
1268 return Hexagon::STh_GP_cPt_V4;
1269
1270 case Hexagon::STw_GP_cPt_V4:
1271 return Hexagon::STw_GP_cNotPt_V4;
1272 case Hexagon::STw_GP_cNotPt_V4:
1273 return Hexagon::STw_GP_cPt_V4;
1274
Sirish Pande30804c22012-02-15 18:52:27 +00001275 // Load.
1276 case Hexagon::LDrid_cPt:
1277 return Hexagon::LDrid_cNotPt;
1278 case Hexagon::LDrid_cNotPt:
1279 return Hexagon::LDrid_cPt;
1280
1281 case Hexagon::LDriw_cPt:
1282 return Hexagon::LDriw_cNotPt;
1283 case Hexagon::LDriw_cNotPt:
1284 return Hexagon::LDriw_cPt;
1285
1286 case Hexagon::LDrih_cPt:
1287 return Hexagon::LDrih_cNotPt;
1288 case Hexagon::LDrih_cNotPt:
1289 return Hexagon::LDrih_cPt;
1290
1291 case Hexagon::LDriuh_cPt:
1292 return Hexagon::LDriuh_cNotPt;
1293 case Hexagon::LDriuh_cNotPt:
1294 return Hexagon::LDriuh_cPt;
1295
1296 case Hexagon::LDrib_cPt:
1297 return Hexagon::LDrib_cNotPt;
1298 case Hexagon::LDrib_cNotPt:
1299 return Hexagon::LDrib_cPt;
1300
1301 case Hexagon::LDriub_cPt:
1302 return Hexagon::LDriub_cNotPt;
1303 case Hexagon::LDriub_cNotPt:
1304 return Hexagon::LDriub_cPt;
1305
1306 // Load Indexed.
1307 case Hexagon::LDrid_indexed_cPt:
1308 return Hexagon::LDrid_indexed_cNotPt;
1309 case Hexagon::LDrid_indexed_cNotPt:
1310 return Hexagon::LDrid_indexed_cPt;
1311
1312 case Hexagon::LDriw_indexed_cPt:
1313 return Hexagon::LDriw_indexed_cNotPt;
1314 case Hexagon::LDriw_indexed_cNotPt:
1315 return Hexagon::LDriw_indexed_cPt;
1316
1317 case Hexagon::LDrih_indexed_cPt:
1318 return Hexagon::LDrih_indexed_cNotPt;
1319 case Hexagon::LDrih_indexed_cNotPt:
1320 return Hexagon::LDrih_indexed_cPt;
1321
1322 case Hexagon::LDriuh_indexed_cPt:
1323 return Hexagon::LDriuh_indexed_cNotPt;
1324 case Hexagon::LDriuh_indexed_cNotPt:
1325 return Hexagon::LDriuh_indexed_cPt;
1326
1327 case Hexagon::LDrib_indexed_cPt:
1328 return Hexagon::LDrib_indexed_cNotPt;
1329 case Hexagon::LDrib_indexed_cNotPt:
1330 return Hexagon::LDrib_indexed_cPt;
1331
1332 case Hexagon::LDriub_indexed_cPt:
1333 return Hexagon::LDriub_indexed_cNotPt;
1334 case Hexagon::LDriub_indexed_cNotPt:
1335 return Hexagon::LDriub_indexed_cPt;
1336
1337 // Post Inc Load.
1338 case Hexagon::POST_LDrid_cPt:
1339 return Hexagon::POST_LDrid_cNotPt;
1340 case Hexagon::POST_LDriw_cNotPt:
1341 return Hexagon::POST_LDriw_cPt;
1342
1343 case Hexagon::POST_LDrih_cPt:
1344 return Hexagon::POST_LDrih_cNotPt;
1345 case Hexagon::POST_LDrih_cNotPt:
1346 return Hexagon::POST_LDrih_cPt;
1347
1348 case Hexagon::POST_LDriuh_cPt:
1349 return Hexagon::POST_LDriuh_cNotPt;
1350 case Hexagon::POST_LDriuh_cNotPt:
1351 return Hexagon::POST_LDriuh_cPt;
1352
1353 case Hexagon::POST_LDrib_cPt:
1354 return Hexagon::POST_LDrib_cNotPt;
1355 case Hexagon::POST_LDrib_cNotPt:
1356 return Hexagon::POST_LDrib_cPt;
1357
1358 case Hexagon::POST_LDriub_cPt:
1359 return Hexagon::POST_LDriub_cNotPt;
1360 case Hexagon::POST_LDriub_cNotPt:
1361 return Hexagon::POST_LDriub_cPt;
1362
1363 // Dealloc_return.
1364 case Hexagon::DEALLOC_RET_cPt_V4:
1365 return Hexagon::DEALLOC_RET_cNotPt_V4;
1366 case Hexagon::DEALLOC_RET_cNotPt_V4:
1367 return Hexagon::DEALLOC_RET_cPt_V4;
Jyotsna Vermaa841af72013-05-02 22:10:59 +00001368
1369 // New Value Jump.
1370 // JMPEQ_ri - with -1.
1371 case Hexagon::JMP_EQriPtneg_nv_V4:
1372 return Hexagon::JMP_EQriNotPtneg_nv_V4;
1373 case Hexagon::JMP_EQriNotPtneg_nv_V4:
1374 return Hexagon::JMP_EQriPtneg_nv_V4;
1375
1376 case Hexagon::JMP_EQriPntneg_nv_V4:
1377 return Hexagon::JMP_EQriNotPntneg_nv_V4;
1378 case Hexagon::JMP_EQriNotPntneg_nv_V4:
1379 return Hexagon::JMP_EQriPntneg_nv_V4;
1380
1381 // JMPEQ_ri.
1382 case Hexagon::JMP_EQriPt_nv_V4:
1383 return Hexagon::JMP_EQriNotPt_nv_V4;
1384 case Hexagon::JMP_EQriNotPt_nv_V4:
1385 return Hexagon::JMP_EQriPt_nv_V4;
1386
1387 case Hexagon::JMP_EQriPnt_nv_V4:
1388 return Hexagon::JMP_EQriNotPnt_nv_V4;
1389 case Hexagon::JMP_EQriNotPnt_nv_V4:
1390 return Hexagon::JMP_EQriPnt_nv_V4;
1391
1392 // JMPEQ_rr.
1393 case Hexagon::JMP_EQrrPt_nv_V4:
1394 return Hexagon::JMP_EQrrNotPt_nv_V4;
1395 case Hexagon::JMP_EQrrNotPt_nv_V4:
1396 return Hexagon::JMP_EQrrPt_nv_V4;
1397
1398 case Hexagon::JMP_EQrrPnt_nv_V4:
1399 return Hexagon::JMP_EQrrNotPnt_nv_V4;
1400 case Hexagon::JMP_EQrrNotPnt_nv_V4:
1401 return Hexagon::JMP_EQrrPnt_nv_V4;
1402
1403 // JMPGT_ri - with -1.
1404 case Hexagon::JMP_GTriPtneg_nv_V4:
1405 return Hexagon::JMP_GTriNotPtneg_nv_V4;
1406 case Hexagon::JMP_GTriNotPtneg_nv_V4:
1407 return Hexagon::JMP_GTriPtneg_nv_V4;
1408
1409 case Hexagon::JMP_GTriPntneg_nv_V4:
1410 return Hexagon::JMP_GTriNotPntneg_nv_V4;
1411 case Hexagon::JMP_GTriNotPntneg_nv_V4:
1412 return Hexagon::JMP_GTriPntneg_nv_V4;
1413
1414 // JMPGT_ri.
1415 case Hexagon::JMP_GTriPt_nv_V4:
1416 return Hexagon::JMP_GTriNotPt_nv_V4;
1417 case Hexagon::JMP_GTriNotPt_nv_V4:
1418 return Hexagon::JMP_GTriPt_nv_V4;
1419
1420 case Hexagon::JMP_GTriPnt_nv_V4:
1421 return Hexagon::JMP_GTriNotPnt_nv_V4;
1422 case Hexagon::JMP_GTriNotPnt_nv_V4:
1423 return Hexagon::JMP_GTriPnt_nv_V4;
1424
1425 // JMPGT_rr.
1426 case Hexagon::JMP_GTrrPt_nv_V4:
1427 return Hexagon::JMP_GTrrNotPt_nv_V4;
1428 case Hexagon::JMP_GTrrNotPt_nv_V4:
1429 return Hexagon::JMP_GTrrPt_nv_V4;
1430
1431 case Hexagon::JMP_GTrrPnt_nv_V4:
1432 return Hexagon::JMP_GTrrNotPnt_nv_V4;
1433 case Hexagon::JMP_GTrrNotPnt_nv_V4:
1434 return Hexagon::JMP_GTrrPnt_nv_V4;
1435
1436 // JMPGT_rrdn.
1437 case Hexagon::JMP_GTrrdnPt_nv_V4:
1438 return Hexagon::JMP_GTrrdnNotPt_nv_V4;
1439 case Hexagon::JMP_GTrrdnNotPt_nv_V4:
1440 return Hexagon::JMP_GTrrdnPt_nv_V4;
1441
1442 case Hexagon::JMP_GTrrdnPnt_nv_V4:
1443 return Hexagon::JMP_GTrrdnNotPnt_nv_V4;
1444 case Hexagon::JMP_GTrrdnNotPnt_nv_V4:
1445 return Hexagon::JMP_GTrrdnPnt_nv_V4;
1446
1447 // JMPGTU_ri.
1448 case Hexagon::JMP_GTUriPt_nv_V4:
1449 return Hexagon::JMP_GTUriNotPt_nv_V4;
1450 case Hexagon::JMP_GTUriNotPt_nv_V4:
1451 return Hexagon::JMP_GTUriPt_nv_V4;
1452
1453 case Hexagon::JMP_GTUriPnt_nv_V4:
1454 return Hexagon::JMP_GTUriNotPnt_nv_V4;
1455 case Hexagon::JMP_GTUriNotPnt_nv_V4:
1456 return Hexagon::JMP_GTUriPnt_nv_V4;
1457
1458 // JMPGTU_rr.
1459 case Hexagon::JMP_GTUrrPt_nv_V4:
1460 return Hexagon::JMP_GTUrrNotPt_nv_V4;
1461 case Hexagon::JMP_GTUrrNotPt_nv_V4:
1462 return Hexagon::JMP_GTUrrPt_nv_V4;
1463
1464 case Hexagon::JMP_GTUrrPnt_nv_V4:
1465 return Hexagon::JMP_GTUrrNotPnt_nv_V4;
1466 case Hexagon::JMP_GTUrrNotPnt_nv_V4:
1467 return Hexagon::JMP_GTUrrPnt_nv_V4;
1468
1469 // JMPGTU_rrdn.
1470 case Hexagon::JMP_GTUrrdnPt_nv_V4:
1471 return Hexagon::JMP_GTUrrdnNotPt_nv_V4;
1472 case Hexagon::JMP_GTUrrdnNotPt_nv_V4:
1473 return Hexagon::JMP_GTUrrdnPt_nv_V4;
1474
1475 case Hexagon::JMP_GTUrrdnPnt_nv_V4:
1476 return Hexagon::JMP_GTUrrdnNotPnt_nv_V4;
1477 case Hexagon::JMP_GTUrrdnNotPnt_nv_V4:
1478 return Hexagon::JMP_GTUrrdnPnt_nv_V4;
Sirish Pande30804c22012-02-15 18:52:27 +00001479 }
1480}
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001481
Andrew Trickd06df962012-02-01 22:13:57 +00001482
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001483int HexagonInstrInfo::
1484getMatchingCondBranchOpcode(int Opc, bool invertPredicate) const {
Pranav Bhandarkar34b60182012-11-01 19:13:23 +00001485 enum Hexagon::PredSense inPredSense;
1486 inPredSense = invertPredicate ? Hexagon::PredSense_false :
1487 Hexagon::PredSense_true;
1488 int CondOpcode = Hexagon::getPredOpcode(Opc, inPredSense);
1489 if (CondOpcode >= 0) // Valid Conditional opcode/instruction
1490 return CondOpcode;
1491
1492 // This switch case will be removed once all the instructions have been
1493 // modified to use relation maps.
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001494 switch(Opc) {
1495 case Hexagon::TFR:
1496 return !invertPredicate ? Hexagon::TFR_cPt :
1497 Hexagon::TFR_cNotPt;
Sirish Pande69295b82012-05-10 20:20:25 +00001498 case Hexagon::TFRI_f:
1499 return !invertPredicate ? Hexagon::TFRI_cPt_f :
1500 Hexagon::TFRI_cNotPt_f;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001501 case Hexagon::TFRI:
1502 return !invertPredicate ? Hexagon::TFRI_cPt :
1503 Hexagon::TFRI_cNotPt;
1504 case Hexagon::JMP:
Jyotsna Verma5ed51812013-05-01 21:37:34 +00001505 return !invertPredicate ? Hexagon::JMP_t :
1506 Hexagon::JMP_f;
Jyotsna Vermaa841af72013-05-02 22:10:59 +00001507 case Hexagon::JMP_EQrrPt_nv_V4:
1508 return !invertPredicate ? Hexagon::JMP_EQrrPt_nv_V4 :
1509 Hexagon::JMP_EQrrNotPt_nv_V4;
1510 case Hexagon::JMP_EQriPt_nv_V4:
1511 return !invertPredicate ? Hexagon::JMP_EQriPt_nv_V4 :
1512 Hexagon::JMP_EQriNotPt_nv_V4;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001513 case Hexagon::COMBINE_rr:
1514 return !invertPredicate ? Hexagon::COMBINE_rr_cPt :
1515 Hexagon::COMBINE_rr_cNotPt;
1516 case Hexagon::ASLH:
1517 return !invertPredicate ? Hexagon::ASLH_cPt_V4 :
1518 Hexagon::ASLH_cNotPt_V4;
1519 case Hexagon::ASRH:
1520 return !invertPredicate ? Hexagon::ASRH_cPt_V4 :
1521 Hexagon::ASRH_cNotPt_V4;
1522 case Hexagon::SXTB:
1523 return !invertPredicate ? Hexagon::SXTB_cPt_V4 :
1524 Hexagon::SXTB_cNotPt_V4;
1525 case Hexagon::SXTH:
1526 return !invertPredicate ? Hexagon::SXTH_cPt_V4 :
1527 Hexagon::SXTH_cNotPt_V4;
1528 case Hexagon::ZXTB:
1529 return !invertPredicate ? Hexagon::ZXTB_cPt_V4 :
1530 Hexagon::ZXTB_cNotPt_V4;
1531 case Hexagon::ZXTH:
1532 return !invertPredicate ? Hexagon::ZXTH_cPt_V4 :
1533 Hexagon::ZXTH_cNotPt_V4;
1534
1535 case Hexagon::JMPR:
Jyotsna Verma5ed51812013-05-01 21:37:34 +00001536 return !invertPredicate ? Hexagon::JMPR_t :
1537 Hexagon::JMPR_f;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001538
1539 // V4 indexed+scaled load.
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001540 case Hexagon::LDrid_indexed_shl_V4:
1541 return !invertPredicate ? Hexagon::LDrid_indexed_shl_cPt_V4 :
1542 Hexagon::LDrid_indexed_shl_cNotPt_V4;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001543 case Hexagon::LDrib_indexed_shl_V4:
1544 return !invertPredicate ? Hexagon::LDrib_indexed_shl_cPt_V4 :
1545 Hexagon::LDrib_indexed_shl_cNotPt_V4;
1546 case Hexagon::LDriub_indexed_shl_V4:
1547 return !invertPredicate ? Hexagon::LDriub_indexed_shl_cPt_V4 :
1548 Hexagon::LDriub_indexed_shl_cNotPt_V4;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001549 case Hexagon::LDrih_indexed_shl_V4:
1550 return !invertPredicate ? Hexagon::LDrih_indexed_shl_cPt_V4 :
1551 Hexagon::LDrih_indexed_shl_cNotPt_V4;
1552 case Hexagon::LDriuh_indexed_shl_V4:
1553 return !invertPredicate ? Hexagon::LDriuh_indexed_shl_cPt_V4 :
1554 Hexagon::LDriuh_indexed_shl_cNotPt_V4;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001555 case Hexagon::LDriw_indexed_shl_V4:
1556 return !invertPredicate ? Hexagon::LDriw_indexed_shl_cPt_V4 :
1557 Hexagon::LDriw_indexed_shl_cNotPt_V4;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001558
1559 // V4 Load from global address
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001560 case Hexagon::LDd_GP_V4:
1561 return !invertPredicate ? Hexagon::LDd_GP_cPt_V4 :
1562 Hexagon::LDd_GP_cNotPt_V4;
1563 case Hexagon::LDb_GP_V4:
1564 return !invertPredicate ? Hexagon::LDb_GP_cPt_V4 :
1565 Hexagon::LDb_GP_cNotPt_V4;
1566 case Hexagon::LDub_GP_V4:
1567 return !invertPredicate ? Hexagon::LDub_GP_cPt_V4 :
1568 Hexagon::LDub_GP_cNotPt_V4;
1569 case Hexagon::LDh_GP_V4:
1570 return !invertPredicate ? Hexagon::LDh_GP_cPt_V4 :
1571 Hexagon::LDh_GP_cNotPt_V4;
1572 case Hexagon::LDuh_GP_V4:
1573 return !invertPredicate ? Hexagon::LDuh_GP_cPt_V4 :
1574 Hexagon::LDuh_GP_cNotPt_V4;
1575 case Hexagon::LDw_GP_V4:
1576 return !invertPredicate ? Hexagon::LDw_GP_cPt_V4 :
1577 Hexagon::LDw_GP_cNotPt_V4;
1578
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001579 // Byte.
1580 case Hexagon::POST_STbri:
1581 return !invertPredicate ? Hexagon::POST_STbri_cPt :
1582 Hexagon::POST_STbri_cNotPt;
1583 case Hexagon::STrib:
1584 return !invertPredicate ? Hexagon::STrib_cPt :
1585 Hexagon::STrib_cNotPt;
1586 case Hexagon::STrib_indexed:
1587 return !invertPredicate ? Hexagon::STrib_indexed_cPt :
1588 Hexagon::STrib_indexed_cNotPt;
1589 case Hexagon::STrib_imm_V4:
1590 return !invertPredicate ? Hexagon::STrib_imm_cPt_V4 :
1591 Hexagon::STrib_imm_cNotPt_V4;
1592 case Hexagon::STrib_indexed_shl_V4:
1593 return !invertPredicate ? Hexagon::STrib_indexed_shl_cPt_V4 :
1594 Hexagon::STrib_indexed_shl_cNotPt_V4;
1595 // Halfword.
1596 case Hexagon::POST_SThri:
1597 return !invertPredicate ? Hexagon::POST_SThri_cPt :
1598 Hexagon::POST_SThri_cNotPt;
1599 case Hexagon::STrih:
1600 return !invertPredicate ? Hexagon::STrih_cPt :
1601 Hexagon::STrih_cNotPt;
1602 case Hexagon::STrih_indexed:
1603 return !invertPredicate ? Hexagon::STrih_indexed_cPt :
1604 Hexagon::STrih_indexed_cNotPt;
1605 case Hexagon::STrih_imm_V4:
1606 return !invertPredicate ? Hexagon::STrih_imm_cPt_V4 :
1607 Hexagon::STrih_imm_cNotPt_V4;
1608 case Hexagon::STrih_indexed_shl_V4:
1609 return !invertPredicate ? Hexagon::STrih_indexed_shl_cPt_V4 :
1610 Hexagon::STrih_indexed_shl_cNotPt_V4;
1611 // Word.
1612 case Hexagon::POST_STwri:
1613 return !invertPredicate ? Hexagon::POST_STwri_cPt :
1614 Hexagon::POST_STwri_cNotPt;
1615 case Hexagon::STriw:
1616 return !invertPredicate ? Hexagon::STriw_cPt :
1617 Hexagon::STriw_cNotPt;
1618 case Hexagon::STriw_indexed:
1619 return !invertPredicate ? Hexagon::STriw_indexed_cPt :
1620 Hexagon::STriw_indexed_cNotPt;
1621 case Hexagon::STriw_indexed_shl_V4:
1622 return !invertPredicate ? Hexagon::STriw_indexed_shl_cPt_V4 :
1623 Hexagon::STriw_indexed_shl_cNotPt_V4;
1624 case Hexagon::STriw_imm_V4:
1625 return !invertPredicate ? Hexagon::STriw_imm_cPt_V4 :
1626 Hexagon::STriw_imm_cNotPt_V4;
1627 // Double word.
1628 case Hexagon::POST_STdri:
1629 return !invertPredicate ? Hexagon::POST_STdri_cPt :
1630 Hexagon::POST_STdri_cNotPt;
1631 case Hexagon::STrid:
1632 return !invertPredicate ? Hexagon::STrid_cPt :
1633 Hexagon::STrid_cNotPt;
1634 case Hexagon::STrid_indexed:
1635 return !invertPredicate ? Hexagon::STrid_indexed_cPt :
1636 Hexagon::STrid_indexed_cNotPt;
1637 case Hexagon::STrid_indexed_shl_V4:
1638 return !invertPredicate ? Hexagon::STrid_indexed_shl_cPt_V4 :
1639 Hexagon::STrid_indexed_shl_cNotPt_V4;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001640
1641 // V4 Store to global address
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001642 case Hexagon::STd_GP_V4:
1643 return !invertPredicate ? Hexagon::STd_GP_cPt_V4 :
1644 Hexagon::STd_GP_cNotPt_V4;
1645 case Hexagon::STb_GP_V4:
1646 return !invertPredicate ? Hexagon::STb_GP_cPt_V4 :
1647 Hexagon::STb_GP_cNotPt_V4;
1648 case Hexagon::STh_GP_V4:
1649 return !invertPredicate ? Hexagon::STh_GP_cPt_V4 :
1650 Hexagon::STh_GP_cNotPt_V4;
1651 case Hexagon::STw_GP_V4:
1652 return !invertPredicate ? Hexagon::STw_GP_cPt_V4 :
1653 Hexagon::STw_GP_cNotPt_V4;
1654
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001655 // Load.
1656 case Hexagon::LDrid:
1657 return !invertPredicate ? Hexagon::LDrid_cPt :
1658 Hexagon::LDrid_cNotPt;
1659 case Hexagon::LDriw:
1660 return !invertPredicate ? Hexagon::LDriw_cPt :
1661 Hexagon::LDriw_cNotPt;
1662 case Hexagon::LDrih:
1663 return !invertPredicate ? Hexagon::LDrih_cPt :
1664 Hexagon::LDrih_cNotPt;
1665 case Hexagon::LDriuh:
1666 return !invertPredicate ? Hexagon::LDriuh_cPt :
1667 Hexagon::LDriuh_cNotPt;
1668 case Hexagon::LDrib:
1669 return !invertPredicate ? Hexagon::LDrib_cPt :
1670 Hexagon::LDrib_cNotPt;
1671 case Hexagon::LDriub:
1672 return !invertPredicate ? Hexagon::LDriub_cPt :
1673 Hexagon::LDriub_cNotPt;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001674 // Load Indexed.
1675 case Hexagon::LDrid_indexed:
1676 return !invertPredicate ? Hexagon::LDrid_indexed_cPt :
1677 Hexagon::LDrid_indexed_cNotPt;
1678 case Hexagon::LDriw_indexed:
1679 return !invertPredicate ? Hexagon::LDriw_indexed_cPt :
1680 Hexagon::LDriw_indexed_cNotPt;
1681 case Hexagon::LDrih_indexed:
1682 return !invertPredicate ? Hexagon::LDrih_indexed_cPt :
1683 Hexagon::LDrih_indexed_cNotPt;
1684 case Hexagon::LDriuh_indexed:
1685 return !invertPredicate ? Hexagon::LDriuh_indexed_cPt :
1686 Hexagon::LDriuh_indexed_cNotPt;
1687 case Hexagon::LDrib_indexed:
1688 return !invertPredicate ? Hexagon::LDrib_indexed_cPt :
1689 Hexagon::LDrib_indexed_cNotPt;
1690 case Hexagon::LDriub_indexed:
1691 return !invertPredicate ? Hexagon::LDriub_indexed_cPt :
1692 Hexagon::LDriub_indexed_cNotPt;
1693 // Post Increment Load.
1694 case Hexagon::POST_LDrid:
1695 return !invertPredicate ? Hexagon::POST_LDrid_cPt :
1696 Hexagon::POST_LDrid_cNotPt;
1697 case Hexagon::POST_LDriw:
1698 return !invertPredicate ? Hexagon::POST_LDriw_cPt :
1699 Hexagon::POST_LDriw_cNotPt;
1700 case Hexagon::POST_LDrih:
1701 return !invertPredicate ? Hexagon::POST_LDrih_cPt :
1702 Hexagon::POST_LDrih_cNotPt;
1703 case Hexagon::POST_LDriuh:
1704 return !invertPredicate ? Hexagon::POST_LDriuh_cPt :
1705 Hexagon::POST_LDriuh_cNotPt;
1706 case Hexagon::POST_LDrib:
1707 return !invertPredicate ? Hexagon::POST_LDrib_cPt :
1708 Hexagon::POST_LDrib_cNotPt;
1709 case Hexagon::POST_LDriub:
1710 return !invertPredicate ? Hexagon::POST_LDriub_cPt :
1711 Hexagon::POST_LDriub_cNotPt;
1712 // DEALLOC_RETURN.
1713 case Hexagon::DEALLOC_RET_V4:
1714 return !invertPredicate ? Hexagon::DEALLOC_RET_cPt_V4 :
1715 Hexagon::DEALLOC_RET_cNotPt_V4;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001716 }
Benjamin Kramerb6684012011-12-27 11:41:05 +00001717 llvm_unreachable("Unexpected predicable instruction");
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001718}
1719
1720
1721bool HexagonInstrInfo::
1722PredicateInstruction(MachineInstr *MI,
1723 const SmallVectorImpl<MachineOperand> &Cond) const {
1724 int Opc = MI->getOpcode();
1725 assert (isPredicable(MI) && "Expected predicable instruction");
1726 bool invertJump = (!Cond.empty() && Cond[0].isImm() &&
1727 (Cond[0].getImm() == 0));
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001728
Jyotsna Verma39f7a2b2013-02-12 16:06:23 +00001729 // This will change MI's opcode to its predicate version.
1730 // However, its operand list is still the old one, i.e. the
1731 // non-predicate one.
1732 MI->setDesc(get(getMatchingCondBranchOpcode(Opc, invertJump)));
1733
1734 int oper = -1;
1735 unsigned int GAIdx = 0;
1736
1737 // Indicates whether the current MI has a GlobalAddress operand
1738 bool hasGAOpnd = false;
1739 std::vector<MachineOperand> tmpOpnds;
1740
1741 // Indicates whether we need to shift operands to right.
1742 bool needShift = true;
1743
1744 // The predicate is ALWAYS the FIRST input operand !!!
1745 if (MI->getNumOperands() == 0) {
1746 // The non-predicate version of MI does not take any operands,
1747 // i.e. no outs and no ins. In this condition, the predicate
1748 // operand will be directly placed at Operands[0]. No operand
1749 // shift is needed.
1750 // Example: BARRIER
1751 needShift = false;
1752 oper = -1;
1753 }
1754 else if ( MI->getOperand(MI->getNumOperands()-1).isReg()
1755 && MI->getOperand(MI->getNumOperands()-1).isDef()
1756 && !MI->getOperand(MI->getNumOperands()-1).isImplicit()) {
1757 // The non-predicate version of MI does not have any input operands.
1758 // In this condition, we extend the length of Operands[] by one and
1759 // copy the original last operand to the newly allocated slot.
1760 // At this moment, it is just a place holder. Later, we will put
1761 // predicate operand directly into it. No operand shift is needed.
1762 // Example: r0=BARRIER (this is a faked insn used here for illustration)
1763 MI->addOperand(MI->getOperand(MI->getNumOperands()-1));
1764 needShift = false;
1765 oper = MI->getNumOperands() - 2;
1766 }
1767 else {
1768 // We need to right shift all input operands by one. Duplicate the
1769 // last operand into the newly allocated slot.
1770 MI->addOperand(MI->getOperand(MI->getNumOperands()-1));
1771 }
1772
1773 if (needShift)
1774 {
1775 // Operands[ MI->getNumOperands() - 2 ] has been copied into
1776 // Operands[ MI->getNumOperands() - 1 ], so we start from
1777 // Operands[ MI->getNumOperands() - 3 ].
1778 // oper is a signed int.
1779 // It is ok if "MI->getNumOperands()-3" is -3, -2, or -1.
1780 for (oper = MI->getNumOperands() - 3; oper >= 0; --oper)
1781 {
1782 MachineOperand &MO = MI->getOperand(oper);
1783
1784 // Opnd[0] Opnd[1] Opnd[2] Opnd[3] Opnd[4] Opnd[5] Opnd[6] Opnd[7]
1785 // <Def0> <Def1> <Use0> <Use1> <ImpDef0> <ImpDef1> <ImpUse0> <ImpUse1>
1786 // /\~
1787 // /||\~
1788 // ||
1789 // Predicate Operand here
1790 if (MO.isReg() && !MO.isUse() && !MO.isImplicit()) {
1791 break;
1792 }
1793 if (MO.isReg()) {
1794 MI->getOperand(oper+1).ChangeToRegister(MO.getReg(), MO.isDef(),
1795 MO.isImplicit(), MO.isKill(),
1796 MO.isDead(), MO.isUndef(),
1797 MO.isDebug());
1798 }
1799 else if (MO.isImm()) {
1800 MI->getOperand(oper+1).ChangeToImmediate(MO.getImm());
1801 }
1802 else if (MO.isGlobal()) {
1803 // MI can not have more than one GlobalAddress operand.
1804 assert(hasGAOpnd == false && "MI can only have one GlobalAddress opnd");
1805
1806 // There is no member function called "ChangeToGlobalAddress" in the
1807 // MachineOperand class (not like "ChangeToRegister" and
1808 // "ChangeToImmediate"). So we have to remove them from Operands[] list
1809 // first, and then add them back after we have inserted the predicate
1810 // operand. tmpOpnds[] is to remember these operands before we remove
1811 // them.
1812 tmpOpnds.push_back(MO);
1813
1814 // Operands[oper] is a GlobalAddress operand;
1815 // Operands[oper+1] has been copied into Operands[oper+2];
1816 hasGAOpnd = true;
1817 GAIdx = oper;
1818 continue;
1819 }
1820 else {
1821 assert(false && "Unexpected operand type");
1822 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001823 }
1824 }
1825
1826 int regPos = invertJump ? 1 : 0;
1827 MachineOperand PredMO = Cond[regPos];
Jyotsna Verma39f7a2b2013-02-12 16:06:23 +00001828
1829 // [oper] now points to the last explicit Def. Predicate operand must be
1830 // located at [oper+1]. See diagram above.
1831 // This assumes that the predicate is always the first operand,
1832 // i.e. Operands[0+numResults], in the set of inputs
1833 // It is better to have an assert here to check this. But I don't know how
1834 // to write this assert because findFirstPredOperandIdx() would return -1
1835 if (oper < -1) oper = -1;
Jyotsna Vermacd66c0a2013-05-01 21:27:30 +00001836
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001837 MI->getOperand(oper+1).ChangeToRegister(PredMO.getReg(), PredMO.isDef(),
Jyotsna Vermacd66c0a2013-05-01 21:27:30 +00001838 PredMO.isImplicit(), false,
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001839 PredMO.isDead(), PredMO.isUndef(),
1840 PredMO.isDebug());
1841
Jyotsna Vermacd66c0a2013-05-01 21:27:30 +00001842 MachineRegisterInfo &RegInfo = MI->getParent()->getParent()->getRegInfo();
1843 RegInfo.clearKillFlags(PredMO.getReg());
1844
Jyotsna Verma39f7a2b2013-02-12 16:06:23 +00001845 if (hasGAOpnd)
1846 {
1847 unsigned int i;
1848
1849 // Operands[GAIdx] is the original GlobalAddress operand, which is
1850 // already copied into tmpOpnds[0].
1851 // Operands[GAIdx] now stores a copy of Operands[GAIdx-1]
1852 // Operands[GAIdx+1] has already been copied into Operands[GAIdx+2],
1853 // so we start from [GAIdx+2]
1854 for (i = GAIdx + 2; i < MI->getNumOperands(); ++i)
1855 tmpOpnds.push_back(MI->getOperand(i));
1856
1857 // Remove all operands in range [ (GAIdx+1) ... (MI->getNumOperands()-1) ]
1858 // It is very important that we always remove from the end of Operands[]
1859 // MI->getNumOperands() is at least 2 if program goes to here.
1860 for (i = MI->getNumOperands() - 1; i > GAIdx; --i)
1861 MI->RemoveOperand(i);
1862
1863 for (i = 0; i < tmpOpnds.size(); ++i)
1864 MI->addOperand(tmpOpnds[i]);
1865 }
1866
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001867 return true;
1868}
1869
1870
1871bool
1872HexagonInstrInfo::
1873isProfitableToIfCvt(MachineBasicBlock &MBB,
Kay Tiong Khoof2949212012-06-13 15:53:04 +00001874 unsigned NumCycles,
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001875 unsigned ExtraPredCycles,
1876 const BranchProbability &Probability) const {
1877 return true;
1878}
1879
1880
1881bool
1882HexagonInstrInfo::
1883isProfitableToIfCvt(MachineBasicBlock &TMBB,
1884 unsigned NumTCycles,
1885 unsigned ExtraTCycles,
1886 MachineBasicBlock &FMBB,
1887 unsigned NumFCycles,
1888 unsigned ExtraFCycles,
1889 const BranchProbability &Probability) const {
1890 return true;
1891}
1892
Jyotsna Vermaa841af72013-05-02 22:10:59 +00001893
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001894bool HexagonInstrInfo::isPredicated(const MachineInstr *MI) const {
Brendon Cahoon6f358372012-02-08 18:25:47 +00001895 const uint64_t F = MI->getDesc().TSFlags;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001896
Brendon Cahoon6f358372012-02-08 18:25:47 +00001897 return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask);
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001898}
1899
Jyotsna Vermaa46059b2013-03-28 19:44:04 +00001900bool HexagonInstrInfo::isPredicatedNew(const MachineInstr *MI) const {
1901 const uint64_t F = MI->getDesc().TSFlags;
1902
1903 assert(isPredicated(MI));
1904 return ((F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask);
1905}
1906
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001907bool
1908HexagonInstrInfo::DefinesPredicate(MachineInstr *MI,
1909 std::vector<MachineOperand> &Pred) const {
1910 for (unsigned oper = 0; oper < MI->getNumOperands(); ++oper) {
1911 MachineOperand MO = MI->getOperand(oper);
1912 if (MO.isReg() && MO.isDef()) {
1913 const TargetRegisterClass* RC = RI.getMinimalPhysRegClass(MO.getReg());
Craig Topperc7242e02012-04-20 07:30:17 +00001914 if (RC == &Hexagon::PredRegsRegClass) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001915 Pred.push_back(MO);
1916 return true;
1917 }
1918 }
1919 }
1920 return false;
1921}
1922
1923
1924bool
1925HexagonInstrInfo::
1926SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
1927 const SmallVectorImpl<MachineOperand> &Pred2) const {
1928 // TODO: Fix this
1929 return false;
1930}
1931
1932
1933//
1934// We indicate that we want to reverse the branch by
1935// inserting a 0 at the beginning of the Cond vector.
1936//
1937bool HexagonInstrInfo::
1938ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
1939 if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) {
1940 Cond.erase(Cond.begin());
1941 } else {
1942 Cond.insert(Cond.begin(), MachineOperand::CreateImm(0));
1943 }
1944 return false;
1945}
1946
1947
1948bool HexagonInstrInfo::
1949isProfitableToDupForIfCvt(MachineBasicBlock &MBB,unsigned NumInstrs,
1950 const BranchProbability &Probability) const {
1951 return (NumInstrs <= 4);
1952}
1953
1954bool HexagonInstrInfo::isDeallocRet(const MachineInstr *MI) const {
1955 switch (MI->getOpcode()) {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001956 default: return false;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001957 case Hexagon::DEALLOC_RET_V4 :
1958 case Hexagon::DEALLOC_RET_cPt_V4 :
1959 case Hexagon::DEALLOC_RET_cNotPt_V4 :
1960 case Hexagon::DEALLOC_RET_cdnPnt_V4 :
1961 case Hexagon::DEALLOC_RET_cNotdnPnt_V4 :
1962 case Hexagon::DEALLOC_RET_cdnPt_V4 :
1963 case Hexagon::DEALLOC_RET_cNotdnPt_V4 :
1964 return true;
1965 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001966}
1967
1968
1969bool HexagonInstrInfo::
1970isValidOffset(const int Opcode, const int Offset) const {
1971 // This function is to check whether the "Offset" is in the correct range of
1972 // the given "Opcode". If "Offset" is not in the correct range, "ADD_ri" is
1973 // inserted to calculate the final address. Due to this reason, the function
1974 // assumes that the "Offset" has correct alignment.
Jyotsna Vermaec613662013-03-14 19:08:03 +00001975 // We used to assert if the offset was not properly aligned, however,
1976 // there are cases where a misaligned pointer recast can cause this
1977 // problem, and we need to allow for it. The front end warns of such
1978 // misaligns with respect to load size.
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001979
1980 switch(Opcode) {
1981
1982 case Hexagon::LDriw:
Jyotsna Verma9b60c1d2013-01-17 18:42:37 +00001983 case Hexagon::LDriw_indexed:
Sirish Pande69295b82012-05-10 20:20:25 +00001984 case Hexagon::LDriw_f:
Jyotsna Verma9b60c1d2013-01-17 18:42:37 +00001985 case Hexagon::STriw_indexed:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001986 case Hexagon::STriw:
Sirish Pande69295b82012-05-10 20:20:25 +00001987 case Hexagon::STriw_f:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001988 return (Offset >= Hexagon_MEMW_OFFSET_MIN) &&
1989 (Offset <= Hexagon_MEMW_OFFSET_MAX);
1990
1991 case Hexagon::LDrid:
Jyotsna Verma9b60c1d2013-01-17 18:42:37 +00001992 case Hexagon::LDrid_indexed:
Sirish Pande69295b82012-05-10 20:20:25 +00001993 case Hexagon::LDrid_f:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001994 case Hexagon::STrid:
Jyotsna Verma9b60c1d2013-01-17 18:42:37 +00001995 case Hexagon::STrid_indexed:
Sirish Pande69295b82012-05-10 20:20:25 +00001996 case Hexagon::STrid_f:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001997 return (Offset >= Hexagon_MEMD_OFFSET_MIN) &&
1998 (Offset <= Hexagon_MEMD_OFFSET_MAX);
1999
2000 case Hexagon::LDrih:
2001 case Hexagon::LDriuh:
2002 case Hexagon::STrih:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002003 return (Offset >= Hexagon_MEMH_OFFSET_MIN) &&
2004 (Offset <= Hexagon_MEMH_OFFSET_MAX);
2005
2006 case Hexagon::LDrib:
2007 case Hexagon::STrib:
2008 case Hexagon::LDriub:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002009 return (Offset >= Hexagon_MEMB_OFFSET_MIN) &&
2010 (Offset <= Hexagon_MEMB_OFFSET_MAX);
2011
2012 case Hexagon::ADD_ri:
2013 case Hexagon::TFR_FI:
2014 return (Offset >= Hexagon_ADDI_OFFSET_MIN) &&
2015 (Offset <= Hexagon_ADDI_OFFSET_MAX);
2016
Jyotsna Vermafdc660b2013-03-22 18:41:34 +00002017 case Hexagon::MemOPw_ADDi_V4 :
2018 case Hexagon::MemOPw_SUBi_V4 :
2019 case Hexagon::MemOPw_ADDr_V4 :
2020 case Hexagon::MemOPw_SUBr_V4 :
2021 case Hexagon::MemOPw_ANDr_V4 :
2022 case Hexagon::MemOPw_ORr_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002023 return (0 <= Offset && Offset <= 255);
2024
Jyotsna Vermafdc660b2013-03-22 18:41:34 +00002025 case Hexagon::MemOPh_ADDi_V4 :
2026 case Hexagon::MemOPh_SUBi_V4 :
2027 case Hexagon::MemOPh_ADDr_V4 :
2028 case Hexagon::MemOPh_SUBr_V4 :
2029 case Hexagon::MemOPh_ANDr_V4 :
2030 case Hexagon::MemOPh_ORr_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002031 return (0 <= Offset && Offset <= 127);
2032
Jyotsna Vermafdc660b2013-03-22 18:41:34 +00002033 case Hexagon::MemOPb_ADDi_V4 :
2034 case Hexagon::MemOPb_SUBi_V4 :
2035 case Hexagon::MemOPb_ADDr_V4 :
2036 case Hexagon::MemOPb_SUBr_V4 :
2037 case Hexagon::MemOPb_ANDr_V4 :
2038 case Hexagon::MemOPb_ORr_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002039 return (0 <= Offset && Offset <= 63);
2040
2041 // LDri_pred and STriw_pred are pseudo operations, so it has to take offset of
2042 // any size. Later pass knows how to handle it.
2043 case Hexagon::STriw_pred:
2044 case Hexagon::LDriw_pred:
2045 return true;
2046
Krzysztof Parzyszek9a278f12013-02-11 21:37:55 +00002047 case Hexagon::LOOP0_i:
2048 return isUInt<10>(Offset);
2049
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002050 // INLINEASM is very special.
2051 case Hexagon::INLINEASM:
2052 return true;
2053 }
2054
Benjamin Kramerb6684012011-12-27 11:41:05 +00002055 llvm_unreachable("No offset range is defined for this opcode. "
2056 "Please define it in the above switch statement!");
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002057}
2058
2059
2060//
2061// Check if the Offset is a valid auto-inc imm by Load/Store Type.
2062//
2063bool HexagonInstrInfo::
2064isValidAutoIncImm(const EVT VT, const int Offset) const {
2065
2066 if (VT == MVT::i64) {
2067 return (Offset >= Hexagon_MEMD_AUTOINC_MIN &&
2068 Offset <= Hexagon_MEMD_AUTOINC_MAX &&
2069 (Offset & 0x7) == 0);
2070 }
2071 if (VT == MVT::i32) {
2072 return (Offset >= Hexagon_MEMW_AUTOINC_MIN &&
2073 Offset <= Hexagon_MEMW_AUTOINC_MAX &&
2074 (Offset & 0x3) == 0);
2075 }
2076 if (VT == MVT::i16) {
2077 return (Offset >= Hexagon_MEMH_AUTOINC_MIN &&
2078 Offset <= Hexagon_MEMH_AUTOINC_MAX &&
2079 (Offset & 0x1) == 0);
2080 }
2081 if (VT == MVT::i8) {
2082 return (Offset >= Hexagon_MEMB_AUTOINC_MIN &&
2083 Offset <= Hexagon_MEMB_AUTOINC_MAX);
2084 }
Craig Toppere55c5562012-02-07 02:50:20 +00002085 llvm_unreachable("Not an auto-inc opc!");
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002086}
2087
2088
2089bool HexagonInstrInfo::
2090isMemOp(const MachineInstr *MI) const {
2091 switch (MI->getOpcode())
2092 {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002093 default: return false;
Jyotsna Vermafdc660b2013-03-22 18:41:34 +00002094 case Hexagon::MemOPw_ADDi_V4 :
2095 case Hexagon::MemOPw_SUBi_V4 :
2096 case Hexagon::MemOPw_ADDr_V4 :
2097 case Hexagon::MemOPw_SUBr_V4 :
2098 case Hexagon::MemOPw_ANDr_V4 :
2099 case Hexagon::MemOPw_ORr_V4 :
2100 case Hexagon::MemOPh_ADDi_V4 :
2101 case Hexagon::MemOPh_SUBi_V4 :
2102 case Hexagon::MemOPh_ADDr_V4 :
2103 case Hexagon::MemOPh_SUBr_V4 :
2104 case Hexagon::MemOPh_ANDr_V4 :
2105 case Hexagon::MemOPh_ORr_V4 :
2106 case Hexagon::MemOPb_ADDi_V4 :
2107 case Hexagon::MemOPb_SUBi_V4 :
2108 case Hexagon::MemOPb_ADDr_V4 :
2109 case Hexagon::MemOPb_SUBr_V4 :
2110 case Hexagon::MemOPb_ANDr_V4 :
2111 case Hexagon::MemOPb_ORr_V4 :
2112 case Hexagon::MemOPb_SETBITi_V4:
2113 case Hexagon::MemOPh_SETBITi_V4:
2114 case Hexagon::MemOPw_SETBITi_V4:
2115 case Hexagon::MemOPb_CLRBITi_V4:
2116 case Hexagon::MemOPh_CLRBITi_V4:
2117 case Hexagon::MemOPw_CLRBITi_V4:
2118 return true;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002119 }
Jyotsna Vermafdc660b2013-03-22 18:41:34 +00002120 return false;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002121}
2122
2123
2124bool HexagonInstrInfo::
2125isSpillPredRegOp(const MachineInstr *MI) const {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002126 switch (MI->getOpcode()) {
2127 default: return false;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002128 case Hexagon::STriw_pred :
2129 case Hexagon::LDriw_pred :
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002130 return true;
Sirish Pande2c7bf002012-04-23 17:49:28 +00002131 }
Sirish Pande4bd20c52012-05-12 05:10:30 +00002132}
2133
2134bool HexagonInstrInfo::isNewValueJumpCandidate(const MachineInstr *MI) const {
2135 switch (MI->getOpcode()) {
Sirish Pande8bb97452012-05-12 05:54:15 +00002136 default: return false;
Sirish Pande4bd20c52012-05-12 05:10:30 +00002137 case Hexagon::CMPEQrr:
2138 case Hexagon::CMPEQri:
Sirish Pande4bd20c52012-05-12 05:10:30 +00002139 case Hexagon::CMPGTrr:
2140 case Hexagon::CMPGTri:
Sirish Pande4bd20c52012-05-12 05:10:30 +00002141 case Hexagon::CMPGTUrr:
2142 case Hexagon::CMPGTUri:
Sirish Pande4bd20c52012-05-12 05:10:30 +00002143 return true;
Sirish Pande4bd20c52012-05-12 05:10:30 +00002144 }
Sirish Pande2c7bf002012-04-23 17:49:28 +00002145}
2146
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002147bool HexagonInstrInfo::
2148isConditionalTransfer (const MachineInstr *MI) const {
2149 switch (MI->getOpcode()) {
2150 default: return false;
2151 case Hexagon::TFR_cPt:
2152 case Hexagon::TFR_cNotPt:
2153 case Hexagon::TFRI_cPt:
2154 case Hexagon::TFRI_cNotPt:
2155 case Hexagon::TFR_cdnPt:
2156 case Hexagon::TFR_cdnNotPt:
2157 case Hexagon::TFRI_cdnPt:
2158 case Hexagon::TFRI_cdnNotPt:
2159 return true;
2160 }
2161}
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002162
2163bool HexagonInstrInfo::isConditionalALU32 (const MachineInstr* MI) const {
2164 const HexagonRegisterInfo& QRI = getRegisterInfo();
2165 switch (MI->getOpcode())
2166 {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002167 default: return false;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002168 case Hexagon::ADD_ri_cPt:
2169 case Hexagon::ADD_ri_cNotPt:
2170 case Hexagon::ADD_rr_cPt:
2171 case Hexagon::ADD_rr_cNotPt:
2172 case Hexagon::XOR_rr_cPt:
2173 case Hexagon::XOR_rr_cNotPt:
2174 case Hexagon::AND_rr_cPt:
2175 case Hexagon::AND_rr_cNotPt:
2176 case Hexagon::OR_rr_cPt:
2177 case Hexagon::OR_rr_cNotPt:
2178 case Hexagon::SUB_rr_cPt:
2179 case Hexagon::SUB_rr_cNotPt:
2180 case Hexagon::COMBINE_rr_cPt:
2181 case Hexagon::COMBINE_rr_cNotPt:
2182 return true;
2183 case Hexagon::ASLH_cPt_V4:
2184 case Hexagon::ASLH_cNotPt_V4:
2185 case Hexagon::ASRH_cPt_V4:
2186 case Hexagon::ASRH_cNotPt_V4:
2187 case Hexagon::SXTB_cPt_V4:
2188 case Hexagon::SXTB_cNotPt_V4:
2189 case Hexagon::SXTH_cPt_V4:
2190 case Hexagon::SXTH_cNotPt_V4:
2191 case Hexagon::ZXTB_cPt_V4:
2192 case Hexagon::ZXTB_cNotPt_V4:
2193 case Hexagon::ZXTH_cPt_V4:
2194 case Hexagon::ZXTH_cNotPt_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002195 return QRI.Subtarget.hasV4TOps();
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002196 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002197}
2198
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002199bool HexagonInstrInfo::
2200isConditionalLoad (const MachineInstr* MI) const {
2201 const HexagonRegisterInfo& QRI = getRegisterInfo();
2202 switch (MI->getOpcode())
2203 {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002204 default: return false;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002205 case Hexagon::LDrid_cPt :
2206 case Hexagon::LDrid_cNotPt :
2207 case Hexagon::LDrid_indexed_cPt :
2208 case Hexagon::LDrid_indexed_cNotPt :
2209 case Hexagon::LDriw_cPt :
2210 case Hexagon::LDriw_cNotPt :
2211 case Hexagon::LDriw_indexed_cPt :
2212 case Hexagon::LDriw_indexed_cNotPt :
2213 case Hexagon::LDrih_cPt :
2214 case Hexagon::LDrih_cNotPt :
2215 case Hexagon::LDrih_indexed_cPt :
2216 case Hexagon::LDrih_indexed_cNotPt :
2217 case Hexagon::LDrib_cPt :
2218 case Hexagon::LDrib_cNotPt :
2219 case Hexagon::LDrib_indexed_cPt :
2220 case Hexagon::LDrib_indexed_cNotPt :
2221 case Hexagon::LDriuh_cPt :
2222 case Hexagon::LDriuh_cNotPt :
2223 case Hexagon::LDriuh_indexed_cPt :
2224 case Hexagon::LDriuh_indexed_cNotPt :
2225 case Hexagon::LDriub_cPt :
2226 case Hexagon::LDriub_cNotPt :
2227 case Hexagon::LDriub_indexed_cPt :
2228 case Hexagon::LDriub_indexed_cNotPt :
2229 return true;
2230 case Hexagon::POST_LDrid_cPt :
2231 case Hexagon::POST_LDrid_cNotPt :
2232 case Hexagon::POST_LDriw_cPt :
2233 case Hexagon::POST_LDriw_cNotPt :
2234 case Hexagon::POST_LDrih_cPt :
2235 case Hexagon::POST_LDrih_cNotPt :
2236 case Hexagon::POST_LDrib_cPt :
2237 case Hexagon::POST_LDrib_cNotPt :
2238 case Hexagon::POST_LDriuh_cPt :
2239 case Hexagon::POST_LDriuh_cNotPt :
2240 case Hexagon::POST_LDriub_cPt :
2241 case Hexagon::POST_LDriub_cNotPt :
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002242 return QRI.Subtarget.hasV4TOps();
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002243 case Hexagon::LDrid_indexed_shl_cPt_V4 :
2244 case Hexagon::LDrid_indexed_shl_cNotPt_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002245 case Hexagon::LDrib_indexed_shl_cPt_V4 :
2246 case Hexagon::LDrib_indexed_shl_cNotPt_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002247 case Hexagon::LDriub_indexed_shl_cPt_V4 :
2248 case Hexagon::LDriub_indexed_shl_cNotPt_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002249 case Hexagon::LDrih_indexed_shl_cPt_V4 :
2250 case Hexagon::LDrih_indexed_shl_cNotPt_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002251 case Hexagon::LDriuh_indexed_shl_cPt_V4 :
2252 case Hexagon::LDriuh_indexed_shl_cNotPt_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002253 case Hexagon::LDriw_indexed_shl_cPt_V4 :
2254 case Hexagon::LDriw_indexed_shl_cNotPt_V4 :
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002255 return QRI.Subtarget.hasV4TOps();
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002256 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002257}
Andrew Trickd06df962012-02-01 22:13:57 +00002258
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002259// Returns true if an instruction is a conditional store.
2260//
2261// Note: It doesn't include conditional new-value stores as they can't be
2262// converted to .new predicate.
2263//
2264// p.new NV store [ if(p0.new)memw(R0+#0)=R2.new ]
2265// ^ ^
2266// / \ (not OK. it will cause new-value store to be
2267// / X conditional on p0.new while R2 producer is
2268// / \ on p0)
2269// / \.
2270// p.new store p.old NV store
2271// [if(p0.new)memw(R0+#0)=R2] [if(p0)memw(R0+#0)=R2.new]
2272// ^ ^
2273// \ /
2274// \ /
2275// \ /
2276// p.old store
2277// [if (p0)memw(R0+#0)=R2]
2278//
2279// The above diagram shows the steps involoved in the conversion of a predicated
2280// store instruction to its .new predicated new-value form.
2281//
2282// The following set of instructions further explains the scenario where
2283// conditional new-value store becomes invalid when promoted to .new predicate
2284// form.
2285//
2286// { 1) if (p0) r0 = add(r1, r2)
2287// 2) p0 = cmp.eq(r3, #0) }
2288//
2289// 3) if (p0) memb(r1+#0) = r0 --> this instruction can't be grouped with
2290// the first two instructions because in instr 1, r0 is conditional on old value
2291// of p0 but its use in instr 3 is conditional on p0 modified by instr 2 which
2292// is not valid for new-value stores.
2293bool HexagonInstrInfo::
2294isConditionalStore (const MachineInstr* MI) const {
2295 const HexagonRegisterInfo& QRI = getRegisterInfo();
2296 switch (MI->getOpcode())
2297 {
2298 default: return false;
2299 case Hexagon::STrib_imm_cPt_V4 :
2300 case Hexagon::STrib_imm_cNotPt_V4 :
2301 case Hexagon::STrib_indexed_shl_cPt_V4 :
2302 case Hexagon::STrib_indexed_shl_cNotPt_V4 :
2303 case Hexagon::STrib_cPt :
2304 case Hexagon::STrib_cNotPt :
2305 case Hexagon::POST_STbri_cPt :
2306 case Hexagon::POST_STbri_cNotPt :
2307 case Hexagon::STrid_indexed_cPt :
2308 case Hexagon::STrid_indexed_cNotPt :
2309 case Hexagon::STrid_indexed_shl_cPt_V4 :
2310 case Hexagon::POST_STdri_cPt :
2311 case Hexagon::POST_STdri_cNotPt :
2312 case Hexagon::STrih_cPt :
2313 case Hexagon::STrih_cNotPt :
2314 case Hexagon::STrih_indexed_cPt :
2315 case Hexagon::STrih_indexed_cNotPt :
2316 case Hexagon::STrih_imm_cPt_V4 :
2317 case Hexagon::STrih_imm_cNotPt_V4 :
2318 case Hexagon::STrih_indexed_shl_cPt_V4 :
2319 case Hexagon::STrih_indexed_shl_cNotPt_V4 :
2320 case Hexagon::POST_SThri_cPt :
2321 case Hexagon::POST_SThri_cNotPt :
2322 case Hexagon::STriw_cPt :
2323 case Hexagon::STriw_cNotPt :
2324 case Hexagon::STriw_indexed_cPt :
2325 case Hexagon::STriw_indexed_cNotPt :
2326 case Hexagon::STriw_imm_cPt_V4 :
2327 case Hexagon::STriw_imm_cNotPt_V4 :
2328 case Hexagon::STriw_indexed_shl_cPt_V4 :
2329 case Hexagon::STriw_indexed_shl_cNotPt_V4 :
2330 case Hexagon::POST_STwri_cPt :
2331 case Hexagon::POST_STwri_cNotPt :
2332 return QRI.Subtarget.hasV4TOps();
2333
2334 // V4 global address store before promoting to dot new.
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002335 case Hexagon::STd_GP_cPt_V4 :
2336 case Hexagon::STd_GP_cNotPt_V4 :
2337 case Hexagon::STb_GP_cPt_V4 :
2338 case Hexagon::STb_GP_cNotPt_V4 :
2339 case Hexagon::STh_GP_cPt_V4 :
2340 case Hexagon::STh_GP_cNotPt_V4 :
2341 case Hexagon::STw_GP_cPt_V4 :
2342 case Hexagon::STw_GP_cNotPt_V4 :
2343 return QRI.Subtarget.hasV4TOps();
2344
2345 // Predicated new value stores (i.e. if (p0) memw(..)=r0.new) are excluded
2346 // from the "Conditional Store" list. Because a predicated new value store
2347 // would NOT be promoted to a double dot new store. See diagram below:
2348 // This function returns yes for those stores that are predicated but not
2349 // yet promoted to predicate dot new instructions.
2350 //
2351 // +---------------------+
2352 // /-----| if (p0) memw(..)=r0 |---------\~
2353 // || +---------------------+ ||
2354 // promote || /\ /\ || promote
2355 // || /||\ /||\ ||
2356 // \||/ demote || \||/
2357 // \/ || || \/
2358 // +-------------------------+ || +-------------------------+
2359 // | if (p0.new) memw(..)=r0 | || | if (p0) memw(..)=r0.new |
2360 // +-------------------------+ || +-------------------------+
2361 // || || ||
2362 // || demote \||/
2363 // promote || \/ NOT possible
2364 // || || /\~
2365 // \||/ || /||\~
2366 // \/ || ||
2367 // +-----------------------------+
2368 // | if (p0.new) memw(..)=r0.new |
2369 // +-----------------------------+
2370 // Double Dot New Store
2371 //
2372 }
2373}
2374
Jyotsna Vermaa46059b2013-03-28 19:44:04 +00002375// Returns true, if any one of the operands is a dot new
2376// insn, whether it is predicated dot new or register dot new.
2377bool HexagonInstrInfo::isDotNewInst (const MachineInstr* MI) const {
2378 return (isNewValueInst(MI) ||
2379 (isPredicated(MI) && isPredicatedNew(MI)));
2380}
2381
Jyotsna Verma84256432013-03-01 17:37:13 +00002382unsigned HexagonInstrInfo::getAddrMode(const MachineInstr* MI) const {
2383 const uint64_t F = MI->getDesc().TSFlags;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002384
Jyotsna Verma84256432013-03-01 17:37:13 +00002385 return((F >> HexagonII::AddrModePos) & HexagonII::AddrModeMask);
2386}
2387
2388/// immediateExtend - Changes the instruction in place to one using an immediate
2389/// extender.
2390void HexagonInstrInfo::immediateExtend(MachineInstr *MI) const {
2391 assert((isExtendable(MI)||isConstExtended(MI)) &&
2392 "Instruction must be extendable");
2393 // Find which operand is extendable.
2394 short ExtOpNum = getCExtOpNum(MI);
2395 MachineOperand &MO = MI->getOperand(ExtOpNum);
2396 // This needs to be something we understand.
2397 assert((MO.isMBB() || MO.isImm()) &&
2398 "Branch with unknown extendable field type");
2399 // Mark given operand as extended.
2400 MO.addTargetFlag(HexagonII::HMOTF_ConstExtended);
2401}
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002402
Andrew Trickd06df962012-02-01 22:13:57 +00002403DFAPacketizer *HexagonInstrInfo::
2404CreateTargetScheduleState(const TargetMachine *TM,
2405 const ScheduleDAG *DAG) const {
2406 const InstrItineraryData *II = TM->getInstrItineraryData();
2407 return TM->getSubtarget<HexagonGenSubtargetInfo>().createDFAPacketizer(II);
2408}
2409
2410bool HexagonInstrInfo::isSchedulingBoundary(const MachineInstr *MI,
2411 const MachineBasicBlock *MBB,
2412 const MachineFunction &MF) const {
2413 // Debug info is never a scheduling boundary. It's necessary to be explicit
2414 // due to the special treatment of IT instructions below, otherwise a
2415 // dbg_value followed by an IT will result in the IT instruction being
2416 // considered a scheduling hazard, which is wrong. It should be the actual
2417 // instruction preceding the dbg_value instruction(s), just like it is
2418 // when debug info is not present.
2419 if (MI->isDebugValue())
2420 return false;
2421
2422 // Terminators and labels can't be scheduled around.
2423 if (MI->getDesc().isTerminator() || MI->isLabel() || MI->isInlineAsm())
2424 return true;
2425
2426 return false;
2427}
Jyotsna Verma84256432013-03-01 17:37:13 +00002428
2429bool HexagonInstrInfo::isConstExtended(MachineInstr *MI) const {
2430
2431 // Constant extenders are allowed only for V4 and above.
2432 if (!Subtarget.hasV4TOps())
2433 return false;
2434
2435 const uint64_t F = MI->getDesc().TSFlags;
2436 unsigned isExtended = (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask;
2437 if (isExtended) // Instruction must be extended.
2438 return true;
2439
2440 unsigned isExtendable = (F >> HexagonII::ExtendablePos)
2441 & HexagonII::ExtendableMask;
2442 if (!isExtendable)
2443 return false;
2444
2445 short ExtOpNum = getCExtOpNum(MI);
2446 const MachineOperand &MO = MI->getOperand(ExtOpNum);
2447 // Use MO operand flags to determine if MO
2448 // has the HMOTF_ConstExtended flag set.
2449 if (MO.getTargetFlags() && HexagonII::HMOTF_ConstExtended)
2450 return true;
2451 // If this is a Machine BB address we are talking about, and it is
2452 // not marked as extended, say so.
2453 if (MO.isMBB())
2454 return false;
2455
2456 // We could be using an instruction with an extendable immediate and shoehorn
2457 // a global address into it. If it is a global address it will be constant
2458 // extended. We do this for COMBINE.
2459 // We currently only handle isGlobal() because it is the only kind of
2460 // object we are going to end up with here for now.
2461 // In the future we probably should add isSymbol(), etc.
2462 if (MO.isGlobal() || MO.isSymbol())
2463 return true;
2464
2465 // If the extendable operand is not 'Immediate' type, the instruction should
2466 // have 'isExtended' flag set.
2467 assert(MO.isImm() && "Extendable operand must be Immediate type");
2468
2469 int MinValue = getMinValue(MI);
2470 int MaxValue = getMaxValue(MI);
2471 int ImmValue = MO.getImm();
2472
2473 return (ImmValue < MinValue || ImmValue > MaxValue);
2474}
2475
Jyotsna Verma1d297502013-05-02 15:39:30 +00002476// Returns the opcode to use when converting MI, which is a conditional jump,
2477// into a conditional instruction which uses the .new value of the predicate.
2478// We also use branch probabilities to add a hint to the jump.
2479int
2480HexagonInstrInfo::getDotNewPredJumpOp(MachineInstr *MI,
2481 const
2482 MachineBranchProbabilityInfo *MBPI) const {
2483
2484 // We assume that block can have at most two successors.
2485 bool taken = false;
2486 MachineBasicBlock *Src = MI->getParent();
2487 MachineOperand *BrTarget = &MI->getOperand(1);
2488 MachineBasicBlock *Dst = BrTarget->getMBB();
2489
2490 const BranchProbability Prediction = MBPI->getEdgeProbability(Src, Dst);
2491 if (Prediction >= BranchProbability(1,2))
2492 taken = true;
2493
2494 switch (MI->getOpcode()) {
2495 case Hexagon::JMP_t:
2496 return taken ? Hexagon::JMP_tnew_t : Hexagon::JMP_tnew_nt;
2497 case Hexagon::JMP_f:
2498 return taken ? Hexagon::JMP_fnew_t : Hexagon::JMP_fnew_nt;
2499
2500 default:
2501 llvm_unreachable("Unexpected jump instruction.");
2502 }
2503}
Jyotsna Verma84256432013-03-01 17:37:13 +00002504// Returns true if a particular operand is extendable for an instruction.
2505bool HexagonInstrInfo::isOperandExtended(const MachineInstr *MI,
2506 unsigned short OperandNum) const {
2507 // Constant extenders are allowed only for V4 and above.
2508 if (!Subtarget.hasV4TOps())
2509 return false;
2510
2511 const uint64_t F = MI->getDesc().TSFlags;
2512
2513 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask)
2514 == OperandNum;
2515}
2516
2517// Returns Operand Index for the constant extended instruction.
2518unsigned short HexagonInstrInfo::getCExtOpNum(const MachineInstr *MI) const {
2519 const uint64_t F = MI->getDesc().TSFlags;
2520 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask);
2521}
2522
2523// Returns the min value that doesn't need to be extended.
2524int HexagonInstrInfo::getMinValue(const MachineInstr *MI) const {
2525 const uint64_t F = MI->getDesc().TSFlags;
2526 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
2527 & HexagonII::ExtentSignedMask;
2528 unsigned bits = (F >> HexagonII::ExtentBitsPos)
2529 & HexagonII::ExtentBitsMask;
2530
2531 if (isSigned) // if value is signed
2532 return -1 << (bits - 1);
2533 else
2534 return 0;
2535}
2536
2537// Returns the max value that doesn't need to be extended.
2538int HexagonInstrInfo::getMaxValue(const MachineInstr *MI) const {
2539 const uint64_t F = MI->getDesc().TSFlags;
2540 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
2541 & HexagonII::ExtentSignedMask;
2542 unsigned bits = (F >> HexagonII::ExtentBitsPos)
2543 & HexagonII::ExtentBitsMask;
2544
2545 if (isSigned) // if value is signed
2546 return ~(-1 << (bits - 1));
2547 else
2548 return ~(-1 << bits);
2549}
2550
2551// Returns true if an instruction can be converted into a non-extended
2552// equivalent instruction.
2553bool HexagonInstrInfo::NonExtEquivalentExists (const MachineInstr *MI) const {
2554
2555 short NonExtOpcode;
2556 // Check if the instruction has a register form that uses register in place
2557 // of the extended operand, if so return that as the non-extended form.
2558 if (Hexagon::getRegForm(MI->getOpcode()) >= 0)
2559 return true;
2560
2561 if (MI->getDesc().mayLoad() || MI->getDesc().mayStore()) {
2562 // Check addressing mode and retreive non-ext equivalent instruction.
2563
2564 switch (getAddrMode(MI)) {
2565 case HexagonII::Absolute :
2566 // Load/store with absolute addressing mode can be converted into
2567 // base+offset mode.
2568 NonExtOpcode = Hexagon::getBasedWithImmOffset(MI->getOpcode());
2569 break;
2570 case HexagonII::BaseImmOffset :
2571 // Load/store with base+offset addressing mode can be converted into
2572 // base+register offset addressing mode. However left shift operand should
2573 // be set to 0.
2574 NonExtOpcode = Hexagon::getBaseWithRegOffset(MI->getOpcode());
2575 break;
2576 default:
2577 return false;
2578 }
2579 if (NonExtOpcode < 0)
2580 return false;
2581 return true;
2582 }
2583 return false;
2584}
2585
2586// Returns opcode of the non-extended equivalent instruction.
2587short HexagonInstrInfo::getNonExtOpcode (const MachineInstr *MI) const {
2588
2589 // Check if the instruction has a register form that uses register in place
2590 // of the extended operand, if so return that as the non-extended form.
2591 short NonExtOpcode = Hexagon::getRegForm(MI->getOpcode());
2592 if (NonExtOpcode >= 0)
2593 return NonExtOpcode;
2594
2595 if (MI->getDesc().mayLoad() || MI->getDesc().mayStore()) {
2596 // Check addressing mode and retreive non-ext equivalent instruction.
2597 switch (getAddrMode(MI)) {
2598 case HexagonII::Absolute :
2599 return Hexagon::getBasedWithImmOffset(MI->getOpcode());
2600 case HexagonII::BaseImmOffset :
2601 return Hexagon::getBaseWithRegOffset(MI->getOpcode());
2602 default:
2603 return -1;
2604 }
2605 }
2606 return -1;
2607}
Jyotsna Verma5ed51812013-05-01 21:37:34 +00002608
2609bool HexagonInstrInfo::PredOpcodeHasJMP_c(Opcode_t Opcode) const {
2610 return (Opcode == Hexagon::JMP_t) ||
2611 (Opcode == Hexagon::JMP_f) ||
2612 (Opcode == Hexagon::JMP_tnew_t) ||
2613 (Opcode == Hexagon::JMP_fnew_t) ||
2614 (Opcode == Hexagon::JMP_tnew_nt) ||
2615 (Opcode == Hexagon::JMP_fnew_nt);
2616}
2617
2618bool HexagonInstrInfo::PredOpcodeHasNot(Opcode_t Opcode) const {
2619 return (Opcode == Hexagon::JMP_f) ||
2620 (Opcode == Hexagon::JMP_fnew_t) ||
2621 (Opcode == Hexagon::JMP_fnew_nt);
2622}