LLVM API Documentation

TargetLoweringObjectFile.h
Go to the documentation of this file.
00001 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements classes used to handle lowerings specific to common
00011 // object file formats.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
00016 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
00017 
00018 #include "llvm/ADT/ArrayRef.h"
00019 #include "llvm/IR/Module.h"
00020 #include "llvm/MC/MCObjectFileInfo.h"
00021 #include "llvm/MC/SectionKind.h"
00022 
00023 namespace llvm {
00024   class MachineModuleInfo;
00025   class Mangler;
00026   class MCContext;
00027   class MCExpr;
00028   class MCSection;
00029   class MCSymbol;
00030   class MCSymbolRefExpr;
00031   class MCStreamer;
00032   class ConstantExpr;
00033   class GlobalValue;
00034   class TargetMachine;
00035 
00036 class TargetLoweringObjectFile : public MCObjectFileInfo {
00037   MCContext *Ctx;
00038   const DataLayout *DL;
00039 
00040   TargetLoweringObjectFile(
00041     const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
00042   void operator=(const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
00043 
00044 public:
00045   MCContext &getContext() const { return *Ctx; }
00046 
00047   TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(nullptr), DL(nullptr) {}
00048 
00049   virtual ~TargetLoweringObjectFile();
00050 
00051   /// This method must be called before any actual lowering is done.  This
00052   /// specifies the current context for codegen, and gives the lowering
00053   /// implementations a chance to set up their default sections.
00054   virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
00055 
00056   virtual void emitPersonalityValue(MCStreamer &Streamer,
00057                                     const TargetMachine &TM,
00058                                     const MCSymbol *Sym) const;
00059 
00060   /// Extract the dependent library name from a linker option string. Returns
00061   /// StringRef() if the option does not specify a library.
00062   virtual StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const {
00063     return StringRef();
00064   }
00065 
00066   /// Emit the module flags that the platform cares about.
00067   virtual void emitModuleFlags(MCStreamer &Streamer,
00068                                ArrayRef<Module::ModuleFlagEntry> Flags,
00069                                Mangler &Mang, const TargetMachine &TM) const {}
00070 
00071   /// Given a constant with the SectionKind, return a section that it should be
00072   /// placed in.
00073   virtual const MCSection *getSectionForConstant(SectionKind Kind,
00074                                                  const Constant *C) const;
00075 
00076   /// Classify the specified global variable into a set of target independent
00077   /// categories embodied in SectionKind.
00078   static SectionKind getKindForGlobal(const GlobalValue *GV,
00079                                       const TargetMachine &TM);
00080 
00081   /// This method computes the appropriate section to emit the specified global
00082   /// variable or function definition. This should not be passed external (or
00083   /// available externally) globals.
00084   const MCSection *SectionForGlobal(const GlobalValue *GV,
00085                                     SectionKind Kind, Mangler &Mang,
00086                                     const TargetMachine &TM) const;
00087 
00088   /// This method computes the appropriate section to emit the specified global
00089   /// variable or function definition. This should not be passed external (or
00090   /// available externally) globals.
00091   const MCSection *SectionForGlobal(const GlobalValue *GV,
00092                                     Mangler &Mang,
00093                                     const TargetMachine &TM) const {
00094     return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
00095   }
00096 
00097   /// Targets should implement this method to assign a section to globals with
00098   /// an explicit section specfied. The implementation of this method can
00099   /// assume that GV->hasSection() is true.
00100   virtual const MCSection *
00101   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
00102                            Mangler &Mang, const TargetMachine &TM) const = 0;
00103 
00104   /// Allow the target to completely override section assignment of a global.
00105   virtual const MCSection *getSpecialCasedSectionGlobals(const GlobalValue *GV,
00106                                                          SectionKind Kind,
00107                                                          Mangler &Mang) const {
00108     return nullptr;
00109   }
00110 
00111   /// Return an MCExpr to use for a reference to the specified global variable
00112   /// from exception handling information.
00113   virtual const MCExpr *
00114   getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
00115                           Mangler &Mang, const TargetMachine &TM,
00116                           MachineModuleInfo *MMI, MCStreamer &Streamer) const;
00117 
00118   /// Return the MCSymbol for a private symbol with global value name as its
00119   /// base, with the specified suffix.
00120   MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
00121                                          StringRef Suffix, Mangler &Mang,
00122                                          const TargetMachine &TM) const;
00123 
00124   // The symbol that gets passed to .cfi_personality.
00125   virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
00126                                             Mangler &Mang,
00127                                             const TargetMachine &TM,
00128                                             MachineModuleInfo *MMI) const;
00129 
00130   const MCExpr *
00131   getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
00132                     MCStreamer &Streamer) const;
00133 
00134   virtual const MCSection *getStaticCtorSection(unsigned Priority,
00135                                                 const MCSymbol *KeySym) const {
00136     return StaticCtorSection;
00137   }
00138 
00139   virtual const MCSection *getStaticDtorSection(unsigned Priority,
00140                                                 const MCSymbol *KeySym) const {
00141     return StaticDtorSection;
00142   }
00143 
00144   /// \brief Create a symbol reference to describe the given TLS variable when
00145   /// emitting the address in debug info.
00146   virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
00147 
00148   virtual const MCExpr *
00149   getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang,
00150                               const TargetMachine &TM) const {
00151     return nullptr;
00152   }
00153 
00154   /// \brief True if the section is atomized using the symbols in it.
00155   /// This is false if the section is not atomized at all (most ELF sections) or
00156   /// if it is atomized based on its contents (MachO' __TEXT,__cstring for
00157   /// example).
00158   virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const;
00159 
00160 protected:
00161   virtual const MCSection *
00162   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
00163                          Mangler &Mang, const TargetMachine &TM) const;
00164 };
00165 
00166 } // end namespace llvm
00167 
00168 #endif