GenericUniformityInfo.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- GenericUniformityInfo.h ---------------------------*- C++ -*--------===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. //
  15. //===----------------------------------------------------------------------===//
  16. #ifndef LLVM_ADT_GENERICUNIFORMITYINFO_H
  17. #define LLVM_ADT_GENERICUNIFORMITYINFO_H
  18. // #include "llvm/ADT/DenseSet.h"
  19. #include "llvm/ADT/GenericCycleInfo.h"
  20. // #include "llvm/ADT/SmallPtrSet.h"
  21. // #include "llvm/ADT/Uniformity.h"
  22. // #include "llvm/Analysis/LegacyDivergenceAnalysis.h"
  23. #include "llvm/Support/raw_ostream.h"
  24. namespace llvm {
  25. class TargetTransformInfo;
  26. template <typename ContextT> class GenericUniformityAnalysisImpl;
  27. template <typename ImplT> struct GenericUniformityAnalysisImplDeleter {
  28. // Ugly hack around the fact that recent (> 15.0) clang will run into an
  29. // is_invocable() check in some GNU libc++'s unique_ptr implementation
  30. // and reject this deleter if you just make it callable with an ImplT *,
  31. // whether or not the type of ImplT is spelled out.
  32. using pointer = ImplT *;
  33. void operator()(ImplT *Impl);
  34. };
  35. template <typename ContextT> class GenericUniformityInfo {
  36. public:
  37. using BlockT = typename ContextT::BlockT;
  38. using FunctionT = typename ContextT::FunctionT;
  39. using ValueRefT = typename ContextT::ValueRefT;
  40. using ConstValueRefT = typename ContextT::ConstValueRefT;
  41. using InstructionT = typename ContextT::InstructionT;
  42. using DominatorTreeT = typename ContextT::DominatorTreeT;
  43. using ThisT = GenericUniformityInfo<ContextT>;
  44. using CycleInfoT = GenericCycleInfo<ContextT>;
  45. using CycleT = typename CycleInfoT::CycleT;
  46. GenericUniformityInfo(FunctionT &F, const DominatorTreeT &DT,
  47. const CycleInfoT &CI,
  48. const TargetTransformInfo *TTI = nullptr);
  49. GenericUniformityInfo() = default;
  50. GenericUniformityInfo(GenericUniformityInfo &&) = default;
  51. GenericUniformityInfo &operator=(GenericUniformityInfo &&) = default;
  52. /// Whether any divergence was detected.
  53. bool hasDivergence() const;
  54. /// The GPU kernel this analysis result is for
  55. const FunctionT &getFunction() const { return *F; }
  56. /// Whether \p V is divergent at its definition.
  57. bool isDivergent(ConstValueRefT V) const;
  58. /// Whether \p V is uniform/non-divergent.
  59. bool isUniform(ConstValueRefT V) const { return !isDivergent(V); }
  60. bool hasDivergentTerminator(const BlockT &B);
  61. void print(raw_ostream &Out) const;
  62. private:
  63. using ImplT = GenericUniformityAnalysisImpl<ContextT>;
  64. FunctionT *F;
  65. std::unique_ptr<ImplT, GenericUniformityAnalysisImplDeleter<ImplT>> DA;
  66. GenericUniformityInfo(const GenericUniformityInfo &) = delete;
  67. GenericUniformityInfo &operator=(const GenericUniformityInfo &) = delete;
  68. };
  69. } // namespace llvm
  70. #endif // LLVM_ADT_GENERICUNIFORMITYINFO_H
  71. #ifdef __GNUC__
  72. #pragma GCC diagnostic pop
  73. #endif