xref: /freebsd/contrib/llvm-project/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 //= LoongArchMCExpr.h - LoongArch 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 LoongArch-specific MCExprs, used for modifiers like
10 // "%pc_hi20" or "%pc_lo12" etc.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_LOONGARCH_MCTARGETDESC_LOONGARCHMCEXPR_H
15 #define LLVM_LIB_TARGET_LOONGARCH_MCTARGETDESC_LOONGARCHMCEXPR_H
16 
17 #include "llvm/MC/MCExpr.h"
18 
19 namespace llvm {
20 
21 class StringRef;
22 
23 class LoongArchMCExpr : public MCTargetExpr {
24 public:
25   enum VariantKind {
26     VK_LoongArch_None,
27     VK_LoongArch_CALL,
28     VK_LoongArch_CALL_PLT,
29     VK_LoongArch_B16,
30     VK_LoongArch_B21,
31     VK_LoongArch_B26,
32     VK_LoongArch_ABS_HI20,
33     VK_LoongArch_ABS_LO12,
34     VK_LoongArch_ABS64_LO20,
35     VK_LoongArch_ABS64_HI12,
36     VK_LoongArch_PCALA_HI20,
37     VK_LoongArch_PCALA_LO12,
38     VK_LoongArch_PCALA64_LO20,
39     VK_LoongArch_PCALA64_HI12,
40     VK_LoongArch_GOT_PC_HI20,
41     VK_LoongArch_GOT_PC_LO12,
42     VK_LoongArch_GOT64_PC_LO20,
43     VK_LoongArch_GOT64_PC_HI12,
44     VK_LoongArch_GOT_HI20,
45     VK_LoongArch_GOT_LO12,
46     VK_LoongArch_GOT64_LO20,
47     VK_LoongArch_GOT64_HI12,
48     VK_LoongArch_TLS_LE_HI20,
49     VK_LoongArch_TLS_LE_LO12,
50     VK_LoongArch_TLS_LE64_LO20,
51     VK_LoongArch_TLS_LE64_HI12,
52     VK_LoongArch_TLS_IE_PC_HI20,
53     VK_LoongArch_TLS_IE_PC_LO12,
54     VK_LoongArch_TLS_IE64_PC_LO20,
55     VK_LoongArch_TLS_IE64_PC_HI12,
56     VK_LoongArch_TLS_IE_HI20,
57     VK_LoongArch_TLS_IE_LO12,
58     VK_LoongArch_TLS_IE64_LO20,
59     VK_LoongArch_TLS_IE64_HI12,
60     VK_LoongArch_TLS_LD_PC_HI20,
61     VK_LoongArch_TLS_LD_HI20,
62     VK_LoongArch_TLS_GD_PC_HI20,
63     VK_LoongArch_TLS_GD_HI20,
64     VK_LoongArch_Invalid // Must be the last item.
65   };
66 
67 private:
68   const MCExpr *Expr;
69   const VariantKind Kind;
70 
71   explicit LoongArchMCExpr(const MCExpr *Expr, VariantKind Kind)
72       : Expr(Expr), Kind(Kind) {}
73 
74 public:
75   static const LoongArchMCExpr *create(const MCExpr *Expr, VariantKind Kind,
76                                        MCContext &Ctx);
77 
78   VariantKind getKind() const { return Kind; }
79   const MCExpr *getSubExpr() const { return Expr; }
80 
81   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
82   bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
83                                  const MCFixup *Fixup) const override;
84   void visitUsedExpr(MCStreamer &Streamer) const override;
85   MCFragment *findAssociatedFragment() const override {
86     return getSubExpr()->findAssociatedFragment();
87   }
88 
89   void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
90 
91   static bool classof(const MCExpr *E) {
92     return E->getKind() == MCExpr::Target;
93   }
94 
95   static StringRef getVariantKindName(VariantKind Kind);
96   static VariantKind getVariantKindForName(StringRef name);
97 };
98 
99 } // end namespace llvm
100 
101 #endif
102