LLVM 24.0.0git
CSKYFrameLowering.cpp
Go to the documentation of this file.
1//===-- CSKYFrameLowering.cpp - CSKY 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 CSKY implementation of TargetFrameLowering class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "CSKYFrameLowering.h"
15#include "CSKYSubtarget.h"
23#include "llvm/MC/MCDwarf.h"
24
25using namespace llvm;
26
27#define DEBUG_TYPE "csky-frame-lowering"
28
29// Returns the register used to hold the frame pointer.
30static Register getFPReg(const CSKYSubtarget &STI) { return CSKY::R8; }
31
32// To avoid the BP value clobbered by a function call, we need to choose a
33// callee saved register to save the value.
34static Register getBPReg(const CSKYSubtarget &STI) { return CSKY::R7; }
35
37 const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
38
39 const MachineFrameInfo &MFI = MF.getFrameInfo();
40 return MF.disableFramePointerElim() || RegInfo->hasStackRealignment(MF) ||
42}
43
45 const MachineFrameInfo &MFI = MF.getFrameInfo();
46
47 return MFI.hasVarSizedObjects();
48}
49
50// Determines the size of the frame and maximum call frame size.
51void CSKYFrameLowering::determineFrameLayout(MachineFunction &MF) const {
53 const CSKYRegisterInfo *RI = STI.getRegisterInfo();
54
55 // Get the number of bytes to allocate from the FrameInfo.
56 uint64_t FrameSize = MFI.getStackSize();
57
58 // Get the alignment.
59 Align StackAlign = getStackAlign();
60 if (RI->hasStackRealignment(MF)) {
61 Align MaxStackAlign = std::max(StackAlign, MFI.getMaxAlign());
62 FrameSize += (MaxStackAlign.value() - StackAlign.value());
63 StackAlign = MaxStackAlign;
64 }
65
66 // Set Max Call Frame Size
67 uint64_t MaxCallSize = alignTo(MFI.getMaxCallFrameSize(), StackAlign);
68 MFI.setMaxCallFrameSize(MaxCallSize);
69
70 // Make sure the frame is aligned.
71 FrameSize = alignTo(FrameSize, StackAlign);
72
73 // Update frame info.
74 MFI.setStackSize(FrameSize);
75}
76
78 MachineBasicBlock &MBB) const {
81 const CSKYRegisterInfo *RI = STI.getRegisterInfo();
82 const CSKYInstrInfo *TII = STI.getInstrInfo();
85 const MachineRegisterInfo &MRI = MF.getRegInfo();
86
87 Register FPReg = getFPReg(STI);
88 Register SPReg = CSKY::R14;
89 Register BPReg = getBPReg(STI);
90
91 // Debug location must be unknown since the first debug location is used
92 // to determine the end of the prologue.
94
95 if (MF.getFunction().hasFnAttribute("interrupt"))
96 BuildMI(MBB, MBBI, DL, TII->get(CSKY::NIE));
97
98 // Determine the correct frame layout
99 determineFrameLayout(MF);
100
101 // FIXME (note copied from Lanai): This appears to be overallocating. Needs
102 // investigation. Get the number of bytes to allocate from the FrameInfo.
103 uint64_t StackSize = MFI.getStackSize();
104
105 // Early exit if there is no need to allocate on the stack
106 if (StackSize == 0 && !MFI.adjustsStack())
107 return;
108
109 const auto &CSI = MFI.getCalleeSavedInfo();
110
111 unsigned spillAreaSize = CFI->getCalleeSaveAreaSize();
112
113 uint64_t ActualSize = spillAreaSize + CFI->getVarArgsSaveSize();
114
115 // First part stack allocation.
116 adjustReg(MBB, MBBI, DL, SPReg, SPReg, -(static_cast<int64_t>(ActualSize)),
118
119 // Emit ".cfi_def_cfa_offset FirstSPAdjustAmount"
120 unsigned CFIIndex =
121 MF.addFrameInst(MCCFIInstruction::cfiDefCfaOffset(nullptr, ActualSize));
122 BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
123 .addCFIIndex(CFIIndex);
124
125 // The frame pointer is callee-saved, and code has been generated for us to
126 // save it to the stack. We need to skip over the storing of callee-saved
127 // registers as the frame pointer must be modified after it has been saved
128 // to the stack, not before.
129 // FIXME: assumes exactly one instruction is used to save each callee-saved
130 // register.
131 std::advance(MBBI, CSI.size());
132
133 // Iterate over list of callee-saved registers and emit .cfi_offset
134 // directives.
135 for (const auto &Entry : CSI) {
136 int64_t Offset = MFI.getObjectOffset(Entry.getFrameIdx());
137 MCRegister Reg = Entry.getReg();
138
139 unsigned Num = TRI->getRegSizeInBits(Reg, MRI) / 32;
140 for (unsigned i = 0; i < Num; i++) {
141 unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset(
142 nullptr, RI->getDwarfRegNum(Reg, true) + i, Offset + i * 4));
143 BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
144 .addCFIIndex(CFIIndex);
145 }
146 }
147
148 // Generate new FP.
149 if (hasFP(MF)) {
150 BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::COPY), FPReg)
151 .addReg(SPReg)
153
154 // Emit ".cfi_def_cfa_register $fp"
156 nullptr, RI->getDwarfRegNum(FPReg, true)));
157 BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
158 .addCFIIndex(CFIIndex);
159
160 // Second part stack allocation.
161 adjustReg(MBB, MBBI, DL, SPReg, SPReg,
162 -(static_cast<int64_t>(StackSize - ActualSize)),
164
165 // Realign Stack
166 const CSKYRegisterInfo *RI = STI.getRegisterInfo();
167 if (RI->hasStackRealignment(MF)) {
168 Align MaxAlignment = MFI.getMaxAlign();
169
170 const CSKYInstrInfo *TII = STI.getInstrInfo();
171 if (STI.hasE2() && isUInt<12>(~(-(int)MaxAlignment.value()))) {
172 BuildMI(MBB, MBBI, DL, TII->get(CSKY::ANDNI32), SPReg)
173 .addReg(SPReg)
174 .addImm(~(-(int)MaxAlignment.value()));
175 } else {
176 unsigned ShiftAmount = Log2(MaxAlignment);
177
178 if (STI.hasE2()) {
179 Register VR =
180 MF.getRegInfo().createVirtualRegister(&CSKY::GPRRegClass);
181 BuildMI(MBB, MBBI, DL, TII->get(CSKY::LSRI32), VR)
182 .addReg(SPReg)
183 .addImm(ShiftAmount);
184 BuildMI(MBB, MBBI, DL, TII->get(CSKY::LSLI32), SPReg)
185 .addReg(VR)
186 .addImm(ShiftAmount);
187 } else {
188 Register VR =
189 MF.getRegInfo().createVirtualRegister(&CSKY::mGPRRegClass);
190 BuildMI(MBB, MBBI, DL, TII->get(CSKY::MOV16), VR).addReg(SPReg);
191 BuildMI(MBB, MBBI, DL, TII->get(CSKY::LSRI16), VR)
192 .addReg(VR)
193 .addImm(ShiftAmount);
194 BuildMI(MBB, MBBI, DL, TII->get(CSKY::LSLI16), VR)
195 .addReg(VR)
196 .addImm(ShiftAmount);
197 BuildMI(MBB, MBBI, DL, TII->get(CSKY::MOV16), SPReg).addReg(VR);
198 }
199 }
200 }
201
202 // FP will be used to restore the frame in the epilogue, so we need
203 // another base register BP to record SP after re-alignment. SP will
204 // track the current stack after allocating variable sized objects.
205 if (hasBP(MF)) {
206 // move BP, SP
207 BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::COPY), BPReg).addReg(SPReg);
208 }
209
210 } else {
211 adjustReg(MBB, MBBI, DL, SPReg, SPReg,
212 -(static_cast<int64_t>(StackSize - ActualSize)),
214 // Emit ".cfi_def_cfa_offset StackSize"
215 unsigned CFIIndex = MF.addFrameInst(
216 MCCFIInstruction::cfiDefCfaOffset(nullptr, MFI.getStackSize()));
217 BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
218 .addCFIIndex(CFIIndex);
219 }
220}
221
223 MachineBasicBlock &MBB) const {
225
226 MachineFrameInfo &MFI = MF.getFrameInfo();
227 Register FPReg = getFPReg(STI);
228 Register SPReg = CSKY::R14;
229
230 // Get the insert location for the epilogue. If there were no terminators in
231 // the block, get the last instruction.
233 DebugLoc DL;
234 if (!MBB.empty()) {
235 MBBI = MBB.getFirstTerminator();
236 if (MBBI == MBB.end())
237 MBBI = MBB.getLastNonDebugInstr();
238 DL = MBBI->getDebugLoc();
239
240 // If this is not a terminator, the actual insert location should be after
241 // the last instruction.
242 if (!MBBI->isTerminator())
243 MBBI = std::next(MBBI);
244 }
245
246 const auto &CSI = MFI.getCalleeSavedInfo();
247 uint64_t StackSize = MFI.getStackSize();
248
249 uint64_t ActualSize =
251
252 // Skip to before the restores of callee-saved registers
253 // FIXME: assumes exactly one instruction is used to restore each
254 // callee-saved register.
255 auto LastFrameDestroy = MBBI;
256 if (!CSI.empty())
257 LastFrameDestroy = std::prev(MBBI, CSI.size());
258
259 if (hasFP(MF)) {
260 const CSKYInstrInfo *TII = STI.getInstrInfo();
261 BuildMI(MBB, LastFrameDestroy, DL, TII->get(TargetOpcode::COPY), SPReg)
262 .addReg(FPReg)
264 } else {
265 adjustReg(MBB, LastFrameDestroy, DL, SPReg, SPReg, (StackSize - ActualSize),
267 }
268
269 adjustReg(MBB, MBBI, DL, SPReg, SPReg, ActualSize,
271}
272
274 const CSKYInstrInfo &TII) {
275 unsigned FnSize = 0;
276 for (auto &MBB : MF) {
277 for (auto &MI : MBB)
278 FnSize += TII.getInstSizeInBytes(MI);
279 }
280 FnSize += MF.getConstantPool()->getConstants().size() * 4;
281 return FnSize;
282}
283
285 const CSKYSubtarget &STI) {
286 unsigned Limit = (1 << 12) - 1;
287
288 for (auto &MBB : MF) {
289 for (auto &MI : MBB) {
290 if (MI.isDebugInstr())
291 continue;
292
293 for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
294 if (!MI.getOperand(i).isFI())
295 continue;
296
297 if (MI.getOpcode() == CSKY::SPILL_CARRY ||
298 MI.getOpcode() == CSKY::RESTORE_CARRY ||
299 MI.getOpcode() == CSKY::STORE_PAIR ||
300 MI.getOpcode() == CSKY::LOAD_PAIR) {
301 Limit = std::min(Limit, ((1U << 12) - 1) * 4);
302 break;
303 }
304
305 if (MI.getOpcode() == CSKY::ADDI32) {
306 Limit = std::min(Limit, (1U << 12));
307 break;
308 }
309
310 if (MI.getOpcode() == CSKY::ADDI16XZ) {
311 Limit = std::min(Limit, (1U << 3));
312 break;
313 }
314
315 // ADDI16 will not require an extra register,
316 // it can reuse the destination.
317 if (MI.getOpcode() == CSKY::ADDI16)
318 break;
319
320 // Otherwise check the addressing mode.
321 switch (MI.getDesc().TSFlags & CSKYII::AddrModeMask) {
322 default:
323 LLVM_DEBUG(MI.dump());
325 "Unhandled addressing mode in stack size limit calculation");
327 Limit = std::min(Limit, (1U << 12) - 1);
328 break;
330 Limit = std::min(Limit, ((1U << 12) - 1) * 2);
331 break;
333 Limit = std::min(Limit, ((1U << 12) - 1) * 4);
334 break;
336 Limit = std::min(Limit, (1U << 5) - 1);
337 break;
339 Limit = std::min(Limit, ((1U << 5) - 1) * 2);
340 break;
342 Limit = std::min(Limit, ((1U << 5) - 1) * 4);
343 break;
345 Limit = std::min(Limit, ((1U << 8) - 1) * 4);
346 break;
347 }
348 break; // At most one FI per instruction
349 }
350 }
351 }
352
353 return Limit;
354}
355
357 BitVector &SavedRegs,
358 RegScavenger *RS) const {
360
363 const CSKYInstrInfo *TII = STI.getInstrInfo();
364 const MachineRegisterInfo &MRI = MF.getRegInfo();
365 MachineFrameInfo &MFI = MF.getFrameInfo();
366
367 if (hasFP(MF))
368 SavedRegs.set(CSKY::R8);
369
370 // Mark BP as used if function has dedicated base pointer.
371 if (hasBP(MF))
372 SavedRegs.set(CSKY::R7);
373
374 // If interrupt is enabled and there are calls in the handler,
375 // unconditionally save all Caller-saved registers and
376 // all FP registers, regardless whether they are used.
377 if (MF.getFunction().hasFnAttribute("interrupt") && MFI.hasCalls()) {
378
379 static const MCPhysReg CSRegs[] = {CSKY::R0, CSKY::R1, CSKY::R2, CSKY::R3,
380 CSKY::R12, CSKY::R13, 0};
381
382 for (unsigned i = 0; CSRegs[i]; ++i)
383 SavedRegs.set(CSRegs[i]);
384
385 if (STI.hasHighRegisters()) {
386
387 static const MCPhysReg CSHRegs[] = {CSKY::R18, CSKY::R19, CSKY::R20,
388 CSKY::R21, CSKY::R22, CSKY::R23,
389 CSKY::R24, CSKY::R25, 0};
390
391 for (unsigned i = 0; CSHRegs[i]; ++i)
392 SavedRegs.set(CSHRegs[i]);
393 }
394
395 static const MCPhysReg CSF32Regs[] = {
396 CSKY::F8_32, CSKY::F9_32, CSKY::F10_32,
397 CSKY::F11_32, CSKY::F12_32, CSKY::F13_32,
398 CSKY::F14_32, CSKY::F15_32, 0};
399 static const MCPhysReg CSF64Regs[] = {
400 CSKY::F8_64, CSKY::F9_64, CSKY::F10_64,
401 CSKY::F11_64, CSKY::F12_64, CSKY::F13_64,
402 CSKY::F14_64, CSKY::F15_64, 0};
403
404 const MCPhysReg *FRegs = NULL;
405 if (STI.hasFPUv2DoubleFloat() || STI.hasFPUv3DoubleFloat())
406 FRegs = CSF64Regs;
407 else if (STI.hasFPUv2SingleFloat() || STI.hasFPUv3SingleFloat())
408 FRegs = CSF32Regs;
409
410 if (FRegs != NULL) {
411 const MCPhysReg *Regs = MF.getRegInfo().getCalleeSavedRegs();
412
413 for (unsigned i = 0; Regs[i]; ++i)
414 if (CSKY::FPR32RegClass.contains(Regs[i]) ||
415 CSKY::FPR64RegClass.contains(Regs[i])) {
416 unsigned x = 0;
417 for (; FRegs[x]; ++x)
418 if (FRegs[x] == Regs[i])
419 break;
420 if (FRegs[x] == 0)
421 SavedRegs.set(Regs[i]);
422 }
423 }
424 }
425
426 unsigned CSStackSize = 0;
427 for (unsigned Reg : SavedRegs.set_bits()) {
428 auto RegSize = TRI->getRegSizeInBits(Reg, MRI) / 8;
429 CSStackSize += RegSize;
430 }
431
432 CFI->setCalleeSaveAreaSize(CSStackSize);
433
434 uint64_t Limit = estimateRSStackSizeLimit(MF, STI);
435
436 bool BigFrame = (MFI.estimateStackSize(MF) + CSStackSize >= Limit);
437
438 if (BigFrame || CFI->isCRSpilled() || !STI.hasE2()) {
439 const TargetRegisterClass *RC = &CSKY::GPRRegClass;
440 unsigned size = TRI->getSpillSize(*RC);
441 Align align = TRI->getSpillAlign(*RC);
442
443 RS->addScavengingFrameIndex(MFI.CreateSpillStackObject(size, align));
444 }
445
446 unsigned FnSize = EstimateFunctionSizeInBytes(MF, *TII);
447 // Force R15 to be spilled if the function size is > 65534. This enables
448 // use of BSR to implement far jump.
449 if (FnSize >= ((1 << (16 - 1)) * 2))
450 SavedRegs.set(CSKY::R15);
451
452 CFI->setLRIsSpilled(SavedRegs.test(CSKY::R15));
453}
454
455// Not preserve stack space within prologue for outgoing variables when the
456// function contains variable size objects and let eliminateCallFramePseudoInstr
457// preserve stack space for it.
461
465 if (CSI.empty())
466 return true;
467
468 MachineFunction *MF = MBB.getParent();
470 DebugLoc DL;
471 if (MI != MBB.end() && !MI->isDebugInstr())
472 DL = MI->getDebugLoc();
473
474 for (auto &CS : CSI) {
475 // Insert the spill to the stack frame.
476 MCRegister Reg = CS.getReg();
477 const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
478 TII.storeRegToStackSlot(MBB, MI, Reg, true, CS.getFrameIdx(), RC,
479 Register());
480 }
481
482 return true;
483}
484
488 if (CSI.empty())
489 return true;
490
491 MachineFunction *MF = MBB.getParent();
493 DebugLoc DL;
494 if (MI != MBB.end() && !MI->isDebugInstr())
495 DL = MI->getDebugLoc();
496
497 for (auto &CS : reverse(CSI)) {
498 MCRegister Reg = CS.getReg();
499 const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
500 TII.loadRegFromStackSlot(MBB, MI, Reg, CS.getFrameIdx(), RC, Register());
501 assert(MI != MBB.begin() && "loadRegFromStackSlot didn't insert any code!");
502 }
503
504 return true;
505}
506
507// Eliminate ADJCALLSTACKDOWN, ADJCALLSTACKUP pseudo instructions.
511 Register SPReg = CSKY::R14;
512 DebugLoc DL = MI->getDebugLoc();
513
514 if (!hasReservedCallFrame(MF)) {
515 // If space has not been reserved for a call frame, ADJCALLSTACKDOWN and
516 // ADJCALLSTACKUP must be converted to instructions manipulating the stack
517 // pointer. This is necessary when there is a variable length stack
518 // allocation (e.g. alloca), which means it's not possible to allocate
519 // space for outgoing arguments from within the function prologue.
520 int64_t Amount = MI->getOperand(0).getImm();
521
522 if (Amount != 0) {
523 // Ensure the stack remains aligned after adjustment.
524 Amount = alignSPAdjust(Amount);
525
526 if (MI->getOpcode() == CSKY::ADJCALLSTACKDOWN)
527 Amount = -Amount;
528
529 adjustReg(MBB, MI, DL, SPReg, SPReg, Amount, MachineInstr::NoFlags);
530 }
531 }
532
533 return MBB.erase(MI);
534}
535
536void CSKYFrameLowering::adjustReg(MachineBasicBlock &MBB,
538 const DebugLoc &DL, Register DestReg,
539 Register SrcReg, int64_t Val,
540 MachineInstr::MIFlag Flag) const {
541 const CSKYInstrInfo *TII = STI.getInstrInfo();
542
543 if (DestReg == SrcReg && Val == 0)
544 return;
545
546 // TODO: Add 16-bit instruction support with immediate num
547 if (STI.hasE2() && isUInt<12>(std::abs(Val) - 1)) {
548 BuildMI(MBB, MBBI, DL, TII->get(Val < 0 ? CSKY::SUBI32 : CSKY::ADDI32),
549 DestReg)
550 .addReg(SrcReg)
551 .addImm(std::abs(Val))
552 .setMIFlag(Flag);
553 } else if (!STI.hasE2() && isShiftedUInt<7, 2>(std::abs(Val))) {
554 BuildMI(MBB, MBBI, DL,
555 TII->get(Val < 0 ? CSKY::SUBI16SPSP : CSKY::ADDI16SPSP), CSKY::R14)
556 .addReg(CSKY::R14, RegState::Kill)
557 .addImm(std::abs(Val))
558 .setMIFlag(Flag);
559 } else {
560
561 unsigned Op = 0;
562
563 if (STI.hasE2()) {
564 Op = Val < 0 ? CSKY::SUBU32 : CSKY::ADDU32;
565 } else {
566 assert(SrcReg == DestReg);
567 Op = Val < 0 ? CSKY::SUBU16XZ : CSKY::ADDU16XZ;
568 }
569
570 Register ScratchReg = TII->movImm(MBB, MBBI, DL, std::abs(Val), Flag);
571
572 BuildMI(MBB, MBBI, DL, TII->get(Op), DestReg)
573 .addReg(SrcReg)
574 .addReg(ScratchReg, RegState::Kill)
575 .setMIFlag(Flag);
576 }
577}
578
581 Register &FrameReg) const {
583 const MachineFrameInfo &MFI = MF.getFrameInfo();
585 const auto &CSI = MFI.getCalleeSavedInfo();
586
587 int MinCSFI = 0;
588 int MaxCSFI = -1;
589
590 int Offset = MFI.getObjectOffset(FI) + MFI.getOffsetAdjustment();
591
592 if (CSI.size()) {
593 MinCSFI = CSI[0].getFrameIdx();
594 MaxCSFI = CSI[CSI.size() - 1].getFrameIdx();
595 }
596
597 if (FI >= MinCSFI && FI <= MaxCSFI) {
598 FrameReg = CSKY::R14;
600 } else if (RI->hasStackRealignment(MF)) {
601 assert(hasFP(MF));
602 if (!MFI.isFixedObjectIndex(FI)) {
603 FrameReg = hasBP(MF) ? getBPReg(STI) : CSKY::R14;
604 Offset += MFI.getStackSize();
605 } else {
606 FrameReg = getFPReg(STI);
608 }
609 } else {
610 if (MFI.isFixedObjectIndex(FI) && hasFP(MF)) {
611 FrameReg = getFPReg(STI);
613 } else {
614 FrameReg = hasBP(MF) ? getBPReg(STI) : CSKY::R14;
615 Offset += MFI.getStackSize();
616 }
617 }
618
620}
static unsigned estimateRSStackSizeLimit(MachineFunction &MF)
Look at each instruction that references stack frames and return the stack size limit beyond which so...
unsigned RegSize
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
static unsigned EstimateFunctionSizeInBytes(const MachineFunction &MF, const ARMBaseInstrInfo &TII, const ARMSubtarget &STI, const ARMBaseRegisterInfo *RegInfo, BitVector &SavedRegs, bool BigFrameOffsets)
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static Register getBPReg(const CSKYSubtarget &STI)
static Register getFPReg(const CSKYSubtarget &STI)
static uint64_t align(uint64_t Size)
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
static constexpr MCPhysReg FPReg
static constexpr MCPhysReg SPReg
This file declares the machine register scavenger class.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:484
#define LLVM_DEBUG(...)
Definition Debug.h:119
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
bool test(unsigned Idx) const
Returns true if bit Idx is set.
Definition BitVector.h:482
BitVector & set()
Set all bits in the bitvector.
Definition BitVector.h:366
iterator_range< const_set_bits_iterator > set_bits() const
Definition BitVector.h:159
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
bool hasFPImpl(const MachineFunction &MF) const override
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
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...
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
bool hasBP(const MachineFunction &MF) const
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...
const CSKYRegisterInfo * getRegisterInfo() const override
const CSKYInstrInfo * getInstrInfo() const override
A debug info location.
Definition DebugLoc.h:126
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition Function.cpp:730
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_def_cfa_register modifies a rule for computing CFA.
Definition MCDwarf.h:635
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:670
static MCCFIInstruction cfiDefCfaOffset(MCSymbol *L, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa_offset modifies a rule for computing CFA.
Definition MCDwarf.h:643
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
MachineInstrBundleIterator< MachineInstr > iterator
const std::vector< MachineConstantPoolEntry > & getConstants() const
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
void setMaxCallFrameSize(uint64_t S)
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
bool hasCalls() const
Return true if the current function has any function calls.
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
Align getMaxAlign() const
Return alignment of this function's frame.
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
LLVM_ABI uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
LLVM_ABI int CreateSpillStackObject(uint64_t Size, Align Alignment, TargetStackID::Value StackID=TargetStackID::Default)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
void setStackSize(uint64_t Size)
Set the size of the stack.
unsigned addFrameInst(const MCCFIInstruction &Inst)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
LLVM_ABI bool disableFramePointerElim() const
Returns true if frame pointer elimination should be disabled for this function.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
LLVM_ABI const MCPhysReg * getCalleeSavedRegs() const
Returns list of callee saved registers.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
Wrapper class representing virtual and physical registers.
Definition Register.h:20
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:30
int64_t getFixed() const
Returns the fixed component of the stack.
Definition TypeSize.h:46
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
int alignSPAdjust(int SPAdj) const
alignSPAdjust - This method aligns the stack adjustment to the correct alignment.
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool hasStackRealignment(const MachineFunction &MF) const
True if stack realignment is required and still possible.
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1669
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
@ Kill
The last use of a register.
auto reverse(ContainerTy &&C)
Definition STLExtras.h:407
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
DWARFExpression::Operation Op
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition Alignment.h:197
constexpr bool isShiftedUInt(uint64_t x)
Checks if a unsigned integer is an N bit number shifted left by S.
Definition MathExtras.h:199
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:77