@@ -401,7 +401,7 @@ namespace {
401
401
void applyCopiesOptimized ();
402
402
void applyCopiesForValue (const std::set<CopyData> &CDSet);
403
403
template <typename Iter>
404
- Iter mergeCopiesTillFailed (SimpleValue CopySV, Iter BeginIt , Iter EndIt);
404
+ LiveRange* mergeCopiesTillFailed (SimpleValue CopySV, Iter &It , Iter EndIt);
405
405
// Helpers
406
406
DominatorTree *getDomTree (Function *F) const {
407
407
return DTWrapper->getDomTree (F);
@@ -1930,15 +1930,14 @@ void GenXCoalescing::applyCopiesForValue(const std::set<CopyData> &CDSet) {
1930
1930
// is used to detect possible interference.
1931
1931
auto CopySV = SimpleValue (CurrCopy, Idx);
1932
1932
Liveness->removeValueNoDelete (CopySV);
1933
- auto *CopyLR = Liveness->buildLiveRange (CopySV);
1934
1933
auto *DestLR = Liveness->getLiveRange (DestSV);
1935
1934
1936
1935
LLVM_DEBUG (dbgs () << " Created copy for LR: " ; DestLR->print (dbgs ());
1937
1936
dbgs () << " \n Value that was copied: " ; SourceSV.print (dbgs ());
1938
1937
dbgs () << " \n Copy inst: " ; CopySV.print (dbgs ()); dbgs () << " \n " );
1939
1938
1940
1939
// Try to apply this copy in other copy candidates.
1941
- It = mergeCopiesTillFailed (CopySV, ++It, EndIt);
1940
+ auto *CopyLR = mergeCopiesTillFailed (CopySV, ++It, EndIt);
1942
1941
1943
1942
LLVM_DEBUG (dbgs () << " Finished processing all candidates for that copy\n " ;
1944
1943
dbgs () << " Final copy val LR: " ; CopyLR->print (dbgs ());
@@ -1962,26 +1961,26 @@ void GenXCoalescing::applyCopiesForValue(const std::set<CopyData> &CDSet) {
1962
1961
* For more details, check applyCopiesOptimized description.
1963
1962
*/
1964
1963
template <typename Iter>
1965
- Iter GenXCoalescing::mergeCopiesTillFailed (SimpleValue CopySV, Iter BeginIt,
1966
- Iter EndIt) {
1967
- if (BeginIt == EndIt)
1968
- return EndIt;
1969
-
1964
+ LiveRange *GenXCoalescing::mergeCopiesTillFailed (SimpleValue CopySV, Iter &It,
1965
+ Iter EndIt) {
1970
1966
auto *CopyLR = Liveness->buildLiveRange (CopySV);
1971
- auto *DestLR = Liveness->getLiveRange (BeginIt->Dest );
1967
+ if (It == EndIt)
1968
+ return CopyLR;
1969
+
1970
+ auto *DestLR = Liveness->getLiveRange (It->Dest );
1972
1971
Instruction *CurrCopy = cast<Instruction>(CopySV.getValue ());
1973
1972
1974
- for ( auto It = BeginIt; It != EndIt; ++It ) {
1973
+ while ( It != EndIt) {
1975
1974
// Interference detection
1976
1975
if (Liveness->interfere (DestLR, CopyLR)) {
1977
1976
LLVM_DEBUG (dbgs () << " Interference detected\n " );
1978
- return It ;
1977
+ return CopyLR ;
1979
1978
}
1980
1979
// Dominance detection
1981
1980
if (!getDomTree (CurrCopy->getFunction ())
1982
1981
->dominates (CurrCopy, cast<Instruction>(It->Dest .getValue ()))) {
1983
1982
LLVM_DEBUG (dbgs () << " Copy doesn't dominate user\n " );
1984
- return It ;
1983
+ return CopyLR ;
1985
1984
}
1986
1985
1987
1986
// Copy may be redundant. Check interference after copy applied.
@@ -1992,8 +1991,9 @@ Iter GenXCoalescing::mergeCopiesTillFailed(SimpleValue CopySV, Iter BeginIt,
1992
1991
if (It->Source .getValue ()->getType () == CurrCopy->getType ()) {
1993
1992
*It->UseInDest = CurrCopy;
1994
1993
} else {
1995
- IGC_ASSERT_MESSAGE (It->Source .getIndex () == 0 ,
1996
- " Must be non-aggregated type: should come from bitcast" );
1994
+ IGC_ASSERT_MESSAGE (
1995
+ It->Source .getIndex () == 0 ,
1996
+ " Must be non-aggregated type: should come from bitcast" );
1997
1997
IRBuilder<> Builder (CurrCopy->getNextNode ());
1998
1998
BCI = cast<BitCastInst>(Builder.CreateBitCast (
1999
1999
CurrCopy, It->Source .getValue ()->getType (), " red_copy_type_conv" ));
@@ -2004,23 +2004,23 @@ Iter GenXCoalescing::mergeCopiesTillFailed(SimpleValue CopySV, Iter BeginIt,
2004
2004
}
2005
2005
2006
2006
Liveness->rebuildLiveRange (CopyLR);
2007
- if (!Liveness->twoAddrInterfere (DestLR, CopyLR)) {
2008
- LLVM_DEBUG (dbgs () << " Success. Moving to next candidate\n " );
2009
- continue ;
2007
+ if (Liveness->twoAddrInterfere (DestLR, CopyLR)) {
2008
+ // Undo copy elimination
2009
+ LLVM_DEBUG (dbgs () << " Interference detected\n " );
2010
+ *It->UseInDest = OldValue;
2011
+ if (BCI) {
2012
+ Liveness->removeValue (BCI);
2013
+ BCI->eraseFromParent ();
2014
+ }
2015
+ Liveness->rebuildLiveRange (CopyLR);
2016
+ return CopyLR;
2010
2017
}
2011
2018
2012
- // Undo copy elimination
2013
- LLVM_DEBUG (dbgs () << " Interference detected\n " );
2014
- *It->UseInDest = OldValue;
2015
- if (BCI) {
2016
- Liveness->removeValue (BCI);
2017
- BCI->eraseFromParent ();
2018
- }
2019
- Liveness->rebuildLiveRange (CopyLR);
2020
- return It;
2019
+ LLVM_DEBUG (dbgs () << " Success. Moving to next candidate\n " );
2020
+ It++;
2021
2021
}
2022
2022
2023
- return EndIt ;
2023
+ return CopyLR ;
2024
2024
}
2025
2025
2026
2026
/* **********************************************************************
0 commit comments