1 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
16 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/MC/MCObjectFileInfo.h"
21 #include "llvm/MC/SectionKind.h"
24 class MachineModuleInfo;
30 class MCSymbolRefExpr;
36 class TargetLoweringObjectFile : public MCObjectFileInfo {
40 TargetLoweringObjectFile(
41 const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
42 void operator=(const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
45 MCContext &getContext() const { return *Ctx; }
47 TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(nullptr), DL(nullptr) {}
49 virtual ~TargetLoweringObjectFile();
51 /// This method must be called before any actual lowering is done. This
52 /// specifies the current context for codegen, and gives the lowering
53 /// implementations a chance to set up their default sections.
54 virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
56 virtual void emitPersonalityValue(MCStreamer &Streamer,
57 const TargetMachine &TM,
58 const MCSymbol *Sym) const;
60 /// Extract the dependent library name from a linker option string. Returns
61 /// StringRef() if the option does not specify a library.
62 virtual StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const {
66 /// Emit the module flags that the platform cares about.
67 virtual void emitModuleFlags(MCStreamer &Streamer,
68 ArrayRef<Module::ModuleFlagEntry> Flags,
69 Mangler &Mang, const TargetMachine &TM) const {}
71 /// Given a constant with the SectionKind, return a section that it should be
73 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
75 /// Classify the specified global variable into a set of target independent
76 /// categories embodied in SectionKind.
77 static SectionKind getKindForGlobal(const GlobalValue *GV,
78 const TargetMachine &TM);
80 /// This method computes the appropriate section to emit the specified global
81 /// variable or function definition. This should not be passed external (or
82 /// available externally) globals.
83 const MCSection *SectionForGlobal(const GlobalValue *GV,
84 SectionKind Kind, Mangler &Mang,
85 const TargetMachine &TM) const;
87 /// This method computes the appropriate section to emit the specified global
88 /// variable or function definition. This should not be passed external (or
89 /// available externally) globals.
90 const MCSection *SectionForGlobal(const GlobalValue *GV,
92 const TargetMachine &TM) const {
93 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
96 /// Targets should implement this method to assign a section to globals with
97 /// an explicit section specfied. The implementation of this method can
98 /// assume that GV->hasSection() is true.
99 virtual const MCSection *
100 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
101 Mangler &Mang, const TargetMachine &TM) const = 0;
103 /// Allow the target to completely override section assignment of a global.
104 virtual const MCSection *getSpecialCasedSectionGlobals(const GlobalValue *GV,
106 Mangler &Mang) const {
110 /// Return an MCExpr to use for a reference to the specified global variable
111 /// from exception handling information.
112 virtual const MCExpr *
113 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
114 Mangler &Mang, const TargetMachine &TM,
115 MachineModuleInfo *MMI, MCStreamer &Streamer) const;
117 /// Return the MCSymbol for a private symbol with global value name as its
118 /// base, with the specified suffix.
119 MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
120 StringRef Suffix, Mangler &Mang,
121 const TargetMachine &TM) const;
123 // The symbol that gets passed to .cfi_personality.
124 virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
126 const TargetMachine &TM,
127 MachineModuleInfo *MMI) const;
130 getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
131 MCStreamer &Streamer) const;
133 virtual const MCSection *getStaticCtorSection(unsigned Priority,
134 const MCSymbol *KeySym) const {
135 return StaticCtorSection;
138 virtual const MCSection *getStaticDtorSection(unsigned Priority,
139 const MCSymbol *KeySym) const {
140 return StaticDtorSection;
143 /// \brief Create a symbol reference to describe the given TLS variable when
144 /// emitting the address in debug info.
145 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
147 virtual const MCExpr *
148 getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang,
149 const TargetMachine &TM) const {
153 /// \brief True if the section is atomized using the symbols in it.
154 /// This is false if the section is not atomized at all (most ELF sections) or
155 /// if it is atomized based on its contents (MachO' __TEXT,__cstring for
157 virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const;
160 virtual const MCSection *
161 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
162 Mangler &Mang, const TargetMachine &TM) const;
165 } // end namespace llvm