AArch64MCExpr.h revision dfe076af9879eb68a7b8331f9c02eecf563d85be
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,
87                                            MCContext &Ctx) {
88    return Create(VK_AARCH64_GOT_LO12, Expr, Ctx);
89  }
90
91  static const AArch64MCExpr *CreateDTPREL_G1(const MCExpr *Expr,
92                                             MCContext &Ctx) {
93    return Create(VK_AARCH64_DTPREL_G1, Expr, Ctx);
94  }
95
96  static const AArch64MCExpr *CreateDTPREL_G0_NC(const MCExpr *Expr,
97                                                MCContext &Ctx) {
98    return Create(VK_AARCH64_DTPREL_G0_NC, Expr, Ctx);
99  }
100
101  static const AArch64MCExpr *CreateGOTTPREL(const MCExpr *Expr,
102                                             MCContext &Ctx) {
103    return Create(VK_AARCH64_GOTTPREL, Expr, Ctx);
104  }
105
106  static const AArch64MCExpr *CreateGOTTPRELLo12(const MCExpr *Expr,
107                                                 MCContext &Ctx) {
108    return Create(VK_AARCH64_GOTTPREL_LO12, Expr, Ctx);
109  }
110
111  static const AArch64MCExpr *CreateTLSDesc(const MCExpr *Expr,
112                                            MCContext &Ctx) {
113    return Create(VK_AARCH64_TLSDESC, Expr, Ctx);
114  }
115
116  static const AArch64MCExpr *CreateTLSDescLo12(const MCExpr *Expr,
117                                                MCContext &Ctx) {
118    return Create(VK_AARCH64_TLSDESC_LO12, Expr, Ctx);
119  }
120
121  static const AArch64MCExpr *CreateTPREL_G1(const MCExpr *Expr,
122                                             MCContext &Ctx) {
123    return Create(VK_AARCH64_TPREL_G1, Expr, Ctx);
124  }
125
126  static const AArch64MCExpr *CreateTPREL_G0_NC(const MCExpr *Expr,
127                                                MCContext &Ctx) {
128    return Create(VK_AARCH64_TPREL_G0_NC, Expr, Ctx);
129  }
130
131  /// @}
132  /// @name Accessors
133  /// @{
134
135  /// getOpcode - Get the kind of this expression.
136  VariantKind getKind() const { return Kind; }
137
138  /// getSubExpr - Get the child of this expression.
139  const MCExpr *getSubExpr() const { return Expr; }
140
141  /// @}
142
143  void PrintImpl(raw_ostream &OS) const;
144  bool EvaluateAsRelocatableImpl(MCValue &Res,
145                                 const MCAsmLayout *Layout) const;
146  void AddValueSymbols(MCAssembler *) const;
147  const MCSection *FindAssociatedSection() const {
148    return getSubExpr()->FindAssociatedSection();
149  }
150
151  void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const;
152
153  static bool classof(const MCExpr *E) {
154    return E->getKind() == MCExpr::Target;
155  }
156
157  static bool classof(const AArch64MCExpr *) { return true; }
158
159};
160} // end namespace llvm
161
162#endif
163