1 //===-- NVPTXMCExpr.h - NVPTX 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 // 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"
20 class NVPTXFloatMCExpr
: public MCTargetExpr
{
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
31 const VariantKind Kind
;
34 explicit NVPTXFloatMCExpr(VariantKind Kind
, APFloat Flt
)
35 : Kind(Kind
), Flt(std::move(Flt
)) {}
38 /// @name Construction
41 static const NVPTXFloatMCExpr
*create(VariantKind Kind
, const APFloat
&Flt
,
44 static const NVPTXFloatMCExpr
*createConstantBFPHalf(const APFloat
&Flt
,
46 return create(VK_NVPTX_BFLOAT_PREC_FLOAT
, Flt
, Ctx
);
49 static const NVPTXFloatMCExpr
*createConstantFPHalf(const APFloat
&Flt
,
51 return create(VK_NVPTX_HALF_PREC_FLOAT
, Flt
, Ctx
);
54 static const NVPTXFloatMCExpr
*createConstantFPSingle(const APFloat
&Flt
,
56 return create(VK_NVPTX_SINGLE_PREC_FLOAT
, Flt
, Ctx
);
59 static const NVPTXFloatMCExpr
*createConstantFPDouble(const APFloat
&Flt
,
61 return create(VK_NVPTX_DOUBLE_PREC_FLOAT
, Flt
, Ctx
);
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
; }
76 void printImpl(raw_ostream
&OS
, const MCAsmInfo
*MAI
) const override
;
77 bool evaluateAsRelocatableImpl(MCValue
&Res
,
78 const MCAsmLayout
*Layout
,
79 const MCFixup
*Fixup
) const override
{
82 void visitUsedExpr(MCStreamer
&Streamer
) const override
{};
83 MCFragment
*findAssociatedFragment() const override
{ return nullptr; }
85 // There are no TLS NVPTXMCExprs at the moment.
86 void fixELFSymbolsInTLSFixups(MCAssembler
&Asm
) const override
{}
88 static bool classof(const MCExpr
*E
) {
89 return E
->getKind() == MCExpr::Target
;
93 /// A wrapper for MCSymbolRefExpr that tells the assembly printer that the
94 /// symbol should be enclosed by generic().
95 class NVPTXGenericMCSymbolRefExpr
: public MCTargetExpr
{
97 const MCSymbolRefExpr
*SymExpr
;
99 explicit NVPTXGenericMCSymbolRefExpr(const MCSymbolRefExpr
*_SymExpr
)
100 : SymExpr(_SymExpr
) {}
103 /// @name Construction
106 static const NVPTXGenericMCSymbolRefExpr
107 *create(const MCSymbolRefExpr
*SymExpr
, MCContext
&Ctx
);
113 /// getOpcode - Get the kind of this expression.
114 const MCSymbolRefExpr
*getSymbolExpr() const { return SymExpr
; }
118 void printImpl(raw_ostream
&OS
, const MCAsmInfo
*MAI
) const override
;
119 bool evaluateAsRelocatableImpl(MCValue
&Res
,
120 const MCAsmLayout
*Layout
,
121 const MCFixup
*Fixup
) const override
{
124 void visitUsedExpr(MCStreamer
&Streamer
) const override
{};
125 MCFragment
*findAssociatedFragment() const override
{ return nullptr; }
127 // There are no TLS NVPTXMCExprs at the moment.
128 void fixELFSymbolsInTLSFixups(MCAssembler
&Asm
) const override
{}
130 static bool classof(const MCExpr
*E
) {
131 return E
->getKind() == MCExpr::Target
;
134 } // end namespace llvm