NVPTXSubtarget.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //===- NVPTXSubtarget.cpp - NVPTX Subtarget Information -------------------===//
  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 implements the NVPTX specific subclass of TargetSubtarget.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "NVPTXSubtarget.h"
  13. #include "NVPTXTargetMachine.h"
  14. using namespace llvm;
  15. #define DEBUG_TYPE "nvptx-subtarget"
  16. #define GET_SUBTARGETINFO_ENUM
  17. #define GET_SUBTARGETINFO_TARGET_DESC
  18. #define GET_SUBTARGETINFO_CTOR
  19. #include "NVPTXGenSubtargetInfo.inc"
  20. static cl::opt<bool>
  21. NoF16Math("nvptx-no-f16-math", cl::ZeroOrMore, cl::Hidden,
  22. cl::desc("NVPTX Specific: Disable generation of f16 math ops."),
  23. cl::init(false));
  24. // Pin the vtable to this file.
  25. void NVPTXSubtarget::anchor() {}
  26. NVPTXSubtarget &NVPTXSubtarget::initializeSubtargetDependencies(StringRef CPU,
  27. StringRef FS) {
  28. // Provide the default CPU if we don't have one.
  29. TargetName = std::string(CPU.empty() ? "sm_20" : CPU);
  30. ParseSubtargetFeatures(TargetName, /*TuneCPU*/ TargetName, FS);
  31. // Set default to PTX 3.2 (CUDA 5.5)
  32. if (PTXVersion == 0) {
  33. PTXVersion = 32;
  34. }
  35. return *this;
  36. }
  37. NVPTXSubtarget::NVPTXSubtarget(const Triple &TT, const std::string &CPU,
  38. const std::string &FS,
  39. const NVPTXTargetMachine &TM)
  40. : NVPTXGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), PTXVersion(0),
  41. SmVersion(20), TM(TM),
  42. TLInfo(TM, initializeSubtargetDependencies(CPU, FS)) {}
  43. bool NVPTXSubtarget::hasImageHandles() const {
  44. // Enable handles for Kepler+, where CUDA supports indirect surfaces and
  45. // textures
  46. if (TM.getDrvInterface() == NVPTX::CUDA)
  47. return (SmVersion >= 30);
  48. // Disabled, otherwise
  49. return false;
  50. }
  51. bool NVPTXSubtarget::allowFP16Math() const {
  52. return hasFP16Math() && NoF16Math == false;
  53. }