1 //===-- NVPTXMCExpr.cpp - NVPTX specific MC expression classes ------------===//
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 #include "NVPTXMCExpr.h"
10 #include "llvm/ADT/StringExtras.h"
11 #include "llvm/MC/MCAssembler.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/Support/Format.h"
16 #define DEBUG_TYPE "nvptx-mcexpr"
18 const NVPTXFloatMCExpr
*
19 NVPTXFloatMCExpr::create(VariantKind Kind
, const APFloat
&Flt
, MCContext
&Ctx
) {
20 return new (Ctx
) NVPTXFloatMCExpr(Kind
, Flt
);
23 void NVPTXFloatMCExpr::printImpl(raw_ostream
&OS
, const MCAsmInfo
*MAI
) const {
26 APFloat APF
= getAPFloat();
29 default: llvm_unreachable("Invalid kind!");
30 case VK_NVPTX_HALF_PREC_FLOAT
:
31 // ptxas does not have a way to specify half-precision floats.
32 // Instead we have to print and load fp16 constants as .b16
35 APF
.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven
, &Ignored
);
37 case VK_NVPTX_SINGLE_PREC_FLOAT
:
40 APF
.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven
, &Ignored
);
42 case VK_NVPTX_DOUBLE_PREC_FLOAT
:
45 APF
.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven
, &Ignored
);
49 APInt API
= APF
.bitcastToAPInt();
50 OS
<< format_hex_no_prefix(API
.getZExtValue(), NumHex
, /*Upper=*/true);
53 const NVPTXGenericMCSymbolRefExpr
*
54 NVPTXGenericMCSymbolRefExpr::create(const MCSymbolRefExpr
*SymExpr
,
56 return new (Ctx
) NVPTXGenericMCSymbolRefExpr(SymExpr
);
59 void NVPTXGenericMCSymbolRefExpr::printImpl(raw_ostream
&OS
,
60 const MCAsmInfo
*MAI
) const {
62 SymExpr
->print(OS
, MAI
);