blob: 90e347279575e773ad207127606eafaace8c6c7a [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- PPCInstrInfo.cpp - PowerPC32 Instruction Information -----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the PowerPC implementation of the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "PPCInstrInfo.h"
Owen Anderson81875432008-01-01 21:11:32 +000015#include "PPCInstrBuilder.h"
Bill Wendlinga1877c52008-03-03 22:19:16 +000016#include "PPCMachineFunctionInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000017#include "PPCPredicates.h"
18#include "PPCGenInstrInfo.inc"
19#include "PPCTargetMachine.h"
Owen Anderson1636de92007-09-07 04:06:50 +000020#include "llvm/ADT/STLExtras.h"
Jakob Stoklund Olesen18275a42010-07-16 18:22:00 +000021#include "llvm/CodeGen/MachineFrameInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000022#include "llvm/CodeGen/MachineInstrBuilder.h"
Jakob Stoklund Olesen18275a42010-07-16 18:22:00 +000023#include "llvm/CodeGen/MachineMemOperand.h"
Jakob Stoklund Olesen98172ee2010-02-26 21:09:24 +000024#include "llvm/CodeGen/MachineRegisterInfo.h"
Jakob Stoklund Olesen18275a42010-07-16 18:22:00 +000025#include "llvm/CodeGen/PseudoSourceValue.h"
Bill Wendling03598502008-03-04 23:13:51 +000026#include "llvm/Support/CommandLine.h"
Edwin Török4d9756a2009-07-08 20:53:28 +000027#include "llvm/Support/ErrorHandling.h"
28#include "llvm/Support/raw_ostream.h"
Chris Lattner621c44d2009-08-22 20:48:53 +000029#include "llvm/MC/MCAsmInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030
Dan Gohmanca9ec762010-04-15 17:20:57 +000031namespace llvm {
Bill Wendling4eaadfb2008-03-10 22:49:16 +000032extern cl::opt<bool> EnablePPC32RS; // FIXME (64-bit): See PPCRegisterInfo.cpp.
33extern cl::opt<bool> EnablePPC64RS; // FIXME (64-bit): See PPCRegisterInfo.cpp.
Dan Gohmanca9ec762010-04-15 17:20:57 +000034}
35
36using namespace llvm;
Bill Wendling03598502008-03-04 23:13:51 +000037
Dan Gohmanf17a25c2007-07-18 16:29:46 +000038PPCInstrInfo::PPCInstrInfo(PPCTargetMachine &tm)
Chris Lattnerd2fd6db2008-01-01 01:03:04 +000039 : TargetInstrInfoImpl(PPCInsts, array_lengthof(PPCInsts)), TM(tm),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000040 RI(*TM.getSubtargetImpl(), *this) {}
41
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042bool PPCInstrInfo::isMoveInstr(const MachineInstr& MI,
43 unsigned& sourceReg,
Evan Chengf97496a2009-01-20 19:12:24 +000044 unsigned& destReg,
45 unsigned& sourceSubIdx,
46 unsigned& destSubIdx) const {
47 sourceSubIdx = destSubIdx = 0; // No sub-registers.
48
Chris Lattner99aa3372008-01-07 02:48:55 +000049 unsigned oc = MI.getOpcode();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050 if (oc == PPC::OR || oc == PPC::OR8 || oc == PPC::VOR ||
51 oc == PPC::OR4To8 || oc == PPC::OR8To4) { // or r1, r2, r2
52 assert(MI.getNumOperands() >= 3 &&
Dan Gohmanb9f4fa72008-10-03 15:45:36 +000053 MI.getOperand(0).isReg() &&
54 MI.getOperand(1).isReg() &&
55 MI.getOperand(2).isReg() &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056 "invalid PPC OR instruction!");
57 if (MI.getOperand(1).getReg() == MI.getOperand(2).getReg()) {
58 sourceReg = MI.getOperand(1).getReg();
59 destReg = MI.getOperand(0).getReg();
60 return true;
61 }
62 } else if (oc == PPC::ADDI) { // addi r1, r2, 0
63 assert(MI.getNumOperands() >= 3 &&
Dan Gohmanb9f4fa72008-10-03 15:45:36 +000064 MI.getOperand(0).isReg() &&
65 MI.getOperand(2).isImm() &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +000066 "invalid PPC ADDI instruction!");
Dan Gohmanb9f4fa72008-10-03 15:45:36 +000067 if (MI.getOperand(1).isReg() && MI.getOperand(2).getImm() == 0) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000068 sourceReg = MI.getOperand(1).getReg();
69 destReg = MI.getOperand(0).getReg();
70 return true;
71 }
72 } else if (oc == PPC::ORI) { // ori r1, r2, 0
73 assert(MI.getNumOperands() >= 3 &&
Dan Gohmanb9f4fa72008-10-03 15:45:36 +000074 MI.getOperand(0).isReg() &&
75 MI.getOperand(1).isReg() &&
76 MI.getOperand(2).isImm() &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +000077 "invalid PPC ORI instruction!");
Chris Lattnera96056a2007-12-30 20:49:49 +000078 if (MI.getOperand(2).getImm() == 0) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000079 sourceReg = MI.getOperand(1).getReg();
80 destReg = MI.getOperand(0).getReg();
81 return true;
82 }
Jakob Stoklund Olesen44ead232010-07-16 21:03:52 +000083 } else if (oc == PPC::FMR) { // fmr r1, r2
Dan Gohmanf17a25c2007-07-18 16:29:46 +000084 assert(MI.getNumOperands() >= 2 &&
Dan Gohmanb9f4fa72008-10-03 15:45:36 +000085 MI.getOperand(0).isReg() &&
86 MI.getOperand(1).isReg() &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +000087 "invalid PPC FMR instruction");
88 sourceReg = MI.getOperand(1).getReg();
89 destReg = MI.getOperand(0).getReg();
90 return true;
91 } else if (oc == PPC::MCRF) { // mcrf cr1, cr2
92 assert(MI.getNumOperands() >= 2 &&
Dan Gohmanb9f4fa72008-10-03 15:45:36 +000093 MI.getOperand(0).isReg() &&
94 MI.getOperand(1).isReg() &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +000095 "invalid PPC MCRF instruction");
96 sourceReg = MI.getOperand(1).getReg();
97 destReg = MI.getOperand(0).getReg();
98 return true;
99 }
100 return false;
101}
102
Dan Gohman90feee22008-11-18 19:49:32 +0000103unsigned PPCInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000104 int &FrameIndex) const {
105 switch (MI->getOpcode()) {
106 default: break;
107 case PPC::LD:
108 case PPC::LWZ:
109 case PPC::LFS:
110 case PPC::LFD:
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000111 if (MI->getOperand(1).isImm() && !MI->getOperand(1).getImm() &&
112 MI->getOperand(2).isFI()) {
Chris Lattner6017d482007-12-30 23:10:15 +0000113 FrameIndex = MI->getOperand(2).getIndex();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000114 return MI->getOperand(0).getReg();
115 }
116 break;
117 }
118 return 0;
119}
120
Dan Gohman90feee22008-11-18 19:49:32 +0000121unsigned PPCInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000122 int &FrameIndex) const {
123 switch (MI->getOpcode()) {
124 default: break;
125 case PPC::STD:
126 case PPC::STW:
127 case PPC::STFS:
128 case PPC::STFD:
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000129 if (MI->getOperand(1).isImm() && !MI->getOperand(1).getImm() &&
130 MI->getOperand(2).isFI()) {
Chris Lattner6017d482007-12-30 23:10:15 +0000131 FrameIndex = MI->getOperand(2).getIndex();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000132 return MI->getOperand(0).getReg();
133 }
134 break;
135 }
136 return 0;
137}
138
139// commuteInstruction - We can commute rlwimi instructions, but only if the
140// rotate amt is zero. We also have to munge the immediates a bit.
Evan Cheng5de1aaf2008-06-16 07:33:11 +0000141MachineInstr *
142PPCInstrInfo::commuteInstruction(MachineInstr *MI, bool NewMI) const {
Dan Gohman221a4372008-07-07 23:14:23 +0000143 MachineFunction &MF = *MI->getParent()->getParent();
144
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000145 // Normal instructions can be commuted the obvious way.
146 if (MI->getOpcode() != PPC::RLWIMI)
Evan Cheng5de1aaf2008-06-16 07:33:11 +0000147 return TargetInstrInfoImpl::commuteInstruction(MI, NewMI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000148
149 // Cannot commute if it has a non-zero rotate count.
Chris Lattnera96056a2007-12-30 20:49:49 +0000150 if (MI->getOperand(3).getImm() != 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000151 return 0;
152
153 // If we have a zero rotate count, we have:
154 // M = mask(MB,ME)
155 // Op0 = (Op1 & ~M) | (Op2 & M)
156 // Change this to:
157 // M = mask((ME+1)&31, (MB-1)&31)
158 // Op0 = (Op2 & ~M) | (Op1 & M)
159
160 // Swap op1/op2
Evan Chengb554e532008-02-13 02:46:49 +0000161 unsigned Reg0 = MI->getOperand(0).getReg();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000162 unsigned Reg1 = MI->getOperand(1).getReg();
163 unsigned Reg2 = MI->getOperand(2).getReg();
164 bool Reg1IsKill = MI->getOperand(1).isKill();
165 bool Reg2IsKill = MI->getOperand(2).isKill();
Evan Cheng5de1aaf2008-06-16 07:33:11 +0000166 bool ChangeReg0 = false;
Evan Chengb554e532008-02-13 02:46:49 +0000167 // If machine instrs are no longer in two-address forms, update
168 // destination register as well.
169 if (Reg0 == Reg1) {
170 // Must be two address instruction!
171 assert(MI->getDesc().getOperandConstraint(0, TOI::TIED_TO) &&
172 "Expecting a two-address instruction!");
Evan Chengb554e532008-02-13 02:46:49 +0000173 Reg2IsKill = false;
Evan Cheng5de1aaf2008-06-16 07:33:11 +0000174 ChangeReg0 = true;
Evan Chengb554e532008-02-13 02:46:49 +0000175 }
Evan Cheng5de1aaf2008-06-16 07:33:11 +0000176
177 // Masks.
178 unsigned MB = MI->getOperand(4).getImm();
179 unsigned ME = MI->getOperand(5).getImm();
180
181 if (NewMI) {
182 // Create a new instruction.
183 unsigned Reg0 = ChangeReg0 ? Reg2 : MI->getOperand(0).getReg();
184 bool Reg0IsDead = MI->getOperand(0).isDead();
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000185 return BuildMI(MF, MI->getDebugLoc(), MI->getDesc())
Bill Wendling2b739762009-05-13 21:33:08 +0000186 .addReg(Reg0, RegState::Define | getDeadRegState(Reg0IsDead))
187 .addReg(Reg2, getKillRegState(Reg2IsKill))
188 .addReg(Reg1, getKillRegState(Reg1IsKill))
Evan Cheng5de1aaf2008-06-16 07:33:11 +0000189 .addImm((ME+1) & 31)
190 .addImm((MB-1) & 31);
191 }
192
193 if (ChangeReg0)
194 MI->getOperand(0).setReg(Reg2);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000195 MI->getOperand(2).setReg(Reg1);
196 MI->getOperand(1).setReg(Reg2);
Chris Lattner7f2d3b82007-12-30 21:56:09 +0000197 MI->getOperand(2).setIsKill(Reg1IsKill);
198 MI->getOperand(1).setIsKill(Reg2IsKill);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000199
200 // Swap the mask around.
Chris Lattnera96056a2007-12-30 20:49:49 +0000201 MI->getOperand(4).setImm((ME+1) & 31);
202 MI->getOperand(5).setImm((MB-1) & 31);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000203 return MI;
204}
205
206void PPCInstrInfo::insertNoop(MachineBasicBlock &MBB,
207 MachineBasicBlock::iterator MI) const {
Chris Lattnerd2c680b2010-04-02 20:16:16 +0000208 DebugLoc DL;
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000209 BuildMI(MBB, MI, DL, get(PPC::NOP));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000210}
211
212
213// Branch analysis.
214bool PPCInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
215 MachineBasicBlock *&FBB,
Evan Chengeac31642009-02-09 07:14:22 +0000216 SmallVectorImpl<MachineOperand> &Cond,
217 bool AllowModify) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000218 // If the block has no terminators, it just falls into the block after it.
219 MachineBasicBlock::iterator I = MBB.end();
Dale Johannesen139dcd72010-04-02 01:38:09 +0000220 if (I == MBB.begin())
221 return false;
222 --I;
223 while (I->isDebugValue()) {
224 if (I == MBB.begin())
225 return false;
226 --I;
227 }
228 if (!isUnpredicatedTerminator(I))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000229 return false;
230
231 // Get the last instruction in the block.
232 MachineInstr *LastInst = I;
233
234 // If there is only one terminator instruction, process it.
235 if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
236 if (LastInst->getOpcode() == PPC::B) {
Evan Cheng6ed927b2009-05-08 23:09:25 +0000237 if (!LastInst->getOperand(0).isMBB())
238 return true;
Chris Lattner6017d482007-12-30 23:10:15 +0000239 TBB = LastInst->getOperand(0).getMBB();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000240 return false;
241 } else if (LastInst->getOpcode() == PPC::BCC) {
Evan Cheng6ed927b2009-05-08 23:09:25 +0000242 if (!LastInst->getOperand(2).isMBB())
243 return true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000244 // Block ends with fall-through condbranch.
Chris Lattner6017d482007-12-30 23:10:15 +0000245 TBB = LastInst->getOperand(2).getMBB();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000246 Cond.push_back(LastInst->getOperand(0));
247 Cond.push_back(LastInst->getOperand(1));
248 return false;
249 }
250 // Otherwise, don't know what this is.
251 return true;
252 }
253
254 // Get the instruction before it if it's a terminator.
255 MachineInstr *SecondLastInst = I;
256
257 // If there are three terminators, we don't know what sort of block this is.
258 if (SecondLastInst && I != MBB.begin() &&
259 isUnpredicatedTerminator(--I))
260 return true;
261
262 // If the block ends with PPC::B and PPC:BCC, handle it.
263 if (SecondLastInst->getOpcode() == PPC::BCC &&
264 LastInst->getOpcode() == PPC::B) {
Evan Cheng6ed927b2009-05-08 23:09:25 +0000265 if (!SecondLastInst->getOperand(2).isMBB() ||
266 !LastInst->getOperand(0).isMBB())
267 return true;
Chris Lattner6017d482007-12-30 23:10:15 +0000268 TBB = SecondLastInst->getOperand(2).getMBB();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269 Cond.push_back(SecondLastInst->getOperand(0));
270 Cond.push_back(SecondLastInst->getOperand(1));
Chris Lattner6017d482007-12-30 23:10:15 +0000271 FBB = LastInst->getOperand(0).getMBB();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000272 return false;
273 }
274
275 // If the block ends with two PPC:Bs, handle it. The second one is not
276 // executed, so remove it.
277 if (SecondLastInst->getOpcode() == PPC::B &&
278 LastInst->getOpcode() == PPC::B) {
Evan Cheng6ed927b2009-05-08 23:09:25 +0000279 if (!SecondLastInst->getOperand(0).isMBB())
280 return true;
Chris Lattner6017d482007-12-30 23:10:15 +0000281 TBB = SecondLastInst->getOperand(0).getMBB();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000282 I = LastInst;
Evan Chengeac31642009-02-09 07:14:22 +0000283 if (AllowModify)
284 I->eraseFromParent();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000285 return false;
286 }
287
288 // Otherwise, can't handle this.
289 return true;
290}
291
292unsigned PPCInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
293 MachineBasicBlock::iterator I = MBB.end();
294 if (I == MBB.begin()) return 0;
295 --I;
Dale Johannesen139dcd72010-04-02 01:38:09 +0000296 while (I->isDebugValue()) {
297 if (I == MBB.begin())
298 return 0;
299 --I;
300 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000301 if (I->getOpcode() != PPC::B && I->getOpcode() != PPC::BCC)
302 return 0;
303
304 // Remove the branch.
305 I->eraseFromParent();
306
307 I = MBB.end();
308
309 if (I == MBB.begin()) return 1;
310 --I;
311 if (I->getOpcode() != PPC::BCC)
312 return 1;
313
314 // Remove the branch.
315 I->eraseFromParent();
316 return 2;
317}
318
319unsigned
320PPCInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
321 MachineBasicBlock *FBB,
Stuart Hastings9fa5e332010-06-17 22:43:56 +0000322 const SmallVectorImpl<MachineOperand> &Cond,
323 DebugLoc DL) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000324 // Shouldn't be a fall through.
325 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
326 assert((Cond.size() == 2 || Cond.size() == 0) &&
327 "PPC branch conditions have two components!");
328
329 // One-way branch.
330 if (FBB == 0) {
331 if (Cond.empty()) // Unconditional branch
Stuart Hastings9fa5e332010-06-17 22:43:56 +0000332 BuildMI(&MBB, DL, get(PPC::B)).addMBB(TBB);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000333 else // Conditional branch
Stuart Hastings9fa5e332010-06-17 22:43:56 +0000334 BuildMI(&MBB, DL, get(PPC::BCC))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000335 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
336 return 1;
337 }
338
339 // Two-way Conditional Branch.
Stuart Hastings9fa5e332010-06-17 22:43:56 +0000340 BuildMI(&MBB, DL, get(PPC::BCC))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000341 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
Stuart Hastings9fa5e332010-06-17 22:43:56 +0000342 BuildMI(&MBB, DL, get(PPC::B)).addMBB(FBB);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000343 return 2;
344}
345
Jakob Stoklund Olesen02200a32010-07-11 07:31:00 +0000346void PPCInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
347 MachineBasicBlock::iterator I, DebugLoc DL,
348 unsigned DestReg, unsigned SrcReg,
349 bool KillSrc) const {
350 unsigned Opc;
351 if (PPC::GPRCRegClass.contains(DestReg, SrcReg))
352 Opc = PPC::OR;
353 else if (PPC::G8RCRegClass.contains(DestReg, SrcReg))
354 Opc = PPC::OR8;
355 else if (PPC::F4RCRegClass.contains(DestReg, SrcReg))
356 Opc = PPC::FMR;
357 else if (PPC::CRRCRegClass.contains(DestReg, SrcReg))
358 Opc = PPC::MCRF;
359 else if (PPC::VRRCRegClass.contains(DestReg, SrcReg))
360 Opc = PPC::VOR;
361 else if (PPC::CRBITRCRegClass.contains(DestReg, SrcReg))
362 Opc = PPC::CROR;
363 else
364 llvm_unreachable("Impossible reg-to-reg copy");
Owen Anderson8f2c8932007-12-31 06:32:00 +0000365
Jakob Stoklund Olesen02200a32010-07-11 07:31:00 +0000366 const TargetInstrDesc &TID = get(Opc);
367 if (TID.getNumOperands() == 3)
368 BuildMI(MBB, I, DL, TID, DestReg)
369 .addReg(SrcReg).addReg(SrcReg, getKillRegState(KillSrc));
370 else
371 BuildMI(MBB, I, DL, TID, DestReg).addReg(SrcReg, getKillRegState(KillSrc));
Owen Anderson8f2c8932007-12-31 06:32:00 +0000372}
373
Bill Wendling4eaadfb2008-03-10 22:49:16 +0000374bool
Dan Gohman221a4372008-07-07 23:14:23 +0000375PPCInstrInfo::StoreRegToStackSlot(MachineFunction &MF,
376 unsigned SrcReg, bool isKill,
Bill Wendling4eaadfb2008-03-10 22:49:16 +0000377 int FrameIdx,
378 const TargetRegisterClass *RC,
379 SmallVectorImpl<MachineInstr*> &NewMIs) const{
Chris Lattnerd2c680b2010-04-02 20:16:16 +0000380 DebugLoc DL;
Owen Anderson81875432008-01-01 21:11:32 +0000381 if (RC == PPC::GPRCRegisterClass) {
382 if (SrcReg != PPC::LR) {
Dale Johannesen77cce4d2009-02-12 23:08:38 +0000383 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STW))
Bill Wendling2b739762009-05-13 21:33:08 +0000384 .addReg(SrcReg,
385 getKillRegState(isKill)),
Bill Wendling4eaadfb2008-03-10 22:49:16 +0000386 FrameIdx));
Owen Anderson81875432008-01-01 21:11:32 +0000387 } else {
388 // FIXME: this spills LR immediately to memory in one step. To do this,
389 // we use R11, which we know cannot be used in the prolog/epilog. This is
390 // a hack.
Dale Johannesen77cce4d2009-02-12 23:08:38 +0000391 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MFLR), PPC::R11));
392 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STW))
Bill Wendling2b739762009-05-13 21:33:08 +0000393 .addReg(PPC::R11,
394 getKillRegState(isKill)),
Bill Wendling4eaadfb2008-03-10 22:49:16 +0000395 FrameIdx));
Owen Anderson81875432008-01-01 21:11:32 +0000396 }
397 } else if (RC == PPC::G8RCRegisterClass) {
398 if (SrcReg != PPC::LR8) {
Dale Johannesen77cce4d2009-02-12 23:08:38 +0000399 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STD))
Bill Wendling2b739762009-05-13 21:33:08 +0000400 .addReg(SrcReg,
401 getKillRegState(isKill)),
402 FrameIdx));
Owen Anderson81875432008-01-01 21:11:32 +0000403 } else {
404 // FIXME: this spills LR immediately to memory in one step. To do this,
405 // we use R11, which we know cannot be used in the prolog/epilog. This is
406 // a hack.
Dale Johannesen77cce4d2009-02-12 23:08:38 +0000407 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MFLR8), PPC::X11));
408 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STD))
Bill Wendling2b739762009-05-13 21:33:08 +0000409 .addReg(PPC::X11,
410 getKillRegState(isKill)),
411 FrameIdx));
Owen Anderson81875432008-01-01 21:11:32 +0000412 }
413 } else if (RC == PPC::F8RCRegisterClass) {
Dale Johannesen77cce4d2009-02-12 23:08:38 +0000414 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STFD))
Bill Wendling2b739762009-05-13 21:33:08 +0000415 .addReg(SrcReg,
416 getKillRegState(isKill)),
417 FrameIdx));
Owen Anderson81875432008-01-01 21:11:32 +0000418 } else if (RC == PPC::F4RCRegisterClass) {
Dale Johannesen77cce4d2009-02-12 23:08:38 +0000419 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STFS))
Bill Wendling2b739762009-05-13 21:33:08 +0000420 .addReg(SrcReg,
421 getKillRegState(isKill)),
422 FrameIdx));
Owen Anderson81875432008-01-01 21:11:32 +0000423 } else if (RC == PPC::CRRCRegisterClass) {
Bill Wendling4eaadfb2008-03-10 22:49:16 +0000424 if ((EnablePPC32RS && !TM.getSubtargetImpl()->isPPC64()) ||
425 (EnablePPC64RS && TM.getSubtargetImpl()->isPPC64())) {
426 // FIXME (64-bit): Enable
Dale Johannesen77cce4d2009-02-12 23:08:38 +0000427 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::SPILL_CR))
Bill Wendling2b739762009-05-13 21:33:08 +0000428 .addReg(SrcReg,
429 getKillRegState(isKill)),
Chris Lattner6734c3a2008-03-20 01:22:40 +0000430 FrameIdx));
Bill Wendlinga1877c52008-03-03 22:19:16 +0000431 return true;
432 } else {
Dale Johannesenb000c482010-02-12 21:35:34 +0000433 // FIXME: We need a scatch reg here. The trouble with using R0 is that
434 // it's possible for the stack frame to be so big the save location is
435 // out of range of immediate offsets, necessitating another register.
436 // We hack this on Darwin by reserving R2. It's probably broken on Linux
437 // at the moment.
438
439 // We need to store the CR in the low 4-bits of the saved value. First,
440 // issue a MFCR to save all of the CRBits.
441 unsigned ScratchReg = TM.getSubtargetImpl()->isDarwinABI() ?
442 PPC::R2 : PPC::R0;
Dale Johannesen8052a182010-05-20 17:48:26 +0000443 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MFCRpseud), ScratchReg)
444 .addReg(SrcReg, getKillRegState(isKill)));
Owen Anderson81875432008-01-01 21:11:32 +0000445
Bill Wendlinga1877c52008-03-03 22:19:16 +0000446 // If the saved register wasn't CR0, shift the bits left so that they are
447 // in CR0's slot.
448 if (SrcReg != PPC::CR0) {
449 unsigned ShiftBits = PPCRegisterInfo::getRegisterNumbering(SrcReg)*4;
Dale Johannesenb000c482010-02-12 21:35:34 +0000450 // rlwinm scratch, scratch, ShiftBits, 0, 31.
451 NewMIs.push_back(BuildMI(MF, DL, get(PPC::RLWINM), ScratchReg)
452 .addReg(ScratchReg).addImm(ShiftBits)
453 .addImm(0).addImm(31));
Bill Wendlinga1877c52008-03-03 22:19:16 +0000454 }
455
Dale Johannesen77cce4d2009-02-12 23:08:38 +0000456 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STW))
Dale Johannesenb000c482010-02-12 21:35:34 +0000457 .addReg(ScratchReg,
Bill Wendling2b739762009-05-13 21:33:08 +0000458 getKillRegState(isKill)),
Bill Wendlinga1877c52008-03-03 22:19:16 +0000459 FrameIdx));
Owen Anderson81875432008-01-01 21:11:32 +0000460 }
Nicolas Geoffrayd01feb22008-03-10 14:12:10 +0000461 } else if (RC == PPC::CRBITRCRegisterClass) {
462 // FIXME: We use CRi here because there is no mtcrf on a bit. Since the
463 // backend currently only uses CR1EQ as an individual bit, this should
464 // not cause any bug. If we need other uses of CR bits, the following
465 // code may be invalid.
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000466 unsigned Reg = 0;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000467 if (SrcReg == PPC::CR0LT || SrcReg == PPC::CR0GT ||
468 SrcReg == PPC::CR0EQ || SrcReg == PPC::CR0UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000469 Reg = PPC::CR0;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000470 else if (SrcReg == PPC::CR1LT || SrcReg == PPC::CR1GT ||
471 SrcReg == PPC::CR1EQ || SrcReg == PPC::CR1UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000472 Reg = PPC::CR1;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000473 else if (SrcReg == PPC::CR2LT || SrcReg == PPC::CR2GT ||
474 SrcReg == PPC::CR2EQ || SrcReg == PPC::CR2UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000475 Reg = PPC::CR2;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000476 else if (SrcReg == PPC::CR3LT || SrcReg == PPC::CR3GT ||
477 SrcReg == PPC::CR3EQ || SrcReg == PPC::CR3UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000478 Reg = PPC::CR3;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000479 else if (SrcReg == PPC::CR4LT || SrcReg == PPC::CR4GT ||
480 SrcReg == PPC::CR4EQ || SrcReg == PPC::CR4UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000481 Reg = PPC::CR4;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000482 else if (SrcReg == PPC::CR5LT || SrcReg == PPC::CR5GT ||
483 SrcReg == PPC::CR5EQ || SrcReg == PPC::CR5UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000484 Reg = PPC::CR5;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000485 else if (SrcReg == PPC::CR6LT || SrcReg == PPC::CR6GT ||
486 SrcReg == PPC::CR6EQ || SrcReg == PPC::CR6UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000487 Reg = PPC::CR6;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000488 else if (SrcReg == PPC::CR7LT || SrcReg == PPC::CR7GT ||
489 SrcReg == PPC::CR7EQ || SrcReg == PPC::CR7UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000490 Reg = PPC::CR7;
491
Dan Gohman221a4372008-07-07 23:14:23 +0000492 return StoreRegToStackSlot(MF, Reg, isKill, FrameIdx,
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000493 PPC::CRRCRegisterClass, NewMIs);
494
Owen Anderson81875432008-01-01 21:11:32 +0000495 } else if (RC == PPC::VRRCRegisterClass) {
496 // We don't have indexed addressing for vector loads. Emit:
497 // R0 = ADDI FI#
498 // STVX VAL, 0, R0
499 //
500 // FIXME: We use R0 here, because it isn't available for RA.
Dale Johannesen77cce4d2009-02-12 23:08:38 +0000501 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::ADDI), PPC::R0),
Owen Anderson81875432008-01-01 21:11:32 +0000502 FrameIdx, 0, 0));
Dale Johannesen77cce4d2009-02-12 23:08:38 +0000503 NewMIs.push_back(BuildMI(MF, DL, get(PPC::STVX))
Bill Wendling2b739762009-05-13 21:33:08 +0000504 .addReg(SrcReg, getKillRegState(isKill))
505 .addReg(PPC::R0)
506 .addReg(PPC::R0));
Owen Anderson81875432008-01-01 21:11:32 +0000507 } else {
Edwin Törökbd448e32009-07-14 16:55:14 +0000508 llvm_unreachable("Unknown regclass!");
Owen Anderson81875432008-01-01 21:11:32 +0000509 }
Bill Wendlinga1877c52008-03-03 22:19:16 +0000510
511 return false;
Owen Anderson81875432008-01-01 21:11:32 +0000512}
513
514void
515PPCInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
Bill Wendlinga1877c52008-03-03 22:19:16 +0000516 MachineBasicBlock::iterator MI,
517 unsigned SrcReg, bool isKill, int FrameIdx,
Evan Cheng1f8534d2010-05-06 19:06:44 +0000518 const TargetRegisterClass *RC,
519 const TargetRegisterInfo *TRI) const {
Dan Gohman221a4372008-07-07 23:14:23 +0000520 MachineFunction &MF = *MBB.getParent();
Owen Anderson81875432008-01-01 21:11:32 +0000521 SmallVector<MachineInstr*, 4> NewMIs;
Bill Wendlinga1877c52008-03-03 22:19:16 +0000522
Dan Gohman221a4372008-07-07 23:14:23 +0000523 if (StoreRegToStackSlot(MF, SrcReg, isKill, FrameIdx, RC, NewMIs)) {
524 PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
Bill Wendlinga1877c52008-03-03 22:19:16 +0000525 FuncInfo->setSpillsCR();
526 }
527
Owen Anderson81875432008-01-01 21:11:32 +0000528 for (unsigned i = 0, e = NewMIs.size(); i != e; ++i)
529 MBB.insert(MI, NewMIs[i]);
Jakob Stoklund Olesen18275a42010-07-16 18:22:00 +0000530
531 const MachineFrameInfo &MFI = *MF.getFrameInfo();
532 MachineMemOperand *MMO =
533 MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FrameIdx),
534 MachineMemOperand::MOStore, /*Offset=*/0,
535 MFI.getObjectSize(FrameIdx),
536 MFI.getObjectAlignment(FrameIdx));
537 NewMIs.back()->addMemOperand(MF, MMO);
Owen Anderson81875432008-01-01 21:11:32 +0000538}
539
Bill Wendling4eaadfb2008-03-10 22:49:16 +0000540void
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000541PPCInstrInfo::LoadRegFromStackSlot(MachineFunction &MF, DebugLoc DL,
Dan Gohman221a4372008-07-07 23:14:23 +0000542 unsigned DestReg, int FrameIdx,
Bill Wendling4eaadfb2008-03-10 22:49:16 +0000543 const TargetRegisterClass *RC,
544 SmallVectorImpl<MachineInstr*> &NewMIs)const{
Owen Anderson81875432008-01-01 21:11:32 +0000545 if (RC == PPC::GPRCRegisterClass) {
546 if (DestReg != PPC::LR) {
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000547 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LWZ),
548 DestReg), FrameIdx));
Owen Anderson81875432008-01-01 21:11:32 +0000549 } else {
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000550 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LWZ),
551 PPC::R11), FrameIdx));
552 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MTLR)).addReg(PPC::R11));
Owen Anderson81875432008-01-01 21:11:32 +0000553 }
554 } else if (RC == PPC::G8RCRegisterClass) {
555 if (DestReg != PPC::LR8) {
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000556 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LD), DestReg),
Owen Anderson81875432008-01-01 21:11:32 +0000557 FrameIdx));
558 } else {
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000559 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LD),
560 PPC::R11), FrameIdx));
561 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MTLR8)).addReg(PPC::R11));
Owen Anderson81875432008-01-01 21:11:32 +0000562 }
563 } else if (RC == PPC::F8RCRegisterClass) {
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000564 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LFD), DestReg),
Owen Anderson81875432008-01-01 21:11:32 +0000565 FrameIdx));
566 } else if (RC == PPC::F4RCRegisterClass) {
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000567 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LFS), DestReg),
Owen Anderson81875432008-01-01 21:11:32 +0000568 FrameIdx));
569 } else if (RC == PPC::CRRCRegisterClass) {
Dale Johannesenb000c482010-02-12 21:35:34 +0000570 // FIXME: We need a scatch reg here. The trouble with using R0 is that
571 // it's possible for the stack frame to be so big the save location is
572 // out of range of immediate offsets, necessitating another register.
573 // We hack this on Darwin by reserving R2. It's probably broken on Linux
574 // at the moment.
575 unsigned ScratchReg = TM.getSubtargetImpl()->isDarwinABI() ?
576 PPC::R2 : PPC::R0;
577 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LWZ),
578 ScratchReg), FrameIdx));
Owen Anderson81875432008-01-01 21:11:32 +0000579
580 // If the reloaded register isn't CR0, shift the bits right so that they are
581 // in the right CR's slot.
582 if (DestReg != PPC::CR0) {
583 unsigned ShiftBits = PPCRegisterInfo::getRegisterNumbering(DestReg)*4;
584 // rlwinm r11, r11, 32-ShiftBits, 0, 31.
Dale Johannesenb000c482010-02-12 21:35:34 +0000585 NewMIs.push_back(BuildMI(MF, DL, get(PPC::RLWINM), ScratchReg)
586 .addReg(ScratchReg).addImm(32-ShiftBits).addImm(0)
587 .addImm(31));
Owen Anderson81875432008-01-01 21:11:32 +0000588 }
589
Dale Johannesenb000c482010-02-12 21:35:34 +0000590 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MTCRF), DestReg)
591 .addReg(ScratchReg));
Nicolas Geoffrayd01feb22008-03-10 14:12:10 +0000592 } else if (RC == PPC::CRBITRCRegisterClass) {
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000593
594 unsigned Reg = 0;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000595 if (DestReg == PPC::CR0LT || DestReg == PPC::CR0GT ||
596 DestReg == PPC::CR0EQ || DestReg == PPC::CR0UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000597 Reg = PPC::CR0;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000598 else if (DestReg == PPC::CR1LT || DestReg == PPC::CR1GT ||
599 DestReg == PPC::CR1EQ || DestReg == PPC::CR1UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000600 Reg = PPC::CR1;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000601 else if (DestReg == PPC::CR2LT || DestReg == PPC::CR2GT ||
602 DestReg == PPC::CR2EQ || DestReg == PPC::CR2UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000603 Reg = PPC::CR2;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000604 else if (DestReg == PPC::CR3LT || DestReg == PPC::CR3GT ||
605 DestReg == PPC::CR3EQ || DestReg == PPC::CR3UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000606 Reg = PPC::CR3;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000607 else if (DestReg == PPC::CR4LT || DestReg == PPC::CR4GT ||
608 DestReg == PPC::CR4EQ || DestReg == PPC::CR4UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000609 Reg = PPC::CR4;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000610 else if (DestReg == PPC::CR5LT || DestReg == PPC::CR5GT ||
611 DestReg == PPC::CR5EQ || DestReg == PPC::CR5UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000612 Reg = PPC::CR5;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000613 else if (DestReg == PPC::CR6LT || DestReg == PPC::CR6GT ||
614 DestReg == PPC::CR6EQ || DestReg == PPC::CR6UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000615 Reg = PPC::CR6;
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000616 else if (DestReg == PPC::CR7LT || DestReg == PPC::CR7GT ||
617 DestReg == PPC::CR7EQ || DestReg == PPC::CR7UN)
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000618 Reg = PPC::CR7;
619
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000620 return LoadRegFromStackSlot(MF, DL, Reg, FrameIdx,
Nicolas Geoffray51ed7a32008-03-10 17:46:45 +0000621 PPC::CRRCRegisterClass, NewMIs);
622
Owen Anderson81875432008-01-01 21:11:32 +0000623 } else if (RC == PPC::VRRCRegisterClass) {
624 // We don't have indexed addressing for vector loads. Emit:
625 // R0 = ADDI FI#
626 // Dest = LVX 0, R0
627 //
628 // FIXME: We use R0 here, because it isn't available for RA.
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000629 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::ADDI), PPC::R0),
Owen Anderson81875432008-01-01 21:11:32 +0000630 FrameIdx, 0, 0));
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000631 NewMIs.push_back(BuildMI(MF, DL, get(PPC::LVX),DestReg).addReg(PPC::R0)
Owen Anderson81875432008-01-01 21:11:32 +0000632 .addReg(PPC::R0));
633 } else {
Edwin Törökbd448e32009-07-14 16:55:14 +0000634 llvm_unreachable("Unknown regclass!");
Owen Anderson81875432008-01-01 21:11:32 +0000635 }
636}
637
638void
639PPCInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
Bill Wendlinga1877c52008-03-03 22:19:16 +0000640 MachineBasicBlock::iterator MI,
641 unsigned DestReg, int FrameIdx,
Evan Cheng1f8534d2010-05-06 19:06:44 +0000642 const TargetRegisterClass *RC,
643 const TargetRegisterInfo *TRI) const {
Dan Gohman221a4372008-07-07 23:14:23 +0000644 MachineFunction &MF = *MBB.getParent();
Owen Anderson81875432008-01-01 21:11:32 +0000645 SmallVector<MachineInstr*, 4> NewMIs;
Chris Lattnerd2c680b2010-04-02 20:16:16 +0000646 DebugLoc DL;
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000647 if (MI != MBB.end()) DL = MI->getDebugLoc();
648 LoadRegFromStackSlot(MF, DL, DestReg, FrameIdx, RC, NewMIs);
Owen Anderson81875432008-01-01 21:11:32 +0000649 for (unsigned i = 0, e = NewMIs.size(); i != e; ++i)
650 MBB.insert(MI, NewMIs[i]);
Jakob Stoklund Olesen18275a42010-07-16 18:22:00 +0000651
652 const MachineFrameInfo &MFI = *MF.getFrameInfo();
653 MachineMemOperand *MMO =
654 MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FrameIdx),
655 MachineMemOperand::MOLoad, /*Offset=*/0,
656 MFI.getObjectSize(FrameIdx),
657 MFI.getObjectAlignment(FrameIdx));
658 NewMIs.back()->addMemOperand(MF, MMO);
Owen Anderson81875432008-01-01 21:11:32 +0000659}
660
Evan Cheng284da772010-04-26 07:39:36 +0000661MachineInstr*
662PPCInstrInfo::emitFrameIndexDebugValue(MachineFunction &MF,
Evan Chengf9c420a2010-04-29 01:13:30 +0000663 int FrameIx, uint64_t Offset,
Evan Cheng284da772010-04-26 07:39:36 +0000664 const MDNode *MDPtr,
665 DebugLoc DL) const {
666 MachineInstrBuilder MIB = BuildMI(MF, DL, get(PPC::DBG_VALUE));
667 addFrameReference(MIB, FrameIx, 0, false).addImm(Offset).addMetadata(MDPtr);
668 return &*MIB;
669}
670
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000671bool PPCInstrInfo::
Owen Andersond131b5b2008-08-14 22:49:33 +0000672ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000673 assert(Cond.size() == 2 && "Invalid PPC branch opcode!");
674 // Leave the CR# the same, but invert the condition.
675 Cond[0].setImm(PPC::InvertPredicate((PPC::Predicate)Cond[0].getImm()));
676 return false;
677}
Nicolas Geoffraycb162a02008-04-16 20:10:13 +0000678
679/// GetInstSize - Return the number of bytes of code the specified
680/// instruction may be. This returns the maximum number of bytes.
681///
682unsigned PPCInstrInfo::GetInstSizeInBytes(const MachineInstr *MI) const {
683 switch (MI->getOpcode()) {
684 case PPC::INLINEASM: { // Inline Asm: Variable size.
685 const MachineFunction *MF = MI->getParent()->getParent();
686 const char *AsmStr = MI->getOperand(0).getSymbolName();
Chris Lattner621c44d2009-08-22 20:48:53 +0000687 return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
Nicolas Geoffraycb162a02008-04-16 20:10:13 +0000688 }
Bill Wendlinga02effc2010-07-16 22:20:36 +0000689 case PPC::PROLOG_LABEL:
Dan Gohmanfa607c92008-07-01 00:05:16 +0000690 case PPC::EH_LABEL:
691 case PPC::GC_LABEL:
Dale Johannesenac548972010-04-07 19:51:44 +0000692 case PPC::DBG_VALUE:
Nicolas Geoffraycb162a02008-04-16 20:10:13 +0000693 return 0;
Nicolas Geoffraycb162a02008-04-16 20:10:13 +0000694 default:
695 return 4; // PowerPC instructions are all 4 bytes
696 }
697}