LLVM  9.0.0svn
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 class MCOperand;
23 class RISCVMCExpr : public MCTargetExpr {
24 public:
25  enum VariantKind {
34  };
35 
36 private:
37  const MCExpr *Expr;
38  const VariantKind Kind;
39 
40  int64_t evaluateAsInt64(int64_t Value) const;
41 
42  bool evaluatePCRelLo(MCValue &Res, const MCAsmLayout *Layout,
43  const MCFixup *Fixup) const;
44 
45  explicit RISCVMCExpr(const MCExpr *Expr, VariantKind Kind)
46  : Expr(Expr), Kind(Kind) {}
47 
48 public:
49  static const RISCVMCExpr *create(const MCExpr *Expr, VariantKind Kind,
50  MCContext &Ctx);
51 
52  VariantKind getKind() const { return Kind; }
53 
54  const MCExpr *getSubExpr() const { return Expr; }
55 
56  /// Get the corresponding PC-relative HI fixup that a VK_RISCV_PCREL_LO
57  /// points to.
58  ///
59  /// \returns nullptr if this isn't a VK_RISCV_PCREL_LO pointing to a
60  /// known PC-relative HI fixup.
61  const MCFixup *getPCRelHiFixup() const;
62 
63  void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
64  bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
65  const MCFixup *Fixup) const override;
66  void visitUsedExpr(MCStreamer &Streamer) const override;
67  MCFragment *findAssociatedFragment() const override {
69  }
70 
71  // There are no TLS RISCVMCExprs at the moment.
72  void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
73 
74  bool evaluateAsConstant(int64_t &Res) const;
75 
76  static bool classof(const MCExpr *E) {
77  return E->getKind() == MCExpr::Target;
78  }
79 
80  static bool classof(const RISCVMCExpr *) { return true; }
81 
84 };
85 
86 } // end namespace llvm.
87 
88 #endif
static bool classof(const MCExpr *E)
Definition: RISCVMCExpr.h:76
bool evaluateAsConstant(int64_t &Res) const
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This represents an "assembler immediate".
Definition: MCValue.h:39
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: RISCVMCExpr.cpp:33
VariantKind getKind() const
Definition: RISCVMCExpr.h:52
static StringRef getVariantKindName(VariantKind Kind)
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:73
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
This is an extension point for target-specific MCExpr subclasses to implement.
Definition: MCExpr.h:580
Context object for machine code objects.
Definition: MCContext.h:62
const MCFixup * getPCRelHiFixup() const
Get the corresponding PC-relative HI fixup that a VK_RISCV_PCREL_LO points to.
Definition: RISCVMCExpr.cpp:43
const MCExpr * getSubExpr() const
Definition: RISCVMCExpr.h:54
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:55
Streaming machine code generation interface.
Definition: MCStreamer.h:188
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
PowerPC TLS Dynamic Call Fixup
ExprKind getKind() const
Definition: MCExpr.h:72
static bool classof(const RISCVMCExpr *)
Definition: RISCVMCExpr.h:80
MCFragment * findAssociatedFragment() const
Find the "associated section" for this expression, which is currently defined as the absolute section...
Definition: MCExpr.cpp:866
MCFragment * findAssociatedFragment() const override
Definition: RISCVMCExpr.h:67
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
static VariantKind getVariantKindForName(StringRef name)
LLVM Value Representation.
Definition: Value.h:72
static const char * name
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
Definition: RISCVMCExpr.h:72
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Target specific expression.
Definition: MCExpr.h:42
void visitUsedExpr(MCStreamer &Streamer) const override
static const RISCVMCExpr * create(const MCExpr *Expr, VariantKind Kind, MCContext &Ctx)
Definition: RISCVMCExpr.cpp:28