NVPTXMCExpr.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. // Modeled after ARMMCExpr
  9. #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXMCEXPR_H
  10. #define LLVM_LIB_TARGET_NVPTX_NVPTXMCEXPR_H
  11. #include "llvm/ADT/APFloat.h"
  12. #include "llvm/MC/MCExpr.h"
  13. #include <utility>
  14. namespace llvm {
  15. class NVPTXFloatMCExpr : public MCTargetExpr {
  16. public:
  17. enum VariantKind {
  18. VK_NVPTX_None,
  19. VK_NVPTX_HALF_PREC_FLOAT, // FP constant in half-precision
  20. VK_NVPTX_SINGLE_PREC_FLOAT, // FP constant in single-precision
  21. VK_NVPTX_DOUBLE_PREC_FLOAT // FP constant in double-precision
  22. };
  23. private:
  24. const VariantKind Kind;
  25. const APFloat Flt;
  26. explicit NVPTXFloatMCExpr(VariantKind Kind, APFloat Flt)
  27. : Kind(Kind), Flt(std::move(Flt)) {}
  28. public:
  29. /// @name Construction
  30. /// @{
  31. static const NVPTXFloatMCExpr *create(VariantKind Kind, const APFloat &Flt,
  32. MCContext &Ctx);
  33. static const NVPTXFloatMCExpr *createConstantFPHalf(const APFloat &Flt,
  34. MCContext &Ctx) {
  35. return create(VK_NVPTX_HALF_PREC_FLOAT, Flt, Ctx);
  36. }
  37. static const NVPTXFloatMCExpr *createConstantFPSingle(const APFloat &Flt,
  38. MCContext &Ctx) {
  39. return create(VK_NVPTX_SINGLE_PREC_FLOAT, Flt, Ctx);
  40. }
  41. static const NVPTXFloatMCExpr *createConstantFPDouble(const APFloat &Flt,
  42. MCContext &Ctx) {
  43. return create(VK_NVPTX_DOUBLE_PREC_FLOAT, Flt, Ctx);
  44. }
  45. /// @}
  46. /// @name Accessors
  47. /// @{
  48. /// getOpcode - Get the kind of this expression.
  49. VariantKind getKind() const { return Kind; }
  50. /// getSubExpr - Get the child of this expression.
  51. APFloat getAPFloat() const { return Flt; }
  52. /// @}
  53. void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
  54. bool evaluateAsRelocatableImpl(MCValue &Res,
  55. const MCAsmLayout *Layout,
  56. const MCFixup *Fixup) const override {
  57. return false;
  58. }
  59. void visitUsedExpr(MCStreamer &Streamer) const override {};
  60. MCFragment *findAssociatedFragment() const override { return nullptr; }
  61. // There are no TLS NVPTXMCExprs at the moment.
  62. void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
  63. static bool classof(const MCExpr *E) {
  64. return E->getKind() == MCExpr::Target;
  65. }
  66. };
  67. /// A wrapper for MCSymbolRefExpr that tells the assembly printer that the
  68. /// symbol should be enclosed by generic().
  69. class NVPTXGenericMCSymbolRefExpr : public MCTargetExpr {
  70. private:
  71. const MCSymbolRefExpr *SymExpr;
  72. explicit NVPTXGenericMCSymbolRefExpr(const MCSymbolRefExpr *_SymExpr)
  73. : SymExpr(_SymExpr) {}
  74. public:
  75. /// @name Construction
  76. /// @{
  77. static const NVPTXGenericMCSymbolRefExpr
  78. *create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx);
  79. /// @}
  80. /// @name Accessors
  81. /// @{
  82. /// getOpcode - Get the kind of this expression.
  83. const MCSymbolRefExpr *getSymbolExpr() const { return SymExpr; }
  84. /// @}
  85. void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
  86. bool evaluateAsRelocatableImpl(MCValue &Res,
  87. const MCAsmLayout *Layout,
  88. const MCFixup *Fixup) const override {
  89. return false;
  90. }
  91. void visitUsedExpr(MCStreamer &Streamer) const override {};
  92. MCFragment *findAssociatedFragment() const override { return nullptr; }
  93. // There are no TLS NVPTXMCExprs at the moment.
  94. void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
  95. static bool classof(const MCExpr *E) {
  96. return E->getKind() == MCExpr::Target;
  97. }
  98. };
  99. } // end namespace llvm
  100. #endif