Line data Source code
1 : //=--- AArch64MCExpr.h - AArch64 specific MC expression classes ---*- 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 describes AArch64-specific MCExprs, used for modifiers like
11 : // ":lo12:" or ":gottprel_g1:".
12 : //
13 : //===----------------------------------------------------------------------===//
14 :
15 : #ifndef LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64MCEXPR_H
16 : #define LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64MCEXPR_H
17 :
18 : #include "llvm/MC/MCExpr.h"
19 : #include "llvm/Support/ErrorHandling.h"
20 :
21 : namespace llvm {
22 :
23 : class AArch64MCExpr : public MCTargetExpr {
24 : public:
25 : enum VariantKind {
26 : VK_NONE = 0x000,
27 :
28 : // Symbol locations specifying (roughly speaking) what calculation should be
29 : // performed to construct the final address for the relocated
30 : // symbol. E.g. direct, via the GOT, ...
31 : VK_ABS = 0x001,
32 : VK_SABS = 0x002,
33 : VK_GOT = 0x003,
34 : VK_DTPREL = 0x004,
35 : VK_GOTTPREL = 0x005,
36 : VK_TPREL = 0x006,
37 : VK_TLSDESC = 0x007,
38 : VK_SECREL = 0x008,
39 : VK_SymLocBits = 0x00f,
40 :
41 : // Variants specifying which part of the final address calculation is
42 : // used. E.g. the low 12 bits for an ADD/LDR, the middle 16 bits for a
43 : // MOVZ/MOVK.
44 : VK_PAGE = 0x010,
45 : VK_PAGEOFF = 0x020,
46 : VK_HI12 = 0x030,
47 : VK_G0 = 0x040,
48 : VK_G1 = 0x050,
49 : VK_G2 = 0x060,
50 : VK_G3 = 0x070,
51 : VK_AddressFragBits = 0x0f0,
52 :
53 : // Whether the final relocation is a checked one (where a linker should
54 : // perform a range-check on the final address) or not. Note that this field
55 : // is unfortunately sometimes omitted from the assembly syntax. E.g. :lo12:
56 : // on its own is a non-checked relocation. We side with ELF on being
57 : // explicit about this!
58 : VK_NC = 0x100,
59 :
60 : // Convenience definitions for referring to specific textual representations
61 : // of relocation specifiers. Note that this means the "_NC" is sometimes
62 : // omitted in line with assembly syntax here (VK_LO12 rather than VK_LO12_NC
63 : // since a user would write ":lo12:").
64 : VK_CALL = VK_ABS,
65 : VK_ABS_PAGE = VK_ABS | VK_PAGE,
66 : VK_ABS_PAGE_NC = VK_ABS | VK_PAGE | VK_NC,
67 : VK_ABS_G3 = VK_ABS | VK_G3,
68 : VK_ABS_G2 = VK_ABS | VK_G2,
69 : VK_ABS_G2_S = VK_SABS | VK_G2,
70 : VK_ABS_G2_NC = VK_ABS | VK_G2 | VK_NC,
71 : VK_ABS_G1 = VK_ABS | VK_G1,
72 : VK_ABS_G1_S = VK_SABS | VK_G1,
73 : VK_ABS_G1_NC = VK_ABS | VK_G1 | VK_NC,
74 : VK_ABS_G0 = VK_ABS | VK_G0,
75 : VK_ABS_G0_S = VK_SABS | VK_G0,
76 : VK_ABS_G0_NC = VK_ABS | VK_G0 | VK_NC,
77 : VK_LO12 = VK_ABS | VK_PAGEOFF | VK_NC,
78 : VK_GOT_LO12 = VK_GOT | VK_PAGEOFF | VK_NC,
79 : VK_GOT_PAGE = VK_GOT | VK_PAGE,
80 : VK_DTPREL_G2 = VK_DTPREL | VK_G2,
81 : VK_DTPREL_G1 = VK_DTPREL | VK_G1,
82 : VK_DTPREL_G1_NC = VK_DTPREL | VK_G1 | VK_NC,
83 : VK_DTPREL_G0 = VK_DTPREL | VK_G0,
84 : VK_DTPREL_G0_NC = VK_DTPREL | VK_G0 | VK_NC,
85 : VK_DTPREL_HI12 = VK_DTPREL | VK_HI12,
86 : VK_DTPREL_LO12 = VK_DTPREL | VK_PAGEOFF,
87 : VK_DTPREL_LO12_NC = VK_DTPREL | VK_PAGEOFF | VK_NC,
88 : VK_GOTTPREL_PAGE = VK_GOTTPREL | VK_PAGE,
89 : VK_GOTTPREL_LO12_NC = VK_GOTTPREL | VK_PAGEOFF | VK_NC,
90 : VK_GOTTPREL_G1 = VK_GOTTPREL | VK_G1,
91 : VK_GOTTPREL_G0_NC = VK_GOTTPREL | VK_G0 | VK_NC,
92 : VK_TPREL_G2 = VK_TPREL | VK_G2,
93 : VK_TPREL_G1 = VK_TPREL | VK_G1,
94 : VK_TPREL_G1_NC = VK_TPREL | VK_G1 | VK_NC,
95 : VK_TPREL_G0 = VK_TPREL | VK_G0,
96 : VK_TPREL_G0_NC = VK_TPREL | VK_G0 | VK_NC,
97 : VK_TPREL_HI12 = VK_TPREL | VK_HI12,
98 : VK_TPREL_LO12 = VK_TPREL | VK_PAGEOFF,
99 : VK_TPREL_LO12_NC = VK_TPREL | VK_PAGEOFF | VK_NC,
100 : VK_TLSDESC_LO12 = VK_TLSDESC | VK_PAGEOFF,
101 : VK_TLSDESC_PAGE = VK_TLSDESC | VK_PAGE,
102 : VK_SECREL_LO12 = VK_SECREL | VK_PAGEOFF,
103 : VK_SECREL_HI12 = VK_SECREL | VK_HI12,
104 :
105 : VK_INVALID = 0xfff
106 : };
107 :
108 : private:
109 : const MCExpr *Expr;
110 : const VariantKind Kind;
111 :
112 : explicit AArch64MCExpr(const MCExpr *Expr, VariantKind Kind)
113 18676 : : Expr(Expr), Kind(Kind) {}
114 :
115 : public:
116 : /// @name Construction
117 : /// @{
118 :
119 : static const AArch64MCExpr *create(const MCExpr *Expr, VariantKind Kind,
120 : MCContext &Ctx);
121 :
122 : /// @}
123 : /// @name Accessors
124 : /// @{
125 :
126 : /// Get the kind of this expression.
127 0 : VariantKind getKind() const { return Kind; }
128 :
129 : /// Get the expression this modifier applies to.
130 0 : const MCExpr *getSubExpr() const { return Expr; }
131 :
132 : /// @}
133 : /// @name VariantKind information extractors.
134 : /// @{
135 :
136 : static VariantKind getSymbolLoc(VariantKind Kind) {
137 2325 : return static_cast<VariantKind>(Kind & VK_SymLocBits);
138 : }
139 :
140 : static VariantKind getAddressFrag(VariantKind Kind) {
141 : return static_cast<VariantKind>(Kind & VK_AddressFragBits);
142 : }
143 :
144 1088 : static bool isNotChecked(VariantKind Kind) { return Kind & VK_NC; }
145 :
146 : /// @}
147 :
148 : /// Convert the variant kind into an ELF-appropriate modifier
149 : /// (e.g. ":got:", ":lo12:").
150 : StringRef getVariantKindName() const;
151 :
152 : void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
153 :
154 : void visitUsedExpr(MCStreamer &Streamer) const override;
155 :
156 : MCFragment *findAssociatedFragment() const override;
157 :
158 : bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
159 : const MCFixup *Fixup) const override;
160 :
161 : void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
162 :
163 : static bool classof(const MCExpr *E) {
164 2318 : return E->getKind() == MCExpr::Target;
165 : }
166 :
167 : static bool classof(const AArch64MCExpr *) { return true; }
168 : };
169 : } // end namespace llvm
170 :
171 : #endif
|