Make the llvm mangler depend only on DataLayout.
[oota-llvm.git] / include / llvm / Target / TargetLoweringObjectFile.h
1 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
16 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
17
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/MC/MCObjectFileInfo.h"
21 #include "llvm/MC/SectionKind.h"
22
23 namespace llvm {
24   class MachineModuleInfo;
25   class Mangler;
26   class MCContext;
27   class MCExpr;
28   class MCSection;
29   class MCSymbol;
30   class MCSymbolRefExpr;
31   class MCStreamer;
32   class GlobalValue;
33   class TargetMachine;
34   
35 class TargetLoweringObjectFile : public MCObjectFileInfo {
36   MCContext *Ctx;
37   const DataLayout *DL;
38
39   TargetLoweringObjectFile(
40     const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
41   void operator=(const TargetLoweringObjectFile&) LLVM_DELETED_FUNCTION;
42
43 public:
44   MCContext &getContext() const { return *Ctx; }
45
46   TargetLoweringObjectFile() : MCObjectFileInfo(), Ctx(0), DL(0) {}
47   
48   virtual ~TargetLoweringObjectFile();
49   
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);
54   
55   virtual void emitPersonalityValue(MCStreamer &Streamer,
56                                     const TargetMachine &TM,
57                                     const MCSymbol *Sym) const;
58
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 {
63   }
64
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,
69                                           Mangler *) const {
70     return GV != 0;
71   }
72   
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;
76   
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);
81   
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;
88   
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                                     Mangler *Mang,
94                                     const TargetMachine &TM) const {
95     return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
96   }
97
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;
104   
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 {
110     return 0;
111   }
112   
113   /// getTTypeGlobalReference - Return an MCExpr to use for a reference
114   /// to the specified global variable from exception handling information.
115   ///
116   virtual const MCExpr *
117   getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
118                           MachineModuleInfo *MMI, unsigned Encoding,
119                           MCStreamer &Streamer) const;
120
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;
124
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;
129
130   // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
131   virtual MCSymbol *
132   getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang,
133                           MachineModuleInfo *MMI) const;
134
135   /// 
136   const MCExpr *
137   getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
138                     MCStreamer &Streamer) const;
139
140   virtual const MCSection *
141   getStaticCtorSection(unsigned Priority = 65535) const {
142     (void)Priority;
143     return StaticCtorSection;
144   }
145   virtual const MCSection *
146   getStaticDtorSection(unsigned Priority = 65535) const {
147     (void)Priority;
148     return StaticDtorSection;
149   }
150
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;
154
155 protected:
156   virtual const MCSection *
157   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
158                          Mangler *Mang, const TargetMachine &TM) const;
159 };
160
161 } // end namespace llvm
162
163 #endif