Skip to content

Commit

Permalink
Make edgeWeightGRF faster
Browse files Browse the repository at this point in the history
edgeWeightGRF() is a hot method as per VTune profile. For large
tests with subroutines, the function consumed about 8% of total compile time.

In this change, we breakup edgeWeightGRF() method so that static version in header is devoid of direct memory accesses on objects and can be easily inlined in simplification phase.

This brings ~3% reduction in total compile time for large tests.
  • Loading branch information
pratikashar authored and igcbot committed Sep 27, 2023
1 parent b631cdd commit 26e89c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
23 changes: 8 additions & 15 deletions visa/GraphColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5360,12 +5360,17 @@ void GraphColor::computeSpillCosts(bool useSplitLLRHeuristic, const RPE *rpe) {
void GraphColor::relaxNeighborDegreeGRF(LiveRange *lr) {
if (!(lr->getIsPseudoNode()) && !(lr->getIsPartialDcl())) {
unsigned lr_id = lr->getVar()->getId();
bool lr2EvenAlign = gra.isEvenAligned(lr->getDcl());
unsigned lr2_nreg = lr->getNumRegNeeded();

// relax degree between 2 nodes
auto relaxDegree = [&](LiveRange *lr1) {
if (lr1->getActive() && !lr1->getIsPseudoNode() &&
!(lr1->getIsPartialDcl())) {
unsigned w = edgeWeightGRF(lr1, lr);
bool lr1EvenAlign = gra.isEvenAligned(lr1->getDcl());
unsigned lr1_nreg = lr1->getNumRegNeeded();
unsigned w =
edgeWeightGRF(lr1EvenAlign, lr2EvenAlign, lr1_nreg, lr2_nreg);
VISA_DEBUG_VERBOSE({
std::cout << "\t relax ";
lr1->dump();
Expand Down Expand Up @@ -10623,23 +10628,11 @@ void GlobalRA::insertRestoreAddr(G4_BB *bb) {
//
unsigned GraphColor::edgeWeightGRF(const LiveRange *lr1, const LiveRange *lr2) {
bool lr1EvenAlign = gra.isEvenAligned(lr1->getDcl());
bool lr2EvenAlign = gra.isEvenAligned(lr2->getDcl());
unsigned lr1_nreg = lr1->getNumRegNeeded();
unsigned lr2_nreg = lr2->getNumRegNeeded();

if (!lr1EvenAlign) {
return lr1_nreg + lr2_nreg - 1;
}

bool lr2EvenAlign = gra.isEvenAligned(lr2->getDcl());
if (!lr2EvenAlign) {
unsigned sum = lr1_nreg + lr2_nreg;
return sum + 1 - ((sum) % 2);
} else if (lr2EvenAlign) {
return lr1_nreg + lr2_nreg - 1 + (lr1_nreg % 2) + (lr2_nreg % 2);
} else {
vISA_ASSERT_UNREACHABLE("should be unreachable");
return 0;
}
return edgeWeightGRF(lr1EvenAlign, lr2EvenAlign, lr1_nreg, lr2_nreg);
}

unsigned GraphColor::edgeWeightARF(const LiveRange *lr1, const LiveRange *lr2) {
Expand Down
16 changes: 16 additions & 0 deletions visa/GraphColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,22 @@ class GraphColor {

unsigned edgeWeightGRF(const LiveRange *lr1, const LiveRange *lr2);
unsigned edgeWeightARF(const LiveRange *lr1, const LiveRange *lr2);
static unsigned edgeWeightGRF(bool lr1EvenAlign, bool lr2EvenAlign,
unsigned lr1_nreg, unsigned lr2_nreg) {
if (!lr1EvenAlign) {
return lr1_nreg + lr2_nreg - 1;
}

if (!lr2EvenAlign) {
unsigned sum = lr1_nreg + lr2_nreg;
return sum + 1 - ((sum) % 2);
} else if (lr2EvenAlign) {
return lr1_nreg + lr2_nreg - 1 + (lr1_nreg % 2) + (lr2_nreg % 2);
} else {
vISA_ASSERT_UNREACHABLE("should be unreachable");
return 0;
}
}

void computeDegreeForGRF();
void computeDegreeForARF();
Expand Down

0 comments on commit 26e89c1

Please sign in to comment.