Skip to content

Commit

Permalink
[llvm][Uniformity] provide overloads for Instruction* and Value*
Browse files Browse the repository at this point in the history
Uniformity analysis is mainly concerned with the uniformity of values. But it is
sometimes useful to ask if an instruction is uniform, for example, if the
instruction is a terminator. On LLVM IR, every Instruction is a Value, so the
queries like isUniform() need to be overloaded so that the most derived class
always wins.

Reviewed By: ruiling

Differential Revision: https://reviews.llvm.org/D144699
  • Loading branch information
ssahasra committed Feb 28, 2023
1 parent d162826 commit 3e03cd8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions llvm/include/llvm/ADT/GenericUniformityImpl.h
Expand Up @@ -1264,6 +1264,11 @@ bool GenericUniformityInfo<ContextT>::isDivergent(ConstValueRefT V) const {
return DA->isDivergent(V);
}

template <typename ContextT>
bool GenericUniformityInfo<ContextT>::isDivergent(const InstructionT *I) const {
return DA->isDivergent(*I);
}

template <typename ContextT>
bool GenericUniformityInfo<ContextT>::hasDivergentTerminator(const BlockT &B) {
return DA->hasDivergentTerminator(B);
Expand Down
7 changes: 7 additions & 0 deletions llvm/include/llvm/ADT/GenericUniformityInfo.h
Expand Up @@ -62,6 +62,13 @@ template <typename ContextT> class GenericUniformityInfo {
/// Whether \p V is uniform/non-divergent.
bool isUniform(ConstValueRefT V) const { return !isDivergent(V); }

// Similar queries for InstructionT. These accept a pointer argument so that
// in LLVM IR, they overload the equivalent queries for Value*. For example,
// if querying whether a BranchInst is divergent, it should not be treated as
// a Value in LLVM IR.
bool isUniform(const InstructionT *I) const { return !isDivergent(I); };
bool isDivergent(const InstructionT *I) const;

bool hasDivergentTerminator(const BlockT &B);

void print(raw_ostream &Out) const;
Expand Down

0 comments on commit 3e03cd8

Please sign in to comment.