LLVM  8.0.1
NVPTXMCExpr.h
Go to the documentation of this file.
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 
22 public:
23  enum VariantKind {
25  VK_NVPTX_HALF_PREC_FLOAT, // FP constant in half-precision
26  VK_NVPTX_SINGLE_PREC_FLOAT, // FP constant in single-precision
27  VK_NVPTX_DOUBLE_PREC_FLOAT // FP constant in double-precision
28  };
29 
30 private:
31  const VariantKind Kind;
32  const APFloat Flt;
33 
34  explicit NVPTXFloatMCExpr(VariantKind Kind, APFloat Flt)
35  : Kind(Kind), Flt(std::move(Flt)) {}
36 
37 public:
38  /// @name Construction
39  /// @{
40 
41  static const NVPTXFloatMCExpr *create(VariantKind Kind, const APFloat &Flt,
42  MCContext &Ctx);
43 
44  static const NVPTXFloatMCExpr *createConstantFPHalf(const APFloat &Flt,
45  MCContext &Ctx) {
46  return create(VK_NVPTX_HALF_PREC_FLOAT, Flt, Ctx);
47  }
48 
50  MCContext &Ctx) {
51  return create(VK_NVPTX_SINGLE_PREC_FLOAT, Flt, Ctx);
52  }
53 
55  MCContext &Ctx) {
56  return create(VK_NVPTX_DOUBLE_PREC_FLOAT, Flt, Ctx);
57  }
58 
59  /// @}
60  /// @name Accessors
61  /// @{
62 
63  /// getOpcode - Get the kind of this expression.
64  VariantKind getKind() const { return Kind; }
65 
66  /// getSubExpr - Get the child of this expression.
67  APFloat getAPFloat() const { return Flt; }
68 
69 /// @}
70 
71  void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
73  const MCAsmLayout *Layout,
74  const MCFixup *Fixup) const override {
75  return false;
76  }
77  void visitUsedExpr(MCStreamer &Streamer) const override {};
78  MCFragment *findAssociatedFragment() const override { return nullptr; }
79 
80  // There are no TLS NVPTXMCExprs at the moment.
81  void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
82 
83  static bool classof(const MCExpr *E) {
84  return E->getKind() == MCExpr::Target;
85  }
86 };
87 
88 /// A wrapper for MCSymbolRefExpr that tells the assembly printer that the
89 /// symbol should be enclosed by generic().
91 private:
92  const MCSymbolRefExpr *SymExpr;
93 
94  explicit NVPTXGenericMCSymbolRefExpr(const MCSymbolRefExpr *_SymExpr)
95  : SymExpr(_SymExpr) {}
96 
97 public:
98  /// @name Construction
99  /// @{
100 
101  static const NVPTXGenericMCSymbolRefExpr
102  *create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx);
103 
104  /// @}
105  /// @name Accessors
106  /// @{
107 
108  /// getOpcode - Get the kind of this expression.
109  const MCSymbolRefExpr *getSymbolExpr() const { return SymExpr; }
110 
111  /// @}
112 
113  void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
115  const MCAsmLayout *Layout,
116  const MCFixup *Fixup) const override {
117  return false;
118  }
119  void visitUsedExpr(MCStreamer &Streamer) const override {};
120  MCFragment *findAssociatedFragment() const override { return nullptr; }
121 
122  // There are no TLS NVPTXMCExprs at the moment.
123  void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
124 
125  static bool classof(const MCExpr *E) {
126  return E->getKind() == MCExpr::Target;
127  }
128  };
129 } // end namespace llvm
130 
131 #endif
void visitUsedExpr(MCStreamer &Streamer) const override
Definition: NVPTXMCExpr.h:119
This class represents lattice values for constants.
Definition: AllocatorList.h:24
This represents an "assembler immediate".
Definition: MCValue.h:40
static const NVPTXFloatMCExpr * createConstantFPSingle(const APFloat &Flt, MCContext &Ctx)
Definition: NVPTXMCExpr.h:49
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:74
MCFragment * findAssociatedFragment() const override
Definition: NVPTXMCExpr.h:120
Definition: BitVector.h:938
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:29
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
This is an extension point for target-specific MCExpr subclasses to implement.
Definition: MCExpr.h:581
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:166
static const NVPTXFloatMCExpr * createConstantFPDouble(const APFloat &Flt, MCContext &Ctx)
Definition: NVPTXMCExpr.h:54
Context object for machine code objects.
Definition: MCContext.h:63
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
MCFragment * findAssociatedFragment() const override
Definition: NVPTXMCExpr.h:78
Streaming machine code generation interface.
Definition: MCStreamer.h:189
static bool classof(const MCExpr *E)
Definition: NVPTXMCExpr.h:125
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
Definition: NVPTXMCExpr.h:72
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
VariantKind getKind() const
getOpcode - Get the kind of this expression.
Definition: NVPTXMCExpr.h:64
This file declares a class to represent arbitrary precision floating point values and provide a varie...
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
Definition: NVPTXMCExpr.h:81
static const NVPTXFloatMCExpr * create(VariantKind Kind, const APFloat &Flt, MCContext &Ctx)
Definition: NVPTXMCExpr.cpp:20
static bool classof(const MCExpr *E)
Definition: NVPTXMCExpr.h:83
void visitUsedExpr(MCStreamer &Streamer) const override
Definition: NVPTXMCExpr.h:77
ExprKind getKind() const
Definition: MCExpr.h:73
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
Definition: NVPTXMCExpr.h:123
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: NVPTXMCExpr.cpp:24
APFloat getAPFloat() const
getSubExpr - Get the child of this expression.
Definition: NVPTXMCExpr.h:67
static const NVPTXFloatMCExpr * createConstantFPHalf(const APFloat &Flt, MCContext &Ctx)
Definition: NVPTXMCExpr.h:44
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
Definition: NVPTXMCExpr.h:114
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
A wrapper for MCSymbolRefExpr that tells the assembly printer that the symbol should be enclosed by g...
Definition: NVPTXMCExpr.h:90
Target specific expression.
Definition: MCExpr.h:43
const MCSymbolRefExpr * getSymbolExpr() const
getOpcode - Get the kind of this expression.
Definition: NVPTXMCExpr.h:109