Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
PPCFrameLowering.cpp
Go to the documentation of this file.
1//===-- PPCFrameLowering.cpp - PPC Frame Information ----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the PPC implementation of TargetFrameLowering class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "PPCFrameLowering.h"
14#include "MCTargetDesc/PPCPredicates.h"
15#include "PPCInstrBuilder.h"
16#include "PPCInstrInfo.h"
17#include "PPCMachineFunctionInfo.h"
18#include "PPCSubtarget.h"
19#include "PPCTargetMachine.h"
20#include "llvm/ADT/Statistic.h"
21#include "llvm/CodeGen/LivePhysRegs.h"
22#include "llvm/CodeGen/MachineFrameInfo.h"
23#include "llvm/CodeGen/MachineFunction.h"
24#include "llvm/CodeGen/MachineInstrBuilder.h"
25#include "llvm/CodeGen/MachineModuleInfo.h"
26#include "llvm/CodeGen/MachineRegisterInfo.h"
27#include "llvm/CodeGen/RegisterScavenging.h"
28#include "llvm/IR/Function.h"
29#include "llvm/Target/TargetOptions.h"
30
31using namespacellvm;
32
33#define DEBUG_TYPE "framelowering"
34STATISTIC(NumPESpillVSR,"Number of spills to vector in prologue");
35STATISTIC(NumPEReloadVSR,"Number of reloads from vector in epilogue");
36STATISTIC(NumPrologProbed,"Number of prologues probed");
37
38staticcl::opt<bool>
39EnablePEVectorSpills("ppc-enable-pe-vector-spills",
40cl::desc("Enable spills in prologue to vector registers."),
41cl::init(false),cl::Hidden);
42
43staticunsignedcomputeReturnSaveOffset(constPPCSubtarget &STI) {
44if (STI.isAIXABI())
45return STI.isPPC64() ? 16 : 8;
46// SVR4 ABI:
47return STI.isPPC64() ? 16 : 4;
48}
49
50staticunsignedcomputeTOCSaveOffset(constPPCSubtarget &STI) {
51if (STI.isAIXABI())
52return STI.isPPC64() ? 40 : 20;
53return STI.isELFv2ABI() ? 24 : 40;
54}
55
56staticunsignedcomputeFramePointerSaveOffset(constPPCSubtarget &STI) {
57// First slot in the general register save area.
58return STI.isPPC64() ? -8U : -4U;
59}
60
61staticunsignedcomputeLinkageSize(constPPCSubtarget &STI) {
62if (STI.isAIXABI() || STI.isPPC64())
63return (STI.isELFv2ABI() ? 4 : 6) * (STI.isPPC64() ? 8 : 4);
64
65// 32-bit SVR4 ABI:
66return 8;
67}
68
69staticunsignedcomputeBasePointerSaveOffset(constPPCSubtarget &STI) {
70// Third slot in the general purpose register save area.
71if (STI.is32BitELFABI() && STI.getTargetMachine().isPositionIndependent())
72return -12U;
73
74// Second slot in the general purpose register save area.
75return STI.isPPC64() ? -16U : -8U;
76}
77
78staticunsignedcomputeCRSaveOffset(constPPCSubtarget &STI) {
79return (STI.isAIXABI() && !STI.isPPC64()) ? 4 : 8;
80}
81
82PPCFrameLowering::PPCFrameLowering(constPPCSubtarget &STI)
83 :TargetFrameLowering(TargetFrameLowering::StackGrowsDown,
84 STI.getPlatformStackAlignment(), 0),
85 Subtarget(STI), ReturnSaveOffset(computeReturnSaveOffset(Subtarget)),
86 TOCSaveOffset(computeTOCSaveOffset(Subtarget)),
87 FramePointerSaveOffset(computeFramePointerSaveOffset(Subtarget)),
88 LinkageSize(computeLinkageSize(Subtarget)),
89 BasePointerSaveOffset(computeBasePointerSaveOffset(Subtarget)),
90 CRSaveOffset(computeCRSaveOffset(Subtarget)) {}
91
92// With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
93constPPCFrameLowering::SpillSlot *PPCFrameLowering::getCalleeSavedSpillSlots(
94unsigned &NumEntries) const{
95
96// Floating-point register save area offsets.
97#define CALLEE_SAVED_FPRS \
98 {PPC::F31, -8}, \
99 {PPC::F30, -16}, \
100 {PPC::F29, -24}, \
101 {PPC::F28, -32}, \
102 {PPC::F27, -40}, \
103 {PPC::F26, -48}, \
104 {PPC::F25, -56}, \
105 {PPC::F24, -64}, \
106 {PPC::F23, -72}, \
107 {PPC::F22, -80}, \
108 {PPC::F21, -88}, \
109 {PPC::F20, -96}, \
110 {PPC::F19, -104}, \
111 {PPC::F18, -112}, \
112 {PPC::F17, -120}, \
113 {PPC::F16, -128}, \
114 {PPC::F15, -136}, \
115 {PPC::F14, -144}
116
117// 32-bit general purpose register save area offsets shared by ELF and
118// AIX. AIX has an extra CSR with r13.
119#define CALLEE_SAVED_GPRS32 \
120 {PPC::R31, -4}, \
121 {PPC::R30, -8}, \
122 {PPC::R29, -12}, \
123 {PPC::R28, -16}, \
124 {PPC::R27, -20}, \
125 {PPC::R26, -24}, \
126 {PPC::R25, -28}, \
127 {PPC::R24, -32}, \
128 {PPC::R23, -36}, \
129 {PPC::R22, -40}, \
130 {PPC::R21, -44}, \
131 {PPC::R20, -48}, \
132 {PPC::R19, -52}, \
133 {PPC::R18, -56}, \
134 {PPC::R17, -60}, \
135 {PPC::R16, -64}, \
136 {PPC::R15, -68}, \
137 {PPC::R14, -72}
138
139// 64-bit general purpose register save area offsets.
140#define CALLEE_SAVED_GPRS64 \
141 {PPC::X31, -8}, \
142 {PPC::X30, -16}, \
143 {PPC::X29, -24}, \
144 {PPC::X28, -32}, \
145 {PPC::X27, -40}, \
146 {PPC::X26, -48}, \
147 {PPC::X25, -56}, \
148 {PPC::X24, -64}, \
149 {PPC::X23, -72}, \
150 {PPC::X22, -80}, \
151 {PPC::X21, -88}, \
152 {PPC::X20, -96}, \
153 {PPC::X19, -104}, \
154 {PPC::X18, -112}, \
155 {PPC::X17, -120}, \
156 {PPC::X16, -128}, \
157 {PPC::X15, -136}, \
158 {PPC::X14, -144}
159
160// Vector register save area offsets.
161#define CALLEE_SAVED_VRS \
162 {PPC::V31, -16}, \
163 {PPC::V30, -32}, \
164 {PPC::V29, -48}, \
165 {PPC::V28, -64}, \
166 {PPC::V27, -80}, \
167 {PPC::V26, -96}, \
168 {PPC::V25, -112}, \
169 {PPC::V24, -128}, \
170 {PPC::V23, -144}, \
171 {PPC::V22, -160}, \
172 {PPC::V21, -176}, \
173 {PPC::V20, -192}
174
175// Note that the offsets here overlap, but this is fixed up in
176// processFunctionBeforeFrameFinalized.
177
178staticconstSpillSlot ELFOffsets32[] = {
179CALLEE_SAVED_FPRS,
180CALLEE_SAVED_GPRS32,
181
182// CR save area offset. We map each of the nonvolatile CR fields
183// to the slot for CR2, which is the first of the nonvolatile CR
184// fields to be assigned, so that we only allocate one save slot.
185// See PPCRegisterInfo::hasReservedSpillSlot() for more information.
186 {PPC::CR2, -4},
187
188// VRSAVE save area offset.
189 {PPC::VRSAVE, -4},
190
191CALLEE_SAVED_VRS,
192
193// SPE register save area (overlaps Vector save area).
194 {PPC::S31, -8},
195 {PPC::S30, -16},
196 {PPC::S29, -24},
197 {PPC::S28, -32},
198 {PPC::S27, -40},
199 {PPC::S26, -48},
200 {PPC::S25, -56},
201 {PPC::S24, -64},
202 {PPC::S23, -72},
203 {PPC::S22, -80},
204 {PPC::S21, -88},
205 {PPC::S20, -96},
206 {PPC::S19, -104},
207 {PPC::S18, -112},
208 {PPC::S17, -120},
209 {PPC::S16, -128},
210 {PPC::S15, -136},
211 {PPC::S14, -144}};
212
213staticconstSpillSlot ELFOffsets64[] = {
214CALLEE_SAVED_FPRS,
215CALLEE_SAVED_GPRS64,
216
217// VRSAVE save area offset.
218 {PPC::VRSAVE, -4},
219CALLEE_SAVED_VRS
220 };
221
222staticconstSpillSlot AIXOffsets32[] = {CALLEE_SAVED_FPRS,
223CALLEE_SAVED_GPRS32,
224// Add AIX's extra CSR.
225 {PPC::R13, -76},
226CALLEE_SAVED_VRS};
227
228staticconstSpillSlot AIXOffsets64[] = {
229CALLEE_SAVED_FPRS,CALLEE_SAVED_GPRS64,CALLEE_SAVED_VRS};
230
231if (Subtarget.is64BitELFABI()) {
232 NumEntries = std::size(ELFOffsets64);
233return ELFOffsets64;
234 }
235
236if (Subtarget.is32BitELFABI()) {
237 NumEntries = std::size(ELFOffsets32);
238return ELFOffsets32;
239 }
240
241assert(Subtarget.isAIXABI() &&"Unexpected ABI.");
242
243if (Subtarget.isPPC64()) {
244 NumEntries = std::size(AIXOffsets64);
245return AIXOffsets64;
246 }
247
248 NumEntries = std::size(AIXOffsets32);
249return AIXOffsets32;
250}
251
252staticboolspillsCR(constMachineFunction &MF) {
253constPPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
254return FuncInfo->isCRSpilled();
255}
256
257staticboolhasSpills(constMachineFunction &MF) {
258constPPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
259return FuncInfo->hasSpills();
260}
261
262staticboolhasNonRISpills(constMachineFunction &MF) {
263constPPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
264return FuncInfo->hasNonRISpills();
265}
266
267/// MustSaveLR - Return true if this function requires that we save the LR
268/// register onto the stack in the prolog and restore it in the epilog of the
269/// function.
270staticboolMustSaveLR(constMachineFunction &MF,unsigned LR) {
271constPPCFunctionInfo *MFI = MF.getInfo<PPCFunctionInfo>();
272
273// We need a save/restore of LR if there is any def of LR (which is
274// defined by calls, including the PIC setup sequence), or if there is
275// some use of the LR stack slot (e.g. for builtin_return_address).
276// (LR comes in 32 and 64 bit versions.)
277MachineRegisterInfo::def_iterator RI = MF.getRegInfo().def_begin(LR);
278return RI !=MF.getRegInfo().def_end() || MFI->isLRStoreRequired();
279}
280
281/// determineFrameLayoutAndUpdate - Determine the size of the frame and maximum
282/// call frame size. Update the MachineFunction object with the stack size.
283uint64_t
284PPCFrameLowering::determineFrameLayoutAndUpdate(MachineFunction &MF,
285bool UseEstimate) const{
286unsigned NewMaxCallFrameSize = 0;
287uint64_t FrameSize =determineFrameLayout(MF, UseEstimate,
288 &NewMaxCallFrameSize);
289 MF.getFrameInfo().setStackSize(FrameSize);
290 MF.getFrameInfo().setMaxCallFrameSize(NewMaxCallFrameSize);
291return FrameSize;
292}
293
294/// determineFrameLayout - Determine the size of the frame and maximum call
295/// frame size.
296uint64_t
297PPCFrameLowering::determineFrameLayout(constMachineFunction &MF,
298bool UseEstimate,
299unsigned *NewMaxCallFrameSize) const{
300constMachineFrameInfo &MFI = MF.getFrameInfo();
301constPPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
302
303// Get the number of bytes to allocate from the FrameInfo
304uint64_t FrameSize =
305 UseEstimate ? MFI.estimateStackSize(MF) : MFI.getStackSize();
306
307// Get stack alignments. The frame must be aligned to the greatest of these:
308Align TargetAlign =getStackAlign();// alignment required per the ABI
309Align MaxAlign = MFI.getMaxAlign();// algmt required by data in frame
310Align Alignment = std::max(TargetAlign, MaxAlign);
311
312constPPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();
313
314unsigned LR = RegInfo->getRARegister();
315bool DisableRedZone = MF.getFunction().hasFnAttribute(Attribute::NoRedZone);
316bool CanUseRedZone = !MFI.hasVarSizedObjects() &&// No dynamic alloca.
317 !MFI.adjustsStack() &&// No calls.
318 !MustSaveLR(MF, LR) &&// No need to save LR.
319 !FI->mustSaveTOC() &&// No need to save TOC.
320 !RegInfo->hasBasePointer(MF) &&// No special alignment.
321 !MFI.isFrameAddressTaken();
322
323// Note: for PPC32 SVR4ABI, we can still generate stackless
324// code if all local vars are reg-allocated.
325bool FitsInRedZone = FrameSize <= Subtarget.getRedZoneSize();
326
327// Check whether we can skip adjusting the stack pointer (by using red zone)
328if (!DisableRedZone && CanUseRedZone && FitsInRedZone) {
329// No need for frame
330return 0;
331 }
332
333// Get the maximum call frame size of all the calls.
334unsigned maxCallFrameSize = MFI.getMaxCallFrameSize();
335
336// Maximum call frame needs to be at least big enough for linkage area.
337unsigned minCallFrameSize =getLinkageSize();
338 maxCallFrameSize = std::max(maxCallFrameSize, minCallFrameSize);
339
340// If we have dynamic alloca then maxCallFrameSize needs to be aligned so
341// that allocations will be aligned.
342if (MFI.hasVarSizedObjects())
343 maxCallFrameSize =alignTo(maxCallFrameSize, Alignment);
344
345// Update the new max call frame size if the caller passes in a valid pointer.
346if (NewMaxCallFrameSize)
347 *NewMaxCallFrameSize = maxCallFrameSize;
348
349// Include call frame size in total.
350 FrameSize += maxCallFrameSize;
351
352// Make sure the frame is aligned.
353 FrameSize =alignTo(FrameSize, Alignment);
354
355return FrameSize;
356}
357
358// hasFPImpl - Return true if the specified function actually has a dedicated
359// frame pointer register.
360boolPPCFrameLowering::hasFPImpl(constMachineFunction &MF) const{
361constMachineFrameInfo &MFI = MF.getFrameInfo();
362// FIXME: This is pretty much broken by design: hasFP() might be called really
363// early, before the stack layout was calculated and thus hasFP() might return
364// true or false here depending on the time of call.
365return (MFI.getStackSize()) &&needsFP(MF);
366}
367
368// needsFP - Return true if the specified function should have a dedicated frame
369// pointer register. This is true if the function has variable sized allocas or
370// if frame pointer elimination is disabled.
371boolPPCFrameLowering::needsFP(constMachineFunction &MF) const{
372constMachineFrameInfo &MFI = MF.getFrameInfo();
373
374// Naked functions have no stack frame pushed, so we don't have a frame
375// pointer.
376if (MF.getFunction().hasFnAttribute(Attribute::Naked))
377returnfalse;
378
379return MF.getTarget().Options.DisableFramePointerElim(MF) ||
380 MFI.hasVarSizedObjects() || MFI.hasStackMap() || MFI.hasPatchPoint() ||
381 MF.exposesReturnsTwice() ||
382 (MF.getTarget().Options.GuaranteedTailCallOpt &&
383 MF.getInfo<PPCFunctionInfo>()->hasFastCall());
384}
385
386voidPPCFrameLowering::replaceFPWithRealFP(MachineFunction &MF) const{
387// When there is dynamic alloca in this function, we can not use the frame
388// pointer X31/R31 for the frameaddress lowering. In this case, only X1/R1
389// always points to the backchain.
390bool is31 =needsFP(MF) && !MF.getFrameInfo().hasVarSizedObjects();
391unsignedFPReg = is31 ? PPC::R31 : PPC::R1;
392unsigned FP8Reg = is31 ? PPC::X31 : PPC::X1;
393
394constPPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();
395bool HasBP = RegInfo->hasBasePointer(MF);
396unsigned BPReg = HasBP ? (unsigned) RegInfo->getBaseRegister(MF) :FPReg;
397unsigned BP8Reg = HasBP ? (unsigned) PPC::X30 : FP8Reg;
398
399for (MachineBasicBlock &MBB : MF)
400for (MachineBasicBlock::iteratorMBBI =MBB.end();MBBI !=MBB.begin();) {
401 --MBBI;
402for (MachineOperand &MO :MBBI->operands()) {
403if (!MO.isReg())
404continue;
405
406switch (MO.getReg()) {
407case PPC::FP:
408 MO.setReg(FPReg);
409break;
410case PPC::FP8:
411 MO.setReg(FP8Reg);
412break;
413case PPC::BP:
414 MO.setReg(BPReg);
415break;
416case PPC::BP8:
417 MO.setReg(BP8Reg);
418break;
419
420 }
421 }
422 }
423}
424
425/* This function will do the following:
426 - If MBB is an entry or exit block, set SR1 and SR2 to R0 and R12
427 respectively (defaults recommended by the ABI) and return true
428 - If MBB is not an entry block, initialize the register scavenger and look
429 for available registers.
430 - If the defaults (R0/R12) are available, return true
431 - If TwoUniqueRegsRequired is set to true, it looks for two unique
432 registers. Otherwise, look for a single available register.
433 - If the required registers are found, set SR1 and SR2 and return true.
434 - If the required registers are not found, set SR2 or both SR1 and SR2 to
435 PPC::NoRegister and return false.
436
437 Note that if both SR1 and SR2 are valid parameters and TwoUniqueRegsRequired
438 is not set, this function will attempt to find two different registers, but
439 still return true if only one register is available (and set SR1 == SR2).
440*/
441bool
442PPCFrameLowering::findScratchRegister(MachineBasicBlock *MBB,
443bool UseAtEnd,
444bool TwoUniqueRegsRequired,
445Register *SR1,
446Register *SR2) const{
447RegScavenger RS;
448Register R0 = Subtarget.isPPC64() ? PPC::X0 : PPC::R0;
449Register R12 = Subtarget.isPPC64() ? PPC::X12 : PPC::R12;
450
451// Set the defaults for the two scratch registers.
452if (SR1)
453 *SR1 = R0;
454
455if (SR2) {
456assert (SR1 &&"Asking for the second scratch register but not the first?");
457 *SR2 = R12;
458 }
459
460// If MBB is an entry or exit block, use R0 and R12 as the scratch registers.
461if ((UseAtEnd &&MBB->isReturnBlock()) ||
462 (!UseAtEnd && (&MBB->getParent()->front() ==MBB)))
463returntrue;
464
465if (UseAtEnd) {
466// The scratch register will be used before the first terminator (or at the
467// end of the block if there are no terminators).
468MachineBasicBlock::iteratorMBBI =MBB->getFirstTerminator();
469if (MBBI ==MBB->begin()) {
470 RS.enterBasicBlock(*MBB);
471 }else {
472 RS.enterBasicBlockEnd(*MBB);
473 RS.backward(MBBI);
474 }
475 }else {
476// The scratch register will be used at the start of the block.
477 RS.enterBasicBlock(*MBB);
478 }
479
480// If the two registers are available, we're all good.
481// Note that we only return here if both R0 and R12 are available because
482// although the function may not require two unique registers, it may benefit
483// from having two so we should try to provide them.
484if (!RS.isRegUsed(R0) && !RS.isRegUsed(R12))
485returntrue;
486
487// Get the list of callee-saved registers for the target.
488constPPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();
489constMCPhysReg *CSRegs =RegInfo->getCalleeSavedRegs(MBB->getParent());
490
491// Get all the available registers in the block.
492BitVector BV = RS.getRegsAvailable(Subtarget.isPPC64() ? &PPC::G8RCRegClass :
493 &PPC::GPRCRegClass);
494
495// We shouldn't use callee-saved registers as scratch registers as they may be
496// available when looking for a candidate block for shrink wrapping but not
497// available when the actual prologue/epilogue is being emitted because they
498// were added as live-in to the prologue block by PrologueEpilogueInserter.
499for (int i = 0; CSRegs[i]; ++i)
500 BV.reset(CSRegs[i]);
501
502// Set the first scratch register to the first available one.
503if (SR1) {
504int FirstScratchReg = BV.find_first();
505 *SR1 = FirstScratchReg == -1 ? (unsigned)PPC::NoRegister : FirstScratchReg;
506 }
507
508// If there is another one available, set the second scratch register to that.
509// Otherwise, set it to either PPC::NoRegister if this function requires two
510// or to whatever SR1 is set to if this function doesn't require two.
511if (SR2) {
512int SecondScratchReg = BV.find_next(*SR1);
513if (SecondScratchReg != -1)
514 *SR2 = SecondScratchReg;
515else
516 *SR2 = TwoUniqueRegsRequired ?Register() : *SR1;
517 }
518
519// Now that we've done our best to provide both registers, double check
520// whether we were unable to provide enough.
521if (BV.count() < (TwoUniqueRegsRequired ? 2U : 1U))
522returnfalse;
523
524returntrue;
525}
526
527// We need a scratch register for spilling LR and for spilling CR. By default,
528// we use two scratch registers to hide latency. However, if only one scratch
529// register is available, we can adjust for that by not overlapping the spill
530// code. However, if we need to realign the stack (i.e. have a base pointer)
531// and the stack frame is large, we need two scratch registers.
532// Also, stack probe requires two scratch registers, one for old sp, one for
533// large frame and large probe size.
534bool
535PPCFrameLowering::twoUniqueScratchRegsRequired(MachineBasicBlock *MBB) const{
536constPPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();
537MachineFunction &MF = *(MBB->getParent());
538bool HasBP =RegInfo->hasBasePointer(MF);
539unsigned FrameSize =determineFrameLayout(MF);
540int NegFrameSize = -FrameSize;
541bool IsLargeFrame = !isInt<16>(NegFrameSize);
542MachineFrameInfo &MFI = MF.getFrameInfo();
543Align MaxAlign = MFI.getMaxAlign();
544bool HasRedZone = Subtarget.isPPC64() || !Subtarget.isSVR4ABI();
545constPPCTargetLowering &TLI = *Subtarget.getTargetLowering();
546
547return ((IsLargeFrame || !HasRedZone) && HasBP && MaxAlign > 1) ||
548 TLI.hasInlineStackProbe(MF);
549}
550
551boolPPCFrameLowering::canUseAsPrologue(constMachineBasicBlock &MBB) const{
552MachineBasicBlock *TmpMBB =const_cast<MachineBasicBlock *>(&MBB);
553
554return findScratchRegister(TmpMBB,false,
555 twoUniqueScratchRegsRequired(TmpMBB));
556}
557
558boolPPCFrameLowering::canUseAsEpilogue(constMachineBasicBlock &MBB) const{
559MachineBasicBlock *TmpMBB =const_cast<MachineBasicBlock *>(&MBB);
560
561return findScratchRegister(TmpMBB,true);
562}
563
564bool PPCFrameLowering::stackUpdateCanBeMoved(MachineFunction &MF) const{
565constPPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();
566PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
567
568// Abort if there is no register info or function info.
569if (!RegInfo || !FI)
570returnfalse;
571
572// Only move the stack update on ELFv2 ABI and PPC64.
573if (!Subtarget.isELFv2ABI() || !Subtarget.isPPC64())
574returnfalse;
575
576// Check the frame size first and return false if it does not fit the
577// requirements.
578// We need a non-zero frame size as well as a frame that will fit in the red
579// zone. This is because by moving the stack pointer update we are now storing
580// to the red zone until the stack pointer is updated. If we get an interrupt
581// inside the prologue but before the stack update we now have a number of
582// stores to the red zone and those stores must all fit.
583MachineFrameInfo &MFI = MF.getFrameInfo();
584unsigned FrameSize = MFI.getStackSize();
585if (!FrameSize || FrameSize > Subtarget.getRedZoneSize())
586returnfalse;
587
588// Frame pointers and base pointers complicate matters so don't do anything
589// if we have them. For example having a frame pointer will sometimes require
590// a copy of r1 into r31 and that makes keeping track of updates to r1 more
591// difficult. Similar situation exists with setjmp.
592if (hasFP(MF) || RegInfo->hasBasePointer(MF) || MF.exposesReturnsTwice())
593returnfalse;
594
595// Calls to fast_cc functions use different rules for passing parameters on
596// the stack from the ABI and using PIC base in the function imposes
597// similar restrictions to using the base pointer. It is not generally safe
598// to move the stack pointer update in these situations.
599if (FI->hasFastCall() || FI->usesPICBase())
600returnfalse;
601
602// Finally we can move the stack update if we do not require register
603// scavenging. Register scavenging can introduce more spills and so
604// may make the frame size larger than we have computed.
605return !RegInfo->requiresFrameIndexScavenging(MF);
606}
607
608voidPPCFrameLowering::emitPrologue(MachineFunction &MF,
609MachineBasicBlock &MBB) const{
610MachineBasicBlock::iteratorMBBI =MBB.begin();
611MachineFrameInfo &MFI = MF.getFrameInfo();
612constPPCInstrInfo &TII = *Subtarget.getInstrInfo();
613constPPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();
614constPPCTargetLowering &TLI = *Subtarget.getTargetLowering();
615
616constMCRegisterInfo *MRI = MF.getContext().getRegisterInfo();
617DebugLoc dl;
618// AIX assembler does not support cfi directives.
619constbool needsCFI = MF.needsFrameMoves() && !Subtarget.isAIXABI();
620
621constbool HasFastMFLR = Subtarget.hasFastMFLR();
622
623// Get processor type.
624bool isPPC64 = Subtarget.isPPC64();
625// Get the ABI.
626bool isSVR4ABI = Subtarget.isSVR4ABI();
627bool isELFv2ABI = Subtarget.isELFv2ABI();
628assert((isSVR4ABI || Subtarget.isAIXABI()) &&"Unsupported PPC ABI.");
629
630// Work out frame sizes.
631uint64_t FrameSize =determineFrameLayoutAndUpdate(MF);
632 int64_t NegFrameSize = -FrameSize;
633if (!isPPC64 && (!isInt<32>(FrameSize) || !isInt<32>(NegFrameSize)))
634llvm_unreachable("Unhandled stack size!");
635
636if (MFI.isFrameAddressTaken())
637replaceFPWithRealFP(MF);
638
639// Check if the link register (LR) must be saved.
640PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
641boolMustSaveLR = FI->mustSaveLR();
642bool MustSaveTOC = FI->mustSaveTOC();
643constSmallVectorImpl<Register> &MustSaveCRs = FI->getMustSaveCRs();
644bool MustSaveCR = !MustSaveCRs.empty();
645// Do we have a frame pointer and/or base pointer for this function?
646bool HasFP =hasFP(MF);
647bool HasBP = RegInfo->hasBasePointer(MF);
648bool HasRedZone = isPPC64 || !isSVR4ABI;
649constbool HasROPProtect = Subtarget.hasROPProtect();
650bool HasPrivileged = Subtarget.hasPrivileged();
651
652RegisterSPReg = isPPC64 ? PPC::X1 : PPC::R1;
653Register BPReg = RegInfo->getBaseRegister(MF);
654RegisterFPReg = isPPC64 ? PPC::X31 : PPC::R31;
655Register LRReg = isPPC64 ? PPC::LR8 : PPC::LR;
656Register TOCReg = isPPC64 ? PPC::X2 : PPC::R2;
657Register ScratchReg;
658Register TempReg = isPPC64 ? PPC::X12 : PPC::R12;// another scratch reg
659// ...(R12/X12 is volatile in both Darwin & SVR4, & can't be a function arg.)
660constMCInstrDesc& MFLRInst =TII.get(isPPC64 ? PPC::MFLR8
661 : PPC::MFLR );
662constMCInstrDesc&StoreInst =TII.get(isPPC64 ? PPC::STD
663 : PPC::STW );
664constMCInstrDesc& StoreUpdtInst =TII.get(isPPC64 ? PPC::STDU
665 : PPC::STWU );
666constMCInstrDesc& StoreUpdtIdxInst =TII.get(isPPC64 ? PPC::STDUX
667 : PPC::STWUX);
668constMCInstrDesc& OrInst =TII.get(isPPC64 ? PPC::OR8
669 : PPC::OR );
670constMCInstrDesc& SubtractCarryingInst =TII.get(isPPC64 ? PPC::SUBFC8
671 : PPC::SUBFC);
672constMCInstrDesc& SubtractImmCarryingInst =TII.get(isPPC64 ? PPC::SUBFIC8
673 : PPC::SUBFIC);
674constMCInstrDesc &MoveFromCondRegInst =TII.get(isPPC64 ? PPC::MFCR8
675 : PPC::MFCR);
676constMCInstrDesc &StoreWordInst =TII.get(isPPC64 ? PPC::STW8 : PPC::STW);
677constMCInstrDesc &HashST =
678TII.get(isPPC64 ? (HasPrivileged ? PPC::HASHSTP8 : PPC::HASHST8)
679 : (HasPrivileged ? PPC::HASHSTP : PPC::HASHST));
680
681// Regarding this assert: Even though LR is saved in the caller's frame (i.e.,
682// LROffset is positive), that slot is callee-owned. Because PPC32 SVR4 has no
683// Red Zone, an asynchronous event (a form of "callee") could claim a frame &
684// overwrite it, so PPC32 SVR4 must claim at least a minimal frame to save LR.
685assert((isPPC64 || !isSVR4ABI || !(!FrameSize && (MustSaveLR || HasFP))) &&
686"FrameSize must be >0 to save/restore the FP or LR for 32-bit SVR4.");
687
688// Using the same bool variable as below to suppress compiler warnings.
689bool SingleScratchReg = findScratchRegister(
690 &MBB,false, twoUniqueScratchRegsRequired(&MBB), &ScratchReg, &TempReg);
691assert(SingleScratchReg &&
692"Required number of registers not available in this block");
693
694 SingleScratchReg = ScratchReg == TempReg;
695
696 int64_t LROffset =getReturnSaveOffset();
697
698 int64_t FPOffset = 0;
699if (HasFP) {
700MachineFrameInfo &MFI = MF.getFrameInfo();
701int FPIndex = FI->getFramePointerSaveIndex();
702assert(FPIndex &&"No Frame Pointer Save Slot!");
703 FPOffset = MFI.getObjectOffset(FPIndex);
704 }
705
706 int64_t BPOffset = 0;
707if (HasBP) {
708MachineFrameInfo &MFI = MF.getFrameInfo();
709int BPIndex = FI->getBasePointerSaveIndex();
710assert(BPIndex &&"No Base Pointer Save Slot!");
711 BPOffset = MFI.getObjectOffset(BPIndex);
712 }
713
714 int64_t PBPOffset = 0;
715if (FI->usesPICBase()) {
716MachineFrameInfo &MFI = MF.getFrameInfo();
717int PBPIndex = FI->getPICBasePointerSaveIndex();
718assert(PBPIndex &&"No PIC Base Pointer Save Slot!");
719 PBPOffset = MFI.getObjectOffset(PBPIndex);
720 }
721
722// Get stack alignments.
723Align MaxAlign = MFI.getMaxAlign();
724if (HasBP && MaxAlign > 1)
725assert(Log2(MaxAlign) < 16 &&"Invalid alignment!");
726
727// Frames of 32KB & larger require special handling because they cannot be
728// indexed into with a simple STDU/STWU/STD/STW immediate offset operand.
729bool isLargeFrame = !isInt<16>(NegFrameSize);
730
731// Check if we can move the stack update instruction (stdu) down the prologue
732// past the callee saves. Hopefully this will avoid the situation where the
733// saves are waiting for the update on the store with update to complete.
734MachineBasicBlock::iterator StackUpdateLoc =MBBI;
735bool MovingStackUpdateDown =false;
736
737// Check if we can move the stack update.
738if (stackUpdateCanBeMoved(MF)) {
739const std::vector<CalleeSavedInfo> &Info = MFI.getCalleeSavedInfo();
740for (CalleeSavedInfo CSI :Info) {
741// If the callee saved register is spilled to a register instead of the
742// stack then the spill no longer uses the stack pointer.
743// This can lead to two consequences:
744// 1) We no longer need to update the stack because the function does not
745// spill any callee saved registers to stack.
746// 2) We have a situation where we still have to update the stack pointer
747// even though some registers are spilled to other registers. In
748// this case the current code moves the stack update to an incorrect
749// position.
750// In either case we should abort moving the stack update operation.
751if (CSI.isSpilledToReg()) {
752 StackUpdateLoc =MBBI;
753 MovingStackUpdateDown =false;
754break;
755 }
756
757int FrIdx = CSI.getFrameIdx();
758// If the frame index is not negative the callee saved info belongs to a
759// stack object that is not a fixed stack object. We ignore non-fixed
760// stack objects because we won't move the stack update pointer past them.
761if (FrIdx >= 0)
762continue;
763
764if (MFI.isFixedObjectIndex(FrIdx) && MFI.getObjectOffset(FrIdx) < 0) {
765 StackUpdateLoc++;
766 MovingStackUpdateDown =true;
767 }else {
768// We need all of the Frame Indices to meet these conditions.
769// If they do not, abort the whole operation.
770 StackUpdateLoc =MBBI;
771 MovingStackUpdateDown =false;
772break;
773 }
774 }
775
776// If the operation was not aborted then update the object offset.
777if (MovingStackUpdateDown) {
778for (CalleeSavedInfo CSI :Info) {
779int FrIdx = CSI.getFrameIdx();
780if (FrIdx < 0)
781 MFI.setObjectOffset(FrIdx, MFI.getObjectOffset(FrIdx) + NegFrameSize);
782 }
783 }
784 }
785
786// Where in the prologue we move the CR fields depends on how many scratch
787// registers we have, and if we need to save the link register or not. This
788// lambda is to avoid duplicating the logic in 2 places.
789auto BuildMoveFromCR = [&]() {
790if (isELFv2ABI && MustSaveCRs.size() == 1) {
791// In the ELFv2 ABI, we are not required to save all CR fields.
792// If only one CR field is clobbered, it is more efficient to use
793// mfocrf to selectively save just that field, because mfocrf has short
794// latency compares to mfcr.
795assert(isPPC64 &&"V2 ABI is 64-bit only.");
796MachineInstrBuilder MIB =
797BuildMI(MBB,MBBI, dl,TII.get(PPC::MFOCRF8), TempReg);
798 MIB.addReg(MustSaveCRs[0],RegState::Kill);
799 }else {
800MachineInstrBuilder MIB =
801BuildMI(MBB,MBBI, dl, MoveFromCondRegInst, TempReg);
802for (unsigned CRfield : MustSaveCRs)
803 MIB.addReg(CRfield,RegState::ImplicitKill);
804 }
805 };
806
807// If we need to spill the CR and the LR but we don't have two separate
808// registers available, we must spill them one at a time
809if (MustSaveCR && SingleScratchReg &&MustSaveLR) {
810 BuildMoveFromCR();
811BuildMI(MBB,MBBI, dl, StoreWordInst)
812 .addReg(TempReg,getKillRegState(true))
813 .addImm(CRSaveOffset)
814 .addReg(SPReg);
815 }
816
817if (MustSaveLR)
818BuildMI(MBB,MBBI, dl, MFLRInst, ScratchReg);
819
820if (MustSaveCR && !(SingleScratchReg &&MustSaveLR))
821 BuildMoveFromCR();
822
823if (HasRedZone) {
824if (HasFP)
825BuildMI(MBB,MBBI, dl,StoreInst)
826 .addReg(FPReg)
827 .addImm(FPOffset)
828 .addReg(SPReg);
829if (FI->usesPICBase())
830BuildMI(MBB,MBBI, dl,StoreInst)
831 .addReg(PPC::R30)
832 .addImm(PBPOffset)
833 .addReg(SPReg);
834if (HasBP)
835BuildMI(MBB,MBBI, dl,StoreInst)
836 .addReg(BPReg)
837 .addImm(BPOffset)
838 .addReg(SPReg);
839 }
840
841// Generate the instruction to store the LR. In the case where ROP protection
842// is required the register holding the LR should not be killed as it will be
843// used by the hash store instruction.
844auto SaveLR = [&](int64_tOffset) {
845assert(MustSaveLR &&"LR is not required to be saved!");
846BuildMI(MBB, StackUpdateLoc, dl,StoreInst)
847 .addReg(ScratchReg,getKillRegState(!HasROPProtect))
848 .addImm(Offset)
849 .addReg(SPReg);
850
851// Add the ROP protection Hash Store instruction.
852// NOTE: This is technically a violation of the ABI. The hash can be saved
853// up to 512 bytes into the Protected Zone. This can be outside of the
854// initial 288 byte volatile program storage region in the Protected Zone.
855// However, this restriction will be removed in an upcoming revision of the
856// ABI.
857if (HasROPProtect) {
858constint SaveIndex = FI->getROPProtectionHashSaveIndex();
859const int64_t ImmOffset = MFI.getObjectOffset(SaveIndex);
860assert((ImmOffset <= -8 && ImmOffset >= -512) &&
861"ROP hash save offset out of range.");
862assert(((ImmOffset & 0x7) == 0) &&
863"ROP hash save offset must be 8 byte aligned.");
864BuildMI(MBB, StackUpdateLoc, dl, HashST)
865 .addReg(ScratchReg,getKillRegState(true))
866 .addImm(ImmOffset)
867 .addReg(SPReg);
868 }
869 };
870
871if (MustSaveLR && HasFastMFLR)
872 SaveLR(LROffset);
873
874if (MustSaveCR &&
875 !(SingleScratchReg &&MustSaveLR)) {
876assert(HasRedZone &&"A red zone is always available on PPC64");
877BuildMI(MBB,MBBI, dl, StoreWordInst)
878 .addReg(TempReg,getKillRegState(true))
879 .addImm(CRSaveOffset)
880 .addReg(SPReg);
881 }
882
883// Skip the rest if this is a leaf function & all spills fit in the Red Zone.
884if (!FrameSize) {
885if (MustSaveLR && !HasFastMFLR)
886 SaveLR(LROffset);
887return;
888 }
889
890// Adjust stack pointer: r1 += NegFrameSize.
891// If there is a preferred stack alignment, align R1 now
892
893if (HasBP && HasRedZone) {
894// Save a copy of r1 as the base pointer.
895BuildMI(MBB,MBBI, dl, OrInst, BPReg)
896 .addReg(SPReg)
897 .addReg(SPReg);
898 }
899
900// Have we generated a STUX instruction to claim stack frame? If so,
901// the negated frame size will be placed in ScratchReg.
902bool HasSTUX =
903 (TLI.hasInlineStackProbe(MF) && FrameSize > TLI.getStackProbeSize(MF)) ||
904 (HasBP && MaxAlign > 1) || isLargeFrame;
905
906// If we use STUX to update the stack pointer, we need the two scratch
907// registers TempReg and ScratchReg, we have to save LR here which is stored
908// in ScratchReg.
909// If the offset can not be encoded into the store instruction, we also have
910// to save LR here.
911// If we are using ROP Protection we need to save the LR here as we cannot
912// move the hashst instruction past the point where we get the stack frame.
913if (MustSaveLR && !HasFastMFLR &&
914 (HasSTUX || !isInt<16>(FrameSize + LROffset) || HasROPProtect))
915 SaveLR(LROffset);
916
917// If FrameSize <= TLI.getStackProbeSize(MF), as POWER ABI requires backchain
918// pointer is always stored at SP, we will get a free probe due to an essential
919// STU(X) instruction.
920if (TLI.hasInlineStackProbe(MF) && FrameSize > TLI.getStackProbeSize(MF)) {
921// To be consistent with other targets, a pseudo instruction is emitted and
922// will be later expanded in `inlineStackProbe`.
923BuildMI(MBB,MBBI, dl,
924TII.get(isPPC64 ? PPC::PROBED_STACKALLOC_64
925 : PPC::PROBED_STACKALLOC_32))
926 .addDef(TempReg)
927 .addDef(ScratchReg)// ScratchReg stores the old sp.
928 .addImm(NegFrameSize);
929// FIXME: HasSTUX is only read if HasRedZone is not set, in such case, we
930// update the ScratchReg to meet the assumption that ScratchReg contains
931// the NegFrameSize. This solution is rather tricky.
932if (!HasRedZone) {
933BuildMI(MBB,MBBI, dl,TII.get(PPC::SUBF), ScratchReg)
934 .addReg(ScratchReg)
935 .addReg(SPReg);
936 }
937 }else {
938// This condition must be kept in sync with canUseAsPrologue.
939if (HasBP && MaxAlign > 1) {
940if (isPPC64)
941BuildMI(MBB,MBBI, dl,TII.get(PPC::RLDICL), ScratchReg)
942 .addReg(SPReg)
943 .addImm(0)
944 .addImm(64 -Log2(MaxAlign));
945else// PPC32...
946BuildMI(MBB,MBBI, dl,TII.get(PPC::RLWINM), ScratchReg)
947 .addReg(SPReg)
948 .addImm(0)
949 .addImm(32 -Log2(MaxAlign))
950 .addImm(31);
951if (!isLargeFrame) {
952BuildMI(MBB,MBBI, dl, SubtractImmCarryingInst, ScratchReg)
953 .addReg(ScratchReg,RegState::Kill)
954 .addImm(NegFrameSize);
955 }else {
956assert(!SingleScratchReg &&"Only a single scratch reg available");
957TII.materializeImmPostRA(MBB,MBBI, dl, TempReg, NegFrameSize);
958BuildMI(MBB,MBBI, dl, SubtractCarryingInst, ScratchReg)
959 .addReg(ScratchReg,RegState::Kill)
960 .addReg(TempReg,RegState::Kill);
961 }
962
963BuildMI(MBB,MBBI, dl, StoreUpdtIdxInst,SPReg)
964 .addReg(SPReg,RegState::Kill)
965 .addReg(SPReg)
966 .addReg(ScratchReg);
967 }elseif (!isLargeFrame) {
968BuildMI(MBB, StackUpdateLoc, dl, StoreUpdtInst,SPReg)
969 .addReg(SPReg)
970 .addImm(NegFrameSize)
971 .addReg(SPReg);
972 }else {
973TII.materializeImmPostRA(MBB,MBBI, dl, ScratchReg, NegFrameSize);
974BuildMI(MBB,MBBI, dl, StoreUpdtIdxInst,SPReg)
975 .addReg(SPReg,RegState::Kill)
976 .addReg(SPReg)
977 .addReg(ScratchReg);
978 }
979 }
980
981// Save the TOC register after the stack pointer update if a prologue TOC
982// save is required for the function.
983if (MustSaveTOC) {
984assert(isELFv2ABI &&"TOC saves in the prologue only supported on ELFv2");
985BuildMI(MBB, StackUpdateLoc, dl,TII.get(PPC::STD))
986 .addReg(TOCReg,getKillRegState(true))
987 .addImm(TOCSaveOffset)
988 .addReg(SPReg);
989 }
990
991if (!HasRedZone) {
992assert(!isPPC64 &&"A red zone is always available on PPC64");
993if (HasSTUX) {
994// The negated frame size is in ScratchReg, and the SPReg has been
995// decremented by the frame size: SPReg = old SPReg + ScratchReg.
996// Since FPOffset, PBPOffset, etc. are relative to the beginning of
997// the stack frame (i.e. the old SP), ideally, we would put the old
998// SP into a register and use it as the base for the stores. The
999// problem is that the only available register may be ScratchReg,
1000// which could be R0, and R0 cannot be used as a base address.
1001
1002// First, set ScratchReg to the old SP. This may need to be modified
1003// later.
1004BuildMI(MBB,MBBI, dl,TII.get(PPC::SUBF), ScratchReg)
1005 .addReg(ScratchReg,RegState::Kill)
1006 .addReg(SPReg);
1007
1008if (ScratchReg == PPC::R0) {
1009// R0 cannot be used as a base register, but it can be used as an
1010// index in a store-indexed.
1011int LastOffset = 0;
1012if (HasFP) {
1013// R0 += (FPOffset-LastOffset).
1014// Need addic, since addi treats R0 as 0.
1015BuildMI(MBB,MBBI, dl,TII.get(PPC::ADDIC), ScratchReg)
1016 .addReg(ScratchReg)
1017 .addImm(FPOffset-LastOffset);
1018 LastOffset = FPOffset;
1019// Store FP into *R0.
1020BuildMI(MBB,MBBI, dl,TII.get(PPC::STWX))
1021 .addReg(FPReg,RegState::Kill)// Save FP.
1022 .addReg(PPC::ZERO)
1023 .addReg(ScratchReg);// This will be the index (R0 is ok here).
1024 }
1025if (FI->usesPICBase()) {
1026// R0 += (PBPOffset-LastOffset).
1027BuildMI(MBB,MBBI, dl,TII.get(PPC::ADDIC), ScratchReg)
1028 .addReg(ScratchReg)
1029 .addImm(PBPOffset-LastOffset);
1030 LastOffset = PBPOffset;
1031BuildMI(MBB,MBBI, dl,TII.get(PPC::STWX))
1032 .addReg(PPC::R30,RegState::Kill)// Save PIC base pointer.
1033 .addReg(PPC::ZERO)
1034 .addReg(ScratchReg);// This will be the index (R0 is ok here).
1035 }
1036if (HasBP) {
1037// R0 += (BPOffset-LastOffset).
1038BuildMI(MBB,MBBI, dl,TII.get(PPC::ADDIC), ScratchReg)
1039 .addReg(ScratchReg)
1040 .addImm(BPOffset-LastOffset);
1041 LastOffset = BPOffset;
1042BuildMI(MBB,MBBI, dl,TII.get(PPC::STWX))
1043 .addReg(BPReg,RegState::Kill)// Save BP.
1044 .addReg(PPC::ZERO)
1045 .addReg(ScratchReg);// This will be the index (R0 is ok here).
1046// BP = R0-LastOffset
1047BuildMI(MBB,MBBI, dl,TII.get(PPC::ADDIC), BPReg)
1048 .addReg(ScratchReg,RegState::Kill)
1049 .addImm(-LastOffset);
1050 }
1051 }else {
1052// ScratchReg is not R0, so use it as the base register. It is
1053// already set to the old SP, so we can use the offsets directly.
1054
1055// Now that the stack frame has been allocated, save all the necessary
1056// registers using ScratchReg as the base address.
1057if (HasFP)
1058BuildMI(MBB,MBBI, dl,StoreInst)
1059 .addReg(FPReg)
1060 .addImm(FPOffset)
1061 .addReg(ScratchReg);
1062if (FI->usesPICBase())
1063BuildMI(MBB,MBBI, dl,StoreInst)
1064 .addReg(PPC::R30)
1065 .addImm(PBPOffset)
1066 .addReg(ScratchReg);
1067if (HasBP) {
1068BuildMI(MBB,MBBI, dl,StoreInst)
1069 .addReg(BPReg)
1070 .addImm(BPOffset)
1071 .addReg(ScratchReg);
1072BuildMI(MBB,MBBI, dl, OrInst, BPReg)
1073 .addReg(ScratchReg,RegState::Kill)
1074 .addReg(ScratchReg);
1075 }
1076 }
1077 }else {
1078// The frame size is a known 16-bit constant (fitting in the immediate
1079// field of STWU). To be here we have to be compiling for PPC32.
1080// Since the SPReg has been decreased by FrameSize, add it back to each
1081// offset.
1082if (HasFP)
1083BuildMI(MBB,MBBI, dl,StoreInst)
1084 .addReg(FPReg)
1085 .addImm(FrameSize + FPOffset)
1086 .addReg(SPReg);
1087if (FI->usesPICBase())
1088BuildMI(MBB,MBBI, dl,StoreInst)
1089 .addReg(PPC::R30)
1090 .addImm(FrameSize + PBPOffset)
1091 .addReg(SPReg);
1092if (HasBP) {
1093BuildMI(MBB,MBBI, dl,StoreInst)
1094 .addReg(BPReg)
1095 .addImm(FrameSize + BPOffset)
1096 .addReg(SPReg);
1097BuildMI(MBB,MBBI, dl,TII.get(PPC::ADDI), BPReg)
1098 .addReg(SPReg)
1099 .addImm(FrameSize);
1100 }
1101 }
1102 }
1103
1104// Save the LR now.
1105if (!HasSTUX &&MustSaveLR && !HasFastMFLR &&
1106 isInt<16>(FrameSize + LROffset) && !HasROPProtect)
1107 SaveLR(LROffset + FrameSize);
1108
1109// Add Call Frame Information for the instructions we generated above.
1110if (needsCFI) {
1111unsigned CFIIndex;
1112
1113if (HasBP) {
1114// Define CFA in terms of BP. Do this in preference to using FP/SP,
1115// because if the stack needed aligning then CFA won't be at a fixed
1116// offset from FP/SP.
1117unsigned Reg =MRI->getDwarfRegNum(BPReg,true);
1118 CFIIndex = MF.addFrameInst(
1119MCCFIInstruction::createDefCfaRegister(nullptr, Reg));
1120 }else {
1121// Adjust the definition of CFA to account for the change in SP.
1122assert(NegFrameSize);
1123 CFIIndex = MF.addFrameInst(
1124MCCFIInstruction::cfiDefCfaOffset(nullptr, -NegFrameSize));
1125 }
1126BuildMI(MBB,MBBI, dl,TII.get(TargetOpcode::CFI_INSTRUCTION))
1127 .addCFIIndex(CFIIndex);
1128
1129if (HasFP) {
1130// Describe where FP was saved, at a fixed offset from CFA.
1131unsigned Reg =MRI->getDwarfRegNum(FPReg,true);
1132 CFIIndex = MF.addFrameInst(
1133MCCFIInstruction::createOffset(nullptr, Reg, FPOffset));
1134BuildMI(MBB,MBBI, dl,TII.get(TargetOpcode::CFI_INSTRUCTION))
1135 .addCFIIndex(CFIIndex);
1136 }
1137
1138if (FI->usesPICBase()) {
1139// Describe where FP was saved, at a fixed offset from CFA.
1140unsigned Reg =MRI->getDwarfRegNum(PPC::R30,true);
1141 CFIIndex = MF.addFrameInst(
1142MCCFIInstruction::createOffset(nullptr, Reg, PBPOffset));
1143BuildMI(MBB,MBBI, dl,TII.get(TargetOpcode::CFI_INSTRUCTION))
1144 .addCFIIndex(CFIIndex);
1145 }
1146
1147if (HasBP) {
1148// Describe where BP was saved, at a fixed offset from CFA.
1149unsigned Reg =MRI->getDwarfRegNum(BPReg,true);
1150 CFIIndex = MF.addFrameInst(
1151MCCFIInstruction::createOffset(nullptr, Reg, BPOffset));
1152BuildMI(MBB,MBBI, dl,TII.get(TargetOpcode::CFI_INSTRUCTION))
1153 .addCFIIndex(CFIIndex);
1154 }
1155
1156if (MustSaveLR) {
1157// Describe where LR was saved, at a fixed offset from CFA.
1158unsigned Reg =MRI->getDwarfRegNum(LRReg,true);
1159 CFIIndex = MF.addFrameInst(
1160MCCFIInstruction::createOffset(nullptr, Reg, LROffset));
1161BuildMI(MBB,MBBI, dl,TII.get(TargetOpcode::CFI_INSTRUCTION))
1162 .addCFIIndex(CFIIndex);
1163 }
1164 }
1165
1166// If there is a frame pointer, copy R1 into R31
1167if (HasFP) {
1168BuildMI(MBB,MBBI, dl, OrInst,FPReg)
1169 .addReg(SPReg)
1170 .addReg(SPReg);
1171
1172if (!HasBP && needsCFI) {
1173// Change the definition of CFA from SP+offset to FP+offset, because SP
1174// will change at every alloca.
1175unsigned Reg =MRI->getDwarfRegNum(FPReg,true);
1176unsigned CFIIndex = MF.addFrameInst(
1177MCCFIInstruction::createDefCfaRegister(nullptr, Reg));
1178
1179BuildMI(MBB,MBBI, dl,TII.get(TargetOpcode::CFI_INSTRUCTION))
1180 .addCFIIndex(CFIIndex);
1181 }
1182 }
1183
1184if (needsCFI) {
1185// Describe where callee saved registers were saved, at fixed offsets from
1186// CFA.
1187const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
1188for (constCalleeSavedInfo &I : CSI) {
1189Register Reg =I.getReg();
1190if (Reg == PPC::LR || Reg == PPC::LR8 || Reg == PPC::RM)continue;
1191
1192// This is a bit of a hack: CR2LT, CR2GT, CR2EQ and CR2UN are just
1193// subregisters of CR2. We just need to emit a move of CR2.
1194if (PPC::CRBITRCRegClass.contains(Reg))
1195continue;
1196
1197if ((Reg == PPC::X2 || Reg == PPC::R2) && MustSaveTOC)
1198continue;
1199
1200// For 64-bit SVR4 when we have spilled CRs, the spill location
1201// is SP+8, not a frame-relative slot.
1202if (isSVR4ABI && isPPC64 && (PPC::CR2 <= Reg && Reg <= PPC::CR4)) {
1203// In the ELFv1 ABI, only CR2 is noted in CFI and stands in for
1204// the whole CR word. In the ELFv2 ABI, every CR that was
1205// actually saved gets its own CFI record.
1206Register CRReg = isELFv2ABI? Reg : PPC::CR2;
1207unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset(
1208nullptr,MRI->getDwarfRegNum(CRReg,true), CRSaveOffset));
1209BuildMI(MBB,MBBI, dl,TII.get(TargetOpcode::CFI_INSTRUCTION))
1210 .addCFIIndex(CFIIndex);
1211continue;
1212 }
1213
1214if (I.isSpilledToReg()) {
1215unsigned SpilledReg =I.getDstReg();
1216unsigned CFIRegister = MF.addFrameInst(MCCFIInstruction::createRegister(
1217nullptr,MRI->getDwarfRegNum(Reg,true),
1218MRI->getDwarfRegNum(SpilledReg,true)));
1219BuildMI(MBB,MBBI, dl,TII.get(TargetOpcode::CFI_INSTRUCTION))
1220 .addCFIIndex(CFIRegister);
1221 }else {
1222 int64_tOffset = MFI.getObjectOffset(I.getFrameIdx());
1223// We have changed the object offset above but we do not want to change
1224// the actual offsets in the CFI instruction so we have to undo the
1225// offset change here.
1226if (MovingStackUpdateDown)
1227Offset -= NegFrameSize;
1228
1229unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset(
1230nullptr,MRI->getDwarfRegNum(Reg,true),Offset));
1231BuildMI(MBB,MBBI, dl,TII.get(TargetOpcode::CFI_INSTRUCTION))
1232 .addCFIIndex(CFIIndex);
1233 }
1234 }
1235 }
1236}
1237
1238voidPPCFrameLowering::inlineStackProbe(MachineFunction &MF,
1239MachineBasicBlock &PrologMBB) const{
1240bool isPPC64 = Subtarget.isPPC64();
1241constPPCTargetLowering &TLI = *Subtarget.getTargetLowering();
1242constPPCInstrInfo &TII = *Subtarget.getInstrInfo();
1243MachineFrameInfo &MFI = MF.getFrameInfo();
1244constMCRegisterInfo *MRI = MF.getContext().getRegisterInfo();
1245// AIX assembler does not support cfi directives.
1246constbool needsCFI = MF.needsFrameMoves() && !Subtarget.isAIXABI();
1247auto StackAllocMIPos =llvm::find_if(PrologMBB, [](MachineInstr &MI) {
1248int Opc =MI.getOpcode();
1249return Opc == PPC::PROBED_STACKALLOC_64 || Opc == PPC::PROBED_STACKALLOC_32;
1250 });
1251if (StackAllocMIPos == PrologMBB.end())
1252return;
1253constBasicBlock *ProbedBB = PrologMBB.getBasicBlock();
1254MachineBasicBlock *CurrentMBB = &PrologMBB;
1255DebugLocDL = PrologMBB.findDebugLoc(StackAllocMIPos);
1256MachineInstr &MI = *StackAllocMIPos;
1257 int64_t NegFrameSize =MI.getOperand(2).getImm();
1258unsigned ProbeSize = TLI.getStackProbeSize(MF);
1259 int64_t NegProbeSize = -(int64_t)ProbeSize;
1260assert(isInt<32>(NegProbeSize) &&"Unhandled probe size");
1261 int64_t NumBlocks = NegFrameSize / NegProbeSize;
1262 int64_t NegResidualSize = NegFrameSize % NegProbeSize;
1263RegisterSPReg = isPPC64 ? PPC::X1 : PPC::R1;
1264Register ScratchReg =MI.getOperand(0).getReg();
1265RegisterFPReg =MI.getOperand(1).getReg();
1266constPPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();
1267bool HasBP = RegInfo->hasBasePointer(MF);
1268Register BPReg = RegInfo->getBaseRegister(MF);
1269Align MaxAlign = MFI.getMaxAlign();
1270bool HasRedZone = Subtarget.isPPC64() || !Subtarget.isSVR4ABI();
1271constMCInstrDesc &CopyInst =TII.get(isPPC64 ? PPC::OR8 : PPC::OR);
1272// Subroutines to generate .cfi_* directives.
1273autobuildDefCFAReg = [&](MachineBasicBlock &MBB,
1274MachineBasicBlock::iteratorMBBI,Register Reg) {
1275unsigned RegNum =MRI->getDwarfRegNum(Reg,true);
1276unsigned CFIIndex = MF.addFrameInst(
1277MCCFIInstruction::createDefCfaRegister(nullptr, RegNum));
1278BuildMI(MBB,MBBI,DL,TII.get(TargetOpcode::CFI_INSTRUCTION))
1279 .addCFIIndex(CFIIndex);
1280 };
1281auto buildDefCFA = [&](MachineBasicBlock &MBB,
1282MachineBasicBlock::iteratorMBBI,Register Reg,
1283intOffset) {
1284unsigned RegNum =MRI->getDwarfRegNum(Reg,true);
1285unsigned CFIIndex =MBB.getParent()->addFrameInst(
1286MCCFIInstruction::cfiDefCfa(nullptr, RegNum,Offset));
1287BuildMI(MBB,MBBI,DL,TII.get(TargetOpcode::CFI_INSTRUCTION))
1288 .addCFIIndex(CFIIndex);
1289 };
1290// Subroutine to determine if we can use the Imm as part of d-form.
1291auto CanUseDForm = [](int64_t Imm) {return isInt<16>(Imm) && Imm % 4 == 0; };
1292// Subroutine to materialize the Imm into TempReg.
1293auto MaterializeImm = [&](MachineBasicBlock &MBB,
1294MachineBasicBlock::iteratorMBBI, int64_t Imm,
1295Register &TempReg) {
1296assert(isInt<32>(Imm) &&"Unhandled imm");
1297if (isInt<16>(Imm))
1298BuildMI(MBB,MBBI,DL,TII.get(isPPC64 ? PPC::LI8 : PPC::LI), TempReg)
1299 .addImm(Imm);
1300else {
1301BuildMI(MBB,MBBI,DL,TII.get(isPPC64 ? PPC::LIS8 : PPC::LIS), TempReg)
1302 .addImm(Imm >> 16);
1303BuildMI(MBB,MBBI,DL,TII.get(isPPC64 ? PPC::ORI8 : PPC::ORI), TempReg)
1304 .addReg(TempReg)
1305 .addImm(Imm & 0xFFFF);
1306 }
1307 };
1308// Subroutine to store frame pointer and decrease stack pointer by probe size.
1309auto allocateAndProbe = [&](MachineBasicBlock &MBB,
1310MachineBasicBlock::iteratorMBBI, int64_t NegSize,
1311Register NegSizeReg,bool UseDForm,
1312Register StoreReg) {
1313if (UseDForm)
1314BuildMI(MBB,MBBI,DL,TII.get(isPPC64 ? PPC::STDU : PPC::STWU),SPReg)
1315 .addReg(StoreReg)
1316 .addImm(NegSize)
1317 .addReg(SPReg);
1318else
1319BuildMI(MBB,MBBI,DL,TII.get(isPPC64 ? PPC::STDUX : PPC::STWUX),SPReg)
1320 .addReg(StoreReg)
1321 .addReg(SPReg)
1322 .addReg(NegSizeReg);
1323 };
1324// Used to probe stack when realignment is required.
1325// Note that, according to ABI's requirement, *sp must always equals the
1326// value of back-chain pointer, only st(w|d)u(x) can be used to update sp.
1327// Following is pseudo code:
1328// final_sp = (sp & align) + negframesize;
1329// neg_gap = final_sp - sp;
1330// while (neg_gap < negprobesize) {
1331// stdu fp, negprobesize(sp);
1332// neg_gap -= negprobesize;
1333// }
1334// stdux fp, sp, neg_gap
1335//
1336// When HasBP & HasRedzone, back-chain pointer is already saved in BPReg
1337// before probe code, we don't need to save it, so we get one additional reg
1338// that can be used to materialize the probeside if needed to use xform.
1339// Otherwise, we can NOT materialize probeside, so we can only use Dform for
1340// now.
1341//
1342// The allocations are:
1343// if (HasBP && HasRedzone) {
1344// r0: materialize the probesize if needed so that we can use xform.
1345// r12: `neg_gap`
1346// } else {
1347// r0: back-chain pointer
1348// r12: `neg_gap`.
1349// }
1350auto probeRealignedStack = [&](MachineBasicBlock &MBB,
1351MachineBasicBlock::iteratorMBBI,
1352Register ScratchReg,Register TempReg) {
1353assert(HasBP &&"The function is supposed to have base pointer when its "
1354"stack is realigned.");
1355assert(isPowerOf2_64(ProbeSize) &&"Probe size should be power of 2");
1356
1357// FIXME: We can eliminate this limitation if we get more infomation about
1358// which part of redzone are already used. Used redzone can be treated
1359// probed. But there might be `holes' in redzone probed, this could
1360// complicate the implementation.
1361assert(ProbeSize >= Subtarget.getRedZoneSize() &&
1362"Probe size should be larger or equal to the size of red-zone so "
1363"that red-zone is not clobbered by probing.");
1364
1365Register &FinalStackPtr = TempReg;
1366// FIXME: We only support NegProbeSize materializable by DForm currently.
1367// When HasBP && HasRedzone, we can use xform if we have an additional idle
1368// register.
1369 NegProbeSize = std::max(NegProbeSize, -((int64_t)1 << 15));
1370assert(isInt<16>(NegProbeSize) &&
1371"NegProbeSize should be materializable by DForm");
1372Register CRReg = PPC::CR0;
1373// Layout of output assembly kinda like:
1374// bb.0:
1375// ...
1376// sub $scratchreg, $finalsp, r1
1377// cmpdi $scratchreg, <negprobesize>
1378// bge bb.2
1379// bb.1:
1380// stdu <backchain>, <negprobesize>(r1)
1381// sub $scratchreg, $scratchreg, negprobesize
1382// cmpdi $scratchreg, <negprobesize>
1383// blt bb.1
1384// bb.2:
1385// stdux <backchain>, r1, $scratchreg
1386MachineFunction::iterator MBBInsertPoint = std::next(MBB.getIterator());
1387MachineBasicBlock *ProbeLoopBodyMBB = MF.CreateMachineBasicBlock(ProbedBB);
1388 MF.insert(MBBInsertPoint, ProbeLoopBodyMBB);
1389MachineBasicBlock *ProbeExitMBB = MF.CreateMachineBasicBlock(ProbedBB);
1390 MF.insert(MBBInsertPoint, ProbeExitMBB);
1391// bb.2
1392 {
1393Register BackChainPointer = HasRedZone ? BPReg : TempReg;
1394 allocateAndProbe(*ProbeExitMBB, ProbeExitMBB->end(), 0, ScratchReg,false,
1395 BackChainPointer);
1396if (HasRedZone)
1397// PROBED_STACKALLOC_64 assumes Operand(1) stores the old sp, copy BPReg
1398// to TempReg to satisfy it.
1399BuildMI(*ProbeExitMBB, ProbeExitMBB->end(),DL, CopyInst, TempReg)
1400 .addReg(BPReg)
1401 .addReg(BPReg);
1402 ProbeExitMBB->splice(ProbeExitMBB->end(), &MBB,MBBI,MBB.end());
1403 ProbeExitMBB->transferSuccessorsAndUpdatePHIs(&MBB);
1404 }
1405// bb.0
1406 {
1407BuildMI(&MBB,DL,TII.get(isPPC64 ? PPC::SUBF8 : PPC::SUBF), ScratchReg)
1408 .addReg(SPReg)
1409 .addReg(FinalStackPtr);
1410if (!HasRedZone)
1411BuildMI(&MBB,DL, CopyInst, TempReg).addReg(SPReg).addReg(SPReg);
1412BuildMI(&MBB,DL,TII.get(isPPC64 ? PPC::CMPDI : PPC::CMPWI), CRReg)
1413 .addReg(ScratchReg)
1414 .addImm(NegProbeSize);
1415BuildMI(&MBB,DL,TII.get(PPC::BCC))
1416 .addImm(PPC::PRED_GE)
1417 .addReg(CRReg)
1418 .addMBB(ProbeExitMBB);
1419MBB.addSuccessor(ProbeLoopBodyMBB);
1420MBB.addSuccessor(ProbeExitMBB);
1421 }
1422// bb.1
1423 {
1424Register BackChainPointer = HasRedZone ? BPReg : TempReg;
1425 allocateAndProbe(*ProbeLoopBodyMBB, ProbeLoopBodyMBB->end(), NegProbeSize,
1426 0,true/*UseDForm*/, BackChainPointer);
1427BuildMI(ProbeLoopBodyMBB,DL,TII.get(isPPC64 ? PPC::ADDI8 : PPC::ADDI),
1428 ScratchReg)
1429 .addReg(ScratchReg)
1430 .addImm(-NegProbeSize);
1431BuildMI(ProbeLoopBodyMBB,DL,TII.get(isPPC64 ? PPC::CMPDI : PPC::CMPWI),
1432 CRReg)
1433 .addReg(ScratchReg)
1434 .addImm(NegProbeSize);
1435BuildMI(ProbeLoopBodyMBB,DL,TII.get(PPC::BCC))
1436 .addImm(PPC::PRED_LT)
1437 .addReg(CRReg)
1438 .addMBB(ProbeLoopBodyMBB);
1439 ProbeLoopBodyMBB->addSuccessor(ProbeExitMBB);
1440 ProbeLoopBodyMBB->addSuccessor(ProbeLoopBodyMBB);
1441 }
1442// Update liveins.
1443fullyRecomputeLiveIns({ProbeExitMBB, ProbeLoopBodyMBB});
1444return ProbeExitMBB;
1445 };
1446// For case HasBP && MaxAlign > 1, we have to realign the SP by performing
1447// SP = SP - SP % MaxAlign, thus make the probe more like dynamic probe since
1448// the offset subtracted from SP is determined by SP's runtime value.
1449if (HasBP && MaxAlign > 1) {
1450// Calculate final stack pointer.
1451if (isPPC64)
1452BuildMI(*CurrentMBB, {MI},DL,TII.get(PPC::RLDICL), ScratchReg)
1453 .addReg(SPReg)
1454 .addImm(0)
1455 .addImm(64 -Log2(MaxAlign));
1456else
1457BuildMI(*CurrentMBB, {MI},DL,TII.get(PPC::RLWINM), ScratchReg)
1458 .addReg(SPReg)
1459 .addImm(0)
1460 .addImm(32 -Log2(MaxAlign))
1461 .addImm(31);
1462BuildMI(*CurrentMBB, {MI},DL,TII.get(isPPC64 ? PPC::SUBF8 : PPC::SUBF),
1463FPReg)
1464 .addReg(ScratchReg)
1465 .addReg(SPReg);
1466 MaterializeImm(*CurrentMBB, {MI}, NegFrameSize, ScratchReg);
1467BuildMI(*CurrentMBB, {MI},DL,TII.get(isPPC64 ? PPC::ADD8 : PPC::ADD4),
1468FPReg)
1469 .addReg(ScratchReg)
1470 .addReg(FPReg);
1471 CurrentMBB = probeRealignedStack(*CurrentMBB, {MI}, ScratchReg,FPReg);
1472if (needsCFI)
1473buildDefCFAReg(*CurrentMBB, {MI},FPReg);
1474 }else {
1475// Initialize current frame pointer.
1476BuildMI(*CurrentMBB, {MI},DL, CopyInst,FPReg).addReg(SPReg).addReg(SPReg);
1477// Use FPReg to calculate CFA.
1478if (needsCFI)
1479 buildDefCFA(*CurrentMBB, {MI},FPReg, 0);
1480// Probe residual part.
1481if (NegResidualSize) {
1482bool ResidualUseDForm = CanUseDForm(NegResidualSize);
1483if (!ResidualUseDForm)
1484 MaterializeImm(*CurrentMBB, {MI}, NegResidualSize, ScratchReg);
1485 allocateAndProbe(*CurrentMBB, {MI}, NegResidualSize, ScratchReg,
1486 ResidualUseDForm,FPReg);
1487 }
1488bool UseDForm = CanUseDForm(NegProbeSize);
1489// If number of blocks is small, just probe them directly.
1490if (NumBlocks < 3) {
1491if (!UseDForm)
1492 MaterializeImm(*CurrentMBB, {MI}, NegProbeSize, ScratchReg);
1493for (int i = 0; i < NumBlocks; ++i)
1494 allocateAndProbe(*CurrentMBB, {MI}, NegProbeSize, ScratchReg, UseDForm,
1495FPReg);
1496if (needsCFI) {
1497// Restore using SPReg to calculate CFA.
1498buildDefCFAReg(*CurrentMBB, {MI},SPReg);
1499 }
1500 }else {
1501// Since CTR is a volatile register and current shrinkwrap implementation
1502// won't choose an MBB in a loop as the PrologMBB, it's safe to synthesize a
1503// CTR loop to probe.
1504// Calculate trip count and stores it in CTRReg.
1505 MaterializeImm(*CurrentMBB, {MI}, NumBlocks, ScratchReg);
1506BuildMI(*CurrentMBB, {MI},DL,TII.get(isPPC64 ? PPC::MTCTR8 : PPC::MTCTR))
1507 .addReg(ScratchReg,RegState::Kill);
1508if (!UseDForm)
1509 MaterializeImm(*CurrentMBB, {MI}, NegProbeSize, ScratchReg);
1510// Create MBBs of the loop.
1511MachineFunction::iterator MBBInsertPoint =
1512 std::next(CurrentMBB->getIterator());
1513MachineBasicBlock *LoopMBB = MF.CreateMachineBasicBlock(ProbedBB);
1514 MF.insert(MBBInsertPoint, LoopMBB);
1515MachineBasicBlock *ExitMBB = MF.CreateMachineBasicBlock(ProbedBB);
1516 MF.insert(MBBInsertPoint, ExitMBB);
1517// Synthesize the loop body.
1518 allocateAndProbe(*LoopMBB, LoopMBB->end(), NegProbeSize, ScratchReg,
1519 UseDForm,FPReg);
1520BuildMI(LoopMBB,DL,TII.get(isPPC64 ? PPC::BDNZ8 : PPC::BDNZ))
1521 .addMBB(LoopMBB);
1522 LoopMBB->addSuccessor(ExitMBB);
1523 LoopMBB->addSuccessor(LoopMBB);
1524// Synthesize the exit MBB.
1525 ExitMBB->splice(ExitMBB->end(), CurrentMBB,
1526 std::next(MachineBasicBlock::iterator(MI)),
1527 CurrentMBB->end());
1528 ExitMBB->transferSuccessorsAndUpdatePHIs(CurrentMBB);
1529 CurrentMBB->addSuccessor(LoopMBB);
1530if (needsCFI) {
1531// Restore using SPReg to calculate CFA.
1532buildDefCFAReg(*ExitMBB, ExitMBB->begin(),SPReg);
1533 }
1534// Update liveins.
1535fullyRecomputeLiveIns({ExitMBB, LoopMBB});
1536 }
1537 }
1538 ++NumPrologProbed;
1539MI.eraseFromParent();
1540}
1541
1542voidPPCFrameLowering::emitEpilogue(MachineFunction &MF,
1543MachineBasicBlock &MBB) const{
1544MachineBasicBlock::iteratorMBBI =MBB.getFirstTerminator();
1545DebugLoc dl;
1546
1547if (MBBI !=MBB.end())
1548 dl =MBBI->getDebugLoc();
1549
1550constPPCInstrInfo &TII = *Subtarget.getInstrInfo();
1551constPPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();
1552
1553// Get alignment info so we know how to restore the SP.
1554constMachineFrameInfo &MFI = MF.getFrameInfo();
1555
1556// Get the number of bytes allocated from the FrameInfo.
1557 int64_t FrameSize = MFI.getStackSize();
1558
1559// Get processor type.
1560bool isPPC64 = Subtarget.isPPC64();
1561
1562// Check if the link register (LR) has been saved.
1563PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
1564boolMustSaveLR = FI->mustSaveLR();
1565constSmallVectorImpl<Register> &MustSaveCRs = FI->getMustSaveCRs();
1566bool MustSaveCR = !MustSaveCRs.empty();
1567// Do we have a frame pointer and/or base pointer for this function?
1568bool HasFP =hasFP(MF);
1569bool HasBP = RegInfo->hasBasePointer(MF);
1570bool HasRedZone = Subtarget.isPPC64() || !Subtarget.isSVR4ABI();
1571bool HasROPProtect = Subtarget.hasROPProtect();
1572bool HasPrivileged = Subtarget.hasPrivileged();
1573
1574RegisterSPReg = isPPC64 ? PPC::X1 : PPC::R1;
1575Register BPReg = RegInfo->getBaseRegister(MF);
1576RegisterFPReg = isPPC64 ? PPC::X31 : PPC::R31;
1577Register ScratchReg;
1578Register TempReg = isPPC64 ? PPC::X12 : PPC::R12;// another scratch reg
1579constMCInstrDesc& MTLRInst =TII.get( isPPC64 ? PPC::MTLR8
1580 : PPC::MTLR );
1581constMCInstrDesc&LoadInst =TII.get( isPPC64 ? PPC::LD
1582 : PPC::LWZ );
1583constMCInstrDesc& LoadImmShiftedInst =TII.get( isPPC64 ? PPC::LIS8
1584 : PPC::LIS );
1585constMCInstrDesc& OrInst =TII.get(isPPC64 ? PPC::OR8
1586 : PPC::OR );
1587constMCInstrDesc& OrImmInst =TII.get( isPPC64 ? PPC::ORI8
1588 : PPC::ORI );
1589constMCInstrDesc& AddImmInst =TII.get( isPPC64 ? PPC::ADDI8
1590 : PPC::ADDI );
1591constMCInstrDesc& AddInst =TII.get( isPPC64 ? PPC::ADD8
1592 : PPC::ADD4 );
1593constMCInstrDesc& LoadWordInst =TII.get( isPPC64 ? PPC::LWZ8
1594 : PPC::LWZ);
1595constMCInstrDesc& MoveToCRInst =TII.get( isPPC64 ? PPC::MTOCRF8
1596 : PPC::MTOCRF);
1597constMCInstrDesc &HashChk =
1598TII.get(isPPC64 ? (HasPrivileged ? PPC::HASHCHKP8 : PPC::HASHCHK8)
1599 : (HasPrivileged ? PPC::HASHCHKP : PPC::HASHCHK));
1600 int64_t LROffset =getReturnSaveOffset();
1601
1602 int64_t FPOffset = 0;
1603
1604// Using the same bool variable as below to suppress compiler warnings.
1605bool SingleScratchReg = findScratchRegister(&MBB,true,false, &ScratchReg,
1606 &TempReg);
1607assert(SingleScratchReg &&
1608"Could not find an available scratch register");
1609
1610 SingleScratchReg = ScratchReg == TempReg;
1611
1612if (HasFP) {
1613int FPIndex = FI->getFramePointerSaveIndex();
1614assert(FPIndex &&"No Frame Pointer Save Slot!");
1615 FPOffset = MFI.getObjectOffset(FPIndex);
1616 }
1617
1618 int64_t BPOffset = 0;
1619if (HasBP) {
1620int BPIndex = FI->getBasePointerSaveIndex();
1621assert(BPIndex &&"No Base Pointer Save Slot!");
1622 BPOffset = MFI.getObjectOffset(BPIndex);
1623 }
1624
1625 int64_t PBPOffset = 0;
1626if (FI->usesPICBase()) {
1627int PBPIndex = FI->getPICBasePointerSaveIndex();
1628assert(PBPIndex &&"No PIC Base Pointer Save Slot!");
1629 PBPOffset = MFI.getObjectOffset(PBPIndex);
1630 }
1631
1632bool IsReturnBlock = (MBBI !=MBB.end() &&MBBI->isReturn());
1633
1634if (IsReturnBlock) {
1635unsigned RetOpcode =MBBI->getOpcode();
1636bool UsesTCRet = RetOpcode == PPC::TCRETURNri ||
1637 RetOpcode == PPC::TCRETURNdi ||
1638 RetOpcode == PPC::TCRETURNai ||
1639 RetOpcode == PPC::TCRETURNri8 ||
1640 RetOpcode == PPC::TCRETURNdi8 ||
1641 RetOpcode == PPC::TCRETURNai8;
1642
1643if (UsesTCRet) {
1644int MaxTCRetDelta = FI->getTailCallSPDelta();
1645MachineOperand &StackAdjust =MBBI->getOperand(1);
1646assert(StackAdjust.isImm() &&"Expecting immediate value.");
1647// Adjust stack pointer.
1648int StackAdj = StackAdjust.getImm();
1649int Delta = StackAdj - MaxTCRetDelta;
1650assert((Delta >= 0) &&"Delta must be positive");
1651if (MaxTCRetDelta>0)
1652 FrameSize += (StackAdj +Delta);
1653else
1654 FrameSize += StackAdj;
1655 }
1656 }
1657
1658// Frames of 32KB & larger require special handling because they cannot be
1659// indexed into with a simple LD/LWZ immediate offset operand.
1660bool isLargeFrame = !isInt<16>(FrameSize);
1661
1662// On targets without red zone, the SP needs to be restored last, so that
1663// all live contents of the stack frame are upwards of the SP. This means
1664// that we cannot restore SP just now, since there may be more registers
1665// to restore from the stack frame (e.g. R31). If the frame size is not
1666// a simple immediate value, we will need a spare register to hold the
1667// restored SP. If the frame size is known and small, we can simply adjust
1668// the offsets of the registers to be restored, and still use SP to restore
1669// them. In such case, the final update of SP will be to add the frame
1670// size to it.
1671// To simplify the code, set RBReg to the base register used to restore
1672// values from the stack, and set SPAdd to the value that needs to be added
1673// to the SP at the end. The default values are as if red zone was present.
1674unsigned RBReg =SPReg;
1675uint64_t SPAdd = 0;
1676
1677// Check if we can move the stack update instruction up the epilogue
1678// past the callee saves. This will allow the move to LR instruction
1679// to be executed before the restores of the callee saves which means
1680// that the callee saves can hide the latency from the MTLR instrcution.
1681MachineBasicBlock::iterator StackUpdateLoc =MBBI;
1682if (stackUpdateCanBeMoved(MF)) {
1683const std::vector<CalleeSavedInfo> &Info = MFI.getCalleeSavedInfo();
1684for (CalleeSavedInfo CSI :Info) {
1685// If the callee saved register is spilled to another register abort the
1686// stack update movement.
1687if (CSI.isSpilledToReg()) {
1688 StackUpdateLoc =MBBI;
1689break;
1690 }
1691int FrIdx = CSI.getFrameIdx();
1692// If the frame index is not negative the callee saved info belongs to a
1693// stack object that is not a fixed stack object. We ignore non-fixed
1694// stack objects because we won't move the update of the stack pointer
1695// past them.
1696if (FrIdx >= 0)
1697continue;
1698
1699if (MFI.isFixedObjectIndex(FrIdx) && MFI.getObjectOffset(FrIdx) < 0)
1700 StackUpdateLoc--;
1701else {
1702// Abort the operation as we can't update all CSR restores.
1703 StackUpdateLoc =MBBI;
1704break;
1705 }
1706 }
1707 }
1708
1709if (FrameSize) {
1710// In the prologue, the loaded (or persistent) stack pointer value is
1711// offset by the STDU/STDUX/STWU/STWUX instruction. For targets with red
1712// zone add this offset back now.
1713
1714// If the function has a base pointer, the stack pointer has been copied
1715// to it so we can restore it by copying in the other direction.
1716if (HasRedZone && HasBP) {
1717BuildMI(MBB,MBBI, dl, OrInst, RBReg).
1718 addReg(BPReg).
1719 addReg(BPReg);
1720 }
1721// If this function contained a fastcc call and GuaranteedTailCallOpt is
1722// enabled (=> hasFastCall()==true) the fastcc call might contain a tail
1723// call which invalidates the stack pointer value in SP(0). So we use the
1724// value of R31 in this case. Similar situation exists with setjmp.
1725elseif (FI->hasFastCall() || MF.exposesReturnsTwice()) {
1726assert(HasFP &&"Expecting a valid frame pointer.");
1727if (!HasRedZone)
1728 RBReg =FPReg;
1729if (!isLargeFrame) {
1730BuildMI(MBB,MBBI, dl, AddImmInst, RBReg)
1731 .addReg(FPReg).addImm(FrameSize);
1732 }else {
1733TII.materializeImmPostRA(MBB,MBBI, dl, ScratchReg, FrameSize);
1734BuildMI(MBB,MBBI, dl, AddInst)
1735 .addReg(RBReg)
1736 .addReg(FPReg)
1737 .addReg(ScratchReg);
1738 }
1739 }elseif (!isLargeFrame && !HasBP && !MFI.hasVarSizedObjects()) {
1740if (HasRedZone) {
1741BuildMI(MBB, StackUpdateLoc, dl, AddImmInst,SPReg)
1742 .addReg(SPReg)
1743 .addImm(FrameSize);
1744 }else {
1745// Make sure that adding FrameSize will not overflow the max offset
1746// size.
1747assert(FPOffset <= 0 && BPOffset <= 0 && PBPOffset <= 0 &&
1748"Local offsets should be negative");
1749 SPAdd = FrameSize;
1750 FPOffset += FrameSize;
1751 BPOffset += FrameSize;
1752 PBPOffset += FrameSize;
1753 }
1754 }else {
1755// We don't want to use ScratchReg as a base register, because it
1756// could happen to be R0. Use FP instead, but make sure to preserve it.
1757if (!HasRedZone) {
1758// If FP is not saved, copy it to ScratchReg.
1759if (!HasFP)
1760BuildMI(MBB,MBBI, dl, OrInst, ScratchReg)
1761 .addReg(FPReg)
1762 .addReg(FPReg);
1763 RBReg =FPReg;
1764 }
1765BuildMI(MBB, StackUpdateLoc, dl,LoadInst, RBReg)
1766 .addImm(0)
1767 .addReg(SPReg);
1768 }
1769 }
1770assert(RBReg != ScratchReg &&"Should have avoided ScratchReg");
1771// If there is no red zone, ScratchReg may be needed for holding a useful
1772// value (although not the base register). Make sure it is not overwritten
1773// too early.
1774
1775// If we need to restore both the LR and the CR and we only have one
1776// available scratch register, we must do them one at a time.
1777if (MustSaveCR && SingleScratchReg &&MustSaveLR) {
1778// Here TempReg == ScratchReg, and in the absence of red zone ScratchReg
1779// is live here.
1780assert(HasRedZone &&"Expecting red zone");
1781BuildMI(MBB,MBBI, dl, LoadWordInst, TempReg)
1782 .addImm(CRSaveOffset)
1783 .addReg(SPReg);
1784for (unsigned i = 0, e = MustSaveCRs.size(); i != e; ++i)
1785BuildMI(MBB,MBBI, dl, MoveToCRInst, MustSaveCRs[i])
1786 .addReg(TempReg,getKillRegState(i == e-1));
1787 }
1788
1789// Delay restoring of the LR if ScratchReg is needed. This is ok, since
1790// LR is stored in the caller's stack frame. ScratchReg will be needed
1791// if RBReg is anything other than SP. We shouldn't use ScratchReg as
1792// a base register anyway, because it may happen to be R0.
1793bool LoadedLR =false;
1794if (MustSaveLR && RBReg ==SPReg && isInt<16>(LROffset+SPAdd)) {
1795BuildMI(MBB, StackUpdateLoc, dl,LoadInst, ScratchReg)
1796 .addImm(LROffset+SPAdd)
1797 .addReg(RBReg);
1798 LoadedLR =true;
1799 }
1800
1801if (MustSaveCR && !(SingleScratchReg &&MustSaveLR)) {
1802assert(RBReg ==SPReg &&"Should be using SP as a base register");
1803BuildMI(MBB,MBBI, dl, LoadWordInst, TempReg)
1804 .addImm(CRSaveOffset)
1805 .addReg(RBReg);
1806 }
1807
1808if (HasFP) {
1809// If there is red zone, restore FP directly, since SP has already been
1810// restored. Otherwise, restore the value of FP into ScratchReg.
1811if (HasRedZone || RBReg ==SPReg)
1812BuildMI(MBB,MBBI, dl,LoadInst,FPReg)
1813 .addImm(FPOffset)
1814 .addReg(SPReg);
1815else
1816BuildMI(MBB,MBBI, dl,LoadInst, ScratchReg)
1817 .addImm(FPOffset)
1818 .addReg(RBReg);
1819 }
1820
1821if (FI->usesPICBase())
1822BuildMI(MBB,MBBI, dl,LoadInst, PPC::R30)
1823 .addImm(PBPOffset)
1824 .addReg(RBReg);
1825
1826if (HasBP)
1827BuildMI(MBB,MBBI, dl,LoadInst, BPReg)
1828 .addImm(BPOffset)
1829 .addReg(RBReg);
1830
1831// There is nothing more to be loaded from the stack, so now we can
1832// restore SP: SP = RBReg + SPAdd.
1833if (RBReg !=SPReg || SPAdd != 0) {
1834assert(!HasRedZone &&"This should not happen with red zone");
1835// If SPAdd is 0, generate a copy.
1836if (SPAdd == 0)
1837BuildMI(MBB,MBBI, dl, OrInst,SPReg)
1838 .addReg(RBReg)
1839 .addReg(RBReg);
1840else
1841BuildMI(MBB,MBBI, dl, AddImmInst,SPReg)
1842 .addReg(RBReg)
1843 .addImm(SPAdd);
1844
1845assert(RBReg != ScratchReg &&"Should be using FP or SP as base register");
1846if (RBReg ==FPReg)
1847BuildMI(MBB,MBBI, dl, OrInst,FPReg)
1848 .addReg(ScratchReg)
1849 .addReg(ScratchReg);
1850
1851// Now load the LR from the caller's stack frame.
1852if (MustSaveLR && !LoadedLR)
1853BuildMI(MBB,MBBI, dl,LoadInst, ScratchReg)
1854 .addImm(LROffset)
1855 .addReg(SPReg);
1856 }
1857
1858if (MustSaveCR &&
1859 !(SingleScratchReg &&MustSaveLR))
1860for (unsigned i = 0, e = MustSaveCRs.size(); i != e; ++i)
1861BuildMI(MBB,MBBI, dl, MoveToCRInst, MustSaveCRs[i])
1862 .addReg(TempReg,getKillRegState(i == e-1));
1863
1864if (MustSaveLR) {
1865// If ROP protection is required, an extra instruction is added to compute a
1866// hash and then compare it to the hash stored in the prologue.
1867if (HasROPProtect) {
1868constint SaveIndex = FI->getROPProtectionHashSaveIndex();
1869const int64_t ImmOffset = MFI.getObjectOffset(SaveIndex);
1870assert((ImmOffset <= -8 && ImmOffset >= -512) &&
1871"ROP hash check location offset out of range.");
1872assert(((ImmOffset & 0x7) == 0) &&
1873"ROP hash check location offset must be 8 byte aligned.");
1874BuildMI(MBB, StackUpdateLoc, dl, HashChk)
1875 .addReg(ScratchReg)
1876 .addImm(ImmOffset)
1877 .addReg(SPReg);
1878 }
1879BuildMI(MBB, StackUpdateLoc, dl, MTLRInst).addReg(ScratchReg);
1880 }
1881
1882// Callee pop calling convention. Pop parameter/linkage area. Used for tail
1883// call optimization
1884if (IsReturnBlock) {
1885unsigned RetOpcode =MBBI->getOpcode();
1886if (MF.getTarget().Options.GuaranteedTailCallOpt &&
1887 (RetOpcode == PPC::BLR || RetOpcode == PPC::BLR8) &&
1888 MF.getFunction().getCallingConv() ==CallingConv::Fast) {
1889PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
1890unsigned CallerAllocatedAmt = FI->getMinReservedArea();
1891
1892if (CallerAllocatedAmt && isInt<16>(CallerAllocatedAmt)) {
1893BuildMI(MBB,MBBI, dl, AddImmInst,SPReg)
1894 .addReg(SPReg).addImm(CallerAllocatedAmt);
1895 }else {
1896BuildMI(MBB,MBBI, dl, LoadImmShiftedInst, ScratchReg)
1897 .addImm(CallerAllocatedAmt >> 16);
1898BuildMI(MBB,MBBI, dl, OrImmInst, ScratchReg)
1899 .addReg(ScratchReg,RegState::Kill)
1900 .addImm(CallerAllocatedAmt & 0xFFFF);
1901BuildMI(MBB,MBBI, dl, AddInst)
1902 .addReg(SPReg)
1903 .addReg(FPReg)
1904 .addReg(ScratchReg);
1905 }
1906 }else {
1907 createTailCallBranchInstr(MBB);
1908 }
1909 }
1910}
1911
1912void PPCFrameLowering::createTailCallBranchInstr(MachineBasicBlock &MBB) const{
1913MachineBasicBlock::iteratorMBBI =MBB.getFirstTerminator();
1914
1915// If we got this far a first terminator should exist.
1916assert(MBBI !=MBB.end() &&"Failed to find the first terminator.");
1917
1918DebugLoc dl =MBBI->getDebugLoc();
1919constPPCInstrInfo &TII = *Subtarget.getInstrInfo();
1920
1921// Create branch instruction for pseudo tail call return instruction.
1922// The TCRETURNdi variants are direct calls. Valid targets for those are
1923// MO_GlobalAddress operands as well as MO_ExternalSymbol with PC-Rel
1924// since we can tail call external functions with PC-Rel (i.e. we don't need
1925// to worry about different TOC pointers). Some of the external functions will
1926// be MO_GlobalAddress while others like memcpy for example, are going to
1927// be MO_ExternalSymbol.
1928unsigned RetOpcode =MBBI->getOpcode();
1929if (RetOpcode == PPC::TCRETURNdi) {
1930MBBI =MBB.getLastNonDebugInstr();
1931MachineOperand &JumpTarget =MBBI->getOperand(0);
1932if (JumpTarget.isGlobal())
1933BuildMI(MBB,MBBI, dl,TII.get(PPC::TAILB)).
1934 addGlobalAddress(JumpTarget.getGlobal(), JumpTarget.getOffset());
1935elseif (JumpTarget.isSymbol())
1936BuildMI(MBB,MBBI, dl,TII.get(PPC::TAILB)).
1937 addExternalSymbol(JumpTarget.getSymbolName());
1938else
1939llvm_unreachable("Expecting Global or External Symbol");
1940 }elseif (RetOpcode == PPC::TCRETURNri) {
1941MBBI =MBB.getLastNonDebugInstr();
1942assert(MBBI->getOperand(0).isReg() &&"Expecting register operand.");
1943BuildMI(MBB,MBBI, dl,TII.get(PPC::TAILBCTR));
1944 }elseif (RetOpcode == PPC::TCRETURNai) {
1945MBBI =MBB.getLastNonDebugInstr();
1946MachineOperand &JumpTarget =MBBI->getOperand(0);
1947BuildMI(MBB,MBBI, dl,TII.get(PPC::TAILBA)).addImm(JumpTarget.getImm());
1948 }elseif (RetOpcode == PPC::TCRETURNdi8) {
1949MBBI =MBB.getLastNonDebugInstr();
1950MachineOperand &JumpTarget =MBBI->getOperand(0);
1951if (JumpTarget.isGlobal())
1952BuildMI(MBB,MBBI, dl,TII.get(PPC::TAILB8)).
1953 addGlobalAddress(JumpTarget.getGlobal(), JumpTarget.getOffset());
1954elseif (JumpTarget.isSymbol())
1955BuildMI(MBB,MBBI, dl,TII.get(PPC::TAILB8)).
1956 addExternalSymbol(JumpTarget.getSymbolName());
1957else
1958llvm_unreachable("Expecting Global or External Symbol");
1959 }elseif (RetOpcode == PPC::TCRETURNri8) {
1960MBBI =MBB.getLastNonDebugInstr();
1961assert(MBBI->getOperand(0).isReg() &&"Expecting register operand.");
1962BuildMI(MBB,MBBI, dl,TII.get(PPC::TAILBCTR8));
1963 }elseif (RetOpcode == PPC::TCRETURNai8) {
1964MBBI =MBB.getLastNonDebugInstr();
1965MachineOperand &JumpTarget =MBBI->getOperand(0);
1966BuildMI(MBB,MBBI, dl,TII.get(PPC::TAILBA8)).addImm(JumpTarget.getImm());
1967 }
1968}
1969
1970voidPPCFrameLowering::determineCalleeSaves(MachineFunction &MF,
1971BitVector &SavedRegs,
1972RegScavenger *RS) const{
1973TargetFrameLowering::determineCalleeSaves(MF, SavedRegs, RS);
1974if (Subtarget.isAIXABI())
1975updateCalleeSaves(MF, SavedRegs);
1976
1977constPPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();
1978
1979// Do not explicitly save the callee saved VSRp registers.
1980// The individual VSR subregisters will be saved instead.
1981 SavedRegs.reset(PPC::VSRp26);
1982 SavedRegs.reset(PPC::VSRp27);
1983 SavedRegs.reset(PPC::VSRp28);
1984 SavedRegs.reset(PPC::VSRp29);
1985 SavedRegs.reset(PPC::VSRp30);
1986 SavedRegs.reset(PPC::VSRp31);
1987
1988// Save and clear the LR state.
1989PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
1990unsigned LR = RegInfo->getRARegister();
1991 FI->setMustSaveLR(MustSaveLR(MF, LR));
1992 SavedRegs.reset(LR);
1993
1994// Save R31 if necessary
1995int FPSI = FI->getFramePointerSaveIndex();
1996constbool isPPC64 = Subtarget.isPPC64();
1997MachineFrameInfo &MFI = MF.getFrameInfo();
1998
1999// If the frame pointer save index hasn't been defined yet.
2000if (!FPSI &&needsFP(MF)) {
2001// Find out what the fix offset of the frame pointer save area.
2002int FPOffset =getFramePointerSaveOffset();
2003// Allocate the frame index for frame pointer save area.
2004 FPSI = MFI.CreateFixedObject(isPPC64? 8 : 4, FPOffset,true);
2005// Save the result.
2006 FI->setFramePointerSaveIndex(FPSI);
2007 }
2008
2009int BPSI = FI->getBasePointerSaveIndex();
2010if (!BPSI && RegInfo->hasBasePointer(MF)) {
2011int BPOffset =getBasePointerSaveOffset();
2012// Allocate the frame index for the base pointer save area.
2013 BPSI = MFI.CreateFixedObject(isPPC64? 8 : 4, BPOffset,true);
2014// Save the result.
2015 FI->setBasePointerSaveIndex(BPSI);
2016 }
2017
2018// Reserve stack space for the PIC Base register (R30).
2019// Only used in SVR4 32-bit.
2020if (FI->usesPICBase()) {
2021int PBPSI = MFI.CreateFixedObject(4, -8,true);
2022 FI->setPICBasePointerSaveIndex(PBPSI);
2023 }
2024
2025// Make sure we don't explicitly spill r31, because, for example, we have
2026// some inline asm which explicitly clobbers it, when we otherwise have a
2027// frame pointer and are using r31's spill slot for the prologue/epilogue
2028// code. Same goes for the base pointer and the PIC base register.
2029if (needsFP(MF))
2030 SavedRegs.reset(isPPC64 ? PPC::X31 : PPC::R31);
2031if (RegInfo->hasBasePointer(MF)) {
2032 SavedRegs.reset(RegInfo->getBaseRegister(MF));
2033// On AIX, when BaseRegister(R30) is used, need to spill r31 too to match
2034// AIX trackback table requirement.
2035if (!needsFP(MF) && !SavedRegs.test(isPPC64 ? PPC::X31 : PPC::R31) &&
2036 Subtarget.isAIXABI()) {
2037assert(
2038 (RegInfo->getBaseRegister(MF) == (isPPC64 ? PPC::X30 : PPC::R30)) &&
2039"Invalid base register on AIX!");
2040 SavedRegs.set(isPPC64 ? PPC::X31 : PPC::R31);
2041 }
2042 }
2043if (FI->usesPICBase())
2044 SavedRegs.reset(PPC::R30);
2045
2046// Reserve stack space to move the linkage area to in case of a tail call.
2047int TCSPDelta = 0;
2048if (MF.getTarget().Options.GuaranteedTailCallOpt &&
2049 (TCSPDelta = FI->getTailCallSPDelta()) < 0) {
2050 MFI.CreateFixedObject(-1 * TCSPDelta, TCSPDelta,true);
2051 }
2052
2053// Allocate the nonvolatile CR spill slot iff the function uses CR 2, 3, or 4.
2054// For 64-bit SVR4, and all flavors of AIX we create a FixedStack
2055// object at the offset of the CR-save slot in the linkage area. The actual
2056// save and restore of the condition register will be created as part of the
2057// prologue and epilogue insertion, but the FixedStack object is needed to
2058// keep the CalleSavedInfo valid.
2059if ((SavedRegs.test(PPC::CR2) || SavedRegs.test(PPC::CR3) ||
2060 SavedRegs.test(PPC::CR4))) {
2061constuint64_t SpillSize = 4;// Condition register is always 4 bytes.
2062const int64_t SpillOffset =
2063 Subtarget.isPPC64() ? 8 : Subtarget.isAIXABI() ? 4 : -4;
2064int FrameIdx =
2065 MFI.CreateFixedObject(SpillSize, SpillOffset,
2066/* IsImmutable */true,/* IsAliased */false);
2067 FI->setCRSpillFrameIndex(FrameIdx);
2068 }
2069}
2070
2071voidPPCFrameLowering::processFunctionBeforeFrameFinalized(MachineFunction &MF,
2072RegScavenger *RS) const{
2073// Get callee saved register information.
2074MachineFrameInfo &MFI = MF.getFrameInfo();
2075const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
2076
2077// If the function is shrink-wrapped, and if the function has a tail call, the
2078// tail call might not be in the new RestoreBlock, so real branch instruction
2079// won't be generated by emitEpilogue(), because shrink-wrap has chosen new
2080// RestoreBlock. So we handle this case here.
2081if (MFI.getSavePoint() && MFI.hasTailCall()) {
2082MachineBasicBlock *RestoreBlock = MFI.getRestorePoint();
2083for (MachineBasicBlock &MBB : MF) {
2084if (MBB.isReturnBlock() && (&MBB) != RestoreBlock)
2085 createTailCallBranchInstr(MBB);
2086 }
2087 }
2088
2089// Early exit if no callee saved registers are modified!
2090if (CSI.empty() && !needsFP(MF)) {
2091addScavengingSpillSlot(MF, RS);
2092return;
2093 }
2094
2095unsigned MinGPR = PPC::R31;
2096unsigned MinG8R = PPC::X31;
2097unsigned MinFPR = PPC::F31;
2098unsigned MinVR = Subtarget.hasSPE() ? PPC::S31 : PPC::V31;
2099
2100bool HasGPSaveArea =false;
2101bool HasG8SaveArea =false;
2102bool HasFPSaveArea =false;
2103bool HasVRSaveArea =false;
2104
2105SmallVector<CalleeSavedInfo, 18> GPRegs;
2106SmallVector<CalleeSavedInfo, 18> G8Regs;
2107SmallVector<CalleeSavedInfo, 18> FPRegs;
2108SmallVector<CalleeSavedInfo, 18> VRegs;
2109
2110for (constCalleeSavedInfo &I : CSI) {
2111Register Reg =I.getReg();
2112assert((!MF.getInfo<PPCFunctionInfo>()->mustSaveTOC() ||
2113 (Reg != PPC::X2 && Reg != PPC::R2)) &&
2114"Not expecting to try to spill R2 in a function that must save TOC");
2115if (PPC::GPRCRegClass.contains(Reg)) {
2116 HasGPSaveArea =true;
2117
2118 GPRegs.push_back(I);
2119
2120if (Reg < MinGPR) {
2121 MinGPR = Reg;
2122 }
2123 }elseif (PPC::G8RCRegClass.contains(Reg)) {
2124 HasG8SaveArea =true;
2125
2126 G8Regs.push_back(I);
2127
2128if (Reg < MinG8R) {
2129 MinG8R = Reg;
2130 }
2131 }elseif (PPC::F8RCRegClass.contains(Reg)) {
2132 HasFPSaveArea =true;
2133
2134 FPRegs.push_back(I);
2135
2136if (Reg < MinFPR) {
2137 MinFPR = Reg;
2138 }
2139 }elseif (PPC::CRBITRCRegClass.contains(Reg) ||
2140 PPC::CRRCRegClass.contains(Reg)) {
2141 ;// do nothing, as we already know whether CRs are spilled
2142 }elseif (PPC::VRRCRegClass.contains(Reg) ||
2143 PPC::SPERCRegClass.contains(Reg)) {
2144// Altivec and SPE are mutually exclusive, but have the same stack
2145// alignment requirements, so overload the save area for both cases.
2146 HasVRSaveArea =true;
2147
2148 VRegs.push_back(I);
2149
2150if (Reg < MinVR) {
2151 MinVR = Reg;
2152 }
2153 }else {
2154llvm_unreachable("Unknown RegisterClass!");
2155 }
2156 }
2157
2158PPCFunctionInfo *PFI = MF.getInfo<PPCFunctionInfo>();
2159constTargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
2160
2161 int64_t LowerBound = 0;
2162
2163// Take into account stack space reserved for tail calls.
2164int TCSPDelta = 0;
2165if (MF.getTarget().Options.GuaranteedTailCallOpt &&
2166 (TCSPDelta = PFI->getTailCallSPDelta()) < 0) {
2167 LowerBound = TCSPDelta;
2168 }
2169
2170// The Floating-point register save area is right below the back chain word
2171// of the previous stack frame.
2172if (HasFPSaveArea) {
2173for (unsigned i = 0, e = FPRegs.size(); i != e; ++i) {
2174int FI = FPRegs[i].getFrameIdx();
2175
2176 MFI.setObjectOffset(FI, LowerBound + MFI.getObjectOffset(FI));
2177 }
2178
2179 LowerBound -= (31 -TRI->getEncodingValue(MinFPR) + 1) * 8;
2180 }
2181
2182// Check whether the frame pointer register is allocated. If so, make sure it
2183// is spilled to the correct offset.
2184if (needsFP(MF)) {
2185int FI = PFI->getFramePointerSaveIndex();
2186assert(FI &&"No Frame Pointer Save Slot!");
2187 MFI.setObjectOffset(FI, LowerBound + MFI.getObjectOffset(FI));
2188// FP is R31/X31, so no need to update MinGPR/MinG8R.
2189 HasGPSaveArea =true;
2190 }
2191
2192if (PFI->usesPICBase()) {
2193int FI = PFI->getPICBasePointerSaveIndex();
2194assert(FI &&"No PIC Base Pointer Save Slot!");
2195 MFI.setObjectOffset(FI, LowerBound + MFI.getObjectOffset(FI));
2196
2197 MinGPR = std::min<unsigned>(MinGPR, PPC::R30);
2198 HasGPSaveArea =true;
2199 }
2200
2201constPPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();
2202if (RegInfo->hasBasePointer(MF)) {
2203int FI = PFI->getBasePointerSaveIndex();
2204assert(FI &&"No Base Pointer Save Slot!");
2205 MFI.setObjectOffset(FI, LowerBound + MFI.getObjectOffset(FI));
2206
2207Register BP = RegInfo->getBaseRegister(MF);
2208if (PPC::G8RCRegClass.contains(BP)) {
2209 MinG8R = std::min<unsigned>(MinG8R, BP);
2210 HasG8SaveArea =true;
2211 }elseif (PPC::GPRCRegClass.contains(BP)) {
2212 MinGPR = std::min<unsigned>(MinGPR, BP);
2213 HasGPSaveArea =true;
2214 }
2215 }
2216
2217// General register save area starts right below the Floating-point
2218// register save area.
2219if (HasGPSaveArea || HasG8SaveArea) {
2220// Move general register save area spill slots down, taking into account
2221// the size of the Floating-point register save area.
2222for (unsigned i = 0, e = GPRegs.size(); i != e; ++i) {
2223if (!GPRegs[i].isSpilledToReg()) {
2224int FI = GPRegs[i].getFrameIdx();
2225 MFI.setObjectOffset(FI, LowerBound + MFI.getObjectOffset(FI));
2226 }
2227 }
2228
2229// Move general register save area spill slots down, taking into account
2230// the size of the Floating-point register save area.
2231for (unsigned i = 0, e = G8Regs.size(); i != e; ++i) {
2232if (!G8Regs[i].isSpilledToReg()) {
2233int FI = G8Regs[i].getFrameIdx();
2234 MFI.setObjectOffset(FI, LowerBound + MFI.getObjectOffset(FI));
2235 }
2236 }
2237
2238unsigned MinReg =
2239 std::min<unsigned>(TRI->getEncodingValue(MinGPR),
2240TRI->getEncodingValue(MinG8R));
2241
2242constunsigned GPRegSize = Subtarget.isPPC64() ? 8 : 4;
2243 LowerBound -= (31 - MinReg + 1) * GPRegSize;
2244 }
2245
2246// For 32-bit only, the CR save area is below the general register
2247// save area. For 64-bit SVR4, the CR save area is addressed relative
2248// to the stack pointer and hence does not need an adjustment here.
2249// Only CR2 (the first nonvolatile spilled) has an associated frame
2250// index so that we have a single uniform save area.
2251if (spillsCR(MF) && Subtarget.is32BitELFABI()) {
2252// Adjust the frame index of the CR spill slot.
2253for (constauto &CSInfo : CSI) {
2254if (CSInfo.getReg() == PPC::CR2) {
2255int FI = CSInfo.getFrameIdx();
2256 MFI.setObjectOffset(FI, LowerBound + MFI.getObjectOffset(FI));
2257break;
2258 }
2259 }
2260
2261 LowerBound -= 4;// The CR save area is always 4 bytes long.
2262 }
2263
2264// Both Altivec and SPE have the same alignment and padding requirements
2265// within the stack frame.
2266if (HasVRSaveArea) {
2267// Insert alignment padding, we need 16-byte alignment. Note: for positive
2268// number the alignment formula is : y = (x + (n-1)) & (~(n-1)). But since
2269// we are using negative number here (the stack grows downward). We should
2270// use formula : y = x & (~(n-1)). Where x is the size before aligning, n
2271// is the alignment size ( n = 16 here) and y is the size after aligning.
2272assert(LowerBound <= 0 &&"Expect LowerBound have a non-positive value!");
2273 LowerBound &= ~(15);
2274
2275for (unsigned i = 0, e = VRegs.size(); i != e; ++i) {
2276int FI = VRegs[i].getFrameIdx();
2277
2278 MFI.setObjectOffset(FI, LowerBound + MFI.getObjectOffset(FI));
2279 }
2280 }
2281
2282addScavengingSpillSlot(MF, RS);
2283}
2284
2285void
2286PPCFrameLowering::addScavengingSpillSlot(MachineFunction &MF,
2287RegScavenger *RS) const{
2288// Reserve a slot closest to SP or frame pointer if we have a dynalloc or
2289// a large stack, which will require scavenging a register to materialize a
2290// large offset.
2291
2292// We need to have a scavenger spill slot for spills if the frame size is
2293// large. In case there is no free register for large-offset addressing,
2294// this slot is used for the necessary emergency spill. Also, we need the
2295// slot for dynamic stack allocations.
2296
2297// The scavenger might be invoked if the frame offset does not fit into
2298// the 16-bit immediate in case of not SPE and 8-bit in case of SPE.
2299// We don't know the complete frame size here because we've not yet computed
2300// callee-saved register spills or the needed alignment padding.
2301unsigned StackSize =determineFrameLayout(MF,true);
2302MachineFrameInfo &MFI = MF.getFrameInfo();
2303bool NeedSpills = Subtarget.hasSPE() ? !isInt<8>(StackSize) : !isInt<16>(StackSize);
2304
2305if (MFI.hasVarSizedObjects() ||spillsCR(MF) ||hasNonRISpills(MF) ||
2306 (hasSpills(MF) && NeedSpills)) {
2307constTargetRegisterClass &GPRC = PPC::GPRCRegClass;
2308constTargetRegisterClass &G8RC = PPC::G8RCRegClass;
2309constTargetRegisterClass &RC = Subtarget.isPPC64() ? G8RC : GPRC;
2310constTargetRegisterInfo &TRI = *Subtarget.getRegisterInfo();
2311unsignedSize =TRI.getSpillSize(RC);
2312Align Alignment =TRI.getSpillAlign(RC);
2313 RS->addScavengingFrameIndex(MFI.CreateSpillStackObject(Size, Alignment));
2314
2315// Might we have over-aligned allocas?
2316bool HasAlVars =
2317 MFI.hasVarSizedObjects() && MFI.getMaxAlign() >getStackAlign();
2318
2319// These kinds of spills might need two registers.
2320if (spillsCR(MF) || HasAlVars)
2321 RS->addScavengingFrameIndex(MFI.CreateSpillStackObject(Size, Alignment));
2322 }
2323}
2324
2325// This function checks if a callee saved gpr can be spilled to a volatile
2326// vector register. This occurs for leaf functions when the option
2327// ppc-enable-pe-vector-spills is enabled. If there are any remaining registers
2328// which were not spilled to vectors, return false so the target independent
2329// code can handle them by assigning a FrameIdx to a stack slot.
2330boolPPCFrameLowering::assignCalleeSavedSpillSlots(
2331MachineFunction &MF,constTargetRegisterInfo *TRI,
2332 std::vector<CalleeSavedInfo> &CSI) const{
2333
2334if (CSI.empty())
2335returntrue;// Early exit if no callee saved registers are modified!
2336
2337constPPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();
2338constMCPhysReg *CSRegs = RegInfo->getCalleeSavedRegs(&MF);
2339constMachineRegisterInfo &MRI = MF.getRegInfo();
2340
2341if (Subtarget.hasSPE()) {
2342// In case of SPE we only have SuperRegs and CRs
2343// in our CalleSaveInfo vector.
2344
2345for (auto &CalleeSaveReg : CSI) {
2346MCPhysReg Reg = CalleeSaveReg.getReg();
2347MCPhysRegLower = RegInfo->getSubReg(Reg, 1);
2348MCPhysReg Higher = RegInfo->getSubReg(Reg, 2);
2349
2350if (// Check only for SuperRegs.
2351Lower &&
2352// Replace Reg if only lower-32 bits modified
2353 !MRI.isPhysRegModified(Higher))
2354 CalleeSaveReg =CalleeSavedInfo(Lower);
2355 }
2356 }
2357
2358// Early exit if cannot spill gprs to volatile vector registers.
2359MachineFrameInfo &MFI = MF.getFrameInfo();
2360if (!EnablePEVectorSpills || MFI.hasCalls() || !Subtarget.hasP9Vector())
2361returnfalse;
2362
2363// Build a BitVector of VSRs that can be used for spilling GPRs.
2364BitVector BVAllocatable =TRI->getAllocatableSet(MF);
2365BitVector BVCalleeSaved(TRI->getNumRegs());
2366for (unsigned i = 0; CSRegs[i]; ++i)
2367 BVCalleeSaved.set(CSRegs[i]);
2368
2369for (unsigned Reg : BVAllocatable.set_bits()) {
2370// Set to 0 if the register is not a volatile VSX register, or if it is
2371// used in the function.
2372if (BVCalleeSaved[Reg] || !PPC::VSRCRegClass.contains(Reg) ||
2373MRI.isPhysRegUsed(Reg))
2374 BVAllocatable.reset(Reg);
2375 }
2376
2377bool AllSpilledToReg =true;
2378unsigned LastVSRUsedForSpill = 0;
2379for (auto &CS : CSI) {
2380if (BVAllocatable.none())
2381returnfalse;
2382
2383Register Reg = CS.getReg();
2384
2385if (!PPC::G8RCRegClass.contains(Reg)) {
2386 AllSpilledToReg =false;
2387continue;
2388 }
2389
2390// For P9, we can reuse LastVSRUsedForSpill to spill two GPRs
2391// into one VSR using the mtvsrdd instruction.
2392if (LastVSRUsedForSpill != 0) {
2393 CS.setDstReg(LastVSRUsedForSpill);
2394 BVAllocatable.reset(LastVSRUsedForSpill);
2395 LastVSRUsedForSpill = 0;
2396continue;
2397 }
2398
2399unsigned VolatileVFReg = BVAllocatable.find_first();
2400if (VolatileVFReg < BVAllocatable.size()) {
2401 CS.setDstReg(VolatileVFReg);
2402 LastVSRUsedForSpill = VolatileVFReg;
2403 }else {
2404 AllSpilledToReg =false;
2405 }
2406 }
2407return AllSpilledToReg;
2408}
2409
2410boolPPCFrameLowering::spillCalleeSavedRegisters(
2411MachineBasicBlock &MBB,MachineBasicBlock::iteratorMI,
2412ArrayRef<CalleeSavedInfo> CSI,constTargetRegisterInfo *TRI) const{
2413
2414MachineFunction *MF =MBB.getParent();
2415constPPCInstrInfo &TII = *Subtarget.getInstrInfo();
2416PPCFunctionInfo *FI = MF->getInfo<PPCFunctionInfo>();
2417bool MustSaveTOC = FI->mustSaveTOC();
2418DebugLocDL;
2419bool CRSpilled =false;
2420MachineInstrBuilder CRMIB;
2421BitVector Spilled(TRI->getNumRegs());
2422
2423 VSRContainingGPRs.clear();
2424
2425// Map each VSR to GPRs to be spilled with into it. Single VSR can contain one
2426// or two GPRs, so we need table to record information for later save/restore.
2427for (constCalleeSavedInfo &Info : CSI) {
2428if (Info.isSpilledToReg()) {
2429auto &SpilledVSR = VSRContainingGPRs[Info.getDstReg()];
2430assert(SpilledVSR.second == 0 &&
2431"Can't spill more than two GPRs into VSR!");
2432if (SpilledVSR.first == 0)
2433 SpilledVSR.first =Info.getReg();
2434else
2435 SpilledVSR.second =Info.getReg();
2436 }
2437 }
2438
2439for (constCalleeSavedInfo &I : CSI) {
2440Register Reg =I.getReg();
2441
2442// CR2 through CR4 are the nonvolatile CR fields.
2443bool IsCRField = PPC::CR2 <= Reg && Reg <= PPC::CR4;
2444
2445// Add the callee-saved register as live-in; it's killed at the spill.
2446// Do not do this for callee-saved registers that are live-in to the
2447// function because they will already be marked live-in and this will be
2448// adding it for a second time. It is an error to add the same register
2449// to the set more than once.
2450constMachineRegisterInfo &MRI = MF->getRegInfo();
2451bool IsLiveIn =MRI.isLiveIn(Reg);
2452if (!IsLiveIn)
2453MBB.addLiveIn(Reg);
2454
2455if (CRSpilled && IsCRField) {
2456 CRMIB.addReg(Reg,RegState::ImplicitKill);
2457continue;
2458 }
2459
2460// The actual spill will happen in the prologue.
2461if ((Reg == PPC::X2 || Reg == PPC::R2) && MustSaveTOC)
2462continue;
2463
2464// Insert the spill to the stack frame.
2465if (IsCRField) {
2466PPCFunctionInfo *FuncInfo = MF->getInfo<PPCFunctionInfo>();
2467if (!Subtarget.is32BitELFABI()) {
2468// The actual spill will happen at the start of the prologue.
2469 FuncInfo->addMustSaveCR(Reg);
2470 }else {
2471 CRSpilled =true;
2472 FuncInfo->setSpillsCR();
2473
2474// 32-bit: FP-relative. Note that we made sure CR2-CR4 all have
2475// the same frame index in PPCRegisterInfo::hasReservedSpillSlot.
2476 CRMIB =BuildMI(*MF,DL,TII.get(PPC::MFCR), PPC::R12)
2477 .addReg(Reg,RegState::ImplicitKill);
2478
2479MBB.insert(MI, CRMIB);
2480MBB.insert(MI,addFrameReference(BuildMI(*MF,DL,TII.get(PPC::STW))
2481 .addReg(PPC::R12,
2482getKillRegState(true)),
2483I.getFrameIdx()));
2484 }
2485 }else {
2486if (I.isSpilledToReg()) {
2487unsigned Dst =I.getDstReg();
2488
2489if (Spilled[Dst])
2490continue;
2491
2492if (VSRContainingGPRs[Dst].second != 0) {
2493assert(Subtarget.hasP9Vector() &&
2494"mtvsrdd is unavailable on pre-P9 targets.");
2495
2496 NumPESpillVSR += 2;
2497BuildMI(MBB,MI,DL,TII.get(PPC::MTVSRDD), Dst)
2498 .addReg(VSRContainingGPRs[Dst].first,getKillRegState(true))
2499 .addReg(VSRContainingGPRs[Dst].second,getKillRegState(true));
2500 }elseif (VSRContainingGPRs[Dst].second == 0) {
2501assert(Subtarget.hasP8Vector() &&
2502"Can't move GPR to VSR on pre-P8 targets.");
2503
2504 ++NumPESpillVSR;
2505BuildMI(MBB,MI,DL,TII.get(PPC::MTVSRD),
2506TRI->getSubReg(Dst, PPC::sub_64))
2507 .addReg(VSRContainingGPRs[Dst].first,getKillRegState(true));
2508 }else {
2509llvm_unreachable("More than two GPRs spilled to a VSR!");
2510 }
2511 Spilled.set(Dst);
2512 }else {
2513constTargetRegisterClass *RC =TRI->getMinimalPhysRegClass(Reg);
2514// Use !IsLiveIn for the kill flag.
2515// We do not want to kill registers that are live in this function
2516// before their use because they will become undefined registers.
2517// Functions without NoUnwind need to preserve the order of elements in
2518// saved vector registers.
2519if (Subtarget.needsSwapsForVSXMemOps() &&
2520 !MF->getFunction().hasFnAttribute(Attribute::NoUnwind))
2521TII.storeRegToStackSlotNoUpd(MBB,MI, Reg, !IsLiveIn,
2522I.getFrameIdx(), RC,TRI);
2523else
2524TII.storeRegToStackSlot(MBB,MI, Reg, !IsLiveIn,I.getFrameIdx(), RC,
2525TRI,Register());
2526 }
2527 }
2528 }
2529returntrue;
2530}
2531
2532staticvoidrestoreCRs(bool is31,bool CR2Spilled,bool CR3Spilled,
2533bool CR4Spilled,MachineBasicBlock &MBB,
2534MachineBasicBlock::iteratorMI,
2535ArrayRef<CalleeSavedInfo> CSI,unsigned CSIIndex) {
2536
2537MachineFunction *MF =MBB.getParent();
2538constPPCInstrInfo &TII = *MF->getSubtarget<PPCSubtarget>().getInstrInfo();
2539DebugLocDL;
2540unsigned MoveReg = PPC::R12;
2541
2542// 32-bit: FP-relative
2543MBB.insert(MI,
2544addFrameReference(BuildMI(*MF,DL,TII.get(PPC::LWZ), MoveReg),
2545 CSI[CSIIndex].getFrameIdx()));
2546
2547unsigned RestoreOp = PPC::MTOCRF;
2548if (CR2Spilled)
2549MBB.insert(MI,BuildMI(*MF,DL,TII.get(RestoreOp), PPC::CR2)
2550 .addReg(MoveReg,getKillRegState(!CR3Spilled && !CR4Spilled)));
2551
2552if (CR3Spilled)
2553MBB.insert(MI,BuildMI(*MF,DL,TII.get(RestoreOp), PPC::CR3)
2554 .addReg(MoveReg,getKillRegState(!CR4Spilled)));
2555
2556if (CR4Spilled)
2557MBB.insert(MI,BuildMI(*MF,DL,TII.get(RestoreOp), PPC::CR4)
2558 .addReg(MoveReg,getKillRegState(true)));
2559}
2560
2561MachineBasicBlock::iteratorPPCFrameLowering::
2562eliminateCallFramePseudoInstr(MachineFunction &MF,MachineBasicBlock &MBB,
2563MachineBasicBlock::iteratorI) const{
2564constTargetInstrInfo &TII = *Subtarget.getInstrInfo();
2565if (MF.getTarget().Options.GuaranteedTailCallOpt &&
2566I->getOpcode() == PPC::ADJCALLSTACKUP) {
2567// Add (actually subtract) back the amount the callee popped on return.
2568if (int CalleeAmt =I->getOperand(1).getImm()) {
2569boolis64Bit = Subtarget.isPPC64();
2570 CalleeAmt *= -1;
2571unsigned StackReg =is64Bit ? PPC::X1 : PPC::R1;
2572unsigned TmpReg =is64Bit ? PPC::X0 : PPC::R0;
2573unsigned ADDIInstr =is64Bit ? PPC::ADDI8 : PPC::ADDI;
2574unsigned ADDInstr =is64Bit ? PPC::ADD8 : PPC::ADD4;
2575unsigned LISInstr =is64Bit ? PPC::LIS8 : PPC::LIS;
2576unsigned ORIInstr =is64Bit ? PPC::ORI8 : PPC::ORI;
2577constDebugLoc &dl =I->getDebugLoc();
2578
2579if (isInt<16>(CalleeAmt)) {
2580BuildMI(MBB,I, dl,TII.get(ADDIInstr), StackReg)
2581 .addReg(StackReg,RegState::Kill)
2582 .addImm(CalleeAmt);
2583 }else {
2584MachineBasicBlock::iteratorMBBI =I;
2585BuildMI(MBB,MBBI, dl,TII.get(LISInstr), TmpReg)
2586 .addImm(CalleeAmt >> 16);
2587BuildMI(MBB,MBBI, dl,TII.get(ORIInstr), TmpReg)
2588 .addReg(TmpReg,RegState::Kill)
2589 .addImm(CalleeAmt & 0xFFFF);
2590BuildMI(MBB,MBBI, dl,TII.get(ADDInstr), StackReg)
2591 .addReg(StackReg,RegState::Kill)
2592 .addReg(TmpReg);
2593 }
2594 }
2595 }
2596// Simply discard ADJCALLSTACKDOWN, ADJCALLSTACKUP instructions.
2597returnMBB.erase(I);
2598}
2599
2600staticboolisCalleeSavedCR(unsigned Reg) {
2601return PPC::CR2 == Reg || Reg == PPC::CR3 || Reg == PPC::CR4;
2602}
2603
2604boolPPCFrameLowering::restoreCalleeSavedRegisters(
2605MachineBasicBlock &MBB,MachineBasicBlock::iteratorMI,
2606MutableArrayRef<CalleeSavedInfo> CSI,constTargetRegisterInfo *TRI) const{
2607MachineFunction *MF =MBB.getParent();
2608constPPCInstrInfo &TII = *Subtarget.getInstrInfo();
2609PPCFunctionInfo *FI = MF->getInfo<PPCFunctionInfo>();
2610bool MustSaveTOC = FI->mustSaveTOC();
2611bool CR2Spilled =false;
2612bool CR3Spilled =false;
2613bool CR4Spilled =false;
2614unsigned CSIIndex = 0;
2615BitVector Restored(TRI->getNumRegs());
2616
2617// Initialize insertion-point logic; we will be restoring in reverse
2618// order of spill.
2619MachineBasicBlock::iteratorI =MI, BeforeI =I;
2620bool AtStart =I ==MBB.begin();
2621
2622if (!AtStart)
2623 --BeforeI;
2624
2625for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
2626Register Reg = CSI[i].getReg();
2627
2628if ((Reg == PPC::X2 || Reg == PPC::R2) && MustSaveTOC)
2629continue;
2630
2631// Restore of callee saved condition register field is handled during
2632// epilogue insertion.
2633if (isCalleeSavedCR(Reg) && !Subtarget.is32BitELFABI())
2634continue;
2635
2636if (Reg == PPC::CR2) {
2637 CR2Spilled =true;
2638// The spill slot is associated only with CR2, which is the
2639// first nonvolatile spilled. Save it here.
2640 CSIIndex = i;
2641continue;
2642 }elseif (Reg == PPC::CR3) {
2643 CR3Spilled =true;
2644continue;
2645 }elseif (Reg == PPC::CR4) {
2646 CR4Spilled =true;
2647continue;
2648 }else {
2649// On 32-bit ELF when we first encounter a non-CR register after seeing at
2650// least one CR register, restore all spilled CRs together.
2651if (CR2Spilled || CR3Spilled || CR4Spilled) {
2652bool is31 =needsFP(*MF);
2653restoreCRs(is31, CR2Spilled, CR3Spilled, CR4Spilled,MBB,I, CSI,
2654 CSIIndex);
2655 CR2Spilled = CR3Spilled = CR4Spilled =false;
2656 }
2657
2658if (CSI[i].isSpilledToReg()) {
2659DebugLocDL;
2660unsigned Dst = CSI[i].getDstReg();
2661
2662if (Restored[Dst])
2663continue;
2664
2665if (VSRContainingGPRs[Dst].second != 0) {
2666assert(Subtarget.hasP9Vector());
2667 NumPEReloadVSR += 2;
2668BuildMI(MBB,I,DL,TII.get(PPC::MFVSRLD),
2669 VSRContainingGPRs[Dst].second)
2670 .addReg(Dst);
2671BuildMI(MBB,I,DL,TII.get(PPC::MFVSRD),
2672 VSRContainingGPRs[Dst].first)
2673 .addReg(TRI->getSubReg(Dst, PPC::sub_64),getKillRegState(true));
2674 }elseif (VSRContainingGPRs[Dst].second == 0) {
2675assert(Subtarget.hasP8Vector());
2676 ++NumPEReloadVSR;
2677BuildMI(MBB,I,DL,TII.get(PPC::MFVSRD),
2678 VSRContainingGPRs[Dst].first)
2679 .addReg(TRI->getSubReg(Dst, PPC::sub_64),getKillRegState(true));
2680 }else {
2681llvm_unreachable("More than two GPRs spilled to a VSR!");
2682 }
2683
2684 Restored.set(Dst);
2685
2686 }else {
2687// Default behavior for non-CR saves.
2688constTargetRegisterClass *RC =TRI->getMinimalPhysRegClass(Reg);
2689
2690// Functions without NoUnwind need to preserve the order of elements in
2691// saved vector registers.
2692if (Subtarget.needsSwapsForVSXMemOps() &&
2693 !MF->getFunction().hasFnAttribute(Attribute::NoUnwind))
2694TII.loadRegFromStackSlotNoUpd(MBB,I, Reg, CSI[i].getFrameIdx(), RC,
2695TRI);
2696else
2697TII.loadRegFromStackSlot(MBB,I, Reg, CSI[i].getFrameIdx(), RC,TRI,
2698Register());
2699
2700assert(I !=MBB.begin() &&
2701"loadRegFromStackSlot didn't insert any code!");
2702 }
2703 }
2704
2705// Insert in reverse order.
2706if (AtStart)
2707I =MBB.begin();
2708else {
2709I = BeforeI;
2710 ++I;
2711 }
2712 }
2713
2714// If we haven't yet spilled the CRs, do so now.
2715if (CR2Spilled || CR3Spilled || CR4Spilled) {
2716assert(Subtarget.is32BitELFABI() &&
2717"Only set CR[2|3|4]Spilled on 32-bit SVR4.");
2718bool is31 =needsFP(*MF);
2719restoreCRs(is31, CR2Spilled, CR3Spilled, CR4Spilled,MBB,I, CSI, CSIIndex);
2720 }
2721
2722returntrue;
2723}
2724
2725uint64_tPPCFrameLowering::getTOCSaveOffset() const{
2726return TOCSaveOffset;
2727}
2728
2729uint64_tPPCFrameLowering::getFramePointerSaveOffset() const{
2730return FramePointerSaveOffset;
2731}
2732
2733uint64_tPPCFrameLowering::getBasePointerSaveOffset() const{
2734return BasePointerSaveOffset;
2735}
2736
2737boolPPCFrameLowering::enableShrinkWrapping(constMachineFunction &MF) const{
2738if (MF.getInfo<PPCFunctionInfo>()->shrinkWrapDisabled())
2739returnfalse;
2740return !MF.getSubtarget<PPCSubtarget>().is32BitELFABI();
2741}
2742
2743voidPPCFrameLowering::updateCalleeSaves(constMachineFunction &MF,
2744BitVector &SavedRegs) const{
2745// The AIX ABI uses traceback tables for EH which require that if callee-saved
2746// register N is used, all registers N-31 must be saved/restored.
2747// NOTE: The check for AIX is not actually what is relevant. Traceback tables
2748// on Linux have the same requirements. It is just that AIX is the only ABI
2749// for which we actually use traceback tables. If another ABI needs to be
2750// supported that also uses them, we can add a check such as
2751// Subtarget.usesTraceBackTables().
2752assert(Subtarget.isAIXABI() &&
2753"Function updateCalleeSaves should only be called for AIX.");
2754
2755// If there are no callee saves then there is nothing to do.
2756if (SavedRegs.none())
2757return;
2758
2759constMCPhysReg *CSRegs =
2760 Subtarget.getRegisterInfo()->getCalleeSavedRegs(&MF);
2761MCPhysReg LowestGPR = PPC::R31;
2762MCPhysReg LowestG8R = PPC::X31;
2763MCPhysReg LowestFPR = PPC::F31;
2764MCPhysReg LowestVR = PPC::V31;
2765
2766// Traverse the CSRs twice so as not to rely on ascending ordering of
2767// registers in the array. The first pass finds the lowest numbered
2768// register and the second pass marks all higher numbered registers
2769// for spilling.
2770for (int i = 0; CSRegs[i]; i++) {
2771// Get the lowest numbered register for each class that actually needs
2772// to be saved.
2773MCPhysReg Cand = CSRegs[i];
2774if (!SavedRegs.test(Cand))
2775continue;
2776// When R2/X2 is a CSR and not used for passing arguments, it is allocated
2777// earlier than other volatile registers. R2/X2 is not contiguous with
2778// R13/X13 to R31/X31.
2779if (Cand == PPC::X2 || Cand == PPC::R2) {
2780 SavedRegs.set(Cand);
2781continue;
2782 }
2783
2784if (PPC::GPRCRegClass.contains(Cand) && Cand < LowestGPR)
2785 LowestGPR = Cand;
2786elseif (PPC::G8RCRegClass.contains(Cand) && Cand < LowestG8R)
2787 LowestG8R = Cand;
2788elseif ((PPC::F4RCRegClass.contains(Cand) ||
2789 PPC::F8RCRegClass.contains(Cand)) &&
2790 Cand < LowestFPR)
2791 LowestFPR = Cand;
2792elseif (PPC::VRRCRegClass.contains(Cand) && Cand < LowestVR)
2793 LowestVR = Cand;
2794 }
2795
2796for (int i = 0; CSRegs[i]; i++) {
2797MCPhysReg Cand = CSRegs[i];
2798if ((PPC::GPRCRegClass.contains(Cand) && Cand > LowestGPR) ||
2799 (PPC::G8RCRegClass.contains(Cand) && Cand > LowestG8R) ||
2800 ((PPC::F4RCRegClass.contains(Cand) ||
2801 PPC::F8RCRegClass.contains(Cand)) &&
2802 Cand > LowestFPR) ||
2803 (PPC::VRRCRegClass.contains(Cand) && Cand > LowestVR))
2804 SavedRegs.set(Cand);
2805 }
2806}
2807
2808uint64_tPPCFrameLowering::getStackThreshold() const{
2809// On PPC64, we use `stux r1, r1, <scratch_reg>` to extend the stack;
2810// use `add r1, r1, <scratch_reg>` to release the stack frame.
2811// Scratch register contains a signed 64-bit number, which is negative
2812// when extending the stack and is positive when releasing the stack frame.
2813// To make `stux` and `add` paired, the absolute value of the number contained
2814// in the scratch register should be the same. Thus the maximum stack size
2815// is (2^63)-1, i.e., LONG_MAX.
2816if (Subtarget.isPPC64())
2817return LONG_MAX;
2818
2819returnTargetFrameLowering::getStackThreshold();
2820}
MRI
unsigned const MachineRegisterInfo * MRI
Definition:AArch64AdvSIMDScalarPass.cpp:105
MBB
MachineBasicBlock & MBB
Definition:ARMSLSHardening.cpp:71
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition:ARMSLSHardening.cpp:73
MBBI
MachineBasicBlock MachineBasicBlock::iterator MBBI
Definition:ARMSLSHardening.cpp:72
Info
Analysis containing CSE Info
Definition:CSEInfo.cpp:27
Size
uint64_t Size
Definition:ELFObjHandler.cpp:81
TII
const HexagonInstrInfo * TII
Definition:HexagonCopyToCombine.cpp:125
MI
IRTranslator LLVM IR MI
Definition:IRTranslator.cpp:112
Function.h
LivePhysRegs.h
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
I
#define I(x, y, z)
Definition:MD5.cpp:58
MachineFrameInfo.h
MachineFunction.h
MachineInstrBuilder.h
MachineModuleInfo.h
MachineRegisterInfo.h
TRI
unsigned const TargetRegisterInfo * TRI
Definition:MachineSink.cpp:2029
CALLEE_SAVED_VRS
#define CALLEE_SAVED_VRS
hasSpills
static bool hasSpills(const MachineFunction &MF)
Definition:PPCFrameLowering.cpp:257
computeCRSaveOffset
static unsigned computeCRSaveOffset(const PPCSubtarget &STI)
Definition:PPCFrameLowering.cpp:78
restoreCRs
static void restoreCRs(bool is31, bool CR2Spilled, bool CR3Spilled, bool CR4Spilled, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, unsigned CSIIndex)
Definition:PPCFrameLowering.cpp:2532
computeReturnSaveOffset
static unsigned computeReturnSaveOffset(const PPCSubtarget &STI)
Definition:PPCFrameLowering.cpp:43
MustSaveLR
static bool MustSaveLR(const MachineFunction &MF, unsigned LR)
MustSaveLR - Return true if this function requires that we save the LR register onto the stack in the...
Definition:PPCFrameLowering.cpp:270
CALLEE_SAVED_FPRS
#define CALLEE_SAVED_FPRS
EnablePEVectorSpills
static cl::opt< bool > EnablePEVectorSpills("ppc-enable-pe-vector-spills", cl::desc("Enable spills in prologue to vector registers."), cl::init(false), cl::Hidden)
CALLEE_SAVED_GPRS32
#define CALLEE_SAVED_GPRS32
CALLEE_SAVED_GPRS64
#define CALLEE_SAVED_GPRS64
computeLinkageSize
static unsigned computeLinkageSize(const PPCSubtarget &STI)
Definition:PPCFrameLowering.cpp:61
computeFramePointerSaveOffset
static unsigned computeFramePointerSaveOffset(const PPCSubtarget &STI)
Definition:PPCFrameLowering.cpp:56
isCalleeSavedCR
static bool isCalleeSavedCR(unsigned Reg)
Definition:PPCFrameLowering.cpp:2600
computeTOCSaveOffset
static unsigned computeTOCSaveOffset(const PPCSubtarget &STI)
Definition:PPCFrameLowering.cpp:50
hasNonRISpills
static bool hasNonRISpills(const MachineFunction &MF)
Definition:PPCFrameLowering.cpp:262
spillsCR
static bool spillsCR(const MachineFunction &MF)
Definition:PPCFrameLowering.cpp:252
computeBasePointerSaveOffset
static unsigned computeBasePointerSaveOffset(const PPCSubtarget &STI)
Definition:PPCFrameLowering.cpp:69
PPCFrameLowering.h
PPCInstrBuilder.h
PPCInstrInfo.h
PPCMachineFunctionInfo.h
PPCPredicates.h
PPCSubtarget.h
PPCTargetMachine.h
SPReg
static constexpr Register SPReg
Definition:RISCVFrameLowering.cpp:108
FPReg
static constexpr Register FPReg
Definition:RISCVFrameLowering.cpp:105
RegisterScavenging.h
This file declares the machine register scavenger class.
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
contains
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition:Value.cpp:469
Statistic.h
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
STATISTIC
#define STATISTIC(VARNAME, DESC)
Definition:Statistic.h:166
buildDefCFAReg
static void buildDefCFAReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, unsigned Reg, const SystemZInstrInfo *ZII)
Definition:SystemZFrameLowering.cpp:514
TargetOptions.h
is64Bit
static bool is64Bit(const char *name)
Definition:X86Disassembler.cpp:1085
T
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition:ArrayRef.h:168
llvm::BasicBlock
LLVM Basic Block Representation.
Definition:BasicBlock.h:61
llvm::BitVector
Definition:BitVector.h:82
llvm::BitVector::test
bool test(unsigned Idx) const
Definition:BitVector.h:461
llvm::BitVector::reset
BitVector & reset()
Definition:BitVector.h:392
llvm::BitVector::find_first
int find_first() const
find_first - Returns the index of the first set bit, -1 if none of the bits are set.
Definition:BitVector.h:300
llvm::BitVector::count
size_type count() const
count - Returns the number of bits which are set.
Definition:BitVector.h:162
llvm::BitVector::set
BitVector & set()
Definition:BitVector.h:351
llvm::BitVector::find_next
int find_next(unsigned Prev) const
find_next - Returns the index of the next set bit following the "Prev" bit.
Definition:BitVector.h:308
llvm::BitVector::none
bool none() const
none - Returns true if none of the bits are set.
Definition:BitVector.h:188
llvm::BitVector::set_bits
iterator_range< const_set_bits_iterator > set_bits() const
Definition:BitVector.h:140
llvm::BitVector::size
size_type size() const
size - Returns the number of bits in this bitvector.
Definition:BitVector.h:159
llvm::CalleeSavedInfo
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
Definition:MachineFrameInfo.h:34
llvm::DebugLoc
A debug info location.
Definition:DebugLoc.h:33
llvm::Function::getCallingConv
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition:Function.h:277
llvm::Function::hasFnAttribute
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition:Function.cpp:731
llvm::HexagonInstrInfo::storeRegToStackSlot
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
Store the specified register of the given register class to the specified stack frame index.
Definition:HexagonInstrInfo.cpp:962
llvm::HexagonInstrInfo::loadRegFromStackSlot
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
Load the specified register of the given register class from the specified stack frame index.
Definition:HexagonInstrInfo.cpp:1011
llvm::LoadInst
An instruction for reading from memory.
Definition:Instructions.h:176
llvm::MCCFIInstruction::createDefCfaRegister
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_def_cfa_register modifies a rule for computing CFA.
Definition:MCDwarf.h:582
llvm::MCCFIInstruction::createRegister
static MCCFIInstruction createRegister(MCSymbol *L, unsigned Register1, unsigned Register2, SMLoc Loc={})
.cfi_register Previous value of Register1 is saved in register Register2.
Definition:MCDwarf.h:632
llvm::MCCFIInstruction::cfiDefCfa
static MCCFIInstruction cfiDefCfa(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it.
Definition:MCDwarf.h:575
llvm::MCCFIInstruction::createOffset
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
Definition:MCDwarf.h:617
llvm::MCCFIInstruction::cfiDefCfaOffset
static MCCFIInstruction cfiDefCfaOffset(MCSymbol *L, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa_offset modifies a rule for computing CFA.
Definition:MCDwarf.h:590
llvm::MCContext::getRegisterInfo
const MCRegisterInfo * getRegisterInfo() const
Definition:MCContext.h:414
llvm::MCInstrDesc
Describe properties that are true of each instruction in the target description file.
Definition:MCInstrDesc.h:198
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition:MCRegisterInfo.h:149
llvm::MachineBasicBlock
Definition:MachineBasicBlock.h:125
llvm::MachineBasicBlock::transferSuccessorsAndUpdatePHIs
void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
Definition:MachineBasicBlock.cpp:937
llvm::MachineBasicBlock::insert
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
Definition:MachineBasicBlock.cpp:1456
llvm::MachineBasicBlock::getBasicBlock
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
Definition:MachineBasicBlock.h:256
llvm::MachineBasicBlock::getFirstTerminator
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
Definition:MachineBasicBlock.cpp:244
llvm::MachineBasicBlock::isReturnBlock
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction.
Definition:MachineBasicBlock.h:948
llvm::MachineBasicBlock::addSuccessor
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
Definition:MachineBasicBlock.cpp:798
llvm::MachineBasicBlock::begin
iterator begin()
Definition:MachineBasicBlock.h:355
llvm::MachineBasicBlock::findDebugLoc
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any debug instructions.
Definition:MachineBasicBlock.cpp:1516
llvm::MachineBasicBlock::getLastNonDebugInstr
iterator getLastNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the last non-debug instruction in the basic block, or end().
Definition:MachineBasicBlock.cpp:273
llvm::MachineBasicBlock::end
iterator end()
Definition:MachineBasicBlock.h:357
llvm::MachineBasicBlock::addLiveIn
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
Definition:MachineBasicBlock.h:456
llvm::MachineBasicBlock::getParent
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Definition:MachineBasicBlock.h:311
llvm::MachineBasicBlock::erase
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
Definition:MachineBasicBlock.cpp:1443
llvm::MachineBasicBlock::splice
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
Definition:MachineBasicBlock.h:1109
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition:MachineFrameInfo.h:106
llvm::MachineFrameInfo::setMaxCallFrameSize
void setMaxCallFrameSize(uint64_t S)
Definition:MachineFrameInfo.h:676
llvm::MachineFrameInfo::CreateFixedObject
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
Definition:MachineFrameInfo.cpp:83
llvm::MachineFrameInfo::hasVarSizedObjects
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
Definition:MachineFrameInfo.h:357
llvm::MachineFrameInfo::getStackSize
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
Definition:MachineFrameInfo.h:587
llvm::MachineFrameInfo::adjustsStack
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
Definition:MachineFrameInfo.h:617
llvm::MachineFrameInfo::hasCalls
bool hasCalls() const
Return true if the current function has any function calls.
Definition:MachineFrameInfo.h:621
llvm::MachineFrameInfo::isFrameAddressTaken
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
Definition:MachineFrameInfo.h:373
llvm::MachineFrameInfo::getMaxAlign
Align getMaxAlign() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
Definition:MachineFrameInfo.h:603
llvm::MachineFrameInfo::setObjectOffset
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
Definition:MachineFrameInfo.h:562
llvm::MachineFrameInfo::getMaxCallFrameSize
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
Definition:MachineFrameInfo.h:666
llvm::MachineFrameInfo::hasPatchPoint
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
Definition:MachineFrameInfo.h:391
llvm::MachineFrameInfo::getRestorePoint
MachineBasicBlock * getRestorePoint() const
Definition:MachineFrameInfo.h:825
llvm::MachineFrameInfo::CreateSpillStackObject
int CreateSpillStackObject(uint64_t Size, Align Alignment)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
Definition:MachineFrameInfo.cpp:66
llvm::MachineFrameInfo::estimateStackSize
uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
Definition:MachineFrameInfo.cpp:137
llvm::MachineFrameInfo::hasTailCall
bool hasTailCall() const
Returns true if the function contains a tail call.
Definition:MachineFrameInfo.h:646
llvm::MachineFrameInfo::hasStackMap
bool hasStackMap() const
This method may be called any time after instruction selection is complete to determine if there is a...
Definition:MachineFrameInfo.h:385
llvm::MachineFrameInfo::getCalleeSavedInfo
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
Definition:MachineFrameInfo.h:806
llvm::MachineFrameInfo::getObjectOffset
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
Definition:MachineFrameInfo.h:528
llvm::MachineFrameInfo::setStackSize
void setStackSize(uint64_t Size)
Set the size of the stack.
Definition:MachineFrameInfo.h:590
llvm::MachineFrameInfo::isFixedObjectIndex
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
Definition:MachineFrameInfo.h:700
llvm::MachineFrameInfo::getSavePoint
MachineBasicBlock * getSavePoint() const
Definition:MachineFrameInfo.h:823
llvm::MachineFunction
Definition:MachineFunction.h:267
llvm::MachineFunction::addFrameInst
unsigned addFrameInst(const MCCFIInstruction &Inst)
Definition:MachineFunction.cpp:334
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition:MachineFunction.h:733
llvm::MachineFunction::exposesReturnsTwice
bool exposesReturnsTwice() const
exposesReturnsTwice - Returns true if the function calls setjmp or any other similar functions with a...
Definition:MachineFunction.h:795
llvm::MachineFunction::needsFrameMoves
bool needsFrameMoves() const
True if this function needs frame moves for debug or exceptions.
Definition:MachineFunction.cpp:691
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition:MachineFunction.h:749
llvm::MachineFunction::getContext
MCContext & getContext() const
Definition:MachineFunction.h:690
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition:MachineFunction.h:743
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition:MachineFunction.h:704
llvm::MachineFunction::getInfo
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Definition:MachineFunction.h:831
llvm::MachineFunction::front
const MachineBasicBlock & front() const
Definition:MachineFunction.h:959
llvm::MachineFunction::CreateMachineBasicBlock
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
Definition:MachineFunction.cpp:499
llvm::MachineFunction::insert
void insert(iterator MBBI, MachineBasicBlock *MBB)
Definition:MachineFunction.h:966
llvm::MachineFunction::getTarget
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Definition:MachineFunction.h:729
llvm::MachineInstrBuilder
Definition:MachineInstrBuilder.h:71
llvm::MachineInstrBuilder::addCFIIndex
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
Definition:MachineInstrBuilder.h:249
llvm::MachineInstrBuilder::addImm
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Definition:MachineInstrBuilder.h:133
llvm::MachineInstrBuilder::addReg
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Definition:MachineInstrBuilder.h:99
llvm::MachineInstrBuilder::addMBB
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
Definition:MachineInstrBuilder.h:148
llvm::MachineInstrBuilder::addDef
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
Definition:MachineInstrBuilder.h:118
llvm::MachineInstrBundleIterator< MachineInstr >
llvm::MachineInstr
Representation of each machine instruction.
Definition:MachineInstr.h:71
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition:MachineOperand.h:48
llvm::MachineOperand::getGlobal
const GlobalValue * getGlobal() const
Definition:MachineOperand.h:582
llvm::MachineOperand::getImm
int64_t getImm() const
Definition:MachineOperand.h:556
llvm::MachineOperand::isImm
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
Definition:MachineOperand.h:331
llvm::MachineOperand::isSymbol
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
Definition:MachineOperand.h:349
llvm::MachineOperand::isGlobal
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
Definition:MachineOperand.h:347
llvm::MachineOperand::getSymbolName
const char * getSymbolName() const
Definition:MachineOperand.h:637
llvm::MachineOperand::getOffset
int64_t getOffset() const
Return the offset from the symbol in this operand.
Definition:MachineOperand.h:629
llvm::MachineRegisterInfo::defusechain_iterator
reg_begin/reg_end - Provide iteration support to walk over all definitions and uses of a register wit...
Definition:MachineRegisterInfo.h:1050
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition:MachineRegisterInfo.h:51
llvm::MachineRegisterInfo::def_begin
def_iterator def_begin(Register RegNo) const
Definition:MachineRegisterInfo.h:400
llvm::MachineRegisterInfo::def_end
static def_iterator def_end()
Definition:MachineRegisterInfo.h:403
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition:ArrayRef.h:310
llvm::PPCFrameLowering::getReturnSaveOffset
uint64_t getReturnSaveOffset() const
getReturnSaveOffset - Return the previous frame offset to save the return address.
Definition:PPCFrameLowering.h:148
llvm::PPCFrameLowering::needsFP
bool needsFP(const MachineFunction &MF) const
Definition:PPCFrameLowering.cpp:371
llvm::PPCFrameLowering::emitEpilogue
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Definition:PPCFrameLowering.cpp:1542
llvm::PPCFrameLowering::canUseAsEpilogue
bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a epilogue for the target.
Definition:PPCFrameLowering.cpp:558
llvm::PPCFrameLowering::getStackThreshold
uint64_t getStackThreshold() const override
getStackThreshold - Return the maximum stack size
Definition:PPCFrameLowering.cpp:2808
llvm::PPCFrameLowering::processFunctionBeforeFrameFinalized
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
Definition:PPCFrameLowering.cpp:2071
llvm::PPCFrameLowering::hasFPImpl
bool hasFPImpl(const MachineFunction &MF) const override
Definition:PPCFrameLowering.cpp:360
llvm::PPCFrameLowering::getFramePointerSaveOffset
uint64_t getFramePointerSaveOffset() const
getFramePointerSaveOffset - Return the previous frame offset to save the frame pointer.
Definition:PPCFrameLowering.cpp:2729
llvm::PPCFrameLowering::spillCalleeSavedRegisters
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
Definition:PPCFrameLowering.cpp:2410
llvm::PPCFrameLowering::getLinkageSize
unsigned getLinkageSize() const
getLinkageSize - Return the size of the PowerPC ABI linkage area.
Definition:PPCFrameLowering.h:164
llvm::PPCFrameLowering::eliminateCallFramePseudoInstr
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
Definition:PPCFrameLowering.cpp:2562
llvm::PPCFrameLowering::getCalleeSavedSpillSlots
const SpillSlot * getCalleeSavedSpillSlots(unsigned &NumEntries) const override
getCalleeSavedSpillSlots - This method returns a pointer to an array of pairs, that contains an entry...
Definition:PPCFrameLowering.cpp:93
llvm::PPCFrameLowering::determineCalleeSaves
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
Definition:PPCFrameLowering.cpp:1970
llvm::PPCFrameLowering::canUseAsPrologue
bool canUseAsPrologue(const MachineBasicBlock &MBB) const override
Methods used by shrink wrapping to determine if MBB can be used for the function prologue/epilogue.
Definition:PPCFrameLowering.cpp:551
llvm::PPCFrameLowering::emitPrologue
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
Definition:PPCFrameLowering.cpp:608
llvm::PPCFrameLowering::restoreCalleeSavedRegisters
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
Definition:PPCFrameLowering.cpp:2604
llvm::PPCFrameLowering::replaceFPWithRealFP
void replaceFPWithRealFP(MachineFunction &MF) const
Definition:PPCFrameLowering.cpp:386
llvm::PPCFrameLowering::enableShrinkWrapping
bool enableShrinkWrapping(const MachineFunction &MF) const override
Returns true if the target will correctly handle shrink wrapping.
Definition:PPCFrameLowering.cpp:2737
llvm::PPCFrameLowering::determineFrameLayout
uint64_t determineFrameLayout(const MachineFunction &MF, bool UseEstimate=false, unsigned *NewMaxCallFrameSize=nullptr) const
Determine the frame layout but do not update the machine function.
Definition:PPCFrameLowering.cpp:297
llvm::PPCFrameLowering::addScavengingSpillSlot
void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const
Definition:PPCFrameLowering.cpp:2286
llvm::PPCFrameLowering::PPCFrameLowering
PPCFrameLowering(const PPCSubtarget &STI)
Definition:PPCFrameLowering.cpp:82
llvm::PPCFrameLowering::assignCalleeSavedSpillSlots
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
This function will assign callee saved gprs to volatile vector registers for prologue spills when app...
Definition:PPCFrameLowering.cpp:2330
llvm::PPCFrameLowering::determineFrameLayoutAndUpdate
uint64_t determineFrameLayoutAndUpdate(MachineFunction &MF, bool UseEstimate=false) const
Determine the frame layout and update the machine function.
Definition:PPCFrameLowering.cpp:284
llvm::PPCFrameLowering::updateCalleeSaves
void updateCalleeSaves(const MachineFunction &MF, BitVector &SavedRegs) const
Definition:PPCFrameLowering.cpp:2743
llvm::PPCFrameLowering::inlineStackProbe
void inlineStackProbe(MachineFunction &MF, MachineBasicBlock &PrologMBB) const override
Replace a StackProbe stub (if any) with the actual probe code inline.
Definition:PPCFrameLowering.cpp:1238
llvm::PPCFrameLowering::getTOCSaveOffset
uint64_t getTOCSaveOffset() const
getTOCSaveOffset - Return the previous frame offset to save the TOC register – 64-bit SVR4 ABI only.
Definition:PPCFrameLowering.cpp:2725
llvm::PPCFrameLowering::getBasePointerSaveOffset
uint64_t getBasePointerSaveOffset() const
getBasePointerSaveOffset - Return the previous frame offset to save the base pointer.
Definition:PPCFrameLowering.cpp:2733
llvm::PPCFunctionInfo
PPCFunctionInfo - This class is derived from MachineFunction private PowerPC target-specific informat...
Definition:PPCMachineFunctionInfo.h:24
llvm::PPCFunctionInfo::isCRSpilled
bool isCRSpilled() const
Definition:PPCMachineFunctionInfo.h:215
llvm::PPCFunctionInfo::getTailCallSPDelta
int getTailCallSPDelta() const
Definition:PPCMachineFunctionInfo.h:188
llvm::PPCFunctionInfo::getMustSaveCRs
const SmallVectorImpl< Register > & getMustSaveCRs() const
Definition:PPCMachineFunctionInfo.h:276
llvm::PPCFunctionInfo::getPICBasePointerSaveIndex
int getPICBasePointerSaveIndex() const
Definition:PPCMachineFunctionInfo.h:175
llvm::PPCFunctionInfo::shrinkWrapDisabled
bool shrinkWrapDisabled() const
Definition:PPCMachineFunctionInfo.h:206
llvm::PPCFunctionInfo::hasSpills
bool hasSpills() const
Definition:PPCMachineFunctionInfo.h:209
llvm::PPCFunctionInfo::getFramePointerSaveIndex
int getFramePointerSaveIndex() const
Definition:PPCMachineFunctionInfo.h:166
llvm::PPCFunctionInfo::usesPICBase
bool usesPICBase() const
Definition:PPCMachineFunctionInfo.h:280
llvm::PPCFunctionInfo::addMustSaveCR
void addMustSaveCR(Register Reg)
Definition:PPCMachineFunctionInfo.h:277
llvm::PPCFunctionInfo::mustSaveTOC
bool mustSaveTOC() const
Definition:PPCMachineFunctionInfo.h:200
llvm::PPCFunctionInfo::setBasePointerSaveIndex
void setBasePointerSaveIndex(int Idx)
Definition:PPCMachineFunctionInfo.h:173
llvm::PPCFunctionInfo::hasFastCall
bool hasFastCall() const
Definition:PPCMachineFunctionInfo.h:227
llvm::PPCFunctionInfo::hasNonRISpills
bool hasNonRISpills() const
Definition:PPCMachineFunctionInfo.h:212
llvm::PPCFunctionInfo::isLRStoreRequired
bool isLRStoreRequired() const
Definition:PPCMachineFunctionInfo.h:221
llvm::PPCFunctionInfo::setPICBasePointerSaveIndex
void setPICBasePointerSaveIndex(int Idx)
Definition:PPCMachineFunctionInfo.h:176
llvm::PPCFunctionInfo::getROPProtectionHashSaveIndex
int getROPProtectionHashSaveIndex() const
Definition:PPCMachineFunctionInfo.h:178
llvm::PPCFunctionInfo::getMinReservedArea
unsigned getMinReservedArea() const
Definition:PPCMachineFunctionInfo.h:185
llvm::PPCFunctionInfo::setMustSaveLR
void setMustSaveLR(bool U)
MustSaveLR - This is set when the prolog/epilog inserter does its initial scan of the function.
Definition:PPCMachineFunctionInfo.h:196
llvm::PPCFunctionInfo::setCRSpillFrameIndex
void setCRSpillFrameIndex(int idx)
Definition:PPCMachineFunctionInfo.h:273
llvm::PPCFunctionInfo::setSpillsCR
void setSpillsCR()
Definition:PPCMachineFunctionInfo.h:214
llvm::PPCFunctionInfo::mustSaveLR
bool mustSaveLR() const
Definition:PPCMachineFunctionInfo.h:197
llvm::PPCFunctionInfo::getBasePointerSaveIndex
int getBasePointerSaveIndex() const
Definition:PPCMachineFunctionInfo.h:172
llvm::PPCFunctionInfo::setFramePointerSaveIndex
void setFramePointerSaveIndex(int Idx)
Definition:PPCMachineFunctionInfo.h:167
llvm::PPCInstrInfo
Definition:PPCInstrInfo.h:175
llvm::PPCRegisterInfo
Definition:PPCRegisterInfo.h:57
llvm::PPCRegisterInfo::hasBasePointer
bool hasBasePointer(const MachineFunction &MF) const
Definition:PPCRegisterInfo.cpp:1834
llvm::PPCRegisterInfo::getBaseRegister
Register getBaseRegister(const MachineFunction &MF) const
Definition:PPCRegisterInfo.cpp:1820
llvm::PPCRegisterInfo::requiresFrameIndexScavenging
bool requiresFrameIndexScavenging(const MachineFunction &MF) const override
Definition:PPCRegisterInfo.cpp:448
llvm::PPCRegisterInfo::getCalleeSavedRegs
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
Code Generation virtual methods...
Definition:PPCRegisterInfo.cpp:183
llvm::PPCSubtarget
Definition:PPCSubtarget.h:72
llvm::PPCSubtarget::is32BitELFABI
bool is32BitELFABI() const
Definition:PPCSubtarget.h:224
llvm::PPCSubtarget::isAIXABI
bool isAIXABI() const
Definition:PPCSubtarget.h:219
llvm::PPCSubtarget::needsSwapsForVSXMemOps
bool needsSwapsForVSXMemOps() const
Definition:PPCSubtarget.h:207
llvm::PPCSubtarget::isPPC64
bool isPPC64() const
isPPC64 - Return true if we are generating code for 64-bit pointer mode.
Definition:PPCSubtarget.cpp:251
llvm::PPCSubtarget::getTargetLowering
const PPCTargetLowering * getTargetLowering() const override
Definition:PPCSubtarget.h:151
llvm::PPCSubtarget::getInstrInfo
const PPCInstrInfo * getInstrInfo() const override
Definition:PPCSubtarget.h:150
llvm::PPCSubtarget::getRedZoneSize
unsigned getRedZoneSize() const
Definition:PPCSubtarget.h:197
llvm::PPCSubtarget::isSVR4ABI
bool isSVR4ABI() const
Definition:PPCSubtarget.h:220
llvm::PPCSubtarget::is64BitELFABI
bool is64BitELFABI() const
Definition:PPCSubtarget.h:223
llvm::PPCSubtarget::isELFv2ABI
bool isELFv2ABI() const
Definition:PPCSubtarget.cpp:250
llvm::PPCSubtarget::getTargetMachine
const PPCTargetMachine & getTargetMachine() const
Definition:PPCSubtarget.h:160
llvm::PPCSubtarget::getRegisterInfo
const PPCRegisterInfo * getRegisterInfo() const override
Definition:PPCSubtarget.h:157
llvm::PPCTargetLowering
Definition:PPCISelLowering.h:753
llvm::PPCTargetLowering::hasInlineStackProbe
bool hasInlineStackProbe(const MachineFunction &MF) const override
Definition:PPCISelLowering.cpp:12976
llvm::PPCTargetLowering::getStackProbeSize
unsigned getStackProbeSize(const MachineFunction &MF) const
Definition:PPCISelLowering.cpp:12984
llvm::RegScavenger
Definition:RegisterScavenging.h:34
llvm::RegScavenger::enterBasicBlockEnd
void enterBasicBlockEnd(MachineBasicBlock &MBB)
Start tracking liveness from the end of basic block MBB.
Definition:RegisterScavenging.cpp:75
llvm::RegScavenger::isRegUsed
bool isRegUsed(Register Reg, bool includeReserved=true) const
Return if a specific register is currently used.
Definition:RegisterScavenging.cpp:94
llvm::RegScavenger::backward
void backward()
Update internal register state and move MBB iterator backwards.
Definition:RegisterScavenging.cpp:81
llvm::RegScavenger::enterBasicBlock
void enterBasicBlock(MachineBasicBlock &MBB)
Start tracking liveness from the begin of basic block MBB.
Definition:RegisterScavenging.cpp:69
llvm::RegScavenger::addScavengingFrameIndex
void addScavengingFrameIndex(int FI)
Add a scavenging frame index.
Definition:RegisterScavenging.h:112
llvm::RegScavenger::getRegsAvailable
BitVector getRegsAvailable(const TargetRegisterClass *RC)
Return all available registers in the register class in Mask.
Definition:RegisterScavenging.cpp:111
llvm::Register
Wrapper class representing virtual and physical registers.
Definition:Register.h:19
llvm::SmallVectorBase::empty
bool empty() const
Definition:SmallVector.h:81
llvm::SmallVectorBase::size
size_t size() const
Definition:SmallVector.h:78
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition:SmallVector.h:573
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StoreInst
An instruction for storing to memory.
Definition:Instructions.h:292
llvm::TargetFrameLowering
Information about stack frame layout on the target.
Definition:TargetFrameLowering.h:45
llvm::TargetFrameLowering::hasFP
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
Definition:TargetFrameLowering.h:285
llvm::TargetFrameLowering::determineCalleeSaves
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
Definition:TargetFrameLoweringImpl.cpp:95
llvm::TargetFrameLowering::getStackThreshold
virtual uint64_t getStackThreshold() const
getStackThreshold - Return the maximum stack size
Definition:TargetFrameLowering.h:109
llvm::TargetFrameLowering::getStackAlign
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
Definition:TargetFrameLowering.h:105
llvm::TargetInstrInfo
TargetInstrInfo - Interface to description of machine instruction set.
Definition:TargetInstrInfo.h:112
llvm::TargetMachine::isPositionIndependent
bool isPositionIndependent() const
Definition:TargetMachine.cpp:117
llvm::TargetMachine::Options
TargetOptions Options
Definition:TargetMachine.h:118
llvm::TargetOptions::DisableFramePointerElim
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
Definition:TargetOptionsImpl.cpp:24
llvm::TargetOptions::GuaranteedTailCallOpt
unsigned GuaranteedTailCallOpt
GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is specified on the commandline.
Definition:TargetOptions.h:234
llvm::TargetRegisterClass
Definition:TargetRegisterInfo.h:44
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition:TargetRegisterInfo.h:235
llvm::cl::opt
Definition:CommandLine.h:1423
llvm::ilist_node_impl::getIterator
self_iterator getIterator()
Definition:ilist_node.h:132
uint16_t
uint64_t
unsigned
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
llvm::CallingConv::Fast
@ Fast
Attempts to make calls as fast as possible (e.g.
Definition:CallingConv.h:41
llvm::PPC::PRED_GE
@ PRED_GE
Definition:PPCPredicates.h:30
llvm::PPC::PRED_LT
@ PRED_LT
Definition:PPCPredicates.h:27
llvm::RegState::Kill
@ Kill
The last use of a register.
Definition:MachineInstrBuilder.h:50
llvm::RegState::ImplicitKill
@ ImplicitKill
Definition:MachineInstrBuilder.h:66
llvm::cl::Hidden
@ Hidden
Definition:CommandLine.h:137
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition:CommandLine.h:443
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::BuildMI
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Definition:MachineInstrBuilder.h:373
llvm::addFrameReference
static const MachineInstrBuilder & addFrameReference(const MachineInstrBuilder &MIB, int FI, int Offset=0, bool mem=true)
addFrameReference - This function is used to add a reference to the base of an abstract object on the...
Definition:PPCInstrBuilder.h:32
llvm::isPowerOf2_64
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition:MathExtras.h:297
llvm::HexPrintStyle::Lower
@ Lower
llvm::getKillRegState
unsigned getKillRegState(bool B)
Definition:MachineInstrBuilder.h:555
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition:Alignment.h:155
llvm::find_if
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition:STLExtras.h:1766
llvm::Log2
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition:Alignment.h:208
llvm::fullyRecomputeLiveIns
void fullyRecomputeLiveIns(ArrayRef< MachineBasicBlock * > MBBs)
Convenience function for recomputing live-in's for a set of MBBs until the computation converges.
Definition:LivePhysRegs.h:215
RegInfo
Definition:AMDGPUAsmParser.cpp:2770
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition:Alignment.h:39
llvm::TargetFrameLowering::SpillSlot
Definition:TargetFrameLowering.h:53
llvm::cl::desc
Definition:CommandLine.h:409

Generated on Fri Jul 18 2025 14:18:06 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp