5151#include " llvm/ADT/SmallPtrSet.h"
5252#include " llvm/ADT/SparseBitVector.h"
5353#include " llvm/ADT/StringExtras.h"
54+ #include " llvm/CodeGen/MachineInstr.h"
5455#include " llvm/Support/raw_ostream.h"
5556
5657#define DEBUG_TYPE " uniformity"
@@ -342,6 +343,9 @@ template <typename ContextT> class GenericUniformityAnalysisImpl {
342343 typename SyncDependenceAnalysisT::DivergenceDescriptor;
343344 using BlockLabelMapT = typename SyncDependenceAnalysisT::BlockLabelMap;
344345
346+ using TemporalDivergenceTuple =
347+ std::tuple<ConstValueRefT, InstructionT *, const CycleT *>;
348+
345349 GenericUniformityAnalysisImpl (const DominatorTreeT &DT, const CycleInfoT &CI,
346350 const TargetTransformInfo *TTI)
347351 : Context(CI.getSSAContext()), F(*Context.getFunction()), CI(CI),
@@ -396,6 +400,11 @@ template <typename ContextT> class GenericUniformityAnalysisImpl {
396400
397401 void print (raw_ostream &out) const ;
398402
403+ SmallVector<TemporalDivergenceTuple, 8 > TemporalDivergenceList;
404+
405+ void recordTemporalDivergence (ConstValueRefT, const InstructionT *,
406+ const CycleT *);
407+
399408protected:
400409 // / \brief Value/block pair representing a single phi input.
401410 struct PhiInput {
@@ -1129,6 +1138,13 @@ void GenericUniformityAnalysisImpl<ContextT>::compute() {
11291138 }
11301139}
11311140
1141+ template <typename ContextT>
1142+ void GenericUniformityAnalysisImpl<ContextT>::recordTemporalDivergence(
1143+ ConstValueRefT Val, const InstructionT *User, const CycleT *Cycle) {
1144+ TemporalDivergenceList.emplace_back (Val, const_cast <InstructionT *>(User),
1145+ Cycle);
1146+ }
1147+
11321148template <typename ContextT>
11331149bool GenericUniformityAnalysisImpl<ContextT>::isAlwaysUniform(
11341150 const InstructionT &Instr) const {
@@ -1146,6 +1162,12 @@ template <typename ContextT>
11461162void GenericUniformityAnalysisImpl<ContextT>::print(raw_ostream &OS) const {
11471163 bool haveDivergentArgs = false ;
11481164
1165+ // When we print Value, LLVM IR instruction, we want to print extra new line.
1166+ // In LLVM IR print function for Value does not print new line at the end.
1167+ // In MIR print for MachineInstr prints new line at the end.
1168+ constexpr bool IsMIR = std::is_same<InstructionT, MachineInstr>::value;
1169+ std::string NewLine = IsMIR ? " " : " \n " ;
1170+
11491171 // Control flow instructions may be divergent even if their inputs are
11501172 // uniform. Thus, although exceedingly rare, it is possible to have a program
11511173 // with no divergent values but with divergent control structures.
@@ -1180,6 +1202,16 @@ void GenericUniformityAnalysisImpl<ContextT>::print(raw_ostream &OS) const {
11801202 }
11811203 }
11821204
1205+ if (!TemporalDivergenceList.empty ()) {
1206+ OS << " \n TEMPORAL DIVERGENCE LIST:\n " ;
1207+
1208+ for (auto [Val, UseInst, Cycle] : TemporalDivergenceList) {
1209+ OS << " Value :" << Context.print (Val) << NewLine
1210+ << " Used by :" << Context.print (UseInst) << NewLine
1211+ << " Outside cycle :" << Cycle->print (Context) << " \n\n " ;
1212+ }
1213+ }
1214+
11831215 for (auto &block : F) {
11841216 OS << " \n BLOCK " << Context.print (&block) << ' \n ' ;
11851217
@@ -1191,7 +1223,7 @@ void GenericUniformityAnalysisImpl<ContextT>::print(raw_ostream &OS) const {
11911223 OS << " DIVERGENT: " ;
11921224 else
11931225 OS << " " ;
1194- OS << Context.print (value) << ' \n ' ;
1226+ OS << Context.print (value) << NewLine ;
11951227 }
11961228
11971229 OS << " TERMINATORS\n " ;
@@ -1203,13 +1235,21 @@ void GenericUniformityAnalysisImpl<ContextT>::print(raw_ostream &OS) const {
12031235 OS << " DIVERGENT: " ;
12041236 else
12051237 OS << " " ;
1206- OS << Context.print (T) << ' \n ' ;
1238+ OS << Context.print (T) << NewLine ;
12071239 }
12081240
12091241 OS << " END BLOCK\n " ;
12101242 }
12111243}
12121244
1245+ template <typename ContextT>
1246+ iterator_range<
1247+ typename GenericUniformityInfo<ContextT>::TemporalDivergenceTuple *>
1248+ GenericUniformityInfo<ContextT>::getTemporalDivergenceList() const {
1249+ return make_range (DA->TemporalDivergenceList .begin (),
1250+ DA->TemporalDivergenceList .end ());
1251+ }
1252+
12131253template <typename ContextT>
12141254bool GenericUniformityInfo<ContextT>::hasDivergence() const {
12151255 return DA->hasDivergence ();
0 commit comments