LLVM  4.0.0
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_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 
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 
44  MCContext &Ctx) {
45  return create(VK_NVPTX_SINGLE_PREC_FLOAT, Flt, Ctx);
46  }
47 
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;
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().
85 private:
86  const MCSymbolRefExpr *SymExpr;
87 
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.
103  const MCSymbolRefExpr *getSymbolExpr() const { return SymExpr; }
104 
105  /// @}
106 
107  void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
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
void visitUsedExpr(MCStreamer &Streamer) const override
Definition: NVPTXMCExpr.h:113
This represents an "assembler immediate".
Definition: MCValue.h:40
ExprKind getKind() const
Definition: MCExpr.h:70
static const NVPTXFloatMCExpr * createConstantFPSingle(const APFloat &Flt, MCContext &Ctx)
Definition: NVPTXMCExpr.h:43
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:66
MCFragment * findAssociatedFragment() const override
Definition: NVPTXMCExpr.h:114
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:29
VariantKind getKind() const
getOpcode - Get the kind of this expression.
Definition: NVPTXMCExpr.h:58
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
This is an extension point for target-specific MCExpr subclasses to implement.
Definition: MCExpr.h:531
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:161
static const NVPTXFloatMCExpr * createConstantFPDouble(const APFloat &Flt, MCContext &Ctx)
Definition: NVPTXMCExpr.h:48
Context object for machine code objects.
Definition: MCContext.h:51
static const NVPTXGenericMCSymbolRefExpr * create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx)
Definition: NVPTXMCExpr.cpp:50
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:57
MCFragment * findAssociatedFragment() const override
Definition: NVPTXMCExpr.h:72
Streaming machine code generation interface.
Definition: MCStreamer.h:161
static bool classof(const MCExpr *E)
Definition: NVPTXMCExpr.h:119
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
Definition: NVPTXMCExpr.h:66
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:75
static const NVPTXFloatMCExpr * create(VariantKind Kind, const APFloat &Flt, MCContext &Ctx)
Definition: NVPTXMCExpr.cpp:19
APFloat getAPFloat() const
getSubExpr - Get the child of this expression.
Definition: NVPTXMCExpr.h:61
static bool classof(const MCExpr *E)
Definition: NVPTXMCExpr.h:77
void visitUsedExpr(MCStreamer &Streamer) const override
Definition: NVPTXMCExpr.h:71
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: NVPTXMCExpr.cpp:55
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
Definition: NVPTXMCExpr.h:117
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: NVPTXMCExpr.cpp:23
const MCSymbolRefExpr * getSymbolExpr() const
getOpcode - Get the kind of this expression.
Definition: NVPTXMCExpr.h:103
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
Definition: NVPTXMCExpr.h:108
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
A wrapper for MCSymbolRefExpr that tells the assembly printer that the symbol should be enclosed by g...
Definition: NVPTXMCExpr.h:84
Target specific expression.
Definition: MCExpr.h:41