LLVM 24.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
14
15namespace llvm {
16
18
19template <typename ContextT> class GenericUniformityAnalysisImpl;
20template <typename ImplT> struct GenericUniformityAnalysisImplDeleter {
21 // Ugly hack around the fact that recent (> 15.0) clang will run into an
22 // is_invocable() check in some GNU libc++'s unique_ptr implementation
23 // and reject this deleter if you just make it callable with an ImplT *,
24 // whether or not the type of ImplT is spelled out.
25 using pointer = ImplT *;
26 void operator()(ImplT *Impl);
27};
28
29template <typename ContextT> class GenericUniformityInfo {
30public:
31 using BlockT = typename ContextT::BlockT;
32 using FunctionT = typename ContextT::FunctionT;
33 using ValueRefT = typename ContextT::ValueRefT;
34 using ConstValueRefT = typename ContextT::ConstValueRefT;
35 using UseT = typename ContextT::UseT;
36 using InstructionT = typename ContextT::InstructionT;
37 using DominatorTreeT = typename ContextT::DominatorTreeT;
39
41
43 std::tuple<ConstValueRefT, InstructionT *, CycleRef>;
44
46 const TargetTransformInfo *TTI = nullptr);
50
51 void compute() {
52 DA->initialize();
53 DA->compute();
54 }
55
56 /// The GPU kernel this analysis result is for
57 const FunctionT &getFunction() const;
58
59 /// The cycle info this analysis was computed with.
60 const CycleInfoT &getCycleInfo() const;
61
62 /// Whether \p V is divergent at its definition.
64
65 /// Whether \p V is uniform/non-divergent at its definition.
66 bool isUniformAtDef(ConstValueRefT V) const { return !isDivergentAtDef(V); }
67
68 // Whether the terminator instruction \p I is uniform/divergent, i.e. whether
69 // the controlling condition of a conditional branch or switch is
70 // uniform/divergent.
71 // TODO: The comment below is now out of date:
72 // These accept a pointer argument so that
73 // in LLVM IR, they overload the equivalent queries for Value*. For example,
74 // if querying whether a CondBrInst is divergent, it should not be treated as
75 // a Value in LLVM IR.
76 bool isUniformTerminator(const InstructionT *I) const {
77 return !isDivergentTerminator(I);
78 };
80
81 /// \brief Whether \p U is divergent at its use. Uses of a uniform value can
82 /// be divergent.
83 bool isDivergentAtUse(const UseT &U) const;
84
85 /// \brief Whether \p U is uniform/non-divergent at its use.
86 bool isUniformAtUse(const UseT &U) const { return !isDivergentAtUse(U); }
87
89
90 void print(raw_ostream &Out) const;
91
93
94private:
96
97 std::unique_ptr<ImplT, GenericUniformityAnalysisImplDeleter<ImplT>> DA;
98
101};
102
103} // namespace llvm
104
105#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:57
Cycle information for a function.
Analysis that identifies uniform values in a data-parallel execution.
bool isUniformAtUse(const UseT &U) const
Whether U is uniform/non-divergent at its use.
bool hasDivergentTerminator(const BlockT &B)
typename ContextT::ValueRefT ValueRefT
typename ContextT::FunctionT FunctionT
void print(raw_ostream &Out) const
T helper function for printing.
bool isDivergentAtDef(ConstValueRefT V) const
Whether V is divergent at its definition.
bool isUniformTerminator(const InstructionT *I) const
std::tuple< ConstValueRefT, InstructionT *, CycleRef > TemporalDivergenceTuple
typename ContextT::ConstValueRefT ConstValueRefT
typename ContextT::BlockT BlockT
bool isDivergentAtUse(const UseT &U) const
Whether U is divergent at its use.
const CycleInfoT & getCycleInfo() const
The cycle info this analysis was computed with.
typename ContextT::InstructionT InstructionT
GenericUniformityInfo & operator=(GenericUniformityInfo &&)=default
const FunctionT & getFunction() const
The GPU kernel this analysis result is for.
GenericUniformityInfo(const DominatorTreeT &DT, const CycleInfoT &CI, const TargetTransformInfo *TTI=nullptr)
bool isDivergentTerminator(const InstructionT *I) const
bool isUniformAtDef(ConstValueRefT V) const
Whether V is uniform/non-divergent at its definition.
GenericCycleInfo< ContextT > CycleInfoT
typename ContextT::DominatorTreeT DominatorTreeT
GenericUniformityInfo< ContextT > ThisT
iterator_range< TemporalDivergenceTuple * > getTemporalDivergenceList() const
GenericUniformityInfo(GenericUniformityInfo &&)=default
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
TargetTransformInfo TTI