@@ -426,8 +426,8 @@ bool Dominator::dominates(G4_BB* bb1, G4_BB* bb2)
426
426
{
427
427
recomputeIfStale ();
428
428
429
- auto & dom = getDom (bb1 );
430
- if (dom.find (bb2 ) != dom.end ())
429
+ auto & dom = getDom (bb2 );
430
+ if (dom.find (bb1 ) != dom.end ())
431
431
return true ;
432
432
433
433
return false ;
@@ -663,6 +663,32 @@ std::vector<Loop*> vISA::LoopDetection::getTopLoops()
663
663
return topLoops;
664
664
}
665
665
666
+ Loop* Loop::getInnerMostLoop (const G4_BB* bb)
667
+ {
668
+ // if current loop contains bb, recurse loop tree and return
669
+ // most nested loop containing it.
670
+ // if current loop doesnt contain bb then return nullptr.
671
+ if (!contains (bb))
672
+ return nullptr ;
673
+
674
+ for (auto & nested : immNested)
675
+ if (auto innerMost = nested->getInnerMostLoop (bb))
676
+ return innerMost;
677
+
678
+ return this ;
679
+ }
680
+
681
+ Loop* LoopDetection::getInnerMostLoop (const G4_BB* bb)
682
+ {
683
+ recomputeIfStale ();
684
+
685
+ for (auto & loop : topLoops)
686
+ if (auto innerMost = loop->getInnerMostLoop (bb))
687
+ return innerMost;
688
+
689
+ return nullptr ;
690
+ }
691
+
666
692
void LoopDetection::reset ()
667
693
{
668
694
allLoops.clear ();
@@ -1016,7 +1042,126 @@ void Loop::dump(std::ostream& os)
1016
1042
}
1017
1043
}
1018
1044
1019
- bool vISA:: Loop::contains (const G4_BB* bb)
1045
+ bool Loop::contains (const G4_BB* bb)
1020
1046
{
1021
1047
return BBsLookup.find (bb) != BBsLookup.end ();
1022
1048
}
1049
+
1050
+ bool VarReferences::isUniqueDef (G4_DstRegRegion* dst)
1051
+ {
1052
+ recomputeIfStale ();
1053
+
1054
+ auto dcl = dst->getTopDcl ();
1055
+
1056
+ // return true if spilled variable has a single static def
1057
+ // and it is not live-in to current bb (eg, loop, sub).
1058
+ if (getDefCount (dcl) != 1 )
1059
+ {
1060
+ // check whether multiple defs exist in program for current
1061
+ // lb, rb
1062
+ auto lb = dst->getLeftBound ();
1063
+ auto rb = dst->getRightBound ();
1064
+
1065
+ unsigned int count = 0 ;
1066
+ const auto & defs = getDefs (dcl);
1067
+ for (auto & def : *defs)
1068
+ {
1069
+ if (std::get<2 >(def) <= rb &&
1070
+ std::get<3 >(def) >= lb)
1071
+ ++count;
1072
+ }
1073
+
1074
+ if (count > 1 )
1075
+ return false ;
1076
+ }
1077
+
1078
+ return true ;
1079
+ }
1080
+
1081
+ unsigned int VarReferences::getDefCount (G4_Declare* dcl)
1082
+ {
1083
+ auto defs = getDefs (dcl);
1084
+ if (defs)
1085
+ return defs->size ();
1086
+ return 0 ;
1087
+ }
1088
+
1089
+ const VarReferences::Defs* VarReferences::getDefs (G4_Declare* dcl)
1090
+ {
1091
+ recomputeIfStale ();
1092
+
1093
+ auto it = VarRefs.find (dcl);
1094
+ if (it != VarRefs.end ())
1095
+ return &(it->second .first );
1096
+
1097
+ return nullptr ;
1098
+ }
1099
+
1100
+ const VarReferences::Uses* VarReferences::getUses (G4_Declare* dcl)
1101
+ {
1102
+ recomputeIfStale ();
1103
+
1104
+ auto it = VarRefs.find (dcl);
1105
+ if (it != VarRefs.end ())
1106
+ return &(it->second .second );
1107
+
1108
+ return nullptr ;
1109
+ }
1110
+
1111
+ void VarReferences::reset ()
1112
+ {
1113
+ VarRefs.clear ();
1114
+
1115
+ setStale ();
1116
+ }
1117
+
1118
+ void VarReferences::run ()
1119
+ {
1120
+ for (auto bb : kernel.fg )
1121
+ {
1122
+ for (auto inst : *bb)
1123
+ {
1124
+ if (inst->isPseudoKill ())
1125
+ continue ;
1126
+
1127
+ auto dst = inst->getDst ();
1128
+
1129
+ if (dst && !dst->isNullReg ())
1130
+ {
1131
+ auto topdcl = dst->getTopDcl ();
1132
+
1133
+ if (topdcl)
1134
+ {
1135
+ auto lb = dst->getLeftBound ();
1136
+ auto rb = dst->getRightBound ();
1137
+ auto & Defs = VarRefs[topdcl].first ;
1138
+ Defs.push_back (std::make_tuple (inst, bb, lb, rb));
1139
+ }
1140
+ }
1141
+
1142
+ for (unsigned int i = 0 ; i != inst->getNumSrc (); ++i)
1143
+ {
1144
+ auto src = inst->getSrc (i);
1145
+ if (src && src->isSrcRegRegion ())
1146
+ {
1147
+ auto topdcl = src->asSrcRegRegion ()->getTopDcl ();
1148
+ if (topdcl)
1149
+ {
1150
+ auto & Uses = VarRefs[topdcl].second ;
1151
+ Uses.push_back (std::make_tuple (inst, bb));
1152
+ }
1153
+ }
1154
+ }
1155
+ }
1156
+ }
1157
+
1158
+ setValid ();
1159
+ }
1160
+
1161
+ void VarReferences::dump (std::ostream& os)
1162
+ {
1163
+ if (isStale ())
1164
+ os << " Data is stale.\n " ;
1165
+
1166
+ os << " #Dcls with defs/uses: " << VarRefs.size ();
1167
+ }
0 commit comments