Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:36

0001 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file implements classes used to handle lowerings specific to common
0010 // object file formats.
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   /// Name-mangler for global names.
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   /// PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values
0056   /// for EH.
0057   unsigned PersonalityEncoding = 0;
0058   unsigned LSDAEncoding = 0;
0059   unsigned TTypeEncoding = 0;
0060   unsigned CallSiteEncoding = 0;
0061 
0062   /// This section contains the static constructor pointer list.
0063   MCSection *StaticCtorSection = nullptr;
0064 
0065   /// This section contains the static destructor pointer list.
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   /// This method must be called before any actual lowering is done.  This
0080   /// specifies the current context for codegen, and gives the lowering
0081   /// implementations a chance to set up their default sections.
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   /// Emit the module-level metadata that the platform cares about.
0089   virtual void emitModuleMetadata(MCStreamer &Streamer, Module &M) const {}
0090 
0091   /// Emit Call Graph Profile metadata.
0092   void emitCGProfileMetadata(MCStreamer &Streamer, Module &M) const;
0093 
0094   /// Process linker options metadata and emit platform-specific bits.
0095   virtual void emitLinkerDirectives(MCStreamer &Streamer, Module &M) const {}
0096 
0097   /// Get the module-level metadata that the platform cares about.
0098   virtual void getModuleMetadata(Module &M) {}
0099 
0100   /// Given a constant with the SectionKind, return a section that it should be
0101   /// placed in.
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   /// Classify the specified global variable into a set of target independent
0116   /// categories embodied in SectionKind.
0117   static SectionKind getKindForGlobal(const GlobalObject *GO,
0118                                       const TargetMachine &TM);
0119 
0120   /// This method computes the appropriate section to emit the specified global
0121   /// variable or function definition. This should not be passed external (or
0122   /// available externally) globals.
0123   MCSection *SectionForGlobal(const GlobalObject *GO, SectionKind Kind,
0124                               const TargetMachine &TM) const;
0125 
0126   /// This method computes the appropriate section to emit the specified global
0127   /// variable or function definition. This should not be passed external (or
0128   /// available externally) globals.
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   /// Targets should implement this method to assign a section to globals with
0147   /// an explicit section specfied. The implementation of this method can
0148   /// assume that GO->hasSection() is true.
0149   virtual MCSection *
0150   getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
0151                            const TargetMachine &TM) const = 0;
0152 
0153   /// Return an MCExpr to use for a reference to the specified global variable
0154   /// from exception handling information.
0155   virtual const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
0156                                                 unsigned Encoding,
0157                                                 const TargetMachine &TM,
0158                                                 MachineModuleInfo *MMI,
0159                                                 MCStreamer &Streamer) const;
0160 
0161   /// Return the MCSymbol for a private symbol with global value name as its
0162   /// base, with the specified suffix.
0163   MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
0164                                          StringRef Suffix,
0165                                          const TargetMachine &TM) const;
0166 
0167   // The symbol that gets passed to .cfi_personality.
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   /// Create a symbol reference to describe the given TLS variable when
0191   /// emitting the address in debug info.
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   /// Target supports a native lowering of a dso_local_equivalent constant
0201   /// without needing to replace it with equivalent IR.
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   /// Target supports replacing a data "PC"-relative access to a symbol
0212   /// through another symbol, by accessing the later via a GOT entry instead?
0213   bool supportIndirectSymViaGOTPCRel() const {
0214     return SupportIndirectSymViaGOTPCRel;
0215   }
0216 
0217   /// Target GOT "PC"-relative relocation supports encoding an additional
0218   /// binary expression with an offset?
0219   bool supportGOTPCRelWithOffset() const {
0220     return SupportGOTPCRelWithOffset;
0221   }
0222 
0223   /// Target supports TLS offset relocation in debug section?
0224   bool supportDebugThreadLocalLocation() const {
0225     return SupportDebugThreadLocalLocation;
0226   }
0227 
0228   /// Returns the register used as static base in RWPI variants.
0229   virtual MCRegister getStaticBase() const { return MCRegister::NoRegister; }
0230 
0231   /// Get the target specific RWPI relocation.
0232   virtual const MCExpr *getIndirectSymViaRWPI(const MCSymbol *Sym) const {
0233     return nullptr;
0234   }
0235 
0236   /// Get the target specific PC relative GOT entry relocation
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   /// If supported, return the section to use for the llvm.commandline
0247   /// metadata. Otherwise, return nullptr.
0248   virtual MCSection *getSectionForCommandLines() const {
0249     return nullptr;
0250   }
0251 
0252   /// On targets that use separate function descriptor symbols, return a section
0253   /// for the descriptor given its symbol. Use only with defined functions.
0254   virtual MCSection *
0255   getSectionForFunctionDescriptor(const Function *F,
0256                                   const TargetMachine &TM) const {
0257     return nullptr;
0258   }
0259 
0260   /// On targets that support TOC entries, return a section for the entry given
0261   /// the symbol it refers to.
0262   /// TODO: Implement this interface for existing ELF targets.
0263   virtual MCSection *getSectionForTOCEntry(const MCSymbol *S,
0264                                            const TargetMachine &TM) const {
0265     return nullptr;
0266   }
0267 
0268   /// On targets that associate external references with a section, return such
0269   /// a section for the given external global.
0270   virtual MCSection *
0271   getSectionForExternalReference(const GlobalObject *GO,
0272                                  const TargetMachine &TM) const {
0273     return nullptr;
0274   }
0275 
0276   /// Targets that have a special convention for their symbols could use
0277   /// this hook to return a specialized symbol.
0278   virtual MCSymbol *getTargetSymbol(const GlobalValue *GV,
0279                                     const TargetMachine &TM) const {
0280     return nullptr;
0281   }
0282 
0283   /// If supported, return the function entry point symbol.
0284   /// Otherwise, returns nullptr.
0285   /// Func must be a function or an alias which has a function as base object.
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 } // end namespace llvm
0298 
0299 #endif // LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H