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