LLVM  6.0.0svn
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 using namespace llvm;
15 
16 #define DEBUG_TYPE "nvptx-mcexpr"
17 
18 const NVPTXFloatMCExpr *
20  return new (Ctx) NVPTXFloatMCExpr(Kind, Flt);
21 }
22 
23 void NVPTXFloatMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
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 << "0f";
39  NumHex = 8;
41  break;
43  OS << "0d";
44  NumHex = 16;
46  break;
47  }
48 
49  APInt API = APF.bitcastToAPInt();
50  std::string HexStr(utohexstr(API.getZExtValue()));
51  if (HexStr.length() < NumHex)
52  OS << std::string(NumHex - HexStr.length(), '0');
53  OS << utohexstr(API.getZExtValue());
54 }
55 
58  MCContext &Ctx) {
59  return new (Ctx) NVPTXGenericMCSymbolRefExpr(SymExpr);
60 }
61 
63  const MCAsmInfo *MAI) const {
64  OS << "generic(";
65  SymExpr->print(OS, MAI);
66  OS << ")";
67 }
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1542
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:165
Context object for machine code objects.
Definition: MCContext.h:59
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
Definition: APFloat.cpp:4441
static const fltSemantics & IEEEdouble() LLVM_READNONE
Definition: APFloat.cpp:122
static const NVPTXGenericMCSymbolRefExpr * create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx)
Definition: NVPTXMCExpr.cpp:57
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:19
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static const fltSemantics & IEEEsingle() LLVM_READNONE
Definition: APFloat.cpp:119
static const fltSemantics & IEEEhalf() LLVM_READNONE
Definition: APFloat.cpp:116
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: NVPTXMCExpr.cpp:62
Class for arbitrary precision integers.
Definition: APInt.h:69
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: NVPTXMCExpr.cpp:23
APFloat getAPFloat() const
getSubExpr - Get the child of this expression.
Definition: NVPTXMCExpr.h:67
const unsigned Kind
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
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
std::string utohexstr(uint64_t X, bool LowerCase=false)
Definition: StringExtras.h:76