LLVM  9.0.0svn
TargetLoweringObjectFileImpl.h
Go to the documentation of this file.
1 //==- llvm/CodeGen/TargetLoweringObjectFileImpl.h - Object Info --*- C++ -*-==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements classes used to handle lowerings specific to common
10 // object file formats.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
15 #define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
16 
17 #include "llvm/IR/Module.h"
18 #include "llvm/MC/MCExpr.h"
20 
21 namespace llvm {
22 
23 class GlobalValue;
24 class MachineModuleInfo;
25 class Mangler;
26 class MCContext;
27 class MCSection;
28 class MCSymbol;
29 class TargetMachine;
30 
32  bool UseInitArray = false;
33  mutable unsigned NextUniqueID = 1; // ID 0 is reserved for execute-only sections
34 
35 protected:
38  const TargetMachine *TM;
39 
40 public:
41  TargetLoweringObjectFileELF() = default;
42  ~TargetLoweringObjectFileELF() override = default;
43 
44  void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
45 
46  /// Emit Obj-C garbage collection and linker options.
47  void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
48 
49  void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &DL,
50  const MCSymbol *Sym) const override;
51 
52  /// Given a constant with the SectionKind, return a section that it should be
53  /// placed in.
55  const Constant *C,
56  unsigned &Align) const override;
57 
59  const TargetMachine &TM) const override;
60 
62  const TargetMachine &TM) const override;
63 
65  const TargetMachine &TM) const override;
66 
67  bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
68  const Function &F) const override;
69 
70  /// Return an MCExpr to use for a reference to the specified type info global
71  /// variable from exception handling information.
73  unsigned Encoding,
74  const TargetMachine &TM,
75  MachineModuleInfo *MMI,
76  MCStreamer &Streamer) const override;
77 
78  // The symbol that gets passed to .cfi_personality.
80  const TargetMachine &TM,
81  MachineModuleInfo *MMI) const override;
82 
83  void InitializeELF(bool UseInitArray_);
84  MCSection *getStaticCtorSection(unsigned Priority,
85  const MCSymbol *KeySym) const override;
86  MCSection *getStaticDtorSection(unsigned Priority,
87  const MCSymbol *KeySym) const override;
88 
89  const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
90  const GlobalValue *RHS,
91  const TargetMachine &TM) const override;
92 
93  MCSection *getSectionForCommandLines() const override;
94 };
95 
97 public:
99  ~TargetLoweringObjectFileMachO() override = default;
100 
101  void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
102 
103  /// Emit the module flags that specify the garbage collection information.
104  void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
105 
107  const TargetMachine &TM) const override;
108 
110  const TargetMachine &TM) const override;
111 
113  const Constant *C,
114  unsigned &Align) const override;
115 
116  /// The mach-o version of this method defaults to returning a stub reference.
117  const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
118  unsigned Encoding,
119  const TargetMachine &TM,
120  MachineModuleInfo *MMI,
121  MCStreamer &Streamer) const override;
122 
123  // The symbol that gets passed to .cfi_personality.
125  const TargetMachine &TM,
126  MachineModuleInfo *MMI) const override;
127 
128  /// Get MachO PC relative GOT entry relocation
129  const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
130  const MCValue &MV, int64_t Offset,
131  MachineModuleInfo *MMI,
132  MCStreamer &Streamer) const override;
133 
134  void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
135  const TargetMachine &TM) const override;
136 };
137 
139  mutable unsigned NextUniqueID = 0;
140 
141 public:
142  ~TargetLoweringObjectFileCOFF() override = default;
143 
144  void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
146  const TargetMachine &TM) const override;
147 
149  const TargetMachine &TM) const override;
150 
151  void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
152  const TargetMachine &TM) const override;
153 
155  const TargetMachine &TM) const override;
156 
157  /// Emit Obj-C garbage collection and linker options.
158  void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
159 
160  MCSection *getStaticCtorSection(unsigned Priority,
161  const MCSymbol *KeySym) const override;
162  MCSection *getStaticDtorSection(unsigned Priority,
163  const MCSymbol *KeySym) const override;
164 
166  const GlobalValue *GV) const override;
167 
169  const GlobalValue *GV) const override;
170 
171  const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
172  const GlobalValue *RHS,
173  const TargetMachine &TM) const override;
174 
175  /// Given a mergeable constant with the specified size and relocation
176  /// information, return a section that it should be placed in.
178  const Constant *C,
179  unsigned &Align) const override;
180 };
181 
183  mutable unsigned NextUniqueID = 0;
184 
185 public:
186  TargetLoweringObjectFileWasm() = default;
187  ~TargetLoweringObjectFileWasm() override = default;
188 
190  const TargetMachine &TM) const override;
191 
193  const TargetMachine &TM) const override;
194 
195  bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
196  const Function &F) const override;
197 
198  void InitializeWasm();
199  MCSection *getStaticCtorSection(unsigned Priority,
200  const MCSymbol *KeySym) const override;
201  MCSection *getStaticDtorSection(unsigned Priority,
202  const MCSymbol *KeySym) const override;
203 
204  const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
205  const GlobalValue *RHS,
206  const TargetMachine &TM) const override;
207 };
208 
209 } // end namespace llvm
210 
211 #endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
uint64_t CallInst * C
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:38
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:110
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
MCSection * getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This represents an "assembler immediate".
Definition: MCValue.h:39
void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &DL, const MCSymbol *Sym) const override
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override
Emit Obj-C garbage collection and linker options.
F(f)
MCSection * getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, unsigned &Align) const override
Given a constant with the SectionKind, return a section that it should be placed in.
virtual void emitLinkerFlagsForUsed(raw_ostream &OS, const GlobalValue *GV) const
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Context object for machine code objects.
Definition: MCContext.h:62
MCSection * getStaticDtorSection(unsigned Priority, const MCSymbol *KeySym) const override
Streaming machine code generation interface.
Definition: MCStreamer.h:188
MCSection * getSectionForCommandLines() const override
If supported, return the section to use for the llvm.commandline metadata.
virtual void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV) const
This is an important base class in LLVM.
Definition: Constant.h:41
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Return an MCExpr to use for a reference to the specified type info global variable from exception han...
~TargetLoweringObjectFileELF() override=default
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
virtual const MCExpr * getIndirectSymViaGOTPCRel(const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const
Get the target specific PC relative GOT entry relocation.
Module.h This file contains the declarations for the Module class.
MCSymbolRefExpr::VariantKind PLTRelativeVariantKind
const MCExpr * lowerRelativeReference(const GlobalValue *LHS, const GlobalValue *RHS, const TargetMachine &TM) const override
MCSection * getStaticCtorSection(unsigned Priority, const MCSymbol *KeySym) const override
virtual void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
This class contains meta information specific to a module.