1f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
2f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
3f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//                     The LLVM Compiler Infrastructure
4f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
5f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// This file is distributed under the University of Illinois Open Source
6f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// License. See LICENSE.TXT for details.
7f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
8f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===//
9f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
10f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// This file implements classes used to handle lowerings specific to common
11f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// object file formats.
12f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
13f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===//
14f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
15f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
16f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
17f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
18f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/ADT/ArrayRef.h"
19f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/ADT/StringRef.h"
20f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/IR/Module.h"
21f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/MC/MCObjectFileInfo.h"
22f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/MC/SectionKind.h"
23f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <cstdint>
24f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
25f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotnamespace llvm {
26f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
27f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass GlobalValue;
28f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass MachineModuleInfo;
29f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass Mangler;
30f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass MCContext;
31f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass MCExpr;
32f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass MCSection;
33f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass MCSymbol;
34f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass MCSymbolRefExpr;
35f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass MCStreamer;
36f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass MCValue;
37f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass TargetMachine;
38f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
39f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass TargetLoweringObjectFile : public MCObjectFileInfo {
40f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  MCContext *Ctx = nullptr;
41f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
42f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Name-mangler for global names.
43f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Mangler *Mang = nullptr;
44f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
45f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprotected:
46f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool SupportIndirectSymViaGOTPCRel = false;
47f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool SupportGOTPCRelWithOffset = true;
48f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
49f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// This section contains the static constructor pointer list.
50f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  MCSection *StaticCtorSection;
51f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
52f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// This section contains the static destructor pointer list.
53f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  MCSection *StaticDtorSection;
54f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
55f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
56f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  TargetLoweringObjectFile() = default;
57f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  TargetLoweringObjectFile(const TargetLoweringObjectFile &) = delete;
58f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  TargetLoweringObjectFile &
59f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  operator=(const TargetLoweringObjectFile &) = delete;
60f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual ~TargetLoweringObjectFile();
61f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
62f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  MCContext &getContext() const { return *Ctx; }
63f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Mangler &getMangler() const { return *Mang; }
64f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
65f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// This method must be called before any actual lowering is done.  This
66f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// specifies the current context for codegen, and gives the lowering
67f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// implementations a chance to set up their default sections.
68f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
69f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
70f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
71f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                    const MCSymbol *Sym) const;
72f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
73f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Emit the module-level metadata that the platform cares about.
74f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual void emitModuleMetadata(MCStreamer &Streamer, Module &M,
75f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                  const TargetMachine &TM) const {}
76f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
77f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Given a constant with the SectionKind, return a section that it should be
78f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// placed in.
79f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual MCSection *getSectionForConstant(const DataLayout &DL,
80f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                           SectionKind Kind,
81f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                           const Constant *C,
82f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                           unsigned &Align) const;
83f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
84f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Classify the specified global variable into a set of target independent
85f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// categories embodied in SectionKind.
86f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static SectionKind getKindForGlobal(const GlobalObject *GO,
87f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                      const TargetMachine &TM);
88f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
89f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// This method computes the appropriate section to emit the specified global
90f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// variable or function definition. This should not be passed external (or
91f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// available externally) globals.
92f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  MCSection *SectionForGlobal(const GlobalObject *GO, SectionKind Kind,
93f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                              const TargetMachine &TM) const;
94f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
95f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// This method computes the appropriate section to emit the specified global
96f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// variable or function definition. This should not be passed external (or
97f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// available externally) globals.
98f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  MCSection *SectionForGlobal(const GlobalObject *GO,
99f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                              const TargetMachine &TM) const {
100f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return SectionForGlobal(GO, getKindForGlobal(GO, TM), TM);
101f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
102f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
103f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
104f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                 const GlobalValue *GV,
105f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                 const TargetMachine &TM) const;
106f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
107f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual MCSection *getSectionForJumpTable(const Function &F,
108f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                            const TargetMachine &TM) const;
109f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
110f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
111f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                                   const Function &F) const;
112f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
113f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Targets should implement this method to assign a section to globals with
114f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// an explicit section specfied. The implementation of this method can
115f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// assume that GO->hasSection() is true.
116f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual MCSection *
117f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
118f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                           const TargetMachine &TM) const = 0;
119f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
120f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Return an MCExpr to use for a reference to the specified global variable
121f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// from exception handling information.
122f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
123f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                                unsigned Encoding,
124f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                                const TargetMachine &TM,
125f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                                MachineModuleInfo *MMI,
126f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                                MCStreamer &Streamer) const;
127f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
128f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Return the MCSymbol for a private symbol with global value name as its
129f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// base, with the specified suffix.
130f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
131f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                         StringRef Suffix,
132f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                         const TargetMachine &TM) const;
133f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
134f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // The symbol that gets passed to .cfi_personality.
135f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
136f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                            const TargetMachine &TM,
137f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                            MachineModuleInfo *MMI) const;
138f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
139f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const MCExpr *getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
140f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                  MCStreamer &Streamer) const;
141f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
142f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual MCSection *getStaticCtorSection(unsigned Priority,
143f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                          const MCSymbol *KeySym) const {
144f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return StaticCtorSection;
145f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
146f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
147f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual MCSection *getStaticDtorSection(unsigned Priority,
148f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                          const MCSymbol *KeySym) const {
149f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return StaticDtorSection;
150f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
151f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
152f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Create a symbol reference to describe the given TLS variable when
153f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// emitting the address in debug info.
154f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
155f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
156f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
157f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                               const GlobalValue *RHS,
158f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                               const TargetMachine &TM) const {
159f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return nullptr;
160f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
161f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
162f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Target supports replacing a data "PC"-relative access to a symbol
163f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// through another symbol, by accessing the later via a GOT entry instead?
164f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool supportIndirectSymViaGOTPCRel() const {
165f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return SupportIndirectSymViaGOTPCRel;
166f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
167f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
168f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Target GOT "PC"-relative relocation supports encoding an additional
169f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// binary expression with an offset?
170f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool supportGOTPCRelWithOffset() const {
171f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return SupportGOTPCRelWithOffset;
172f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
173f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
174f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Get the target specific PC relative GOT entry relocation
175f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
176f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                                  const MCValue &MV,
177f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                                  int64_t Offset,
178f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                                  MachineModuleInfo *MMI,
179f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                                  MCStreamer &Streamer) const {
180f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return nullptr;
181f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
182f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
183f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual void emitLinkerFlagsForGlobal(raw_ostream &OS,
184f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                        const GlobalValue *GV) const {}
185f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
186f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprotected:
187f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  virtual MCSection *SelectSectionForGlobal(const GlobalObject *GO,
188f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                            SectionKind Kind,
189f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                            const TargetMachine &TM) const = 0;
190f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
191f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
192f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot} // end namespace llvm
193f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
194f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#endif // LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
195