Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 6aa9823

Browse files
committed
Track actual SSA memory usage
Currently SsaBuilder use comp->getAllocator() in a lot of places so a lot of the memory it allocates lands in CMK_Generic instead of CMK_SSA. Same for CopyProp phase.
1 parent 63e363c commit 6aa9823

File tree

5 files changed

+45
-76
lines changed

5 files changed

+45
-76
lines changed

src/jit/compmemkind.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ CompMemKindMacro(LoopOpt)
5252
CompMemKindMacro(LoopHoist)
5353
CompMemKindMacro(Unknown)
5454
CompMemKindMacro(RangeCheck)
55+
CompMemKindMacro(CopyProp)
5556
//clang-format on
5657

5758
#undef CompMemKindMacro

src/jit/copyprop.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ void Compiler::optBlockCopyProp(BasicBlock* block, LclNumToGenTreePtrStack* curS
348348
GenTreePtrStack* stack;
349349
if (!curSsaName->Lookup(lclNum, &stack))
350350
{
351-
stack = new (getAllocator()) GenTreePtrStack(this);
351+
stack = new (curSsaName->GetAllocator()) GenTreePtrStack(this);
352352
}
353353
stack->Push(tree);
354354
curSsaName->Set(lclNum, stack);
@@ -361,7 +361,7 @@ void Compiler::optBlockCopyProp(BasicBlock* block, LclNumToGenTreePtrStack* curS
361361
GenTreePtrStack* stack;
362362
if (!curSsaName->Lookup(lclNum, &stack))
363363
{
364-
stack = new (getAllocator()) GenTreePtrStack(this);
364+
stack = new (curSsaName->GetAllocator()) GenTreePtrStack(this);
365365
stack->Push(tree);
366366
curSsaName->Set(lclNum, stack);
367367
}
@@ -408,10 +408,11 @@ void Compiler::optVnCopyProp()
408408
{
409409
return;
410410
}
411-
jitstd::allocator<void> allocator(getAllocator());
411+
412+
CompAllocator allocator(this, CMK_CopyProp);
412413

413414
// Compute the domTree to use.
414-
BlkToBlkSetMap* domTree = new (getAllocator()) BlkToBlkSetMap(getAllocator());
415+
BlkToBlkSetMap* domTree = new (&allocator) BlkToBlkSetMap(&allocator);
415416
domTree->Reallocate(fgBBcount * 3 / 2); // Prime the allocation
416417
SsaBuilder::ComputeDominators(this, domTree);
417418

@@ -430,10 +431,9 @@ void Compiler::optVnCopyProp()
430431
VarSetOps::AssignNoCopy(this, optCopyPropKillSet, VarSetOps::MakeEmpty(this));
431432

432433
// The map from lclNum to its recently live definitions as a stack.
433-
LclNumToGenTreePtrStack curSsaName(getAllocator());
434+
LclNumToGenTreePtrStack curSsaName(&allocator);
434435

435-
BlockWorkStack* worklist =
436-
new (allocate_any<BlockWorkStack>(allocator), jitstd::placement_t()) BlockWorkStack(allocator);
436+
BlockWorkStack* worklist = new (&allocator) BlockWorkStack(&allocator);
437437

438438
worklist->push_back(BlockWork(fgFirstBB));
439439
while (!worklist->empty())

src/jit/jithashtable.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ class JitHashTable
353353
return m_tableCount;
354354
}
355355

356+
// Get the allocator used by this hash table.
357+
Allocator* GetAllocator()
358+
{
359+
return m_alloc;
360+
}
361+
356362
private:
357363
struct Node;
358364

src/jit/ssabuilder.cpp

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
// ==++==
6-
//
7-
8-
//
9-
10-
//
11-
// ==--==
12-
13-
/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
14-
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
15-
XX XX
16-
XX SSA XX
17-
XX XX
18-
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
19-
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
20-
*/
21-
225
#include "jitpch.h"
236
#include "ssaconfig.h"
247
#include "ssarenamestate.h"
@@ -79,7 +62,7 @@ void Compiler::fgSsaBuild()
7962
fgResetForSsa();
8063
}
8164

82-
SsaBuilder builder(this, new (this, CMK_SSA) CompAllocator(this, CMK_SSA));
65+
SsaBuilder builder(this);
8366
builder.Build();
8467
fgSsaPassesCompleted++;
8568
#ifdef DEBUG
@@ -159,17 +142,16 @@ void Compiler::fgResetForSsa()
159142
*
160143
* @remarks Initializes the class and member pointers/objects that use constructors.
161144
*/
162-
SsaBuilder::SsaBuilder(Compiler* pCompiler, CompAllocator* pAllocator)
145+
SsaBuilder::SsaBuilder(Compiler* pCompiler)
163146
: m_pCompiler(pCompiler)
164-
, m_allocator(pAllocator)
165-
147+
, m_allocator(pCompiler, CMK_SSA)
166148
#ifdef SSA_FEATURE_DOMARR
167-
, m_pDomPreOrder(NULL)
168-
, m_pDomPostOrder(NULL)
149+
, m_pDomPreOrder(nullptr)
150+
, m_pDomPostOrder(nullptr)
169151
#endif
170152
#ifdef SSA_FEATURE_USEDEF
171-
, m_uses(jitstd::allocator<void>(pAllocator))
172-
, m_defs(jitstd::allocator<void>(pAllocator))
153+
, m_uses(&m_allocator)
154+
, m_defs(&m_allocator)
173155
#endif
174156
{
175157
}
@@ -425,7 +407,7 @@ void SsaBuilder::ConstructDomTreeForBlock(Compiler* pCompiler, BasicBlock* block
425407
BlkSet* pBlkSet;
426408
if (!domTree->Lookup(bbIDom, &pBlkSet))
427409
{
428-
pBlkSet = new (pCompiler->getAllocator()) BlkSet(pCompiler->getAllocator());
410+
pBlkSet = new (domTree->GetAllocator()) BlkSet(domTree->GetAllocator());
429411
domTree->Set(bbIDom, pBlkSet);
430412
}
431413

@@ -484,8 +466,8 @@ void SsaBuilder::ComputeDominators(BasicBlock** postOrder, int count, BlkToBlkSe
484466
// Allocate space for constant time computation of (a DOM b?) query.
485467
unsigned bbArrSize = m_pCompiler->fgBBNumMax + 1; // We will use 1-based bbNums as indices into these arrays, so
486468
// add 1.
487-
m_pDomPreOrder = jitstd::utility::allocate<int>(m_allocator, bbArrSize);
488-
m_pDomPostOrder = jitstd::utility::allocate<int>(m_allocator, bbArrSize);
469+
m_pDomPreOrder = new (&m_allocator) int[bbArrSize];
470+
m_pDomPostOrder = new (&m_allocator) int[bbArrSize];
489471

490472
// Initial counters.
491473
int preIndex = 0;
@@ -532,7 +514,7 @@ void SsaBuilder::DisplayDominators(BlkToBlkSetMap* domTree)
532514
// dominance frontiers by a closure operation.
533515
BlkToBlkSetMap* SsaBuilder::ComputeIteratedDominanceFrontier(BasicBlock** postOrder, int count)
534516
{
535-
BlkToBlkSetMap* frontier = new (m_pCompiler->getAllocator()) BlkToBlkSetMap(m_pCompiler->getAllocator());
517+
BlkToBlkSetMap* frontier = new (&m_allocator) BlkToBlkSetMap(&m_allocator);
536518

537519
DBG_SSA_JITDUMP("Computing IDF: First computing DF.\n");
538520

@@ -582,7 +564,7 @@ BlkToBlkSetMap* SsaBuilder::ComputeIteratedDominanceFrontier(BasicBlock** postOr
582564
BlkSet* pBlkSet;
583565
if (!frontier->Lookup(b1, &pBlkSet))
584566
{
585-
pBlkSet = new (m_pCompiler->getAllocator()) BlkSet(m_pCompiler->getAllocator());
567+
pBlkSet = new (&m_allocator) BlkSet(&m_allocator);
586568
frontier->Set(b1, pBlkSet);
587569
}
588570
pBlkSet->Set(block, true);
@@ -620,16 +602,16 @@ BlkToBlkSetMap* SsaBuilder::ComputeIteratedDominanceFrontier(BasicBlock** postOr
620602

621603
// Now do the closure operation to make the dominance frontier into an IDF.
622604
// There's probably a better way to do this...
623-
BlkToBlkSetMap* idf = new (m_pCompiler->getAllocator()) BlkToBlkSetMap(m_pCompiler->getAllocator());
605+
BlkToBlkSetMap* idf = new (&m_allocator) BlkToBlkSetMap(&m_allocator);
624606
for (BlkToBlkSetMap::KeyIterator kiFrontBlks = frontier->Begin(); !kiFrontBlks.Equal(frontier->End());
625607
kiFrontBlks++)
626608
{
627609
// Create IDF(b)
628-
BlkSet* blkIdf = new (m_pCompiler->getAllocator()) BlkSet(m_pCompiler->getAllocator());
610+
BlkSet* blkIdf = new (&m_allocator) BlkSet(&m_allocator);
629611
idf->Set(kiFrontBlks.Get(), blkIdf);
630612

631613
// Keep track of what got newly added to the IDF, so we can go after their DFs.
632-
BlkSet* delta = new (m_pCompiler->getAllocator()) BlkSet(m_pCompiler->getAllocator());
614+
BlkSet* delta = new (&m_allocator) BlkSet(&m_allocator);
633615
delta->Set(kiFrontBlks.Get(), true);
634616

635617
// Now transitively add DF+(delta) to IDF(b), each step gathering new "delta."
@@ -1743,9 +1725,8 @@ void SsaBuilder::RenameVariables(BlkToBlkSetMap* domTree, SsaRenameState* pRenam
17431725
}
17441726
};
17451727
typedef jitstd::vector<BlockWork> BlockWorkStack;
1746-
BlockWorkStack* blocksToDo =
1747-
new (jitstd::utility::allocate<BlockWorkStack>(m_allocator), jitstd::placement_t()) BlockWorkStack(m_allocator);
17481728

1729+
BlockWorkStack* blocksToDo = new (&m_allocator) BlockWorkStack(&m_allocator);
17491730
blocksToDo->push_back(BlockWork(m_pCompiler->fgFirstBB)); // Probably have to include other roots of dom tree.
17501731

17511732
while (blocksToDo->size() != 0)
@@ -1870,7 +1851,7 @@ void SsaBuilder::Build()
18701851

18711852
if (blockCount > DEFAULT_MIN_OPTS_BB_COUNT)
18721853
{
1873-
postOrder = new (m_pCompiler->getAllocator()) BasicBlock*[blockCount];
1854+
postOrder = new (&m_allocator) BasicBlock*[blockCount];
18741855
}
18751856
else
18761857
{
@@ -1886,16 +1867,16 @@ void SsaBuilder::Build()
18861867
ComputeImmediateDom(postOrder, count);
18871868

18881869
// Compute the dominator tree.
1889-
BlkToBlkSetMap* domTree = new (m_pCompiler->getAllocator()) BlkToBlkSetMap(m_pCompiler->getAllocator());
1870+
BlkToBlkSetMap* domTree = new (&m_allocator) BlkToBlkSetMap(&m_allocator);
18901871
ComputeDominators(postOrder, count, domTree);
18911872
EndPhase(PHASE_BUILD_SSA_DOMS);
18921873

18931874
// Insert phi functions.
18941875
InsertPhiFunctions(postOrder, count);
18951876

18961877
// Rename local variables and collect UD information for each ssa var.
1897-
SsaRenameState* pRenameState = new (jitstd::utility::allocate<SsaRenameState>(m_allocator), jitstd::placement_t())
1898-
SsaRenameState(m_allocator, m_pCompiler->lvaCount, m_pCompiler->byrefStatesMatchGcHeapStates);
1878+
SsaRenameState* pRenameState = new (&m_allocator)
1879+
SsaRenameState(&m_allocator, m_pCompiler->lvaCount, m_pCompiler->byrefStatesMatchGcHeapStates);
18991880
RenameVariables(domTree, pRenameState);
19001881
EndPhase(PHASE_BUILD_SSA_RENAME);
19011882

src/jit/ssabuilder.h

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
// ==++==
6-
//
7-
8-
//
9-
10-
//
11-
// ==--==
12-
13-
/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
14-
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
15-
XX XX
16-
XX SSA XX
17-
XX XX
18-
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
19-
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
20-
*/
21-
225
#pragma once
236
#pragma warning(disable : 4503) // 'identifier' : decorated name length exceeded, name was truncated
247

@@ -62,7 +45,7 @@ class SsaBuilder
6245

6346
public:
6447
// Constructor
65-
SsaBuilder(Compiler* pCompiler, CompAllocator* pAllocator);
48+
SsaBuilder(Compiler* pCompiler);
6649

6750
// Requires stmt nodes to be already sequenced in evaluation order. Analyzes the graph
6851
// for introduction of phi-nodes as GT_PHI tree nodes at the beginning of each block.
@@ -105,7 +88,7 @@ class SsaBuilder
10588
// as children.) Requires "preIndex" and "postIndex" to be initialized to 0 at entry into recursion.
10689
// Computes arrays "m_pDomPreOrder" and "m_pDomPostOrder" of block indices such that the blocks of a
10790
// "domTree" are in pre and postorder respectively.
108-
void DomTreeWalk(BasicBlock* curBlock, const BlkToBlkSetMap& domTree, int* preIndex, int* postIndex);
91+
void DomTreeWalk(BasicBlock* curBlock, BlkToBlkSetMap* domTree, int* preIndex, int* postIndex);
10992
#endif
11093

11194
// Requires all blocks to have computed "bbIDom." Requires "domTree" to be a preallocated BlkToBlkSetMap.
@@ -190,13 +173,8 @@ class SsaBuilder
190173
#endif
191174

192175
private:
193-
#ifdef SSA_FEATURE_USEDEF
194-
// Use Def information after SSA. To query the uses and def of a given ssa var,
195-
// probe these data structures.
196-
// Do not move these outside of this class, use accessors/interface methods.
197-
VarToUses m_uses;
198-
VarToDef m_defs;
199-
#endif
176+
Compiler* m_pCompiler;
177+
CompAllocator m_allocator;
200178

201179
#ifdef SSA_FEATURE_DOMARR
202180
// To answer queries of type a DOM b.
@@ -205,8 +183,11 @@ class SsaBuilder
205183
int* m_pDomPostOrder;
206184
#endif
207185

208-
Compiler* m_pCompiler;
209-
210-
// Used to allocate space for jitstd data structures.
211-
jitstd::allocator<void> m_allocator;
186+
#ifdef SSA_FEATURE_USEDEF
187+
// Use Def information after SSA. To query the uses and def of a given ssa var,
188+
// probe these data structures.
189+
// Do not move these outside of this class, use accessors/interface methods.
190+
VarToUses m_uses;
191+
VarToDef m_defs;
192+
#endif
212193
};

0 commit comments

Comments
 (0)