AArch64MCExpr.h revision 72062f5744557e270a38192554c3126ea5f97434
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#ifndef LLVM_AARCH64MCEXPR_H
11#define LLVM_AARCH64MCEXPR_H
12
13#include "llvm/MC/MCExpr.h"
14
15namespace llvm {
16
17class AArch64MCExpr : public MCTargetExpr {
18public:
19  enum VariantKind {
20    VK_AARCH64_None,
21    VK_AARCH64_GOT,      // :got: modifier in assembly
22    VK_AARCH64_GOT_LO12, // :got_lo12:
23    VK_AARCH64_LO12,     // :lo12:
24
25    VK_AARCH64_ABS_G0, // :abs_g0:
26    VK_AARCH64_ABS_G0_NC, // :abs_g0_nc:
27    VK_AARCH64_ABS_G1,
28    VK_AARCH64_ABS_G1_NC,
29    VK_AARCH64_ABS_G2,
30    VK_AARCH64_ABS_G2_NC,
31    VK_AARCH64_ABS_G3,
32
33    VK_AARCH64_SABS_G0, // :abs_g0_s:
34    VK_AARCH64_SABS_G1,
35    VK_AARCH64_SABS_G2,
36
37    VK_AARCH64_DTPREL_G2, // :dtprel_g2:
38    VK_AARCH64_DTPREL_G1,
39    VK_AARCH64_DTPREL_G1_NC,
40    VK_AARCH64_DTPREL_G0,
41    VK_AARCH64_DTPREL_G0_NC,
42    VK_AARCH64_DTPREL_HI12,
43    VK_AARCH64_DTPREL_LO12,
44    VK_AARCH64_DTPREL_LO12_NC,
45
46    VK_AARCH64_GOTTPREL_G1, // :gottprel:
47    VK_AARCH64_GOTTPREL_G0_NC,
48    VK_AARCH64_GOTTPREL,
49    VK_AARCH64_GOTTPREL_LO12,
50
51    VK_AARCH64_TPREL_G2, // :tprel:
52    VK_AARCH64_TPREL_G1,
53    VK_AARCH64_TPREL_G1_NC,
54    VK_AARCH64_TPREL_G0,
55    VK_AARCH64_TPREL_G0_NC,
56    VK_AARCH64_TPREL_HI12,
57    VK_AARCH64_TPREL_LO12,
58    VK_AARCH64_TPREL_LO12_NC,
59
60    VK_AARCH64_TLSDESC, // :tlsdesc:
61    VK_AARCH64_TLSDESC_LO12
62  };
63
64private:
65  const VariantKind Kind;
66  const MCExpr *Expr;
67
68  explicit AArch64MCExpr(VariantKind _Kind, const MCExpr *_Expr)
69    : Kind(_Kind), Expr(_Expr) {}
70
71public:
72  /// @name Construction
73  /// @{
74
75  static const AArch64MCExpr *Create(VariantKind Kind, const MCExpr *Expr,
76                                     MCContext &Ctx);
77
78  static const AArch64MCExpr *CreateLo12(const MCExpr *Expr, MCContext &Ctx) {
79    return Create(VK_AARCH64_LO12, Expr, Ctx);
80  }
81
82  static const AArch64MCExpr *CreateGOT(const MCExpr *Expr, MCContext &Ctx) {
83    return Create(VK_AARCH64_GOT, Expr, Ctx);
84  }
85
86  static const AArch64MCExpr *CreateGOTLo12(const MCExpr *Expr, MCContext &Ctx) {
87    return Create(VK_AARCH64_GOT_LO12, Expr, Ctx);
88  }
89
90  static const AArch64MCExpr *CreateDTPREL_G1(const MCExpr *Expr,
91                                             MCContext &Ctx) {
92    return Create(VK_AARCH64_DTPREL_G1, Expr, Ctx);
93  }
94
95  static const AArch64MCExpr *CreateDTPREL_G0_NC(const MCExpr *Expr,
96                                                MCContext &Ctx) {
97    return Create(VK_AARCH64_DTPREL_G0_NC, Expr, Ctx);
98  }
99
100  static const AArch64MCExpr *CreateGOTTPREL(const MCExpr *Expr,
101                                             MCContext &Ctx) {
102    return Create(VK_AARCH64_GOTTPREL, Expr, Ctx);
103  }
104
105  static const AArch64MCExpr *CreateGOTTPRELLo12(const MCExpr *Expr,
106                                                 MCContext &Ctx) {
107    return Create(VK_AARCH64_GOTTPREL_LO12, Expr, Ctx);
108  }
109
110  static const AArch64MCExpr *CreateTLSDesc(const MCExpr *Expr,
111                                            MCContext &Ctx) {
112    return Create(VK_AARCH64_TLSDESC, Expr, Ctx);
113  }
114
115  static const AArch64MCExpr *CreateTLSDescLo12(const MCExpr *Expr,
116                                                MCContext &Ctx) {
117    return Create(VK_AARCH64_TLSDESC_LO12, Expr, Ctx);
118  }
119
120  static const AArch64MCExpr *CreateTPREL_G1(const MCExpr *Expr,
121                                             MCContext &Ctx) {
122    return Create(VK_AARCH64_TPREL_G1, Expr, Ctx);
123  }
124
125  static const AArch64MCExpr *CreateTPREL_G0_NC(const MCExpr *Expr,
126                                                MCContext &Ctx) {
127    return Create(VK_AARCH64_TPREL_G0_NC, Expr, Ctx);
128  }
129
130  /// @}
131  /// @name Accessors
132  /// @{
133
134  /// getOpcode - Get the kind of this expression.
135  VariantKind getKind() const { return Kind; }
136
137  /// getSubExpr - Get the child of this expression.
138  const MCExpr *getSubExpr() const { return Expr; }
139
140  /// @}
141
142  void PrintImpl(raw_ostream &OS) const;
143  bool EvaluateAsRelocatableImpl(MCValue &Res,
144                                 const MCAsmLayout *Layout) const;
145  void AddValueSymbols(MCAssembler *) const;
146  const MCSection *FindAssociatedSection() const {
147    return getSubExpr()->FindAssociatedSection();
148  }
149
150  void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const;
151
152  static bool classof(const MCExpr *E) {
153    return E->getKind() == MCExpr::Target;
154  }
155
156  static bool classof(const AArch64MCExpr *) { return true; }
157
158};
159} // end namespace llvm
160
161#endif
162