From 343013538f72f2202338f57161c0bd92344ca407 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Sat, 1 Sep 2007 02:03:17 +0000 Subject: [PATCH] More tweaks to improve compile time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41669 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/LiveInterval.cpp | 57 +++++++++++++++--------- lib/CodeGen/SimpleRegisterCoalescing.cpp | 40 +++++++++-------- 2 files changed, 56 insertions(+), 41 deletions(-) diff --git a/lib/CodeGen/LiveInterval.cpp b/lib/CodeGen/LiveInterval.cpp index c9e98bc42a6..53ffbe3fca4 100644 --- a/lib/CodeGen/LiveInterval.cpp +++ b/lib/CodeGen/LiveInterval.cpp @@ -288,26 +288,24 @@ LiveInterval::FindLiveRangeContaining(unsigned Idx) { void LiveInterval::join(LiveInterval &Other, int *LHSValNoAssignments, int *RHSValNoAssignments, SmallVector &NewVNInfo) { - - // There might be some dead val#, create VNInfo for them. - for (unsigned i = 0, e = NewVNInfo.size(); i != e; ++i) { - VNInfo *VNI = NewVNInfo[i]; - if (!VNI) { - VNI = new VNInfo(this, i, ~1U, 0); - NewVNInfo[i] = VNI; - } - } - // Determine if any of our live range values are mapped. This is uncommon, so - // we want to avoid the interval scan if not. + // we want to avoid the interval scan if not. bool MustMapCurValNos = false; - for (vni_iterator i = vni_begin(), e = vni_end(); i != e; ++i) { - VNInfo *VNI = *i; - unsigned VN = VNI->id; - if (VNI->def == ~1U) continue; // tombstone value # - if (VNI != NewVNInfo[LHSValNoAssignments[VN]]) { + unsigned NumVals = getNumValNums(); + unsigned NumNewVals = NewVNInfo.size(); + for (unsigned i = 0; i != NumVals; ++i) { + unsigned LHSValID = LHSValNoAssignments[i]; + if (i != LHSValID || + (NewVNInfo[LHSValID] && NewVNInfo[LHSValID]->parent != this)) MustMapCurValNos = true; - break; + + // There might be some dead val#, create VNInfo for them. + if (i < NumNewVals) { + VNInfo *VNI = NewVNInfo[i]; + if (!VNI) { + VNI = new VNInfo(this, i, ~1U, 0); + NewVNInfo[i] = VNI; + } } } @@ -342,19 +340,34 @@ void LiveInterval::join(LiveInterval &Other, int *LHSValNoAssignments, } // Remember assignements because val# ids are changing. - std::vector OtherAssignments; + SmallVector OtherAssignments; for (iterator I = Other.begin(), E = Other.end(); I != E; ++I) OtherAssignments.push_back(RHSValNoAssignments[I->valno->id]); // Update val# info. Renumber them and make sure they all belong to this // LiveInterval now. - valnos.clear(); - for (unsigned i = 0, e = NewVNInfo.size(); i != e; ++i) { + for (unsigned i = 0; i != NumVals; ++i) { + if (i == NumNewVals) + break; VNInfo *VNI = NewVNInfo[i]; - VNI->parent = this; - VNI->id = i; // Renumber val#. + if (VNI->parent != this || VNI->id != i) { + VNI->parent = this; + VNI->id = i; // Renumber val#. + valnos[i] = VNI; + } + } + for (unsigned i = NumVals; i < NumNewVals; ++i) { + VNInfo *VNI = NewVNInfo[i]; + if (!VNI) + VNI = new VNInfo(this, i, ~1U, 0); + else { + VNI->parent = this; + VNI->id = i; // Renumber val#. + } valnos.push_back(VNI); } + if (NumNewVals < NumVals) + valnos.resize(NumNewVals); // shrinkify // Okay, now insert the RHS live ranges into the LHS. iterator InsertPos = begin(); diff --git a/lib/CodeGen/SimpleRegisterCoalescing.cpp b/lib/CodeGen/SimpleRegisterCoalescing.cpp index 052573a35c4..03e416b2606 100644 --- a/lib/CodeGen/SimpleRegisterCoalescing.cpp +++ b/lib/CodeGen/SimpleRegisterCoalescing.cpp @@ -682,8 +682,9 @@ bool SimpleRegisterCoalescing::JoinIntervals(LiveInterval &LHS, assert(RHSValID != -1 && "Didn't find value #?"); RHSValNoAssignments[0] = RHSValID; if (RHSVal0DefinedFromLHS != -1) { - RHSValsDefinedFromLHS[RHSValNoInfo0] = - LHS.getLiveRangeContaining(RHSValNoInfo0->def-1)->valno; + // This path doesn't go through ComputeUltimateVN so just set + // it to anything. + RHSValsDefinedFromLHS[RHSValNoInfo0] = (VNInfo*)1; } } else { // Loop over the value numbers of the LHS, seeing if any are defined from @@ -798,31 +799,32 @@ bool SimpleRegisterCoalescing::JoinIntervals(LiveInterval &LHS, } } - // Update kill info. Some live ranges are extended due to copy coalescing. - for (DenseMap::iterator I = RHSValsDefinedFromLHS.begin(), - E = RHSValsDefinedFromLHS.end(); I != E; ++I) { - VNInfo *VNI = I->first; - unsigned RHSValID = RHSValNoAssignments[VNI->id]; - LiveInterval::removeKill(*NewVNInfo[RHSValID], VNI->def); - LHS.addKills(*NewVNInfo[RHSValID], VNI->kills); - } - - for (DenseMap::iterator I = LHSValsDefinedFromRHS.begin(), - E = LHSValsDefinedFromRHS.end(); I != E; ++I) { - VNInfo *VNI = I->first; - unsigned LHSValID = LHSValNoAssignments[VNI->id]; - LiveInterval::removeKill(*NewVNInfo[LHSValID], VNI->def); - RHS.addKills(*NewVNInfo[LHSValID], VNI->kills); - } - // If we get here, we know that we can coalesce the live ranges. Ask the // intervals to coalesce themselves now. if ((RHS.ranges.size() > LHS.ranges.size() && MRegisterInfo::isVirtualRegister(LHS.reg)) || MRegisterInfo::isPhysicalRegister(RHS.reg)) { + // Update kill info. Some live ranges are extended due to copy coalescing. + for (DenseMap::iterator I = LHSValsDefinedFromRHS.begin(), + E = LHSValsDefinedFromRHS.end(); I != E; ++I) { + VNInfo *VNI = I->first; + unsigned LHSValID = LHSValNoAssignments[VNI->id]; + LiveInterval::removeKill(*NewVNInfo[LHSValID], VNI->def); + RHS.addKills(*NewVNInfo[LHSValID], VNI->kills); + } + RHS.join(LHS, &RHSValNoAssignments[0], &LHSValNoAssignments[0], NewVNInfo); Swapped = true; } else { + // Update kill info. Some live ranges are extended due to copy coalescing. + for (DenseMap::iterator I = RHSValsDefinedFromLHS.begin(), + E = RHSValsDefinedFromLHS.end(); I != E; ++I) { + VNInfo *VNI = I->first; + unsigned RHSValID = RHSValNoAssignments[VNI->id]; + LiveInterval::removeKill(*NewVNInfo[RHSValID], VNI->def); + LHS.addKills(*NewVNInfo[RHSValID], VNI->kills); + } + LHS.join(RHS, &LHSValNoAssignments[0], &RHSValNoAssignments[0], NewVNInfo); Swapped = false; }