LLVM 17.0.0git
GenericUniformityInfo.h
Go to the documentation of this file.
1//===- GenericUniformityInfo.h ---------------------------*- 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#ifndef LLVM_ADT_GENERICUNIFORMITYINFO_H
10#define LLVM_ADT_GENERICUNIFORMITYINFO_H
11
12// #include "llvm/ADT/DenseSet.h"
14// #include "llvm/ADT/SmallPtrSet.h"
15// #include "llvm/ADT/Uniformity.h"
16// #include "llvm/Analysis/LegacyDivergenceAnalysis.h"
18
19namespace llvm {
20
21class TargetTransformInfo;
22
23template <typename ContextT> class GenericUniformityAnalysisImpl;
24template <typename ImplT> struct GenericUniformityAnalysisImplDeleter {
25 // Ugly hack around the fact that recent (> 15.0) clang will run into an
26 // is_invocable() check in some GNU libc++'s unique_ptr implementation
27 // and reject this deleter if you just make it callable with an ImplT *,
28 // whether or not the type of ImplT is spelled out.
29 using pointer = ImplT *;
30 void operator()(ImplT *Impl);
31};
32
33template <typename ContextT> class GenericUniformityInfo {
34public:
35 using BlockT = typename ContextT::BlockT;
36 using FunctionT = typename ContextT::FunctionT;
37 using ValueRefT = typename ContextT::ValueRefT;
38 using ConstValueRefT = typename ContextT::ConstValueRefT;
39 using UseT = typename ContextT::UseT;
40 using InstructionT = typename ContextT::InstructionT;
41 using DominatorTreeT = typename ContextT::DominatorTreeT;
43
45 using CycleT = typename CycleInfoT::CycleT;
46
48 const CycleInfoT &CI,
49 const TargetTransformInfo *TTI = nullptr);
53
54 /// Whether any divergence was detected.
55 bool hasDivergence() const;
56
57 /// The GPU kernel this analysis result is for
58 const FunctionT &getFunction() const { return *F; }
59
60 /// Whether \p V is divergent at its definition.
61 bool isDivergent(ConstValueRefT V) const;
62
63 /// Whether \p V is uniform/non-divergent.
64 bool isUniform(ConstValueRefT V) const { return !isDivergent(V); }
65
66 // Similar queries for InstructionT. These accept a pointer argument so that
67 // in LLVM IR, they overload the equivalent queries for Value*. For example,
68 // if querying whether a BranchInst is divergent, it should not be treated as
69 // a Value in LLVM IR.
70 bool isUniform(const InstructionT *I) const { return !isDivergent(I); };
71 bool isDivergent(const InstructionT *I) const;
72
73 /// \brief Whether \p U is divergent. Uses of a uniform value can be
74 /// divergent.
75 bool isDivergentUse(const UseT &U) const;
76
77 bool hasDivergentTerminator(const BlockT &B);
78
79 void print(raw_ostream &Out) const;
80
81private:
83
84 FunctionT *F;
85 std::unique_ptr<ImplT, GenericUniformityAnalysisImplDeleter<ImplT>> DA;
86
89};
90
91} // namespace llvm
92
93#endif // LLVM_ADT_GENERICUNIFORMITYINFO_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Find all cycles in a control-flow graph, including irreducible loops.
#define I(x, y, z)
Definition: MD5.cpp:58
Cycle information for a function.
GenericCycle< ContextT > CycleT
Analysis that identifies uniform values in a data-parallel execution.
bool hasDivergentTerminator(const BlockT &B)
bool isDivergentUse(const UseT &U) const
Whether U is divergent.
typename ContextT::ValueRefT ValueRefT
const FunctionT & getFunction() const
The GPU kernel this analysis result is for.
typename ContextT::FunctionT FunctionT
bool isDivergent(ConstValueRefT V) const
Whether V is divergent at its definition.
void print(raw_ostream &Out) const
T helper function for printing.
bool isUniform(ConstValueRefT V) const
Whether V is uniform/non-divergent.
typename CycleInfoT::CycleT CycleT
bool isUniform(const InstructionT *I) const
typename ContextT::ConstValueRefT ConstValueRefT
typename ContextT::BlockT BlockT
typename ContextT::InstructionT InstructionT
typename ContextT::UseT UseT
bool hasDivergence() const
Whether any divergence was detected.
GenericUniformityInfo & operator=(GenericUniformityInfo &&)=default
typename ContextT::DominatorTreeT DominatorTreeT
GenericUniformityInfo(GenericUniformityInfo &&)=default
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18