xref: /freebsd/contrib/llvm-project/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.h (revision 1db9f3b21e39176dd5b67cf8ac378633b172463e)
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_CALL36,
65     VK_LoongArch_Invalid // Must be the last item.
66   };
67 
68 private:
69   const MCExpr *Expr;
70   const VariantKind Kind;
71   const bool RelaxHint;
72 
73   explicit LoongArchMCExpr(const MCExpr *Expr, VariantKind Kind, bool Hint)
74       : Expr(Expr), Kind(Kind), RelaxHint(Hint) {}
75 
76 public:
77   static const LoongArchMCExpr *create(const MCExpr *Expr, VariantKind Kind,
78                                        MCContext &Ctx, bool Hint = false);
79 
80   VariantKind getKind() const { return Kind; }
81   const MCExpr *getSubExpr() const { return Expr; }
82   bool getRelaxHint() const { return RelaxHint; }
83 
84   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
85   bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
86                                  const MCFixup *Fixup) const override;
87   void visitUsedExpr(MCStreamer &Streamer) const override;
88   MCFragment *findAssociatedFragment() const override {
89     return getSubExpr()->findAssociatedFragment();
90   }
91 
92   void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
93 
94   static bool classof(const MCExpr *E) {
95     return E->getKind() == MCExpr::Target;
96   }
97 
98   static StringRef getVariantKindName(VariantKind Kind);
99   static VariantKind getVariantKindForName(StringRef name);
100 };
101 
102 } // end namespace llvm
103 
104 #endif
105