From: Aiden Grossman Date: Mon, 12 Sep 2022 23:21:29 +0000 (+0000) Subject: [nfc] Refactor SlotIndex::getInstrDistance to better reflect actual functionality X-Git-Tag: upstream/17.0.6~33734 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eec183c171c271578ebd7ee35eafb5ef0ae29298;p=platform%2Fupstream%2Fllvm.git [nfc] Refactor SlotIndex::getInstrDistance to better reflect actual functionality This patch refactors SlotIndex::getInstrDistance to SlotIndex::getApproxInstrDistance to better describe the actual functionality of this function. This patch also adds in some additional comments better documenting the assumptions that this function makes to increase clarity. Based on discussion on the LLVM Discourse: https://discourse.llvm.org/t/odd-behavior-in-slotindex-getinstrdistance/64934/5 Reviewed By: mtrofin, foad Differential Revision: https://reviews.llvm.org/D133386 --- diff --git a/llvm/include/llvm/CodeGen/SlotIndexes.h b/llvm/include/llvm/CodeGen/SlotIndexes.h index 942a47c..5df6520 100644 --- a/llvm/include/llvm/CodeGen/SlotIndexes.h +++ b/llvm/include/llvm/CodeGen/SlotIndexes.h @@ -215,8 +215,12 @@ class raw_ostream; } /// Return the scaled distance from this index to the given one, where all - /// slots on the same instruction have zero distance. - int getInstrDistance(SlotIndex other) const { + /// slots on the same instruction have zero distance, assuming that the slot + /// indices are packed as densely as possible. There are normally gaps + /// between instructions, so this assumption often doesn't hold. This + /// results in this function often returning a value greater than the actual + /// instruction distance. + int getApproxInstrDistance(SlotIndex other) const { return (other.listEntry()->getIndex() - listEntry()->getIndex()) / Slot_Count; } diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp index 8c412b2..dd6e205 100644 --- a/llvm/lib/CodeGen/RegAllocGreedy.cpp +++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp @@ -330,12 +330,12 @@ unsigned DefaultPriorityAdvisor::getPriority(const LiveInterval &LI) const { // are singly defined, this produces optimal coloring in the absence of // global interference and other constraints. if (!ReverseLocalAssignment) - Prio = LI.beginIndex().getInstrDistance(Indexes->getLastIndex()); + Prio = LI.beginIndex().getApproxInstrDistance(Indexes->getLastIndex()); else { // Allocating bottom up may allow many short LRGs to be assigned first // to one of the cheap registers. This could be much faster for very // large blocks on targets with many physical registers. - Prio = Indexes->getZeroIndex().getInstrDistance(LI.endIndex()); + Prio = Indexes->getZeroIndex().getApproxInstrDistance(LI.endIndex()); } } else { // Allocate global and split ranges in long->short order. Long ranges that