LLVM  14.0.0git
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  // Symbol locations specifying (roughly speaking) what calculation should be
26  // performed to construct the final address for the relocated
27  // symbol. E.g. direct, via the GOT, ...
28  VK_ABS = 0x001,
29  VK_SABS = 0x002,
30  VK_PREL = 0x003,
31  VK_GOT = 0x004,
32  VK_DTPREL = 0x005,
33  VK_GOTTPREL = 0x006,
34  VK_TPREL = 0x007,
35  VK_TLSDESC = 0x008,
36  VK_SECREL = 0x009,
37  VK_SymLocBits = 0x00f,
38 
39  // Variants specifying which part of the final address calculation is
40  // used. E.g. the low 12 bits for an ADD/LDR, the middle 16 bits for a
41  // MOVZ/MOVK.
42  VK_PAGE = 0x010,
43  VK_PAGEOFF = 0x020,
44  VK_HI12 = 0x030,
45  VK_G0 = 0x040,
46  VK_G1 = 0x050,
47  VK_G2 = 0x060,
48  VK_G3 = 0x070,
49  VK_LO15 = 0x080,
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:").
111 
112  VK_INVALID = 0xfff
113  };
114 
115 private:
116  const MCExpr *Expr;
117  const VariantKind Kind;
118 
119  explicit AArch64MCExpr(const MCExpr *Expr, VariantKind Kind)
120  : Expr(Expr), Kind(Kind) {}
121 
122 public:
123  /// @name Construction
124  /// @{
125 
126  static const AArch64MCExpr *create(const MCExpr *Expr, VariantKind Kind,
127  MCContext &Ctx);
128 
129  /// @}
130  /// @name Accessors
131  /// @{
132 
133  /// Get the kind of this expression.
134  VariantKind getKind() const { return Kind; }
135 
136  /// Get the expression this modifier applies to.
137  const MCExpr *getSubExpr() const { return Expr; }
138 
139  /// @}
140  /// @name VariantKind information extractors.
141  /// @{
142 
144  return static_cast<VariantKind>(Kind & VK_SymLocBits);
145  }
146 
148  return static_cast<VariantKind>(Kind & VK_AddressFragBits);
149  }
150 
151  static bool isNotChecked(VariantKind Kind) { return Kind & VK_NC; }
152 
153  /// @}
154 
155  /// Convert the variant kind into an ELF-appropriate modifier
156  /// (e.g. ":got:", ":lo12:").
158 
159  void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
160 
161  void visitUsedExpr(MCStreamer &Streamer) const override;
162 
163  MCFragment *findAssociatedFragment() const override;
164 
165  bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
166  const MCFixup *Fixup) const override;
167 
168  void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
169 
170  static bool classof(const MCExpr *E) {
171  return E->getKind() == MCExpr::Target;
172  }
173 
174  static bool classof(const AArch64MCExpr *) { return true; }
175 };
176 } // end namespace llvm
177 
178 #endif
llvm::AArch64MCExpr::create
static const AArch64MCExpr * create(const MCExpr *Expr, VariantKind Kind, MCContext &Ctx)
Definition: AArch64MCExpr.cpp:26
llvm::AArch64MCExpr::VK_PREL_G2_NC
@ VK_PREL_G2_NC
Definition: AArch64MCExpr.h:79
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::AArch64MCExpr::VK_ABS_G0_S
@ VK_ABS_G0_S
Definition: AArch64MCExpr.h:74
llvm::AArch64MCExpr::VK_ABS_PAGE_NC
@ VK_ABS_PAGE_NC
Definition: AArch64MCExpr.h:65
llvm::AArch64MCExpr::VK_ABS
@ VK_ABS
Definition: AArch64MCExpr.h:28
llvm::AArch64MCExpr::VK_GOTTPREL_PAGE
@ VK_GOTTPREL_PAGE
Definition: AArch64MCExpr.h:95
llvm::AArch64MCExpr::getKind
VariantKind getKind() const
Get the kind of this expression.
Definition: AArch64MCExpr.h:134
llvm::AArch64MCExpr::findAssociatedFragment
MCFragment * findAssociatedFragment() const override
Definition: AArch64MCExpr.cpp:98
llvm::AArch64MCExpr::VK_LO12
@ VK_LO12
Definition: AArch64MCExpr.h:76
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::AArch64MCExpr::VK_TLSDESC_LO12
@ VK_TLSDESC_LO12
Definition: AArch64MCExpr.h:107
ErrorHandling.h
llvm::AArch64MCExpr::VK_NC
@ VK_NC
Definition: AArch64MCExpr.h:57
llvm::AArch64MCExpr::VK_HI12
@ VK_HI12
Definition: AArch64MCExpr.h:44
llvm::AArch64MCExpr::VK_ABS_G1_NC
@ VK_ABS_G1_NC
Definition: AArch64MCExpr.h:72
llvm::AArch64MCExpr::VK_DTPREL_G1_NC
@ VK_DTPREL_G1_NC
Definition: AArch64MCExpr.h:89
llvm::AArch64MCExpr::VK_ABS_G1
@ VK_ABS_G1
Definition: AArch64MCExpr.h:70
llvm::AArch64MCExpr::VK_TPREL_LO12
@ VK_TPREL_LO12
Definition: AArch64MCExpr.h:105
llvm::AArch64MCExpr::VK_TPREL
@ VK_TPREL
Definition: AArch64MCExpr.h:34
llvm::AArch64MCExpr::evaluateAsRelocatableImpl
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
Definition: AArch64MCExpr.cpp:102
llvm::AArch64MCExpr::VK_DTPREL
@ VK_DTPREL
Definition: AArch64MCExpr.h:32
llvm::AArch64MCExpr::VK_GOT_PAGE
@ VK_GOT_PAGE
Definition: AArch64MCExpr.h:85
llvm::MCFragment
Definition: MCFragment.h:31
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
llvm::AArch64MCExpr::VK_SECREL
@ VK_SECREL
Definition: AArch64MCExpr.h:36
llvm::AArch64MCExpr::getSubExpr
const MCExpr * getSubExpr() const
Get the expression this modifier applies to.
Definition: AArch64MCExpr.h:137
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::AArch64MCExpr::VK_TPREL_LO12_NC
@ VK_TPREL_LO12_NC
Definition: AArch64MCExpr.h:106
llvm::MCExpr::Target
@ Target
Target specific expression.
Definition: MCExpr.h:42
llvm::AArch64MCExpr::VK_SymLocBits
@ VK_SymLocBits
Definition: AArch64MCExpr.h:37
llvm::AArch64MCExpr::VK_PREL_G0_NC
@ VK_PREL_G0_NC
Definition: AArch64MCExpr.h:83
llvm::AArch64MCExpr::VK_G1
@ VK_G1
Definition: AArch64MCExpr.h:46
llvm::AArch64MCExpr::VK_TPREL_G0_NC
@ VK_TPREL_G0_NC
Definition: AArch64MCExpr.h:103
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::AArch64MCExpr::VK_PREL_G1_NC
@ VK_PREL_G1_NC
Definition: AArch64MCExpr.h:81
llvm::AArch64MCExpr::isNotChecked
static bool isNotChecked(VariantKind Kind)
Definition: AArch64MCExpr.h:151
llvm::AArch64MCExpr::VK_GOTTPREL_G0_NC
@ VK_GOTTPREL_G0_NC
Definition: AArch64MCExpr.h:98
llvm::AArch64MCExpr::VK_GOTTPREL_LO12_NC
@ VK_GOTTPREL_LO12_NC
Definition: AArch64MCExpr.h:96
llvm::AArch64MCExpr::VK_PAGEOFF
@ VK_PAGEOFF
Definition: AArch64MCExpr.h:43
llvm::AArch64MCExpr::VK_ABS_PAGE
@ VK_ABS_PAGE
Definition: AArch64MCExpr.h:64
llvm::AArch64MCExpr::VK_GOT_LO12
@ VK_GOT_LO12
Definition: AArch64MCExpr.h:84
llvm::AArch64MCExpr::VK_ABS_G2_NC
@ VK_ABS_G2_NC
Definition: AArch64MCExpr.h:69
llvm::MCAssembler
Definition: MCAssembler.h:60
llvm::AArch64MCExpr::VK_TPREL_G1
@ VK_TPREL_G1
Definition: AArch64MCExpr.h:100
llvm::AArch64MCExpr::VK_PREL_G1
@ VK_PREL_G1
Definition: AArch64MCExpr.h:80
llvm::AArch64MCExpr::VK_PAGE
@ VK_PAGE
Definition: AArch64MCExpr.h:42
llvm::MCExpr::MCExpr
MCExpr(ExprKind Kind, SMLoc Loc, unsigned SubclassData=0)
Definition: MCExpr.h:61
llvm::AArch64MCExpr::VK_ABS_G0_NC
@ VK_ABS_G0_NC
Definition: AArch64MCExpr.h:75
llvm::AArch64MCExpr::VK_DTPREL_HI12
@ VK_DTPREL_HI12
Definition: AArch64MCExpr.h:92
llvm::AArch64MCExpr::VK_SECREL_LO12
@ VK_SECREL_LO12
Definition: AArch64MCExpr.h:109
llvm::AArch64MCExpr::fixELFSymbolsInTLSFixups
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
Definition: AArch64MCExpr.cpp:143
llvm::AArch64MCExpr::getAddressFrag
static VariantKind getAddressFrag(VariantKind Kind)
Definition: AArch64MCExpr.h:147
llvm::AArch64MCExpr::VK_PREL_G2
@ VK_PREL_G2
Definition: AArch64MCExpr.h:78
llvm::AArch64MCExpr::VK_DTPREL_G2
@ VK_DTPREL_G2
Definition: AArch64MCExpr.h:87
llvm::AArch64MCExpr::VK_DTPREL_G0
@ VK_DTPREL_G0
Definition: AArch64MCExpr.h:90
llvm::AArch64MCExpr::VK_PREL_G0
@ VK_PREL_G0
Definition: AArch64MCExpr.h:82
llvm::AArch64MCExpr::VK_GOTTPREL_G1
@ VK_GOTTPREL_G1
Definition: AArch64MCExpr.h:97
llvm::AArch64MCExpr::VK_ABS_G0
@ VK_ABS_G0
Definition: AArch64MCExpr.h:73
llvm::AArch64MCExpr::VK_DTPREL_G1
@ VK_DTPREL_G1
Definition: AArch64MCExpr.h:88
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AArch64MCExpr::VK_TPREL_G1_NC
@ VK_TPREL_G1_NC
Definition: AArch64MCExpr.h:101
llvm::AArch64MCExpr::classof
static bool classof(const MCExpr *E)
Definition: AArch64MCExpr.h:170
llvm::AArch64MCExpr::VK_ABS_G2_S
@ VK_ABS_G2_S
Definition: AArch64MCExpr.h:68
llvm::AArch64MCExpr::VK_DTPREL_LO12_NC
@ VK_DTPREL_LO12_NC
Definition: AArch64MCExpr.h:94
llvm::AArch64MCExpr::VK_INVALID
@ VK_INVALID
Definition: AArch64MCExpr.h:112
llvm::AArch64MCExpr::VK_GOT_PAGE_LO15
@ VK_GOT_PAGE_LO15
Definition: AArch64MCExpr.h:86
llvm::AArch64MCExpr::visitUsedExpr
void visitUsedExpr(MCStreamer &Streamer) const override
Definition: AArch64MCExpr.cpp:94
llvm::AArch64MCExpr::VK_ABS_G3
@ VK_ABS_G3
Definition: AArch64MCExpr.h:66
llvm::AArch64MCExpr::VK_TPREL_G2
@ VK_TPREL_G2
Definition: AArch64MCExpr.h:99
llvm::MCAsmLayout
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
llvm::AArch64MCExpr::classof
static bool classof(const AArch64MCExpr *)
Definition: AArch64MCExpr.h:174
llvm::AArch64MCExpr
Definition: AArch64MCExpr.h:22
llvm::AArch64MCExpr::VK_ABS_G2
@ VK_ABS_G2
Definition: AArch64MCExpr.h:67
llvm::AArch64MCExpr::VK_G3
@ VK_G3
Definition: AArch64MCExpr.h:48
llvm::AArch64MCExpr::printImpl
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: AArch64MCExpr.cpp:89
llvm::AArch64MCExpr::VK_PREL_G3
@ VK_PREL_G3
Definition: AArch64MCExpr.h:77
llvm::AArch64MCExpr::getVariantKindName
StringRef getVariantKindName() const
Convert the variant kind into an ELF-appropriate modifier (e.g.
Definition: AArch64MCExpr.cpp:31
llvm::AArch64MCExpr::VK_ABS_G1_S
@ VK_ABS_G1_S
Definition: AArch64MCExpr.h:71
llvm::AArch64MCExpr::VariantKind
VariantKind
Definition: AArch64MCExpr.h:24
llvm::AArch64MCExpr::VK_DTPREL_LO12
@ VK_DTPREL_LO12
Definition: AArch64MCExpr.h:93
llvm::AArch64MCExpr::VK_TLSDESC
@ VK_TLSDESC
Definition: AArch64MCExpr.h:35
llvm::AArch64MCExpr::VK_AddressFragBits
@ VK_AddressFragBits
Definition: AArch64MCExpr.h:50
llvm::AArch64MCExpr::VK_TPREL_HI12
@ VK_TPREL_HI12
Definition: AArch64MCExpr.h:104
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::AArch64MCExpr::VK_TPREL_G0
@ VK_TPREL_G0
Definition: AArch64MCExpr.h:102
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
llvm::AArch64MCExpr::VK_TLSDESC_PAGE
@ VK_TLSDESC_PAGE
Definition: AArch64MCExpr.h:108
llvm::AArch64MCExpr::getSymbolLoc
static VariantKind getSymbolLoc(VariantKind Kind)
Definition: AArch64MCExpr.h:143
llvm::AArch64MCExpr::VK_GOTTPREL
@ VK_GOTTPREL
Definition: AArch64MCExpr.h:33
llvm::MCTargetExpr
This is an extension point for target-specific MCExpr subclasses to implement.
Definition: MCExpr.h:644
MCExpr.h
llvm::AArch64MCExpr::VK_LO15
@ VK_LO15
Definition: AArch64MCExpr.h:49
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
llvm::AArch64MCExpr::VK_G2
@ VK_G2
Definition: AArch64MCExpr.h:47
llvm::AArch64MCExpr::VK_DTPREL_G0_NC
@ VK_DTPREL_G0_NC
Definition: AArch64MCExpr.h:91
llvm::AArch64MCExpr::VK_SECREL_HI12
@ VK_SECREL_HI12
Definition: AArch64MCExpr.h:110
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::AArch64MCExpr::VK_G0
@ VK_G0
Definition: AArch64MCExpr.h:45
llvm::AArch64MCExpr::VK_SABS
@ VK_SABS
Definition: AArch64MCExpr.h:29
llvm::AArch64MCExpr::VK_PREL
@ VK_PREL
Definition: AArch64MCExpr.h:30
llvm::AArch64MCExpr::VK_CALL
@ VK_CALL
Definition: AArch64MCExpr.h:63
llvm::AArch64MCExpr::VK_GOT
@ VK_GOT
Definition: AArch64MCExpr.h:31