• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 namespace llvm {
20 
21 class NVPTXFloatMCExpr : public MCTargetExpr {
22 public:
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 
29 private:
30   const VariantKind Kind;
31   const APFloat Flt;
32 
NVPTXFloatMCExpr(VariantKind Kind,APFloat Flt)33   explicit NVPTXFloatMCExpr(VariantKind Kind, APFloat Flt)
34       : Kind(Kind), Flt(std::move(Flt)) {}
35 
36 public:
37   /// @name Construction
38   /// @{
39 
40   static const NVPTXFloatMCExpr *create(VariantKind Kind, const APFloat &Flt,
41                                         MCContext &Ctx);
42 
createConstantFPSingle(const APFloat & Flt,MCContext & Ctx)43   static const NVPTXFloatMCExpr *createConstantFPSingle(const APFloat &Flt,
44                                                         MCContext &Ctx) {
45     return create(VK_NVPTX_SINGLE_PREC_FLOAT, Flt, Ctx);
46   }
47 
createConstantFPDouble(const APFloat & Flt,MCContext & Ctx)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.
getKind()58   VariantKind getKind() const { return Kind; }
59 
60   /// getSubExpr - Get the child of this expression.
getAPFloat()61   APFloat getAPFloat() const { return Flt; }
62 
63 /// @}
64 
65   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
evaluateAsRelocatableImpl(MCValue & Res,const MCAsmLayout * Layout,const MCFixup * Fixup)66   bool evaluateAsRelocatableImpl(MCValue &Res,
67                                  const MCAsmLayout *Layout,
68                                  const MCFixup *Fixup) const override {
69     return false;
70   }
visitUsedExpr(MCStreamer & Streamer)71   void visitUsedExpr(MCStreamer &Streamer) const override {};
findAssociatedFragment()72   MCFragment *findAssociatedFragment() const override { return nullptr; }
73 
74   // There are no TLS NVPTXMCExprs at the moment.
fixELFSymbolsInTLSFixups(MCAssembler & Asm)75   void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
76 
classof(const MCExpr * E)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().
84 class NVPTXGenericMCSymbolRefExpr : public MCTargetExpr {
85 private:
86   const MCSymbolRefExpr *SymExpr;
87 
NVPTXGenericMCSymbolRefExpr(const MCSymbolRefExpr * _SymExpr)88   explicit NVPTXGenericMCSymbolRefExpr(const MCSymbolRefExpr *_SymExpr)
89       : SymExpr(_SymExpr) {}
90 
91 public:
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.
getSymbolExpr()103   const MCSymbolRefExpr *getSymbolExpr() const { return SymExpr; }
104 
105   /// @}
106 
107   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
evaluateAsRelocatableImpl(MCValue & Res,const MCAsmLayout * Layout,const MCFixup * Fixup)108   bool evaluateAsRelocatableImpl(MCValue &Res,
109                                  const MCAsmLayout *Layout,
110                                  const MCFixup *Fixup) const override {
111     return false;
112   }
visitUsedExpr(MCStreamer & Streamer)113   void visitUsedExpr(MCStreamer &Streamer) const override {};
findAssociatedFragment()114   MCFragment *findAssociatedFragment() const override { return nullptr; }
115 
116   // There are no TLS NVPTXMCExprs at the moment.
fixELFSymbolsInTLSFixups(MCAssembler & Asm)117   void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
118 
classof(const MCExpr * E)119   static bool classof(const MCExpr *E) {
120     return E->getKind() == MCExpr::Target;
121   }
122   };
123 } // end namespace llvm
124 
125 #endif
126