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;
37 class TargetLoweringObjectFile : public MCObjectFileInfo {
40 TargetLoweringObjectFile(
41 const TargetLoweringObjectFile&) = delete;
42 void operator=(const TargetLoweringObjectFile&) = delete;
45 bool SupportIndirectSymViaGOTPCRel;
46 bool SupportGOTPCRelWithOffset;
49 MCContext &getContext() const { return *Ctx; }
51 TargetLoweringObjectFile()
52 : MCObjectFileInfo(), Ctx(nullptr), SupportIndirectSymViaGOTPCRel(false),
53 SupportGOTPCRelWithOffset(true) {}
55 virtual ~TargetLoweringObjectFile();
57 /// This method must be called before any actual lowering is done. This
58 /// specifies the current context for codegen, and gives the lowering
59 /// implementations a chance to set up their default sections.
60 virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
62 virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
63 const MCSymbol *Sym) const;
65 /// Emit the module flags that the platform cares about.
66 virtual void emitModuleFlags(MCStreamer &Streamer,
67 ArrayRef<Module::ModuleFlagEntry> Flags,
68 Mangler &Mang, const TargetMachine &TM) const {}
70 /// Given a constant with the SectionKind, return a section that it should be
72 virtual MCSection *getSectionForConstant(const DataLayout &DL,
74 const Constant *C) const;
76 /// Classify the specified global variable into a set of target independent
77 /// categories embodied in SectionKind.
78 static SectionKind getKindForGlobal(const GlobalValue *GV,
79 const TargetMachine &TM);
81 /// This method computes the appropriate section to emit the specified global
82 /// variable or function definition. This should not be passed external (or
83 /// available externally) globals.
84 MCSection *SectionForGlobal(const GlobalValue *GV, SectionKind Kind,
85 Mangler &Mang, 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 MCSection *SectionForGlobal(const GlobalValue *GV, Mangler &Mang,
91 const TargetMachine &TM) const {
92 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
95 virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
96 const GlobalValue *GV, Mangler &Mang,
97 const TargetMachine &TM) const;
99 virtual MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
100 const TargetMachine &TM) const;
102 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
103 const Function &F) const;
105 /// Targets should implement this method to assign a section to globals with
106 /// an explicit section specfied. The implementation of this method can
107 /// assume that GV->hasSection() is true.
109 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
110 Mangler &Mang, const TargetMachine &TM) const = 0;
112 /// Allow the target to completely override section assignment of a global.
113 virtual const MCSection *getSpecialCasedSectionGlobals(const GlobalValue *GV,
115 Mangler &Mang) const {
119 /// Return an MCExpr to use for a reference to the specified global variable
120 /// from exception handling information.
121 virtual const MCExpr *
122 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
123 Mangler &Mang, const TargetMachine &TM,
124 MachineModuleInfo *MMI, MCStreamer &Streamer) const;
126 /// Return the MCSymbol for a private symbol with global value name as its
127 /// base, with the specified suffix.
128 MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
129 StringRef Suffix, Mangler &Mang,
130 const TargetMachine &TM) const;
132 // The symbol that gets passed to .cfi_personality.
133 virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
135 const TargetMachine &TM,
136 MachineModuleInfo *MMI) const;
139 getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
140 MCStreamer &Streamer) const;
142 virtual MCSection *getStaticCtorSection(unsigned Priority,
143 const MCSymbol *KeySym) const {
144 return StaticCtorSection;
147 virtual MCSection *getStaticDtorSection(unsigned Priority,
148 const MCSymbol *KeySym) const {
149 return StaticDtorSection;
152 /// \brief Create a symbol reference to describe the given TLS variable when
153 /// emitting the address in debug info.
154 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
156 virtual const MCExpr *
157 getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang,
158 const TargetMachine &TM) const {
162 /// \brief Target supports replacing a data "PC"-relative access to a symbol
163 /// through another symbol, by accessing the later via a GOT entry instead?
164 bool supportIndirectSymViaGOTPCRel() const {
165 return SupportIndirectSymViaGOTPCRel;
168 /// \brief Target GOT "PC"-relative relocation supports encoding an additional
169 /// binary expression with an offset?
170 bool supportGOTPCRelWithOffset() const {
171 return SupportGOTPCRelWithOffset;
174 /// \brief Get the target specific PC relative GOT entry relocation
175 virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
178 MachineModuleInfo *MMI,
179 MCStreamer &Streamer) const {
183 virtual void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV,
184 const Mangler &Mang) const {}
187 virtual MCSection *SelectSectionForGlobal(const GlobalValue *GV,
188 SectionKind Kind, Mangler &Mang,
189 const TargetMachine &TM) const = 0;
192 } // end namespace llvm