LLVM 22.0.0git
CFIInstBuilder.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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#ifndef LLVM_CODEGEN_CFIINSTBUILDER_H
10#define LLVM_CODEGEN_CFIINSTBUILDER_H
11
15#include "llvm/MC/MCDwarf.h"
16
17namespace llvm {
18
19/// Helper class for creating CFI instructions and inserting them into MIR.
24
25 /// MIFlag to set on a MachineInstr. Typically, FrameSetup or FrameDestroy.
27
28 /// Selects DWARF register numbering: debug or exception handling. Should be
29 /// consistent with the choice of the ELF section (.debug_frame or .eh_frame)
30 /// where CFI will be encoded.
31 bool IsEH;
32
33 // Cache frequently used variables.
34 const TargetRegisterInfo &TRI;
35 const MCInstrDesc &CFIID;
36 const MIMetadata MIMD; // Default-initialized, no debug location desired.
37
38public:
40 MachineInstr::MIFlag MIFlag, bool IsEH = true)
41 : MF(*MBB.getParent()), MBB(MBB), MIFlag(MIFlag), IsEH(IsEH),
42 TRI(*MF.getSubtarget().getRegisterInfo()),
43 CFIID(MF.getSubtarget().getInstrInfo()->get(
44 TargetOpcode::CFI_INSTRUCTION)) {
45 setInsertPoint(InsertPt);
46 }
47
49 bool IsEH = true)
50 : CFIInstBuilder(*MBB, MBB->end(), MIFlag, IsEH) {}
51
52 void setInsertPoint(MachineBasicBlock::iterator IP) { InsertPt = IP; }
53
54 void insertCFIInst(const MCCFIInstruction &CFIInst) const {
55 BuildMI(MBB, InsertPt, MIMD, CFIID)
56 .addCFIIndex(MF.addFrameInst(CFIInst))
57 .setMIFlag(MIFlag);
58 }
59
60 void buildDefCFA(MCRegister Reg, int64_t Offset) const {
62 nullptr, TRI.getDwarfRegNum(Reg, IsEH), Offset));
63 }
64
67 nullptr, TRI.getDwarfRegNum(Reg, IsEH)));
68 }
69
70 void buildDefCFAOffset(int64_t Offset, MCSymbol *Label = nullptr) const {
72 }
73
74 void buildAdjustCFAOffset(int64_t Adjustment) const {
76 }
77
78 void buildOffset(MCRegister Reg, int64_t Offset) const {
80 nullptr, TRI.getDwarfRegNum(Reg, IsEH), Offset));
81 }
82
86
90
91 void buildRegister(MCRegister Reg1, MCRegister Reg2) const {
93 nullptr, TRI.getDwarfRegNum(Reg1, IsEH),
94 TRI.getDwarfRegNum(Reg2, IsEH)));
95 }
96
100
103 nullptr, TRI.getDwarfRegNum(Reg, IsEH)));
104 }
105
108 nullptr, TRI.getDwarfRegNum(Reg, IsEH)));
109 }
110
113 nullptr, TRI.getDwarfRegNum(Reg, IsEH)));
114 }
115
116 void buildEscape(StringRef Bytes, StringRef Comment = "") const {
118 MCCFIInstruction::createEscape(nullptr, Bytes, SMLoc(), Comment));
119 }
120};
121
122} // namespace llvm
123
124#endif // LLVM_CODEGEN_CFIINSTBUILDER_H
static const Function * getParent(const Value *V)
Register Reg
void buildEscape(StringRef Bytes, StringRef Comment="") const
void buildAdjustCFAOffset(int64_t Adjustment) const
CFIInstBuilder(MachineBasicBlock &MBB, MachineBasicBlock::iterator InsertPt, MachineInstr::MIFlag MIFlag, bool IsEH=true)
void buildDefCFAOffset(int64_t Offset, MCSymbol *Label=nullptr) const
void buildWindowSave() const
void buildRegister(MCRegister Reg1, MCRegister Reg2) const
void buildRestore(MCRegister Reg) const
void buildNegateRAState() const
void buildDefCFARegister(MCRegister Reg) const
void buildSameValue(MCRegister Reg) const
void buildNegateRAStateWithPC() const
void buildOffset(MCRegister Reg, int64_t Offset) const
void insertCFIInst(const MCCFIInstruction &CFIInst) const
CFIInstBuilder(MachineBasicBlock *MBB, MachineInstr::MIFlag MIFlag, bool IsEH=true)
void buildUndefined(MCRegister Reg) const
void buildDefCFA(MCRegister Reg, int64_t Offset) const
void setInsertPoint(MachineBasicBlock::iterator IP)
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_def_cfa_register modifies a rule for computing CFA.
Definition MCDwarf.h:592
static MCCFIInstruction createUndefined(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_undefined From now on the previous value of Register can't be restored anymore.
Definition MCDwarf.h:673
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:666
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:642
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:585
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:627
static MCCFIInstruction createNegateRAStateWithPC(MCSymbol *L, SMLoc Loc={})
.cfi_negate_ra_state_with_pc AArch64 negate RA state with PC.
Definition MCDwarf.h:658
static MCCFIInstruction createNegateRAState(MCSymbol *L, SMLoc Loc={})
.cfi_negate_ra_state AArch64 negate RA state.
Definition MCDwarf.h:653
static MCCFIInstruction cfiDefCfaOffset(MCSymbol *L, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa_offset modifies a rule for computing CFA.
Definition MCDwarf.h:600
static MCCFIInstruction createEscape(MCSymbol *L, StringRef Vals, SMLoc Loc={}, StringRef Comment="")
.cfi_escape Allows the user to add arbitrary bytes to the unwind info.
Definition MCDwarf.h:697
static MCCFIInstruction createWindowSave(MCSymbol *L, SMLoc Loc={})
.cfi_window_save SPARC register window is saved.
Definition MCDwarf.h:648
static MCCFIInstruction createAdjustCfaOffset(MCSymbol *L, int64_t Adjustment, SMLoc Loc={})
.cfi_adjust_cfa_offset Same as .cfi_def_cfa_offset, but Offset is a relative value that is added/subt...
Definition MCDwarf.h:608
static MCCFIInstruction createSameValue(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_same_value Current value of Register is the same as in the previous frame.
Definition MCDwarf.h:680
Describe properties that are true of each instruction in the target description file.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:33
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
Set of metadata that should be preserved when using BuildMI().
MachineInstrBundleIterator< MachineInstr > iterator
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
Represents a location in source code.
Definition SMLoc.h:23
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Invariant opcodes: All instruction sets have these as their low opcodes.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)