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_HALF_PREC_FLOAT
, // FP constant in half-precision
25 VK_NVPTX_SINGLE_PREC_FLOAT
, // FP constant in single-precision
26 VK_NVPTX_DOUBLE_PREC_FLOAT
// FP constant in double-precision
30 const VariantKind Kind
;
33 explicit NVPTXFloatMCExpr(VariantKind Kind
, APFloat Flt
)
34 : Kind(Kind
), Flt(std::move(Flt
)) {}
37 /// @name Construction
40 static const NVPTXFloatMCExpr
*create(VariantKind Kind
, const APFloat
&Flt
,
43 static const NVPTXFloatMCExpr
*createConstantFPHalf(const APFloat
&Flt
,
45 return create(VK_NVPTX_HALF_PREC_FLOAT
, Flt
, Ctx
);
48 static const NVPTXFloatMCExpr
*createConstantFPSingle(const APFloat
&Flt
,
50 return create(VK_NVPTX_SINGLE_PREC_FLOAT
, Flt
, Ctx
);
53 static const NVPTXFloatMCExpr
*createConstantFPDouble(const APFloat
&Flt
,
55 return create(VK_NVPTX_DOUBLE_PREC_FLOAT
, Flt
, Ctx
);
62 /// getOpcode - Get the kind of this expression.
63 VariantKind
getKind() const { return Kind
; }
65 /// getSubExpr - Get the child of this expression.
66 APFloat
getAPFloat() const { return Flt
; }
70 void printImpl(raw_ostream
&OS
, const MCAsmInfo
*MAI
) const override
;
71 bool evaluateAsRelocatableImpl(MCValue
&Res
,
72 const MCAsmLayout
*Layout
,
73 const MCFixup
*Fixup
) const override
{
76 void visitUsedExpr(MCStreamer
&Streamer
) const override
{};
77 MCFragment
*findAssociatedFragment() const override
{ return nullptr; }
79 // There are no TLS NVPTXMCExprs at the moment.
80 void fixELFSymbolsInTLSFixups(MCAssembler
&Asm
) const override
{}
82 static bool classof(const MCExpr
*E
) {
83 return E
->getKind() == MCExpr::Target
;
87 /// A wrapper for MCSymbolRefExpr that tells the assembly printer that the
88 /// symbol should be enclosed by generic().
89 class NVPTXGenericMCSymbolRefExpr
: public MCTargetExpr
{
91 const MCSymbolRefExpr
*SymExpr
;
93 explicit NVPTXGenericMCSymbolRefExpr(const MCSymbolRefExpr
*_SymExpr
)
94 : SymExpr(_SymExpr
) {}
97 /// @name Construction
100 static const NVPTXGenericMCSymbolRefExpr
101 *create(const MCSymbolRefExpr
*SymExpr
, MCContext
&Ctx
);
107 /// getOpcode - Get the kind of this expression.
108 const MCSymbolRefExpr
*getSymbolExpr() const { return SymExpr
; }
112 void printImpl(raw_ostream
&OS
, const MCAsmInfo
*MAI
) const override
;
113 bool evaluateAsRelocatableImpl(MCValue
&Res
,
114 const MCAsmLayout
*Layout
,
115 const MCFixup
*Fixup
) const override
{
118 void visitUsedExpr(MCStreamer
&Streamer
) const override
{};
119 MCFragment
*findAssociatedFragment() const override
{ return nullptr; }
121 // There are no TLS NVPTXMCExprs at the moment.
122 void fixELFSymbolsInTLSFixups(MCAssembler
&Asm
) const override
{}
124 static bool classof(const MCExpr
*E
) {
125 return E
->getKind() == MCExpr::Target
;
128 } // end namespace llvm