LLVM 19.0.0git
NVPTXMCExpr.cpp
Go to the documentation of this file.
1//===-- NVPTXMCExpr.cpp - NVPTX specific MC expression classes ------------===//
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#include "NVPTXMCExpr.h"
11#include "llvm/MC/MCAssembler.h"
12#include "llvm/MC/MCContext.h"
13#include "llvm/Support/Format.h"
14using namespace llvm;
15
16#define DEBUG_TYPE "nvptx-mcexpr"
17
18const NVPTXFloatMCExpr *
20 return new (Ctx) NVPTXFloatMCExpr(Kind, Flt);
21}
22
24 bool Ignored;
25 unsigned NumHex;
26 APFloat APF = getAPFloat();
27
28 switch (Kind) {
29 default: llvm_unreachable("Invalid kind!");
31 // ptxas does not have a way to specify half-precision floats.
32 // Instead we have to print and load fp16 constants as .b16
33 OS << "0x";
34 NumHex = 4;
36 break;
38 OS << "0x";
39 NumHex = 4;
41 break;
43 OS << "0f";
44 NumHex = 8;
46 break;
48 OS << "0d";
49 NumHex = 16;
51 break;
52 }
53
54 APInt API = APF.bitcastToAPInt();
55 OS << format_hex_no_prefix(API.getZExtValue(), NumHex, /*Upper=*/true);
56}
57
60 MCContext &Ctx) {
61 return new (Ctx) NVPTXGenericMCSymbolRefExpr(SymExpr);
62}
63
65 const MCAsmInfo *MAI) const {
66 OS << "generic(";
67 SymExpr->print(OS, MAI);
68 OS << ")";
69}
raw_pwrite_stream & OS
This file contains some functions that are useful when dealing with strings.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition: APFloat.cpp:5196
APInt bitcastToAPInt() const
Definition: APFloat.h:1210
Class for arbitrary precision integers.
Definition: APInt.h:76
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1491
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
Context object for machine code objects.
Definition: MCContext.h:76
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:41
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
APFloat getAPFloat() const
getSubExpr - Get the child of this expression.
Definition: NVPTXMCExpr.h:72
static const NVPTXFloatMCExpr * create(VariantKind Kind, const APFloat &Flt, MCContext &Ctx)
Definition: NVPTXMCExpr.cpp:19
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: NVPTXMCExpr.cpp:23
A wrapper for MCSymbolRefExpr that tells the assembly printer that the symbol should be enclosed by g...
Definition: NVPTXMCExpr.h:95
static const NVPTXGenericMCSymbolRefExpr * create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx)
Definition: NVPTXMCExpr.cpp:59
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: NVPTXMCExpr.cpp:64
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
Definition: Format.h:200
static const fltSemantics & IEEEsingle() LLVM_READNONE
Definition: APFloat.cpp:249
static constexpr roundingMode rmNearestTiesToEven
Definition: APFloat.h:230
static const fltSemantics & IEEEdouble() LLVM_READNONE
Definition: APFloat.cpp:250
static const fltSemantics & IEEEhalf() LLVM_READNONE
Definition: APFloat.cpp:247
static const fltSemantics & BFloat() LLVM_READNONE
Definition: APFloat.cpp:248