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 "PPCTargetMachine.h"
19 #include "PPCHazardRecognizers.h"
20 #include "MCTargetDesc/PPCPredicates.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/MC/MCAsmInfo.h"
26 #include "llvm/Support/CommandLine.h"
27 #include "llvm/Support/ErrorHandling.h"
28 #include "llvm/Support/TargetRegistry.h"
29 #include "llvm/Support/raw_ostream.h"
30 #include "llvm/ADT/STLExtras.h"
32 #define GET_INSTRINFO_CTOR
33 #include "PPCGenInstrInfo.inc"
36 extern cl::opt<bool> DisablePPC32RS;
37 extern cl::opt<bool> DisablePPC64RS;
42 PPCInstrInfo::PPCInstrInfo(PPCTargetMachine &tm)
43 : PPCGenInstrInfo(PPC::ADJCALLSTACKDOWN, PPC::ADJCALLSTACKUP),
44 TM(tm), RI(*TM.getSubtargetImpl(), *this) {}
46 /// CreateTargetHazardRecognizer - Return the hazard recognizer to use for
47 /// this target when scheduling the DAG.
48 ScheduleHazardRecognizer *PPCInstrInfo::CreateTargetHazardRecognizer(
49 const TargetMachine *TM,
50 const ScheduleDAG *DAG) const {
51 unsigned Directive = TM->getSubtarget<PPCSubtarget>().getDarwinDirective();
52 if (Directive == PPC::DIR_440) {
53 const InstrItineraryData *II = TM->getInstrItineraryData();
54 return new PPCHazardRecognizer440(II, DAG);
57 return TargetInstrInfoImpl::CreateTargetHazardRecognizer(TM, DAG);
60 /// CreateTargetPostRAHazardRecognizer - Return the postRA hazard recognizer
61 /// to use for this target when scheduling the DAG.
62 ScheduleHazardRecognizer *PPCInstrInfo::CreateTargetPostRAHazardRecognizer(
63 const InstrItineraryData *II,
64 const ScheduleDAG *DAG) const {
65 unsigned Directive = TM.getSubtarget<PPCSubtarget>().getDarwinDirective();
67 // Most subtargets use a PPC970 recognizer.
68 if (Directive != PPC::DIR_440) {
69 const TargetInstrInfo *TII = TM.getInstrInfo();
70 assert(TII && "No InstrInfo?");
72 return new PPCHazardRecognizer970(*TII);
75 return TargetInstrInfoImpl::CreateTargetPostRAHazardRecognizer(II, DAG);
77 unsigned PPCInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
78 int &FrameIndex) const {
79 switch (MI->getOpcode()) {
85 if (MI->getOperand(1).isImm() && !MI->getOperand(1).getImm() &&
86 MI->getOperand(2).isFI()) {
87 FrameIndex = MI->getOperand(2).getIndex();
88 return MI->getOperand(0).getReg();
95 unsigned PPCInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
96 int &FrameIndex) const {
97 switch (MI->getOpcode()) {
103 if (MI->getOperand(1).isImm() && !MI->getOperand(1).getImm() &&
104 MI->getOperand(2).isFI()) {
105 FrameIndex = MI->getOperand(2).getIndex();
106 return MI->getOperand(0).getReg();
113 // commuteInstruction - We can commute rlwimi instructions, but only if the
114 // rotate amt is zero. We also have to munge the immediates a bit.
116 PPCInstrInfo::commuteInstruction(MachineInstr *MI, bool NewMI) const {
117 MachineFunction &MF = *MI->getParent()->getParent();
119 // Normal instructions can be commuted the obvious way.
120 if (MI->getOpcode() != PPC::RLWIMI)
121 return TargetInstrInfoImpl::commuteInstruction(MI, NewMI);
123 // Cannot commute if it has a non-zero rotate count.
124 if (MI->getOperand(3).getImm() != 0)
127 // If we have a zero rotate count, we have:
129 // Op0 = (Op1 & ~M) | (Op2 & M)
131 // M = mask((ME+1)&31, (MB-1)&31)
132 // Op0 = (Op2 & ~M) | (Op1 & M)
135 unsigned Reg0 = MI->getOperand(0).getReg();
136 unsigned Reg1 = MI->getOperand(1).getReg();
137 unsigned Reg2 = MI->getOperand(2).getReg();
138 bool Reg1IsKill = MI->getOperand(1).isKill();
139 bool Reg2IsKill = MI->getOperand(2).isKill();
140 bool ChangeReg0 = false;
141 // If machine instrs are no longer in two-address forms, update
142 // destination register as well.
144 // Must be two address instruction!
145 assert(MI->getDesc().getOperandConstraint(0, MCOI::TIED_TO) &&
146 "Expecting a two-address instruction!");
152 unsigned MB = MI->getOperand(4).getImm();
153 unsigned ME = MI->getOperand(5).getImm();
156 // Create a new instruction.
157 unsigned Reg0 = ChangeReg0 ? Reg2 : MI->getOperand(0).getReg();
158 bool Reg0IsDead = MI->getOperand(0).isDead();
159 return BuildMI(MF, MI->getDebugLoc(), MI->getDesc())
160 .addReg(Reg0, RegState::Define | getDeadRegState(Reg0IsDead))
161 .addReg(Reg2, getKillRegState(Reg2IsKill))
162 .addReg(Reg1, getKillRegState(Reg1IsKill))
164 .addImm((MB-1) & 31);
168 MI->getOperand(0).setReg(Reg2);
169 MI->getOperand(2).setReg(Reg1);
170 MI->getOperand(1).setReg(Reg2);
171 MI->getOperand(2).setIsKill(Reg1IsKill);
172 MI->getOperand(1).setIsKill(Reg2IsKill);
174 // Swap the mask around.
175 MI->getOperand(4).setImm((ME+1) & 31);
176 MI->getOperand(5).setImm((MB-1) & 31);
180 void PPCInstrInfo::insertNoop(MachineBasicBlock &MBB,
181 MachineBasicBlock::iterator MI) const {
183 BuildMI(MBB, MI, DL, get(PPC::NOP));
188 bool PPCInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
189 MachineBasicBlock *&FBB,
190 SmallVectorImpl<MachineOperand> &Cond,
191 bool AllowModify) const {
192 // If the block has no terminators, it just falls into the block after it.
193 MachineBasicBlock::iterator I = MBB.end();
194 if (I == MBB.begin())
197 while (I->isDebugValue()) {
198 if (I == MBB.begin())
202 if (!isUnpredicatedTerminator(I))
205 // Get the last instruction in the block.
206 MachineInstr *LastInst = I;
208 // If there is only one terminator instruction, process it.
209 if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
210 if (LastInst->getOpcode() == PPC::B) {
211 if (!LastInst->getOperand(0).isMBB())
213 TBB = LastInst->getOperand(0).getMBB();
215 } else if (LastInst->getOpcode() == PPC::BCC) {
216 if (!LastInst->getOperand(2).isMBB())
218 // Block ends with fall-through condbranch.
219 TBB = LastInst->getOperand(2).getMBB();
220 Cond.push_back(LastInst->getOperand(0));
221 Cond.push_back(LastInst->getOperand(1));
224 // Otherwise, don't know what this is.
228 // Get the instruction before it if it's a terminator.
229 MachineInstr *SecondLastInst = I;
231 // If there are three terminators, we don't know what sort of block this is.
232 if (SecondLastInst && I != MBB.begin() &&
233 isUnpredicatedTerminator(--I))
236 // If the block ends with PPC::B and PPC:BCC, handle it.
237 if (SecondLastInst->getOpcode() == PPC::BCC &&
238 LastInst->getOpcode() == PPC::B) {
239 if (!SecondLastInst->getOperand(2).isMBB() ||
240 !LastInst->getOperand(0).isMBB())
242 TBB = SecondLastInst->getOperand(2).getMBB();
243 Cond.push_back(SecondLastInst->getOperand(0));
244 Cond.push_back(SecondLastInst->getOperand(1));
245 FBB = LastInst->getOperand(0).getMBB();
249 // If the block ends with two PPC:Bs, handle it. The second one is not
250 // executed, so remove it.
251 if (SecondLastInst->getOpcode() == PPC::B &&
252 LastInst->getOpcode() == PPC::B) {
253 if (!SecondLastInst->getOperand(0).isMBB())
255 TBB = SecondLastInst->getOperand(0).getMBB();
258 I->eraseFromParent();
262 // Otherwise, can't handle this.
266 unsigned PPCInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
267 MachineBasicBlock::iterator I = MBB.end();
268 if (I == MBB.begin()) return 0;
270 while (I->isDebugValue()) {
271 if (I == MBB.begin())
275 if (I->getOpcode() != PPC::B && I->getOpcode() != PPC::BCC)
278 // Remove the branch.
279 I->eraseFromParent();
283 if (I == MBB.begin()) return 1;
285 if (I->getOpcode() != PPC::BCC)
288 // Remove the branch.
289 I->eraseFromParent();
294 PPCInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
295 MachineBasicBlock *FBB,
296 const SmallVectorImpl<MachineOperand> &Cond,
298 // Shouldn't be a fall through.
299 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
300 assert((Cond.size() == 2 || Cond.size() == 0) &&
301 "PPC branch conditions have two components!");
305 if (Cond.empty()) // Unconditional branch
306 BuildMI(&MBB, DL, get(PPC::B)).addMBB(TBB);
307 else // Conditional branch
308 BuildMI(&MBB, DL, get(PPC::BCC))
309 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
313 // Two-way Conditional Branch.
314 BuildMI(&MBB, DL, get(PPC::BCC))
315 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
316 BuildMI(&MBB, DL, get(PPC::B)).addMBB(FBB);
320 void PPCInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
321 MachineBasicBlock::iterator I, DebugLoc DL,
322 unsigned DestReg, unsigned SrcReg,
323 bool KillSrc) const {
325 if (PPC::GPRCRegClass.contains(DestReg, SrcReg))
327 else if (PPC::G8RCRegClass.contains(DestReg, SrcReg))
329 else if (PPC::F4RCRegClass.contains(DestReg, SrcReg))
331 else if (PPC::CRRCRegClass.contains(DestReg, SrcReg))
333 else if (PPC::VRRCRegClass.contains(DestReg, SrcReg))
335 else if (PPC::CRBITRCRegClass.contains(DestReg, SrcReg))
338 llvm_unreachable("Impossible reg-to-reg copy");
340 const MCInstrDesc &MCID = get(Opc);
341 if (MCID.getNumOperands() == 3)
342 BuildMI(MBB, I, DL, MCID, DestReg)
343 .addReg(SrcReg).addReg(SrcReg, getKillRegState(KillSrc));
345 BuildMI(MBB, I, DL, MCID, DestReg).addReg(SrcReg, getKillRegState(KillSrc));
348 // This function returns true if a CR spill is necessary and false otherwise.
350 PPCInstrInfo::StoreRegToStackSlot(MachineFunction &MF,
351 unsigned SrcReg, bool isKill,
353 const TargetRegisterClass *RC,
354 SmallVectorImpl<MachineInstr*> &NewMIs) const{
356 if (PPC::GPRCRegisterClass->hasSubClassEq(RC)) {
357 if (SrcReg != PPC::LR) {
358 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STW))
360 getKillRegState(isKill)),
363 // FIXME: this spills LR immediately to memory in one step. To do this,
364 // we use R11, which we know cannot be used in the prolog/epilog. This is
366 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MFLR), PPC::R11));
367 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STW))
369 getKillRegState(isKill)),
372 } else if (PPC::G8RCRegisterClass->hasSubClassEq(RC)) {
373 if (SrcReg != PPC::LR8) {
374 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STD))
376 getKillRegState(isKill)),
379 // FIXME: this spills LR immediately to memory in one step. To do this,
380 // we use X11, which we know cannot be used in the prolog/epilog. This is
382 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MFLR8), PPC::X11));
383 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STD))
385 getKillRegState(isKill)),
388 } else if (PPC::F8RCRegisterClass->hasSubClassEq(RC)) {
389 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STFD))
391 getKillRegState(isKill)),
393 } else if (PPC::F4RCRegisterClass->hasSubClassEq(RC)) {
394 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STFS))
396 getKillRegState(isKill)),
398 } else if (PPC::CRRCRegisterClass->hasSubClassEq(RC)) {
399 if ((!DisablePPC32RS && !TM.getSubtargetImpl()->isPPC64()) ||
400 (!DisablePPC64RS && TM.getSubtargetImpl()->isPPC64())) {
401 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::SPILL_CR))
403 getKillRegState(isKill)),
407 // FIXME: We need a scatch reg here. The trouble with using R0 is that
408 // it's possible for the stack frame to be so big the save location is
409 // out of range of immediate offsets, necessitating another register.
410 // We hack this on Darwin by reserving R2. It's probably broken on Linux
413 // We need to store the CR in the low 4-bits of the saved value. First,
414 // issue a MFCR to save all of the CRBits.
415 unsigned ScratchReg = TM.getSubtargetImpl()->isDarwinABI() ?
417 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MFCRpseud), ScratchReg)
418 .addReg(SrcReg, getKillRegState(isKill)));
420 // If the saved register wasn't CR0, shift the bits left so that they are
422 if (SrcReg != PPC::CR0) {
423 unsigned ShiftBits = getPPCRegisterNumbering(SrcReg)*4;
424 // rlwinm scratch, scratch, ShiftBits, 0, 31.
425 NewMIs.push_back(BuildMI(MF, DL, get(PPC::RLWINM), ScratchReg)
426 .addReg(ScratchReg).addImm(ShiftBits)
427 .addImm(0).addImm(31));
430 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::STW))
432 getKillRegState(isKill)),
435 } else if (PPC::CRBITRCRegisterClass->hasSubClassEq(RC)) {
436 // FIXME: We use CRi here because there is no mtcrf on a bit. Since the
437 // backend currently only uses CR1EQ as an individual bit, this should
438 // not cause any bug. If we need other uses of CR bits, the following
439 // code may be invalid.
441 if (SrcReg == PPC::CR0LT || SrcReg == PPC::CR0GT ||
442 SrcReg == PPC::CR0EQ || SrcReg == PPC::CR0UN)
444 else if (SrcReg == PPC::CR1LT || SrcReg == PPC::CR1GT ||
445 SrcReg == PPC::CR1EQ || SrcReg == PPC::CR1UN)
447 else if (SrcReg == PPC::CR2LT || SrcReg == PPC::CR2GT ||
448 SrcReg == PPC::CR2EQ || SrcReg == PPC::CR2UN)
450 else if (SrcReg == PPC::CR3LT || SrcReg == PPC::CR3GT ||
451 SrcReg == PPC::CR3EQ || SrcReg == PPC::CR3UN)
453 else if (SrcReg == PPC::CR4LT || SrcReg == PPC::CR4GT ||
454 SrcReg == PPC::CR4EQ || SrcReg == PPC::CR4UN)
456 else if (SrcReg == PPC::CR5LT || SrcReg == PPC::CR5GT ||
457 SrcReg == PPC::CR5EQ || SrcReg == PPC::CR5UN)
459 else if (SrcReg == PPC::CR6LT || SrcReg == PPC::CR6GT ||
460 SrcReg == PPC::CR6EQ || SrcReg == PPC::CR6UN)
462 else if (SrcReg == PPC::CR7LT || SrcReg == PPC::CR7GT ||
463 SrcReg == PPC::CR7EQ || SrcReg == PPC::CR7UN)
466 return StoreRegToStackSlot(MF, Reg, isKill, FrameIdx,
467 PPC::CRRCRegisterClass, NewMIs);
469 } else if (PPC::VRRCRegisterClass->hasSubClassEq(RC)) {
470 // We don't have indexed addressing for vector loads. Emit:
474 // FIXME: We use R0 here, because it isn't available for RA.
475 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::ADDI), PPC::R0),
477 NewMIs.push_back(BuildMI(MF, DL, get(PPC::STVX))
478 .addReg(SrcReg, getKillRegState(isKill))
482 llvm_unreachable("Unknown regclass!");
489 PPCInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
490 MachineBasicBlock::iterator MI,
491 unsigned SrcReg, bool isKill, int FrameIdx,
492 const TargetRegisterClass *RC,
493 const TargetRegisterInfo *TRI) const {
494 MachineFunction &MF = *MBB.getParent();
495 SmallVector<MachineInstr*, 4> NewMIs;
497 if (StoreRegToStackSlot(MF, SrcReg, isKill, FrameIdx, RC, NewMIs)) {
498 PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
499 FuncInfo->setSpillsCR();
502 for (unsigned i = 0, e = NewMIs.size(); i != e; ++i)
503 MBB.insert(MI, NewMIs[i]);
505 const MachineFrameInfo &MFI = *MF.getFrameInfo();
506 MachineMemOperand *MMO =
507 MF.getMachineMemOperand(MachinePointerInfo::getFixedStack(FrameIdx),
508 MachineMemOperand::MOStore,
509 MFI.getObjectSize(FrameIdx),
510 MFI.getObjectAlignment(FrameIdx));
511 NewMIs.back()->addMemOperand(MF, MMO);
515 PPCInstrInfo::LoadRegFromStackSlot(MachineFunction &MF, DebugLoc DL,
516 unsigned DestReg, int FrameIdx,
517 const TargetRegisterClass *RC,
518 SmallVectorImpl<MachineInstr*> &NewMIs)const{
519 if (PPC::GPRCRegisterClass->hasSubClassEq(RC)) {
520 if (DestReg != PPC::LR) {
521 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LWZ),
522 DestReg), FrameIdx));
524 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LWZ),
525 PPC::R11), FrameIdx));
526 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MTLR)).addReg(PPC::R11));
528 } else if (PPC::G8RCRegisterClass->hasSubClassEq(RC)) {
529 if (DestReg != PPC::LR8) {
530 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LD), DestReg),
533 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LD),
534 PPC::X11), FrameIdx));
535 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MTLR8)).addReg(PPC::X11));
537 } else if (PPC::F8RCRegisterClass->hasSubClassEq(RC)) {
538 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LFD), DestReg),
540 } else if (PPC::F4RCRegisterClass->hasSubClassEq(RC)) {
541 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LFS), DestReg),
543 } else if (PPC::CRRCRegisterClass->hasSubClassEq(RC)) {
544 if ((!DisablePPC32RS && !TM.getSubtargetImpl()->isPPC64()) ||
545 (!DisablePPC64RS && TM.getSubtargetImpl()->isPPC64())) {
546 NewMIs.push_back(addFrameReference(BuildMI(MF, DL,
547 get(PPC::RESTORE_CR), DestReg)
551 // FIXME: We need a scatch reg here. The trouble with using R0 is that
552 // it's possible for the stack frame to be so big the save location is
553 // out of range of immediate offsets, necessitating another register.
554 // We hack this on Darwin by reserving R2. It's probably broken on Linux
556 unsigned ScratchReg = TM.getSubtargetImpl()->isDarwinABI() ?
558 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::LWZ),
559 ScratchReg), FrameIdx));
561 // If the reloaded register isn't CR0, shift the bits right so that they are
562 // in the right CR's slot.
563 if (DestReg != PPC::CR0) {
564 unsigned ShiftBits = getPPCRegisterNumbering(DestReg)*4;
565 // rlwinm r11, r11, 32-ShiftBits, 0, 31.
566 NewMIs.push_back(BuildMI(MF, DL, get(PPC::RLWINM), ScratchReg)
567 .addReg(ScratchReg).addImm(32-ShiftBits).addImm(0)
571 NewMIs.push_back(BuildMI(MF, DL, get(PPC::MTCRF), DestReg)
572 .addReg(ScratchReg));
574 } else if (PPC::CRBITRCRegisterClass->hasSubClassEq(RC)) {
577 if (DestReg == PPC::CR0LT || DestReg == PPC::CR0GT ||
578 DestReg == PPC::CR0EQ || DestReg == PPC::CR0UN)
580 else if (DestReg == PPC::CR1LT || DestReg == PPC::CR1GT ||
581 DestReg == PPC::CR1EQ || DestReg == PPC::CR1UN)
583 else if (DestReg == PPC::CR2LT || DestReg == PPC::CR2GT ||
584 DestReg == PPC::CR2EQ || DestReg == PPC::CR2UN)
586 else if (DestReg == PPC::CR3LT || DestReg == PPC::CR3GT ||
587 DestReg == PPC::CR3EQ || DestReg == PPC::CR3UN)
589 else if (DestReg == PPC::CR4LT || DestReg == PPC::CR4GT ||
590 DestReg == PPC::CR4EQ || DestReg == PPC::CR4UN)
592 else if (DestReg == PPC::CR5LT || DestReg == PPC::CR5GT ||
593 DestReg == PPC::CR5EQ || DestReg == PPC::CR5UN)
595 else if (DestReg == PPC::CR6LT || DestReg == PPC::CR6GT ||
596 DestReg == PPC::CR6EQ || DestReg == PPC::CR6UN)
598 else if (DestReg == PPC::CR7LT || DestReg == PPC::CR7GT ||
599 DestReg == PPC::CR7EQ || DestReg == PPC::CR7UN)
602 return LoadRegFromStackSlot(MF, DL, Reg, FrameIdx,
603 PPC::CRRCRegisterClass, NewMIs);
605 } else if (PPC::VRRCRegisterClass->hasSubClassEq(RC)) {
606 // We don't have indexed addressing for vector loads. Emit:
610 // FIXME: We use R0 here, because it isn't available for RA.
611 NewMIs.push_back(addFrameReference(BuildMI(MF, DL, get(PPC::ADDI), PPC::R0),
613 NewMIs.push_back(BuildMI(MF, DL, get(PPC::LVX),DestReg).addReg(PPC::R0)
616 llvm_unreachable("Unknown regclass!");
623 PPCInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
624 MachineBasicBlock::iterator MI,
625 unsigned DestReg, int FrameIdx,
626 const TargetRegisterClass *RC,
627 const TargetRegisterInfo *TRI) const {
628 MachineFunction &MF = *MBB.getParent();
629 SmallVector<MachineInstr*, 4> NewMIs;
631 if (MI != MBB.end()) DL = MI->getDebugLoc();
632 if (LoadRegFromStackSlot(MF, DL, DestReg, FrameIdx, RC, NewMIs)) {
633 PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
634 FuncInfo->setSpillsCR();
636 for (unsigned i = 0, e = NewMIs.size(); i != e; ++i)
637 MBB.insert(MI, NewMIs[i]);
639 const MachineFrameInfo &MFI = *MF.getFrameInfo();
640 MachineMemOperand *MMO =
641 MF.getMachineMemOperand(MachinePointerInfo::getFixedStack(FrameIdx),
642 MachineMemOperand::MOLoad,
643 MFI.getObjectSize(FrameIdx),
644 MFI.getObjectAlignment(FrameIdx));
645 NewMIs.back()->addMemOperand(MF, MMO);
649 PPCInstrInfo::emitFrameIndexDebugValue(MachineFunction &MF,
650 int FrameIx, uint64_t Offset,
653 MachineInstrBuilder MIB = BuildMI(MF, DL, get(PPC::DBG_VALUE));
654 addFrameReference(MIB, FrameIx, 0, false).addImm(Offset).addMetadata(MDPtr);
659 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
660 assert(Cond.size() == 2 && "Invalid PPC branch opcode!");
661 // Leave the CR# the same, but invert the condition.
662 Cond[0].setImm(PPC::InvertPredicate((PPC::Predicate)Cond[0].getImm()));
666 /// GetInstSize - Return the number of bytes of code the specified
667 /// instruction may be. This returns the maximum number of bytes.
669 unsigned PPCInstrInfo::GetInstSizeInBytes(const MachineInstr *MI) const {
670 switch (MI->getOpcode()) {
671 case PPC::INLINEASM: { // Inline Asm: Variable size.
672 const MachineFunction *MF = MI->getParent()->getParent();
673 const char *AsmStr = MI->getOperand(0).getSymbolName();
674 return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
676 case PPC::PROLOG_LABEL:
682 return 4; // PowerPC instructions are all 4 bytes