NVPTXSubtarget.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //=====-- NVPTXSubtarget.h - Define Subtarget for the NVPTX ---*- 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. // This file declares the NVPTX specific subclass of TargetSubtarget.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXSUBTARGET_H
  13. #define LLVM_LIB_TARGET_NVPTX_NVPTXSUBTARGET_H
  14. #include "NVPTX.h"
  15. #include "NVPTXFrameLowering.h"
  16. #include "NVPTXISelLowering.h"
  17. #include "NVPTXInstrInfo.h"
  18. #include "NVPTXRegisterInfo.h"
  19. #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
  20. #include "llvm/CodeGen/TargetSubtargetInfo.h"
  21. #include "llvm/IR/DataLayout.h"
  22. #include <string>
  23. #define GET_SUBTARGETINFO_HEADER
  24. #include "NVPTXGenSubtargetInfo.inc"
  25. namespace llvm {
  26. class NVPTXSubtarget : public NVPTXGenSubtargetInfo {
  27. virtual void anchor();
  28. std::string TargetName;
  29. // PTX version x.y is represented as 10*x+y, e.g. 3.1 == 31
  30. unsigned PTXVersion;
  31. // SM version x.y is represented as 10*x+y, e.g. 3.1 == 31
  32. unsigned int SmVersion;
  33. const NVPTXTargetMachine &TM;
  34. NVPTXInstrInfo InstrInfo;
  35. NVPTXTargetLowering TLInfo;
  36. SelectionDAGTargetInfo TSInfo;
  37. // NVPTX does not have any call stack frame, but need a NVPTX specific
  38. // FrameLowering class because TargetFrameLowering is abstract.
  39. NVPTXFrameLowering FrameLowering;
  40. public:
  41. /// This constructor initializes the data members to match that
  42. /// of the specified module.
  43. ///
  44. NVPTXSubtarget(const Triple &TT, const std::string &CPU,
  45. const std::string &FS, const NVPTXTargetMachine &TM);
  46. const TargetFrameLowering *getFrameLowering() const override {
  47. return &FrameLowering;
  48. }
  49. const NVPTXInstrInfo *getInstrInfo() const override { return &InstrInfo; }
  50. const NVPTXRegisterInfo *getRegisterInfo() const override {
  51. return &InstrInfo.getRegisterInfo();
  52. }
  53. const NVPTXTargetLowering *getTargetLowering() const override {
  54. return &TLInfo;
  55. }
  56. const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
  57. return &TSInfo;
  58. }
  59. bool hasAtomAddF64() const { return SmVersion >= 60; }
  60. bool hasAtomScope() const { return SmVersion >= 60; }
  61. bool hasAtomBitwise64() const { return SmVersion >= 32; }
  62. bool hasAtomMinMax64() const { return SmVersion >= 32; }
  63. bool hasLDG() const { return SmVersion >= 32; }
  64. inline bool hasHWROT32() const { return SmVersion >= 32; }
  65. bool hasImageHandles() const;
  66. bool hasFP16Math() const { return SmVersion >= 53; }
  67. bool allowFP16Math() const;
  68. bool hasMaskOperator() const { return PTXVersion >= 71; }
  69. bool hasNoReturn() const { return SmVersion >= 30 && PTXVersion >= 64; }
  70. unsigned int getSmVersion() const { return SmVersion; }
  71. std::string getTargetName() const { return TargetName; }
  72. // Get maximum value of required alignments among the supported data types.
  73. // From the PTX ISA doc, section 8.2.3:
  74. // The memory consistency model relates operations executed on memory
  75. // locations with scalar data-types, which have a maximum size and alignment
  76. // of 64 bits. Memory operations with a vector data-type are modelled as a
  77. // set of equivalent memory operations with a scalar data-type, executed in
  78. // an unspecified order on the elements in the vector.
  79. unsigned getMaxRequiredAlignment() const { return 8; }
  80. unsigned getPTXVersion() const { return PTXVersion; }
  81. NVPTXSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
  82. void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
  83. };
  84. } // End llvm namespace
  85. #endif