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;
35 class TargetLoweringObjectFile : public MCObjectFileInfo {
39 TargetLoweringObjectFile(
40 const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
41 void operator=(const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
44 MCContext &getContext() const { return *Ctx; }
46 TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(0), DL(0) {}
48 virtual ~TargetLoweringObjectFile();
50 /// Initialize - this method must be called before any actual lowering is
51 /// done. This specifies the current context for codegen, and gives the
52 /// lowering implementations a chance to set up their default sections.
53 virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
55 virtual void emitPersonalityValue(MCStreamer &Streamer,
56 const TargetMachine &TM,
57 const MCSymbol *Sym) const;
59 /// emitModuleFlags - Emit the module flags that the platform cares about.
60 virtual void emitModuleFlags(MCStreamer &,
61 ArrayRef<Module::ModuleFlagEntry>,
62 Mangler *, const TargetMachine &) const {
65 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
66 /// decide not to emit the UsedDirective for some symbols in llvm.used.
67 /// FIXME: REMOVE this (rdar://7071300)
68 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
73 /// getSectionForConstant - Given a constant with the SectionKind, return a
74 /// section that it should be placed in.
75 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
77 /// getKindForGlobal - Classify the specified global variable into a set of
78 /// target independent categories embodied in SectionKind.
79 static SectionKind getKindForGlobal(const GlobalValue *GV,
80 const TargetMachine &TM);
82 /// SectionForGlobal - This method computes the appropriate section to emit
83 /// the specified global variable or function definition. This should not
84 /// be passed external (or available externally) globals.
85 const MCSection *SectionForGlobal(const GlobalValue *GV,
86 SectionKind Kind, Mangler *Mang,
87 const TargetMachine &TM) const;
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,
94 const TargetMachine &TM) const {
95 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
98 /// getExplicitSectionGlobal - Targets should implement this method to assign
99 /// a section to globals with an explicit section specfied. The
100 /// implementation of this method can assume that GV->hasSection() is true.
101 virtual const MCSection *
102 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
103 Mangler *Mang, const TargetMachine &TM) const = 0;
105 /// getSpecialCasedSectionGlobals - Allow the target to completely override
106 /// section assignment of a global.
107 virtual const MCSection *
108 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
109 SectionKind Kind) const {
113 /// getTTypeGlobalReference - Return an MCExpr to use for a reference
114 /// to the specified global variable from exception handling information.
116 virtual const MCExpr *
117 getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
118 MachineModuleInfo *MMI, unsigned Encoding,
119 MCStreamer &Streamer) const;
121 /// Return the MCSymbol for the specified global value. This symbol is the
122 /// main label that is the address of the global
123 MCSymbol *getSymbol(Mangler &M, const GlobalValue *GV) const;
125 /// Return the MCSymbol for a private symbol with global value name as its
126 /// base, with the specified suffix.
127 MCSymbol *getSymbolWithGlobalValueBase(Mangler &M, const GlobalValue *GV,
128 StringRef Suffix) const;
130 // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
132 getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang,
133 MachineModuleInfo *MMI) const;
137 getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
138 MCStreamer &Streamer) const;
140 virtual const MCSection *
141 getStaticCtorSection(unsigned Priority = 65535) const {
143 return StaticCtorSection;
145 virtual const MCSection *
146 getStaticDtorSection(unsigned Priority = 65535) const {
148 return StaticDtorSection;
151 /// \brief Create a symbol reference to describe the given TLS variable when
152 /// emitting the address in debug info.
153 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
156 virtual const MCSection *
157 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
158 Mangler *Mang, const TargetMachine &TM) const;
161 } // end namespace llvm