2013-08-06 22:13:27 +08:00
|
|
|
//===-- NVPTXMCExpr.cpp - NVPTX specific MC expression classes ------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "NVPTXMCExpr.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/MC/MCAssembler.h"
|
|
|
|
#include "llvm/MC/MCContext.h"
|
2017-12-29 00:58:54 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2013-08-06 22:13:27 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:41:26 +08:00
|
|
|
#define DEBUG_TYPE "nvptx-mcexpr"
|
|
|
|
|
2016-06-09 03:09:22 +08:00
|
|
|
const NVPTXFloatMCExpr *
|
|
|
|
NVPTXFloatMCExpr::create(VariantKind Kind, const APFloat &Flt, MCContext &Ctx) {
|
2013-08-06 22:13:27 +08:00
|
|
|
return new (Ctx) NVPTXFloatMCExpr(Kind, Flt);
|
|
|
|
}
|
|
|
|
|
2015-06-09 08:31:39 +08:00
|
|
|
void NVPTXFloatMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
|
2013-08-06 22:13:27 +08:00
|
|
|
bool Ignored;
|
|
|
|
unsigned NumHex;
|
|
|
|
APFloat APF = getAPFloat();
|
|
|
|
|
|
|
|
switch (Kind) {
|
|
|
|
default: llvm_unreachable("Invalid kind!");
|
2017-01-14 04:56:17 +08:00
|
|
|
case VK_NVPTX_HALF_PREC_FLOAT:
|
|
|
|
// ptxas does not have a way to specify half-precision floats.
|
|
|
|
// Instead we have to print and load fp16 constants as .b16
|
|
|
|
OS << "0x";
|
|
|
|
NumHex = 4;
|
|
|
|
APF.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, &Ignored);
|
|
|
|
break;
|
2013-08-06 22:13:27 +08:00
|
|
|
case VK_NVPTX_SINGLE_PREC_FLOAT:
|
|
|
|
OS << "0f";
|
|
|
|
NumHex = 8;
|
2016-12-14 19:57:17 +08:00
|
|
|
APF.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven, &Ignored);
|
2013-08-06 22:13:27 +08:00
|
|
|
break;
|
|
|
|
case VK_NVPTX_DOUBLE_PREC_FLOAT:
|
|
|
|
OS << "0d";
|
|
|
|
NumHex = 16;
|
2016-12-14 19:57:17 +08:00
|
|
|
APF.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &Ignored);
|
2013-08-06 22:13:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
APInt API = APF.bitcastToAPInt();
|
2017-12-29 00:58:54 +08:00
|
|
|
OS << format_hex_no_prefix(API.getZExtValue(), NumHex, /*Upper=*/true);
|
2013-08-06 22:13:27 +08:00
|
|
|
}
|
2015-04-29 01:18:30 +08:00
|
|
|
|
|
|
|
const NVPTXGenericMCSymbolRefExpr*
|
2015-05-30 09:25:56 +08:00
|
|
|
NVPTXGenericMCSymbolRefExpr::create(const MCSymbolRefExpr *SymExpr,
|
2015-04-29 01:18:30 +08:00
|
|
|
MCContext &Ctx) {
|
|
|
|
return new (Ctx) NVPTXGenericMCSymbolRefExpr(SymExpr);
|
|
|
|
}
|
|
|
|
|
2015-06-09 08:31:39 +08:00
|
|
|
void NVPTXGenericMCSymbolRefExpr::printImpl(raw_ostream &OS,
|
|
|
|
const MCAsmInfo *MAI) const {
|
|
|
|
OS << "generic(";
|
|
|
|
SymExpr->print(OS, MAI);
|
|
|
|
OS << ")";
|
2015-04-29 01:18:30 +08:00
|
|
|
}
|