NVPTXTargetMachine.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //===-- NVPTXTargetMachine.h - Define TargetMachine for 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 TargetMachine.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXTARGETMACHINE_H
  13. #define LLVM_LIB_TARGET_NVPTX_NVPTXTARGETMACHINE_H
  14. #include "NVPTXSubtarget.h"
  15. #include "llvm/Target/TargetMachine.h"
  16. #include <optional>
  17. #include <utility>
  18. namespace llvm {
  19. /// NVPTXTargetMachine
  20. ///
  21. class NVPTXTargetMachine : public LLVMTargetMachine {
  22. bool is64bit;
  23. // Use 32-bit pointers for accessing const/local/short AS.
  24. bool UseShortPointers;
  25. std::unique_ptr<TargetLoweringObjectFile> TLOF;
  26. NVPTX::DrvInterface drvInterface;
  27. NVPTXSubtarget Subtarget;
  28. // Hold Strings that can be free'd all together with NVPTXTargetMachine
  29. BumpPtrAllocator StrAlloc;
  30. UniqueStringSaver StrPool;
  31. public:
  32. NVPTXTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
  33. StringRef FS, const TargetOptions &Options,
  34. std::optional<Reloc::Model> RM,
  35. std::optional<CodeModel::Model> CM, CodeGenOpt::Level OP,
  36. bool is64bit);
  37. ~NVPTXTargetMachine() override;
  38. const NVPTXSubtarget *getSubtargetImpl(const Function &) const override {
  39. return &Subtarget;
  40. }
  41. const NVPTXSubtarget *getSubtargetImpl() const { return &Subtarget; }
  42. bool is64Bit() const { return is64bit; }
  43. bool useShortPointers() const { return UseShortPointers; }
  44. NVPTX::DrvInterface getDrvInterface() const { return drvInterface; }
  45. UniqueStringSaver &getStrPool() const {
  46. return const_cast<UniqueStringSaver &>(StrPool);
  47. }
  48. TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
  49. // Emission of machine code through MCJIT is not supported.
  50. bool addPassesToEmitMC(PassManagerBase &, MCContext *&, raw_pwrite_stream &,
  51. bool = true) override {
  52. return true;
  53. }
  54. TargetLoweringObjectFile *getObjFileLowering() const override {
  55. return TLOF.get();
  56. }
  57. MachineFunctionInfo *
  58. createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
  59. const TargetSubtargetInfo *STI) const override;
  60. void registerPassBuilderCallbacks(PassBuilder &PB) override;
  61. TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
  62. bool isMachineVerifierClean() const override {
  63. return false;
  64. }
  65. std::pair<const Value *, unsigned>
  66. getPredicatedAddrSpace(const Value *V) const override;
  67. }; // NVPTXTargetMachine.
  68. class NVPTXTargetMachine32 : public NVPTXTargetMachine {
  69. virtual void anchor();
  70. public:
  71. NVPTXTargetMachine32(const Target &T, const Triple &TT, StringRef CPU,
  72. StringRef FS, const TargetOptions &Options,
  73. std::optional<Reloc::Model> RM,
  74. std::optional<CodeModel::Model> CM, CodeGenOpt::Level OL,
  75. bool JIT);
  76. };
  77. class NVPTXTargetMachine64 : public NVPTXTargetMachine {
  78. virtual void anchor();
  79. public:
  80. NVPTXTargetMachine64(const Target &T, const Triple &TT, StringRef CPU,
  81. StringRef FS, const TargetOptions &Options,
  82. std::optional<Reloc::Model> RM,
  83. std::optional<CodeModel::Model> CM, CodeGenOpt::Level OL,
  84. bool JIT);
  85. };
  86. } // end namespace llvm
  87. #endif