blob: 1298045e495d3b8d2ba26707152da683b72cabda [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"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000028#define GET_INSTRINFO_CTOR
Pranav Bhandarkar34b60182012-11-01 19:13:23 +000029#define GET_INSTRMAP_INFO
Tony Linthicum1213a7a2011-12-12 21:14:40 +000030#include "HexagonGenInstrInfo.inc"
Andrew Trickd06df962012-02-01 22:13:57 +000031#include "HexagonGenDFAPacketizer.inc"
Tony Linthicum1213a7a2011-12-12 21:14:40 +000032
Tony Linthicum1213a7a2011-12-12 21:14:40 +000033using namespace llvm;
34
35///
36/// Constants for Hexagon instructions.
37///
38const int Hexagon_MEMW_OFFSET_MAX = 4095;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000039const int Hexagon_MEMW_OFFSET_MIN = -4096;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000040const int Hexagon_MEMD_OFFSET_MAX = 8191;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000041const int Hexagon_MEMD_OFFSET_MIN = -8192;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000042const int Hexagon_MEMH_OFFSET_MAX = 2047;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000043const int Hexagon_MEMH_OFFSET_MIN = -2048;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000044const int Hexagon_MEMB_OFFSET_MAX = 1023;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000045const int Hexagon_MEMB_OFFSET_MIN = -1024;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000046const int Hexagon_ADDI_OFFSET_MAX = 32767;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000047const int Hexagon_ADDI_OFFSET_MIN = -32768;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000048const int Hexagon_MEMD_AUTOINC_MAX = 56;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000049const int Hexagon_MEMD_AUTOINC_MIN = -64;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000050const int Hexagon_MEMW_AUTOINC_MAX = 28;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000051const int Hexagon_MEMW_AUTOINC_MIN = -32;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000052const int Hexagon_MEMH_AUTOINC_MAX = 14;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000053const int Hexagon_MEMH_AUTOINC_MIN = -16;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000054const int Hexagon_MEMB_AUTOINC_MAX = 7;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000055const int Hexagon_MEMB_AUTOINC_MIN = -8;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000056
57
58HexagonInstrInfo::HexagonInstrInfo(HexagonSubtarget &ST)
59 : HexagonGenInstrInfo(Hexagon::ADJCALLSTACKDOWN, Hexagon::ADJCALLSTACKUP),
60 RI(ST, *this), Subtarget(ST) {
61}
62
63
64/// isLoadFromStackSlot - If the specified machine instruction is a direct
65/// load from a stack slot, return the virtual or physical register number of
66/// the destination along with the FrameIndex of the loaded stack slot. If
67/// not, return 0. This predicate must return 0 if the instruction has
68/// any side effects other than loading from the stack slot.
69unsigned HexagonInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
70 int &FrameIndex) const {
71
72
73 switch (MI->getOpcode()) {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000074 default: break;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000075 case Hexagon::LDriw:
76 case Hexagon::LDrid:
77 case Hexagon::LDrih:
78 case Hexagon::LDrib:
79 case Hexagon::LDriub:
80 if (MI->getOperand(2).isFI() &&
81 MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) {
82 FrameIndex = MI->getOperand(2).getIndex();
83 return MI->getOperand(0).getReg();
84 }
85 break;
Tony Linthicum1213a7a2011-12-12 21:14:40 +000086 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +000087 return 0;
88}
89
90
91/// isStoreToStackSlot - If the specified machine instruction is a direct
92/// store to a stack slot, return the virtual or physical register number of
93/// the source reg along with the FrameIndex of the loaded stack slot. If
94/// not, return 0. This predicate must return 0 if the instruction has
95/// any side effects other than storing to the stack slot.
96unsigned HexagonInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
97 int &FrameIndex) const {
98 switch (MI->getOpcode()) {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +000099 default: break;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000100 case Hexagon::STriw:
101 case Hexagon::STrid:
102 case Hexagon::STrih:
103 case Hexagon::STrib:
104 if (MI->getOperand(2).isFI() &&
105 MI->getOperand(1).isImm() && (MI->getOperand(1).getImm() == 0)) {
Sirish Pande8bb97452012-05-12 05:54:15 +0000106 FrameIndex = MI->getOperand(0).getIndex();
107 return MI->getOperand(2).getReg();
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000108 }
109 break;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000110 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000111 return 0;
112}
113
114
115unsigned
116HexagonInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB,
117 MachineBasicBlock *FBB,
118 const SmallVectorImpl<MachineOperand> &Cond,
119 DebugLoc DL) const{
120
121 int BOpc = Hexagon::JMP;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000122 int BccOpc = Hexagon::JMP_t;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000123
124 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
125
126 int regPos = 0;
127 // Check if ReverseBranchCondition has asked to reverse this branch
128 // If we want to reverse the branch an odd number of times, we want
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000129 // JMP_f.
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000130 if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) {
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000131 BccOpc = Hexagon::JMP_f;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000132 regPos = 1;
133 }
134
135 if (FBB == 0) {
136 if (Cond.empty()) {
137 // Due to a bug in TailMerging/CFG Optimization, we need to add a
138 // special case handling of a predicated jump followed by an
139 // unconditional jump. If not, Tail Merging and CFG Optimization go
140 // into an infinite loop.
141 MachineBasicBlock *NewTBB, *NewFBB;
142 SmallVector<MachineOperand, 4> Cond;
143 MachineInstr *Term = MBB.getFirstTerminator();
144 if (isPredicated(Term) && !AnalyzeBranch(MBB, NewTBB, NewFBB, Cond,
145 false)) {
146 MachineBasicBlock *NextBB =
147 llvm::next(MachineFunction::iterator(&MBB));
148 if (NewTBB == NextBB) {
149 ReverseBranchCondition(Cond);
150 RemoveBranch(MBB);
151 return InsertBranch(MBB, TBB, 0, Cond, DL);
152 }
153 }
154 BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB);
155 } else {
156 BuildMI(&MBB, DL,
157 get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB);
158 }
159 return 1;
160 }
161
162 BuildMI(&MBB, DL, get(BccOpc)).addReg(Cond[regPos].getReg()).addMBB(TBB);
163 BuildMI(&MBB, DL, get(BOpc)).addMBB(FBB);
164
165 return 2;
166}
167
168
169bool HexagonInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
170 MachineBasicBlock *&TBB,
171 MachineBasicBlock *&FBB,
172 SmallVectorImpl<MachineOperand> &Cond,
173 bool AllowModify) const {
Benjamin Kramer0b03cbd2012-05-13 15:13:22 +0000174 TBB = NULL;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000175 FBB = NULL;
176
177 // If the block has no terminators, it just falls into the block after it.
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000178 MachineBasicBlock::instr_iterator I = MBB.instr_end();
179 if (I == MBB.instr_begin())
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000180 return false;
181
182 // A basic block may looks like this:
183 //
184 // [ insn
185 // EH_LABEL
186 // insn
187 // insn
188 // insn
189 // EH_LABEL
190 // insn ]
191 //
192 // It has two succs but does not have a terminator
193 // Don't know how to handle it.
194 do {
195 --I;
196 if (I->isEHLabel())
197 return true;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000198 } while (I != MBB.instr_begin());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000199
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000200 I = MBB.instr_end();
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000201 --I;
202
203 while (I->isDebugValue()) {
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000204 if (I == MBB.instr_begin())
205 return false;
206 --I;
207 }
208
209 // Delete the JMP if it's equivalent to a fall-through.
210 if (AllowModify && I->getOpcode() == Hexagon::JMP &&
211 MBB.isLayoutSuccessor(I->getOperand(0).getMBB())) {
212 DEBUG(dbgs()<< "\nErasing the jump to successor block\n";);
213 I->eraseFromParent();
214 I = MBB.instr_end();
215 if (I == MBB.instr_begin())
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000216 return false;
217 --I;
218 }
219 if (!isUnpredicatedTerminator(I))
220 return false;
221
222 // Get the last instruction in the block.
223 MachineInstr *LastInst = I;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000224 MachineInstr *SecondLastInst = NULL;
225 // Find one more terminator if present.
226 do {
227 if (&*I != LastInst && !I->isBundle() && isUnpredicatedTerminator(I)) {
228 if (!SecondLastInst)
229 SecondLastInst = I;
230 else
231 // This is a third branch.
232 return true;
233 }
234 if (I == MBB.instr_begin())
235 break;
236 --I;
237 } while(I);
238
239 int LastOpcode = LastInst->getOpcode();
240
241 bool LastOpcodeHasJMP_c = PredOpcodeHasJMP_c(LastOpcode);
242 bool LastOpcodeHasNot = PredOpcodeHasNot(LastOpcode);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000243
244 // If there is only one terminator instruction, process it.
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000245 if (LastInst && !SecondLastInst) {
246 if (LastOpcode == Hexagon::JMP) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000247 TBB = LastInst->getOperand(0).getMBB();
248 return false;
249 }
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000250 if (LastOpcode == Hexagon::ENDLOOP0) {
251 TBB = LastInst->getOperand(0).getMBB();
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000252 Cond.push_back(LastInst->getOperand(0));
253 return false;
254 }
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000255 if (LastOpcodeHasJMP_c) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000256 TBB = LastInst->getOperand(1).getMBB();
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000257 if (LastOpcodeHasNot) {
258 Cond.push_back(MachineOperand::CreateImm(0));
259 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000260 Cond.push_back(LastInst->getOperand(0));
261 return false;
262 }
263 // Otherwise, don't know what this is.
264 return true;
265 }
266
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000267 int SecLastOpcode = SecondLastInst->getOpcode();
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000268
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000269 bool SecLastOpcodeHasJMP_c = PredOpcodeHasJMP_c(SecLastOpcode);
270 bool SecLastOpcodeHasNot = PredOpcodeHasNot(SecLastOpcode);
271 if (SecLastOpcodeHasJMP_c && (LastOpcode == Hexagon::JMP)) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000272 TBB = SecondLastInst->getOperand(1).getMBB();
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000273 if (SecLastOpcodeHasNot)
274 Cond.push_back(MachineOperand::CreateImm(0));
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000275 Cond.push_back(SecondLastInst->getOperand(0));
276 FBB = LastInst->getOperand(0).getMBB();
277 return false;
278 }
279
280 // If the block ends with two Hexagon:JMPs, handle it. The second one is not
281 // executed, so remove it.
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000282 if (SecLastOpcode == Hexagon::JMP && LastOpcode == Hexagon::JMP) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000283 TBB = SecondLastInst->getOperand(0).getMBB();
284 I = LastInst;
285 if (AllowModify)
286 I->eraseFromParent();
287 return false;
288 }
289
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000290 // If the block ends with an ENDLOOP, and JMP, handle it.
291 if (SecLastOpcode == Hexagon::ENDLOOP0 &&
292 LastOpcode == Hexagon::JMP) {
293 TBB = SecondLastInst->getOperand(0).getMBB();
294 Cond.push_back(SecondLastInst->getOperand(0));
295 FBB = LastInst->getOperand(0).getMBB();
296 return false;
297 }
298
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000299 // Otherwise, can't handle this.
300 return true;
301}
302
303
304unsigned HexagonInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
305 int BOpc = Hexagon::JMP;
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000306 int BccOpc = Hexagon::JMP_t;
307 int BccOpcNot = Hexagon::JMP_f;
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000308
309 MachineBasicBlock::iterator I = MBB.end();
310 if (I == MBB.begin()) return 0;
311 --I;
312 if (I->getOpcode() != BOpc && I->getOpcode() != BccOpc &&
313 I->getOpcode() != BccOpcNot)
314 return 0;
315
316 // Remove the branch.
317 I->eraseFromParent();
318
319 I = MBB.end();
320
321 if (I == MBB.begin()) return 1;
322 --I;
323 if (I->getOpcode() != BccOpc && I->getOpcode() != BccOpcNot)
324 return 1;
325
326 // Remove the branch.
327 I->eraseFromParent();
328 return 2;
329}
330
331
Krzysztof Parzyszekcfe285e2013-02-11 20:04:29 +0000332/// \brief For a comparison instruction, return the source registers in
333/// \p SrcReg and \p SrcReg2 if having two register operands, and the value it
334/// compares against in CmpValue. Return true if the comparison instruction
335/// can be analyzed.
336bool HexagonInstrInfo::analyzeCompare(const MachineInstr *MI,
337 unsigned &SrcReg, unsigned &SrcReg2,
338 int &Mask, int &Value) const {
339 unsigned Opc = MI->getOpcode();
340
341 // Set mask and the first source register.
342 switch (Opc) {
343 case Hexagon::CMPEHexagon4rr:
344 case Hexagon::CMPEQri:
345 case Hexagon::CMPEQrr:
346 case Hexagon::CMPGT64rr:
347 case Hexagon::CMPGTU64rr:
348 case Hexagon::CMPGTUri:
349 case Hexagon::CMPGTUrr:
350 case Hexagon::CMPGTri:
351 case Hexagon::CMPGTrr:
Krzysztof Parzyszekcfe285e2013-02-11 20:04:29 +0000352 SrcReg = MI->getOperand(1).getReg();
353 Mask = ~0;
354 break;
355 case Hexagon::CMPbEQri_V4:
356 case Hexagon::CMPbEQrr_sbsb_V4:
357 case Hexagon::CMPbEQrr_ubub_V4:
358 case Hexagon::CMPbGTUri_V4:
359 case Hexagon::CMPbGTUrr_V4:
360 case Hexagon::CMPbGTrr_V4:
361 SrcReg = MI->getOperand(1).getReg();
362 Mask = 0xFF;
363 break;
364 case Hexagon::CMPhEQri_V4:
365 case Hexagon::CMPhEQrr_shl_V4:
366 case Hexagon::CMPhEQrr_xor_V4:
367 case Hexagon::CMPhGTUri_V4:
368 case Hexagon::CMPhGTUrr_V4:
369 case Hexagon::CMPhGTrr_shl_V4:
370 SrcReg = MI->getOperand(1).getReg();
371 Mask = 0xFFFF;
372 break;
373 }
374
375 // Set the value/second source register.
376 switch (Opc) {
377 case Hexagon::CMPEHexagon4rr:
378 case Hexagon::CMPEQrr:
379 case Hexagon::CMPGT64rr:
380 case Hexagon::CMPGTU64rr:
381 case Hexagon::CMPGTUrr:
382 case Hexagon::CMPGTrr:
383 case Hexagon::CMPbEQrr_sbsb_V4:
384 case Hexagon::CMPbEQrr_ubub_V4:
385 case Hexagon::CMPbGTUrr_V4:
386 case Hexagon::CMPbGTrr_V4:
387 case Hexagon::CMPhEQrr_shl_V4:
388 case Hexagon::CMPhEQrr_xor_V4:
389 case Hexagon::CMPhGTUrr_V4:
390 case Hexagon::CMPhGTrr_shl_V4:
Krzysztof Parzyszekcfe285e2013-02-11 20:04:29 +0000391 SrcReg2 = MI->getOperand(2).getReg();
392 return true;
393
394 case Hexagon::CMPEQri:
395 case Hexagon::CMPGTUri:
396 case Hexagon::CMPGTri:
397 case Hexagon::CMPbEQri_V4:
398 case Hexagon::CMPbGTUri_V4:
399 case Hexagon::CMPhEQri_V4:
400 case Hexagon::CMPhGTUri_V4:
401 SrcReg2 = 0;
402 Value = MI->getOperand(2).getImm();
403 return true;
404 }
405
406 return false;
407}
408
409
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000410void HexagonInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
411 MachineBasicBlock::iterator I, DebugLoc DL,
412 unsigned DestReg, unsigned SrcReg,
413 bool KillSrc) const {
414 if (Hexagon::IntRegsRegClass.contains(SrcReg, DestReg)) {
415 BuildMI(MBB, I, DL, get(Hexagon::TFR), DestReg).addReg(SrcReg);
416 return;
417 }
418 if (Hexagon::DoubleRegsRegClass.contains(SrcReg, DestReg)) {
Jyotsna Vermae95559f2012-11-29 19:35:44 +0000419 BuildMI(MBB, I, DL, get(Hexagon::TFR64), DestReg).addReg(SrcReg);
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000420 return;
421 }
422 if (Hexagon::PredRegsRegClass.contains(SrcReg, DestReg)) {
423 // Map Pd = Ps to Pd = or(Ps, Ps).
424 BuildMI(MBB, I, DL, get(Hexagon::OR_pp),
425 DestReg).addReg(SrcReg).addReg(SrcReg);
426 return;
427 }
Sirish Pande8bb97452012-05-12 05:54:15 +0000428 if (Hexagon::DoubleRegsRegClass.contains(DestReg) &&
429 Hexagon::IntRegsRegClass.contains(SrcReg)) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000430 // We can have an overlap between single and double reg: r1:0 = r0.
431 if(SrcReg == RI.getSubReg(DestReg, Hexagon::subreg_loreg)) {
432 // r1:0 = r0
433 BuildMI(MBB, I, DL, get(Hexagon::TFRI), (RI.getSubReg(DestReg,
434 Hexagon::subreg_hireg))).addImm(0);
435 } else {
436 // r1:0 = r1 or no overlap.
437 BuildMI(MBB, I, DL, get(Hexagon::TFR), (RI.getSubReg(DestReg,
438 Hexagon::subreg_loreg))).addReg(SrcReg);
439 BuildMI(MBB, I, DL, get(Hexagon::TFRI), (RI.getSubReg(DestReg,
440 Hexagon::subreg_hireg))).addImm(0);
441 }
442 return;
443 }
Sirish Pande8bb97452012-05-12 05:54:15 +0000444 if (Hexagon::CRRegsRegClass.contains(DestReg) &&
445 Hexagon::IntRegsRegClass.contains(SrcReg)) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000446 BuildMI(MBB, I, DL, get(Hexagon::TFCR), DestReg).addReg(SrcReg);
447 return;
Sirish Pande30804c22012-02-15 18:52:27 +0000448 }
Anshuman Dasguptae96f8042013-02-13 22:56:34 +0000449 if (Hexagon::PredRegsRegClass.contains(SrcReg) &&
450 Hexagon::IntRegsRegClass.contains(DestReg)) {
451 BuildMI(MBB, I, DL, get(Hexagon::TFR_RsPd), DestReg).
452 addReg(SrcReg, getKillRegState(KillSrc));
453 return;
454 }
455 if (Hexagon::IntRegsRegClass.contains(SrcReg) &&
456 Hexagon::PredRegsRegClass.contains(DestReg)) {
457 BuildMI(MBB, I, DL, get(Hexagon::TFR_PdRs), DestReg).
458 addReg(SrcReg, getKillRegState(KillSrc));
459 return;
460 }
Sirish Pande30804c22012-02-15 18:52:27 +0000461
462 llvm_unreachable("Unimplemented");
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000463}
464
465
466void HexagonInstrInfo::
467storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
468 unsigned SrcReg, bool isKill, int FI,
469 const TargetRegisterClass *RC,
470 const TargetRegisterInfo *TRI) const {
471
472 DebugLoc DL = MBB.findDebugLoc(I);
473 MachineFunction &MF = *MBB.getParent();
474 MachineFrameInfo &MFI = *MF.getFrameInfo();
475 unsigned Align = MFI.getObjectAlignment(FI);
476
477 MachineMemOperand *MMO =
478 MF.getMachineMemOperand(
479 MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)),
480 MachineMemOperand::MOStore,
481 MFI.getObjectSize(FI),
482 Align);
483
Craig Topperc7242e02012-04-20 07:30:17 +0000484 if (Hexagon::IntRegsRegClass.hasSubClassEq(RC)) {
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000485 BuildMI(MBB, I, DL, get(Hexagon::STriw))
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000486 .addFrameIndex(FI).addImm(0)
487 .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
Craig Topperc7242e02012-04-20 07:30:17 +0000488 } else if (Hexagon::DoubleRegsRegClass.hasSubClassEq(RC)) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000489 BuildMI(MBB, I, DL, get(Hexagon::STrid))
490 .addFrameIndex(FI).addImm(0)
491 .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
Craig Topperc7242e02012-04-20 07:30:17 +0000492 } else if (Hexagon::PredRegsRegClass.hasSubClassEq(RC)) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000493 BuildMI(MBB, I, DL, get(Hexagon::STriw_pred))
494 .addFrameIndex(FI).addImm(0)
495 .addReg(SrcReg, getKillRegState(isKill)).addMemOperand(MMO);
496 } else {
Craig Toppere55c5562012-02-07 02:50:20 +0000497 llvm_unreachable("Unimplemented");
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000498 }
499}
500
501
502void HexagonInstrInfo::storeRegToAddr(
503 MachineFunction &MF, unsigned SrcReg,
504 bool isKill,
505 SmallVectorImpl<MachineOperand> &Addr,
506 const TargetRegisterClass *RC,
507 SmallVectorImpl<MachineInstr*> &NewMIs) const
508{
Craig Toppere55c5562012-02-07 02:50:20 +0000509 llvm_unreachable("Unimplemented");
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000510}
511
512
513void HexagonInstrInfo::
514loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
515 unsigned DestReg, int FI,
516 const TargetRegisterClass *RC,
517 const TargetRegisterInfo *TRI) const {
518 DebugLoc DL = MBB.findDebugLoc(I);
519 MachineFunction &MF = *MBB.getParent();
520 MachineFrameInfo &MFI = *MF.getFrameInfo();
521 unsigned Align = MFI.getObjectAlignment(FI);
522
523 MachineMemOperand *MMO =
524 MF.getMachineMemOperand(
525 MachinePointerInfo(PseudoSourceValue::getFixedStack(FI)),
526 MachineMemOperand::MOLoad,
527 MFI.getObjectSize(FI),
528 Align);
Craig Topperc7242e02012-04-20 07:30:17 +0000529 if (RC == &Hexagon::IntRegsRegClass) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000530 BuildMI(MBB, I, DL, get(Hexagon::LDriw), DestReg)
531 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
Craig Topperc7242e02012-04-20 07:30:17 +0000532 } else if (RC == &Hexagon::DoubleRegsRegClass) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000533 BuildMI(MBB, I, DL, get(Hexagon::LDrid), DestReg)
534 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
Craig Topperc7242e02012-04-20 07:30:17 +0000535 } else if (RC == &Hexagon::PredRegsRegClass) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000536 BuildMI(MBB, I, DL, get(Hexagon::LDriw_pred), DestReg)
537 .addFrameIndex(FI).addImm(0).addMemOperand(MMO);
538 } else {
Craig Toppere55c5562012-02-07 02:50:20 +0000539 llvm_unreachable("Can't store this register to stack slot");
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000540 }
541}
542
543
544void HexagonInstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
545 SmallVectorImpl<MachineOperand> &Addr,
546 const TargetRegisterClass *RC,
547 SmallVectorImpl<MachineInstr*> &NewMIs) const {
Craig Toppere55c5562012-02-07 02:50:20 +0000548 llvm_unreachable("Unimplemented");
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000549}
550
551
552MachineInstr *HexagonInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
553 MachineInstr* MI,
554 const SmallVectorImpl<unsigned> &Ops,
555 int FI) const {
556 // Hexagon_TODO: Implement.
557 return(0);
558}
559
Jyotsna Vermaadd82b32013-03-29 21:09:53 +0000560MachineInstr*
561HexagonInstrInfo::emitFrameIndexDebugValue(MachineFunction &MF,
562 int FrameIx, uint64_t Offset,
563 const MDNode *MDPtr,
564 DebugLoc DL) const {
565 MachineInstrBuilder MIB = BuildMI(MF, DL, get(Hexagon::DBG_VALUE))
566 .addImm(0).addImm(Offset).addMetadata(MDPtr);
567 return &*MIB;
568}
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000569
570unsigned HexagonInstrInfo::createVR(MachineFunction* MF, MVT VT) const {
571
572 MachineRegisterInfo &RegInfo = MF->getRegInfo();
573 const TargetRegisterClass *TRC;
Sirish Pande69295b82012-05-10 20:20:25 +0000574 if (VT == MVT::i1) {
Craig Topperc7242e02012-04-20 07:30:17 +0000575 TRC = &Hexagon::PredRegsRegClass;
Sirish Pande69295b82012-05-10 20:20:25 +0000576 } else if (VT == MVT::i32 || VT == MVT::f32) {
Craig Topperc7242e02012-04-20 07:30:17 +0000577 TRC = &Hexagon::IntRegsRegClass;
Sirish Pande69295b82012-05-10 20:20:25 +0000578 } else if (VT == MVT::i64 || VT == MVT::f64) {
Craig Topperc7242e02012-04-20 07:30:17 +0000579 TRC = &Hexagon::DoubleRegsRegClass;
Sirish Pande69295b82012-05-10 20:20:25 +0000580 } else {
Benjamin Kramerb6684012011-12-27 11:41:05 +0000581 llvm_unreachable("Cannot handle this register class");
Sirish Pande69295b82012-05-10 20:20:25 +0000582 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000583
584 unsigned NewReg = RegInfo.createVirtualRegister(TRC);
585 return NewReg;
586}
587
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000588bool HexagonInstrInfo::isExtendable(const MachineInstr *MI) const {
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000589 // Constant extenders are allowed only for V4 and above.
590 if (!Subtarget.hasV4TOps())
591 return false;
592
593 const MCInstrDesc &MID = MI->getDesc();
594 const uint64_t F = MID.TSFlags;
595 if ((F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask)
596 return true;
597
598 // TODO: This is largely obsolete now. Will need to be removed
599 // in consecutive patches.
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000600 switch(MI->getOpcode()) {
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000601 // TFR_FI Remains a special case.
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000602 case Hexagon::TFR_FI:
603 return true;
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000604 default:
605 return false;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000606 }
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000607 return false;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000608}
609
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000610// This returns true in two cases:
611// - The OP code itself indicates that this is an extended instruction.
612// - One of MOs has been marked with HMOTF_ConstExtended flag.
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000613bool HexagonInstrInfo::isExtended(const MachineInstr *MI) const {
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000614 // First check if this is permanently extended op code.
615 const uint64_t F = MI->getDesc().TSFlags;
616 if ((F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask)
617 return true;
618 // Use MO operand flags to determine if one of MI's operands
619 // has HMOTF_ConstExtended flag set.
620 for (MachineInstr::const_mop_iterator I = MI->operands_begin(),
621 E = MI->operands_end(); I != E; ++I) {
622 if (I->getTargetFlags() && HexagonII::HMOTF_ConstExtended)
Sirish Pande69295b82012-05-10 20:20:25 +0000623 return true;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000624 }
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000625 return false;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000626}
627
Jyotsna Verma7e7c7302013-05-02 21:21:57 +0000628bool HexagonInstrInfo::isBranch (const MachineInstr *MI) const {
629 return MI->getDesc().isBranch();
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000630}
631
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000632bool HexagonInstrInfo::isNewValueStore(const MachineInstr *MI) const {
633 switch (MI->getOpcode()) {
634 default: return false;
635 // Store Byte
636 case Hexagon::STrib_nv_V4:
637 case Hexagon::STrib_indexed_nv_V4:
638 case Hexagon::STrib_indexed_shl_nv_V4:
639 case Hexagon::STrib_shl_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000640 case Hexagon::STb_GP_nv_V4:
641 case Hexagon::POST_STbri_nv_V4:
642 case Hexagon::STrib_cPt_nv_V4:
643 case Hexagon::STrib_cdnPt_nv_V4:
644 case Hexagon::STrib_cNotPt_nv_V4:
645 case Hexagon::STrib_cdnNotPt_nv_V4:
646 case Hexagon::STrib_indexed_cPt_nv_V4:
647 case Hexagon::STrib_indexed_cdnPt_nv_V4:
648 case Hexagon::STrib_indexed_cNotPt_nv_V4:
649 case Hexagon::STrib_indexed_cdnNotPt_nv_V4:
650 case Hexagon::STrib_indexed_shl_cPt_nv_V4:
651 case Hexagon::STrib_indexed_shl_cdnPt_nv_V4:
652 case Hexagon::STrib_indexed_shl_cNotPt_nv_V4:
653 case Hexagon::STrib_indexed_shl_cdnNotPt_nv_V4:
654 case Hexagon::POST_STbri_cPt_nv_V4:
655 case Hexagon::POST_STbri_cdnPt_nv_V4:
656 case Hexagon::POST_STbri_cNotPt_nv_V4:
657 case Hexagon::POST_STbri_cdnNotPt_nv_V4:
658 case Hexagon::STb_GP_cPt_nv_V4:
659 case Hexagon::STb_GP_cNotPt_nv_V4:
660 case Hexagon::STb_GP_cdnPt_nv_V4:
661 case Hexagon::STb_GP_cdnNotPt_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000662 case Hexagon::STrib_abs_nv_V4:
663 case Hexagon::STrib_abs_cPt_nv_V4:
664 case Hexagon::STrib_abs_cdnPt_nv_V4:
665 case Hexagon::STrib_abs_cNotPt_nv_V4:
666 case Hexagon::STrib_abs_cdnNotPt_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000667
668 // Store Halfword
669 case Hexagon::STrih_nv_V4:
670 case Hexagon::STrih_indexed_nv_V4:
671 case Hexagon::STrih_indexed_shl_nv_V4:
672 case Hexagon::STrih_shl_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000673 case Hexagon::STh_GP_nv_V4:
674 case Hexagon::POST_SThri_nv_V4:
675 case Hexagon::STrih_cPt_nv_V4:
676 case Hexagon::STrih_cdnPt_nv_V4:
677 case Hexagon::STrih_cNotPt_nv_V4:
678 case Hexagon::STrih_cdnNotPt_nv_V4:
679 case Hexagon::STrih_indexed_cPt_nv_V4:
680 case Hexagon::STrih_indexed_cdnPt_nv_V4:
681 case Hexagon::STrih_indexed_cNotPt_nv_V4:
682 case Hexagon::STrih_indexed_cdnNotPt_nv_V4:
683 case Hexagon::STrih_indexed_shl_cPt_nv_V4:
684 case Hexagon::STrih_indexed_shl_cdnPt_nv_V4:
685 case Hexagon::STrih_indexed_shl_cNotPt_nv_V4:
686 case Hexagon::STrih_indexed_shl_cdnNotPt_nv_V4:
687 case Hexagon::POST_SThri_cPt_nv_V4:
688 case Hexagon::POST_SThri_cdnPt_nv_V4:
689 case Hexagon::POST_SThri_cNotPt_nv_V4:
690 case Hexagon::POST_SThri_cdnNotPt_nv_V4:
691 case Hexagon::STh_GP_cPt_nv_V4:
692 case Hexagon::STh_GP_cNotPt_nv_V4:
693 case Hexagon::STh_GP_cdnPt_nv_V4:
694 case Hexagon::STh_GP_cdnNotPt_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000695 case Hexagon::STrih_abs_nv_V4:
696 case Hexagon::STrih_abs_cPt_nv_V4:
697 case Hexagon::STrih_abs_cdnPt_nv_V4:
698 case Hexagon::STrih_abs_cNotPt_nv_V4:
699 case Hexagon::STrih_abs_cdnNotPt_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000700
701 // Store Word
702 case Hexagon::STriw_nv_V4:
703 case Hexagon::STriw_indexed_nv_V4:
704 case Hexagon::STriw_indexed_shl_nv_V4:
705 case Hexagon::STriw_shl_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000706 case Hexagon::STw_GP_nv_V4:
707 case Hexagon::POST_STwri_nv_V4:
708 case Hexagon::STriw_cPt_nv_V4:
709 case Hexagon::STriw_cdnPt_nv_V4:
710 case Hexagon::STriw_cNotPt_nv_V4:
711 case Hexagon::STriw_cdnNotPt_nv_V4:
712 case Hexagon::STriw_indexed_cPt_nv_V4:
713 case Hexagon::STriw_indexed_cdnPt_nv_V4:
714 case Hexagon::STriw_indexed_cNotPt_nv_V4:
715 case Hexagon::STriw_indexed_cdnNotPt_nv_V4:
716 case Hexagon::STriw_indexed_shl_cPt_nv_V4:
717 case Hexagon::STriw_indexed_shl_cdnPt_nv_V4:
718 case Hexagon::STriw_indexed_shl_cNotPt_nv_V4:
719 case Hexagon::STriw_indexed_shl_cdnNotPt_nv_V4:
720 case Hexagon::POST_STwri_cPt_nv_V4:
721 case Hexagon::POST_STwri_cdnPt_nv_V4:
722 case Hexagon::POST_STwri_cNotPt_nv_V4:
723 case Hexagon::POST_STwri_cdnNotPt_nv_V4:
724 case Hexagon::STw_GP_cPt_nv_V4:
725 case Hexagon::STw_GP_cNotPt_nv_V4:
726 case Hexagon::STw_GP_cdnPt_nv_V4:
727 case Hexagon::STw_GP_cdnNotPt_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000728 case Hexagon::STriw_abs_nv_V4:
729 case Hexagon::STriw_abs_cPt_nv_V4:
730 case Hexagon::STriw_abs_cdnPt_nv_V4:
731 case Hexagon::STriw_abs_cNotPt_nv_V4:
732 case Hexagon::STriw_abs_cdnNotPt_nv_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000733 return true;
734 }
735}
736
737bool HexagonInstrInfo::isPostIncrement (const MachineInstr* MI) const {
738 switch (MI->getOpcode())
739 {
740 default: return false;
741 // Load Byte
742 case Hexagon::POST_LDrib:
743 case Hexagon::POST_LDrib_cPt:
744 case Hexagon::POST_LDrib_cNotPt:
745 case Hexagon::POST_LDrib_cdnPt_V4:
746 case Hexagon::POST_LDrib_cdnNotPt_V4:
747
748 // Load unsigned byte
749 case Hexagon::POST_LDriub:
750 case Hexagon::POST_LDriub_cPt:
751 case Hexagon::POST_LDriub_cNotPt:
752 case Hexagon::POST_LDriub_cdnPt_V4:
753 case Hexagon::POST_LDriub_cdnNotPt_V4:
754
755 // Load halfword
756 case Hexagon::POST_LDrih:
757 case Hexagon::POST_LDrih_cPt:
758 case Hexagon::POST_LDrih_cNotPt:
759 case Hexagon::POST_LDrih_cdnPt_V4:
760 case Hexagon::POST_LDrih_cdnNotPt_V4:
761
762 // Load unsigned halfword
763 case Hexagon::POST_LDriuh:
764 case Hexagon::POST_LDriuh_cPt:
765 case Hexagon::POST_LDriuh_cNotPt:
766 case Hexagon::POST_LDriuh_cdnPt_V4:
767 case Hexagon::POST_LDriuh_cdnNotPt_V4:
768
769 // Load word
770 case Hexagon::POST_LDriw:
771 case Hexagon::POST_LDriw_cPt:
772 case Hexagon::POST_LDriw_cNotPt:
773 case Hexagon::POST_LDriw_cdnPt_V4:
774 case Hexagon::POST_LDriw_cdnNotPt_V4:
775
776 // Load double word
777 case Hexagon::POST_LDrid:
778 case Hexagon::POST_LDrid_cPt:
779 case Hexagon::POST_LDrid_cNotPt:
780 case Hexagon::POST_LDrid_cdnPt_V4:
781 case Hexagon::POST_LDrid_cdnNotPt_V4:
782
783 // Store byte
784 case Hexagon::POST_STbri:
785 case Hexagon::POST_STbri_cPt:
786 case Hexagon::POST_STbri_cNotPt:
787 case Hexagon::POST_STbri_cdnPt_V4:
788 case Hexagon::POST_STbri_cdnNotPt_V4:
789
790 // Store halfword
791 case Hexagon::POST_SThri:
792 case Hexagon::POST_SThri_cPt:
793 case Hexagon::POST_SThri_cNotPt:
794 case Hexagon::POST_SThri_cdnPt_V4:
795 case Hexagon::POST_SThri_cdnNotPt_V4:
796
797 // Store word
798 case Hexagon::POST_STwri:
799 case Hexagon::POST_STwri_cPt:
800 case Hexagon::POST_STwri_cNotPt:
801 case Hexagon::POST_STwri_cdnPt_V4:
802 case Hexagon::POST_STwri_cdnNotPt_V4:
803
804 // Store double word
805 case Hexagon::POST_STdri:
806 case Hexagon::POST_STdri_cPt:
807 case Hexagon::POST_STdri_cNotPt:
808 case Hexagon::POST_STdri_cdnPt_V4:
809 case Hexagon::POST_STdri_cdnNotPt_V4:
810 return true;
811 }
812}
813
Jyotsna Vermaf1214a82013-03-05 18:51:42 +0000814bool HexagonInstrInfo::isNewValueInst(const MachineInstr *MI) const {
815 if (isNewValueJump(MI))
816 return true;
817
818 if (isNewValueStore(MI))
819 return true;
820
821 return false;
822}
823
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000824bool HexagonInstrInfo::isSaveCalleeSavedRegsCall(const MachineInstr *MI) const {
825 return MI->getOpcode() == Hexagon::SAVE_REGISTERS_CALL_V4;
826}
Andrew Trickd06df962012-02-01 22:13:57 +0000827
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000828bool HexagonInstrInfo::isPredicable(MachineInstr *MI) const {
829 bool isPred = MI->getDesc().isPredicable();
830
831 if (!isPred)
832 return false;
833
834 const int Opc = MI->getOpcode();
835
836 switch(Opc) {
837 case Hexagon::TFRI:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000838 return isInt<12>(MI->getOperand(1).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000839
840 case Hexagon::STrid:
841 case Hexagon::STrid_indexed:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000842 return isShiftedUInt<6,3>(MI->getOperand(1).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000843
844 case Hexagon::STriw:
845 case Hexagon::STriw_indexed:
846 case Hexagon::STriw_nv_V4:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000847 return isShiftedUInt<6,2>(MI->getOperand(1).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000848
849 case Hexagon::STrih:
850 case Hexagon::STrih_indexed:
851 case Hexagon::STrih_nv_V4:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000852 return isShiftedUInt<6,1>(MI->getOperand(1).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000853
854 case Hexagon::STrib:
855 case Hexagon::STrib_indexed:
856 case Hexagon::STrib_nv_V4:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000857 return isUInt<6>(MI->getOperand(1).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000858
859 case Hexagon::LDrid:
860 case Hexagon::LDrid_indexed:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000861 return isShiftedUInt<6,3>(MI->getOperand(2).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000862
863 case Hexagon::LDriw:
864 case Hexagon::LDriw_indexed:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000865 return isShiftedUInt<6,2>(MI->getOperand(2).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000866
867 case Hexagon::LDrih:
868 case Hexagon::LDriuh:
869 case Hexagon::LDrih_indexed:
870 case Hexagon::LDriuh_indexed:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000871 return isShiftedUInt<6,1>(MI->getOperand(2).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000872
873 case Hexagon::LDrib:
874 case Hexagon::LDriub:
875 case Hexagon::LDrib_indexed:
876 case Hexagon::LDriub_indexed:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000877 return isUInt<6>(MI->getOperand(2).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000878
879 case Hexagon::POST_LDrid:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000880 return isShiftedInt<4,3>(MI->getOperand(3).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000881
882 case Hexagon::POST_LDriw:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000883 return isShiftedInt<4,2>(MI->getOperand(3).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000884
885 case Hexagon::POST_LDrih:
886 case Hexagon::POST_LDriuh:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000887 return isShiftedInt<4,1>(MI->getOperand(3).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000888
889 case Hexagon::POST_LDrib:
890 case Hexagon::POST_LDriub:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000891 return isInt<4>(MI->getOperand(3).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000892
893 case Hexagon::STrib_imm_V4:
894 case Hexagon::STrih_imm_V4:
895 case Hexagon::STriw_imm_V4:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000896 return (isUInt<6>(MI->getOperand(1).getImm()) &&
897 isInt<6>(MI->getOperand(2).getImm()));
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000898
899 case Hexagon::ADD_ri:
Brendon Cahoonf6b687e2012-05-14 19:35:42 +0000900 return isInt<8>(MI->getOperand(2).getImm());
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000901
902 case Hexagon::ASLH:
903 case Hexagon::ASRH:
904 case Hexagon::SXTB:
905 case Hexagon::SXTH:
906 case Hexagon::ZXTB:
907 case Hexagon::ZXTH:
Sirish Pande8bb97452012-05-12 05:54:15 +0000908 return Subtarget.hasV4TOps();
Tony Linthicum1213a7a2011-12-12 21:14:40 +0000909 }
910
911 return true;
912}
913
Sirish Pande8bb97452012-05-12 05:54:15 +0000914// This function performs the following inversiones:
915//
916// cPt ---> cNotPt
917// cNotPt ---> cPt
918//
919// however, these inversiones are NOT included:
920//
921// cdnPt -X-> cdnNotPt
922// cdnNotPt -X-> cdnPt
923// cPt_nv -X-> cNotPt_nv (new value stores)
924// cNotPt_nv -X-> cPt_nv (new value stores)
925//
926// because only the following transformations are allowed:
927//
928// cNotPt ---> cdnNotPt
929// cPt ---> cdnPt
930// cNotPt ---> cNotPt_nv
931// cPt ---> cPt_nv
Sirish Pande30804c22012-02-15 18:52:27 +0000932unsigned HexagonInstrInfo::getInvertedPredicatedOpcode(const int Opc) const {
Jyotsna Verma7e7c7302013-05-02 21:21:57 +0000933 int InvPredOpcode;
934 InvPredOpcode = isPredicatedTrue(Opc) ? Hexagon::getFalsePredOpcode(Opc)
935 : Hexagon::getTruePredOpcode(Opc);
936 if (InvPredOpcode >= 0) // Valid instruction with the inverted predicate.
937 return InvPredOpcode;
938
Sirish Pande30804c22012-02-15 18:52:27 +0000939 switch(Opc) {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +0000940 default: llvm_unreachable("Unexpected predicated instruction");
Sirish Pande30804c22012-02-15 18:52:27 +0000941 case Hexagon::TFR_cPt:
942 return Hexagon::TFR_cNotPt;
943 case Hexagon::TFR_cNotPt:
944 return Hexagon::TFR_cPt;
945
946 case Hexagon::TFRI_cPt:
947 return Hexagon::TFRI_cNotPt;
948 case Hexagon::TFRI_cNotPt:
949 return Hexagon::TFRI_cPt;
950
Jyotsna Verma5ed51812013-05-01 21:37:34 +0000951 case Hexagon::JMP_t:
952 return Hexagon::JMP_f;
953 case Hexagon::JMP_f:
954 return Hexagon::JMP_t;
Sirish Pande30804c22012-02-15 18:52:27 +0000955
956 case Hexagon::ADD_ri_cPt:
957 return Hexagon::ADD_ri_cNotPt;
958 case Hexagon::ADD_ri_cNotPt:
959 return Hexagon::ADD_ri_cPt;
960
961 case Hexagon::ADD_rr_cPt:
962 return Hexagon::ADD_rr_cNotPt;
963 case Hexagon::ADD_rr_cNotPt:
964 return Hexagon::ADD_rr_cPt;
965
966 case Hexagon::XOR_rr_cPt:
967 return Hexagon::XOR_rr_cNotPt;
968 case Hexagon::XOR_rr_cNotPt:
969 return Hexagon::XOR_rr_cPt;
970
971 case Hexagon::AND_rr_cPt:
972 return Hexagon::AND_rr_cNotPt;
973 case Hexagon::AND_rr_cNotPt:
974 return Hexagon::AND_rr_cPt;
975
976 case Hexagon::OR_rr_cPt:
977 return Hexagon::OR_rr_cNotPt;
978 case Hexagon::OR_rr_cNotPt:
979 return Hexagon::OR_rr_cPt;
980
981 case Hexagon::SUB_rr_cPt:
982 return Hexagon::SUB_rr_cNotPt;
983 case Hexagon::SUB_rr_cNotPt:
984 return Hexagon::SUB_rr_cPt;
985
986 case Hexagon::COMBINE_rr_cPt:
987 return Hexagon::COMBINE_rr_cNotPt;
988 case Hexagon::COMBINE_rr_cNotPt:
989 return Hexagon::COMBINE_rr_cPt;
990
991 case Hexagon::ASLH_cPt_V4:
992 return Hexagon::ASLH_cNotPt_V4;
993 case Hexagon::ASLH_cNotPt_V4:
994 return Hexagon::ASLH_cPt_V4;
995
996 case Hexagon::ASRH_cPt_V4:
997 return Hexagon::ASRH_cNotPt_V4;
998 case Hexagon::ASRH_cNotPt_V4:
999 return Hexagon::ASRH_cPt_V4;
1000
1001 case Hexagon::SXTB_cPt_V4:
1002 return Hexagon::SXTB_cNotPt_V4;
1003 case Hexagon::SXTB_cNotPt_V4:
1004 return Hexagon::SXTB_cPt_V4;
1005
1006 case Hexagon::SXTH_cPt_V4:
1007 return Hexagon::SXTH_cNotPt_V4;
1008 case Hexagon::SXTH_cNotPt_V4:
1009 return Hexagon::SXTH_cPt_V4;
1010
1011 case Hexagon::ZXTB_cPt_V4:
1012 return Hexagon::ZXTB_cNotPt_V4;
1013 case Hexagon::ZXTB_cNotPt_V4:
1014 return Hexagon::ZXTB_cPt_V4;
1015
1016 case Hexagon::ZXTH_cPt_V4:
1017 return Hexagon::ZXTH_cNotPt_V4;
1018 case Hexagon::ZXTH_cNotPt_V4:
1019 return Hexagon::ZXTH_cPt_V4;
1020
1021
Jyotsna Verma5ed51812013-05-01 21:37:34 +00001022 case Hexagon::JMPR_t:
1023 return Hexagon::JMPR_f;
1024 case Hexagon::JMPR_f:
1025 return Hexagon::JMPR_t;
Sirish Pande30804c22012-02-15 18:52:27 +00001026
1027 // V4 indexed+scaled load.
Sirish Pande30804c22012-02-15 18:52:27 +00001028 case Hexagon::LDrid_indexed_shl_cPt_V4:
1029 return Hexagon::LDrid_indexed_shl_cNotPt_V4;
1030 case Hexagon::LDrid_indexed_shl_cNotPt_V4:
1031 return Hexagon::LDrid_indexed_shl_cPt_V4;
1032
Sirish Pande30804c22012-02-15 18:52:27 +00001033 case Hexagon::LDrib_indexed_shl_cPt_V4:
1034 return Hexagon::LDrib_indexed_shl_cNotPt_V4;
1035 case Hexagon::LDrib_indexed_shl_cNotPt_V4:
1036 return Hexagon::LDrib_indexed_shl_cPt_V4;
1037
1038 case Hexagon::LDriub_indexed_shl_cPt_V4:
1039 return Hexagon::LDriub_indexed_shl_cNotPt_V4;
1040 case Hexagon::LDriub_indexed_shl_cNotPt_V4:
1041 return Hexagon::LDriub_indexed_shl_cPt_V4;
1042
Sirish Pande30804c22012-02-15 18:52:27 +00001043 case Hexagon::LDrih_indexed_shl_cPt_V4:
1044 return Hexagon::LDrih_indexed_shl_cNotPt_V4;
1045 case Hexagon::LDrih_indexed_shl_cNotPt_V4:
1046 return Hexagon::LDrih_indexed_shl_cPt_V4;
1047
1048 case Hexagon::LDriuh_indexed_shl_cPt_V4:
1049 return Hexagon::LDriuh_indexed_shl_cNotPt_V4;
1050 case Hexagon::LDriuh_indexed_shl_cNotPt_V4:
1051 return Hexagon::LDriuh_indexed_shl_cPt_V4;
1052
Sirish Pande30804c22012-02-15 18:52:27 +00001053 case Hexagon::LDriw_indexed_shl_cPt_V4:
1054 return Hexagon::LDriw_indexed_shl_cNotPt_V4;
1055 case Hexagon::LDriw_indexed_shl_cNotPt_V4:
1056 return Hexagon::LDriw_indexed_shl_cPt_V4;
1057
1058 // Byte.
1059 case Hexagon::POST_STbri_cPt:
1060 return Hexagon::POST_STbri_cNotPt;
1061 case Hexagon::POST_STbri_cNotPt:
1062 return Hexagon::POST_STbri_cPt;
1063
1064 case Hexagon::STrib_cPt:
1065 return Hexagon::STrib_cNotPt;
1066 case Hexagon::STrib_cNotPt:
1067 return Hexagon::STrib_cPt;
1068
1069 case Hexagon::STrib_indexed_cPt:
1070 return Hexagon::STrib_indexed_cNotPt;
1071 case Hexagon::STrib_indexed_cNotPt:
1072 return Hexagon::STrib_indexed_cPt;
1073
1074 case Hexagon::STrib_imm_cPt_V4:
1075 return Hexagon::STrib_imm_cNotPt_V4;
1076 case Hexagon::STrib_imm_cNotPt_V4:
1077 return Hexagon::STrib_imm_cPt_V4;
1078
1079 case Hexagon::STrib_indexed_shl_cPt_V4:
1080 return Hexagon::STrib_indexed_shl_cNotPt_V4;
1081 case Hexagon::STrib_indexed_shl_cNotPt_V4:
1082 return Hexagon::STrib_indexed_shl_cPt_V4;
1083
1084 // Halfword.
1085 case Hexagon::POST_SThri_cPt:
1086 return Hexagon::POST_SThri_cNotPt;
1087 case Hexagon::POST_SThri_cNotPt:
1088 return Hexagon::POST_SThri_cPt;
1089
1090 case Hexagon::STrih_cPt:
1091 return Hexagon::STrih_cNotPt;
1092 case Hexagon::STrih_cNotPt:
1093 return Hexagon::STrih_cPt;
1094
1095 case Hexagon::STrih_indexed_cPt:
1096 return Hexagon::STrih_indexed_cNotPt;
1097 case Hexagon::STrih_indexed_cNotPt:
1098 return Hexagon::STrih_indexed_cPt;
1099
1100 case Hexagon::STrih_imm_cPt_V4:
1101 return Hexagon::STrih_imm_cNotPt_V4;
1102 case Hexagon::STrih_imm_cNotPt_V4:
1103 return Hexagon::STrih_imm_cPt_V4;
1104
1105 case Hexagon::STrih_indexed_shl_cPt_V4:
1106 return Hexagon::STrih_indexed_shl_cNotPt_V4;
1107 case Hexagon::STrih_indexed_shl_cNotPt_V4:
1108 return Hexagon::STrih_indexed_shl_cPt_V4;
1109
1110 // Word.
1111 case Hexagon::POST_STwri_cPt:
1112 return Hexagon::POST_STwri_cNotPt;
1113 case Hexagon::POST_STwri_cNotPt:
1114 return Hexagon::POST_STwri_cPt;
1115
1116 case Hexagon::STriw_cPt:
1117 return Hexagon::STriw_cNotPt;
1118 case Hexagon::STriw_cNotPt:
1119 return Hexagon::STriw_cPt;
1120
1121 case Hexagon::STriw_indexed_cPt:
1122 return Hexagon::STriw_indexed_cNotPt;
1123 case Hexagon::STriw_indexed_cNotPt:
1124 return Hexagon::STriw_indexed_cPt;
1125
1126 case Hexagon::STriw_indexed_shl_cPt_V4:
1127 return Hexagon::STriw_indexed_shl_cNotPt_V4;
1128 case Hexagon::STriw_indexed_shl_cNotPt_V4:
1129 return Hexagon::STriw_indexed_shl_cPt_V4;
1130
1131 case Hexagon::STriw_imm_cPt_V4:
1132 return Hexagon::STriw_imm_cNotPt_V4;
1133 case Hexagon::STriw_imm_cNotPt_V4:
1134 return Hexagon::STriw_imm_cPt_V4;
1135
1136 // Double word.
1137 case Hexagon::POST_STdri_cPt:
1138 return Hexagon::POST_STdri_cNotPt;
1139 case Hexagon::POST_STdri_cNotPt:
1140 return Hexagon::POST_STdri_cPt;
1141
1142 case Hexagon::STrid_cPt:
1143 return Hexagon::STrid_cNotPt;
1144 case Hexagon::STrid_cNotPt:
1145 return Hexagon::STrid_cPt;
1146
1147 case Hexagon::STrid_indexed_cPt:
1148 return Hexagon::STrid_indexed_cNotPt;
1149 case Hexagon::STrid_indexed_cNotPt:
1150 return Hexagon::STrid_indexed_cPt;
1151
1152 case Hexagon::STrid_indexed_shl_cPt_V4:
1153 return Hexagon::STrid_indexed_shl_cNotPt_V4;
1154 case Hexagon::STrid_indexed_shl_cNotPt_V4:
1155 return Hexagon::STrid_indexed_shl_cPt_V4;
1156
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001157 // V4 Store to global address.
1158 case Hexagon::STd_GP_cPt_V4:
1159 return Hexagon::STd_GP_cNotPt_V4;
1160 case Hexagon::STd_GP_cNotPt_V4:
1161 return Hexagon::STd_GP_cPt_V4;
1162
1163 case Hexagon::STb_GP_cPt_V4:
1164 return Hexagon::STb_GP_cNotPt_V4;
1165 case Hexagon::STb_GP_cNotPt_V4:
1166 return Hexagon::STb_GP_cPt_V4;
1167
1168 case Hexagon::STh_GP_cPt_V4:
1169 return Hexagon::STh_GP_cNotPt_V4;
1170 case Hexagon::STh_GP_cNotPt_V4:
1171 return Hexagon::STh_GP_cPt_V4;
1172
1173 case Hexagon::STw_GP_cPt_V4:
1174 return Hexagon::STw_GP_cNotPt_V4;
1175 case Hexagon::STw_GP_cNotPt_V4:
1176 return Hexagon::STw_GP_cPt_V4;
1177
Sirish Pande30804c22012-02-15 18:52:27 +00001178 // Load.
1179 case Hexagon::LDrid_cPt:
1180 return Hexagon::LDrid_cNotPt;
1181 case Hexagon::LDrid_cNotPt:
1182 return Hexagon::LDrid_cPt;
1183
1184 case Hexagon::LDriw_cPt:
1185 return Hexagon::LDriw_cNotPt;
1186 case Hexagon::LDriw_cNotPt:
1187 return Hexagon::LDriw_cPt;
1188
1189 case Hexagon::LDrih_cPt:
1190 return Hexagon::LDrih_cNotPt;
1191 case Hexagon::LDrih_cNotPt:
1192 return Hexagon::LDrih_cPt;
1193
1194 case Hexagon::LDriuh_cPt:
1195 return Hexagon::LDriuh_cNotPt;
1196 case Hexagon::LDriuh_cNotPt:
1197 return Hexagon::LDriuh_cPt;
1198
1199 case Hexagon::LDrib_cPt:
1200 return Hexagon::LDrib_cNotPt;
1201 case Hexagon::LDrib_cNotPt:
1202 return Hexagon::LDrib_cPt;
1203
1204 case Hexagon::LDriub_cPt:
1205 return Hexagon::LDriub_cNotPt;
1206 case Hexagon::LDriub_cNotPt:
1207 return Hexagon::LDriub_cPt;
1208
1209 // Load Indexed.
1210 case Hexagon::LDrid_indexed_cPt:
1211 return Hexagon::LDrid_indexed_cNotPt;
1212 case Hexagon::LDrid_indexed_cNotPt:
1213 return Hexagon::LDrid_indexed_cPt;
1214
1215 case Hexagon::LDriw_indexed_cPt:
1216 return Hexagon::LDriw_indexed_cNotPt;
1217 case Hexagon::LDriw_indexed_cNotPt:
1218 return Hexagon::LDriw_indexed_cPt;
1219
1220 case Hexagon::LDrih_indexed_cPt:
1221 return Hexagon::LDrih_indexed_cNotPt;
1222 case Hexagon::LDrih_indexed_cNotPt:
1223 return Hexagon::LDrih_indexed_cPt;
1224
1225 case Hexagon::LDriuh_indexed_cPt:
1226 return Hexagon::LDriuh_indexed_cNotPt;
1227 case Hexagon::LDriuh_indexed_cNotPt:
1228 return Hexagon::LDriuh_indexed_cPt;
1229
1230 case Hexagon::LDrib_indexed_cPt:
1231 return Hexagon::LDrib_indexed_cNotPt;
1232 case Hexagon::LDrib_indexed_cNotPt:
1233 return Hexagon::LDrib_indexed_cPt;
1234
1235 case Hexagon::LDriub_indexed_cPt:
1236 return Hexagon::LDriub_indexed_cNotPt;
1237 case Hexagon::LDriub_indexed_cNotPt:
1238 return Hexagon::LDriub_indexed_cPt;
1239
1240 // Post Inc Load.
1241 case Hexagon::POST_LDrid_cPt:
1242 return Hexagon::POST_LDrid_cNotPt;
1243 case Hexagon::POST_LDriw_cNotPt:
1244 return Hexagon::POST_LDriw_cPt;
1245
1246 case Hexagon::POST_LDrih_cPt:
1247 return Hexagon::POST_LDrih_cNotPt;
1248 case Hexagon::POST_LDrih_cNotPt:
1249 return Hexagon::POST_LDrih_cPt;
1250
1251 case Hexagon::POST_LDriuh_cPt:
1252 return Hexagon::POST_LDriuh_cNotPt;
1253 case Hexagon::POST_LDriuh_cNotPt:
1254 return Hexagon::POST_LDriuh_cPt;
1255
1256 case Hexagon::POST_LDrib_cPt:
1257 return Hexagon::POST_LDrib_cNotPt;
1258 case Hexagon::POST_LDrib_cNotPt:
1259 return Hexagon::POST_LDrib_cPt;
1260
1261 case Hexagon::POST_LDriub_cPt:
1262 return Hexagon::POST_LDriub_cNotPt;
1263 case Hexagon::POST_LDriub_cNotPt:
1264 return Hexagon::POST_LDriub_cPt;
1265
1266 // Dealloc_return.
1267 case Hexagon::DEALLOC_RET_cPt_V4:
1268 return Hexagon::DEALLOC_RET_cNotPt_V4;
1269 case Hexagon::DEALLOC_RET_cNotPt_V4:
1270 return Hexagon::DEALLOC_RET_cPt_V4;
Sirish Pande30804c22012-02-15 18:52:27 +00001271 }
1272}
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001273
Andrew Trickd06df962012-02-01 22:13:57 +00001274
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001275int HexagonInstrInfo::
1276getMatchingCondBranchOpcode(int Opc, bool invertPredicate) const {
Pranav Bhandarkar34b60182012-11-01 19:13:23 +00001277 enum Hexagon::PredSense inPredSense;
1278 inPredSense = invertPredicate ? Hexagon::PredSense_false :
1279 Hexagon::PredSense_true;
1280 int CondOpcode = Hexagon::getPredOpcode(Opc, inPredSense);
1281 if (CondOpcode >= 0) // Valid Conditional opcode/instruction
1282 return CondOpcode;
1283
1284 // This switch case will be removed once all the instructions have been
1285 // modified to use relation maps.
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001286 switch(Opc) {
1287 case Hexagon::TFR:
1288 return !invertPredicate ? Hexagon::TFR_cPt :
1289 Hexagon::TFR_cNotPt;
Sirish Pande69295b82012-05-10 20:20:25 +00001290 case Hexagon::TFRI_f:
1291 return !invertPredicate ? Hexagon::TFRI_cPt_f :
1292 Hexagon::TFRI_cNotPt_f;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001293 case Hexagon::TFRI:
1294 return !invertPredicate ? Hexagon::TFRI_cPt :
1295 Hexagon::TFRI_cNotPt;
1296 case Hexagon::JMP:
Jyotsna Verma5ed51812013-05-01 21:37:34 +00001297 return !invertPredicate ? Hexagon::JMP_t :
1298 Hexagon::JMP_f;
Jyotsna Verma7e7c7302013-05-02 21:21:57 +00001299
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001300 case Hexagon::COMBINE_rr:
1301 return !invertPredicate ? Hexagon::COMBINE_rr_cPt :
1302 Hexagon::COMBINE_rr_cNotPt;
1303 case Hexagon::ASLH:
1304 return !invertPredicate ? Hexagon::ASLH_cPt_V4 :
1305 Hexagon::ASLH_cNotPt_V4;
1306 case Hexagon::ASRH:
1307 return !invertPredicate ? Hexagon::ASRH_cPt_V4 :
1308 Hexagon::ASRH_cNotPt_V4;
1309 case Hexagon::SXTB:
1310 return !invertPredicate ? Hexagon::SXTB_cPt_V4 :
1311 Hexagon::SXTB_cNotPt_V4;
1312 case Hexagon::SXTH:
1313 return !invertPredicate ? Hexagon::SXTH_cPt_V4 :
1314 Hexagon::SXTH_cNotPt_V4;
1315 case Hexagon::ZXTB:
1316 return !invertPredicate ? Hexagon::ZXTB_cPt_V4 :
1317 Hexagon::ZXTB_cNotPt_V4;
1318 case Hexagon::ZXTH:
1319 return !invertPredicate ? Hexagon::ZXTH_cPt_V4 :
1320 Hexagon::ZXTH_cNotPt_V4;
1321
1322 case Hexagon::JMPR:
Jyotsna Verma5ed51812013-05-01 21:37:34 +00001323 return !invertPredicate ? Hexagon::JMPR_t :
1324 Hexagon::JMPR_f;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001325
1326 // V4 indexed+scaled load.
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001327 case Hexagon::LDrid_indexed_shl_V4:
1328 return !invertPredicate ? Hexagon::LDrid_indexed_shl_cPt_V4 :
1329 Hexagon::LDrid_indexed_shl_cNotPt_V4;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001330 case Hexagon::LDrib_indexed_shl_V4:
1331 return !invertPredicate ? Hexagon::LDrib_indexed_shl_cPt_V4 :
1332 Hexagon::LDrib_indexed_shl_cNotPt_V4;
1333 case Hexagon::LDriub_indexed_shl_V4:
1334 return !invertPredicate ? Hexagon::LDriub_indexed_shl_cPt_V4 :
1335 Hexagon::LDriub_indexed_shl_cNotPt_V4;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001336 case Hexagon::LDrih_indexed_shl_V4:
1337 return !invertPredicate ? Hexagon::LDrih_indexed_shl_cPt_V4 :
1338 Hexagon::LDrih_indexed_shl_cNotPt_V4;
1339 case Hexagon::LDriuh_indexed_shl_V4:
1340 return !invertPredicate ? Hexagon::LDriuh_indexed_shl_cPt_V4 :
1341 Hexagon::LDriuh_indexed_shl_cNotPt_V4;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001342 case Hexagon::LDriw_indexed_shl_V4:
1343 return !invertPredicate ? Hexagon::LDriw_indexed_shl_cPt_V4 :
1344 Hexagon::LDriw_indexed_shl_cNotPt_V4;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001345
1346 // V4 Load from global address
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001347 case Hexagon::LDd_GP_V4:
1348 return !invertPredicate ? Hexagon::LDd_GP_cPt_V4 :
1349 Hexagon::LDd_GP_cNotPt_V4;
1350 case Hexagon::LDb_GP_V4:
1351 return !invertPredicate ? Hexagon::LDb_GP_cPt_V4 :
1352 Hexagon::LDb_GP_cNotPt_V4;
1353 case Hexagon::LDub_GP_V4:
1354 return !invertPredicate ? Hexagon::LDub_GP_cPt_V4 :
1355 Hexagon::LDub_GP_cNotPt_V4;
1356 case Hexagon::LDh_GP_V4:
1357 return !invertPredicate ? Hexagon::LDh_GP_cPt_V4 :
1358 Hexagon::LDh_GP_cNotPt_V4;
1359 case Hexagon::LDuh_GP_V4:
1360 return !invertPredicate ? Hexagon::LDuh_GP_cPt_V4 :
1361 Hexagon::LDuh_GP_cNotPt_V4;
1362 case Hexagon::LDw_GP_V4:
1363 return !invertPredicate ? Hexagon::LDw_GP_cPt_V4 :
1364 Hexagon::LDw_GP_cNotPt_V4;
1365
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001366 // Byte.
1367 case Hexagon::POST_STbri:
1368 return !invertPredicate ? Hexagon::POST_STbri_cPt :
1369 Hexagon::POST_STbri_cNotPt;
1370 case Hexagon::STrib:
1371 return !invertPredicate ? Hexagon::STrib_cPt :
1372 Hexagon::STrib_cNotPt;
1373 case Hexagon::STrib_indexed:
1374 return !invertPredicate ? Hexagon::STrib_indexed_cPt :
1375 Hexagon::STrib_indexed_cNotPt;
1376 case Hexagon::STrib_imm_V4:
1377 return !invertPredicate ? Hexagon::STrib_imm_cPt_V4 :
1378 Hexagon::STrib_imm_cNotPt_V4;
1379 case Hexagon::STrib_indexed_shl_V4:
1380 return !invertPredicate ? Hexagon::STrib_indexed_shl_cPt_V4 :
1381 Hexagon::STrib_indexed_shl_cNotPt_V4;
1382 // Halfword.
1383 case Hexagon::POST_SThri:
1384 return !invertPredicate ? Hexagon::POST_SThri_cPt :
1385 Hexagon::POST_SThri_cNotPt;
1386 case Hexagon::STrih:
1387 return !invertPredicate ? Hexagon::STrih_cPt :
1388 Hexagon::STrih_cNotPt;
1389 case Hexagon::STrih_indexed:
1390 return !invertPredicate ? Hexagon::STrih_indexed_cPt :
1391 Hexagon::STrih_indexed_cNotPt;
1392 case Hexagon::STrih_imm_V4:
1393 return !invertPredicate ? Hexagon::STrih_imm_cPt_V4 :
1394 Hexagon::STrih_imm_cNotPt_V4;
1395 case Hexagon::STrih_indexed_shl_V4:
1396 return !invertPredicate ? Hexagon::STrih_indexed_shl_cPt_V4 :
1397 Hexagon::STrih_indexed_shl_cNotPt_V4;
1398 // Word.
1399 case Hexagon::POST_STwri:
1400 return !invertPredicate ? Hexagon::POST_STwri_cPt :
1401 Hexagon::POST_STwri_cNotPt;
1402 case Hexagon::STriw:
1403 return !invertPredicate ? Hexagon::STriw_cPt :
1404 Hexagon::STriw_cNotPt;
1405 case Hexagon::STriw_indexed:
1406 return !invertPredicate ? Hexagon::STriw_indexed_cPt :
1407 Hexagon::STriw_indexed_cNotPt;
1408 case Hexagon::STriw_indexed_shl_V4:
1409 return !invertPredicate ? Hexagon::STriw_indexed_shl_cPt_V4 :
1410 Hexagon::STriw_indexed_shl_cNotPt_V4;
1411 case Hexagon::STriw_imm_V4:
1412 return !invertPredicate ? Hexagon::STriw_imm_cPt_V4 :
1413 Hexagon::STriw_imm_cNotPt_V4;
1414 // Double word.
1415 case Hexagon::POST_STdri:
1416 return !invertPredicate ? Hexagon::POST_STdri_cPt :
1417 Hexagon::POST_STdri_cNotPt;
1418 case Hexagon::STrid:
1419 return !invertPredicate ? Hexagon::STrid_cPt :
1420 Hexagon::STrid_cNotPt;
1421 case Hexagon::STrid_indexed:
1422 return !invertPredicate ? Hexagon::STrid_indexed_cPt :
1423 Hexagon::STrid_indexed_cNotPt;
1424 case Hexagon::STrid_indexed_shl_V4:
1425 return !invertPredicate ? Hexagon::STrid_indexed_shl_cPt_V4 :
1426 Hexagon::STrid_indexed_shl_cNotPt_V4;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001427
1428 // V4 Store to global address
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001429 case Hexagon::STd_GP_V4:
1430 return !invertPredicate ? Hexagon::STd_GP_cPt_V4 :
1431 Hexagon::STd_GP_cNotPt_V4;
1432 case Hexagon::STb_GP_V4:
1433 return !invertPredicate ? Hexagon::STb_GP_cPt_V4 :
1434 Hexagon::STb_GP_cNotPt_V4;
1435 case Hexagon::STh_GP_V4:
1436 return !invertPredicate ? Hexagon::STh_GP_cPt_V4 :
1437 Hexagon::STh_GP_cNotPt_V4;
1438 case Hexagon::STw_GP_V4:
1439 return !invertPredicate ? Hexagon::STw_GP_cPt_V4 :
1440 Hexagon::STw_GP_cNotPt_V4;
1441
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001442 // Load.
1443 case Hexagon::LDrid:
1444 return !invertPredicate ? Hexagon::LDrid_cPt :
1445 Hexagon::LDrid_cNotPt;
1446 case Hexagon::LDriw:
1447 return !invertPredicate ? Hexagon::LDriw_cPt :
1448 Hexagon::LDriw_cNotPt;
1449 case Hexagon::LDrih:
1450 return !invertPredicate ? Hexagon::LDrih_cPt :
1451 Hexagon::LDrih_cNotPt;
1452 case Hexagon::LDriuh:
1453 return !invertPredicate ? Hexagon::LDriuh_cPt :
1454 Hexagon::LDriuh_cNotPt;
1455 case Hexagon::LDrib:
1456 return !invertPredicate ? Hexagon::LDrib_cPt :
1457 Hexagon::LDrib_cNotPt;
1458 case Hexagon::LDriub:
1459 return !invertPredicate ? Hexagon::LDriub_cPt :
1460 Hexagon::LDriub_cNotPt;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001461 // Load Indexed.
1462 case Hexagon::LDrid_indexed:
1463 return !invertPredicate ? Hexagon::LDrid_indexed_cPt :
1464 Hexagon::LDrid_indexed_cNotPt;
1465 case Hexagon::LDriw_indexed:
1466 return !invertPredicate ? Hexagon::LDriw_indexed_cPt :
1467 Hexagon::LDriw_indexed_cNotPt;
1468 case Hexagon::LDrih_indexed:
1469 return !invertPredicate ? Hexagon::LDrih_indexed_cPt :
1470 Hexagon::LDrih_indexed_cNotPt;
1471 case Hexagon::LDriuh_indexed:
1472 return !invertPredicate ? Hexagon::LDriuh_indexed_cPt :
1473 Hexagon::LDriuh_indexed_cNotPt;
1474 case Hexagon::LDrib_indexed:
1475 return !invertPredicate ? Hexagon::LDrib_indexed_cPt :
1476 Hexagon::LDrib_indexed_cNotPt;
1477 case Hexagon::LDriub_indexed:
1478 return !invertPredicate ? Hexagon::LDriub_indexed_cPt :
1479 Hexagon::LDriub_indexed_cNotPt;
1480 // Post Increment Load.
1481 case Hexagon::POST_LDrid:
1482 return !invertPredicate ? Hexagon::POST_LDrid_cPt :
1483 Hexagon::POST_LDrid_cNotPt;
1484 case Hexagon::POST_LDriw:
1485 return !invertPredicate ? Hexagon::POST_LDriw_cPt :
1486 Hexagon::POST_LDriw_cNotPt;
1487 case Hexagon::POST_LDrih:
1488 return !invertPredicate ? Hexagon::POST_LDrih_cPt :
1489 Hexagon::POST_LDrih_cNotPt;
1490 case Hexagon::POST_LDriuh:
1491 return !invertPredicate ? Hexagon::POST_LDriuh_cPt :
1492 Hexagon::POST_LDriuh_cNotPt;
1493 case Hexagon::POST_LDrib:
1494 return !invertPredicate ? Hexagon::POST_LDrib_cPt :
1495 Hexagon::POST_LDrib_cNotPt;
1496 case Hexagon::POST_LDriub:
1497 return !invertPredicate ? Hexagon::POST_LDriub_cPt :
1498 Hexagon::POST_LDriub_cNotPt;
1499 // DEALLOC_RETURN.
1500 case Hexagon::DEALLOC_RET_V4:
1501 return !invertPredicate ? Hexagon::DEALLOC_RET_cPt_V4 :
1502 Hexagon::DEALLOC_RET_cNotPt_V4;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001503 }
Benjamin Kramerb6684012011-12-27 11:41:05 +00001504 llvm_unreachable("Unexpected predicable instruction");
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001505}
1506
1507
1508bool HexagonInstrInfo::
1509PredicateInstruction(MachineInstr *MI,
1510 const SmallVectorImpl<MachineOperand> &Cond) const {
1511 int Opc = MI->getOpcode();
1512 assert (isPredicable(MI) && "Expected predicable instruction");
1513 bool invertJump = (!Cond.empty() && Cond[0].isImm() &&
1514 (Cond[0].getImm() == 0));
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001515
Jyotsna Verma39f7a2b2013-02-12 16:06:23 +00001516 // This will change MI's opcode to its predicate version.
1517 // However, its operand list is still the old one, i.e. the
1518 // non-predicate one.
1519 MI->setDesc(get(getMatchingCondBranchOpcode(Opc, invertJump)));
1520
1521 int oper = -1;
1522 unsigned int GAIdx = 0;
1523
1524 // Indicates whether the current MI has a GlobalAddress operand
1525 bool hasGAOpnd = false;
1526 std::vector<MachineOperand> tmpOpnds;
1527
1528 // Indicates whether we need to shift operands to right.
1529 bool needShift = true;
1530
1531 // The predicate is ALWAYS the FIRST input operand !!!
1532 if (MI->getNumOperands() == 0) {
1533 // The non-predicate version of MI does not take any operands,
1534 // i.e. no outs and no ins. In this condition, the predicate
1535 // operand will be directly placed at Operands[0]. No operand
1536 // shift is needed.
1537 // Example: BARRIER
1538 needShift = false;
1539 oper = -1;
1540 }
1541 else if ( MI->getOperand(MI->getNumOperands()-1).isReg()
1542 && MI->getOperand(MI->getNumOperands()-1).isDef()
1543 && !MI->getOperand(MI->getNumOperands()-1).isImplicit()) {
1544 // The non-predicate version of MI does not have any input operands.
1545 // In this condition, we extend the length of Operands[] by one and
1546 // copy the original last operand to the newly allocated slot.
1547 // At this moment, it is just a place holder. Later, we will put
1548 // predicate operand directly into it. No operand shift is needed.
1549 // Example: r0=BARRIER (this is a faked insn used here for illustration)
1550 MI->addOperand(MI->getOperand(MI->getNumOperands()-1));
1551 needShift = false;
1552 oper = MI->getNumOperands() - 2;
1553 }
1554 else {
1555 // We need to right shift all input operands by one. Duplicate the
1556 // last operand into the newly allocated slot.
1557 MI->addOperand(MI->getOperand(MI->getNumOperands()-1));
1558 }
1559
1560 if (needShift)
1561 {
1562 // Operands[ MI->getNumOperands() - 2 ] has been copied into
1563 // Operands[ MI->getNumOperands() - 1 ], so we start from
1564 // Operands[ MI->getNumOperands() - 3 ].
1565 // oper is a signed int.
1566 // It is ok if "MI->getNumOperands()-3" is -3, -2, or -1.
1567 for (oper = MI->getNumOperands() - 3; oper >= 0; --oper)
1568 {
1569 MachineOperand &MO = MI->getOperand(oper);
1570
1571 // Opnd[0] Opnd[1] Opnd[2] Opnd[3] Opnd[4] Opnd[5] Opnd[6] Opnd[7]
1572 // <Def0> <Def1> <Use0> <Use1> <ImpDef0> <ImpDef1> <ImpUse0> <ImpUse1>
1573 // /\~
1574 // /||\~
1575 // ||
1576 // Predicate Operand here
1577 if (MO.isReg() && !MO.isUse() && !MO.isImplicit()) {
1578 break;
1579 }
1580 if (MO.isReg()) {
1581 MI->getOperand(oper+1).ChangeToRegister(MO.getReg(), MO.isDef(),
1582 MO.isImplicit(), MO.isKill(),
1583 MO.isDead(), MO.isUndef(),
1584 MO.isDebug());
1585 }
1586 else if (MO.isImm()) {
1587 MI->getOperand(oper+1).ChangeToImmediate(MO.getImm());
1588 }
1589 else if (MO.isGlobal()) {
1590 // MI can not have more than one GlobalAddress operand.
1591 assert(hasGAOpnd == false && "MI can only have one GlobalAddress opnd");
1592
1593 // There is no member function called "ChangeToGlobalAddress" in the
1594 // MachineOperand class (not like "ChangeToRegister" and
1595 // "ChangeToImmediate"). So we have to remove them from Operands[] list
1596 // first, and then add them back after we have inserted the predicate
1597 // operand. tmpOpnds[] is to remember these operands before we remove
1598 // them.
1599 tmpOpnds.push_back(MO);
1600
1601 // Operands[oper] is a GlobalAddress operand;
1602 // Operands[oper+1] has been copied into Operands[oper+2];
1603 hasGAOpnd = true;
1604 GAIdx = oper;
1605 continue;
1606 }
1607 else {
1608 assert(false && "Unexpected operand type");
1609 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001610 }
1611 }
1612
1613 int regPos = invertJump ? 1 : 0;
1614 MachineOperand PredMO = Cond[regPos];
Jyotsna Verma39f7a2b2013-02-12 16:06:23 +00001615
1616 // [oper] now points to the last explicit Def. Predicate operand must be
1617 // located at [oper+1]. See diagram above.
1618 // This assumes that the predicate is always the first operand,
1619 // i.e. Operands[0+numResults], in the set of inputs
1620 // It is better to have an assert here to check this. But I don't know how
1621 // to write this assert because findFirstPredOperandIdx() would return -1
1622 if (oper < -1) oper = -1;
Jyotsna Vermacd66c0a2013-05-01 21:27:30 +00001623
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001624 MI->getOperand(oper+1).ChangeToRegister(PredMO.getReg(), PredMO.isDef(),
Jyotsna Vermacd66c0a2013-05-01 21:27:30 +00001625 PredMO.isImplicit(), false,
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001626 PredMO.isDead(), PredMO.isUndef(),
1627 PredMO.isDebug());
1628
Jyotsna Vermacd66c0a2013-05-01 21:27:30 +00001629 MachineRegisterInfo &RegInfo = MI->getParent()->getParent()->getRegInfo();
1630 RegInfo.clearKillFlags(PredMO.getReg());
1631
Jyotsna Verma39f7a2b2013-02-12 16:06:23 +00001632 if (hasGAOpnd)
1633 {
1634 unsigned int i;
1635
1636 // Operands[GAIdx] is the original GlobalAddress operand, which is
1637 // already copied into tmpOpnds[0].
1638 // Operands[GAIdx] now stores a copy of Operands[GAIdx-1]
1639 // Operands[GAIdx+1] has already been copied into Operands[GAIdx+2],
1640 // so we start from [GAIdx+2]
1641 for (i = GAIdx + 2; i < MI->getNumOperands(); ++i)
1642 tmpOpnds.push_back(MI->getOperand(i));
1643
1644 // Remove all operands in range [ (GAIdx+1) ... (MI->getNumOperands()-1) ]
1645 // It is very important that we always remove from the end of Operands[]
1646 // MI->getNumOperands() is at least 2 if program goes to here.
1647 for (i = MI->getNumOperands() - 1; i > GAIdx; --i)
1648 MI->RemoveOperand(i);
1649
1650 for (i = 0; i < tmpOpnds.size(); ++i)
1651 MI->addOperand(tmpOpnds[i]);
1652 }
1653
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001654 return true;
1655}
1656
1657
1658bool
1659HexagonInstrInfo::
1660isProfitableToIfCvt(MachineBasicBlock &MBB,
Kay Tiong Khoof2949212012-06-13 15:53:04 +00001661 unsigned NumCycles,
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001662 unsigned ExtraPredCycles,
1663 const BranchProbability &Probability) const {
1664 return true;
1665}
1666
1667
1668bool
1669HexagonInstrInfo::
1670isProfitableToIfCvt(MachineBasicBlock &TMBB,
1671 unsigned NumTCycles,
1672 unsigned ExtraTCycles,
1673 MachineBasicBlock &FMBB,
1674 unsigned NumFCycles,
1675 unsigned ExtraFCycles,
1676 const BranchProbability &Probability) const {
1677 return true;
1678}
1679
Jyotsna Verma7e7c7302013-05-02 21:21:57 +00001680// Returns true if an instruction is predicated irrespective of the predicate
1681// sense. For example, all of the following will return true.
1682// if (p0) R1 = add(R2, R3)
1683// if (!p0) R1 = add(R2, R3)
1684// if (p0.new) R1 = add(R2, R3)
1685// if (!p0.new) R1 = add(R2, R3)
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001686bool HexagonInstrInfo::isPredicated(const MachineInstr *MI) const {
Brendon Cahoon6f358372012-02-08 18:25:47 +00001687 const uint64_t F = MI->getDesc().TSFlags;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001688
Brendon Cahoon6f358372012-02-08 18:25:47 +00001689 return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask);
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001690}
1691
Jyotsna Verma7e7c7302013-05-02 21:21:57 +00001692bool HexagonInstrInfo::isPredicated(unsigned Opcode) const {
1693 const uint64_t F = get(Opcode).TSFlags;
1694
1695 return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask);
1696}
1697
1698bool HexagonInstrInfo::isPredicatedTrue(const MachineInstr *MI) const {
1699 const uint64_t F = MI->getDesc().TSFlags;
1700
1701 assert(isPredicated(MI));
1702 return (!((F >> HexagonII::PredicatedFalsePos) &
1703 HexagonII::PredicatedFalseMask));
1704}
1705
1706bool HexagonInstrInfo::isPredicatedTrue(unsigned Opcode) const {
1707 const uint64_t F = get(Opcode).TSFlags;
1708
1709 // Make sure that the instruction is predicated.
1710 assert((F>> HexagonII::PredicatedPos) & HexagonII::PredicatedMask);
1711 return (!((F >> HexagonII::PredicatedFalsePos) &
1712 HexagonII::PredicatedFalseMask));
1713}
1714
Jyotsna Vermaa46059b2013-03-28 19:44:04 +00001715bool HexagonInstrInfo::isPredicatedNew(const MachineInstr *MI) const {
1716 const uint64_t F = MI->getDesc().TSFlags;
1717
1718 assert(isPredicated(MI));
1719 return ((F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask);
1720}
1721
Jyotsna Verma7e7c7302013-05-02 21:21:57 +00001722bool HexagonInstrInfo::isPredicatedNew(unsigned Opcode) const {
1723 const uint64_t F = get(Opcode).TSFlags;
1724
1725 assert(isPredicated(Opcode));
1726 return ((F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask);
1727}
1728
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001729bool
1730HexagonInstrInfo::DefinesPredicate(MachineInstr *MI,
1731 std::vector<MachineOperand> &Pred) const {
1732 for (unsigned oper = 0; oper < MI->getNumOperands(); ++oper) {
1733 MachineOperand MO = MI->getOperand(oper);
1734 if (MO.isReg() && MO.isDef()) {
1735 const TargetRegisterClass* RC = RI.getMinimalPhysRegClass(MO.getReg());
Craig Topperc7242e02012-04-20 07:30:17 +00001736 if (RC == &Hexagon::PredRegsRegClass) {
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001737 Pred.push_back(MO);
1738 return true;
1739 }
1740 }
1741 }
1742 return false;
1743}
1744
1745
1746bool
1747HexagonInstrInfo::
1748SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
1749 const SmallVectorImpl<MachineOperand> &Pred2) const {
1750 // TODO: Fix this
1751 return false;
1752}
1753
1754
1755//
1756// We indicate that we want to reverse the branch by
1757// inserting a 0 at the beginning of the Cond vector.
1758//
1759bool HexagonInstrInfo::
1760ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
1761 if (!Cond.empty() && Cond[0].isImm() && Cond[0].getImm() == 0) {
1762 Cond.erase(Cond.begin());
1763 } else {
1764 Cond.insert(Cond.begin(), MachineOperand::CreateImm(0));
1765 }
1766 return false;
1767}
1768
1769
1770bool HexagonInstrInfo::
1771isProfitableToDupForIfCvt(MachineBasicBlock &MBB,unsigned NumInstrs,
1772 const BranchProbability &Probability) const {
1773 return (NumInstrs <= 4);
1774}
1775
1776bool HexagonInstrInfo::isDeallocRet(const MachineInstr *MI) const {
1777 switch (MI->getOpcode()) {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001778 default: return false;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001779 case Hexagon::DEALLOC_RET_V4 :
1780 case Hexagon::DEALLOC_RET_cPt_V4 :
1781 case Hexagon::DEALLOC_RET_cNotPt_V4 :
1782 case Hexagon::DEALLOC_RET_cdnPnt_V4 :
1783 case Hexagon::DEALLOC_RET_cNotdnPnt_V4 :
1784 case Hexagon::DEALLOC_RET_cdnPt_V4 :
1785 case Hexagon::DEALLOC_RET_cNotdnPt_V4 :
1786 return true;
1787 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001788}
1789
1790
1791bool HexagonInstrInfo::
1792isValidOffset(const int Opcode, const int Offset) const {
1793 // This function is to check whether the "Offset" is in the correct range of
1794 // the given "Opcode". If "Offset" is not in the correct range, "ADD_ri" is
1795 // inserted to calculate the final address. Due to this reason, the function
1796 // assumes that the "Offset" has correct alignment.
Jyotsna Vermaec613662013-03-14 19:08:03 +00001797 // We used to assert if the offset was not properly aligned, however,
1798 // there are cases where a misaligned pointer recast can cause this
1799 // problem, and we need to allow for it. The front end warns of such
1800 // misaligns with respect to load size.
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001801
1802 switch(Opcode) {
1803
1804 case Hexagon::LDriw:
Jyotsna Verma9b60c1d2013-01-17 18:42:37 +00001805 case Hexagon::LDriw_indexed:
Sirish Pande69295b82012-05-10 20:20:25 +00001806 case Hexagon::LDriw_f:
Jyotsna Verma9b60c1d2013-01-17 18:42:37 +00001807 case Hexagon::STriw_indexed:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001808 case Hexagon::STriw:
Sirish Pande69295b82012-05-10 20:20:25 +00001809 case Hexagon::STriw_f:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001810 return (Offset >= Hexagon_MEMW_OFFSET_MIN) &&
1811 (Offset <= Hexagon_MEMW_OFFSET_MAX);
1812
1813 case Hexagon::LDrid:
Jyotsna Verma9b60c1d2013-01-17 18:42:37 +00001814 case Hexagon::LDrid_indexed:
Sirish Pande69295b82012-05-10 20:20:25 +00001815 case Hexagon::LDrid_f:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001816 case Hexagon::STrid:
Jyotsna Verma9b60c1d2013-01-17 18:42:37 +00001817 case Hexagon::STrid_indexed:
Sirish Pande69295b82012-05-10 20:20:25 +00001818 case Hexagon::STrid_f:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001819 return (Offset >= Hexagon_MEMD_OFFSET_MIN) &&
1820 (Offset <= Hexagon_MEMD_OFFSET_MAX);
1821
1822 case Hexagon::LDrih:
1823 case Hexagon::LDriuh:
1824 case Hexagon::STrih:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001825 return (Offset >= Hexagon_MEMH_OFFSET_MIN) &&
1826 (Offset <= Hexagon_MEMH_OFFSET_MAX);
1827
1828 case Hexagon::LDrib:
1829 case Hexagon::STrib:
1830 case Hexagon::LDriub:
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001831 return (Offset >= Hexagon_MEMB_OFFSET_MIN) &&
1832 (Offset <= Hexagon_MEMB_OFFSET_MAX);
1833
1834 case Hexagon::ADD_ri:
1835 case Hexagon::TFR_FI:
1836 return (Offset >= Hexagon_ADDI_OFFSET_MIN) &&
1837 (Offset <= Hexagon_ADDI_OFFSET_MAX);
1838
Jyotsna Vermafdc660b2013-03-22 18:41:34 +00001839 case Hexagon::MemOPw_ADDi_V4 :
1840 case Hexagon::MemOPw_SUBi_V4 :
1841 case Hexagon::MemOPw_ADDr_V4 :
1842 case Hexagon::MemOPw_SUBr_V4 :
1843 case Hexagon::MemOPw_ANDr_V4 :
1844 case Hexagon::MemOPw_ORr_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001845 return (0 <= Offset && Offset <= 255);
1846
Jyotsna Vermafdc660b2013-03-22 18:41:34 +00001847 case Hexagon::MemOPh_ADDi_V4 :
1848 case Hexagon::MemOPh_SUBi_V4 :
1849 case Hexagon::MemOPh_ADDr_V4 :
1850 case Hexagon::MemOPh_SUBr_V4 :
1851 case Hexagon::MemOPh_ANDr_V4 :
1852 case Hexagon::MemOPh_ORr_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001853 return (0 <= Offset && Offset <= 127);
1854
Jyotsna Vermafdc660b2013-03-22 18:41:34 +00001855 case Hexagon::MemOPb_ADDi_V4 :
1856 case Hexagon::MemOPb_SUBi_V4 :
1857 case Hexagon::MemOPb_ADDr_V4 :
1858 case Hexagon::MemOPb_SUBr_V4 :
1859 case Hexagon::MemOPb_ANDr_V4 :
1860 case Hexagon::MemOPb_ORr_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001861 return (0 <= Offset && Offset <= 63);
1862
1863 // LDri_pred and STriw_pred are pseudo operations, so it has to take offset of
1864 // any size. Later pass knows how to handle it.
1865 case Hexagon::STriw_pred:
1866 case Hexagon::LDriw_pred:
1867 return true;
1868
Krzysztof Parzyszek9a278f12013-02-11 21:37:55 +00001869 case Hexagon::LOOP0_i:
1870 return isUInt<10>(Offset);
1871
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001872 // INLINEASM is very special.
1873 case Hexagon::INLINEASM:
1874 return true;
1875 }
1876
Benjamin Kramerb6684012011-12-27 11:41:05 +00001877 llvm_unreachable("No offset range is defined for this opcode. "
1878 "Please define it in the above switch statement!");
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001879}
1880
1881
1882//
1883// Check if the Offset is a valid auto-inc imm by Load/Store Type.
1884//
1885bool HexagonInstrInfo::
1886isValidAutoIncImm(const EVT VT, const int Offset) const {
1887
1888 if (VT == MVT::i64) {
1889 return (Offset >= Hexagon_MEMD_AUTOINC_MIN &&
1890 Offset <= Hexagon_MEMD_AUTOINC_MAX &&
1891 (Offset & 0x7) == 0);
1892 }
1893 if (VT == MVT::i32) {
1894 return (Offset >= Hexagon_MEMW_AUTOINC_MIN &&
1895 Offset <= Hexagon_MEMW_AUTOINC_MAX &&
1896 (Offset & 0x3) == 0);
1897 }
1898 if (VT == MVT::i16) {
1899 return (Offset >= Hexagon_MEMH_AUTOINC_MIN &&
1900 Offset <= Hexagon_MEMH_AUTOINC_MAX &&
1901 (Offset & 0x1) == 0);
1902 }
1903 if (VT == MVT::i8) {
1904 return (Offset >= Hexagon_MEMB_AUTOINC_MIN &&
1905 Offset <= Hexagon_MEMB_AUTOINC_MAX);
1906 }
Craig Toppere55c5562012-02-07 02:50:20 +00001907 llvm_unreachable("Not an auto-inc opc!");
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001908}
1909
1910
1911bool HexagonInstrInfo::
1912isMemOp(const MachineInstr *MI) const {
1913 switch (MI->getOpcode())
1914 {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001915 default: return false;
Jyotsna Vermafdc660b2013-03-22 18:41:34 +00001916 case Hexagon::MemOPw_ADDi_V4 :
1917 case Hexagon::MemOPw_SUBi_V4 :
1918 case Hexagon::MemOPw_ADDr_V4 :
1919 case Hexagon::MemOPw_SUBr_V4 :
1920 case Hexagon::MemOPw_ANDr_V4 :
1921 case Hexagon::MemOPw_ORr_V4 :
1922 case Hexagon::MemOPh_ADDi_V4 :
1923 case Hexagon::MemOPh_SUBi_V4 :
1924 case Hexagon::MemOPh_ADDr_V4 :
1925 case Hexagon::MemOPh_SUBr_V4 :
1926 case Hexagon::MemOPh_ANDr_V4 :
1927 case Hexagon::MemOPh_ORr_V4 :
1928 case Hexagon::MemOPb_ADDi_V4 :
1929 case Hexagon::MemOPb_SUBi_V4 :
1930 case Hexagon::MemOPb_ADDr_V4 :
1931 case Hexagon::MemOPb_SUBr_V4 :
1932 case Hexagon::MemOPb_ANDr_V4 :
1933 case Hexagon::MemOPb_ORr_V4 :
1934 case Hexagon::MemOPb_SETBITi_V4:
1935 case Hexagon::MemOPh_SETBITi_V4:
1936 case Hexagon::MemOPw_SETBITi_V4:
1937 case Hexagon::MemOPb_CLRBITi_V4:
1938 case Hexagon::MemOPh_CLRBITi_V4:
1939 case Hexagon::MemOPw_CLRBITi_V4:
1940 return true;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001941 }
Jyotsna Vermafdc660b2013-03-22 18:41:34 +00001942 return false;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001943}
1944
1945
1946bool HexagonInstrInfo::
1947isSpillPredRegOp(const MachineInstr *MI) const {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001948 switch (MI->getOpcode()) {
1949 default: return false;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001950 case Hexagon::STriw_pred :
1951 case Hexagon::LDriw_pred :
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001952 return true;
Sirish Pande2c7bf002012-04-23 17:49:28 +00001953 }
Sirish Pande4bd20c52012-05-12 05:10:30 +00001954}
1955
1956bool HexagonInstrInfo::isNewValueJumpCandidate(const MachineInstr *MI) const {
1957 switch (MI->getOpcode()) {
Sirish Pande8bb97452012-05-12 05:54:15 +00001958 default: return false;
Sirish Pande4bd20c52012-05-12 05:10:30 +00001959 case Hexagon::CMPEQrr:
1960 case Hexagon::CMPEQri:
Sirish Pande4bd20c52012-05-12 05:10:30 +00001961 case Hexagon::CMPGTrr:
1962 case Hexagon::CMPGTri:
Sirish Pande4bd20c52012-05-12 05:10:30 +00001963 case Hexagon::CMPGTUrr:
1964 case Hexagon::CMPGTUri:
Sirish Pande4bd20c52012-05-12 05:10:30 +00001965 return true;
Sirish Pande4bd20c52012-05-12 05:10:30 +00001966 }
Sirish Pande2c7bf002012-04-23 17:49:28 +00001967}
1968
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001969bool HexagonInstrInfo::
1970isConditionalTransfer (const MachineInstr *MI) const {
1971 switch (MI->getOpcode()) {
1972 default: return false;
1973 case Hexagon::TFR_cPt:
1974 case Hexagon::TFR_cNotPt:
1975 case Hexagon::TFRI_cPt:
1976 case Hexagon::TFRI_cNotPt:
1977 case Hexagon::TFR_cdnPt:
1978 case Hexagon::TFR_cdnNotPt:
1979 case Hexagon::TFRI_cdnPt:
1980 case Hexagon::TFRI_cdnNotPt:
1981 return true;
1982 }
1983}
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001984
1985bool HexagonInstrInfo::isConditionalALU32 (const MachineInstr* MI) const {
1986 const HexagonRegisterInfo& QRI = getRegisterInfo();
1987 switch (MI->getOpcode())
1988 {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00001989 default: return false;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00001990 case Hexagon::ADD_ri_cPt:
1991 case Hexagon::ADD_ri_cNotPt:
1992 case Hexagon::ADD_rr_cPt:
1993 case Hexagon::ADD_rr_cNotPt:
1994 case Hexagon::XOR_rr_cPt:
1995 case Hexagon::XOR_rr_cNotPt:
1996 case Hexagon::AND_rr_cPt:
1997 case Hexagon::AND_rr_cNotPt:
1998 case Hexagon::OR_rr_cPt:
1999 case Hexagon::OR_rr_cNotPt:
2000 case Hexagon::SUB_rr_cPt:
2001 case Hexagon::SUB_rr_cNotPt:
2002 case Hexagon::COMBINE_rr_cPt:
2003 case Hexagon::COMBINE_rr_cNotPt:
2004 return true;
2005 case Hexagon::ASLH_cPt_V4:
2006 case Hexagon::ASLH_cNotPt_V4:
2007 case Hexagon::ASRH_cPt_V4:
2008 case Hexagon::ASRH_cNotPt_V4:
2009 case Hexagon::SXTB_cPt_V4:
2010 case Hexagon::SXTB_cNotPt_V4:
2011 case Hexagon::SXTH_cPt_V4:
2012 case Hexagon::SXTH_cNotPt_V4:
2013 case Hexagon::ZXTB_cPt_V4:
2014 case Hexagon::ZXTB_cNotPt_V4:
2015 case Hexagon::ZXTH_cPt_V4:
2016 case Hexagon::ZXTH_cNotPt_V4:
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002017 return QRI.Subtarget.hasV4TOps();
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002018 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002019}
2020
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002021bool HexagonInstrInfo::
2022isConditionalLoad (const MachineInstr* MI) const {
2023 const HexagonRegisterInfo& QRI = getRegisterInfo();
2024 switch (MI->getOpcode())
2025 {
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002026 default: return false;
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002027 case Hexagon::LDrid_cPt :
2028 case Hexagon::LDrid_cNotPt :
2029 case Hexagon::LDrid_indexed_cPt :
2030 case Hexagon::LDrid_indexed_cNotPt :
2031 case Hexagon::LDriw_cPt :
2032 case Hexagon::LDriw_cNotPt :
2033 case Hexagon::LDriw_indexed_cPt :
2034 case Hexagon::LDriw_indexed_cNotPt :
2035 case Hexagon::LDrih_cPt :
2036 case Hexagon::LDrih_cNotPt :
2037 case Hexagon::LDrih_indexed_cPt :
2038 case Hexagon::LDrih_indexed_cNotPt :
2039 case Hexagon::LDrib_cPt :
2040 case Hexagon::LDrib_cNotPt :
2041 case Hexagon::LDrib_indexed_cPt :
2042 case Hexagon::LDrib_indexed_cNotPt :
2043 case Hexagon::LDriuh_cPt :
2044 case Hexagon::LDriuh_cNotPt :
2045 case Hexagon::LDriuh_indexed_cPt :
2046 case Hexagon::LDriuh_indexed_cNotPt :
2047 case Hexagon::LDriub_cPt :
2048 case Hexagon::LDriub_cNotPt :
2049 case Hexagon::LDriub_indexed_cPt :
2050 case Hexagon::LDriub_indexed_cNotPt :
2051 return true;
2052 case Hexagon::POST_LDrid_cPt :
2053 case Hexagon::POST_LDrid_cNotPt :
2054 case Hexagon::POST_LDriw_cPt :
2055 case Hexagon::POST_LDriw_cNotPt :
2056 case Hexagon::POST_LDrih_cPt :
2057 case Hexagon::POST_LDrih_cNotPt :
2058 case Hexagon::POST_LDrib_cPt :
2059 case Hexagon::POST_LDrib_cNotPt :
2060 case Hexagon::POST_LDriuh_cPt :
2061 case Hexagon::POST_LDriuh_cNotPt :
2062 case Hexagon::POST_LDriub_cPt :
2063 case Hexagon::POST_LDriub_cNotPt :
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002064 return QRI.Subtarget.hasV4TOps();
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002065 case Hexagon::LDrid_indexed_shl_cPt_V4 :
2066 case Hexagon::LDrid_indexed_shl_cNotPt_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002067 case Hexagon::LDrib_indexed_shl_cPt_V4 :
2068 case Hexagon::LDrib_indexed_shl_cNotPt_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002069 case Hexagon::LDriub_indexed_shl_cPt_V4 :
2070 case Hexagon::LDriub_indexed_shl_cNotPt_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002071 case Hexagon::LDrih_indexed_shl_cPt_V4 :
2072 case Hexagon::LDrih_indexed_shl_cNotPt_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002073 case Hexagon::LDriuh_indexed_shl_cPt_V4 :
2074 case Hexagon::LDriuh_indexed_shl_cNotPt_V4 :
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002075 case Hexagon::LDriw_indexed_shl_cPt_V4 :
2076 case Hexagon::LDriw_indexed_shl_cNotPt_V4 :
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002077 return QRI.Subtarget.hasV4TOps();
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002078 }
Tony Linthicum1213a7a2011-12-12 21:14:40 +00002079}
Andrew Trickd06df962012-02-01 22:13:57 +00002080
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002081// Returns true if an instruction is a conditional store.
2082//
2083// Note: It doesn't include conditional new-value stores as they can't be
2084// converted to .new predicate.
2085//
2086// p.new NV store [ if(p0.new)memw(R0+#0)=R2.new ]
2087// ^ ^
2088// / \ (not OK. it will cause new-value store to be
2089// / X conditional on p0.new while R2 producer is
2090// / \ on p0)
2091// / \.
2092// p.new store p.old NV store
2093// [if(p0.new)memw(R0+#0)=R2] [if(p0)memw(R0+#0)=R2.new]
2094// ^ ^
2095// \ /
2096// \ /
2097// \ /
2098// p.old store
2099// [if (p0)memw(R0+#0)=R2]
2100//
2101// The above diagram shows the steps involoved in the conversion of a predicated
2102// store instruction to its .new predicated new-value form.
2103//
2104// The following set of instructions further explains the scenario where
2105// conditional new-value store becomes invalid when promoted to .new predicate
2106// form.
2107//
2108// { 1) if (p0) r0 = add(r1, r2)
2109// 2) p0 = cmp.eq(r3, #0) }
2110//
2111// 3) if (p0) memb(r1+#0) = r0 --> this instruction can't be grouped with
2112// the first two instructions because in instr 1, r0 is conditional on old value
2113// of p0 but its use in instr 3 is conditional on p0 modified by instr 2 which
2114// is not valid for new-value stores.
2115bool HexagonInstrInfo::
2116isConditionalStore (const MachineInstr* MI) const {
2117 const HexagonRegisterInfo& QRI = getRegisterInfo();
2118 switch (MI->getOpcode())
2119 {
2120 default: return false;
2121 case Hexagon::STrib_imm_cPt_V4 :
2122 case Hexagon::STrib_imm_cNotPt_V4 :
2123 case Hexagon::STrib_indexed_shl_cPt_V4 :
2124 case Hexagon::STrib_indexed_shl_cNotPt_V4 :
2125 case Hexagon::STrib_cPt :
2126 case Hexagon::STrib_cNotPt :
2127 case Hexagon::POST_STbri_cPt :
2128 case Hexagon::POST_STbri_cNotPt :
2129 case Hexagon::STrid_indexed_cPt :
2130 case Hexagon::STrid_indexed_cNotPt :
2131 case Hexagon::STrid_indexed_shl_cPt_V4 :
2132 case Hexagon::POST_STdri_cPt :
2133 case Hexagon::POST_STdri_cNotPt :
2134 case Hexagon::STrih_cPt :
2135 case Hexagon::STrih_cNotPt :
2136 case Hexagon::STrih_indexed_cPt :
2137 case Hexagon::STrih_indexed_cNotPt :
2138 case Hexagon::STrih_imm_cPt_V4 :
2139 case Hexagon::STrih_imm_cNotPt_V4 :
2140 case Hexagon::STrih_indexed_shl_cPt_V4 :
2141 case Hexagon::STrih_indexed_shl_cNotPt_V4 :
2142 case Hexagon::POST_SThri_cPt :
2143 case Hexagon::POST_SThri_cNotPt :
2144 case Hexagon::STriw_cPt :
2145 case Hexagon::STriw_cNotPt :
2146 case Hexagon::STriw_indexed_cPt :
2147 case Hexagon::STriw_indexed_cNotPt :
2148 case Hexagon::STriw_imm_cPt_V4 :
2149 case Hexagon::STriw_imm_cNotPt_V4 :
2150 case Hexagon::STriw_indexed_shl_cPt_V4 :
2151 case Hexagon::STriw_indexed_shl_cNotPt_V4 :
2152 case Hexagon::POST_STwri_cPt :
2153 case Hexagon::POST_STwri_cNotPt :
2154 return QRI.Subtarget.hasV4TOps();
2155
2156 // V4 global address store before promoting to dot new.
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002157 case Hexagon::STd_GP_cPt_V4 :
2158 case Hexagon::STd_GP_cNotPt_V4 :
2159 case Hexagon::STb_GP_cPt_V4 :
2160 case Hexagon::STb_GP_cNotPt_V4 :
2161 case Hexagon::STh_GP_cPt_V4 :
2162 case Hexagon::STh_GP_cNotPt_V4 :
2163 case Hexagon::STw_GP_cPt_V4 :
2164 case Hexagon::STw_GP_cNotPt_V4 :
2165 return QRI.Subtarget.hasV4TOps();
2166
2167 // Predicated new value stores (i.e. if (p0) memw(..)=r0.new) are excluded
2168 // from the "Conditional Store" list. Because a predicated new value store
2169 // would NOT be promoted to a double dot new store. See diagram below:
2170 // This function returns yes for those stores that are predicated but not
2171 // yet promoted to predicate dot new instructions.
2172 //
2173 // +---------------------+
2174 // /-----| if (p0) memw(..)=r0 |---------\~
2175 // || +---------------------+ ||
2176 // promote || /\ /\ || promote
2177 // || /||\ /||\ ||
2178 // \||/ demote || \||/
2179 // \/ || || \/
2180 // +-------------------------+ || +-------------------------+
2181 // | if (p0.new) memw(..)=r0 | || | if (p0) memw(..)=r0.new |
2182 // +-------------------------+ || +-------------------------+
2183 // || || ||
2184 // || demote \||/
2185 // promote || \/ NOT possible
2186 // || || /\~
2187 // \||/ || /||\~
2188 // \/ || ||
2189 // +-----------------------------+
2190 // | if (p0.new) memw(..)=r0.new |
2191 // +-----------------------------+
2192 // Double Dot New Store
2193 //
2194 }
2195}
2196
Jyotsna Verma7e7c7302013-05-02 21:21:57 +00002197
2198bool HexagonInstrInfo::isNewValueJump(const MachineInstr *MI) const {
2199 if (isNewValue(MI) && isBranch(MI))
2200 return true;
2201 return false;
2202}
2203
2204bool HexagonInstrInfo::isNewValue(const MachineInstr* MI) const {
2205 const uint64_t F = MI->getDesc().TSFlags;
2206 return ((F >> HexagonII::NewValuePos) & HexagonII::NewValueMask);
2207}
2208
Jyotsna Vermaa46059b2013-03-28 19:44:04 +00002209// Returns true, if any one of the operands is a dot new
2210// insn, whether it is predicated dot new or register dot new.
2211bool HexagonInstrInfo::isDotNewInst (const MachineInstr* MI) const {
2212 return (isNewValueInst(MI) ||
2213 (isPredicated(MI) && isPredicatedNew(MI)));
2214}
2215
Jyotsna Verma84256432013-03-01 17:37:13 +00002216unsigned HexagonInstrInfo::getAddrMode(const MachineInstr* MI) const {
2217 const uint64_t F = MI->getDesc().TSFlags;
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002218
Jyotsna Verma84256432013-03-01 17:37:13 +00002219 return((F >> HexagonII::AddrModePos) & HexagonII::AddrModeMask);
2220}
2221
2222/// immediateExtend - Changes the instruction in place to one using an immediate
2223/// extender.
2224void HexagonInstrInfo::immediateExtend(MachineInstr *MI) const {
2225 assert((isExtendable(MI)||isConstExtended(MI)) &&
2226 "Instruction must be extendable");
2227 // Find which operand is extendable.
2228 short ExtOpNum = getCExtOpNum(MI);
2229 MachineOperand &MO = MI->getOperand(ExtOpNum);
2230 // This needs to be something we understand.
2231 assert((MO.isMBB() || MO.isImm()) &&
2232 "Branch with unknown extendable field type");
2233 // Mark given operand as extended.
2234 MO.addTargetFlag(HexagonII::HMOTF_ConstExtended);
2235}
Sirish Pandef8e5e3c2012-05-03 21:52:53 +00002236
Andrew Trickd06df962012-02-01 22:13:57 +00002237DFAPacketizer *HexagonInstrInfo::
2238CreateTargetScheduleState(const TargetMachine *TM,
2239 const ScheduleDAG *DAG) const {
2240 const InstrItineraryData *II = TM->getInstrItineraryData();
2241 return TM->getSubtarget<HexagonGenSubtargetInfo>().createDFAPacketizer(II);
2242}
2243
2244bool HexagonInstrInfo::isSchedulingBoundary(const MachineInstr *MI,
2245 const MachineBasicBlock *MBB,
2246 const MachineFunction &MF) const {
2247 // Debug info is never a scheduling boundary. It's necessary to be explicit
2248 // due to the special treatment of IT instructions below, otherwise a
2249 // dbg_value followed by an IT will result in the IT instruction being
2250 // considered a scheduling hazard, which is wrong. It should be the actual
2251 // instruction preceding the dbg_value instruction(s), just like it is
2252 // when debug info is not present.
2253 if (MI->isDebugValue())
2254 return false;
2255
2256 // Terminators and labels can't be scheduled around.
2257 if (MI->getDesc().isTerminator() || MI->isLabel() || MI->isInlineAsm())
2258 return true;
2259
2260 return false;
2261}
Jyotsna Verma84256432013-03-01 17:37:13 +00002262
2263bool HexagonInstrInfo::isConstExtended(MachineInstr *MI) const {
2264
2265 // Constant extenders are allowed only for V4 and above.
2266 if (!Subtarget.hasV4TOps())
2267 return false;
2268
2269 const uint64_t F = MI->getDesc().TSFlags;
2270 unsigned isExtended = (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask;
2271 if (isExtended) // Instruction must be extended.
2272 return true;
2273
2274 unsigned isExtendable = (F >> HexagonII::ExtendablePos)
2275 & HexagonII::ExtendableMask;
2276 if (!isExtendable)
2277 return false;
2278
2279 short ExtOpNum = getCExtOpNum(MI);
2280 const MachineOperand &MO = MI->getOperand(ExtOpNum);
2281 // Use MO operand flags to determine if MO
2282 // has the HMOTF_ConstExtended flag set.
2283 if (MO.getTargetFlags() && HexagonII::HMOTF_ConstExtended)
2284 return true;
2285 // If this is a Machine BB address we are talking about, and it is
2286 // not marked as extended, say so.
2287 if (MO.isMBB())
2288 return false;
2289
2290 // We could be using an instruction with an extendable immediate and shoehorn
2291 // a global address into it. If it is a global address it will be constant
2292 // extended. We do this for COMBINE.
2293 // We currently only handle isGlobal() because it is the only kind of
2294 // object we are going to end up with here for now.
2295 // In the future we probably should add isSymbol(), etc.
2296 if (MO.isGlobal() || MO.isSymbol())
2297 return true;
2298
2299 // If the extendable operand is not 'Immediate' type, the instruction should
2300 // have 'isExtended' flag set.
2301 assert(MO.isImm() && "Extendable operand must be Immediate type");
2302
2303 int MinValue = getMinValue(MI);
2304 int MaxValue = getMaxValue(MI);
2305 int ImmValue = MO.getImm();
2306
2307 return (ImmValue < MinValue || ImmValue > MaxValue);
2308}
2309
Jyotsna Verma1d297502013-05-02 15:39:30 +00002310// Returns the opcode to use when converting MI, which is a conditional jump,
2311// into a conditional instruction which uses the .new value of the predicate.
2312// We also use branch probabilities to add a hint to the jump.
2313int
2314HexagonInstrInfo::getDotNewPredJumpOp(MachineInstr *MI,
2315 const
2316 MachineBranchProbabilityInfo *MBPI) const {
2317
2318 // We assume that block can have at most two successors.
2319 bool taken = false;
2320 MachineBasicBlock *Src = MI->getParent();
2321 MachineOperand *BrTarget = &MI->getOperand(1);
2322 MachineBasicBlock *Dst = BrTarget->getMBB();
2323
2324 const BranchProbability Prediction = MBPI->getEdgeProbability(Src, Dst);
2325 if (Prediction >= BranchProbability(1,2))
2326 taken = true;
2327
2328 switch (MI->getOpcode()) {
2329 case Hexagon::JMP_t:
2330 return taken ? Hexagon::JMP_tnew_t : Hexagon::JMP_tnew_nt;
2331 case Hexagon::JMP_f:
2332 return taken ? Hexagon::JMP_fnew_t : Hexagon::JMP_fnew_nt;
2333
2334 default:
2335 llvm_unreachable("Unexpected jump instruction.");
2336 }
2337}
Jyotsna Verma84256432013-03-01 17:37:13 +00002338// Returns true if a particular operand is extendable for an instruction.
2339bool HexagonInstrInfo::isOperandExtended(const MachineInstr *MI,
2340 unsigned short OperandNum) const {
2341 // Constant extenders are allowed only for V4 and above.
2342 if (!Subtarget.hasV4TOps())
2343 return false;
2344
2345 const uint64_t F = MI->getDesc().TSFlags;
2346
2347 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask)
2348 == OperandNum;
2349}
2350
2351// Returns Operand Index for the constant extended instruction.
2352unsigned short HexagonInstrInfo::getCExtOpNum(const MachineInstr *MI) const {
2353 const uint64_t F = MI->getDesc().TSFlags;
2354 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask);
2355}
2356
2357// Returns the min value that doesn't need to be extended.
2358int HexagonInstrInfo::getMinValue(const MachineInstr *MI) const {
2359 const uint64_t F = MI->getDesc().TSFlags;
2360 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
2361 & HexagonII::ExtentSignedMask;
2362 unsigned bits = (F >> HexagonII::ExtentBitsPos)
2363 & HexagonII::ExtentBitsMask;
2364
2365 if (isSigned) // if value is signed
2366 return -1 << (bits - 1);
2367 else
2368 return 0;
2369}
2370
2371// Returns the max value that doesn't need to be extended.
2372int HexagonInstrInfo::getMaxValue(const MachineInstr *MI) const {
2373 const uint64_t F = MI->getDesc().TSFlags;
2374 unsigned isSigned = (F >> HexagonII::ExtentSignedPos)
2375 & HexagonII::ExtentSignedMask;
2376 unsigned bits = (F >> HexagonII::ExtentBitsPos)
2377 & HexagonII::ExtentBitsMask;
2378
2379 if (isSigned) // if value is signed
2380 return ~(-1 << (bits - 1));
2381 else
2382 return ~(-1 << bits);
2383}
2384
2385// Returns true if an instruction can be converted into a non-extended
2386// equivalent instruction.
2387bool HexagonInstrInfo::NonExtEquivalentExists (const MachineInstr *MI) const {
2388
2389 short NonExtOpcode;
2390 // Check if the instruction has a register form that uses register in place
2391 // of the extended operand, if so return that as the non-extended form.
2392 if (Hexagon::getRegForm(MI->getOpcode()) >= 0)
2393 return true;
2394
2395 if (MI->getDesc().mayLoad() || MI->getDesc().mayStore()) {
2396 // Check addressing mode and retreive non-ext equivalent instruction.
2397
2398 switch (getAddrMode(MI)) {
2399 case HexagonII::Absolute :
2400 // Load/store with absolute addressing mode can be converted into
2401 // base+offset mode.
2402 NonExtOpcode = Hexagon::getBasedWithImmOffset(MI->getOpcode());
2403 break;
2404 case HexagonII::BaseImmOffset :
2405 // Load/store with base+offset addressing mode can be converted into
2406 // base+register offset addressing mode. However left shift operand should
2407 // be set to 0.
2408 NonExtOpcode = Hexagon::getBaseWithRegOffset(MI->getOpcode());
2409 break;
2410 default:
2411 return false;
2412 }
2413 if (NonExtOpcode < 0)
2414 return false;
2415 return true;
2416 }
2417 return false;
2418}
2419
2420// Returns opcode of the non-extended equivalent instruction.
2421short HexagonInstrInfo::getNonExtOpcode (const MachineInstr *MI) const {
2422
2423 // Check if the instruction has a register form that uses register in place
2424 // of the extended operand, if so return that as the non-extended form.
2425 short NonExtOpcode = Hexagon::getRegForm(MI->getOpcode());
2426 if (NonExtOpcode >= 0)
2427 return NonExtOpcode;
2428
2429 if (MI->getDesc().mayLoad() || MI->getDesc().mayStore()) {
2430 // Check addressing mode and retreive non-ext equivalent instruction.
2431 switch (getAddrMode(MI)) {
2432 case HexagonII::Absolute :
2433 return Hexagon::getBasedWithImmOffset(MI->getOpcode());
2434 case HexagonII::BaseImmOffset :
2435 return Hexagon::getBaseWithRegOffset(MI->getOpcode());
2436 default:
2437 return -1;
2438 }
2439 }
2440 return -1;
2441}
Jyotsna Verma5ed51812013-05-01 21:37:34 +00002442
2443bool HexagonInstrInfo::PredOpcodeHasJMP_c(Opcode_t Opcode) const {
2444 return (Opcode == Hexagon::JMP_t) ||
2445 (Opcode == Hexagon::JMP_f) ||
2446 (Opcode == Hexagon::JMP_tnew_t) ||
2447 (Opcode == Hexagon::JMP_fnew_t) ||
2448 (Opcode == Hexagon::JMP_tnew_nt) ||
2449 (Opcode == Hexagon::JMP_fnew_nt);
2450}
2451
2452bool HexagonInstrInfo::PredOpcodeHasNot(Opcode_t Opcode) const {
2453 return (Opcode == Hexagon::JMP_f) ||
2454 (Opcode == Hexagon::JMP_fnew_t) ||
2455 (Opcode == Hexagon::JMP_fnew_nt);
2456}