1 //===-- NVPTXMCExpr.h - NVPTX specific MC expression classes ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Modeled after ARMMCExpr
12 #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXMCEXPR_H
13 #define LLVM_LIB_TARGET_NVPTX_NVPTXMCEXPR_H
15 #include "llvm/ADT/APFloat.h"
16 #include "llvm/MC/MCExpr.h"
20 class NVPTXFloatMCExpr : public MCTargetExpr {
24 VK_NVPTX_SINGLE_PREC_FLOAT, // FP constant in single-precision
25 VK_NVPTX_DOUBLE_PREC_FLOAT // FP constant in double-precision
29 const VariantKind Kind;
32 explicit NVPTXFloatMCExpr(VariantKind Kind, APFloat Flt)
33 : Kind(Kind), Flt(Flt) {}
36 /// @name Construction
39 static const NVPTXFloatMCExpr *create(VariantKind Kind, APFloat Flt,
42 static const NVPTXFloatMCExpr *createConstantFPSingle(APFloat Flt,
44 return create(VK_NVPTX_SINGLE_PREC_FLOAT, Flt, Ctx);
47 static const NVPTXFloatMCExpr *createConstantFPDouble(APFloat Flt,
49 return create(VK_NVPTX_DOUBLE_PREC_FLOAT, Flt, Ctx);
56 /// getOpcode - Get the kind of this expression.
57 VariantKind getKind() const { return Kind; }
59 /// getSubExpr - Get the child of this expression.
60 APFloat getAPFloat() const { return Flt; }
64 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
65 bool evaluateAsRelocatableImpl(MCValue &Res,
66 const MCAsmLayout *Layout,
67 const MCFixup *Fixup) const override {
70 void visitUsedExpr(MCStreamer &Streamer) const override {};
71 MCSection *findAssociatedSection() const override { return nullptr; }
73 // There are no TLS NVPTXMCExprs at the moment.
74 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
76 static bool classof(const MCExpr *E) {
77 return E->getKind() == MCExpr::Target;
81 /// A wrapper for MCSymbolRefExpr that tells the assembly printer that the
82 /// symbol should be enclosed by generic().
83 class NVPTXGenericMCSymbolRefExpr : public MCTargetExpr {
85 const MCSymbolRefExpr *SymExpr;
87 explicit NVPTXGenericMCSymbolRefExpr(const MCSymbolRefExpr *_SymExpr)
88 : SymExpr(_SymExpr) {}
91 /// @name Construction
94 static const NVPTXGenericMCSymbolRefExpr
95 *create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx);
101 /// getOpcode - Get the kind of this expression.
102 const MCSymbolRefExpr *getSymbolExpr() const { return SymExpr; }
106 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
107 bool evaluateAsRelocatableImpl(MCValue &Res,
108 const MCAsmLayout *Layout,
109 const MCFixup *Fixup) const override {
112 void visitUsedExpr(MCStreamer &Streamer) const override {};
113 MCSection *findAssociatedSection() const override { return nullptr; }
115 // There are no TLS NVPTXMCExprs at the moment.
116 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
118 static bool classof(const MCExpr *E) {
119 return E->getKind() == MCExpr::Target;
122 } // end namespace llvm