LLVM  8.0.1
NVPTXMCExpr.cpp
Go to the documentation of this file.
1 //===-- NVPTXMCExpr.cpp - NVPTX specific MC expression classes ------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "NVPTXMCExpr.h"
11 #include "llvm/ADT/StringExtras.h"
12 #include "llvm/MC/MCAssembler.h"
13 #include "llvm/MC/MCContext.h"
14 #include "llvm/Support/Format.h"
15 using namespace llvm;
16 
17 #define DEBUG_TYPE "nvptx-mcexpr"
18 
19 const NVPTXFloatMCExpr *
21  return new (Ctx) NVPTXFloatMCExpr(Kind, Flt);
22 }
23 
24 void NVPTXFloatMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
25  bool Ignored;
26  unsigned NumHex;
27  APFloat APF = getAPFloat();
28 
29  switch (Kind) {
30  default: llvm_unreachable("Invalid kind!");
32  // ptxas does not have a way to specify half-precision floats.
33  // Instead we have to print and load fp16 constants as .b16
34  OS << "0x";
35  NumHex = 4;
37  break;
39  OS << "0f";
40  NumHex = 8;
42  break;
44  OS << "0d";
45  NumHex = 16;
47  break;
48  }
49 
50  APInt API = APF.bitcastToAPInt();
51  OS << format_hex_no_prefix(API.getZExtValue(), NumHex, /*Upper=*/true);
52 }
53 
56  MCContext &Ctx) {
57  return new (Ctx) NVPTXGenericMCSymbolRefExpr(SymExpr);
58 }
59 
61  const MCAsmInfo *MAI) const {
62  OS << "generic(";
63  SymExpr->print(OS, MAI);
64  OS << ")";
65 }
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1563
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:166
Context object for machine code objects.
Definition: MCContext.h:63
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition: APFloat.cpp:4444
static const fltSemantics & IEEEdouble() LLVM_READNONE
Definition: APFloat.cpp:123
static const NVPTXGenericMCSymbolRefExpr * create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx)
Definition: NVPTXMCExpr.cpp:55
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
static const NVPTXFloatMCExpr * create(VariantKind Kind, const APFloat &Flt, MCContext &Ctx)
Definition: NVPTXMCExpr.cpp:20
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static const fltSemantics & IEEEsingle() LLVM_READNONE
Definition: APFloat.cpp:120
static const fltSemantics & IEEEhalf() LLVM_READNONE
Definition: APFloat.cpp:117
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: NVPTXMCExpr.cpp:60
Class for arbitrary precision integers.
Definition: APInt.h:70
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: NVPTXMCExpr.cpp:24
APFloat getAPFloat() const
getSubExpr - Get the child of this expression.
Definition: NVPTXMCExpr.h:67
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:199
const unsigned Kind
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
A wrapper for MCSymbolRefExpr that tells the assembly printer that the symbol should be enclosed by g...
Definition: NVPTXMCExpr.h:90
APInt bitcastToAPInt() const
Definition: APFloat.h:1094