NVPTXMCExpr.h revision de2d8694e25a814696358e95141f4b1aa4d8847e
1//===-- NVPTXMCExpr.h - NVPTX specific MC expression classes ----*- C++ -*-===// 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// Modeled after ARMMCExpr 11 12#ifndef LLVM_LIB_TARGET_NVPTX_NVPTXMCEXPR_H 13#define LLVM_LIB_TARGET_NVPTX_NVPTXMCEXPR_H 14 15#include "llvm/ADT/APFloat.h" 16#include "llvm/MC/MCExpr.h" 17#include <utility> 18 19namespace llvm { 20 21class NVPTXFloatMCExpr : public MCTargetExpr { 22public: 23 enum VariantKind { 24 VK_NVPTX_None, 25 VK_NVPTX_SINGLE_PREC_FLOAT, // FP constant in single-precision 26 VK_NVPTX_DOUBLE_PREC_FLOAT // FP constant in double-precision 27 }; 28 29private: 30 const VariantKind Kind; 31 const APFloat Flt; 32 33 explicit NVPTXFloatMCExpr(VariantKind Kind, APFloat Flt) 34 : Kind(Kind), Flt(std::move(Flt)) {} 35 36public: 37 /// @name Construction 38 /// @{ 39 40 static const NVPTXFloatMCExpr *create(VariantKind Kind, const APFloat &Flt, 41 MCContext &Ctx); 42 43 static const NVPTXFloatMCExpr *createConstantFPSingle(const APFloat &Flt, 44 MCContext &Ctx) { 45 return create(VK_NVPTX_SINGLE_PREC_FLOAT, Flt, Ctx); 46 } 47 48 static const NVPTXFloatMCExpr *createConstantFPDouble(const APFloat &Flt, 49 MCContext &Ctx) { 50 return create(VK_NVPTX_DOUBLE_PREC_FLOAT, Flt, Ctx); 51 } 52 53 /// @} 54 /// @name Accessors 55 /// @{ 56 57 /// getOpcode - Get the kind of this expression. 58 VariantKind getKind() const { return Kind; } 59 60 /// getSubExpr - Get the child of this expression. 61 APFloat getAPFloat() const { return Flt; } 62 63/// @} 64 65 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; 66 bool evaluateAsRelocatableImpl(MCValue &Res, 67 const MCAsmLayout *Layout, 68 const MCFixup *Fixup) const override { 69 return false; 70 } 71 void visitUsedExpr(MCStreamer &Streamer) const override {}; 72 MCFragment *findAssociatedFragment() const override { return nullptr; } 73 74 // There are no TLS NVPTXMCExprs at the moment. 75 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {} 76 77 static bool classof(const MCExpr *E) { 78 return E->getKind() == MCExpr::Target; 79 } 80}; 81 82/// A wrapper for MCSymbolRefExpr that tells the assembly printer that the 83/// symbol should be enclosed by generic(). 84class NVPTXGenericMCSymbolRefExpr : public MCTargetExpr { 85private: 86 const MCSymbolRefExpr *SymExpr; 87 88 explicit NVPTXGenericMCSymbolRefExpr(const MCSymbolRefExpr *_SymExpr) 89 : SymExpr(_SymExpr) {} 90 91public: 92 /// @name Construction 93 /// @{ 94 95 static const NVPTXGenericMCSymbolRefExpr 96 *create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx); 97 98 /// @} 99 /// @name Accessors 100 /// @{ 101 102 /// getOpcode - Get the kind of this expression. 103 const MCSymbolRefExpr *getSymbolExpr() const { return SymExpr; } 104 105 /// @} 106 107 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; 108 bool evaluateAsRelocatableImpl(MCValue &Res, 109 const MCAsmLayout *Layout, 110 const MCFixup *Fixup) const override { 111 return false; 112 } 113 void visitUsedExpr(MCStreamer &Streamer) const override {}; 114 MCFragment *findAssociatedFragment() const override { return nullptr; } 115 116 // There are no TLS NVPTXMCExprs at the moment. 117 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {} 118 119 static bool classof(const MCExpr *E) { 120 return E->getKind() == MCExpr::Target; 121 } 122 }; 123} // end namespace llvm 124 125#endif 126