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