Skip to content

Commit b8e94a9

Browse files
bcheng0127igcbot
authored andcommitted
graph coloring compilation time optimization
graph coloring compilation time optimization
1 parent 1264337 commit b8e94a9

File tree

11 files changed

+270
-307
lines changed

11 files changed

+270
-307
lines changed

visa/BitSet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SPDX-License-Identifier: MIT
1313
#include <cstdlib>
1414
#include <cstring>
1515
#include <map>
16+
#include "llvm/ADT/SparseBitVector.h"
1617

1718
// Array-based bitset implementation where each element occupies a single bit.
1819
// Inside each array element, bits are stored and indexed from lsb to msb.
@@ -21,6 +22,8 @@ typedef unsigned int BITSET_ARRAY_TYPE;
2122
#define BIT(x) (((BITSET_ARRAY_TYPE)1) << x)
2223
#define NUM_BITS_PER_ELT (sizeof(BITSET_ARRAY_TYPE) * BITS_PER_BYTE)
2324

25+
typedef llvm::SparseBitVector<2048> llvm_SBitVector;
26+
2427
class BitSet {
2528
public:
2629
BitSet() : m_BitSetArray(nullptr), m_Size(0) {}

visa/DebugInfo.cpp

Lines changed: 39 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ void resetGenOffsets(G4_Kernel &kernel) {
15781578
void updateDebugInfo(G4_Kernel &kernel, G4_INST *inst,
15791579
const LivenessAnalysis &liveAnalysis,
15801580
const LiveRangeVec& lrs,
1581-
SparseBitSet &live, DebugInfoState *state,
1581+
llvm_SBitVector &live, DebugInfoState *state,
15821582
bool closeAllOpenIntervals) {
15831583
if (closeAllOpenIntervals && !state->getPrevInst())
15841584
return;
@@ -1588,79 +1588,59 @@ void updateDebugInfo(G4_Kernel &kernel, G4_INST *inst,
15881588
// Update live-intervals only when bits change in bit-vector.
15891589
// state parameter contains previous instruction and bit-vector.
15901590
for (unsigned int i = 0; i < liveAnalysis.getNumSelectedVar();
1591-
i += NUM_BITS_PER_ELT) {
1592-
auto elt = live.getElt(i / NUM_BITS_PER_ELT);
1593-
auto prevElt = state->getPrevBitset()
1594-
? state->getPrevBitset()->getElt(i / NUM_BITS_PER_ELT)
1595-
: 0;
1591+
i++) {
1592+
bool eltI = live.test(i);
1593+
bool prevEltI = state->getPrevBitset() ? state->getPrevBitset()->test(i) : false;
15961594

1597-
if (elt != prevElt) {
1595+
if (eltI && !prevEltI) {
15981596
// Some variables have changed state in bit-vector, so update their states
15991597
// accordingly.
16001598
//
16011599
// If elt is set and prevElt is reset, it means the variable became live
16021600
// at current inst, If elt is reset and prevElt is set, it means the
16031601
// variable was killed at current inst
16041602
//
1605-
for (unsigned int j = 0; j < NUM_BITS_PER_ELT; j++) {
1606-
unsigned char eltJ = (elt >> j) & 0x1;
1607-
unsigned char prevEltJ = (prevElt >> j) & 0x1;
1608-
1609-
if (eltJ == 1 && prevEltJ == 0) {
1610-
if (inst->getVISAId() != UNMAPPABLE_VISA_INDEX) {
1611-
// This check guarantees that for an open
1612-
// interval, at least the same CISA offset
1613-
// can be used to close it. If there is no
1614-
// instruction with valid CISA offset
1615-
// between open/close IR instruction, then
1616-
// the interval will not be recorded.
1617-
auto idx = (i + j);
1618-
G4_Declare *dcl = lrs[idx]->getVar()->getDeclare();
1619-
auto lr = krnlDbgInfo->getLiveIntervalInfo(dcl);
1620-
1621-
lr->setStateOpen(inst->getVISAId());
1622-
}
1623-
} else if (eltJ == 0 && prevEltJ == 1) {
1624-
auto idx = (i + j);
1625-
G4_Declare *dcl = lrs[idx]->getVar()->getDeclare();
1626-
1627-
auto lr = krnlDbgInfo->getLiveIntervalInfo(dcl);
1628-
1629-
if (lr->getState() ==
1630-
LiveIntervalInfo::DebugLiveIntervalState::Open) {
1631-
auto closeAt = state->getPrevInst()->getVISAId();
1632-
while (closeAt >= 1 && krnlDbgInfo->isMissingVISAId(closeAt - 1)) {
1633-
closeAt--;
1634-
}
1635-
lr->setStateClosed(closeAt);
1636-
}
1637-
}
1603+
if (inst->getVISAId() != UNMAPPABLE_VISA_INDEX) {
1604+
// This check guarantees that for an open
1605+
// interval, at least the same CISA offset
1606+
// can be used to close it. If there is no
1607+
// instruction with valid CISA offset
1608+
// between open/close IR instruction, then
1609+
// the interval will not be recorded.
1610+
G4_Declare *dcl = lrs[i]->getVar()->getDeclare();
1611+
auto lr = krnlDbgInfo->getLiveIntervalInfo(dcl);
1612+
1613+
lr->setStateOpen(inst->getVISAId());
16381614
}
1639-
}
1615+
} else if (!eltI && prevEltI) {
1616+
G4_Declare *dcl = lrs[i]->getVar()->getDeclare();
16401617

1641-
if (closeAllOpenIntervals) {
1642-
for (unsigned int j = 0; j < NUM_BITS_PER_ELT; j++) {
1643-
unsigned char eltJ = (elt >> j) & 0x1;
1618+
auto lr = krnlDbgInfo->getLiveIntervalInfo(dcl);
16441619

1645-
if (eltJ) {
1646-
auto idx = (i + j);
1647-
G4_Declare *dcl = lrs[idx]->getVar()->getDeclare();
1648-
auto lr = krnlDbgInfo->getLiveIntervalInfo(dcl);
1620+
if (lr->getState() == LiveIntervalInfo::DebugLiveIntervalState::Open) {
1621+
auto closeAt = state->getPrevInst()->getVISAId();
1622+
while (closeAt >= 1 && krnlDbgInfo->isMissingVISAId(closeAt - 1)) {
1623+
closeAt--;
1624+
}
1625+
lr->setStateClosed(closeAt);
1626+
}
1627+
}
16491628

1650-
if (lr->getState() ==
1651-
LiveIntervalInfo::DebugLiveIntervalState::Open) {
1652-
uint32_t lastCISAOff = (inst->getVISAId() != UNMAPPABLE_VISA_INDEX)
1653-
? inst->getVISAId()
1654-
: state->getPrevInst()->getVISAId();
1629+
if (closeAllOpenIntervals && eltI) {
1630+
G4_Declare *dcl = lrs[i]->getVar()->getDeclare();
1631+
auto lr = krnlDbgInfo->getLiveIntervalInfo(dcl);
16551632

1656-
while (lastCISAOff >= 1 &&
1657-
krnlDbgInfo->isMissingVISAId(lastCISAOff - 1)) {
1658-
lastCISAOff--;
1659-
}
1633+
if (lr->getState() == LiveIntervalInfo::DebugLiveIntervalState::Open) {
1634+
uint32_t lastCISAOff = (inst->getVISAId() != UNMAPPABLE_VISA_INDEX)
1635+
? inst->getVISAId()
1636+
: state->getPrevInst()->getVISAId();
16601637

1661-
lr->setStateClosed(lastCISAOff);
1662-
}
1638+
while (lastCISAOff >= 1 &&
1639+
krnlDbgInfo->isMissingVISAId(lastCISAOff - 1)) {
1640+
lastCISAOff--;
16631641
}
1642+
1643+
lr->setStateClosed(lastCISAOff);
16641644
}
16651645
}
16661646
}

visa/DebugInfo.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void addCallFrameInfo(VISAKernelImpl *kernel);
6868
// For ranges colored during graph coloring
6969
void updateDebugInfo(vISA::G4_Kernel &kernel, vISA::G4_INST *inst,
7070
const vISA::LivenessAnalysis &liveAnalysis,
71-
const LiveRangeVec& lrs, SparseBitSet &live,
71+
const LiveRangeVec& lrs, llvm_SBitVector &live,
7272
vISA::DebugInfoState *state, bool closeAllOpenIntervals);
7373
// For ranges allocated by local RA
7474
void updateDebugInfo(vISA::G4_Kernel &kernel,
@@ -450,22 +450,22 @@ class DbgDecoder {
450450
class DebugInfoState {
451451
// Class used to store state during RA.
452452
public:
453-
void setPrevBitset(const SparseBitSet &b) { prevBitset = b; }
453+
void setPrevBitset(const llvm_SBitVector &b) { prevBitset = b; }
454454
void setPrevInst(G4_INST *i) {
455455
if (i->getVISAId() != UNMAPPABLE_VISA_INDEX) {
456456
prevInst = i;
457457
}
458458
}
459459

460-
SparseBitSet *getPrevBitset() {
461-
if (prevBitset.getSize() == 0)
460+
llvm_SBitVector *getPrevBitset() {
461+
if (prevBitset.empty())
462462
return nullptr;
463463
return &prevBitset;
464464
}
465465
G4_INST *getPrevInst() { return prevInst; }
466466

467467
private:
468-
SparseBitSet prevBitset;
468+
llvm_SBitVector prevBitset;
469469
G4_INST *prevInst = nullptr;
470470
};
471471
} // namespace vISA

0 commit comments

Comments
 (0)