[Codegen] Alter the default promotion for saturating adds and subs
[llvm-complete.git] / lib / Target / RISCV / MCTargetDesc / RISCVMCExpr.h
blob921df376f3dfc83d265ae6ad4df13f7224dd09fd
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.,
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"
19 namespace llvm {
21 class StringRef;
22 class MCOperand;
23 class RISCVMCExpr : public MCTargetExpr {
24 public:
25 enum VariantKind {
26 VK_RISCV_None,
27 VK_RISCV_LO,
28 VK_RISCV_HI,
29 VK_RISCV_PCREL_LO,
30 VK_RISCV_PCREL_HI,
31 VK_RISCV_GOT_HI,
32 VK_RISCV_TPREL_LO,
33 VK_RISCV_TPREL_HI,
34 VK_RISCV_TPREL_ADD,
35 VK_RISCV_TLS_GOT_HI,
36 VK_RISCV_TLS_GD_HI,
37 VK_RISCV_CALL,
38 VK_RISCV_CALL_PLT,
39 VK_RISCV_32_PCREL,
40 VK_RISCV_Invalid
43 private:
44 const MCExpr *Expr;
45 const VariantKind Kind;
47 int64_t evaluateAsInt64(int64_t Value) const;
49 bool evaluatePCRelLo(MCValue &Res, const MCAsmLayout *Layout,
50 const MCFixup *Fixup) const;
52 explicit RISCVMCExpr(const MCExpr *Expr, VariantKind Kind)
53 : Expr(Expr), Kind(Kind) {}
55 public:
56 static const RISCVMCExpr *create(const MCExpr *Expr, VariantKind Kind,
57 MCContext &Ctx);
59 VariantKind getKind() const { return Kind; }
61 const MCExpr *getSubExpr() const { return Expr; }
63 /// Get the corresponding PC-relative HI fixup that a VK_RISCV_PCREL_LO
64 /// points to.
65 ///
66 /// \returns nullptr if this isn't a VK_RISCV_PCREL_LO pointing to a
67 /// known PC-relative HI fixup.
68 const MCFixup *getPCRelHiFixup() const;
70 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
71 bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
72 const MCFixup *Fixup) const override;
73 void visitUsedExpr(MCStreamer &Streamer) const override;
74 MCFragment *findAssociatedFragment() const override {
75 return getSubExpr()->findAssociatedFragment();
78 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
80 bool evaluateAsConstant(int64_t &Res) const;
82 static bool classof(const MCExpr *E) {
83 return E->getKind() == MCExpr::Target;
86 static bool classof(const RISCVMCExpr *) { return true; }
88 static VariantKind getVariantKindForName(StringRef name);
89 static StringRef getVariantKindName(VariantKind Kind);
92 } // end namespace llvm.
94 #endif