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(0), DL(0) {}
49 virtual ~TargetLoweringObjectFile();
51 /// Initialize - this method must be called before any actual lowering is
52 /// done. This specifies the current context for codegen, and gives the
53 /// lowering 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 /// getDepLibFromLinkerOpt - Extract the dependent library name from a linker
61 /// option string. Returns StringRef() if the option does not specify a library.
62 virtual StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const {
66 /// emitModuleFlags - Emit the module flags that the platform cares about.
67 virtual void emitModuleFlags(MCStreamer &,
68 ArrayRef<Module::ModuleFlagEntry>,
69 Mangler *, const TargetMachine &) const {
72 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
73 /// decide not to emit the UsedDirective for some symbols in llvm.used.
74 /// FIXME: REMOVE this (rdar://7071300)
75 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
80 /// getSectionForConstant - Given a constant with the SectionKind, return a
81 /// section that it should be placed in.
82 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
84 /// getKindForGlobal - Classify the specified global variable into a set of
85 /// target independent categories embodied in SectionKind.
86 static SectionKind getKindForGlobal(const GlobalValue *GV,
87 const TargetMachine &TM);
89 /// SectionForGlobal - This method computes the appropriate section to emit
90 /// the specified global variable or function definition. This should not
91 /// be passed external (or available externally) globals.
92 const MCSection *SectionForGlobal(const GlobalValue *GV,
93 SectionKind Kind, Mangler *Mang,
94 const TargetMachine &TM) const;
96 /// SectionForGlobal - This method computes the appropriate section to emit
97 /// the specified global variable or function definition. This should not
98 /// be passed external (or available externally) globals.
99 const MCSection *SectionForGlobal(const GlobalValue *GV,
101 const TargetMachine &TM) const {
102 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
105 /// getExplicitSectionGlobal - Targets should implement this method to assign
106 /// a section to globals with an explicit section specfied. The
107 /// implementation of this method can assume that GV->hasSection() is true.
108 virtual const MCSection *
109 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
110 Mangler *Mang, const TargetMachine &TM) const = 0;
112 /// getSpecialCasedSectionGlobals - Allow the target to completely override
113 /// section assignment of a global.
114 virtual const MCSection *
115 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
116 SectionKind Kind) const {
120 /// getTTypeGlobalReference - Return an MCExpr to use for a reference
121 /// to the specified global variable from exception handling information.
123 virtual const MCExpr *
124 getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
125 MachineModuleInfo *MMI, unsigned Encoding,
126 MCStreamer &Streamer) const;
128 /// Return the MCSymbol for the specified global value. This symbol is the
129 /// main label that is the address of the global
130 MCSymbol *getSymbol(Mangler &M, const GlobalValue *GV) const;
132 /// Return the MCSymbol for a private symbol with global value name as its
133 /// base, with the specified suffix.
134 MCSymbol *getSymbolWithGlobalValueBase(Mangler &M, const GlobalValue *GV,
135 StringRef Suffix) const;
137 // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
139 getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang,
140 MachineModuleInfo *MMI) const;
144 getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
145 MCStreamer &Streamer) const;
147 virtual const MCSection *
148 getStaticCtorSection(unsigned Priority = 65535) const {
150 return StaticCtorSection;
152 virtual const MCSection *
153 getStaticDtorSection(unsigned Priority = 65535) const {
155 return StaticDtorSection;
158 /// \brief Create a symbol reference to describe the given TLS variable when
159 /// emitting the address in debug info.
160 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
162 virtual const MCExpr *
163 getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler *Mang) const {
168 virtual const MCSection *
169 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
170 Mangler *Mang, const TargetMachine &TM) const;
173 } // end namespace llvm