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_TLS_DESC_PC_HI20, 66 VK_LoongArch_TLS_DESC_PC_LO12, 67 VK_LoongArch_TLS_DESC64_PC_LO20, 68 VK_LoongArch_TLS_DESC64_PC_HI12, 69 VK_LoongArch_TLS_DESC_HI20, 70 VK_LoongArch_TLS_DESC_LO12, 71 VK_LoongArch_TLS_DESC64_LO20, 72 VK_LoongArch_TLS_DESC64_HI12, 73 VK_LoongArch_TLS_DESC_LD, 74 VK_LoongArch_TLS_DESC_CALL, 75 VK_LoongArch_TLS_LE_HI20_R, 76 VK_LoongArch_TLS_LE_ADD_R, 77 VK_LoongArch_TLS_LE_LO12_R, 78 VK_LoongArch_PCREL20_S2, 79 VK_LoongArch_TLS_LD_PCREL20_S2, 80 VK_LoongArch_TLS_GD_PCREL20_S2, 81 VK_LoongArch_TLS_DESC_PCREL20_S2, 82 VK_LoongArch_Invalid // Must be the last item. 83 }; 84 85 private: 86 const MCExpr *Expr; 87 const VariantKind Kind; 88 const bool RelaxHint; 89 LoongArchMCExpr(const MCExpr * Expr,VariantKind Kind,bool Hint)90 explicit LoongArchMCExpr(const MCExpr *Expr, VariantKind Kind, bool Hint) 91 : Expr(Expr), Kind(Kind), RelaxHint(Hint) {} 92 93 public: 94 static const LoongArchMCExpr *create(const MCExpr *Expr, VariantKind Kind, 95 MCContext &Ctx, bool Hint = false); 96 getKind()97 VariantKind getKind() const { return Kind; } getSubExpr()98 const MCExpr *getSubExpr() const { return Expr; } getRelaxHint()99 bool getRelaxHint() const { return RelaxHint; } 100 101 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; 102 bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, 103 const MCFixup *Fixup) const override; 104 void visitUsedExpr(MCStreamer &Streamer) const override; findAssociatedFragment()105 MCFragment *findAssociatedFragment() const override { 106 return getSubExpr()->findAssociatedFragment(); 107 } 108 109 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override; 110 classof(const MCExpr * E)111 static bool classof(const MCExpr *E) { 112 return E->getKind() == MCExpr::Target; 113 } 114 115 static StringRef getVariantKindName(VariantKind Kind); 116 static VariantKind getVariantKindForName(StringRef name); 117 }; 118 119 } // end namespace llvm 120 121 #endif 122