1 //===- PPCInstrInfo.cpp - PowerPC32 Instruction Information -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the PowerPC implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
14 #include "PPCInstrInfo.h"
16 #include "PPCInstrBuilder.h"
17 #include "PPCMachineFunctionInfo.h"
18 #include "PPCPredicates.h"
19 #include "PPCTargetMachine.h"
20 #include "PPCHazardRecognizers.h"
21 #include "llvm/CodeGen/MachineFrameInfo.h"
22 #include "llvm/CodeGen/MachineInstrBuilder.h"
23 #include "llvm/CodeGen/MachineMemOperand.h"
24 #include "llvm/CodeGen/MachineRegisterInfo.h"
25 #include "llvm/CodeGen/PseudoSourceValue.h"
26 #include "llvm/MC/MCAsmInfo.h"
27 #include "llvm/Target/TargetRegistry.h"
28 #include "llvm/Support/CommandLine.h"
29 #include "llvm/Support/ErrorHandling.h"
30 #include "llvm/Support/raw_ostream.h"
31 #include "llvm/ADT/STLExtras.h"
33 #define GET_INSTRINFO_CTOR
34 #define GET_INSTRINFO_MC_DESC
35 #include "PPCGenInstrInfo.inc"
38 extern cl::opt<bool> EnablePPC32RS; // FIXME (64-bit): See PPCRegisterInfo.cpp.
39 extern cl::opt<bool> EnablePPC64RS; // FIXME (64-bit): See PPCRegisterInfo.cpp.
44 PPCInstrInfo::PPCInstrInfo(PPCTargetMachine &tm)
45 : PPCGenInstrInfo(PPC::ADJCALLSTACKDOWN, PPC::ADJCALLSTACKUP),
46 TM(tm), RI(*TM.getSubtargetImpl(), *this) {}
48 /// CreateTargetHazardRecognizer - Return the hazard recognizer to use for
49 /// this target when scheduling the DAG.
50 ScheduleHazardRecognizer *PPCInstrInfo::CreateTargetHazardRecognizer(
51 const TargetMachine *TM,
52 const ScheduleDAG *DAG) const {
53 // Should use subtarget info to pick the right hazard recognizer. For
54 // now, always return a PPC970 recognizer.
55 const TargetInstrInfo *TII = TM->getInstrInfo();
56 assert(TII && "No InstrInfo?");
57 return new PPCHazardRecognizer970(*TII);
60 unsigned PPCInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
61 int &FrameIndex) const {
62 switch (MI->getOpcode()) {
68 if (MI->getOperand(1).isImm() && !MI->getOperand(1).getImm() &&
69 MI->getOperand(2).isFI()) {
70 FrameIndex = MI->getOperand(2).getIndex();
71 return MI->getOperand(0).getReg();
78 unsigned PPCInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
79 int &FrameIndex) const {
80 switch (MI->getOpcode()) {
86 if (MI->getOperand(1).isImm() && !MI->getOperand(1).getImm() &&
87 MI->getOperand(2).isFI()) {
88 FrameIndex = MI->getOperand(2).getIndex();
89 return MI->getOperand(0).getReg();
96 // commuteInstruction - We can commute rlwimi instructions, but only if the
97 // rotate amt is zero. We also have to munge the immediates a bit.
99 PPCInstrInfo::commuteInstruction(MachineInstr *MI, bool NewMI) const {
100 MachineFunction &MF = *MI->getParent()->getParent();
102 // Normal instructions can be commuted the obvious way.
103 if (MI->getOpcode() != PPC::RLWIMI)
104 return TargetInstrInfoImpl::commuteInstruction(MI, NewMI);
106 // Cannot commute if it has a non-zero rotate count.
107 if (MI->getOperand(3).getImm() != 0)
110 // If we have a zero rotate count, we have:
112 // Op0 = (Op1 & ~M) | (Op2 & M)
114 // M = mask((ME+1)&31, (MB-1)&31)
115 // Op0 = (Op2 & ~M) | (Op1 & M)
118 unsigned Reg0 = MI->getOperand(0).getReg();
119 unsigned Reg1 = MI->getOperand(1).getReg();
120 unsigned Reg2 = MI->getOperand(2).getReg();
121 bool Reg1IsKill = MI->getOperand(1).isKill();
122 bool Reg2IsKill = MI->getOperand(2).isKill();
123 bool ChangeReg0 = false;
124 // If machine instrs are no longer in two-address forms, update
125 // destination register as well.
127 // Must be two address instruction!
128 assert(MI->getDesc().getOperandConstraint(0, MCOI::TIED_TO) &&
129 "Expecting a two-address instruction!");
135 unsigned MB = MI->getOperand(4).getImm();
136 unsigned ME = MI->getOperand(5).getImm();
139 // Create a new instruction.
140 unsigned Reg0 = ChangeReg0 ? Reg2 : MI->getOperand(0).getReg();
141 bool Reg0IsDead = MI->getOperand(0).isDead();
142 return BuildMI(MF, MI->getDebugLoc(), MI->getDesc())
143 .addReg(Reg0, RegState::Define | getDeadRegState(Reg0IsDead))
144 .addReg(Reg2, getKillRegState(Reg2IsKill))
145 .addReg(Reg1, getKillRegState(Reg1IsKill))
147 .addImm((MB-1) & 31);
151 MI->getOperand(0).setReg(Reg2);
152 MI->getOperand(2).setReg(Reg1);
153 MI->getOperand(1).setReg(Reg2);
154 MI->getOperand(2).setIsKill(Reg1IsKill);
155 MI->getOperand(1).setIsKill(Reg2IsKill);
157 // Swap the mask around.
158 MI->getOperand(4).setImm((ME+1) & 31);
159 MI->getOperand(5).setImm((MB-1) & 31);
163 void PPCInstrInfo::insertNoop(MachineBasicBlock &MBB,
164 MachineBasicBlock::iterator MI) const {
166 BuildMI(MBB, MI, DL, get(PPC::NOP));
171 bool PPCInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
172 MachineBasicBlock *&FBB,
173 SmallVectorImpl<MachineOperand> &Cond,
174 bool AllowModify) const {
175 // If the block has no terminators, it just falls into the block after it.
176 MachineBasicBlock::iterator I = MBB.end();
177 if (I == MBB.begin())
180 while (I->isDebugValue()) {
181 if (I == MBB.begin())
185 if (!isUnpredicatedTerminator(I))
188 // Get the last instruction in the block.
189 MachineInstr *LastInst = I;
191 // If there is only one terminator instruction, process it.
192 if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
193 if (LastInst->getOpcode() == PPC::B) {
194 if (!LastInst->getOperand(0).isMBB())
196 TBB = LastInst->getOperand(0).getMBB();
198 } else if (LastInst->getOpcode() == PPC::BCC) {
199 if (!LastInst->getOperand(2).isMBB())
201 // Block ends with fall-through condbranch.
202 TBB = LastInst->getOperand(2).getMBB();
203 Cond.push_back(LastInst->getOperand(0));
204 Cond.push_back(LastInst->getOperand(1));
207 // Otherwise, don't know what this is.
211 // Get the instruction before it if it's a terminator.
212 MachineInstr *SecondLastInst = I;
214 // If there are three terminators, we don't know what sort of block this is.
215 if (SecondLastInst && I != MBB.begin() &&
216 isUnpredicatedTerminator(--I))
219 // If the block ends with PPC::B and PPC:BCC, handle it.
220 if (SecondLastInst->getOpcode() == PPC::BCC &&
221 LastInst->getOpcode() == PPC::B) {
222 if (!SecondLastInst->getOperand(2).isMBB() ||
223 !LastInst->getOperand(0).isMBB())
225 TBB = SecondLastInst->getOperand(2).getMBB();
226 Cond.push_back(SecondLastInst->getOperand(0));
227 Cond.push_back(SecondLastInst->getOperand(1));
228 FBB = LastInst->getOperand(0).getMBB();
232 // If the block ends with two PPC:Bs, handle it. The second one is not
233 // executed, so remove it.
234 if (SecondLastInst->getOpcode() == PPC::B &&
235 LastInst->getOpcode() == PPC::B) {
236 if (!SecondLastInst->getOperand(0).isMBB())
238 TBB = SecondLastInst->getOperand(0).getMBB();
241 I->eraseFromParent();
245 // Otherwise, can't handle this.
249 unsigned PPCInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
250 MachineBasicBlock::iterator I = MBB.end();
251 if (I == MBB.begin()) return 0;
253 while (I->isDebugValue()) {
254 if (I == MBB.begin())
258 if (I->getOpcode() != PPC::B && I->getOpcode() != PPC::BCC)
261 // Remove the branch.
262 I->eraseFromParent();
266 if (I == MBB.begin()) return 1;
268 if (I->getOpcode() != PPC::BCC)
271 // Remove the branch.
272 I->eraseFromParent();
277 PPCInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
278 MachineBasicBlock *FBB,
279 const SmallVectorImpl<MachineOperand> &Cond,
281 // Shouldn't be a fall through.
282 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
283 assert((Cond.size() == 2 || Cond.size() == 0) &&
284 "PPC branch conditions have two components!");
288 if (Cond.empty()) // Unconditional branch
289 BuildMI(&MBB, DL, get(PPC::B)).addMBB(TBB);
290 else // Conditional branch
291 BuildMI(&MBB, DL, get(PPC::BCC))
292 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
296 // Two-way Conditional Branch.
297 BuildMI(&MBB, DL, get(PPC::BCC))
298 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
299 BuildMI(&MBB, DL, get(PPC::B)).addMBB(FBB);
303 void PPCInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
304 MachineBasicBlock::iterator I, DebugLoc DL,
305 unsigned DestReg, unsigned SrcReg,
306 bool KillSrc) const {
308 if (PPC::GPRCRegClass.contains(DestReg, SrcReg))
310 else if (PPC::G8RCRegClass.contains(DestReg, SrcReg))
312 else if (PPC::F4RCRegClass.contains(DestReg, SrcReg))
314 else if (PPC::CRRCRegClass.contains(DestReg, SrcReg))
316 else if (PPC::VRRCRegClass.contains(DestReg, SrcReg))
318 else if (PPC::CRBITRCRegClass.contains(DestReg, SrcReg))
321 llvm_unreachable("Impossible reg-to-reg copy");
323 const MCInstrDesc &MCID = get(Opc);
324 if (MCID.getNumOperands() == 3)
325 BuildMI(MBB, I, DL, MCID, DestReg)
326 .addReg(SrcReg).addReg(SrcReg, getKillRegState(KillSrc));
328 BuildMI(MBB, I, DL, MCID, DestReg).addReg(SrcReg, getKillRegState(KillSrc));
332 PPCInstrInfo::StoreRegToStackSlot(MachineFunction &MF,
333 unsigned SrcReg, bool isKill,
335 const TargetRegisterClass *RC,
336 SmallVectorImpl<MachineInstr*> &NewMIs) const{
338 if (RC == PPC::GPRCRegisterClass) {
339 if (SrcReg != PPC::LR) {
340 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STW))
342 getKillRegState(isKill)),
345 // FIXME: this spills LR immediately to memory in one step. To do this,
346 // we use R11, which we know cannot be used in the prolog/epilog. This is
348 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MFLR), PPC::R11));
349 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STW))
351 getKillRegState(isKill)),
354 } else if (RC == PPC::G8RCRegisterClass) {
355 if (SrcReg != PPC::LR8) {
356 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STD))
358 getKillRegState(isKill)),
361 // FIXME: this spills LR immediately to memory in one step. To do this,
362 // we use R11, which we know cannot be used in the prolog/epilog. This is
364 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MFLR8), PPC::X11));
365 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STD))
367 getKillRegState(isKill)),
370 } else if (RC == PPC::F8RCRegisterClass) {
371 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STFD))
373 getKillRegState(isKill)),
375 } else if (RC == PPC::F4RCRegisterClass) {
376 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STFS))
378 getKillRegState(isKill)),
380 } else if (RC == PPC::CRRCRegisterClass) {
381 if ((EnablePPC32RS && !TM.getSubtargetImpl()->isPPC64()) ||
382 (EnablePPC64RS && TM.getSubtargetImpl()->isPPC64())) {
383 // FIXME (64-bit): Enable
384 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::SPILL_CR))
386 getKillRegState(isKill)),
390 // FIXME: We need a scatch reg here. The trouble with using R0 is that
391 // it's possible for the stack frame to be so big the save location is
392 // out of range of immediate offsets, necessitating another register.
393 // We hack this on Darwin by reserving R2. It's probably broken on Linux
396 // We need to store the CR in the low 4-bits of the saved value. First,
397 // issue a MFCR to save all of the CRBits.
398 unsigned ScratchReg = TM.getSubtargetImpl()->isDarwinABI() ?
400 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MFCRpseud), ScratchReg)
401 .addReg(SrcReg, getKillRegState(isKill)));
403 // If the saved register wasn't CR0, shift the bits left so that they are
405 if (SrcReg != PPC::CR0) {
406 unsigned ShiftBits = PPCRegisterInfo::getRegisterNumbering(SrcReg)*4;
407 // rlwinm scratch, scratch, ShiftBits, 0, 31.
408 NewMIs.push_back(BuildMI(MF, DL, get(PPC::RLWINM), ScratchReg)
409 .addReg(ScratchReg).addImm(ShiftBits)
410 .addImm(0).addImm(31));
413 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STW))
415 getKillRegState(isKill)),
418 } else if (RC == PPC::CRBITRCRegisterClass) {
419 // FIXME: We use CRi here because there is no mtcrf on a bit. Since the
420 // backend currently only uses CR1EQ as an individual bit, this should
421 // not cause any bug. If we need other uses of CR bits, the following
422 // code may be invalid.
424 if (SrcReg == PPC::CR0LT || SrcReg == PPC::CR0GT ||
425 SrcReg == PPC::CR0EQ || SrcReg == PPC::CR0UN)
427 else if (SrcReg == PPC::CR1LT || SrcReg == PPC::CR1GT ||
428 SrcReg == PPC::CR1EQ || SrcReg == PPC::CR1UN)
430 else if (SrcReg == PPC::CR2LT || SrcReg == PPC::CR2GT ||
431 SrcReg == PPC::CR2EQ || SrcReg == PPC::CR2UN)
433 else if (SrcReg == PPC::CR3LT || SrcReg == PPC::CR3GT ||
434 SrcReg == PPC::CR3EQ || SrcReg == PPC::CR3UN)
436 else if (SrcReg == PPC::CR4LT || SrcReg == PPC::CR4GT ||
437 SrcReg == PPC::CR4EQ || SrcReg == PPC::CR4UN)
439 else if (SrcReg == PPC::CR5LT || SrcReg == PPC::CR5GT ||
440 SrcReg == PPC::CR5EQ || SrcReg == PPC::CR5UN)
442 else if (SrcReg == PPC::CR6LT || SrcReg == PPC::CR6GT ||
443 SrcReg == PPC::CR6EQ || SrcReg == PPC::CR6UN)
445 else if (SrcReg == PPC::CR7LT || SrcReg == PPC::CR7GT ||
446 SrcReg == PPC::CR7EQ || SrcReg == PPC::CR7UN)
449 return StoreRegToStackSlot(MF, Reg, isKill, FrameIdx,
450 PPC::CRRCRegisterClass, NewMIs);
452 } else if (RC == PPC::VRRCRegisterClass) {
453 // We don't have indexed addressing for vector loads. Emit:
457 // FIXME: We use R0 here, because it isn't available for RA.
458 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::ADDI), PPC::R0),
460 NewMIs.push_back(BuildMI(MF, DL, get(PPC::STVX))
461 .addReg(SrcReg, getKillRegState(isKill))
465 llvm_unreachable("Unknown regclass!");
472 PPCInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
473 MachineBasicBlock::iterator MI,
474 unsigned SrcReg, bool isKill, int FrameIdx,
475 const TargetRegisterClass *RC,
476 const TargetRegisterInfo *TRI) const {
477 MachineFunction &MF = *MBB.getParent();
478 SmallVector<MachineInstr*, 4> NewMIs;
480 if (StoreRegToStackSlot(MF, SrcReg, isKill, FrameIdx, RC, NewMIs)) {
481 PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
482 FuncInfo->setSpillsCR();
485 for (unsigned i = 0, e = NewMIs.size(); i != e; ++i)
486 MBB.insert(MI, NewMIs[i]);
488 const MachineFrameInfo &MFI = *MF.getFrameInfo();
489 MachineMemOperand *MMO =
490 MF.getMachineMemOperand(
491 MachinePointerInfo(PseudoSourceValue::getFixedStack(FrameIdx)),
492 MachineMemOperand::MOStore,
493 MFI.getObjectSize(FrameIdx),
494 MFI.getObjectAlignment(FrameIdx));
495 NewMIs.back()->addMemOperand(MF, MMO);
499 PPCInstrInfo::LoadRegFromStackSlot(MachineFunction &MF, DebugLoc DL,
500 unsigned DestReg, int FrameIdx,
501 const TargetRegisterClass *RC,
502 SmallVectorImpl<MachineInstr*> &NewMIs)const{
503 if (RC == PPC::GPRCRegisterClass) {
504 if (DestReg != PPC::LR) {
505 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LWZ),
506 DestReg), FrameIdx));
508 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LWZ),
509 PPC::R11), FrameIdx));
510 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MTLR)).addReg(PPC::R11));
512 } else if (RC == PPC::G8RCRegisterClass) {
513 if (DestReg != PPC::LR8) {
514 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LD), DestReg),
517 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LD),
518 PPC::R11), FrameIdx));
519 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MTLR8)).addReg(PPC::R11));
521 } else if (RC == PPC::F8RCRegisterClass) {
522 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LFD), DestReg),
524 } else if (RC == PPC::F4RCRegisterClass) {
525 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LFS), DestReg),
527 } else if (RC == PPC::CRRCRegisterClass) {
528 // FIXME: We need a scatch reg here. The trouble with using R0 is that
529 // it's possible for the stack frame to be so big the save location is
530 // out of range of immediate offsets, necessitating another register.
531 // We hack this on Darwin by reserving R2. It's probably broken on Linux
533 unsigned ScratchReg = TM.getSubtargetImpl()->isDarwinABI() ?
535 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LWZ),
536 ScratchReg), FrameIdx));
538 // If the reloaded register isn't CR0, shift the bits right so that they are
539 // in the right CR's slot.
540 if (DestReg != PPC::CR0) {
541 unsigned ShiftBits = PPCRegisterInfo::getRegisterNumbering(DestReg)*4;
542 // rlwinm r11, r11, 32-ShiftBits, 0, 31.
543 NewMIs.push_back(BuildMI(MF, DL, get(PPC::RLWINM), ScratchReg)
544 .addReg(ScratchReg).addImm(32-ShiftBits).addImm(0)
548 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MTCRF), DestReg)
549 .addReg(ScratchReg));
550 } else if (RC == PPC::CRBITRCRegisterClass) {
553 if (DestReg == PPC::CR0LT || DestReg == PPC::CR0GT ||
554 DestReg == PPC::CR0EQ || DestReg == PPC::CR0UN)
556 else if (DestReg == PPC::CR1LT || DestReg == PPC::CR1GT ||
557 DestReg == PPC::CR1EQ || DestReg == PPC::CR1UN)
559 else if (DestReg == PPC::CR2LT || DestReg == PPC::CR2GT ||
560 DestReg == PPC::CR2EQ || DestReg == PPC::CR2UN)
562 else if (DestReg == PPC::CR3LT || DestReg == PPC::CR3GT ||
563 DestReg == PPC::CR3EQ || DestReg == PPC::CR3UN)
565 else if (DestReg == PPC::CR4LT || DestReg == PPC::CR4GT ||
566 DestReg == PPC::CR4EQ || DestReg == PPC::CR4UN)
568 else if (DestReg == PPC::CR5LT || DestReg == PPC::CR5GT ||
569 DestReg == PPC::CR5EQ || DestReg == PPC::CR5UN)
571 else if (DestReg == PPC::CR6LT || DestReg == PPC::CR6GT ||
572 DestReg == PPC::CR6EQ || DestReg == PPC::CR6UN)
574 else if (DestReg == PPC::CR7LT || DestReg == PPC::CR7GT ||
575 DestReg == PPC::CR7EQ || DestReg == PPC::CR7UN)
578 return LoadRegFromStackSlot(MF, DL, Reg, FrameIdx,
579 PPC::CRRCRegisterClass, NewMIs);
581 } else if (RC == PPC::VRRCRegisterClass) {
582 // We don't have indexed addressing for vector loads. Emit:
586 // FIXME: We use R0 here, because it isn't available for RA.
587 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::ADDI), PPC::R0),
589 NewMIs.push_back(BuildMI(MF, DL, get(PPC::LVX),DestReg).addReg(PPC::R0)
592 llvm_unreachable("Unknown regclass!");
597 PPCInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
598 MachineBasicBlock::iterator MI,
599 unsigned DestReg, int FrameIdx,
600 const TargetRegisterClass *RC,
601 const TargetRegisterInfo *TRI) const {
602 MachineFunction &MF = *MBB.getParent();
603 SmallVector<MachineInstr*, 4> NewMIs;
605 if (MI != MBB.end()) DL = MI->getDebugLoc();
606 LoadRegFromStackSlot(MF, DL, DestReg, FrameIdx, RC, NewMIs);
607 for (unsigned i = 0, e = NewMIs.size(); i != e; ++i)
608 MBB.insert(MI, NewMIs[i]);
610 const MachineFrameInfo &MFI = *MF.getFrameInfo();
611 MachineMemOperand *MMO =
612 MF.getMachineMemOperand(
613 MachinePointerInfo(PseudoSourceValue::getFixedStack(FrameIdx)),
614 MachineMemOperand::MOLoad,
615 MFI.getObjectSize(FrameIdx),
616 MFI.getObjectAlignment(FrameIdx));
617 NewMIs.back()->addMemOperand(MF, MMO);
621 PPCInstrInfo::emitFrameIndexDebugValue(MachineFunction &MF,
622 int FrameIx, uint64_t Offset,
625 MachineInstrBuilder MIB = BuildMI(MF, DL, get(PPC::DBG_VALUE));
626 addFrameReference(MIB, FrameIx, 0, false).addImm(Offset).addMetadata(MDPtr);
631 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
632 assert(Cond.size() == 2 && "Invalid PPC branch opcode!");
633 // Leave the CR# the same, but invert the condition.
634 Cond[0].setImm(PPC::InvertPredicate((PPC::Predicate)Cond[0].getImm()));
638 /// GetInstSize - Return the number of bytes of code the specified
639 /// instruction may be. This returns the maximum number of bytes.
641 unsigned PPCInstrInfo::GetInstSizeInBytes(const MachineInstr *MI) const {
642 switch (MI->getOpcode()) {
643 case PPC::INLINEASM: { // Inline Asm: Variable size.
644 const MachineFunction *MF = MI->getParent()->getParent();
645 const char *AsmStr = MI->getOperand(0).getSymbolName();
646 return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
648 case PPC::PROLOG_LABEL:
654 return 4; // PowerPC instructions are all 4 bytes
658 MCInstrInfo *createPPCMCInstrInfo() {
659 MCInstrInfo *X = new MCInstrInfo();
660 InitPPCMCInstrInfo(X);
664 extern "C" void LLVMInitializePowerPCMCInstrInfo() {
665 TargetRegistry::RegisterMCInstrInfo(ThePPC32Target, createPPCMCInstrInfo);
666 TargetRegistry::RegisterMCInstrInfo(ThePPC64Target, createPPCMCInstrInfo);