88
99#include " llvm/Analysis/UniformityAnalysis.h"
1010#include " llvm/ADT/GenericUniformityImpl.h"
11+ #include " llvm/ADT/Uniformity.h"
1112#include " llvm/Analysis/CycleAnalysis.h"
1213#include " llvm/Analysis/TargetTransformInfo.h"
1314#include " llvm/IR/Dominators.h"
@@ -29,25 +30,15 @@ bool llvm::GenericUniformityAnalysisImpl<SSAContext>::markDefsDivergent(
2930 return markDivergent (cast<Value>(&Instr));
3031}
3132
32- template <>
33- bool llvm::GenericUniformityAnalysisImpl<SSAContext>::isDivergentUse(
34- const Use &U) const {
35- const auto *V = U.get ();
36- if (isDivergent (V))
37- return true ;
38- if (const auto *DefInstr = dyn_cast<Instruction>(V)) {
39- const auto *UseInstr = cast<Instruction>(U.getUser ());
40- return isTemporalDivergent (*UseInstr->getParent (), *DefInstr);
41- }
42- return false ;
43- }
44-
4533template <> void llvm::GenericUniformityAnalysisImpl<SSAContext>::initialize() {
4634 for (auto &I : instructions (F)) {
4735 if (TTI->isSourceOfDivergence (&I))
4836 markDivergent (I);
4937 else if (TTI->isAlwaysUniform (&I))
5038 addUniformOverride (I);
39+ InstructionUniformity IU = TTI->getInstructionUniformity (I);
40+ if (IU != InstructionUniformity::Default)
41+ addUniformInstruction (&I, IU);
5142 }
5243 for (auto &Arg : F.args ()) {
5344 if (TTI->isSourceOfDivergence (&Arg)) {
@@ -101,6 +92,31 @@ void llvm::GenericUniformityAnalysisImpl<
10192 }
10293}
10394
95+ template <>
96+ bool llvm::GenericUniformityAnalysisImpl<SSAContext>::isDivergentUse(
97+ const Use &U) const {
98+ const auto *V = U.get ();
99+ if (isDivergent (V))
100+ return true ;
101+ if (const auto *DefInstr = dyn_cast<Instruction>(V)) {
102+ const auto *UseInstr = cast<Instruction>(U.getUser ());
103+ return isTemporalDivergent (*UseInstr->getParent (), *DefInstr);
104+ }
105+ return false ;
106+ }
107+
108+ template <>
109+ bool GenericUniformityAnalysisImpl<SSAContext>::isOperandUniform(
110+ const Instruction &I, InstructionUniformity IU) const {
111+ switch (IU) {
112+ case InstructionUniformity::EitherOfFirstTwoOp:
113+ return !isDivergentUse (I.getOperandUse (0 )) ||
114+ !isDivergentUse (I.getOperandUse (1 ));
115+ default :
116+ return false ;
117+ }
118+ }
119+
104120// This ensures explicit instantiation of
105121// GenericUniformityAnalysisImpl::ImplDeleter::operator()
106122template class llvm ::GenericUniformityInfo<SSAContext>;
0 commit comments