Add argument TargetRegisterInfo to loadRegFromStackSlot and storeRegToStackSlot.
[oota-llvm.git] / lib / Target / SystemZ / SystemZInstrInfo.cpp
1 //===- SystemZInstrInfo.cpp - SystemZ Instruction Information --------------===//
2 //
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 SystemZ implementation of the TargetInstrInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "SystemZ.h"
15 #include "SystemZInstrBuilder.h"
16 #include "SystemZInstrInfo.h"
17 #include "SystemZMachineFunctionInfo.h"
18 #include "SystemZTargetMachine.h"
19 #include "SystemZGenInstrInfo.inc"
20 #include "llvm/Function.h"
21 #include "llvm/CodeGen/MachineFrameInfo.h"
22 #include "llvm/CodeGen/MachineInstrBuilder.h"
23 #include "llvm/CodeGen/MachineRegisterInfo.h"
24 #include "llvm/CodeGen/PseudoSourceValue.h"
25 #include "llvm/Support/ErrorHandling.h"
26 using namespace llvm;
27
28 SystemZInstrInfo::SystemZInstrInfo(SystemZTargetMachine &tm)
29   : TargetInstrInfoImpl(SystemZInsts, array_lengthof(SystemZInsts)),
30     RI(tm, *this), TM(tm) {
31   // Fill the spill offsets map
32   static const unsigned SpillOffsTab[][2] = {
33     { SystemZ::R2D,  0x10 },
34     { SystemZ::R3D,  0x18 },
35     { SystemZ::R4D,  0x20 },
36     { SystemZ::R5D,  0x28 },
37     { SystemZ::R6D,  0x30 },
38     { SystemZ::R7D,  0x38 },
39     { SystemZ::R8D,  0x40 },
40     { SystemZ::R9D,  0x48 },
41     { SystemZ::R10D, 0x50 },
42     { SystemZ::R11D, 0x58 },
43     { SystemZ::R12D, 0x60 },
44     { SystemZ::R13D, 0x68 },
45     { SystemZ::R14D, 0x70 },
46     { SystemZ::R15D, 0x78 }
47   };
48
49   RegSpillOffsets.grow(SystemZ::NUM_TARGET_REGS);
50
51   for (unsigned i = 0, e = array_lengthof(SpillOffsTab); i != e; ++i)
52     RegSpillOffsets[SpillOffsTab[i][0]] = SpillOffsTab[i][1];
53 }
54
55 /// isGVStub - Return true if the GV requires an extra load to get the
56 /// real address.
57 static inline bool isGVStub(GlobalValue *GV, SystemZTargetMachine &TM) {
58   return TM.getSubtarget<SystemZSubtarget>().GVRequiresExtraLoad(GV, TM, false);
59 }
60
61 void SystemZInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
62                                           MachineBasicBlock::iterator MI,
63                                     unsigned SrcReg, bool isKill, int FrameIdx,
64                                            const TargetRegisterClass *RC,
65                                            const TargetRegisterInfo *TRI) const {
66   DebugLoc DL;
67   if (MI != MBB.end()) DL = MI->getDebugLoc();
68
69   unsigned Opc = 0;
70   if (RC == &SystemZ::GR32RegClass ||
71       RC == &SystemZ::ADDR32RegClass)
72     Opc = SystemZ::MOV32mr;
73   else if (RC == &SystemZ::GR64RegClass ||
74            RC == &SystemZ::ADDR64RegClass) {
75     Opc = SystemZ::MOV64mr;
76   } else if (RC == &SystemZ::FP32RegClass) {
77     Opc = SystemZ::FMOV32mr;
78   } else if (RC == &SystemZ::FP64RegClass) {
79     Opc = SystemZ::FMOV64mr;
80   } else if (RC == &SystemZ::GR64PRegClass) {
81     Opc = SystemZ::MOV64Pmr;
82   } else if (RC == &SystemZ::GR128RegClass) {
83     Opc = SystemZ::MOV128mr;
84   } else
85     llvm_unreachable("Unsupported regclass to store");
86
87   addFrameReference(BuildMI(MBB, MI, DL, get(Opc)), FrameIdx)
88     .addReg(SrcReg, getKillRegState(isKill));
89 }
90
91 void SystemZInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
92                                            MachineBasicBlock::iterator MI,
93                                            unsigned DestReg, int FrameIdx,
94                                             const TargetRegisterClass *RC,
95                                             const TargetRegisterInfo *TRI) const{
96   DebugLoc DL;
97   if (MI != MBB.end()) DL = MI->getDebugLoc();
98
99   unsigned Opc = 0;
100   if (RC == &SystemZ::GR32RegClass ||
101       RC == &SystemZ::ADDR32RegClass)
102     Opc = SystemZ::MOV32rm;
103   else if (RC == &SystemZ::GR64RegClass ||
104            RC == &SystemZ::ADDR64RegClass) {
105     Opc = SystemZ::MOV64rm;
106   } else if (RC == &SystemZ::FP32RegClass) {
107     Opc = SystemZ::FMOV32rm;
108   } else if (RC == &SystemZ::FP64RegClass) {
109     Opc = SystemZ::FMOV64rm;
110   } else if (RC == &SystemZ::GR64PRegClass) {
111     Opc = SystemZ::MOV64Prm;
112   } else if (RC == &SystemZ::GR128RegClass) {
113     Opc = SystemZ::MOV128rm;
114   } else
115     llvm_unreachable("Unsupported regclass to load");
116
117   addFrameReference(BuildMI(MBB, MI, DL, get(Opc), DestReg), FrameIdx);
118 }
119
120 bool SystemZInstrInfo::copyRegToReg(MachineBasicBlock &MBB,
121                                     MachineBasicBlock::iterator I,
122                                     unsigned DestReg, unsigned SrcReg,
123                                     const TargetRegisterClass *DestRC,
124                                     const TargetRegisterClass *SrcRC) const {
125   DebugLoc DL;
126   if (I != MBB.end()) DL = I->getDebugLoc();
127
128   // Determine if DstRC and SrcRC have a common superclass.
129   const TargetRegisterClass *CommonRC = DestRC;
130   if (DestRC == SrcRC)
131     /* Same regclass for source and dest */;
132   else if (CommonRC->hasSuperClass(SrcRC))
133     CommonRC = SrcRC;
134   else if (!CommonRC->hasSubClass(SrcRC))
135     CommonRC = 0;
136
137   if (CommonRC) {
138     if (CommonRC == &SystemZ::GR64RegClass ||
139         CommonRC == &SystemZ::ADDR64RegClass) {
140       BuildMI(MBB, I, DL, get(SystemZ::MOV64rr), DestReg).addReg(SrcReg);
141     } else if (CommonRC == &SystemZ::GR32RegClass ||
142                CommonRC == &SystemZ::ADDR32RegClass) {
143       BuildMI(MBB, I, DL, get(SystemZ::MOV32rr), DestReg).addReg(SrcReg);
144     } else if (CommonRC == &SystemZ::GR64PRegClass) {
145       BuildMI(MBB, I, DL, get(SystemZ::MOV64rrP), DestReg).addReg(SrcReg);
146     } else if (CommonRC == &SystemZ::GR128RegClass) {
147       BuildMI(MBB, I, DL, get(SystemZ::MOV128rr), DestReg).addReg(SrcReg);
148     } else if (CommonRC == &SystemZ::FP32RegClass) {
149       BuildMI(MBB, I, DL, get(SystemZ::FMOV32rr), DestReg).addReg(SrcReg);
150     } else if (CommonRC == &SystemZ::FP64RegClass) {
151       BuildMI(MBB, I, DL, get(SystemZ::FMOV64rr), DestReg).addReg(SrcReg);
152     } else {
153       return false;
154     }
155
156     return true;
157   }
158
159   if ((SrcRC == &SystemZ::GR64RegClass &&
160        DestRC == &SystemZ::ADDR64RegClass) ||
161       (DestRC == &SystemZ::GR64RegClass &&
162        SrcRC == &SystemZ::ADDR64RegClass)) {
163     BuildMI(MBB, I, DL, get(SystemZ::MOV64rr), DestReg).addReg(SrcReg);
164     return true;
165   } else if ((SrcRC == &SystemZ::GR32RegClass &&
166               DestRC == &SystemZ::ADDR32RegClass) ||
167              (DestRC == &SystemZ::GR32RegClass &&
168               SrcRC == &SystemZ::ADDR32RegClass)) {
169     BuildMI(MBB, I, DL, get(SystemZ::MOV32rr), DestReg).addReg(SrcReg);
170     return true;
171   }
172
173   return false;
174 }
175
176 bool
177 SystemZInstrInfo::isMoveInstr(const MachineInstr& MI,
178                               unsigned &SrcReg, unsigned &DstReg,
179                               unsigned &SrcSubIdx, unsigned &DstSubIdx) const {
180   switch (MI.getOpcode()) {
181   default:
182     return false;
183   case SystemZ::MOV32rr:
184   case SystemZ::MOV64rr:
185   case SystemZ::MOV64rrP:
186   case SystemZ::MOV128rr:
187   case SystemZ::FMOV32rr:
188   case SystemZ::FMOV64rr:
189     assert(MI.getNumOperands() >= 2 &&
190            MI.getOperand(0).isReg() &&
191            MI.getOperand(1).isReg() &&
192            "invalid register-register move instruction");
193     SrcReg = MI.getOperand(1).getReg();
194     DstReg = MI.getOperand(0).getReg();
195     SrcSubIdx = MI.getOperand(1).getSubReg();
196     DstSubIdx = MI.getOperand(0).getSubReg();
197     return true;
198   }
199 }
200
201 unsigned SystemZInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
202                                                int &FrameIndex) const {
203   switch (MI->getOpcode()) {
204   default: break;
205   case SystemZ::MOV32rm:
206   case SystemZ::MOV32rmy:
207   case SystemZ::MOV64rm:
208   case SystemZ::MOVSX32rm8:
209   case SystemZ::MOVSX32rm16y:
210   case SystemZ::MOVSX64rm8:
211   case SystemZ::MOVSX64rm16:
212   case SystemZ::MOVSX64rm32:
213   case SystemZ::MOVZX32rm8:
214   case SystemZ::MOVZX32rm16:
215   case SystemZ::MOVZX64rm8:
216   case SystemZ::MOVZX64rm16:
217   case SystemZ::MOVZX64rm32:
218   case SystemZ::FMOV32rm:
219   case SystemZ::FMOV32rmy:
220   case SystemZ::FMOV64rm:
221   case SystemZ::FMOV64rmy:
222   case SystemZ::MOV64Prm:
223   case SystemZ::MOV64Prmy:
224   case SystemZ::MOV128rm:
225     if (MI->getOperand(1).isFI() &&
226         MI->getOperand(2).isImm() && MI->getOperand(3).isReg() &&
227         MI->getOperand(2).getImm() == 0 && MI->getOperand(3).getReg() == 0) {
228       FrameIndex = MI->getOperand(1).getIndex();
229       return MI->getOperand(0).getReg();
230     }
231     break;
232   }
233   return 0;
234 }
235
236 unsigned SystemZInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
237                                               int &FrameIndex) const {
238   switch (MI->getOpcode()) {
239   default: break;
240   case SystemZ::MOV32mr:
241   case SystemZ::MOV32mry:
242   case SystemZ::MOV64mr:
243   case SystemZ::MOV32m8r:
244   case SystemZ::MOV32m8ry:
245   case SystemZ::MOV32m16r:
246   case SystemZ::MOV32m16ry:
247   case SystemZ::MOV64m8r:
248   case SystemZ::MOV64m8ry:
249   case SystemZ::MOV64m16r:
250   case SystemZ::MOV64m16ry:
251   case SystemZ::MOV64m32r:
252   case SystemZ::MOV64m32ry:
253   case SystemZ::FMOV32mr:
254   case SystemZ::FMOV32mry:
255   case SystemZ::FMOV64mr:
256   case SystemZ::FMOV64mry:
257   case SystemZ::MOV64Pmr:
258   case SystemZ::MOV64Pmry:
259   case SystemZ::MOV128mr:
260     if (MI->getOperand(0).isFI() &&
261         MI->getOperand(1).isImm() && MI->getOperand(2).isReg() &&
262         MI->getOperand(1).getImm() == 0 && MI->getOperand(2).getReg() == 0) {
263       FrameIndex = MI->getOperand(0).getIndex();
264       return MI->getOperand(3).getReg();
265     }
266     break;
267   }
268   return 0;
269 }
270
271 bool
272 SystemZInstrInfo::spillCalleeSavedRegisters(MachineBasicBlock &MBB,
273                                            MachineBasicBlock::iterator MI,
274                                 const std::vector<CalleeSavedInfo> &CSI) const {
275   if (CSI.empty())
276     return false;
277
278   DebugLoc DL;
279   if (MI != MBB.end()) DL = MI->getDebugLoc();
280
281   MachineFunction &MF = *MBB.getParent();
282   SystemZMachineFunctionInfo *MFI = MF.getInfo<SystemZMachineFunctionInfo>();
283   unsigned CalleeFrameSize = 0;
284
285   // Scan the callee-saved and find the bounds of register spill area.
286   unsigned LowReg = 0, HighReg = 0, StartOffset = -1U, EndOffset = 0;
287   for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
288     unsigned Reg = CSI[i].getReg();
289     const TargetRegisterClass *RegClass = CSI[i].getRegClass();
290     if (RegClass != &SystemZ::FP64RegClass) {
291       unsigned Offset = RegSpillOffsets[Reg];
292       CalleeFrameSize += 8;
293       if (StartOffset > Offset) {
294         LowReg = Reg; StartOffset = Offset;
295       }
296       if (EndOffset < Offset) {
297         HighReg = Reg; EndOffset = RegSpillOffsets[Reg];
298       }
299     }
300   }
301
302   // Save information for epilogue inserter.
303   MFI->setCalleeSavedFrameSize(CalleeFrameSize);
304   MFI->setLowReg(LowReg); MFI->setHighReg(HighReg);
305
306   // Save GPRs
307   if (StartOffset) {
308     // Build a store instruction. Use STORE MULTIPLE instruction if there are many
309     // registers to store, otherwise - just STORE.
310     MachineInstrBuilder MIB =
311       BuildMI(MBB, MI, DL, get((LowReg == HighReg ?
312                                 SystemZ::MOV64mr : SystemZ::MOV64mrm)));
313
314     // Add store operands.
315     MIB.addReg(SystemZ::R15D).addImm(StartOffset);
316     if (LowReg == HighReg)
317       MIB.addReg(0);
318     MIB.addReg(LowReg, RegState::Kill);
319     if (LowReg != HighReg)
320       MIB.addReg(HighReg, RegState::Kill);
321
322     // Do a second scan adding regs as being killed by instruction
323     for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
324       unsigned Reg = CSI[i].getReg();
325       // Add the callee-saved register as live-in. It's killed at the spill.
326       MBB.addLiveIn(Reg);
327       if (Reg != LowReg && Reg != HighReg)
328         MIB.addReg(Reg, RegState::ImplicitKill);
329     }
330   }
331
332   // Save FPRs
333   for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
334     unsigned Reg = CSI[i].getReg();
335     const TargetRegisterClass *RegClass = CSI[i].getRegClass();
336     if (RegClass == &SystemZ::FP64RegClass) {
337       MBB.addLiveIn(Reg);
338       storeRegToStackSlot(MBB, MI, Reg, true, CSI[i].getFrameIdx(), RegClass,
339                           &RI);
340     }
341   }
342
343   return true;
344 }
345
346 bool
347 SystemZInstrInfo::restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
348                                              MachineBasicBlock::iterator MI,
349                                 const std::vector<CalleeSavedInfo> &CSI) const {
350   if (CSI.empty())
351     return false;
352
353   DebugLoc DL;
354   if (MI != MBB.end()) DL = MI->getDebugLoc();
355
356   MachineFunction &MF = *MBB.getParent();
357   const TargetRegisterInfo *RegInfo= MF.getTarget().getRegisterInfo();
358   SystemZMachineFunctionInfo *MFI = MF.getInfo<SystemZMachineFunctionInfo>();
359
360   // Restore FP registers
361   for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
362     unsigned Reg = CSI[i].getReg();
363     const TargetRegisterClass *RegClass = CSI[i].getRegClass();
364     if (RegClass == &SystemZ::FP64RegClass)
365       loadRegFromStackSlot(MBB, MI, Reg, CSI[i].getFrameIdx(), RegClass, &RI);
366   }
367
368   // Restore GP registers
369   unsigned LowReg = MFI->getLowReg(), HighReg = MFI->getHighReg();
370   unsigned StartOffset = RegSpillOffsets[LowReg];
371
372   if (StartOffset) {
373     // Build a load instruction. Use LOAD MULTIPLE instruction if there are many
374     // registers to load, otherwise - just LOAD.
375     MachineInstrBuilder MIB =
376       BuildMI(MBB, MI, DL, get((LowReg == HighReg ?
377                                 SystemZ::MOV64rm : SystemZ::MOV64rmm)));
378     // Add store operands.
379     MIB.addReg(LowReg, RegState::Define);
380     if (LowReg != HighReg)
381       MIB.addReg(HighReg, RegState::Define);
382
383     MIB.addReg((RegInfo->hasFP(MF) ? SystemZ::R11D : SystemZ::R15D));
384     MIB.addImm(StartOffset);
385     if (LowReg == HighReg)
386       MIB.addReg(0);
387
388     // Do a second scan adding regs as being defined by instruction
389     for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
390       unsigned Reg = CSI[i].getReg();
391       if (Reg != LowReg && Reg != HighReg)
392         MIB.addReg(Reg, RegState::ImplicitDefine);
393     }
394   }
395
396   return true;
397 }
398
399 bool SystemZInstrInfo::
400 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
401   assert(Cond.size() == 1 && "Invalid Xbranch condition!");
402
403   SystemZCC::CondCodes CC = static_cast<SystemZCC::CondCodes>(Cond[0].getImm());
404   Cond[0].setImm(getOppositeCondition(CC));
405   return false;
406 }
407
408 bool SystemZInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
409   const TargetInstrDesc &TID = MI->getDesc();
410   if (!TID.isTerminator()) return false;
411
412   // Conditional branch is a special case.
413   if (TID.isBranch() && !TID.isBarrier())
414     return true;
415   if (!TID.isPredicable())
416     return true;
417   return !isPredicated(MI);
418 }
419
420 bool SystemZInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
421                                      MachineBasicBlock *&TBB,
422                                      MachineBasicBlock *&FBB,
423                                      SmallVectorImpl<MachineOperand> &Cond,
424                                      bool AllowModify) const {
425   // Start from the bottom of the block and work up, examining the
426   // terminator instructions.
427   MachineBasicBlock::iterator I = MBB.end();
428   while (I != MBB.begin()) {
429     --I;
430     if (I->isDebugValue())
431       continue;
432     // Working from the bottom, when we see a non-terminator
433     // instruction, we're done.
434     if (!isUnpredicatedTerminator(I))
435       break;
436
437     // A terminator that isn't a branch can't easily be handled
438     // by this analysis.
439     if (!I->getDesc().isBranch())
440       return true;
441
442     // Handle unconditional branches.
443     if (I->getOpcode() == SystemZ::JMP) {
444       if (!AllowModify) {
445         TBB = I->getOperand(0).getMBB();
446         continue;
447       }
448
449       // If the block has any instructions after a JMP, delete them.
450       while (llvm::next(I) != MBB.end())
451         llvm::next(I)->eraseFromParent();
452       Cond.clear();
453       FBB = 0;
454
455       // Delete the JMP if it's equivalent to a fall-through.
456       if (MBB.isLayoutSuccessor(I->getOperand(0).getMBB())) {
457         TBB = 0;
458         I->eraseFromParent();
459         I = MBB.end();
460         continue;
461       }
462
463       // TBB is used to indicate the unconditinal destination.
464       TBB = I->getOperand(0).getMBB();
465       continue;
466     }
467
468     // Handle conditional branches.
469     SystemZCC::CondCodes BranchCode = getCondFromBranchOpc(I->getOpcode());
470     if (BranchCode == SystemZCC::INVALID)
471       return true;  // Can't handle indirect branch.
472
473     // Working from the bottom, handle the first conditional branch.
474     if (Cond.empty()) {
475       FBB = TBB;
476       TBB = I->getOperand(0).getMBB();
477       Cond.push_back(MachineOperand::CreateImm(BranchCode));
478       continue;
479     }
480
481     // Handle subsequent conditional branches. Only handle the case where all
482     // conditional branches branch to the same destination.
483     assert(Cond.size() == 1);
484     assert(TBB);
485
486     // Only handle the case where all conditional branches branch to
487     // the same destination.
488     if (TBB != I->getOperand(0).getMBB())
489       return true;
490
491     SystemZCC::CondCodes OldBranchCode = (SystemZCC::CondCodes)Cond[0].getImm();
492     // If the conditions are the same, we can leave them alone.
493     if (OldBranchCode == BranchCode)
494       continue;
495
496     return true;
497   }
498
499   return false;
500 }
501
502 unsigned SystemZInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
503   MachineBasicBlock::iterator I = MBB.end();
504   unsigned Count = 0;
505
506   while (I != MBB.begin()) {
507     --I;
508     if (I->isDebugValue())
509       continue;
510     if (I->getOpcode() != SystemZ::JMP &&
511         getCondFromBranchOpc(I->getOpcode()) == SystemZCC::INVALID)
512       break;
513     // Remove the branch.
514     I->eraseFromParent();
515     I = MBB.end();
516     ++Count;
517   }
518
519   return Count;
520 }
521
522 unsigned
523 SystemZInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
524                                MachineBasicBlock *FBB,
525                             const SmallVectorImpl<MachineOperand> &Cond) const {
526   // FIXME: this should probably have a DebugLoc operand
527   DebugLoc DL;
528   // Shouldn't be a fall through.
529   assert(TBB && "InsertBranch must not be told to insert a fallthrough");
530   assert((Cond.size() == 1 || Cond.size() == 0) &&
531          "SystemZ branch conditions have one component!");
532
533   if (Cond.empty()) {
534     // Unconditional branch?
535     assert(!FBB && "Unconditional branch with multiple successors!");
536     BuildMI(&MBB, DL, get(SystemZ::JMP)).addMBB(TBB);
537     return 1;
538   }
539
540   // Conditional branch.
541   unsigned Count = 0;
542   SystemZCC::CondCodes CC = (SystemZCC::CondCodes)Cond[0].getImm();
543   BuildMI(&MBB, DL, getBrCond(CC)).addMBB(TBB);
544   ++Count;
545
546   if (FBB) {
547     // Two-way Conditional branch. Insert the second branch.
548     BuildMI(&MBB, DL, get(SystemZ::JMP)).addMBB(FBB);
549     ++Count;
550   }
551   return Count;
552 }
553
554 const TargetInstrDesc&
555 SystemZInstrInfo::getBrCond(SystemZCC::CondCodes CC) const {
556   switch (CC) {
557   default:
558    llvm_unreachable("Unknown condition code!");
559   case SystemZCC::O:   return get(SystemZ::JO);
560   case SystemZCC::H:   return get(SystemZ::JH);
561   case SystemZCC::NLE: return get(SystemZ::JNLE);
562   case SystemZCC::L:   return get(SystemZ::JL);
563   case SystemZCC::NHE: return get(SystemZ::JNHE);
564   case SystemZCC::LH:  return get(SystemZ::JLH);
565   case SystemZCC::NE:  return get(SystemZ::JNE);
566   case SystemZCC::E:   return get(SystemZ::JE);
567   case SystemZCC::NLH: return get(SystemZ::JNLH);
568   case SystemZCC::HE:  return get(SystemZ::JHE);
569   case SystemZCC::NL:  return get(SystemZ::JNL);
570   case SystemZCC::LE:  return get(SystemZ::JLE);
571   case SystemZCC::NH:  return get(SystemZ::JNH);
572   case SystemZCC::NO:  return get(SystemZ::JNO);
573   }
574 }
575
576 SystemZCC::CondCodes
577 SystemZInstrInfo::getCondFromBranchOpc(unsigned Opc) const {
578   switch (Opc) {
579   default:            return SystemZCC::INVALID;
580   case SystemZ::JO:   return SystemZCC::O;
581   case SystemZ::JH:   return SystemZCC::H;
582   case SystemZ::JNLE: return SystemZCC::NLE;
583   case SystemZ::JL:   return SystemZCC::L;
584   case SystemZ::JNHE: return SystemZCC::NHE;
585   case SystemZ::JLH:  return SystemZCC::LH;
586   case SystemZ::JNE:  return SystemZCC::NE;
587   case SystemZ::JE:   return SystemZCC::E;
588   case SystemZ::JNLH: return SystemZCC::NLH;
589   case SystemZ::JHE:  return SystemZCC::HE;
590   case SystemZ::JNL:  return SystemZCC::NL;
591   case SystemZ::JLE:  return SystemZCC::LE;
592   case SystemZ::JNH:  return SystemZCC::NH;
593   case SystemZ::JNO:  return SystemZCC::NO;
594   }
595 }
596
597 SystemZCC::CondCodes
598 SystemZInstrInfo::getOppositeCondition(SystemZCC::CondCodes CC) const {
599   switch (CC) {
600   default:
601     llvm_unreachable("Invalid condition!");
602   case SystemZCC::O:   return SystemZCC::NO;
603   case SystemZCC::H:   return SystemZCC::NH;
604   case SystemZCC::NLE: return SystemZCC::LE;
605   case SystemZCC::L:   return SystemZCC::NL;
606   case SystemZCC::NHE: return SystemZCC::HE;
607   case SystemZCC::LH:  return SystemZCC::NLH;
608   case SystemZCC::NE:  return SystemZCC::E;
609   case SystemZCC::E:   return SystemZCC::NE;
610   case SystemZCC::NLH: return SystemZCC::LH;
611   case SystemZCC::HE:  return SystemZCC::NHE;
612   case SystemZCC::NL:  return SystemZCC::L;
613   case SystemZCC::LE:  return SystemZCC::NLE;
614   case SystemZCC::NH:  return SystemZCC::H;
615   case SystemZCC::NO:  return SystemZCC::O;
616   }
617 }
618
619 const TargetInstrDesc&
620 SystemZInstrInfo::getLongDispOpc(unsigned Opc) const {
621   switch (Opc) {
622   default:
623     llvm_unreachable("Don't have long disp version of this instruction");
624   case SystemZ::MOV32mr:   return get(SystemZ::MOV32mry);
625   case SystemZ::MOV32rm:   return get(SystemZ::MOV32rmy);
626   case SystemZ::MOVSX32rm16: return get(SystemZ::MOVSX32rm16y);
627   case SystemZ::MOV32m8r:  return get(SystemZ::MOV32m8ry);
628   case SystemZ::MOV32m16r: return get(SystemZ::MOV32m16ry);
629   case SystemZ::MOV64m8r:  return get(SystemZ::MOV64m8ry);
630   case SystemZ::MOV64m16r: return get(SystemZ::MOV64m16ry);
631   case SystemZ::MOV64m32r: return get(SystemZ::MOV64m32ry);
632   case SystemZ::MOV8mi:    return get(SystemZ::MOV8miy);
633   case SystemZ::MUL32rm:   return get(SystemZ::MUL32rmy);
634   case SystemZ::CMP32rm:   return get(SystemZ::CMP32rmy);
635   case SystemZ::UCMP32rm:  return get(SystemZ::UCMP32rmy);
636   case SystemZ::FMOV32mr:  return get(SystemZ::FMOV32mry);
637   case SystemZ::FMOV64mr:  return get(SystemZ::FMOV64mry);
638   case SystemZ::FMOV32rm:  return get(SystemZ::FMOV32rmy);
639   case SystemZ::FMOV64rm:  return get(SystemZ::FMOV64rmy);
640   case SystemZ::MOV64Pmr:  return get(SystemZ::MOV64Pmry);
641   case SystemZ::MOV64Prm:  return get(SystemZ::MOV64Prmy);
642   }
643 }