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 // Functions with Windows unwind info have no DWARF CFI to fix up.
46 if (MF.usesWindowsUnwindInfo())
47 return false;
48
49 MBBVector.resize(MF.getNumBlockIDs());
50 calculateCFAInfo(MF);
51
52 if (VerifyCFI) {
53 if (unsigned ErrorNum = verify(MF))
54 report_fatal_error("Found " + Twine(ErrorNum) +
55 " in/out CFI information errors.");
56 }
57 bool insertedCFI = insertCFIInstrs(MF);
58 MBBVector.clear();
59 return insertedCFI;
60 }
61
62private:
63 /// contains the location where CSR register is saved.
64 class CSRSavedLocation {
65 public:
66 enum Kind { Invalid, Register, CFAOffset };
67 Kind K = Invalid;
68
69 private:
70 union {
71 // Dwarf register number
72 unsigned Reg;
73 // CFA offset
74 int64_t Offset;
75 };
76
77 public:
78 CSRSavedLocation() {}
79
80 static CSRSavedLocation createCFAOffset(int64_t Offset) {
81 CSRSavedLocation Loc;
82 Loc.K = Kind::CFAOffset;
83 Loc.Offset = Offset;
84 return Loc;
85 }
86
87 static CSRSavedLocation createRegister(unsigned Reg) {
88 CSRSavedLocation Loc;
89 Loc.K = Kind::Register;
90 Loc.Reg = Reg;
91 return Loc;
92 }
93
94 bool isValid() const { return K != Kind::Invalid; }
95
96 unsigned getRegister() const {
97 assert(K == Kind::Register);
98 return Reg;
99 }
100
101 int64_t getOffset() const {
102 assert(K == Kind::CFAOffset);
103 return Offset;
104 }
105
106 bool operator==(const CSRSavedLocation &RHS) const {
107 if (K != RHS.K)
108 return false;
109 switch (K) {
110 case Kind::Invalid:
111 return true;
112 case Kind::Register:
113 return getRegister() == RHS.getRegister();
114 case Kind::CFAOffset:
115 return getOffset() == RHS.getOffset();
116 }
117 llvm_unreachable("Unknown CSRSavedLocation Kind!");
118 }
119 bool operator!=(const CSRSavedLocation &RHS) const {
120 return !(*this == RHS);
121 }
122 void dump(raw_ostream &OS) const {
123 switch (K) {
124 case Kind::Invalid:
125 OS << "Invalid";
126 break;
127 case Kind::Register:
128 OS << "In Dwarf register: " << Reg;
129 break;
130 case Kind::CFAOffset:
131 OS << "At CFA offset: " << Offset;
132 break;
133 }
134 }
135 };
136
137 struct MBBCFAInfo {
138 MachineBasicBlock *MBB;
139 /// Value of cfa offset valid at basic block entry.
140 int64_t IncomingCFAOffset = -1;
141 /// Value of cfa offset valid at basic block exit.
142 int64_t OutgoingCFAOffset = -1;
143 /// Value of cfa register valid at basic block entry.
144 unsigned IncomingCFARegister = 0;
145 /// Value of cfa register valid at basic block exit.
146 unsigned OutgoingCFARegister = 0;
147 /// Set of callee saved registers saved at basic block entry.
148 BitVector IncomingCSRSaved;
149 /// Set of callee saved registers saved at basic block exit.
150 BitVector OutgoingCSRSaved;
151 /// If in/out cfa offset and register values for this block have already
152 /// been set or not.
153 bool Processed = false;
154 };
155
156 /// Contains cfa offset and register values valid at entry and exit of basic
157 /// blocks.
158 std::vector<MBBCFAInfo> MBBVector;
159
160 /// Map the callee save registers to the locations where they are saved.
161 SmallDenseMap<unsigned, CSRSavedLocation, 16> CSRLocMap;
162
163 /// Calculate cfa offset and register values valid at entry and exit for all
164 /// basic blocks in a function.
165 void calculateCFAInfo(MachineFunction &MF);
166 /// Calculate cfa offset and register values valid at basic block exit by
167 /// checking the block for CFI instructions. Block's incoming CFA info remains
168 /// the same.
169 void calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo);
170 /// Update in/out cfa offset and register values for successors of the basic
171 /// block.
172 void updateSuccCFAInfo(MBBCFAInfo &MBBInfo);
173
174 /// Check if incoming CFA information of a basic block matches outgoing CFA
175 /// information of the previous block. If it doesn't, insert CFI instruction
176 /// at the beginning of the block that corrects the CFA calculation rule for
177 /// that block.
178 bool insertCFIInstrs(MachineFunction &MF);
179 /// Return the cfa offset value that should be set at the beginning of a MBB
180 /// if needed. The negated value is needed when creating CFI instructions that
181 /// set absolute offset.
182 int64_t getCorrectCFAOffset(MachineBasicBlock *MBB) {
183 return MBBVector[MBB->getNumber()].IncomingCFAOffset;
184 }
185
186 void reportCFAError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
187 void reportCSRError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
188 /// Go through each MBB in a function and check that outgoing offset and
189 /// register of its predecessors match incoming offset and register of that
190 /// MBB, as well as that incoming offset and register of its successors match
191 /// outgoing offset and register of the MBB.
192 unsigned verify(MachineFunction &MF);
193};
194
195class CFIInstrInserterLegacy : public MachineFunctionPass {
196public:
197 static char ID;
198
199 CFIInstrInserterLegacy() : MachineFunctionPass(ID) {}
200
201 void getAnalysisUsage(AnalysisUsage &AU) const override {
202 AU.setPreservesAll();
204 }
205
206 bool runOnMachineFunction(MachineFunction &MF) override {
207 return CFIInstrInserterImpl().run(MF);
208 }
209};
210} // namespace
211
212char CFIInstrInserterLegacy::ID = 0;
213INITIALIZE_PASS(CFIInstrInserterLegacy, "cfi-instr-inserter",
214 "Check CFA info and insert CFI instructions if needed", false,
215 false)
217 return new CFIInstrInserterLegacy();
218}
219
223 CFIInstrInserterImpl().run(MF);
224 return PreservedAnalyses::all();
225}
226
227void CFIInstrInserterImpl::calculateCFAInfo(MachineFunction &MF) {
229 // Initial CFA offset value i.e. the one valid at the beginning of the
230 // function.
231 int InitialOffset =
233 // Initial CFA register value i.e. the one valid at the beginning of the
234 // function.
235 Register InitialRegister =
237 unsigned DwarfInitialRegister = TRI.getDwarfRegNum(InitialRegister, true);
238 unsigned NumRegs = TRI.getNumSupportedRegs(MF);
239
240 // Initialize MBBMap.
241 for (MachineBasicBlock &MBB : MF) {
242 MBBCFAInfo &MBBInfo = MBBVector[MBB.getNumber()];
243 MBBInfo.MBB = &MBB;
244 MBBInfo.IncomingCFAOffset = InitialOffset;
245 MBBInfo.OutgoingCFAOffset = InitialOffset;
246 MBBInfo.IncomingCFARegister = DwarfInitialRegister;
247 MBBInfo.OutgoingCFARegister = DwarfInitialRegister;
248 MBBInfo.IncomingCSRSaved.resize(NumRegs);
249 MBBInfo.OutgoingCSRSaved.resize(NumRegs);
250 }
251 CSRLocMap.clear();
252
253 // Set in/out cfa info for all blocks in the function. This traversal is based
254 // on the assumption that the first block in the function is the entry block
255 // i.e. that it has initial cfa offset and register values as incoming CFA
256 // information.
257 updateSuccCFAInfo(MBBVector[MF.front().getNumber()]);
258}
259
260void CFIInstrInserterImpl::calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo) {
261 // Outgoing cfa offset set by the block.
262 int64_t SetOffset = MBBInfo.IncomingCFAOffset;
263 // Outgoing cfa register set by the block.
264 unsigned SetRegister = MBBInfo.IncomingCFARegister;
265 MachineFunction *MF = MBBInfo.MBB->getParent();
266 const std::vector<MCCFIInstruction> &Instrs = MF->getFrameInstructions();
268 unsigned NumRegs = TRI.getNumSupportedRegs(*MF);
269 BitVector CSRSaved(NumRegs), CSRRestored(NumRegs);
270
271#ifndef NDEBUG
272 int RememberState = 0;
273#endif
274
275 // Determine cfa offset and register set by the block.
276 for (MachineInstr &MI : *MBBInfo.MBB) {
277 if (MI.isCFIInstruction()) {
278 std::optional<unsigned> CSRReg;
279 std::optional<int64_t> CSROffset;
280 unsigned CFIIndex = MI.getOperand(0).getCFIIndex();
281 const MCCFIInstruction &CFI = Instrs[CFIIndex];
282 switch (CFI.getOperation()) {
284 SetRegister = CFI.getRegister();
285 break;
287 SetOffset = CFI.getOffset();
288 break;
290 SetOffset += CFI.getOffset();
291 break;
293 SetRegister = CFI.getRegister();
294 SetOffset = CFI.getOffset();
295 break;
297 CSROffset = CFI.getOffset();
298 break;
300 CSRReg = CFI.getRegister2();
301 break;
303 CSROffset = CFI.getOffset() - SetOffset;
304 break;
306 CSRRestored.set(CFI.getRegister());
307 break;
309 // TODO: Add support for handling cfi_def_aspace_cfa.
310#ifndef NDEBUG
312 "Support for cfi_llvm_def_aspace_cfa not implemented! Value of CFA "
313 "may be incorrect!\n");
314#endif
315 break;
317 // TODO: Add support for handling cfi_remember_state.
318#ifndef NDEBUG
319 // Currently we need cfi_remember_state and cfi_restore_state to be in
320 // the same BB, so it will not impact outgoing CFA.
321 ++RememberState;
322 if (RememberState != 1)
324 SMLoc(),
325 "Support for cfi_remember_state not implemented! Value of CFA "
326 "may be incorrect!\n");
327#endif
328 break;
330 // TODO: Add support for handling cfi_restore_state.
331#ifndef NDEBUG
332 --RememberState;
333 if (RememberState != 0)
335 SMLoc(),
336 "Support for cfi_restore_state not implemented! Value of CFA may "
337 "be incorrect!\n");
338#endif
339 break;
340 // Other CFI directives do not affect CFA value.
355 break;
356 }
357 assert((!CSRReg.has_value() || !CSROffset.has_value()) &&
358 "A register can only be at an offset from CFA or in another "
359 "register, but not both!");
360 CSRSavedLocation CSRLoc;
361 if (CSRReg)
362 CSRLoc = CSRSavedLocation::createRegister(*CSRReg);
363 else if (CSROffset)
364 CSRLoc = CSRSavedLocation::createCFAOffset(*CSROffset);
365 if (CSRLoc.isValid()) {
366 auto [It, Inserted] = CSRLocMap.insert({CFI.getRegister(), CSRLoc});
367 if (!Inserted && It->second != CSRLoc)
369 "Different saved locations for the same CSR");
370 CSRSaved.set(CFI.getRegister());
371 }
372 }
373 }
374
375#ifndef NDEBUG
376 if (RememberState != 0)
378 SMLoc(),
379 "Support for cfi_remember_state not implemented! Value of CFA may be "
380 "incorrect!\n");
381#endif
382
383 MBBInfo.Processed = true;
384
385 // Update outgoing CFA info.
386 MBBInfo.OutgoingCFAOffset = SetOffset;
387 MBBInfo.OutgoingCFARegister = SetRegister;
388
389 // Update outgoing CSR info.
390 BitVector::apply([](auto x, auto y, auto z) { return (x | y) & ~z; },
391 MBBInfo.OutgoingCSRSaved, MBBInfo.IncomingCSRSaved, CSRSaved,
392 CSRRestored);
393}
394
395void CFIInstrInserterImpl::updateSuccCFAInfo(MBBCFAInfo &MBBInfo) {
397 Stack.push_back(MBBInfo.MBB);
398
399 do {
400 MachineBasicBlock *Current = Stack.pop_back_val();
401 MBBCFAInfo &CurrentInfo = MBBVector[Current->getNumber()];
402 calculateOutgoingCFAInfo(CurrentInfo);
403 for (auto *Succ : CurrentInfo.MBB->successors()) {
404 MBBCFAInfo &SuccInfo = MBBVector[Succ->getNumber()];
405 if (!SuccInfo.Processed) {
406 SuccInfo.IncomingCFAOffset = CurrentInfo.OutgoingCFAOffset;
407 SuccInfo.IncomingCFARegister = CurrentInfo.OutgoingCFARegister;
408 SuccInfo.IncomingCSRSaved = CurrentInfo.OutgoingCSRSaved;
409 Stack.push_back(Succ);
410 }
411 }
412 } while (!Stack.empty());
413}
414
415bool CFIInstrInserterImpl::insertCFIInstrs(MachineFunction &MF) {
416 const MBBCFAInfo *PrevMBBInfo = &MBBVector[MF.front().getNumber()];
418 bool InsertedCFIInstr = false;
419
420 BitVector SetDifference;
421 for (MachineBasicBlock &MBB : MF) {
422 // Skip the first MBB in a function
423 if (MBB.getNumber() == MF.front().getNumber()) continue;
424
425 const MBBCFAInfo &MBBInfo = MBBVector[MBB.getNumber()];
426 auto MBBI = MBBInfo.MBB->begin();
427 DebugLoc DL = MBBInfo.MBB->findDebugLoc(MBBI);
428
429 // If the current MBB will be placed in a unique section, a full DefCfa
430 // must be emitted.
431 const bool ForceFullCFA = MBB.isBeginSection();
432
433 if ((PrevMBBInfo->OutgoingCFAOffset != MBBInfo.IncomingCFAOffset &&
434 PrevMBBInfo->OutgoingCFARegister != MBBInfo.IncomingCFARegister) ||
435 ForceFullCFA) {
436 // If both outgoing offset and register of a previous block don't match
437 // incoming offset and register of this block, or if this block begins a
438 // section, add a def_cfa instruction with the correct offset and
439 // register for this block.
440 unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfa(
441 nullptr, MBBInfo.IncomingCFARegister, getCorrectCFAOffset(&MBB)));
442 BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
443 .addCFIIndex(CFIIndex);
444 InsertedCFIInstr = true;
445 } else if (PrevMBBInfo->OutgoingCFAOffset != MBBInfo.IncomingCFAOffset) {
446 // If outgoing offset of a previous block doesn't match incoming offset
447 // of this block, add a def_cfa_offset instruction with the correct
448 // offset for this block.
449 unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfaOffset(
450 nullptr, getCorrectCFAOffset(&MBB)));
451 BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
452 .addCFIIndex(CFIIndex);
453 InsertedCFIInstr = true;
454 } else if (PrevMBBInfo->OutgoingCFARegister !=
455 MBBInfo.IncomingCFARegister) {
456 unsigned CFIIndex =
458 nullptr, MBBInfo.IncomingCFARegister));
459 BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
460 .addCFIIndex(CFIIndex);
461 InsertedCFIInstr = true;
462 }
463
464 if (ForceFullCFA) {
465 MF.getSubtarget().getFrameLowering()->emitCalleeSavedFrameMovesFullCFA(
466 *MBBInfo.MBB, MBBI);
467 InsertedCFIInstr = true;
468 PrevMBBInfo = &MBBInfo;
469 continue;
470 }
471
472 BitVector::apply([](auto x, auto y) { return x & ~y; }, SetDifference,
473 PrevMBBInfo->OutgoingCSRSaved, MBBInfo.IncomingCSRSaved);
474 for (int Reg : SetDifference.set_bits()) {
475 unsigned CFIIndex =
476 MF.addFrameInst(MCCFIInstruction::createRestore(nullptr, Reg));
477 BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
478 .addCFIIndex(CFIIndex);
479 InsertedCFIInstr = true;
480 }
481
482 BitVector::apply([](auto x, auto y) { return x & ~y; }, SetDifference,
483 MBBInfo.IncomingCSRSaved, PrevMBBInfo->OutgoingCSRSaved);
484 for (int Reg : SetDifference.set_bits()) {
485 auto it = CSRLocMap.find(Reg);
486 assert(it != CSRLocMap.end() && "Reg should have an entry in CSRLocMap");
487 unsigned CFIIndex;
488 CSRSavedLocation RO = it->second;
489 switch (RO.K) {
490 case CSRSavedLocation::CFAOffset: {
491 CFIIndex = MF.addFrameInst(
492 MCCFIInstruction::createOffset(nullptr, Reg, RO.getOffset()));
493 break;
494 }
495 case CSRSavedLocation::Register: {
496 CFIIndex = MF.addFrameInst(
497 MCCFIInstruction::createRegister(nullptr, Reg, RO.getRegister()));
498 break;
499 }
500 default:
501 llvm_unreachable("Invalid CSRSavedLocation!");
502 }
503 BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
504 .addCFIIndex(CFIIndex);
505 InsertedCFIInstr = true;
506 }
507
508 PrevMBBInfo = &MBBInfo;
509 }
510 return InsertedCFIInstr;
511}
512
513void CFIInstrInserterImpl::reportCFAError(const MBBCFAInfo &Pred,
514 const MBBCFAInfo &Succ) {
515 errs() << "*** Inconsistent CFA register and/or offset between pred and succ "
516 "***\n";
517 errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber()
518 << " in " << Pred.MBB->getParent()->getName()
519 << " outgoing CFA Reg:" << Pred.OutgoingCFARegister << "\n";
520 errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber()
521 << " in " << Pred.MBB->getParent()->getName()
522 << " outgoing CFA Offset:" << Pred.OutgoingCFAOffset << "\n";
523 errs() << "Succ: " << Succ.MBB->getName() << " #" << Succ.MBB->getNumber()
524 << " incoming CFA Reg:" << Succ.IncomingCFARegister << "\n";
525 errs() << "Succ: " << Succ.MBB->getName() << " #" << Succ.MBB->getNumber()
526 << " incoming CFA Offset:" << Succ.IncomingCFAOffset << "\n";
527}
528
529void CFIInstrInserterImpl::reportCSRError(const MBBCFAInfo &Pred,
530 const MBBCFAInfo &Succ) {
531 errs() << "*** Inconsistent CSR Saved between pred and succ in function "
532 << Pred.MBB->getParent()->getName() << " ***\n";
533 errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber()
534 << " outgoing CSR Saved: ";
535 for (int Reg : Pred.OutgoingCSRSaved.set_bits())
536 errs() << Reg << " ";
537 errs() << "\n";
538 errs() << "Succ: " << Succ.MBB->getName() << " #" << Succ.MBB->getNumber()
539 << " incoming CSR Saved: ";
540 for (int Reg : Succ.IncomingCSRSaved.set_bits())
541 errs() << Reg << " ";
542 errs() << "\n";
543}
544
545unsigned CFIInstrInserterImpl::verify(MachineFunction &MF) {
546 unsigned ErrorNum = 0;
547 for (auto *CurrMBB : depth_first(&MF)) {
548 const MBBCFAInfo &CurrMBBInfo = MBBVector[CurrMBB->getNumber()];
549 for (MachineBasicBlock *Succ : CurrMBB->successors()) {
550 const MBBCFAInfo &SuccMBBInfo = MBBVector[Succ->getNumber()];
551 // Check that incoming offset and register values of successors match the
552 // outgoing offset and register values of CurrMBB
553 if (SuccMBBInfo.IncomingCFAOffset != CurrMBBInfo.OutgoingCFAOffset ||
554 SuccMBBInfo.IncomingCFARegister != CurrMBBInfo.OutgoingCFARegister) {
555 // Inconsistent offsets/registers are ok for 'noreturn' blocks because
556 // we don't generate epilogues inside such blocks.
557 if (SuccMBBInfo.MBB->succ_empty() && !SuccMBBInfo.MBB->isReturnBlock())
558 continue;
559 reportCFAError(CurrMBBInfo, SuccMBBInfo);
560 ErrorNum++;
561 }
562 // Check that IncomingCSRSaved of every successor matches the
563 // OutgoingCSRSaved of CurrMBB
564 if (SuccMBBInfo.IncomingCSRSaved != CurrMBBInfo.OutgoingCSRSaved) {
565 reportCSRError(CurrMBBInfo, SuccMBBInfo);
566 ErrorNum++;
567 }
568 }
569 }
570 return ErrorNum;
571}
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:766
iterator end()
Definition DenseMap.h:686
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:827
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
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
bool usesWindowsUnwindInfo() const
True if this function describes its unwind information with Windows SEH unwind opcodes (....
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:577
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:2139
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)