1 //==- AArch64MCExpr.h - AArch64 specific MC expression classes --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes AArch64-specific MCExprs, used for modifiers like
11 // ":lo12:" or ":gottprel_g1:".
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_AARCH64MCEXPR_H
16 #define LLVM_AARCH64MCEXPR_H
18 #include "llvm/MC/MCExpr.h"
22 class AArch64MCExpr : public MCTargetExpr {
26 VK_AARCH64_GOT, // :got: modifier in assembly
27 VK_AARCH64_GOT_LO12, // :got_lo12:
28 VK_AARCH64_LO12, // :lo12:
30 VK_AARCH64_ABS_G0, // :abs_g0:
31 VK_AARCH64_ABS_G0_NC, // :abs_g0_nc:
38 VK_AARCH64_SABS_G0, // :abs_g0_s:
42 VK_AARCH64_DTPREL_G2, // :dtprel_g2:
44 VK_AARCH64_DTPREL_G1_NC,
46 VK_AARCH64_DTPREL_G0_NC,
47 VK_AARCH64_DTPREL_HI12,
48 VK_AARCH64_DTPREL_LO12,
49 VK_AARCH64_DTPREL_LO12_NC,
51 VK_AARCH64_GOTTPREL_G1, // :gottprel:
52 VK_AARCH64_GOTTPREL_G0_NC,
54 VK_AARCH64_GOTTPREL_LO12,
56 VK_AARCH64_TPREL_G2, // :tprel:
58 VK_AARCH64_TPREL_G1_NC,
60 VK_AARCH64_TPREL_G0_NC,
61 VK_AARCH64_TPREL_HI12,
62 VK_AARCH64_TPREL_LO12,
63 VK_AARCH64_TPREL_LO12_NC,
65 VK_AARCH64_TLSDESC, // :tlsdesc:
66 VK_AARCH64_TLSDESC_LO12
70 const VariantKind Kind;
73 explicit AArch64MCExpr(VariantKind _Kind, const MCExpr *_Expr)
74 : Kind(_Kind), Expr(_Expr) {}
77 /// @name Construction
80 static const AArch64MCExpr *Create(VariantKind Kind, const MCExpr *Expr,
83 static const AArch64MCExpr *CreateLo12(const MCExpr *Expr, MCContext &Ctx) {
84 return Create(VK_AARCH64_LO12, Expr, Ctx);
87 static const AArch64MCExpr *CreateGOT(const MCExpr *Expr, MCContext &Ctx) {
88 return Create(VK_AARCH64_GOT, Expr, Ctx);
91 static const AArch64MCExpr *CreateGOTLo12(const MCExpr *Expr,
93 return Create(VK_AARCH64_GOT_LO12, Expr, Ctx);
96 static const AArch64MCExpr *CreateDTPREL_G1(const MCExpr *Expr,
98 return Create(VK_AARCH64_DTPREL_G1, Expr, Ctx);
101 static const AArch64MCExpr *CreateDTPREL_G0_NC(const MCExpr *Expr,
103 return Create(VK_AARCH64_DTPREL_G0_NC, Expr, Ctx);
106 static const AArch64MCExpr *CreateGOTTPREL(const MCExpr *Expr,
108 return Create(VK_AARCH64_GOTTPREL, Expr, Ctx);
111 static const AArch64MCExpr *CreateGOTTPRELLo12(const MCExpr *Expr,
113 return Create(VK_AARCH64_GOTTPREL_LO12, Expr, Ctx);
116 static const AArch64MCExpr *CreateTLSDesc(const MCExpr *Expr,
118 return Create(VK_AARCH64_TLSDESC, Expr, Ctx);
121 static const AArch64MCExpr *CreateTLSDescLo12(const MCExpr *Expr,
123 return Create(VK_AARCH64_TLSDESC_LO12, Expr, Ctx);
126 static const AArch64MCExpr *CreateTPREL_G1(const MCExpr *Expr,
128 return Create(VK_AARCH64_TPREL_G1, Expr, Ctx);
131 static const AArch64MCExpr *CreateTPREL_G0_NC(const MCExpr *Expr,
133 return Create(VK_AARCH64_TPREL_G0_NC, Expr, Ctx);
136 static const AArch64MCExpr *CreateABS_G3(const MCExpr *Expr,
138 return Create(VK_AARCH64_ABS_G3, Expr, Ctx);
141 static const AArch64MCExpr *CreateABS_G2_NC(const MCExpr *Expr,
143 return Create(VK_AARCH64_ABS_G2_NC, Expr, Ctx);
146 static const AArch64MCExpr *CreateABS_G1_NC(const MCExpr *Expr,
148 return Create(VK_AARCH64_ABS_G1_NC, Expr, Ctx);
151 static const AArch64MCExpr *CreateABS_G0_NC(const MCExpr *Expr,
153 return Create(VK_AARCH64_ABS_G0_NC, Expr, Ctx);
160 /// getOpcode - Get the kind of this expression.
161 VariantKind getKind() const { return Kind; }
163 /// getSubExpr - Get the child of this expression.
164 const MCExpr *getSubExpr() const { return Expr; }
168 void PrintImpl(raw_ostream &OS) const;
169 bool EvaluateAsRelocatableImpl(MCValue &Res,
170 const MCAsmLayout *Layout) const;
171 void AddValueSymbols(MCAssembler *) const;
172 const MCSection *FindAssociatedSection() const {
173 return getSubExpr()->FindAssociatedSection();
176 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const;
178 static bool classof(const MCExpr *E) {
179 return E->getKind() == MCExpr::Target;
182 static bool classof(const AArch64MCExpr *) { return true; }
185 } // end namespace llvm