Skip to content

Commit 6d806b9

Browse files
committed
Use TR_BitVector instead of CS2::ABitVector in TR_InterferenceGraph
Some of the largest symbols in the compiler obj files originates from TR_InterferenceGraph resulting from its use of CS2::ABitVector, while providing no real benefits in terms of capabilities or performance. Use of CS2::ABitVector has been replaced with TR_BitVector in TR_InterferenceGraph, which results in significant reduction in the size of the Compiler component's obj files, whether it is part of a standalone OMR build or part of a downstream project. Signed-off-by: Nazim Bhuiyan <nubhuiyan@ibm.com>
1 parent 3151719 commit 6d806b9

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

compiler/infra/InterferenceGraph.cpp

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2019 IBM Corp. and others
2+
* Copyright (c) 2000, 2020 IBM Corp. and others
33
*
44
* This program and the accompanying materials are made available under
55
* the terms of the Eclipse Public License 2.0 which accompanies this
@@ -225,50 +225,48 @@ void TR_InterferenceGraph::virtualRemoveNodeFromIG(TR_IGNode *igNode)
225225
// Partition the nodes identified by the 'workingSet' bit vector into sets
226226
// based on their degree.
227227
//
228-
void TR_InterferenceGraph::partitionNodesIntoDegreeSets(CS2::ABitVector<TR::Allocator> &workingSet,
229-
CS2::ABitVector<TR::Allocator> &colourableDegreeSet,
230-
CS2::ABitVector<TR::Allocator> &notColourableDegreeSet)
228+
void TR_InterferenceGraph::partitionNodesIntoDegreeSets(TR_BitVector *workingSet,
229+
TR_BitVector *colourableDegreeSet,
230+
TR_BitVector *notColourableDegreeSet)
231231
{
232232
int32_t i;
233-
CS2::ABitVector<TR::Allocator>::Cursor bvc(workingSet);
233+
TR_BitVectorIterator bvi(*workingSet);
234234

235235
TR_ASSERT(getNumColours() > 0,
236236
"can't partition without knowing the number of available colours\n");
237237

238238
// Empty the existing degree sets.
239239
//
240-
colourableDegreeSet.Clear();
241-
colourableDegreeSet.GrowTo(getNumColours());
242-
notColourableDegreeSet.Clear();
243-
notColourableDegreeSet.GrowTo(getNumColours());
240+
colourableDegreeSet->empty();
241+
notColourableDegreeSet->empty();
244242

245243
// Partition the specified nodes into sets based on their working degree.
246244
//
247-
for(bvc.SetToFirstOne(); bvc.Valid(); bvc.SetToNextOne())
248-
{
249-
i = bvc;
250-
251-
if (getNodeTable(i)->getWorkingDegree() < getNumColours())
252-
{
253-
colourableDegreeSet[i] = 1;
254-
}
255-
else
256-
{
257-
notColourableDegreeSet[i] = 1;
258-
}
259-
}
245+
while (bvi.hasMoreElements())
246+
{
247+
i = bvi.getNextElement();
248+
249+
if (getNodeTable(i)->getWorkingDegree() < getNumColours())
250+
{
251+
colourableDegreeSet->set(i);
252+
}
253+
else
254+
{
255+
notColourableDegreeSet->set(i);
256+
}
257+
}
260258

261259
#ifdef DEBUG
262260
if (debug("traceIG"))
263261
{
264262
diagnostic("\nPartitioned Nodes\n");
265263
diagnostic("-----------------\n");
266264

267-
diagnostic("\n[%4d] degree < %-10d : ", colourableDegreeSet.PopulationCount(), getNumColours());
268-
(*comp()) << colourableDegreeSet;
265+
diagnostic("\n[%4d] degree < %-10d : ", colourableDegreeSet->elementCount(), getNumColours());
266+
colourableDegreeSet->print(comp());
269267

270-
diagnostic("\n[%4d] degree < MAX_DEGREE : ", notColourableDegreeSet.PopulationCount());
271-
(*comp()) << notColourableDegreeSet;
268+
diagnostic("\n[%4d] degree < MAX_DEGREE : ", notColourableDegreeSet->elementCount());
269+
notColourableDegreeSet->print(comp());
272270
diagnostic("\n\n");
273271
}
274272
#endif
@@ -344,13 +342,11 @@ bool TR_InterferenceGraph::simplify()
344342

345343
if (getNumNodes()==0) return true;
346344

347-
CS2::ABitVector<TR::Allocator> workingSet(comp()->allocator());
348-
workingSet.SetAll(getNumNodes());
345+
TR_BitVector *workingSet = new (trStackMemory()) TR_BitVector(getNumNodes(), trMemory(), stackAlloc);
346+
workingSet->setAll(getNumNodes());
349347

350-
CS2::ABitVector<TR::Allocator> colourableDegreeSet(comp()->allocator());
351-
CS2::ABitVector<TR::Allocator> notColourableDegreeSet(comp()->allocator());
352-
colourableDegreeSet.GrowTo(getNumNodes());
353-
notColourableDegreeSet.GrowTo(getNumNodes());
348+
TR_BitVector * colourableDegreeSet = new (trStackMemory()) TR_BitVector(getNumNodes(), trMemory(), stackAlloc);
349+
TR_BitVector * notColourableDegreeSet = new (trStackMemory()) TR_BitVector(getNumNodes(), trMemory(), stackAlloc);
354350

355351
for (i=0; i<getNumNodes(); i++)
356352
{
@@ -360,20 +356,20 @@ bool TR_InterferenceGraph::simplify()
360356
igNode->setColour(UNCOLOURED);
361357
}
362358

363-
while (!workingSet.IsZero())
359+
while (!workingSet->isEmpty())
364360
{
365361
partitionNodesIntoDegreeSets(workingSet,colourableDegreeSet,notColourableDegreeSet);
366362

367363
// Push nodes from the colourable set onto the stack and adjust the degrees of
368364
// their neighbours until there are no nodes remaining in the colourable set.
369365
//
370-
if (!colourableDegreeSet.IsZero())
366+
if (!colourableDegreeSet->isEmpty())
371367
{
372-
CS2::ABitVector<TR::Allocator>::Cursor colourableCursor(colourableDegreeSet);
368+
TR_BitVectorIterator bvi(*colourableDegreeSet);
373369

374-
for(colourableCursor.SetToFirstOne(); colourableCursor.Valid(); colourableCursor.SetToNextOne())
370+
while (bvi.hasMoreElements())
375371
{
376-
igNode = getNodeTable(colourableCursor);
372+
igNode = getNodeTable(bvi.getNextElement());
377373

378374
if (debug("traceIG"))
379375
{
@@ -382,7 +378,7 @@ bool TR_InterferenceGraph::simplify()
382378
}
383379

384380
virtualRemoveNodeFromIG(igNode);
385-
workingSet[igNode->getIndex()] = 0;
381+
workingSet->reset(igNode->getIndex());
386382
getNodeStack()->push(igNode);
387383
}
388384

@@ -394,21 +390,22 @@ bool TR_InterferenceGraph::simplify()
394390
// There are no nodes left in the colourable set. Choose a spill candidate among nodes in
395391
// the non-colourable degree set.
396392
//
397-
TR_ASSERT(!notColourableDegreeSet.IsZero(),
393+
TR_ASSERT(!notColourableDegreeSet->isEmpty(),
398394
"not colourable set must contain at least one member\n");
399395

400-
CS2::ABitVector<TR::Allocator>::Cursor notColourableCursor(notColourableDegreeSet);
401-
if (!notColourableDegreeSet.IsZero())
396+
//CS2::ABitVector<TR::Allocator>::Cursor notColourableCursor(notColourableDegreeSet);
397+
TR_BitVectorIterator bvi;
398+
if (!notColourableDegreeSet->isEmpty())
402399
{
403400
// Choose the node from this degree set with the largest degree
404401
// and optimistically push it onto the stack.
405402
//
406403
int32_t degree = -1;
407404

408405
bestSpillNode = NULL;
409-
for(notColourableCursor.SetToFirstOne(); notColourableCursor.Valid(); notColourableCursor.SetToNextOne())
406+
while (bvi.hasMoreElements())
410407
{
411-
igNode = getNodeTable(notColourableCursor);
408+
igNode = getNodeTable(bvi.getNextElement());
412409
if (igNode->getDegree() > degree)
413410
{
414411
degree = igNode->getDegree();
@@ -419,7 +416,7 @@ bool TR_InterferenceGraph::simplify()
419416
TR_ASSERT(bestSpillNode, "Could not find a spill candidate.\n");
420417

421418
virtualRemoveNodeFromIG(bestSpillNode);
422-
workingSet[bestSpillNode->getIndex()] = 0;
419+
workingSet->reset(bestSpillNode->getIndex());
423420
getNodeStack()->push(bestSpillNode);
424421
}
425422
}
@@ -435,18 +432,16 @@ bool TR_InterferenceGraph::select()
435432
TR_IGNode *igNode;
436433
TR_BitVectorIterator bvi;
437434

438-
CS2::ABitVector<TR::Allocator> availableColours(comp()->allocator());
439-
CS2::ABitVector<TR::Allocator> assignedColours(comp()->allocator());
440-
availableColours.GrowTo(getNumColours());
441-
assignedColours.GrowTo(getNumColours());
435+
TR_BitVector *availableColours = new (trStackMemory()) TR_BitVector(getNumColours(), trMemory(), stackAlloc);
436+
TR_BitVector *assignedColours = new (trStackMemory()) TR_BitVector(getNumColours(), trMemory(), stackAlloc);
442437

443438
setNumberOfColoursUsedToColour(0);
444439

445440
while (!getNodeStack()->isEmpty())
446441
{
447442
igNode = getNodeStack()->pop();
448443

449-
availableColours.SetAll(getNumColours());
444+
availableColours->setAll(getNumColours());
450445

451446
ListIterator<TR_IGNode> iterator(&igNode->getAdjList());
452447
TR_IGNode *adjCursor = iterator.getFirst();
@@ -455,7 +450,7 @@ bool TR_InterferenceGraph::select()
455450
{
456451
if (adjCursor->getColour() != UNCOLOURED)
457452
{
458-
availableColours[adjCursor->getColour()] = 0;
453+
availableColours->reset(adjCursor->getColour());
459454
}
460455

461456
adjCursor = iterator.getNext();
@@ -464,16 +459,21 @@ bool TR_InterferenceGraph::select()
464459
if (debug("traceIG"))
465460
{
466461
diagnostic("SELECT: For IG node #%d (%p), available colours = ", igNode->getIndex(), igNode);
467-
(*comp()) << availableColours;
462+
availableColours->print(_compilation);
468463
diagnostic("\n");
469464
}
470465

471-
if (!availableColours.IsZero())
466+
bvi.setBitVector(*availableColours);
467+
468+
if (bvi.hasMoreElements())
472469
{
473-
IGNodeColour colour = (IGNodeColour)availableColours.FirstOne();
470+
IGNodeColour colour = (IGNodeColour)bvi.getNextElement();
474471
igNode->setColour(colour);
475472

476-
assignedColours[colour] = 1;
473+
if (!assignedColours->isSet(colour))
474+
{
475+
assignedColours->set(colour);
476+
}
477477

478478
if (debug("traceIG"))
479479
{
@@ -493,7 +493,7 @@ bool TR_InterferenceGraph::select()
493493
}
494494
}
495495

496-
setNumberOfColoursUsedToColour(assignedColours.PopulationCount());
496+
setNumberOfColoursUsedToColour(assignedColours->elementCount());
497497
return true;
498498
}
499499

compiler/infra/InterferenceGraph.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ class TR_InterferenceGraph : public TR_IGBase
7676
TR_StackMemory trStackMemory() { return _trMemory; }
7777
TR_HeapMemory trHeapMemory() { return _trMemory; }
7878

79-
void partitionNodesIntoDegreeSets(CS2::ABitVector<TR::Allocator> &workingSet,
80-
CS2::ABitVector<TR::Allocator> &colourableDegreeSet,
81-
CS2::ABitVector<TR::Allocator> &notColourableDegreeSet);
79+
void partitionNodesIntoDegreeSets(TR_BitVector *workingSet,
80+
TR_BitVector *colourableDegreeSet,
81+
TR_BitVector *notColourableDegreeSet);
8282

8383
TR::Compilation *_compilation;
8484
TR_Memory *_trMemory;

0 commit comments

Comments
 (0)