Revert " [LoongArch][ISel] Check the number of sign bits in `PatGprGpr_32` (#107432)"
[llvm-project.git] / llvm / lib / Target / NVPTX / NVPTXMCExpr.h
blobd95b61c34acfea6a23e7cd060436d46b8ea97dfd
1 //===-- NVPTXMCExpr.h - NVPTX 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 //===----------------------------------------------------------------------===//
9 // Modeled after ARMMCExpr
11 #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXMCEXPR_H
12 #define LLVM_LIB_TARGET_NVPTX_NVPTXMCEXPR_H
14 #include "llvm/ADT/APFloat.h"
15 #include "llvm/MC/MCExpr.h"
16 #include <utility>
18 namespace llvm {
20 class NVPTXFloatMCExpr : public MCTargetExpr {
21 public:
22 enum VariantKind {
23 VK_NVPTX_None,
24 VK_NVPTX_BFLOAT_PREC_FLOAT, // FP constant in bfloat-precision
25 VK_NVPTX_HALF_PREC_FLOAT, // FP constant in half-precision
26 VK_NVPTX_SINGLE_PREC_FLOAT, // FP constant in single-precision
27 VK_NVPTX_DOUBLE_PREC_FLOAT // FP constant in double-precision
30 private:
31 const VariantKind Kind;
32 const APFloat Flt;
34 explicit NVPTXFloatMCExpr(VariantKind Kind, APFloat Flt)
35 : Kind(Kind), Flt(std::move(Flt)) {}
37 public:
38 /// @name Construction
39 /// @{
41 static const NVPTXFloatMCExpr *create(VariantKind Kind, const APFloat &Flt,
42 MCContext &Ctx);
44 static const NVPTXFloatMCExpr *createConstantBFPHalf(const APFloat &Flt,
45 MCContext &Ctx) {
46 return create(VK_NVPTX_BFLOAT_PREC_FLOAT, Flt, Ctx);
49 static const NVPTXFloatMCExpr *createConstantFPHalf(const APFloat &Flt,
50 MCContext &Ctx) {
51 return create(VK_NVPTX_HALF_PREC_FLOAT, Flt, Ctx);
54 static const NVPTXFloatMCExpr *createConstantFPSingle(const APFloat &Flt,
55 MCContext &Ctx) {
56 return create(VK_NVPTX_SINGLE_PREC_FLOAT, Flt, Ctx);
59 static const NVPTXFloatMCExpr *createConstantFPDouble(const APFloat &Flt,
60 MCContext &Ctx) {
61 return create(VK_NVPTX_DOUBLE_PREC_FLOAT, Flt, Ctx);
64 /// @}
65 /// @name Accessors
66 /// @{
68 /// getOpcode - Get the kind of this expression.
69 VariantKind getKind() const { return Kind; }
71 /// getSubExpr - Get the child of this expression.
72 APFloat getAPFloat() const { return Flt; }
74 /// @}
76 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
77 bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
78 const MCFixup *Fixup) const override {
79 return false;
81 void visitUsedExpr(MCStreamer &Streamer) const override {};
82 MCFragment *findAssociatedFragment() const override { return nullptr; }
84 // There are no TLS NVPTXMCExprs at the moment.
85 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
87 static bool classof(const MCExpr *E) {
88 return E->getKind() == MCExpr::Target;
92 /// A wrapper for MCSymbolRefExpr that tells the assembly printer that the
93 /// symbol should be enclosed by generic().
94 class NVPTXGenericMCSymbolRefExpr : public MCTargetExpr {
95 private:
96 const MCSymbolRefExpr *SymExpr;
98 explicit NVPTXGenericMCSymbolRefExpr(const MCSymbolRefExpr *_SymExpr)
99 : SymExpr(_SymExpr) {}
101 public:
102 /// @name Construction
103 /// @{
105 static const NVPTXGenericMCSymbolRefExpr
106 *create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx);
108 /// @}
109 /// @name Accessors
110 /// @{
112 /// getOpcode - Get the kind of this expression.
113 const MCSymbolRefExpr *getSymbolExpr() const { return SymExpr; }
115 /// @}
117 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
118 bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
119 const MCFixup *Fixup) const override {
120 return false;
122 void visitUsedExpr(MCStreamer &Streamer) const override {};
123 MCFragment *findAssociatedFragment() const override { return nullptr; }
125 // There are no TLS NVPTXMCExprs at the moment.
126 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
128 static bool classof(const MCExpr *E) {
129 return E->getKind() == MCExpr::Target;
132 } // end namespace llvm
134 #endif