1 //===-- RISCVMCExpr.h - RISC-V specific MC expression classes----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file describes RISC-V specific MCExprs, used for modifiers like
10 // "%hi" or "%lo" etc.,
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVMCEXPR_H
15 #define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVMCEXPR_H
17 #include "llvm/MC/MCExpr.h"
23 class RISCVMCExpr
: public MCTargetExpr
{
41 VK_RISCV_TLSDESC_LOAD_LO
,
42 VK_RISCV_TLSDESC_ADD_LO
,
43 VK_RISCV_TLSDESC_CALL
,
44 VK_RISCV_Invalid
// Must be the last item
49 const VariantKind Kind
;
51 int64_t evaluateAsInt64(int64_t Value
) const;
53 explicit RISCVMCExpr(const MCExpr
*Expr
, VariantKind Kind
)
54 : Expr(Expr
), Kind(Kind
) {}
57 static const RISCVMCExpr
*create(const MCExpr
*Expr
, VariantKind Kind
,
60 VariantKind
getKind() const { return Kind
; }
62 const MCExpr
*getSubExpr() const { return Expr
; }
64 /// Get the corresponding PC-relative HI fixup that a VK_RISCV_PCREL_LO
65 /// points to, and optionally the fragment containing it.
67 /// \returns nullptr if this isn't a VK_RISCV_PCREL_LO pointing to a
68 /// known PC-relative HI fixup.
69 const MCFixup
*getPCRelHiFixup(const MCFragment
**DFOut
) const;
71 void printImpl(raw_ostream
&OS
, const MCAsmInfo
*MAI
) const override
;
72 bool evaluateAsRelocatableImpl(MCValue
&Res
, const MCAsmLayout
*Layout
,
73 const MCFixup
*Fixup
) const override
;
74 void visitUsedExpr(MCStreamer
&Streamer
) const override
;
75 MCFragment
*findAssociatedFragment() const override
{
76 return getSubExpr()->findAssociatedFragment();
79 void fixELFSymbolsInTLSFixups(MCAssembler
&Asm
) const override
;
81 bool evaluateAsConstant(int64_t &Res
) const;
83 static bool classof(const MCExpr
*E
) {
84 return E
->getKind() == MCExpr::Target
;
87 static VariantKind
getVariantKindForName(StringRef name
);
88 static StringRef
getVariantKindName(VariantKind Kind
);
91 } // end namespace llvm.