@@ -2770,6 +2770,56 @@ void GlobalRA::getBankAlignment(LiveRange *lr, BankAlign &align) {
2770
2770
}
2771
2771
}
2772
2772
2773
+ // Compute homeFunc for dcl. Following rules are used:
2774
+ // 1. A variable that's defined or used in a single function has
2775
+ // that function as its home function.
2776
+ // 2. A variable that's defined or used across functions (eg,
2777
+ // args, retval) have their home function set to nullptr.
2778
+ // 3. homeFunc is set only on root G4_Declare.
2779
+ FuncInfo *Augmentation::computeHomeFunc (G4_Declare *dcl) {
2780
+ vISA_ASSERT (!dcl->getAliasDeclare (), " root dcl expected" );
2781
+ // If there are no subroutines then all dcls have kernel as home function
2782
+ if (!hasSubroutines)
2783
+ return kernel.fg .kernelInfo ;
2784
+
2785
+ if (hasUniqueFuncHome (dcl))
2786
+ return getUniqueFuncHome (dcl);
2787
+
2788
+ FuncInfo *homeFunction = nullptr ;
2789
+ // Live-ins to kernel are modeled as being implicitly defined in kernel.
2790
+ if (dcl->isInput ())
2791
+ homeFunction = kernel.fg .kernelInfo ;
2792
+ auto *defs = refs.getDefs (dcl);
2793
+ if (defs) {
2794
+ for (auto &def : *defs) {
2795
+ auto *bb = std::get<1 >(def);
2796
+ auto *curDefFunc = bbToFunc.at (bb);
2797
+ if (!homeFunction) {
2798
+ homeFunction = curDefFunc;
2799
+ continue ;
2800
+ } else if (homeFunction != curDefFunc) {
2801
+ return nullptr ;
2802
+ }
2803
+ }
2804
+ }
2805
+
2806
+ auto *uses = refs.getUses (dcl);
2807
+ if (uses) {
2808
+ for (auto &use : *uses) {
2809
+ auto *bb = std::get<1 >(use);
2810
+ auto *curUseFunc = bbToFunc.at (bb);
2811
+ if (!homeFunction) {
2812
+ homeFunction = curUseFunc;
2813
+ continue ;
2814
+ } else if (homeFunction != curUseFunc) {
2815
+ return nullptr ;
2816
+ }
2817
+ }
2818
+ }
2819
+
2820
+ return homeFunction;
2821
+ }
2822
+
2773
2823
void Augmentation::populateFuncMaps () {
2774
2824
vISA_ASSERT (kernel.fg .getBBList ().back ()->size () > 0 , " last BB empty" );
2775
2825
instToFunc.resize (kernel.fg .getBBList ().back ()->back ()->getLexicalId () + 1 );
@@ -2783,10 +2833,24 @@ void Augmentation::populateFuncMaps() {
2783
2833
}
2784
2834
}
2785
2835
2836
+ void Augmentation::populateHomeFunc () {
2837
+ // Assume last G4_Declare has max declId
2838
+ homeFunc.resize (kernel.Declares .back ()->getDeclId () + 1 );
2839
+ for (auto dcl : kernel.Declares ) {
2840
+ if (dcl->getAliasDeclare ())
2841
+ dcl = dcl->getRootDeclare ();
2842
+ auto *func = computeHomeFunc (dcl);
2843
+ vISA_ASSERT (!hasUniqueFuncHome (dcl) || getUniqueFuncHome (dcl) == func,
2844
+ " different home func set" );
2845
+ homeFunc[dcl->getDeclId ()] = func;
2846
+ }
2847
+ }
2848
+
2786
2849
Augmentation::Augmentation (Interference &i, const LivenessAnalysis &l,
2787
2850
GlobalRA &g)
2788
2851
: kernel(g.kernel), intf(i), gra(g), liveAnalysis(l), lrs(g.incRA.getLRs()),
2789
- fcallRetMap(g.fcallRetMap), refs(g.kernel, false , false , true ),
2852
+ fcallRetMap(g.fcallRetMap),
2853
+ refs(g.kernel, false , false , true , &g.pointsToAnalysis),
2790
2854
hasSubroutines(kernel.fg.sortedFuncTable.size() > 0 &&
2791
2855
g.kernel.getOption(vISA_NewAugmentation)) {
2792
2856
useGenericAugAlign =
@@ -3813,6 +3877,16 @@ void Augmentation::buildUnknownArgRetval() {
3813
3877
}
3814
3878
}
3815
3879
3880
+ bool Augmentation::hasUniqueFuncHome (G4_Declare *dcl) const {
3881
+ auto *homeFunction = homeFunc[dcl->getDeclId ()];
3882
+ return homeFunction != nullptr ;
3883
+ }
3884
+
3885
+ FuncInfo* Augmentation::getUniqueFuncHome (G4_Declare* dcl) const {
3886
+ vISA_ASSERT (hasUniqueFuncHome (dcl), " expecting unique home func" );
3887
+ return homeFunc[dcl->getDeclId ()];
3888
+ }
3889
+
3816
3890
void Augmentation::startIntervalForLiveIn (FuncInfo *funcInfo, G4_BB *bb) {
3817
3891
// Start live-in intervals
3818
3892
auto liveInBB = liveAnalysis.getLiveAtEntry (bb) & liveAnalysis.globalVars ;
@@ -3821,6 +3895,9 @@ void Augmentation::startIntervalForLiveIn(FuncInfo *funcInfo, G4_BB *bb) {
3821
3895
if (isUnknownArgOrRetval (dcl))
3822
3896
continue ;
3823
3897
3898
+ if (hasUniqueFuncHome (dcl) && getUniqueFuncHome (dcl) != funcInfo)
3899
+ continue ;
3900
+
3824
3901
vISA_ASSERT (bb->size () > 0 , " empty instlist" );
3825
3902
vISA_ASSERT (funcInfo == kernel.fg .kernelInfo ||
3826
3903
argsPerSub.count (funcInfo) > 0 ||
@@ -4022,7 +4099,7 @@ void Augmentation::handlePred(FuncInfo* funcInfo, G4_INST *inst) {
4022
4099
}
4023
4100
}
4024
4101
4025
- void Augmentation::endIntervalForLiveOut (G4_BB *bb) {
4102
+ void Augmentation::endIntervalForLiveOut (FuncInfo* funcInfo, G4_BB *bb) {
4026
4103
auto liveOutBB = liveAnalysis.getLiveAtExit (bb) & liveAnalysis.globalVars ;
4027
4104
if (bb->isEndWithCall () && liveAnalysis.livenessClass (G4_GRF)) {
4028
4105
// reset bit for RET__loc as we handle it specially later to
@@ -4050,6 +4127,10 @@ void Augmentation::endIntervalForLiveOut(G4_BB *bb) {
4050
4127
G4_Declare *dcl = lrs[i]->getDcl ()->getRootDeclare ();
4051
4128
if (isUnknownArgOrRetval (dcl))
4052
4129
continue ;
4130
+
4131
+ if (hasUniqueFuncHome (dcl) && getUniqueFuncHome (dcl) != funcInfo)
4132
+ continue ;
4133
+
4053
4134
vISA_ASSERT (bb->size () > 0 , " empty instlist" );
4054
4135
updateEndInterval (dcl, bb->back ());
4055
4136
}
@@ -4079,7 +4160,7 @@ void Augmentation::handleNonReducibleExtension(FuncInfo *funcInfo) {
4079
4160
}
4080
4161
}
4081
4162
for (auto exitBB : SCCSucc) {
4082
- extendVarLiveness (exitBB, headBB->front ());
4163
+ extendVarLiveness (funcInfo, exitBB, headBB->front ());
4083
4164
}
4084
4165
}
4085
4166
}
@@ -4118,7 +4199,7 @@ void Augmentation::handleLoopExtension(FuncInfo *funcInfo) {
4118
4199
std::cout << " ==> Extend live-in for BB" << exitBB->getId () << " \n " ;
4119
4200
exitBB->emit (std::cout);
4120
4201
});
4121
- extendVarLiveness (exitBB, startInst);
4202
+ extendVarLiveness (funcInfo, exitBB, startInst);
4122
4203
}
4123
4204
}
4124
4205
}
@@ -4133,6 +4214,10 @@ void Augmentation::handleLoopExtension(FuncInfo *funcInfo) {
4133
4214
4134
4215
for (auto i : globalsLiveInAndLiveOut) {
4135
4216
auto *dcl = lrs[i]->getDcl ()->getRootDeclare ();
4217
+ // If dcl has non-nullptr home function then extend liveness only
4218
+ // in same function.
4219
+ if (hasUniqueFuncHome (dcl) && getUniqueFuncHome (dcl) != funcInfo)
4220
+ continue ;
4136
4221
4137
4222
updateEndInterval (dcl, endBB->back ());
4138
4223
VISA_DEBUG_VERBOSE ({
@@ -4150,11 +4235,16 @@ void Augmentation::handleLoopExtension(FuncInfo *funcInfo) {
4150
4235
}
4151
4236
4152
4237
// Extend all variables that are live at bb entry to the given inst
4153
- void Augmentation::extendVarLiveness (G4_BB *bb, G4_INST *inst) {
4238
+ void Augmentation::extendVarLiveness (FuncInfo *funcInfo, G4_BB *bb,
4239
+ G4_INST *inst) {
4154
4240
auto liveAtEntryBB =
4155
4241
liveAnalysis.getLiveAtEntry (bb) & liveAnalysis.globalVars ;
4156
4242
for (auto i : liveAtEntryBB) {
4157
4243
G4_Declare *dcl = lrs[i]->getDcl ()->getRootDeclare ();
4244
+ // If dcl has non-nullptr home function then extend liveness only
4245
+ // in same function.
4246
+ if (hasUniqueFuncHome (dcl) && getUniqueFuncHome (dcl) != funcInfo)
4247
+ continue ;
4158
4248
4159
4249
if (!kernel.fg .isPseudoDcl (dcl)) {
4160
4250
// Extend ith live-interval
@@ -4181,7 +4271,7 @@ void Augmentation::buildLiveIntervals(FuncInfo* funcInfo) {
4181
4271
for (G4_BB *curBB : funcInfo->getBBList ()) {
4182
4272
if (!curBB->empty ()) {
4183
4273
startIntervalForLiveIn (funcInfo, curBB);
4184
- endIntervalForLiveOut (curBB);
4274
+ endIntervalForLiveOut (funcInfo, curBB);
4185
4275
}
4186
4276
4187
4277
for (G4_INST *inst : *curBB) {
@@ -5041,6 +5131,8 @@ void Augmentation::discoverRetVal(FuncInfo *func) {
5041
5131
retValPerSub[func].insert (dcl);
5042
5132
if (retValInfo.subroutines .size () > 1 )
5043
5133
retValInfo.retValType = RetValType::Unknown;
5134
+ vISA_ASSERT (!hasUniqueFuncHome (dcl),
5135
+ " retval cannot have non-nullptr home function" );
5044
5136
}
5045
5137
5046
5138
if (kernel.getOption (vISA_VerifyAugmentation)) {
@@ -5057,7 +5149,8 @@ void Augmentation::discoverArgs(FuncInfo *func) {
5057
5149
5058
5150
SparseBitVector subArgs;
5059
5151
if (func == kernel.fg .kernelInfo )
5060
- subArgs = liveAnalysis.use_in [kernel.fg .getEntryBB ()->getId ()];
5152
+ subArgs = liveAnalysis.use_in [kernel.fg .getEntryBB ()->getId ()] &
5153
+ liveAnalysis.def_in [kernel.fg .getEntryBB ()->getId ()];
5061
5154
else
5062
5155
subArgs = liveAnalysis.args .at (func);
5063
5156
@@ -5074,6 +5167,10 @@ void Augmentation::discoverArgs(FuncInfo *func) {
5074
5167
if (argInfo.subroutines .size () > 1 &&
5075
5168
argInfo.argType == ArgType::DefBeforeEachCall)
5076
5169
argInfo.argType = ArgType::Unknown;
5170
+ vISA_ASSERT (
5171
+ argInfo.argType != ArgType::DefBeforeEachCall ||
5172
+ !hasUniqueFuncHome (dcl),
5173
+ " def before each call arg cannot have non-nullptr home function" );
5077
5174
}
5078
5175
5079
5176
@@ -5113,6 +5210,16 @@ void Augmentation::dumpSortedIntervals() {
5113
5210
std::cout << " (LiveThroughArg)" ;
5114
5211
else if (isRegularRetVal (dcl))
5115
5212
std::cout << " (RegularRetVal)" ;
5213
+ if (dcl->getDeclId () >= homeFunc.size ()) {
5214
+ std::cout << " @ (new var)" ;
5215
+ }
5216
+ else {
5217
+ auto *homeFunction = homeFunc[dcl->getDeclId ()];
5218
+ if (!homeFunction)
5219
+ std::cout << " @ (global)" ;
5220
+ else
5221
+ std::cout << " @ (func " << (int )homeFunction->getId () << " )" ;
5222
+ }
5116
5223
std::cout << " - (" << gra.getIntervalStart (interval)->getLexicalId ()
5117
5224
<< " , " << gra.getIntervalEnd (interval)->getLexicalId () << " ]" ;
5118
5225
if (intervalsPerVar[dcl].size () > 1 ) {
@@ -5572,16 +5679,17 @@ void Augmentation::augmentIntfGraph() {
5572
5679
bool nonDefaultMaskDef = markNonDefaultMaskDef ();
5573
5680
5574
5681
if (nonDefaultMaskDef == true ) {
5575
- if (augWithHoles && kernel.fg .getNumFuncs () > 0 )
5576
- populateFuncMaps ();
5577
-
5578
5682
if (augWithHoles) {
5683
+ if (kernel.fg .getNumFuncs () > 0 )
5684
+ populateFuncMaps ();
5685
+
5686
+ populateHomeFunc ();
5687
+
5579
5688
// Atleast one definition with non-default mask was found so
5580
5689
// perform steps to augment intf graph with such defs
5581
5690
5582
5691
// Discover and store subroutine arguments
5583
5692
if (hasSubroutines) {
5584
-
5585
5693
for (auto &subroutine : kernel.fg .sortedFuncTable ) {
5586
5694
discoverArgs (subroutine);
5587
5695
discoverRetVal (subroutine);
0 commit comments