1 //===- MipsMCExpr.h - Mips 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 #ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCEXPR_H
10 #define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCEXPR_H
11 
12 #include "llvm/MC/MCAsmLayout.h"
13 #include "llvm/MC/MCExpr.h"
14 #include "llvm/MC/MCValue.h"
15 
16 namespace llvm {
17 
18 class MipsMCExpr : public MCTargetExpr {
19 public:
20   enum MipsExprKind {
21     MEK_None,
22     MEK_CALL_HI16,
23     MEK_CALL_LO16,
24     MEK_DTPREL,
25     MEK_DTPREL_HI,
26     MEK_DTPREL_LO,
27     MEK_GOT,
28     MEK_GOTTPREL,
29     MEK_GOT_CALL,
30     MEK_GOT_DISP,
31     MEK_GOT_HI16,
32     MEK_GOT_LO16,
33     MEK_GOT_OFST,
34     MEK_GOT_PAGE,
35     MEK_GPREL,
36     MEK_HI,
37     MEK_HIGHER,
38     MEK_HIGHEST,
39     MEK_LO,
40     MEK_NEG,
41     MEK_PCREL_HI16,
42     MEK_PCREL_LO16,
43     MEK_TLSGD,
44     MEK_TLSLDM,
45     MEK_TPREL_HI,
46     MEK_TPREL_LO,
47     MEK_CAPTABLE11,
48     MEK_CAPTABLE_HI16,
49     MEK_CAPTABLE_LO16,
50     MEK_CAPTABLE20,
51     MEK_CAPCALL11,
52     MEK_CAPCALL_HI16,
53     MEK_CAPCALL_LO16,
54     MEK_CAPCALL20,
55 
56     MEK_CHERI_CAP,
57     // Like GPREL but the offset from _CHERI_CAPABILITY_TABLE_ to symbol
58     MEK_CAPTABLEREL,
59 
60     MEK_CAPTAB_TLSGD_HI16,
61     MEK_CAPTAB_TLSGD_LO16,
62     MEK_CAPTAB_TLSLDM_HI16,
63     MEK_CAPTAB_TLSLDM_LO16,
64     MEK_CAPTAB_TPREL_HI16,
65     MEK_CAPTAB_TPREL_LO16,
66 
67     MEK_Special,
68   };
69 
70 private:
71   const MipsExprKind Kind;
72   const MCExpr *Expr;
73 
MipsMCExpr(MipsExprKind Kind,const MCExpr * Expr)74   explicit MipsMCExpr(MipsExprKind Kind, const MCExpr *Expr)
75       : Kind(Kind), Expr(Expr) {}
76 
77 public:
78   static const MipsMCExpr *create(MipsExprKind Kind, const MCExpr *Expr,
79                                   MCContext &Ctx);
80   static const MipsMCExpr *createGpOff(MipsExprKind Kind, const MCExpr *Expr,
81                                        MCContext &Ctx);
82  static const MipsMCExpr *createCaptableOff(MipsExprKind Kind,
83                                             const MCExpr *Expr, MCContext &Ctx);
84 
85   /// Get the kind of this expression.
getKind()86   MipsExprKind getKind() const { return Kind; }
87 
88   /// Get the child of this expression.
getSubExpr()89   const MCExpr *getSubExpr() const { return Expr; }
90 
91   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
92   bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
93                                  const MCFixup *Fixup) const override;
94   void visitUsedExpr(MCStreamer &Streamer) const override;
95 
findAssociatedFragment()96   MCFragment *findAssociatedFragment() const override {
97     return getSubExpr()->findAssociatedFragment();
98   }
99 
100   void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
101 
classof(const MCExpr * E)102   static bool classof(const MCExpr *E) {
103     return E->getKind() == MCExpr::Target;
104   }
105 
isGpOff(MipsExprKind & Kind)106   bool isGpOff(MipsExprKind &Kind) const { return isOffImpl(Kind, MEK_GPREL); }
isGpOff()107   bool isGpOff() const {
108     MipsExprKind Kind;
109     return isGpOff(Kind);
110   }
111 
isCaptableOff()112   bool isCaptableOff() const {
113     MipsExprKind Kind;
114     return isOffImpl(Kind, MEK_CAPTABLEREL);
115   }
116 private:
117   bool isOffImpl(MipsExprKind &Kind, MipsExprKind Expected) const;
118 };
119 
120 } // end namespace llvm
121 
122 #endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCEXPR_H
123