LLVM  9.0.0svn
AArch64MCExpr.h
Go to the documentation of this file.
1 //=--- AArch64MCExpr.h - AArch64 specific MC expression classes ---*- 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 describes AArch64-specific MCExprs, used for modifiers like
10 // ":lo12:" or ":gottprel_g1:".
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64MCEXPR_H
15 #define LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64MCEXPR_H
16 
17 #include "llvm/MC/MCExpr.h"
19 
20 namespace llvm {
21 
22 class AArch64MCExpr : public MCTargetExpr {
23 public:
24  enum VariantKind {
25  VK_NONE = 0x000,
26 
27  // Symbol locations specifying (roughly speaking) what calculation should be
28  // performed to construct the final address for the relocated
29  // symbol. E.g. direct, via the GOT, ...
30  VK_ABS = 0x001,
31  VK_SABS = 0x002,
32  VK_GOT = 0x003,
33  VK_DTPREL = 0x004,
34  VK_GOTTPREL = 0x005,
35  VK_TPREL = 0x006,
36  VK_TLSDESC = 0x007,
37  VK_SECREL = 0x008,
38  VK_SymLocBits = 0x00f,
39 
40  // Variants specifying which part of the final address calculation is
41  // used. E.g. the low 12 bits for an ADD/LDR, the middle 16 bits for a
42  // MOVZ/MOVK.
43  VK_PAGE = 0x010,
44  VK_PAGEOFF = 0x020,
45  VK_HI12 = 0x030,
46  VK_G0 = 0x040,
47  VK_G1 = 0x050,
48  VK_G2 = 0x060,
49  VK_G3 = 0x070,
51 
52  // Whether the final relocation is a checked one (where a linker should
53  // perform a range-check on the final address) or not. Note that this field
54  // is unfortunately sometimes omitted from the assembly syntax. E.g. :lo12:
55  // on its own is a non-checked relocation. We side with ELF on being
56  // explicit about this!
57  VK_NC = 0x100,
58 
59  // Convenience definitions for referring to specific textual representations
60  // of relocation specifiers. Note that this means the "_NC" is sometimes
61  // omitted in line with assembly syntax here (VK_LO12 rather than VK_LO12_NC
62  // since a user would write ":lo12:").
103 
104  VK_INVALID = 0xfff
105  };
106 
107 private:
108  const MCExpr *Expr;
109  const VariantKind Kind;
110 
111  explicit AArch64MCExpr(const MCExpr *Expr, VariantKind Kind)
112  : Expr(Expr), Kind(Kind) {}
113 
114 public:
115  /// @name Construction
116  /// @{
117 
118  static const AArch64MCExpr *create(const MCExpr *Expr, VariantKind Kind,
119  MCContext &Ctx);
120 
121  /// @}
122  /// @name Accessors
123  /// @{
124 
125  /// Get the kind of this expression.
126  VariantKind getKind() const { return Kind; }
127 
128  /// Get the expression this modifier applies to.
129  const MCExpr *getSubExpr() const { return Expr; }
130 
131  /// @}
132  /// @name VariantKind information extractors.
133  /// @{
134 
136  return static_cast<VariantKind>(Kind & VK_SymLocBits);
137  }
138 
140  return static_cast<VariantKind>(Kind & VK_AddressFragBits);
141  }
142 
143  static bool isNotChecked(VariantKind Kind) { return Kind & VK_NC; }
144 
145  /// @}
146 
147  /// Convert the variant kind into an ELF-appropriate modifier
148  /// (e.g. ":got:", ":lo12:").
150 
151  void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
152 
153  void visitUsedExpr(MCStreamer &Streamer) const override;
154 
155  MCFragment *findAssociatedFragment() const override;
156 
157  bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
158  const MCFixup *Fixup) const override;
159 
160  void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
161 
162  static bool classof(const MCExpr *E) {
163  return E->getKind() == MCExpr::Target;
164  }
165 
166  static bool classof(const AArch64MCExpr *) { return true; }
167 };
168 } // end namespace llvm
169 
170 #endif
VariantKind getKind() const
Get the kind of this expression.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This represents an "assembler immediate".
Definition: MCValue.h:39
static const AArch64MCExpr * create(const MCExpr *Expr, VariantKind Kind, MCContext &Ctx)
static bool classof(const AArch64MCExpr *)
StringRef getVariantKindName() const
Convert the variant kind into an ELF-appropriate modifier (e.g.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:73
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
This is an extension point for target-specific MCExpr subclasses to implement.
Definition: MCExpr.h:579
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
Context object for machine code objects.
Definition: MCContext.h:62
static VariantKind getAddressFrag(VariantKind Kind)
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:55
Streaming machine code generation interface.
Definition: MCStreamer.h:188
const MCExpr * getSubExpr() const
Get the expression this modifier applies to.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void visitUsedExpr(MCStreamer &Streamer) const override
PowerPC TLS Dynamic Call Fixup
ExprKind getKind() const
Definition: MCExpr.h:72
static bool isNotChecked(VariantKind Kind)
static bool classof(const MCExpr *E)
static VariantKind getSymbolLoc(VariantKind Kind)
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Target specific expression.
Definition: MCExpr.h:42
MCFragment * findAssociatedFragment() const override