Path: blob/main/contrib/llvm-project/llvm/lib/Target/NVPTX/NVPTXMCExpr.cpp
35271 views
//===-- NVPTXMCExpr.cpp - NVPTX specific MC expression classes ------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "NVPTXMCExpr.h"9#include "llvm/ADT/StringExtras.h"10#include "llvm/MC/MCAssembler.h"11#include "llvm/MC/MCContext.h"12#include "llvm/Support/Format.h"13using namespace llvm;1415#define DEBUG_TYPE "nvptx-mcexpr"1617const NVPTXFloatMCExpr *18NVPTXFloatMCExpr::create(VariantKind Kind, const APFloat &Flt, MCContext &Ctx) {19return new (Ctx) NVPTXFloatMCExpr(Kind, Flt);20}2122void NVPTXFloatMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {23bool Ignored;24unsigned NumHex;25APFloat APF = getAPFloat();2627switch (Kind) {28default: llvm_unreachable("Invalid kind!");29case VK_NVPTX_HALF_PREC_FLOAT:30// ptxas does not have a way to specify half-precision floats.31// Instead we have to print and load fp16 constants as .b1632OS << "0x";33NumHex = 4;34APF.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, &Ignored);35break;36case VK_NVPTX_BFLOAT_PREC_FLOAT:37OS << "0x";38NumHex = 4;39APF.convert(APFloat::BFloat(), APFloat::rmNearestTiesToEven, &Ignored);40break;41case VK_NVPTX_SINGLE_PREC_FLOAT:42OS << "0f";43NumHex = 8;44APF.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven, &Ignored);45break;46case VK_NVPTX_DOUBLE_PREC_FLOAT:47OS << "0d";48NumHex = 16;49APF.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &Ignored);50break;51}5253APInt API = APF.bitcastToAPInt();54OS << format_hex_no_prefix(API.getZExtValue(), NumHex, /*Upper=*/true);55}5657const NVPTXGenericMCSymbolRefExpr*58NVPTXGenericMCSymbolRefExpr::create(const MCSymbolRefExpr *SymExpr,59MCContext &Ctx) {60return new (Ctx) NVPTXGenericMCSymbolRefExpr(SymExpr);61}6263void NVPTXGenericMCSymbolRefExpr::printImpl(raw_ostream &OS,64const MCAsmInfo *MAI) const {65OS << "generic(";66SymExpr->print(OS, MAI);67OS << ")";68}697071