LLVM 23.0.0git
CFIInstrInserter.cpp
Go to the documentation of this file.
1//===------ CFIInstrInserter.cpp - Insert additional CFI instructions -----===//
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/// \file This pass verifies incoming and outgoing CFA information of basic
10/// blocks. CFA information is information about offset and register set by CFI
11/// directives, valid at the start and end of a basic block. This pass checks
12/// that outgoing information of predecessors matches incoming information of
13/// their successors. Then it checks if blocks have correct CFA calculation rule
14/// set and inserts additional CFI instruction at their beginnings if they
15/// don't. CFI instructions are inserted if basic blocks have incorrect offset
16/// or register set by previous blocks, as a result of a non-linear layout of
17/// blocks in a function.
18//===----------------------------------------------------------------------===//
19
23#include "llvm/CodeGen/Passes.h"
28#include "llvm/MC/MCContext.h"
29#include "llvm/MC/MCDwarf.h"
30using namespace llvm;
31
32static cl::opt<bool> VerifyCFI("verify-cfiinstrs",
33 cl::desc("Verify Call Frame Information instructions"),
34 cl::init(false),
36
37namespace {
38class CFIInstrInserter : public MachineFunctionPass {
39 public:
40 static char ID;
41
42 CFIInstrInserter() : MachineFunctionPass(ID) {}
43
44 void getAnalysisUsage(AnalysisUsage &AU) const override {
45 AU.setPreservesAll();
47 }
48
49 bool runOnMachineFunction(MachineFunction &MF) override {
50 if (!MF.needsFrameMoves())
51 return false;
52
53 MBBVector.resize(MF.getNumBlockIDs());
54 calculateCFAInfo(MF);
55
56 if (VerifyCFI) {
57 if (unsigned ErrorNum = verify(MF))
58 report_fatal_error("Found " + Twine(ErrorNum) +
59 " in/out CFI information errors.");
60 }
61 bool insertedCFI = insertCFIInstrs(MF);
62 MBBVector.clear();
63 return insertedCFI;
64 }
65
66private:
67 /// contains the location where CSR register is saved.
68 class CSRSavedLocation {
69 public:
70 enum Kind { Invalid, Register, CFAOffset };
71 Kind K = Invalid;
72
73 private:
74 union {
75 // Dwarf register number
76 unsigned Reg;
77 // CFA offset
78 int64_t Offset;
79 };
80
81 public:
82 CSRSavedLocation() {}
83
84 static CSRSavedLocation createCFAOffset(int64_t Offset) {
85 CSRSavedLocation Loc;
86 Loc.K = Kind::CFAOffset;
87 Loc.Offset = Offset;
88 return Loc;
89 }
90
91 static CSRSavedLocation createRegister(unsigned Reg) {
92 CSRSavedLocation Loc;
93 Loc.K = Kind::Register;
94 Loc.Reg = Reg;
95 return Loc;
96 }
97
98 bool isValid() const { return K != Kind::Invalid; }
99
100 unsigned getRegister() const {
101 assert(K == Kind::Register);
102 return Reg;
103 }
104
105 int64_t getOffset() const {
106 assert(K == Kind::CFAOffset);
107 return Offset;
108 }
109
110 bool operator==(const CSRSavedLocation &RHS) const {
111 if (K != RHS.K)
112 return false;
113 switch (K) {
114 case Kind::Invalid:
115 return true;
116 case Kind::Register:
117 return getRegister() == RHS.getRegister();
118 case Kind::CFAOffset:
119 return getOffset() == RHS.getOffset();
120 }
121 llvm_unreachable("Unknown CSRSavedLocation Kind!");
122 }
123 bool operator!=(const CSRSavedLocation &RHS) const {
124 return !(*this == RHS);
125 }
126 void dump(raw_ostream &OS) const {
127 switch (K) {
128 case Kind::Invalid:
129 OS << "Invalid";
130 break;
131 case Kind::Register:
132 OS << "In Dwarf register: " << Reg;
133 break;
134 case Kind::CFAOffset:
135 OS << "At CFA offset: " << Offset;
136 break;
137 }
138 }
139 };
140
141 struct MBBCFAInfo {
142 MachineBasicBlock *MBB;
143 /// Value of cfa offset valid at basic block entry.
144 int64_t IncomingCFAOffset = -1;
145 /// Value of cfa offset valid at basic block exit.
146 int64_t OutgoingCFAOffset = -1;
147 /// Value of cfa register valid at basic block entry.
148 unsigned IncomingCFARegister = 0;
149 /// Value of cfa register valid at basic block exit.
150 unsigned OutgoingCFARegister = 0;
151 /// Set of callee saved registers saved at basic block entry.
152 BitVector IncomingCSRSaved;
153 /// Set of callee saved registers saved at basic block exit.
154 BitVector OutgoingCSRSaved;
155 /// If in/out cfa offset and register values for this block have already
156 /// been set or not.
157 bool Processed = false;
158 };
159
160 /// Contains cfa offset and register values valid at entry and exit of basic
161 /// blocks.
162 std::vector<MBBCFAInfo> MBBVector;
163
164 /// Map the callee save registers to the locations where they are saved.
165 SmallDenseMap<unsigned, CSRSavedLocation, 16> CSRLocMap;
166
167 /// Calculate cfa offset and register values valid at entry and exit for all
168 /// basic blocks in a function.
169 void calculateCFAInfo(MachineFunction &MF);
170 /// Calculate cfa offset and register values valid at basic block exit by
171 /// checking the block for CFI instructions. Block's incoming CFA info remains
172 /// the same.
173 void calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo);
174 /// Update in/out cfa offset and register values for successors of the basic
175 /// block.
176 void updateSuccCFAInfo(MBBCFAInfo &MBBInfo);
177
178 /// Check if incoming CFA information of a basic block matches outgoing CFA
179 /// information of the previous block. If it doesn't, insert CFI instruction
180 /// at the beginning of the block that corrects the CFA calculation rule for
181 /// that block.
182 bool insertCFIInstrs(MachineFunction &MF);
183 /// Return the cfa offset value that should be set at the beginning of a MBB
184 /// if needed. The negated value is needed when creating CFI instructions that
185 /// set absolute offset.
186 int64_t getCorrectCFAOffset(MachineBasicBlock *MBB) {
187 return MBBVector[MBB->getNumber()].IncomingCFAOffset;
188 }
189
190 void reportCFAError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
191 void reportCSRError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
192 /// Go through each MBB in a function and check that outgoing offset and
193 /// register of its predecessors match incoming offset and register of that
194 /// MBB, as well as that incoming offset and register of its successors match
195 /// outgoing offset and register of the MBB.
196 unsigned verify(MachineFunction &MF);
197};
198} // namespace
199
200char CFIInstrInserter::ID = 0;
201INITIALIZE_PASS(CFIInstrInserter, "cfi-instr-inserter",
202 "Check CFA info and insert CFI instructions if needed", false,
203 false)
204FunctionPass *llvm::createCFIInstrInserter() { return new CFIInstrInserter(); }
205
206void CFIInstrInserter::calculateCFAInfo(MachineFunction &MF) {
207 const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
208 // Initial CFA offset value i.e. the one valid at the beginning of the
209 // function.
210 int InitialOffset =
212 // Initial CFA register value i.e. the one valid at the beginning of the
213 // function.
214 Register InitialRegister =
216 unsigned DwarfInitialRegister = TRI.getDwarfRegNum(InitialRegister, true);
217 unsigned NumRegs = TRI.getNumSupportedRegs(MF);
218
219 // Initialize MBBMap.
220 for (MachineBasicBlock &MBB : MF) {
221 MBBCFAInfo &MBBInfo = MBBVector[MBB.getNumber()];
222 MBBInfo.MBB = &MBB;
223 MBBInfo.IncomingCFAOffset = InitialOffset;
224 MBBInfo.OutgoingCFAOffset = InitialOffset;
225 MBBInfo.IncomingCFARegister = DwarfInitialRegister;
226 MBBInfo.OutgoingCFARegister = DwarfInitialRegister;
227 MBBInfo.IncomingCSRSaved.resize(NumRegs);
228 MBBInfo.OutgoingCSRSaved.resize(NumRegs);
229 }
230 CSRLocMap.clear();
231
232 // Set in/out cfa info for all blocks in the function. This traversal is based
233 // on the assumption that the first block in the function is the entry block
234 // i.e. that it has initial cfa offset and register values as incoming CFA
235 // information.
236 updateSuccCFAInfo(MBBVector[MF.front().getNumber()]);
237}
238
239void CFIInstrInserter::calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo) {
240 // Outgoing cfa offset set by the block.
241 int64_t SetOffset = MBBInfo.IncomingCFAOffset;
242 // Outgoing cfa register set by the block.
243 unsigned SetRegister = MBBInfo.IncomingCFARegister;
244 MachineFunction *MF = MBBInfo.MBB->getParent();
245 const std::vector<MCCFIInstruction> &Instrs = MF->getFrameInstructions();
246 const TargetRegisterInfo &TRI = *MF->getSubtarget().getRegisterInfo();
247 unsigned NumRegs = TRI.getNumSupportedRegs(*MF);
248 BitVector CSRSaved(NumRegs), CSRRestored(NumRegs);
249
250#ifndef NDEBUG
251 int RememberState = 0;
252#endif
253
254 // Determine cfa offset and register set by the block.
255 for (MachineInstr &MI : *MBBInfo.MBB) {
256 if (MI.isCFIInstruction()) {
257 std::optional<unsigned> CSRReg;
258 std::optional<int64_t> CSROffset;
259 unsigned CFIIndex = MI.getOperand(0).getCFIIndex();
260 const MCCFIInstruction &CFI = Instrs[CFIIndex];
261 switch (CFI.getOperation()) {
263 SetRegister = CFI.getRegister();
264 break;
266 SetOffset = CFI.getOffset();
267 break;
269 SetOffset += CFI.getOffset();
270 break;
272 SetRegister = CFI.getRegister();
273 SetOffset = CFI.getOffset();
274 break;
276 CSROffset = CFI.getOffset();
277 break;
279 CSRReg = CFI.getRegister2();
280 break;
282 CSROffset = CFI.getOffset() - SetOffset;
283 break;
285 CSRRestored.set(CFI.getRegister());
286 break;
288 // TODO: Add support for handling cfi_def_aspace_cfa.
289#ifndef NDEBUG
291 "Support for cfi_llvm_def_aspace_cfa not implemented! Value of CFA "
292 "may be incorrect!\n");
293#endif
294 break;
296 // TODO: Add support for handling cfi_remember_state.
297#ifndef NDEBUG
298 // Currently we need cfi_remember_state and cfi_restore_state to be in
299 // the same BB, so it will not impact outgoing CFA.
300 ++RememberState;
301 if (RememberState != 1)
303 SMLoc(),
304 "Support for cfi_remember_state not implemented! Value of CFA "
305 "may be incorrect!\n");
306#endif
307 break;
309 // TODO: Add support for handling cfi_restore_state.
310#ifndef NDEBUG
311 --RememberState;
312 if (RememberState != 0)
314 SMLoc(),
315 "Support for cfi_restore_state not implemented! Value of CFA may "
316 "be incorrect!\n");
317#endif
318 break;
319 // Other CFI directives do not affect CFA value.
329 break;
330 }
331 assert((!CSRReg.has_value() || !CSROffset.has_value()) &&
332 "A register can only be at an offset from CFA or in another "
333 "register, but not both!");
334 CSRSavedLocation CSRLoc;
335 if (CSRReg)
336 CSRLoc = CSRSavedLocation::createRegister(*CSRReg);
337 else if (CSROffset)
338 CSRLoc = CSRSavedLocation::createCFAOffset(*CSROffset);
339 if (CSRLoc.isValid()) {
340 auto [It, Inserted] = CSRLocMap.insert({CFI.getRegister(), CSRLoc});
341 if (!Inserted && It->second != CSRLoc)
343 "Different saved locations for the same CSR");
344 CSRSaved.set(CFI.getRegister());
345 }
346 }
347 }
348
349#ifndef NDEBUG
350 if (RememberState != 0)
352 SMLoc(),
353 "Support for cfi_remember_state not implemented! Value of CFA may be "
354 "incorrect!\n");
355#endif
356
357 MBBInfo.Processed = true;
358
359 // Update outgoing CFA info.
360 MBBInfo.OutgoingCFAOffset = SetOffset;
361 MBBInfo.OutgoingCFARegister = SetRegister;
362
363 // Update outgoing CSR info.
364 BitVector::apply([](auto x, auto y, auto z) { return (x | y) & ~z; },
365 MBBInfo.OutgoingCSRSaved, MBBInfo.IncomingCSRSaved, CSRSaved,
366 CSRRestored);
367}
368
369void CFIInstrInserter::updateSuccCFAInfo(MBBCFAInfo &MBBInfo) {
370 SmallVector<MachineBasicBlock *, 4> Stack;
371 Stack.push_back(MBBInfo.MBB);
372
373 do {
374 MachineBasicBlock *Current = Stack.pop_back_val();
375 MBBCFAInfo &CurrentInfo = MBBVector[Current->getNumber()];
376 calculateOutgoingCFAInfo(CurrentInfo);
377 for (auto *Succ : CurrentInfo.MBB->successors()) {
378 MBBCFAInfo &SuccInfo = MBBVector[Succ->getNumber()];
379 if (!SuccInfo.Processed) {
380 SuccInfo.IncomingCFAOffset = CurrentInfo.OutgoingCFAOffset;
381 SuccInfo.IncomingCFARegister = CurrentInfo.OutgoingCFARegister;
382 SuccInfo.IncomingCSRSaved = CurrentInfo.OutgoingCSRSaved;
383 Stack.push_back(Succ);
384 }
385 }
386 } while (!Stack.empty());
387}
388
389bool CFIInstrInserter::insertCFIInstrs(MachineFunction &MF) {
390 const MBBCFAInfo *PrevMBBInfo = &MBBVector[MF.front().getNumber()];
391 const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
392 bool InsertedCFIInstr = false;
393
394 BitVector SetDifference;
395 for (MachineBasicBlock &MBB : MF) {
396 // Skip the first MBB in a function
397 if (MBB.getNumber() == MF.front().getNumber()) continue;
398
399 const MBBCFAInfo &MBBInfo = MBBVector[MBB.getNumber()];
400 auto MBBI = MBBInfo.MBB->begin();
401 DebugLoc DL = MBBInfo.MBB->findDebugLoc(MBBI);
402
403 // If the current MBB will be placed in a unique section, a full DefCfa
404 // must be emitted.
405 const bool ForceFullCFA = MBB.isBeginSection();
406
407 if ((PrevMBBInfo->OutgoingCFAOffset != MBBInfo.IncomingCFAOffset &&
408 PrevMBBInfo->OutgoingCFARegister != MBBInfo.IncomingCFARegister) ||
409 ForceFullCFA) {
410 // If both outgoing offset and register of a previous block don't match
411 // incoming offset and register of this block, or if this block begins a
412 // section, add a def_cfa instruction with the correct offset and
413 // register for this block.
414 unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfa(
415 nullptr, MBBInfo.IncomingCFARegister, getCorrectCFAOffset(&MBB)));
416 BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
417 .addCFIIndex(CFIIndex);
418 InsertedCFIInstr = true;
419 } else if (PrevMBBInfo->OutgoingCFAOffset != MBBInfo.IncomingCFAOffset) {
420 // If outgoing offset of a previous block doesn't match incoming offset
421 // of this block, add a def_cfa_offset instruction with the correct
422 // offset for this block.
423 unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfaOffset(
424 nullptr, getCorrectCFAOffset(&MBB)));
425 BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
426 .addCFIIndex(CFIIndex);
427 InsertedCFIInstr = true;
428 } else if (PrevMBBInfo->OutgoingCFARegister !=
429 MBBInfo.IncomingCFARegister) {
430 unsigned CFIIndex =
432 nullptr, MBBInfo.IncomingCFARegister));
433 BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
434 .addCFIIndex(CFIIndex);
435 InsertedCFIInstr = true;
436 }
437
438 if (ForceFullCFA) {
439 MF.getSubtarget().getFrameLowering()->emitCalleeSavedFrameMovesFullCFA(
440 *MBBInfo.MBB, MBBI);
441 InsertedCFIInstr = true;
442 PrevMBBInfo = &MBBInfo;
443 continue;
444 }
445
446 BitVector::apply([](auto x, auto y) { return x & ~y; }, SetDifference,
447 PrevMBBInfo->OutgoingCSRSaved, MBBInfo.IncomingCSRSaved);
448 for (int Reg : SetDifference.set_bits()) {
449 unsigned CFIIndex =
450 MF.addFrameInst(MCCFIInstruction::createRestore(nullptr, Reg));
451 BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
452 .addCFIIndex(CFIIndex);
453 InsertedCFIInstr = true;
454 }
455
456 BitVector::apply([](auto x, auto y) { return x & ~y; }, SetDifference,
457 MBBInfo.IncomingCSRSaved, PrevMBBInfo->OutgoingCSRSaved);
458 for (int Reg : SetDifference.set_bits()) {
459 auto it = CSRLocMap.find(Reg);
460 assert(it != CSRLocMap.end() && "Reg should have an entry in CSRLocMap");
461 unsigned CFIIndex;
462 CSRSavedLocation RO = it->second;
463 switch (RO.K) {
464 case CSRSavedLocation::CFAOffset: {
465 CFIIndex = MF.addFrameInst(
466 MCCFIInstruction::createOffset(nullptr, Reg, RO.getOffset()));
467 break;
468 }
469 case CSRSavedLocation::Register: {
470 CFIIndex = MF.addFrameInst(
471 MCCFIInstruction::createRegister(nullptr, Reg, RO.getRegister()));
472 break;
473 }
474 default:
475 llvm_unreachable("Invalid CSRSavedLocation!");
476 }
477 BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
478 .addCFIIndex(CFIIndex);
479 InsertedCFIInstr = true;
480 }
481
482 PrevMBBInfo = &MBBInfo;
483 }
484 return InsertedCFIInstr;
485}
486
487void CFIInstrInserter::reportCFAError(const MBBCFAInfo &Pred,
488 const MBBCFAInfo &Succ) {
489 errs() << "*** Inconsistent CFA register and/or offset between pred and succ "
490 "***\n";
491 errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber()
492 << " in " << Pred.MBB->getParent()->getName()
493 << " outgoing CFA Reg:" << Pred.OutgoingCFARegister << "\n";
494 errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber()
495 << " in " << Pred.MBB->getParent()->getName()
496 << " outgoing CFA Offset:" << Pred.OutgoingCFAOffset << "\n";
497 errs() << "Succ: " << Succ.MBB->getName() << " #" << Succ.MBB->getNumber()
498 << " incoming CFA Reg:" << Succ.IncomingCFARegister << "\n";
499 errs() << "Succ: " << Succ.MBB->getName() << " #" << Succ.MBB->getNumber()
500 << " incoming CFA Offset:" << Succ.IncomingCFAOffset << "\n";
501}
502
503void CFIInstrInserter::reportCSRError(const MBBCFAInfo &Pred,
504 const MBBCFAInfo &Succ) {
505 errs() << "*** Inconsistent CSR Saved between pred and succ in function "
506 << Pred.MBB->getParent()->getName() << " ***\n";
507 errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber()
508 << " outgoing CSR Saved: ";
509 for (int Reg : Pred.OutgoingCSRSaved.set_bits())
510 errs() << Reg << " ";
511 errs() << "\n";
512 errs() << "Succ: " << Succ.MBB->getName() << " #" << Succ.MBB->getNumber()
513 << " incoming CSR Saved: ";
514 for (int Reg : Succ.IncomingCSRSaved.set_bits())
515 errs() << Reg << " ";
516 errs() << "\n";
517}
518
519unsigned CFIInstrInserter::verify(MachineFunction &MF) {
520 unsigned ErrorNum = 0;
521 for (auto *CurrMBB : depth_first(&MF)) {
522 const MBBCFAInfo &CurrMBBInfo = MBBVector[CurrMBB->getNumber()];
523 for (MachineBasicBlock *Succ : CurrMBB->successors()) {
524 const MBBCFAInfo &SuccMBBInfo = MBBVector[Succ->getNumber()];
525 // Check that incoming offset and register values of successors match the
526 // outgoing offset and register values of CurrMBB
527 if (SuccMBBInfo.IncomingCFAOffset != CurrMBBInfo.OutgoingCFAOffset ||
528 SuccMBBInfo.IncomingCFARegister != CurrMBBInfo.OutgoingCFARegister) {
529 // Inconsistent offsets/registers are ok for 'noreturn' blocks because
530 // we don't generate epilogues inside such blocks.
531 if (SuccMBBInfo.MBB->succ_empty() && !SuccMBBInfo.MBB->isReturnBlock())
532 continue;
533 reportCFAError(CurrMBBInfo, SuccMBBInfo);
534 ErrorNum++;
535 }
536 // Check that IncomingCSRSaved of every successor matches the
537 // OutgoingCSRSaved of CurrMBB
538 if (SuccMBBInfo.IncomingCSRSaved != CurrMBBInfo.OutgoingCSRSaved) {
539 reportCSRError(CurrMBBInfo, SuccMBBInfo);
540 ErrorNum++;
541 }
542 }
543 }
544 return ErrorNum;
545}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static cl::opt< bool > VerifyCFI("verify-cfiinstrs", cl::desc("Verify Call Frame Information instructions"), cl::init(false), cl::Hidden)
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
ppc ctr loops verify
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
SmallVector< MachineBasicBlock *, 4 > MBBVector
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
Value * RHS
void setPreservesAll()
Set by analyses that do not transform their input at all.
iterator_range< const_set_bits_iterator > set_bits() const
Definition BitVector.h:159
static BitVector & apply(F &&f, BitVector &Out, BitVector const &Arg, ArgTys const &...Args)
Definition BitVector.h:574
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_def_cfa_register modifies a rule for computing CFA.
Definition MCDwarf.h:583
static MCCFIInstruction createRestore(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_restore says that the rule for Register is now the same as it was at the beginning of the functi...
Definition MCDwarf.h:657
unsigned getRegister2() const
Definition MCDwarf.h:726
unsigned getRegister() const
Definition MCDwarf.h:717
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:633
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:576
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:618
OpType getOperation() const
Definition MCDwarf.h:714
static MCCFIInstruction cfiDefCfaOffset(MCSymbol *L, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa_offset modifies a rule for computing CFA.
Definition MCDwarf.h:591
int64_t getOffset() const
Definition MCDwarf.h:736
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
bool isBeginSection() const
Returns true if this block begins any section.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const std::vector< MCCFIInstruction > & getFrameInstructions() const
Returns a reference to a list of cfi instructions in the function's prologue.
bool needsFrameMoves() const
True if this function needs frame moves for debug or exceptions.
MCContext & getContext() const
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
const MachineBasicBlock & front() const
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
virtual Register getInitialCFARegister(const MachineFunction &MF) const
Return initial CFA register value i.e.
virtual int getInitialCFAOffset(const MachineFunction &MF) const
Return initial CFA offset value i.e.
virtual const TargetFrameLowering * getFrameLowering() const
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
@ Offset
Definition DWP.cpp:532
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
bool operator!=(uint64_t V1, const APInt &V2)
Definition APInt.h:2122
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
Definition Error.cpp:173
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
MCCFIInstruction createCFAOffset(const TargetRegisterInfo &MRI, unsigned Reg, const StackOffset &OffsetFromDefCFA, std::optional< int64_t > IncomingVGOffsetFromDefCFA)
iterator_range< df_iterator< T > > depth_first(const T &G)
LLVM_ABI FunctionPass * createCFIInstrInserter()
Creates CFI Instruction Inserter pass.