llvm.org GIT mirror llvm / 2007298
Always compare the cost of region splitting with the cost of per-block splitting. Sometimes it is better to split per block, and we missed those cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130025 91177308-0d34-0410-b5e6-96231b3b80d8 Jakob Stoklund Olesen 9 years ago
1 changed file(s) with 45 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
174174 void LRE_WillShrinkVirtReg(unsigned);
175175 void LRE_DidCloneVirtReg(unsigned, unsigned);
176176
177 float calcSpillCost();
177178 bool addSplitConstraints(InterferenceCache::Cursor, float&);
178179 void addThroughConstraints(InterferenceCache::Cursor, ArrayRef);
179180 void growRegion(GlobalSplitCandidate &Cand, InterferenceCache::Cursor);
200201 } // end anonymous namespace
201202
202203 char RAGreedy::ID = 0;
204
205 // Hysteresis to use when comparing floats.
206 // This helps stabilize decisions based on float comparisons.
207 const float Hysteresis = 0.98f;
208
203209
204210 FunctionPass* llvm::createGreedyRegisterAllocator() {
205211 return new RAGreedy();
612618 SpillPlacer->iterate();
613619 }
614620 DEBUG(dbgs() << ", v=" << Visited);
621 }
622
623 /// calcSpillCost - Compute how expensive it would be to split the live range in
624 /// SA around all use blocks instead of forming bundle regions.
625 float RAGreedy::calcSpillCost() {
626 float Cost = 0;
627 const LiveInterval &LI = SA->getParent();
628 ArrayRef UseBlocks = SA->getUseBlocks();
629 for (unsigned i = 0; i != UseBlocks.size(); ++i) {
630 const SplitAnalysis::BlockInfo &BI = UseBlocks[i];
631 unsigned Number = BI.MBB->getNumber();
632 // We normally only need one spill instruction - a load or a store.
633 Cost += SpillPlacer->getBlockFrequency(Number);
634
635 // Unless the value is redefined in the block.
636 if (BI.LiveIn && BI.LiveOut) {
637 SlotIndex Start, Stop;
638 tie(Start, Stop) = Indexes->getMBBRange(Number);
639 LiveInterval::const_iterator I = LI.find(Start);
640 assert(I != LI.end() && "Expected live-in value");
641 // Is there a different live-out value? If so, we need an extra spill
642 // instruction.
643 if (I->end < Stop)
644 Cost += SpillPlacer->getBlockFrequency(Number);
645 }
646 }
647 return Cost;
615648 }
616649
617650 /// calcGlobalSplitCost - Return the global split cost of following the split
918951
919952 unsigned RAGreedy::tryRegionSplit(LiveInterval &VirtReg, AllocationOrder &Order,
920953 SmallVectorImpl &NewVRegs) {
921 float BestCost = 0;
954 float BestCost = Hysteresis * calcSpillCost();
955 DEBUG(dbgs() << "Cost of isolating all blocks = " << BestCost << '\n');
922956 const unsigned NoCand = ~0u;
923957 unsigned BestCand = NoCand;
924958
936970 continue;
937971 }
938972 DEBUG(dbgs() << PrintReg(PhysReg, TRI) << "\tstatic = " << Cost);
939 if (BestCand != NoCand && Cost >= BestCost) {
940 DEBUG(dbgs() << " worse than "
941 << PrintReg(GlobalCand[BestCand].PhysReg, TRI) << '\n');
973 if (Cost >= BestCost) {
974 DEBUG({
975 if (BestCand == NoCand)
976 dbgs() << " worse than no bundles\n";
977 else
978 dbgs() << " worse than "
979 << PrintReg(GlobalCand[BestCand].PhysReg, TRI) << '\n';
980 });
942981 continue;
943982 }
944983 growRegion(GlobalCand[Cand], Intf);
959998 dbgs() << " EB#" << i;
960999 dbgs() << ".\n";
9611000 });
962 if (BestCand == NoCand || Cost < BestCost) {
1001 if (Cost < BestCost) {
9631002 BestCand = Cand;
964 BestCost = 0.98f * Cost; // Prevent rounding effects.
1003 BestCost = Hysteresis * Cost; // Prevent rounding effects.
9651004 }
9661005 }
9671006