LLVM  14.0.0git
RISCVMCExpr.h
Go to the documentation of this file.
1 //===-- RISCVMCExpr.h - RISCV 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 RISCV-specific MCExprs, used for modifiers like
10 // "%hi" or "%lo" etc.,
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVMCEXPR_H
15 #define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVMCEXPR_H
16 
17 #include "llvm/MC/MCExpr.h"
18 
19 namespace llvm {
20 
21 class StringRef;
22 
23 class RISCVMCExpr : public MCTargetExpr {
24 public:
25  enum VariantKind {
40  VK_RISCV_Invalid // Must be the last item
41  };
42 
43 private:
44  const MCExpr *Expr;
45  const VariantKind Kind;
46 
47  int64_t evaluateAsInt64(int64_t Value) const;
48 
49  explicit RISCVMCExpr(const MCExpr *Expr, VariantKind Kind)
50  : Expr(Expr), Kind(Kind) {}
51 
52 public:
53  static const RISCVMCExpr *create(const MCExpr *Expr, VariantKind Kind,
54  MCContext &Ctx);
55 
56  VariantKind getKind() const { return Kind; }
57 
58  const MCExpr *getSubExpr() const { return Expr; }
59 
60  /// Get the corresponding PC-relative HI fixup that a VK_RISCV_PCREL_LO
61  /// points to, and optionally the fragment containing it.
62  ///
63  /// \returns nullptr if this isn't a VK_RISCV_PCREL_LO pointing to a
64  /// known PC-relative HI fixup.
65  const MCFixup *getPCRelHiFixup(const MCFragment **DFOut) const;
66 
67  void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
68  bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
69  const MCFixup *Fixup) const override;
70  void visitUsedExpr(MCStreamer &Streamer) const override;
71  MCFragment *findAssociatedFragment() const override {
73  }
74 
75  void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
76 
77  bool evaluateAsConstant(int64_t &Res) const;
78 
79  static bool classof(const MCExpr *E) {
80  return E->getKind() == MCExpr::Target;
81  }
82 
83  static bool classof(const RISCVMCExpr *) { return true; }
84 
87 };
88 
89 } // end namespace llvm.
90 
91 #endif
llvm::RISCVMCExpr::VK_RISCV_Invalid
@ VK_RISCV_Invalid
Definition: RISCVMCExpr.h:40
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::RISCVMCExpr::printImpl
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: RISCVMCExpr.cpp:35
llvm::RISCVMCExpr::VK_RISCV_TLS_GD_HI
@ VK_RISCV_TLS_GD_HI
Definition: RISCVMCExpr.h:36
llvm::RISCVMCExpr::VK_RISCV_TPREL_ADD
@ VK_RISCV_TPREL_ADD
Definition: RISCVMCExpr.h:34
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::RISCVMCExpr::evaluateAsConstant
bool evaluateAsConstant(int64_t &Res) const
Definition: RISCVMCExpr.cpp:203
llvm::RISCVMCExpr::classof
static bool classof(const MCExpr *E)
Definition: RISCVMCExpr.h:79
llvm::RISCVMCExpr::VK_RISCV_TPREL_LO
@ VK_RISCV_TPREL_LO
Definition: RISCVMCExpr.h:32
llvm::RISCVMCExpr::getVariantKindForName
static VariantKind getVariantKindForName(StringRef name)
Definition: RISCVMCExpr.cpp:111
llvm::RISCVMCExpr::VK_RISCV_HI
@ VK_RISCV_HI
Definition: RISCVMCExpr.h:28
llvm::RISCVMCExpr::VK_RISCV_TPREL_HI
@ VK_RISCV_TPREL_HI
Definition: RISCVMCExpr.h:33
llvm::RISCVMCExpr::classof
static bool classof(const RISCVMCExpr *)
Definition: RISCVMCExpr.h:83
llvm::RISCVMCExpr::VK_RISCV_TLS_GOT_HI
@ VK_RISCV_TLS_GOT_HI
Definition: RISCVMCExpr.h:35
llvm::RISCVMCExpr::VariantKind
VariantKind
Definition: RISCVMCExpr.h:25
llvm::MCFragment
Definition: MCFragment.h:31
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
llvm::RISCVMCExpr::VK_RISCV_LO
@ VK_RISCV_LO
Definition: RISCVMCExpr.h:27
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::MCExpr::Target
@ Target
Target specific expression.
Definition: MCExpr.h:42
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::RISCVMCExpr::findAssociatedFragment
MCFragment * findAssociatedFragment() const override
Definition: RISCVMCExpr.h:71
llvm::RISCVMCExpr::getSubExpr
const MCExpr * getSubExpr() const
Definition: RISCVMCExpr.h:58
llvm::RISCVMCExpr::VK_RISCV_None
@ VK_RISCV_None
Definition: RISCVMCExpr.h:26
llvm::RISCVMCExpr::create
static const RISCVMCExpr * create(const MCExpr *Expr, VariantKind Kind, MCContext &Ctx)
Definition: RISCVMCExpr.cpp:30
llvm::MCAssembler
Definition: MCAssembler.h:60
llvm::RISCVMCExpr::VK_RISCV_PCREL_HI
@ VK_RISCV_PCREL_HI
Definition: RISCVMCExpr.h:30
llvm::MCExpr::MCExpr
MCExpr(ExprKind Kind, SMLoc Loc, unsigned SubclassData=0)
Definition: MCExpr.h:61
llvm::RISCVMCExpr::evaluateAsRelocatableImpl
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
Definition: RISCVMCExpr.cpp:92
llvm::RISCVMCExpr::visitUsedExpr
void visitUsedExpr(MCStreamer &Streamer) const override
Definition: RISCVMCExpr.cpp:107
llvm::RISCVMCExpr::VK_RISCV_PCREL_LO
@ VK_RISCV_PCREL_LO
Definition: RISCVMCExpr.h:29
llvm::RISCVMCExpr::VK_RISCV_GOT_HI
@ VK_RISCV_GOT_HI
Definition: RISCVMCExpr.h:31
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::RISCVMCExpr::fixELFSymbolsInTLSFixups
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
Definition: RISCVMCExpr.cpp:190
llvm::RISCVMCExpr::getKind
VariantKind getKind() const
Definition: RISCVMCExpr.h:56
name
static const char * name
Definition: SVEIntrinsicOpts.cpp:78
llvm::RISCVMCExpr::VK_RISCV_32_PCREL
@ VK_RISCV_32_PCREL
Definition: RISCVMCExpr.h:39
llvm::MCAsmLayout
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
llvm::RISCVMCExpr::getVariantKindName
static StringRef getVariantKindName(VariantKind Kind)
Definition: RISCVMCExpr.cpp:126
llvm::RISCVMCExpr::VK_RISCV_CALL
@ VK_RISCV_CALL
Definition: RISCVMCExpr.h:37
llvm::MCExpr::findAssociatedFragment
MCFragment * findAssociatedFragment() const
Find the "associated section" for this expression, which is currently defined as the absolute section...
Definition: MCExpr.cpp:985
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::RISCVMCExpr::getPCRelHiFixup
const MCFixup * getPCRelHiFixup(const MCFragment **DFOut) const
Get the corresponding PC-relative HI fixup that a VK_RISCV_PCREL_LO points to, and optionally the fra...
Definition: RISCVMCExpr.cpp:49
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
llvm::RISCVMCExpr::VK_RISCV_CALL_PLT
@ VK_RISCV_CALL_PLT
Definition: RISCVMCExpr.h:38
llvm::MCTargetExpr
This is an extension point for target-specific MCExpr subclasses to implement.
Definition: MCExpr.h:644
MCExpr.h
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::RISCVMCExpr
Definition: RISCVMCExpr.h:23