LLVM 24.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
24#include "llvm/CodeGen/Passes.h"
29#include "llvm/MC/MCContext.h"
30#include "llvm/MC/MCDwarf.h"
31using namespace llvm;
32
33static cl::opt<bool> VerifyCFI("verify-cfiinstrs",
34 cl::desc("Verify Call Frame Information instructions"),
35 cl::init(false),
37
38namespace {
39class CFIInstrInserterImpl {
40public:
41 bool run(MachineFunction &MF) {
42 if (!MF.needsFrameMoves())
43 return false;
44
45 MBBVector.resize(MF.getNumBlockIDs());
46 calculateCFAInfo(MF);
47
48 if (VerifyCFI) {
49 if (unsigned ErrorNum = verify(MF))
50 report_fatal_error("Found " + Twine(ErrorNum) +
51 " in/out CFI information errors.");
52 }
53 bool insertedCFI = insertCFIInstrs(MF);
54 MBBVector.clear();
55 return insertedCFI;
56 }
57
58private:
59 /// contains the location where CSR register is saved.
60 class CSRSavedLocation {
61 public:
62 enum Kind { Invalid, Register, CFAOffset };
63 Kind K = Invalid;
64
65 private:
66 union {
67 // Dwarf register number
68 unsigned Reg;
69 // CFA offset
70 int64_t Offset;
71 };
72
73 public:
74 CSRSavedLocation() {}
75
76 static CSRSavedLocation createCFAOffset(int64_t Offset) {
77 CSRSavedLocation Loc;
78 Loc.K = Kind::CFAOffset;
79 Loc.Offset = Offset;
80 return Loc;
81 }
82
83 static CSRSavedLocation createRegister(unsigned Reg) {
84 CSRSavedLocation Loc;
85 Loc.K = Kind::Register;
86 Loc.Reg = Reg;
87 return Loc;
88 }
89
90 bool isValid() const { return K != Kind::Invalid; }
91
92 unsigned getRegister() const {
93 assert(K == Kind::Register);
94 return Reg;
95 }
96
97 int64_t getOffset() const {
98 assert(K == Kind::CFAOffset);
99 return Offset;
100 }
101
102 bool operator==(const CSRSavedLocation &RHS) const {
103 if (K != RHS.K)
104 return false;
105 switch (K) {
106 case Kind::Invalid:
107 return true;
108 case Kind::Register:
109 return getRegister() == RHS.getRegister();
110 case Kind::CFAOffset:
111 return getOffset() == RHS.getOffset();
112 }
113 llvm_unreachable("Unknown CSRSavedLocation Kind!");
114 }
115 bool operator!=(const CSRSavedLocation &RHS) const {
116 return !(*this == RHS);
117 }
118 void dump(raw_ostream &OS) const {
119 switch (K) {
120 case Kind::Invalid:
121 OS << "Invalid";
122 break;
123 case Kind::Register:
124 OS << "In Dwarf register: " << Reg;
125 break;
126 case Kind::CFAOffset:
127 OS << "At CFA offset: " << Offset;
128 break;
129 }
130 }
131 };
132
133 struct MBBCFAInfo {
134 MachineBasicBlock *MBB;
135 /// Value of cfa offset valid at basic block entry.
136 int64_t IncomingCFAOffset = -1;
137 /// Value of cfa offset valid at basic block exit.
138 int64_t OutgoingCFAOffset = -1;
139 /// Value of cfa register valid at basic block entry.
140 unsigned IncomingCFARegister = 0;
141 /// Value of cfa register valid at basic block exit.
142 unsigned OutgoingCFARegister = 0;
143 /// Set of callee saved registers saved at basic block entry.
144 BitVector IncomingCSRSaved;
145 /// Set of callee saved registers saved at basic block exit.
146 BitVector OutgoingCSRSaved;
147 /// If in/out cfa offset and register values for this block have already
148 /// been set or not.
149 bool Processed = false;
150 };
151
152 /// Contains cfa offset and register values valid at entry and exit of basic
153 /// blocks.
154 std::vector<MBBCFAInfo> MBBVector;
155
156 /// Map the callee save registers to the locations where they are saved.
157 SmallDenseMap<unsigned, CSRSavedLocation, 16> CSRLocMap;
158
159 /// Calculate cfa offset and register values valid at entry and exit for all
160 /// basic blocks in a function.
161 void calculateCFAInfo(MachineFunction &MF);
162 /// Calculate cfa offset and register values valid at basic block exit by
163 /// checking the block for CFI instructions. Block's incoming CFA info remains
164 /// the same.
165 void calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo);
166 /// Update in/out cfa offset and register values for successors of the basic
167 /// block.
168 void updateSuccCFAInfo(MBBCFAInfo &MBBInfo);
169
170 /// Check if incoming CFA information of a basic block matches outgoing CFA
171 /// information of the previous block. If it doesn't, insert CFI instruction
172 /// at the beginning of the block that corrects the CFA calculation rule for
173 /// that block.
174 bool insertCFIInstrs(MachineFunction &MF);
175 /// Return the cfa offset value that should be set at the beginning of a MBB
176 /// if needed. The negated value is needed when creating CFI instructions that
177 /// set absolute offset.
178 int64_t getCorrectCFAOffset(MachineBasicBlock *MBB) {
179 return MBBVector[MBB->getNumber()].IncomingCFAOffset;
180 }
181
182 void reportCFAError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
183 void reportCSRError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
184 /// Go through each MBB in a function and check that outgoing offset and
185 /// register of its predecessors match incoming offset and register of that
186 /// MBB, as well as that incoming offset and register of its successors match
187 /// outgoing offset and register of the MBB.
188 unsigned verify(MachineFunction &MF);
189};
190
191class CFIInstrInserterLegacy : public MachineFunctionPass {
192public:
193 static char ID;
194
195 CFIInstrInserterLegacy() : MachineFunctionPass(ID) {}
196
197 void getAnalysisUsage(AnalysisUsage &AU) const override {
198 AU.setPreservesAll();
200 }
201
202 bool runOnMachineFunction(MachineFunction &MF) override {
203 return CFIInstrInserterImpl().run(MF);
204 }
205};
206} // namespace
207
208char CFIInstrInserterLegacy::ID = 0;
209INITIALIZE_PASS(CFIInstrInserterLegacy, "cfi-instr-inserter",
210 "Check CFA info and insert CFI instructions if needed", false,
211 false)
213 return new CFIInstrInserterLegacy();
214}
215
219 CFIInstrInserterImpl().run(MF);
220 return PreservedAnalyses::all();
221}
222
223void CFIInstrInserterImpl::calculateCFAInfo(MachineFunction &MF) {
225 // Initial CFA offset value i.e. the one valid at the beginning of the
226 // function.
227 int InitialOffset =
229 // Initial CFA register value i.e. the one valid at the beginning of the
230 // function.
231 Register InitialRegister =
233 unsigned DwarfInitialRegister = TRI.getDwarfRegNum(InitialRegister, true);
234 unsigned NumRegs = TRI.getNumSupportedRegs(MF);
235
236 // Initialize MBBMap.
237 for (MachineBasicBlock &MBB : MF) {
238 MBBCFAInfo &MBBInfo = MBBVector[MBB.getNumber()];
239 MBBInfo.MBB = &MBB;
240 MBBInfo.IncomingCFAOffset = InitialOffset;
241 MBBInfo.OutgoingCFAOffset = InitialOffset;
242 MBBInfo.IncomingCFARegister = DwarfInitialRegister;
243 MBBInfo.OutgoingCFARegister = DwarfInitialRegister;
244 MBBInfo.IncomingCSRSaved.resize(NumRegs);
245 MBBInfo.OutgoingCSRSaved.resize(NumRegs);
246 }
247 CSRLocMap.clear();
248
249 // Set in/out cfa info for all blocks in the function. This traversal is based
250 // on the assumption that the first block in the function is the entry block
251 // i.e. that it has initial cfa offset and register values as incoming CFA
252 // information.
253 updateSuccCFAInfo(MBBVector[MF.front().getNumber()]);
254}
255
256void CFIInstrInserterImpl::calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo) {
257 // Outgoing cfa offset set by the block.
258 int64_t SetOffset = MBBInfo.IncomingCFAOffset;
259 // Outgoing cfa register set by the block.
260 unsigned SetRegister = MBBInfo.IncomingCFARegister;
261 MachineFunction *MF = MBBInfo.MBB->getParent();
262 const std::vector<MCCFIInstruction> &Instrs = MF->getFrameInstructions();
264 unsigned NumRegs = TRI.getNumSupportedRegs(*MF);
265 BitVector CSRSaved(NumRegs), CSRRestored(NumRegs);
266
267#ifndef NDEBUG
268 int RememberState = 0;
269#endif
270
271 // Determine cfa offset and register set by the block.
272 for (MachineInstr &MI : *MBBInfo.MBB) {
273 if (MI.isCFIInstruction()) {
274 std::optional<unsigned> CSRReg;
275 std::optional<int64_t> CSROffset;
276 unsigned CFIIndex = MI.getOperand(0).getCFIIndex();
277 const MCCFIInstruction &CFI = Instrs[CFIIndex];
278 switch (CFI.getOperation()) {
280 SetRegister = CFI.getRegister();
281 break;
283 SetOffset = CFI.getOffset();
284 break;
286 SetOffset += CFI.getOffset();
287 break;
289 SetRegister = CFI.getRegister();
290 SetOffset = CFI.getOffset();
291 break;
293 CSROffset = CFI.getOffset();
294 break;
296 CSRReg = CFI.getRegister2();
297 break;
299 CSROffset = CFI.getOffset() - SetOffset;
300 break;
302 CSRRestored.set(CFI.getRegister());
303 break;
305 // TODO: Add support for handling cfi_def_aspace_cfa.
306#ifndef NDEBUG
308 "Support for cfi_llvm_def_aspace_cfa not implemented! Value of CFA "
309 "may be incorrect!\n");
310#endif
311 break;
313 // TODO: Add support for handling cfi_remember_state.
314#ifndef NDEBUG
315 // Currently we need cfi_remember_state and cfi_restore_state to be in
316 // the same BB, so it will not impact outgoing CFA.
317 ++RememberState;
318 if (RememberState != 1)
320 SMLoc(),
321 "Support for cfi_remember_state not implemented! Value of CFA "
322 "may be incorrect!\n");
323#endif
324 break;
326 // TODO: Add support for handling cfi_restore_state.
327#ifndef NDEBUG
328 --RememberState;
329 if (RememberState != 0)
331 SMLoc(),
332 "Support for cfi_restore_state not implemented! Value of CFA may "
333 "be incorrect!\n");
334#endif
335 break;
336 // Other CFI directives do not affect CFA value.
351 break;
352 }
353 assert((!CSRReg.has_value() || !CSROffset.has_value()) &&
354 "A register can only be at an offset from CFA or in another "
355 "register, but not both!");
356 CSRSavedLocation CSRLoc;
357 if (CSRReg)
358 CSRLoc = CSRSavedLocation::createRegister(*CSRReg);
359 else if (CSROffset)
360 CSRLoc = CSRSavedLocation::createCFAOffset(*CSROffset);
361 if (CSRLoc.isValid()) {
362 auto [It, Inserted] = CSRLocMap.insert({CFI.getRegister(), CSRLoc});
363 if (!Inserted && It->second != CSRLoc)
365 "Different saved locations for the same CSR");
366 CSRSaved.set(CFI.getRegister());
367 }
368 }
369 }
370
371#ifndef NDEBUG
372 if (RememberState != 0)
374 SMLoc(),
375 "Support for cfi_remember_state not implemented! Value of CFA may be "
376 "incorrect!\n");
377#endif
378
379 MBBInfo.Processed = true;
380
381 // Update outgoing CFA info.
382 MBBInfo.OutgoingCFAOffset = SetOffset;
383 MBBInfo.OutgoingCFARegister = SetRegister;
384
385 // Update outgoing CSR info.
386 BitVector::apply([](auto x, auto y, auto z) { return (x | y) & ~z; },
387 MBBInfo.OutgoingCSRSaved, MBBInfo.IncomingCSRSaved, CSRSaved,
388 CSRRestored);
389}
390
391void CFIInstrInserterImpl::updateSuccCFAInfo(MBBCFAInfo &MBBInfo) {
393 Stack.push_back(MBBInfo.MBB);
394
395 do {
396 MachineBasicBlock *Current = Stack.pop_back_val();
397 MBBCFAInfo &CurrentInfo = MBBVector[Current->getNumber()];
398 calculateOutgoingCFAInfo(CurrentInfo);
399 for (auto *Succ : CurrentInfo.MBB->successors()) {
400 MBBCFAInfo &SuccInfo = MBBVector[Succ->getNumber()];
401 if (!SuccInfo.Processed) {
402 SuccInfo.IncomingCFAOffset = CurrentInfo.OutgoingCFAOffset;
403 SuccInfo.IncomingCFARegister = CurrentInfo.OutgoingCFARegister;
404 SuccInfo.IncomingCSRSaved = CurrentInfo.OutgoingCSRSaved;
405 Stack.push_back(Succ);
406 }
407 }
408 } while (!Stack.empty());
409}
410
411bool CFIInstrInserterImpl::insertCFIInstrs(MachineFunction &MF) {
412 const MBBCFAInfo *PrevMBBInfo = &MBBVector[MF.front().getNumber()];
414 bool InsertedCFIInstr = false;
415
416 BitVector SetDifference;
417 for (MachineBasicBlock &MBB : MF) {
418 // Skip the first MBB in a function
419 if (MBB.getNumber() == MF.front().getNumber()) continue;
420
421 const MBBCFAInfo &MBBInfo = MBBVector[MBB.getNumber()];
422 auto MBBI = MBBInfo.MBB->begin();
423 DebugLoc DL = MBBInfo.MBB->findDebugLoc(MBBI);
424
425 // If the current MBB will be placed in a unique section, a full DefCfa
426 // must be emitted.
427 const bool ForceFullCFA = MBB.isBeginSection();
428
429 if ((PrevMBBInfo->OutgoingCFAOffset != MBBInfo.IncomingCFAOffset &&
430 PrevMBBInfo->OutgoingCFARegister != MBBInfo.IncomingCFARegister) ||
431 ForceFullCFA) {
432 // If both outgoing offset and register of a previous block don't match
433 // incoming offset and register of this block, or if this block begins a
434 // section, add a def_cfa instruction with the correct offset and
435 // register for this block.
436 unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfa(
437 nullptr, MBBInfo.IncomingCFARegister, getCorrectCFAOffset(&MBB)));
438 BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
439 .addCFIIndex(CFIIndex);
440 InsertedCFIInstr = true;
441 } else if (PrevMBBInfo->OutgoingCFAOffset != MBBInfo.IncomingCFAOffset) {
442 // If outgoing offset of a previous block doesn't match incoming offset
443 // of this block, add a def_cfa_offset instruction with the correct
444 // offset for this block.
445 unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfaOffset(
446 nullptr, getCorrectCFAOffset(&MBB)));
447 BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
448 .addCFIIndex(CFIIndex);
449 InsertedCFIInstr = true;
450 } else if (PrevMBBInfo->OutgoingCFARegister !=
451 MBBInfo.IncomingCFARegister) {
452 unsigned CFIIndex =
454 nullptr, MBBInfo.IncomingCFARegister));
455 BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
456 .addCFIIndex(CFIIndex);
457 InsertedCFIInstr = true;
458 }
459
460 if (ForceFullCFA) {
461 MF.getSubtarget().getFrameLowering()->emitCalleeSavedFrameMovesFullCFA(
462 *MBBInfo.MBB, MBBI);
463 InsertedCFIInstr = true;
464 PrevMBBInfo = &MBBInfo;
465 continue;
466 }
467
468 BitVector::apply([](auto x, auto y) { return x & ~y; }, SetDifference,
469 PrevMBBInfo->OutgoingCSRSaved, MBBInfo.IncomingCSRSaved);
470 for (int Reg : SetDifference.set_bits()) {
471 unsigned CFIIndex =
472 MF.addFrameInst(MCCFIInstruction::createRestore(nullptr, Reg));
473 BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
474 .addCFIIndex(CFIIndex);
475 InsertedCFIInstr = true;
476 }
477
478 BitVector::apply([](auto x, auto y) { return x & ~y; }, SetDifference,
479 MBBInfo.IncomingCSRSaved, PrevMBBInfo->OutgoingCSRSaved);
480 for (int Reg : SetDifference.set_bits()) {
481 auto it = CSRLocMap.find(Reg);
482 assert(it != CSRLocMap.end() && "Reg should have an entry in CSRLocMap");
483 unsigned CFIIndex;
484 CSRSavedLocation RO = it->second;
485 switch (RO.K) {
486 case CSRSavedLocation::CFAOffset: {
487 CFIIndex = MF.addFrameInst(
488 MCCFIInstruction::createOffset(nullptr, Reg, RO.getOffset()));
489 break;
490 }
491 case CSRSavedLocation::Register: {
492 CFIIndex = MF.addFrameInst(
493 MCCFIInstruction::createRegister(nullptr, Reg, RO.getRegister()));
494 break;
495 }
496 default:
497 llvm_unreachable("Invalid CSRSavedLocation!");
498 }
499 BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
500 .addCFIIndex(CFIIndex);
501 InsertedCFIInstr = true;
502 }
503
504 PrevMBBInfo = &MBBInfo;
505 }
506 return InsertedCFIInstr;
507}
508
509void CFIInstrInserterImpl::reportCFAError(const MBBCFAInfo &Pred,
510 const MBBCFAInfo &Succ) {
511 errs() << "*** Inconsistent CFA register and/or offset between pred and succ "
512 "***\n";
513 errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber()
514 << " in " << Pred.MBB->getParent()->getName()
515 << " outgoing CFA Reg:" << Pred.OutgoingCFARegister << "\n";
516 errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber()
517 << " in " << Pred.MBB->getParent()->getName()
518 << " outgoing CFA Offset:" << Pred.OutgoingCFAOffset << "\n";
519 errs() << "Succ: " << Succ.MBB->getName() << " #" << Succ.MBB->getNumber()
520 << " incoming CFA Reg:" << Succ.IncomingCFARegister << "\n";
521 errs() << "Succ: " << Succ.MBB->getName() << " #" << Succ.MBB->getNumber()
522 << " incoming CFA Offset:" << Succ.IncomingCFAOffset << "\n";
523}
524
525void CFIInstrInserterImpl::reportCSRError(const MBBCFAInfo &Pred,
526 const MBBCFAInfo &Succ) {
527 errs() << "*** Inconsistent CSR Saved between pred and succ in function "
528 << Pred.MBB->getParent()->getName() << " ***\n";
529 errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber()
530 << " outgoing CSR Saved: ";
531 for (int Reg : Pred.OutgoingCSRSaved.set_bits())
532 errs() << Reg << " ";
533 errs() << "\n";
534 errs() << "Succ: " << Succ.MBB->getName() << " #" << Succ.MBB->getNumber()
535 << " incoming CSR Saved: ";
536 for (int Reg : Succ.IncomingCSRSaved.set_bits())
537 errs() << Reg << " ";
538 errs() << "\n";
539}
540
541unsigned CFIInstrInserterImpl::verify(MachineFunction &MF) {
542 unsigned ErrorNum = 0;
543 for (auto *CurrMBB : depth_first(&MF)) {
544 const MBBCFAInfo &CurrMBBInfo = MBBVector[CurrMBB->getNumber()];
545 for (MachineBasicBlock *Succ : CurrMBB->successors()) {
546 const MBBCFAInfo &SuccMBBInfo = MBBVector[Succ->getNumber()];
547 // Check that incoming offset and register values of successors match the
548 // outgoing offset and register values of CurrMBB
549 if (SuccMBBInfo.IncomingCFAOffset != CurrMBBInfo.OutgoingCFAOffset ||
550 SuccMBBInfo.IncomingCFARegister != CurrMBBInfo.OutgoingCFARegister) {
551 // Inconsistent offsets/registers are ok for 'noreturn' blocks because
552 // we don't generate epilogues inside such blocks.
553 if (SuccMBBInfo.MBB->succ_empty() && !SuccMBBInfo.MBB->isReturnBlock())
554 continue;
555 reportCFAError(CurrMBBInfo, SuccMBBInfo);
556 ErrorNum++;
557 }
558 // Check that IncomingCSRSaved of every successor matches the
559 // OutgoingCSRSaved of CurrMBB
560 if (SuccMBBInfo.IncomingCSRSaved != CurrMBBInfo.OutgoingCSRSaved) {
561 reportCSRError(CurrMBBInfo, SuccMBBInfo);
562 ErrorNum++;
563 }
564 }
565 }
566 return ErrorNum;
567}
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
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_>.
static MachineInstr * SetRegister(MachineInstr &I, Register *TLSBaseAddrReg)
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:594
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
A debug info location.
Definition DebugLoc.h:126
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:223
iterator end()
Definition DenseMap.h:141
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:284
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:635
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:725
unsigned getRegister2() const
Definition MCDwarf.h:845
unsigned getRegister() const
Definition MCDwarf.h:836
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:685
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:628
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
OpType getOperation() const
Definition MCDwarf.h:833
static MCCFIInstruction cfiDefCfaOffset(MCSymbol *L, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa_offset modifies a rule for computing CFA.
Definition MCDwarf.h:643
int64_t getOffset() const
Definition MCDwarf.h:855
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.
iterator_range< succ_iterator > successors()
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
Representation of each machine instruction.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Represents a location in source code.
Definition SMLoc.h:22
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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.
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
@ Offset
Definition DWP.cpp:578
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:2140
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
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
LLVM_ABI FunctionPass * createCFIInstrInserterLegacy()
Creates CFI Instruction Inserter pass.
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)