Replace M_REMATERIALIZIBLE and the newly-added isOtherReMaterializableLoad
[oota-llvm.git] / lib / Target / X86 / X86InstrInfo.cpp
1 //===- X86InstrInfo.cpp - X86 Instruction Information -----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the X86 implementation of the TargetInstrInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "X86InstrInfo.h"
15 #include "X86.h"
16 #include "X86GenInstrInfo.inc"
17 #include "X86InstrBuilder.h"
18 #include "X86Subtarget.h"
19 #include "X86TargetMachine.h"
20 #include "llvm/CodeGen/MachineInstrBuilder.h"
21 #include "llvm/CodeGen/LiveVariables.h"
22 using namespace llvm;
23
24 X86InstrInfo::X86InstrInfo(X86TargetMachine &tm)
25   : TargetInstrInfo(X86Insts, sizeof(X86Insts)/sizeof(X86Insts[0])),
26     TM(tm), RI(tm, *this) {
27 }
28
29 bool X86InstrInfo::isMoveInstr(const MachineInstr& MI,
30                                unsigned& sourceReg,
31                                unsigned& destReg) const {
32   MachineOpCode oc = MI.getOpcode();
33   if (oc == X86::MOV8rr || oc == X86::MOV16rr ||
34       oc == X86::MOV32rr || oc == X86::MOV64rr ||
35       oc == X86::MOV16to16_ || oc == X86::MOV32to32_ ||
36       oc == X86::FpMOV  || oc == X86::MOVSSrr || oc == X86::MOVSDrr ||
37       oc == X86::FsMOVAPSrr || oc == X86::FsMOVAPDrr ||
38       oc == X86::MOVAPSrr || oc == X86::MOVAPDrr ||
39       oc == X86::MOVSS2PSrr || oc == X86::MOVSD2PDrr ||
40       oc == X86::MOVPS2SSrr || oc == X86::MOVPD2SDrr ||
41       oc == X86::MMX_MOVD64rr || oc == X86::MMX_MOVQ64rr) {
42       assert(MI.getNumOperands() >= 2 &&
43              MI.getOperand(0).isRegister() &&
44              MI.getOperand(1).isRegister() &&
45              "invalid register-register move instruction");
46       sourceReg = MI.getOperand(1).getReg();
47       destReg = MI.getOperand(0).getReg();
48       return true;
49   }
50   return false;
51 }
52
53 unsigned X86InstrInfo::isLoadFromStackSlot(MachineInstr *MI, 
54                                            int &FrameIndex) const {
55   switch (MI->getOpcode()) {
56   default: break;
57   case X86::MOV8rm:
58   case X86::MOV16rm:
59   case X86::MOV16_rm:
60   case X86::MOV32rm:
61   case X86::MOV32_rm:
62   case X86::MOV64rm:
63   case X86::FpLD64m:
64   case X86::MOVSSrm:
65   case X86::MOVSDrm:
66   case X86::MOVAPSrm:
67   case X86::MOVAPDrm:
68   case X86::MMX_MOVD64rm:
69   case X86::MMX_MOVQ64rm:
70     if (MI->getOperand(1).isFrameIndex() && MI->getOperand(2).isImmediate() &&
71         MI->getOperand(3).isRegister() && MI->getOperand(4).isImmediate() &&
72         MI->getOperand(2).getImmedValue() == 1 &&
73         MI->getOperand(3).getReg() == 0 &&
74         MI->getOperand(4).getImmedValue() == 0) {
75       FrameIndex = MI->getOperand(1).getFrameIndex();
76       return MI->getOperand(0).getReg();
77     }
78     break;
79   }
80   return 0;
81 }
82
83 unsigned X86InstrInfo::isStoreToStackSlot(MachineInstr *MI,
84                                           int &FrameIndex) const {
85   switch (MI->getOpcode()) {
86   default: break;
87   case X86::MOV8mr:
88   case X86::MOV16mr:
89   case X86::MOV16_mr:
90   case X86::MOV32mr:
91   case X86::MOV32_mr:
92   case X86::MOV64mr:
93   case X86::FpSTP64m:
94   case X86::MOVSSmr:
95   case X86::MOVSDmr:
96   case X86::MOVAPSmr:
97   case X86::MOVAPDmr:
98   case X86::MMX_MOVD64mr:
99   case X86::MMX_MOVQ64mr:
100   case X86::MMX_MOVNTQmr:
101     if (MI->getOperand(0).isFrameIndex() && MI->getOperand(1).isImmediate() &&
102         MI->getOperand(2).isRegister() && MI->getOperand(3).isImmediate() &&
103         MI->getOperand(1).getImmedValue() == 1 &&
104         MI->getOperand(2).getReg() == 0 &&
105         MI->getOperand(3).getImmedValue() == 0) {
106       FrameIndex = MI->getOperand(0).getFrameIndex();
107       return MI->getOperand(4).getReg();
108     }
109     break;
110   }
111   return 0;
112 }
113
114
115 bool X86InstrInfo::isTriviallyReMaterializable(MachineInstr *MI) const {
116   switch (MI->getOpcode()) {
117   default: break;
118   case X86::FpLD0:
119   case X86::FpLD1:
120   case X86::MOV8ri:
121   case X86::MOV16ri:
122   case X86::MOV32ri:
123   case X86::MMX_V_SET0:
124   case X86::MMX_V_SETALLONES:
125   case X86::V_SET0:
126   case X86::V_SETALLONES:
127     // These instructions are always trivially rematerializable.
128     return true;
129   case X86::MOV8rm:
130   case X86::MOV16rm:
131   case X86::MOV16_rm:
132   case X86::MOV32rm:
133   case X86::MOV32_rm:
134   case X86::MOV64rm:
135   case X86::FpLD64m:
136   case X86::MOVSSrm:
137   case X86::MOVSDrm:
138   case X86::MOVAPSrm:
139   case X86::MOVAPDrm:
140   case X86::MMX_MOVD64rm:
141   case X86::MMX_MOVQ64rm:
142     // Loads from constant pools are trivially rematerializable.
143     return MI->getOperand(1).isRegister() && MI->getOperand(2).isImmediate() &&
144            MI->getOperand(3).isRegister() && MI->getOperand(4).isConstantPoolIndex() &&
145            MI->getOperand(1).getReg() == 0 &&
146            MI->getOperand(2).getImmedValue() == 1 &&
147            MI->getOperand(3).getReg() == 0;
148   }
149   return false;
150 }
151
152 /// convertToThreeAddress - This method must be implemented by targets that
153 /// set the M_CONVERTIBLE_TO_3_ADDR flag.  When this flag is set, the target
154 /// may be able to convert a two-address instruction into a true
155 /// three-address instruction on demand.  This allows the X86 target (for
156 /// example) to convert ADD and SHL instructions into LEA instructions if they
157 /// would require register copies due to two-addressness.
158 ///
159 /// This method returns a null pointer if the transformation cannot be
160 /// performed, otherwise it returns the new instruction.
161 ///
162 MachineInstr *
163 X86InstrInfo::convertToThreeAddress(MachineFunction::iterator &MFI,
164                                     MachineBasicBlock::iterator &MBBI,
165                                     LiveVariables &LV) const {
166   MachineInstr *MI = MBBI;
167   // All instructions input are two-addr instructions.  Get the known operands.
168   unsigned Dest = MI->getOperand(0).getReg();
169   unsigned Src = MI->getOperand(1).getReg();
170
171   MachineInstr *NewMI = NULL;
172   // FIXME: 16-bit LEA's are really slow on Athlons, but not bad on P4's.  When
173   // we have better subtarget support, enable the 16-bit LEA generation here.
174   bool DisableLEA16 = true;
175
176   switch (MI->getOpcode()) {
177   default: return 0;
178   case X86::SHUFPSrri: {
179     assert(MI->getNumOperands() == 4 && "Unknown shufps instruction!");
180     if (!TM.getSubtarget<X86Subtarget>().hasSSE2()) return 0;
181     
182     unsigned A = MI->getOperand(0).getReg();
183     unsigned B = MI->getOperand(1).getReg();
184     unsigned C = MI->getOperand(2).getReg();
185     unsigned M = MI->getOperand(3).getImm();
186     if (B != C) return 0;
187     NewMI = BuildMI(get(X86::PSHUFDri), A).addReg(B).addImm(M);
188     break;
189   }
190   case X86::SHL64ri: {
191     assert(MI->getNumOperands() == 3 && "Unknown shift instruction!");
192     // NOTE: LEA doesn't produce flags like shift does, but LLVM never uses
193     // the flags produced by a shift yet, so this is safe.
194     unsigned Dest = MI->getOperand(0).getReg();
195     unsigned Src = MI->getOperand(1).getReg();
196     unsigned ShAmt = MI->getOperand(2).getImm();
197     if (ShAmt == 0 || ShAmt >= 4) return 0;
198     
199     NewMI = BuildMI(get(X86::LEA64r), Dest)
200       .addReg(0).addImm(1 << ShAmt).addReg(Src).addImm(0);
201     break;
202   }
203   case X86::SHL32ri: {
204     assert(MI->getNumOperands() == 3 && "Unknown shift instruction!");
205     // NOTE: LEA doesn't produce flags like shift does, but LLVM never uses
206     // the flags produced by a shift yet, so this is safe.
207     unsigned Dest = MI->getOperand(0).getReg();
208     unsigned Src = MI->getOperand(1).getReg();
209     unsigned ShAmt = MI->getOperand(2).getImm();
210     if (ShAmt == 0 || ShAmt >= 4) return 0;
211     
212     unsigned Opc = TM.getSubtarget<X86Subtarget>().is64Bit() ?
213       X86::LEA64_32r : X86::LEA32r;
214     NewMI = BuildMI(get(Opc), Dest)
215       .addReg(0).addImm(1 << ShAmt).addReg(Src).addImm(0);
216     break;
217   }
218   case X86::SHL16ri: {
219     assert(MI->getNumOperands() == 3 && "Unknown shift instruction!");
220     if (DisableLEA16) return 0;
221     
222     // NOTE: LEA doesn't produce flags like shift does, but LLVM never uses
223     // the flags produced by a shift yet, so this is safe.
224     unsigned Dest = MI->getOperand(0).getReg();
225     unsigned Src = MI->getOperand(1).getReg();
226     unsigned ShAmt = MI->getOperand(2).getImm();
227     if (ShAmt == 0 || ShAmt >= 4) return 0;
228     
229     NewMI = BuildMI(get(X86::LEA16r), Dest)
230       .addReg(0).addImm(1 << ShAmt).addReg(Src).addImm(0);
231     break;
232   }
233   }
234
235   // FIXME: None of these instructions are promotable to LEAs without
236   // additional information.  In particular, LEA doesn't set the flags that
237   // add and inc do.  :(
238   if (0)
239   switch (MI->getOpcode()) {
240   case X86::INC32r:
241   case X86::INC64_32r:
242     assert(MI->getNumOperands() == 2 && "Unknown inc instruction!");
243     NewMI = addRegOffset(BuildMI(get(X86::LEA32r), Dest), Src, 1);
244     break;
245   case X86::INC16r:
246   case X86::INC64_16r:
247     if (DisableLEA16) return 0;
248     assert(MI->getNumOperands() == 2 && "Unknown inc instruction!");
249     NewMI = addRegOffset(BuildMI(get(X86::LEA16r), Dest), Src, 1);
250     break;
251   case X86::DEC32r:
252   case X86::DEC64_32r:
253     assert(MI->getNumOperands() == 2 && "Unknown dec instruction!");
254     NewMI = addRegOffset(BuildMI(get(X86::LEA32r), Dest), Src, -1);
255     break;
256   case X86::DEC16r:
257   case X86::DEC64_16r:
258     if (DisableLEA16) return 0;
259     assert(MI->getNumOperands() == 2 && "Unknown dec instruction!");
260     NewMI = addRegOffset(BuildMI(get(X86::LEA16r), Dest), Src, -1);
261     break;
262   case X86::ADD32rr:
263     assert(MI->getNumOperands() == 3 && "Unknown add instruction!");
264     NewMI = addRegReg(BuildMI(get(X86::LEA32r), Dest), Src,
265                      MI->getOperand(2).getReg());
266     break;
267   case X86::ADD16rr:
268     if (DisableLEA16) return 0;
269     assert(MI->getNumOperands() == 3 && "Unknown add instruction!");
270     NewMI = addRegReg(BuildMI(get(X86::LEA16r), Dest), Src,
271                      MI->getOperand(2).getReg());
272     break;
273   case X86::ADD32ri:
274   case X86::ADD32ri8:
275     assert(MI->getNumOperands() == 3 && "Unknown add instruction!");
276     if (MI->getOperand(2).isImmediate())
277       NewMI = addRegOffset(BuildMI(get(X86::LEA32r), Dest), Src,
278                           MI->getOperand(2).getImmedValue());
279     break;
280   case X86::ADD16ri:
281   case X86::ADD16ri8:
282     if (DisableLEA16) return 0;
283     assert(MI->getNumOperands() == 3 && "Unknown add instruction!");
284     if (MI->getOperand(2).isImmediate())
285       NewMI = addRegOffset(BuildMI(get(X86::LEA16r), Dest), Src,
286                           MI->getOperand(2).getImmedValue());
287     break;
288   case X86::SHL16ri:
289     if (DisableLEA16) return 0;
290   case X86::SHL32ri:
291     assert(MI->getNumOperands() == 3 && MI->getOperand(2).isImmediate() &&
292            "Unknown shl instruction!");
293     unsigned ShAmt = MI->getOperand(2).getImmedValue();
294     if (ShAmt == 1 || ShAmt == 2 || ShAmt == 3) {
295       X86AddressMode AM;
296       AM.Scale = 1 << ShAmt;
297       AM.IndexReg = Src;
298       unsigned Opc = MI->getOpcode() == X86::SHL32ri ? X86::LEA32r :X86::LEA16r;
299       NewMI = addFullAddress(BuildMI(get(Opc), Dest), AM);
300     }
301     break;
302   }
303
304   if (NewMI) {
305     NewMI->copyKillDeadInfo(MI);
306     LV.instructionChanged(MI, NewMI);  // Update live variables
307     MFI->insert(MBBI, NewMI);          // Insert the new inst    
308   }
309   return NewMI;
310 }
311
312 /// commuteInstruction - We have a few instructions that must be hacked on to
313 /// commute them.
314 ///
315 MachineInstr *X86InstrInfo::commuteInstruction(MachineInstr *MI) const {
316   // FIXME: Can commute cmoves by changing the condition!
317   switch (MI->getOpcode()) {
318   case X86::SHRD16rri8: // A = SHRD16rri8 B, C, I -> A = SHLD16rri8 C, B, (16-I)
319   case X86::SHLD16rri8: // A = SHLD16rri8 B, C, I -> A = SHRD16rri8 C, B, (16-I)
320   case X86::SHRD32rri8: // A = SHRD32rri8 B, C, I -> A = SHLD32rri8 C, B, (32-I)
321   case X86::SHLD32rri8:{// A = SHLD32rri8 B, C, I -> A = SHRD32rri8 C, B, (32-I)
322     unsigned Opc;
323     unsigned Size;
324     switch (MI->getOpcode()) {
325     default: assert(0 && "Unreachable!");
326     case X86::SHRD16rri8: Size = 16; Opc = X86::SHLD16rri8; break;
327     case X86::SHLD16rri8: Size = 16; Opc = X86::SHRD16rri8; break;
328     case X86::SHRD32rri8: Size = 32; Opc = X86::SHLD32rri8; break;
329     case X86::SHLD32rri8: Size = 32; Opc = X86::SHRD32rri8; break;
330     }
331     unsigned Amt = MI->getOperand(3).getImmedValue();
332     unsigned A = MI->getOperand(0).getReg();
333     unsigned B = MI->getOperand(1).getReg();
334     unsigned C = MI->getOperand(2).getReg();
335     bool BisKill = MI->getOperand(1).isKill();
336     bool CisKill = MI->getOperand(2).isKill();
337     return BuildMI(get(Opc), A).addReg(C, false, false, CisKill)
338       .addReg(B, false, false, BisKill).addImm(Size-Amt);
339   }
340   default:
341     return TargetInstrInfo::commuteInstruction(MI);
342   }
343 }
344
345 static X86::CondCode GetCondFromBranchOpc(unsigned BrOpc) {
346   switch (BrOpc) {
347   default: return X86::COND_INVALID;
348   case X86::JE:  return X86::COND_E;
349   case X86::JNE: return X86::COND_NE;
350   case X86::JL:  return X86::COND_L;
351   case X86::JLE: return X86::COND_LE;
352   case X86::JG:  return X86::COND_G;
353   case X86::JGE: return X86::COND_GE;
354   case X86::JB:  return X86::COND_B;
355   case X86::JBE: return X86::COND_BE;
356   case X86::JA:  return X86::COND_A;
357   case X86::JAE: return X86::COND_AE;
358   case X86::JS:  return X86::COND_S;
359   case X86::JNS: return X86::COND_NS;
360   case X86::JP:  return X86::COND_P;
361   case X86::JNP: return X86::COND_NP;
362   case X86::JO:  return X86::COND_O;
363   case X86::JNO: return X86::COND_NO;
364   }
365 }
366
367 unsigned X86::GetCondBranchFromCond(X86::CondCode CC) {
368   switch (CC) {
369   default: assert(0 && "Illegal condition code!");
370   case X86::COND_E:  return X86::JE;
371   case X86::COND_NE: return X86::JNE;
372   case X86::COND_L:  return X86::JL;
373   case X86::COND_LE: return X86::JLE;
374   case X86::COND_G:  return X86::JG;
375   case X86::COND_GE: return X86::JGE;
376   case X86::COND_B:  return X86::JB;
377   case X86::COND_BE: return X86::JBE;
378   case X86::COND_A:  return X86::JA;
379   case X86::COND_AE: return X86::JAE;
380   case X86::COND_S:  return X86::JS;
381   case X86::COND_NS: return X86::JNS;
382   case X86::COND_P:  return X86::JP;
383   case X86::COND_NP: return X86::JNP;
384   case X86::COND_O:  return X86::JO;
385   case X86::COND_NO: return X86::JNO;
386   }
387 }
388
389 /// GetOppositeBranchCondition - Return the inverse of the specified condition,
390 /// e.g. turning COND_E to COND_NE.
391 X86::CondCode X86::GetOppositeBranchCondition(X86::CondCode CC) {
392   switch (CC) {
393   default: assert(0 && "Illegal condition code!");
394   case X86::COND_E:  return X86::COND_NE;
395   case X86::COND_NE: return X86::COND_E;
396   case X86::COND_L:  return X86::COND_GE;
397   case X86::COND_LE: return X86::COND_G;
398   case X86::COND_G:  return X86::COND_LE;
399   case X86::COND_GE: return X86::COND_L;
400   case X86::COND_B:  return X86::COND_AE;
401   case X86::COND_BE: return X86::COND_A;
402   case X86::COND_A:  return X86::COND_BE;
403   case X86::COND_AE: return X86::COND_B;
404   case X86::COND_S:  return X86::COND_NS;
405   case X86::COND_NS: return X86::COND_S;
406   case X86::COND_P:  return X86::COND_NP;
407   case X86::COND_NP: return X86::COND_P;
408   case X86::COND_O:  return X86::COND_NO;
409   case X86::COND_NO: return X86::COND_O;
410   }
411 }
412
413 // For purposes of branch analysis do not count FP_REG_KILL as a terminator.
414 bool X86InstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
415   const TargetInstrDescriptor *TID = MI->getInstrDescriptor();
416   if (MI->getOpcode() == X86::FP_REG_KILL)
417     return false;
418   if (TID->Flags & M_TERMINATOR_FLAG)
419     return !isPredicated(MI);
420   return false;
421 }
422
423 bool X86InstrInfo::AnalyzeBranch(MachineBasicBlock &MBB, 
424                                  MachineBasicBlock *&TBB,
425                                  MachineBasicBlock *&FBB,
426                                  std::vector<MachineOperand> &Cond) const {
427   // If the block has no terminators, it just falls into the block after it.
428   MachineBasicBlock::iterator I = MBB.end();
429   if (I == MBB.begin() || !isUnpredicatedTerminator(--I))
430     return false;
431
432   // Get the last instruction in the block.
433   MachineInstr *LastInst = I;
434   
435   // If there is only one terminator instruction, process it.
436   if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
437     if (!isBranch(LastInst->getOpcode()))
438       return true;
439     
440     // If the block ends with a branch there are 3 possibilities:
441     // it's an unconditional, conditional, or indirect branch.
442     
443     if (LastInst->getOpcode() == X86::JMP) {
444       TBB = LastInst->getOperand(0).getMachineBasicBlock();
445       return false;
446     }
447     X86::CondCode BranchCode = GetCondFromBranchOpc(LastInst->getOpcode());
448     if (BranchCode == X86::COND_INVALID)
449       return true;  // Can't handle indirect branch.
450
451     // Otherwise, block ends with fall-through condbranch.
452     TBB = LastInst->getOperand(0).getMachineBasicBlock();
453     Cond.push_back(MachineOperand::CreateImm(BranchCode));
454     return false;
455   }
456   
457   // Get the instruction before it if it's a terminator.
458   MachineInstr *SecondLastInst = I;
459   
460   // If there are three terminators, we don't know what sort of block this is.
461   if (SecondLastInst && I != MBB.begin() && isUnpredicatedTerminator(--I))
462     return true;
463
464   // If the block ends with X86::JMP and a conditional branch, handle it.
465   X86::CondCode BranchCode = GetCondFromBranchOpc(SecondLastInst->getOpcode());
466   if (BranchCode != X86::COND_INVALID && LastInst->getOpcode() == X86::JMP) {
467     TBB = SecondLastInst->getOperand(0).getMachineBasicBlock();
468     Cond.push_back(MachineOperand::CreateImm(BranchCode));
469     FBB = LastInst->getOperand(0).getMachineBasicBlock();
470     return false;
471   }
472
473   // If the block ends with two X86::JMPs, handle it.  The second one is not
474   // executed, so remove it.
475   if (SecondLastInst->getOpcode() == X86::JMP && 
476       LastInst->getOpcode() == X86::JMP) {
477     TBB = SecondLastInst->getOperand(0).getMachineBasicBlock();
478     I = LastInst;
479     I->eraseFromParent();
480     return false;
481   }
482
483   // Otherwise, can't handle this.
484   return true;
485 }
486
487 unsigned X86InstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
488   MachineBasicBlock::iterator I = MBB.end();
489   if (I == MBB.begin()) return 0;
490   --I;
491   if (I->getOpcode() != X86::JMP && 
492       GetCondFromBranchOpc(I->getOpcode()) == X86::COND_INVALID)
493     return 0;
494   
495   // Remove the branch.
496   I->eraseFromParent();
497   
498   I = MBB.end();
499   
500   if (I == MBB.begin()) return 1;
501   --I;
502   if (GetCondFromBranchOpc(I->getOpcode()) == X86::COND_INVALID)
503     return 1;
504   
505   // Remove the branch.
506   I->eraseFromParent();
507   return 2;
508 }
509
510 unsigned
511 X86InstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
512                            MachineBasicBlock *FBB,
513                            const std::vector<MachineOperand> &Cond) const {
514   // Shouldn't be a fall through.
515   assert(TBB && "InsertBranch must not be told to insert a fallthrough");
516   assert((Cond.size() == 1 || Cond.size() == 0) &&
517          "X86 branch conditions have one component!");
518
519   if (FBB == 0) { // One way branch.
520     if (Cond.empty()) {
521       // Unconditional branch?
522       BuildMI(&MBB, get(X86::JMP)).addMBB(TBB);
523     } else {
524       // Conditional branch.
525       unsigned Opc = GetCondBranchFromCond((X86::CondCode)Cond[0].getImm());
526       BuildMI(&MBB, get(Opc)).addMBB(TBB);
527     }
528     return 1;
529   }
530   
531   // Two-way Conditional branch.
532   unsigned Opc = GetCondBranchFromCond((X86::CondCode)Cond[0].getImm());
533   BuildMI(&MBB, get(Opc)).addMBB(TBB);
534   BuildMI(&MBB, get(X86::JMP)).addMBB(FBB);
535   return 2;
536 }
537
538 bool X86InstrInfo::BlockHasNoFallThrough(MachineBasicBlock &MBB) const {
539   if (MBB.empty()) return false;
540   
541   switch (MBB.back().getOpcode()) {
542   case X86::RET:     // Return.
543   case X86::RETI:
544   case X86::TAILJMPd:
545   case X86::TAILJMPr:
546   case X86::TAILJMPm:
547   case X86::JMP:     // Uncond branch.
548   case X86::JMP32r:  // Indirect branch.
549   case X86::JMP32m:  // Indirect branch through mem.
550     return true;
551   default: return false;
552   }
553 }
554
555 bool X86InstrInfo::
556 ReverseBranchCondition(std::vector<MachineOperand> &Cond) const {
557   assert(Cond.size() == 1 && "Invalid X86 branch condition!");
558   Cond[0].setImm(GetOppositeBranchCondition((X86::CondCode)Cond[0].getImm()));
559   return false;
560 }
561
562 const TargetRegisterClass *X86InstrInfo::getPointerRegClass() const {
563   const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
564   if (Subtarget->is64Bit())
565     return &X86::GR64RegClass;
566   else
567     return &X86::GR32RegClass;
568 }