LLVM  13.0.0git
NVPTXMCExpr.h
Go to the documentation of this file.
1 //===-- NVPTXMCExpr.h - NVPTX specific MC expression classes ----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // Modeled after ARMMCExpr
10 
11 #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXMCEXPR_H
12 #define LLVM_LIB_TARGET_NVPTX_NVPTXMCEXPR_H
13 
14 #include "llvm/ADT/APFloat.h"
15 #include "llvm/MC/MCExpr.h"
16 #include <utility>
17 
18 namespace llvm {
19 
21 public:
22  enum VariantKind {
24  VK_NVPTX_HALF_PREC_FLOAT, // FP constant in half-precision
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 
43  static const NVPTXFloatMCExpr *createConstantFPHalf(const APFloat &Flt,
44  MCContext &Ctx) {
45  return create(VK_NVPTX_HALF_PREC_FLOAT, Flt, Ctx);
46  }
47 
49  MCContext &Ctx) {
50  return create(VK_NVPTX_SINGLE_PREC_FLOAT, Flt, Ctx);
51  }
52 
54  MCContext &Ctx) {
55  return create(VK_NVPTX_DOUBLE_PREC_FLOAT, Flt, Ctx);
56  }
57 
58  /// @}
59  /// @name Accessors
60  /// @{
61 
62  /// getOpcode - Get the kind of this expression.
63  VariantKind getKind() const { return Kind; }
64 
65  /// getSubExpr - Get the child of this expression.
66  APFloat getAPFloat() const { return Flt; }
67 
68 /// @}
69 
70  void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
72  const MCAsmLayout *Layout,
73  const MCFixup *Fixup) const override {
74  return false;
75  }
76  void visitUsedExpr(MCStreamer &Streamer) const override {};
77  MCFragment *findAssociatedFragment() const override { return nullptr; }
78 
79  // There are no TLS NVPTXMCExprs at the moment.
80  void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
81 
82  static bool classof(const MCExpr *E) {
83  return E->getKind() == MCExpr::Target;
84  }
85 };
86 
87 /// A wrapper for MCSymbolRefExpr that tells the assembly printer that the
88 /// symbol should be enclosed by generic().
90 private:
91  const MCSymbolRefExpr *SymExpr;
92 
93  explicit NVPTXGenericMCSymbolRefExpr(const MCSymbolRefExpr *_SymExpr)
94  : SymExpr(_SymExpr) {}
95 
96 public:
97  /// @name Construction
98  /// @{
99 
100  static const NVPTXGenericMCSymbolRefExpr
101  *create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx);
102 
103  /// @}
104  /// @name Accessors
105  /// @{
106 
107  /// getOpcode - Get the kind of this expression.
108  const MCSymbolRefExpr *getSymbolExpr() const { return SymExpr; }
109 
110  /// @}
111 
112  void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
114  const MCAsmLayout *Layout,
115  const MCFixup *Fixup) const override {
116  return false;
117  }
118  void visitUsedExpr(MCStreamer &Streamer) const override {};
119  MCFragment *findAssociatedFragment() const override { return nullptr; }
120 
121  // There are no TLS NVPTXMCExprs at the moment.
122  void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
123 
124  static bool classof(const MCExpr *E) {
125  return E->getKind() == MCExpr::Target;
126  }
127  };
128 } // end namespace llvm
129 
130 #endif
llvm::NVPTXFloatMCExpr::create
static const NVPTXFloatMCExpr * create(VariantKind Kind, const APFloat &Flt, MCContext &Ctx)
Definition: NVPTXMCExpr.cpp:19
llvm::lltok::APFloat
@ APFloat
Definition: LLToken.h:490
llvm
Definition: AllocatorList.h:23
llvm::NVPTXGenericMCSymbolRefExpr::findAssociatedFragment
MCFragment * findAssociatedFragment() const override
Definition: NVPTXMCExpr.h:119
llvm::NVPTXFloatMCExpr::VK_NVPTX_HALF_PREC_FLOAT
@ VK_NVPTX_HALF_PREC_FLOAT
Definition: NVPTXMCExpr.h:24
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:71
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::NVPTXGenericMCSymbolRefExpr::create
static const NVPTXGenericMCSymbolRefExpr * create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx)
Definition: NVPTXMCExpr.cpp:54
llvm::NVPTXFloatMCExpr::VK_NVPTX_DOUBLE_PREC_FLOAT
@ VK_NVPTX_DOUBLE_PREC_FLOAT
Definition: NVPTXMCExpr.h:26
llvm::NVPTXFloatMCExpr::createConstantFPDouble
static const NVPTXFloatMCExpr * createConstantFPDouble(const APFloat &Flt, MCContext &Ctx)
Definition: NVPTXMCExpr.h:53
llvm::NVPTXGenericMCSymbolRefExpr::getSymbolExpr
const MCSymbolRefExpr * getSymbolExpr() const
getOpcode - Get the kind of this expression.
Definition: NVPTXMCExpr.h:108
llvm::NVPTXGenericMCSymbolRefExpr::fixELFSymbolsInTLSFixups
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
Definition: NVPTXMCExpr.h:122
llvm::MCFragment
Definition: MCFragment.h:31
llvm::NVPTXFloatMCExpr::createConstantFPSingle
static const NVPTXFloatMCExpr * createConstantFPSingle(const APFloat &Flt, MCContext &Ctx)
Definition: NVPTXMCExpr.h:48
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:197
llvm::NVPTXGenericMCSymbolRefExpr::printImpl
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: NVPTXMCExpr.cpp:59
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::MCExpr::Target
@ Target
Target specific expression.
Definition: MCExpr.h:42
llvm::NVPTXFloatMCExpr::findAssociatedFragment
MCFragment * findAssociatedFragment() const override
Definition: NVPTXMCExpr.h:77
llvm::NVPTXFloatMCExpr
Definition: NVPTXMCExpr.h:20
llvm::NVPTXFloatMCExpr::fixELFSymbolsInTLSFixups
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override
Definition: NVPTXMCExpr.h:80
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
APFloat.h
This file declares a class to represent arbitrary precision floating point values and provide a varie...
llvm::NVPTXFloatMCExpr::printImpl
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override
Definition: NVPTXMCExpr.cpp:23
llvm::NVPTXFloatMCExpr::VK_NVPTX_None
@ VK_NVPTX_None
Definition: NVPTXMCExpr.h:23
llvm::NVPTXFloatMCExpr::getAPFloat
APFloat getAPFloat() const
getSubExpr - Get the child of this expression.
Definition: NVPTXMCExpr.h:66
llvm::NVPTXFloatMCExpr::createConstantFPHalf
static const NVPTXFloatMCExpr * createConstantFPHalf(const APFloat &Flt, MCContext &Ctx)
Definition: NVPTXMCExpr.h:43
llvm::APFloat
Definition: APFloat.h:701
llvm::MCAssembler
Definition: MCAssembler.h:60
llvm::NVPTXGenericMCSymbolRefExpr::visitUsedExpr
void visitUsedExpr(MCStreamer &Streamer) const override
Definition: NVPTXMCExpr.h:118
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1540
llvm::MCSymbolRefExpr
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
llvm::NVPTXFloatMCExpr::evaluateAsRelocatableImpl
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
Definition: NVPTXMCExpr.h:71
llvm::NVPTXFloatMCExpr::VK_NVPTX_SINGLE_PREC_FLOAT
@ VK_NVPTX_SINGLE_PREC_FLOAT
Definition: NVPTXMCExpr.h:25
llvm::NVPTXFloatMCExpr::classof
static bool classof(const MCExpr *E)
Definition: NVPTXMCExpr.h:82
llvm::NVPTXFloatMCExpr::visitUsedExpr
void visitUsedExpr(MCStreamer &Streamer) const override
Definition: NVPTXMCExpr.h:76
std
Definition: BitVector.h:838
llvm::MCAsmLayout
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
llvm::NVPTXFloatMCExpr::VariantKind
VariantKind
Definition: NVPTXMCExpr.h:22
llvm::NVPTXGenericMCSymbolRefExpr::classof
static bool classof(const MCExpr *E)
Definition: NVPTXMCExpr.h:124
llvm::NVPTXFloatMCExpr::getKind
VariantKind getKind() const
getOpcode - Get the kind of this expression.
Definition: NVPTXMCExpr.h:63
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
llvm::MCTargetExpr
This is an extension point for target-specific MCExpr subclasses to implement.
Definition: MCExpr.h:643
MCExpr.h
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:81
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::NVPTXGenericMCSymbolRefExpr::evaluateAsRelocatableImpl
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const override
Definition: NVPTXMCExpr.h:113
llvm::NVPTXGenericMCSymbolRefExpr
A wrapper for MCSymbolRefExpr that tells the assembly printer that the symbol should be enclosed by g...
Definition: NVPTXMCExpr.h:89