blob: 81a606d7535cbb24e2255b71b5552651f070ffef [file] [log] [blame]
Justin Holewinskia2a63d22013-08-06 14:13:27 +00001//===-- 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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000012#ifndef LLVM_LIB_TARGET_NVPTX_NVPTXMCEXPR_H
13#define LLVM_LIB_TARGET_NVPTX_NVPTXMCEXPR_H
Justin Holewinskia2a63d22013-08-06 14:13:27 +000014
15#include "llvm/ADT/APFloat.h"
16#include "llvm/MC/MCExpr.h"
17
18namespace llvm {
19
20class NVPTXFloatMCExpr : public MCTargetExpr {
21public:
22 enum VariantKind {
23 VK_NVPTX_None,
24 VK_NVPTX_SINGLE_PREC_FLOAT, // FP constant in single-precision
25 VK_NVPTX_DOUBLE_PREC_FLOAT // FP constant in double-precision
26 };
27
28private:
29 const VariantKind Kind;
30 const APFloat Flt;
31
David Blaikie9f380a32015-03-16 18:06:57 +000032 explicit NVPTXFloatMCExpr(VariantKind Kind, APFloat Flt)
33 : Kind(Kind), Flt(Flt) {}
Justin Holewinskia2a63d22013-08-06 14:13:27 +000034
35public:
36 /// @name Construction
37 /// @{
38
Jim Grosbach13760bd2015-05-30 01:25:56 +000039 static const NVPTXFloatMCExpr *create(VariantKind Kind, APFloat Flt,
Justin Holewinskia2a63d22013-08-06 14:13:27 +000040 MCContext &Ctx);
41
Jim Grosbach13760bd2015-05-30 01:25:56 +000042 static const NVPTXFloatMCExpr *createConstantFPSingle(APFloat Flt,
Justin Holewinskia2a63d22013-08-06 14:13:27 +000043 MCContext &Ctx) {
Jim Grosbach13760bd2015-05-30 01:25:56 +000044 return create(VK_NVPTX_SINGLE_PREC_FLOAT, Flt, Ctx);
Justin Holewinskia2a63d22013-08-06 14:13:27 +000045 }
46
Jim Grosbach13760bd2015-05-30 01:25:56 +000047 static const NVPTXFloatMCExpr *createConstantFPDouble(APFloat Flt,
Justin Holewinskia2a63d22013-08-06 14:13:27 +000048 MCContext &Ctx) {
Jim Grosbach13760bd2015-05-30 01:25:56 +000049 return create(VK_NVPTX_DOUBLE_PREC_FLOAT, Flt, Ctx);
Justin Holewinskia2a63d22013-08-06 14:13:27 +000050 }
51
52 /// @}
53 /// @name Accessors
54 /// @{
55
56 /// getOpcode - Get the kind of this expression.
57 VariantKind getKind() const { return Kind; }
58
59 /// getSubExpr - Get the child of this expression.
60 APFloat getAPFloat() const { return Flt; }
61
62/// @}
63
Matt Arsenault8b643552015-06-09 00:31:39 +000064 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
Jim Grosbach13760bd2015-05-30 01:25:56 +000065 bool evaluateAsRelocatableImpl(MCValue &Res,
Joerg Sonnenberger752b91b2014-08-10 11:35:12 +000066 const MCAsmLayout *Layout,
67 const MCFixup *Fixup) const override {
Justin Holewinskia2a63d22013-08-06 14:13:27 +000068 return false;
69 }
Rafael Espindolae2c66242014-06-25 15:45:33 +000070 void visitUsedExpr(MCStreamer &Streamer) const override {};
Rafael Espindolae3a20f52015-10-05 12:07:05 +000071 MCFragment *findAssociatedFragment() const override { return nullptr; }
Justin Holewinskia2a63d22013-08-06 14:13:27 +000072
73 // There are no TLS NVPTXMCExprs at the moment.
Craig Topper2865c982014-04-29 07:57:44 +000074 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
Justin Holewinskia2a63d22013-08-06 14:13:27 +000075
76 static bool classof(const MCExpr *E) {
77 return E->getKind() == MCExpr::Target;
78 }
79};
Justin Holewinski3d2a9762015-04-28 17:18:30 +000080
81/// A wrapper for MCSymbolRefExpr that tells the assembly printer that the
82/// symbol should be enclosed by generic().
83class NVPTXGenericMCSymbolRefExpr : public MCTargetExpr {
84private:
85 const MCSymbolRefExpr *SymExpr;
86
87 explicit NVPTXGenericMCSymbolRefExpr(const MCSymbolRefExpr *_SymExpr)
88 : SymExpr(_SymExpr) {}
89
90public:
91 /// @name Construction
92 /// @{
93
94 static const NVPTXGenericMCSymbolRefExpr
Jim Grosbach13760bd2015-05-30 01:25:56 +000095 *create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx);
Justin Holewinski3d2a9762015-04-28 17:18:30 +000096
97 /// @}
98 /// @name Accessors
99 /// @{
100
101 /// getOpcode - Get the kind of this expression.
102 const MCSymbolRefExpr *getSymbolExpr() const { return SymExpr; }
103
104 /// @}
105
Matt Arsenault8b643552015-06-09 00:31:39 +0000106 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
Jim Grosbach13760bd2015-05-30 01:25:56 +0000107 bool evaluateAsRelocatableImpl(MCValue &Res,
Justin Holewinski3d2a9762015-04-28 17:18:30 +0000108 const MCAsmLayout *Layout,
109 const MCFixup *Fixup) const override {
110 return false;
111 }
112 void visitUsedExpr(MCStreamer &Streamer) const override {};
Rafael Espindolae3a20f52015-10-05 12:07:05 +0000113 MCFragment *findAssociatedFragment() const override { return nullptr; }
Justin Holewinski3d2a9762015-04-28 17:18:30 +0000114
115 // There are no TLS NVPTXMCExprs at the moment.
116 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
117
118 static bool classof(const MCExpr *E) {
119 return E->getKind() == MCExpr::Target;
120 }
121 };
Justin Holewinskia2a63d22013-08-06 14:13:27 +0000122} // end namespace llvm
123
124#endif