File indexing completed on 2026-05-10 08:44:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
0015 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
0016
0017 #include "llvm/MC/MCObjectFileInfo.h"
0018 #include "llvm/MC/MCRegister.h"
0019 #include <cstdint>
0020
0021 namespace llvm {
0022
0023 struct Align;
0024 class Constant;
0025 class DataLayout;
0026 class Function;
0027 class GlobalObject;
0028 class GlobalValue;
0029 class MachineBasicBlock;
0030 class MachineModuleInfo;
0031 class Mangler;
0032 class MCContext;
0033 class MCExpr;
0034 class MCSection;
0035 class MCSymbol;
0036 class MCSymbolRefExpr;
0037 class MCStreamer;
0038 class MCValue;
0039 class Module;
0040 class SectionKind;
0041 class StringRef;
0042 class TargetMachine;
0043 class DSOLocalEquivalent;
0044
0045 class TargetLoweringObjectFile : public MCObjectFileInfo {
0046
0047 Mangler *Mang = nullptr;
0048
0049 protected:
0050 bool SupportIndirectSymViaGOTPCRel = false;
0051 bool SupportGOTPCRelWithOffset = true;
0052 bool SupportDebugThreadLocalLocation = true;
0053 bool SupportDSOLocalEquivalentLowering = false;
0054
0055
0056
0057 unsigned PersonalityEncoding = 0;
0058 unsigned LSDAEncoding = 0;
0059 unsigned TTypeEncoding = 0;
0060 unsigned CallSiteEncoding = 0;
0061
0062
0063 MCSection *StaticCtorSection = nullptr;
0064
0065
0066 MCSection *StaticDtorSection = nullptr;
0067
0068 const TargetMachine *TM = nullptr;
0069
0070 public:
0071 TargetLoweringObjectFile() = default;
0072 TargetLoweringObjectFile(const TargetLoweringObjectFile &) = delete;
0073 TargetLoweringObjectFile &
0074 operator=(const TargetLoweringObjectFile &) = delete;
0075 virtual ~TargetLoweringObjectFile();
0076
0077 Mangler &getMangler() const { return *Mang; }
0078
0079
0080
0081
0082 virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
0083
0084 virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
0085 const MCSymbol *Sym,
0086 const MachineModuleInfo *MMI) const;
0087
0088
0089 virtual void emitModuleMetadata(MCStreamer &Streamer, Module &M) const {}
0090
0091
0092 void emitCGProfileMetadata(MCStreamer &Streamer, Module &M) const;
0093
0094
0095 virtual void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const {}
0096
0097
0098 virtual void getModuleMetadata(Module &M) {}
0099
0100
0101
0102 virtual MCSection *getSectionForConstant(const DataLayout &DL,
0103 SectionKind Kind, const Constant *C,
0104 Align &Alignment) const;
0105
0106 virtual MCSection *
0107 getSectionForMachineBasicBlock(const Function &F,
0108 const MachineBasicBlock &MBB,
0109 const TargetMachine &TM) const;
0110
0111 virtual MCSection *
0112 getUniqueSectionForFunction(const Function &F,
0113 const TargetMachine &TM) const;
0114
0115
0116
0117 static SectionKind getKindForGlobal(const GlobalObject *GO,
0118 const TargetMachine &TM);
0119
0120
0121
0122
0123 MCSection *SectionForGlobal(const GlobalObject *GO, SectionKind Kind,
0124 const TargetMachine &TM) const;
0125
0126
0127
0128
0129 MCSection *SectionForGlobal(const GlobalObject *GO,
0130 const TargetMachine &TM) const;
0131
0132 virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
0133 const GlobalValue *GV,
0134 const TargetMachine &TM) const;
0135
0136 virtual MCSection *getSectionForJumpTable(const Function &F,
0137 const TargetMachine &TM) const;
0138 virtual MCSection *getSectionForLSDA(const Function &, const MCSymbol &,
0139 const TargetMachine &) const {
0140 return LSDASection;
0141 }
0142
0143 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
0144 const Function &F) const;
0145
0146
0147
0148
0149 virtual MCSection *
0150 getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
0151 const TargetMachine &TM) const = 0;
0152
0153
0154
0155 virtual const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
0156 unsigned Encoding,
0157 const TargetMachine &TM,
0158 MachineModuleInfo *MMI,
0159 MCStreamer &Streamer) const;
0160
0161
0162
0163 MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
0164 StringRef Suffix,
0165 const TargetMachine &TM) const;
0166
0167
0168 virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
0169 const TargetMachine &TM,
0170 MachineModuleInfo *MMI) const;
0171
0172 unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
0173 unsigned getLSDAEncoding() const { return LSDAEncoding; }
0174 unsigned getTTypeEncoding() const { return TTypeEncoding; }
0175 unsigned getCallSiteEncoding() const;
0176
0177 const MCExpr *getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
0178 MCStreamer &Streamer) const;
0179
0180 virtual MCSection *getStaticCtorSection(unsigned Priority,
0181 const MCSymbol *KeySym) const {
0182 return StaticCtorSection;
0183 }
0184
0185 virtual MCSection *getStaticDtorSection(unsigned Priority,
0186 const MCSymbol *KeySym) const {
0187 return StaticDtorSection;
0188 }
0189
0190
0191
0192 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
0193
0194 virtual const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
0195 const GlobalValue *RHS,
0196 const TargetMachine &TM) const {
0197 return nullptr;
0198 }
0199
0200
0201
0202 bool supportDSOLocalEquivalentLowering() const {
0203 return SupportDSOLocalEquivalentLowering;
0204 }
0205
0206 virtual const MCExpr *lowerDSOLocalEquivalent(const DSOLocalEquivalent *Equiv,
0207 const TargetMachine &TM) const {
0208 return nullptr;
0209 }
0210
0211
0212
0213 bool supportIndirectSymViaGOTPCRel() const {
0214 return SupportIndirectSymViaGOTPCRel;
0215 }
0216
0217
0218
0219 bool supportGOTPCRelWithOffset() const {
0220 return SupportGOTPCRelWithOffset;
0221 }
0222
0223
0224 bool supportDebugThreadLocalLocation() const {
0225 return SupportDebugThreadLocalLocation;
0226 }
0227
0228
0229 virtual MCRegister getStaticBase() const { return MCRegister::NoRegister; }
0230
0231
0232 virtual const MCExpr *getIndirectSymViaRWPI(const MCSymbol *Sym) const {
0233 return nullptr;
0234 }
0235
0236
0237 virtual const MCExpr *getIndirectSymViaGOTPCRel(const GlobalValue *GV,
0238 const MCSymbol *Sym,
0239 const MCValue &MV,
0240 int64_t Offset,
0241 MachineModuleInfo *MMI,
0242 MCStreamer &Streamer) const {
0243 return nullptr;
0244 }
0245
0246
0247
0248 virtual MCSection *getSectionForCommandLines() const {
0249 return nullptr;
0250 }
0251
0252
0253
0254 virtual MCSection *
0255 getSectionForFunctionDescriptor(const Function *F,
0256 const TargetMachine &TM) const {
0257 return nullptr;
0258 }
0259
0260
0261
0262
0263 virtual MCSection *getSectionForTOCEntry(const MCSymbol *S,
0264 const TargetMachine &TM) const {
0265 return nullptr;
0266 }
0267
0268
0269
0270 virtual MCSection *
0271 getSectionForExternalReference(const GlobalObject *GO,
0272 const TargetMachine &TM) const {
0273 return nullptr;
0274 }
0275
0276
0277
0278 virtual MCSymbol *getTargetSymbol(const GlobalValue *GV,
0279 const TargetMachine &TM) const {
0280 return nullptr;
0281 }
0282
0283
0284
0285
0286 virtual MCSymbol *getFunctionEntryPointSymbol(const GlobalValue *Func,
0287 const TargetMachine &TM) const {
0288 return nullptr;
0289 }
0290
0291 protected:
0292 virtual MCSection *SelectSectionForGlobal(const GlobalObject *GO,
0293 SectionKind Kind,
0294 const TargetMachine &TM) const = 0;
0295 };
0296
0297 }
0298
0299 #endif