diff options
author | Mike Danes <onemihaid@hotmail.com> | 2017-11-09 08:18:48 +0200 |
---|---|---|
committer | Mike Danes <onemihaid@hotmail.com> | 2017-11-09 08:41:56 +0200 |
commit | 028ee930f8f965715b0a82ad16917e9942701f65 (patch) | |
tree | 23de3c4b9b2ab5185d9a0e59ae92d8a4a92e5e61 /src/jit | |
parent | 97c4729dd928bd6ea82f824b6a2d90cfc86af44b (diff) | |
download | coreclr-028ee930f8f965715b0a82ad16917e9942701f65.tar.gz coreclr-028ee930f8f965715b0a82ad16917e9942701f65.tar.bz2 coreclr-028ee930f8f965715b0a82ad16917e9942701f65.zip |
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.
Diffstat (limited to 'src/jit')
-rw-r--r-- | src/jit/compmemkind.h | 1 | ||||
-rw-r--r-- | src/jit/copyprop.cpp | 14 | ||||
-rw-r--r-- | src/jit/jithashtable.h | 6 | ||||
-rw-r--r-- | src/jit/ssabuilder.cpp | 59 | ||||
-rw-r--r-- | src/jit/ssabuilder.h | 41 |
5 files changed, 45 insertions, 76 deletions
diff --git a/src/jit/compmemkind.h b/src/jit/compmemkind.h index 0a22bdc4b9..bd8483d13a 100644 --- a/src/jit/compmemkind.h +++ b/src/jit/compmemkind.h @@ -52,6 +52,7 @@ CompMemKindMacro(LoopOpt) CompMemKindMacro(LoopHoist) CompMemKindMacro(Unknown) CompMemKindMacro(RangeCheck) +CompMemKindMacro(CopyProp) //clang-format on #undef CompMemKindMacro diff --git a/src/jit/copyprop.cpp b/src/jit/copyprop.cpp index c9699f190c..12206671f1 100644 --- a/src/jit/copyprop.cpp +++ b/src/jit/copyprop.cpp @@ -348,7 +348,7 @@ void Compiler::optBlockCopyProp(BasicBlock* block, LclNumToGenTreePtrStack* curS GenTreePtrStack* stack; if (!curSsaName->Lookup(lclNum, &stack)) { - stack = new (getAllocator()) GenTreePtrStack(this); + stack = new (curSsaName->GetAllocator()) GenTreePtrStack(this); } stack->Push(tree); curSsaName->Set(lclNum, stack); @@ -361,7 +361,7 @@ void Compiler::optBlockCopyProp(BasicBlock* block, LclNumToGenTreePtrStack* curS GenTreePtrStack* stack; if (!curSsaName->Lookup(lclNum, &stack)) { - stack = new (getAllocator()) GenTreePtrStack(this); + stack = new (curSsaName->GetAllocator()) GenTreePtrStack(this); stack->Push(tree); curSsaName->Set(lclNum, stack); } @@ -408,10 +408,11 @@ void Compiler::optVnCopyProp() { return; } - jitstd::allocator<void> allocator(getAllocator()); + + CompAllocator allocator(this, CMK_CopyProp); // Compute the domTree to use. - BlkToBlkSetMap* domTree = new (getAllocator()) BlkToBlkSetMap(getAllocator()); + BlkToBlkSetMap* domTree = new (&allocator) BlkToBlkSetMap(&allocator); domTree->Reallocate(fgBBcount * 3 / 2); // Prime the allocation SsaBuilder::ComputeDominators(this, domTree); @@ -430,10 +431,9 @@ void Compiler::optVnCopyProp() VarSetOps::AssignNoCopy(this, optCopyPropKillSet, VarSetOps::MakeEmpty(this)); // The map from lclNum to its recently live definitions as a stack. - LclNumToGenTreePtrStack curSsaName(getAllocator()); + LclNumToGenTreePtrStack curSsaName(&allocator); - BlockWorkStack* worklist = - new (allocate_any<BlockWorkStack>(allocator), jitstd::placement_t()) BlockWorkStack(allocator); + BlockWorkStack* worklist = new (&allocator) BlockWorkStack(&allocator); worklist->push_back(BlockWork(fgFirstBB)); while (!worklist->empty()) diff --git a/src/jit/jithashtable.h b/src/jit/jithashtable.h index 52d61a679b..140fc0688f 100644 --- a/src/jit/jithashtable.h +++ b/src/jit/jithashtable.h @@ -353,6 +353,12 @@ public: return m_tableCount; } + // Get the allocator used by this hash table. + Allocator* GetAllocator() + { + return m_alloc; + } + private: struct Node; diff --git a/src/jit/ssabuilder.cpp b/src/jit/ssabuilder.cpp index 4d6302e7ec..a4facef584 100644 --- a/src/jit/ssabuilder.cpp +++ b/src/jit/ssabuilder.cpp @@ -2,23 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// ==++== -// - -// - -// -// ==--== - -/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -XX XX -XX SSA XX -XX XX -XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -*/ - #include "jitpch.h" #include "ssaconfig.h" #include "ssarenamestate.h" @@ -79,7 +62,7 @@ void Compiler::fgSsaBuild() fgResetForSsa(); } - SsaBuilder builder(this, new (this, CMK_SSA) CompAllocator(this, CMK_SSA)); + SsaBuilder builder(this); builder.Build(); fgSsaPassesCompleted++; #ifdef DEBUG @@ -159,17 +142,16 @@ void Compiler::fgResetForSsa() * * @remarks Initializes the class and member pointers/objects that use constructors. */ -SsaBuilder::SsaBuilder(Compiler* pCompiler, CompAllocator* pAllocator) +SsaBuilder::SsaBuilder(Compiler* pCompiler) : m_pCompiler(pCompiler) - , m_allocator(pAllocator) - + , m_allocator(pCompiler, CMK_SSA) #ifdef SSA_FEATURE_DOMARR - , m_pDomPreOrder(NULL) - , m_pDomPostOrder(NULL) + , m_pDomPreOrder(nullptr) + , m_pDomPostOrder(nullptr) #endif #ifdef SSA_FEATURE_USEDEF - , m_uses(jitstd::allocator<void>(pAllocator)) - , m_defs(jitstd::allocator<void>(pAllocator)) + , m_uses(&m_allocator) + , m_defs(&m_allocator) #endif { } @@ -425,7 +407,7 @@ void SsaBuilder::ConstructDomTreeForBlock(Compiler* pCompiler, BasicBlock* block BlkSet* pBlkSet; if (!domTree->Lookup(bbIDom, &pBlkSet)) { - pBlkSet = new (pCompiler->getAllocator()) BlkSet(pCompiler->getAllocator()); + pBlkSet = new (domTree->GetAllocator()) BlkSet(domTree->GetAllocator()); domTree->Set(bbIDom, pBlkSet); } @@ -484,8 +466,8 @@ void SsaBuilder::ComputeDominators(BasicBlock** postOrder, int count, BlkToBlkSe // Allocate space for constant time computation of (a DOM b?) query. unsigned bbArrSize = m_pCompiler->fgBBNumMax + 1; // We will use 1-based bbNums as indices into these arrays, so // add 1. - m_pDomPreOrder = jitstd::utility::allocate<int>(m_allocator, bbArrSize); - m_pDomPostOrder = jitstd::utility::allocate<int>(m_allocator, bbArrSize); + m_pDomPreOrder = new (&m_allocator) int[bbArrSize]; + m_pDomPostOrder = new (&m_allocator) int[bbArrSize]; // Initial counters. int preIndex = 0; @@ -532,7 +514,7 @@ void SsaBuilder::DisplayDominators(BlkToBlkSetMap* domTree) // dominance frontiers by a closure operation. BlkToBlkSetMap* SsaBuilder::ComputeIteratedDominanceFrontier(BasicBlock** postOrder, int count) { - BlkToBlkSetMap* frontier = new (m_pCompiler->getAllocator()) BlkToBlkSetMap(m_pCompiler->getAllocator()); + BlkToBlkSetMap* frontier = new (&m_allocator) BlkToBlkSetMap(&m_allocator); DBG_SSA_JITDUMP("Computing IDF: First computing DF.\n"); @@ -582,7 +564,7 @@ BlkToBlkSetMap* SsaBuilder::ComputeIteratedDominanceFrontier(BasicBlock** postOr BlkSet* pBlkSet; if (!frontier->Lookup(b1, &pBlkSet)) { - pBlkSet = new (m_pCompiler->getAllocator()) BlkSet(m_pCompiler->getAllocator()); + pBlkSet = new (&m_allocator) BlkSet(&m_allocator); frontier->Set(b1, pBlkSet); } pBlkSet->Set(block, true); @@ -620,16 +602,16 @@ BlkToBlkSetMap* SsaBuilder::ComputeIteratedDominanceFrontier(BasicBlock** postOr // Now do the closure operation to make the dominance frontier into an IDF. // There's probably a better way to do this... - BlkToBlkSetMap* idf = new (m_pCompiler->getAllocator()) BlkToBlkSetMap(m_pCompiler->getAllocator()); + BlkToBlkSetMap* idf = new (&m_allocator) BlkToBlkSetMap(&m_allocator); for (BlkToBlkSetMap::KeyIterator kiFrontBlks = frontier->Begin(); !kiFrontBlks.Equal(frontier->End()); kiFrontBlks++) { // Create IDF(b) - BlkSet* blkIdf = new (m_pCompiler->getAllocator()) BlkSet(m_pCompiler->getAllocator()); + BlkSet* blkIdf = new (&m_allocator) BlkSet(&m_allocator); idf->Set(kiFrontBlks.Get(), blkIdf); // Keep track of what got newly added to the IDF, so we can go after their DFs. - BlkSet* delta = new (m_pCompiler->getAllocator()) BlkSet(m_pCompiler->getAllocator()); + BlkSet* delta = new (&m_allocator) BlkSet(&m_allocator); delta->Set(kiFrontBlks.Get(), true); // Now transitively add DF+(delta) to IDF(b), each step gathering new "delta." @@ -1743,9 +1725,8 @@ void SsaBuilder::RenameVariables(BlkToBlkSetMap* domTree, SsaRenameState* pRenam } }; typedef jitstd::vector<BlockWork> BlockWorkStack; - BlockWorkStack* blocksToDo = - new (jitstd::utility::allocate<BlockWorkStack>(m_allocator), jitstd::placement_t()) BlockWorkStack(m_allocator); + BlockWorkStack* blocksToDo = new (&m_allocator) BlockWorkStack(&m_allocator); blocksToDo->push_back(BlockWork(m_pCompiler->fgFirstBB)); // Probably have to include other roots of dom tree. while (blocksToDo->size() != 0) @@ -1870,7 +1851,7 @@ void SsaBuilder::Build() if (blockCount > DEFAULT_MIN_OPTS_BB_COUNT) { - postOrder = new (m_pCompiler->getAllocator()) BasicBlock*[blockCount]; + postOrder = new (&m_allocator) BasicBlock*[blockCount]; } else { @@ -1886,7 +1867,7 @@ void SsaBuilder::Build() ComputeImmediateDom(postOrder, count); // Compute the dominator tree. - BlkToBlkSetMap* domTree = new (m_pCompiler->getAllocator()) BlkToBlkSetMap(m_pCompiler->getAllocator()); + BlkToBlkSetMap* domTree = new (&m_allocator) BlkToBlkSetMap(&m_allocator); ComputeDominators(postOrder, count, domTree); EndPhase(PHASE_BUILD_SSA_DOMS); @@ -1894,8 +1875,8 @@ void SsaBuilder::Build() InsertPhiFunctions(postOrder, count); // Rename local variables and collect UD information for each ssa var. - SsaRenameState* pRenameState = new (jitstd::utility::allocate<SsaRenameState>(m_allocator), jitstd::placement_t()) - SsaRenameState(m_allocator, m_pCompiler->lvaCount, m_pCompiler->byrefStatesMatchGcHeapStates); + SsaRenameState* pRenameState = new (&m_allocator) + SsaRenameState(&m_allocator, m_pCompiler->lvaCount, m_pCompiler->byrefStatesMatchGcHeapStates); RenameVariables(domTree, pRenameState); EndPhase(PHASE_BUILD_SSA_RENAME); diff --git a/src/jit/ssabuilder.h b/src/jit/ssabuilder.h index 7a97375fb7..49ac7550fd 100644 --- a/src/jit/ssabuilder.h +++ b/src/jit/ssabuilder.h @@ -2,23 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// ==++== -// - -// - -// -// ==--== - -/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -XX XX -XX SSA XX -XX XX -XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -*/ - #pragma once #pragma warning(disable : 4503) // 'identifier' : decorated name length exceeded, name was truncated @@ -62,7 +45,7 @@ private: public: // Constructor - SsaBuilder(Compiler* pCompiler, CompAllocator* pAllocator); + SsaBuilder(Compiler* pCompiler); // Requires stmt nodes to be already sequenced in evaluation order. Analyzes the graph // for introduction of phi-nodes as GT_PHI tree nodes at the beginning of each block. @@ -105,7 +88,7 @@ private: // as children.) Requires "preIndex" and "postIndex" to be initialized to 0 at entry into recursion. // Computes arrays "m_pDomPreOrder" and "m_pDomPostOrder" of block indices such that the blocks of a // "domTree" are in pre and postorder respectively. - void DomTreeWalk(BasicBlock* curBlock, const BlkToBlkSetMap& domTree, int* preIndex, int* postIndex); + void DomTreeWalk(BasicBlock* curBlock, BlkToBlkSetMap* domTree, int* preIndex, int* postIndex); #endif // Requires all blocks to have computed "bbIDom." Requires "domTree" to be a preallocated BlkToBlkSetMap. @@ -190,13 +173,8 @@ private: #endif private: -#ifdef SSA_FEATURE_USEDEF - // Use Def information after SSA. To query the uses and def of a given ssa var, - // probe these data structures. - // Do not move these outside of this class, use accessors/interface methods. - VarToUses m_uses; - VarToDef m_defs; -#endif + Compiler* m_pCompiler; + CompAllocator m_allocator; #ifdef SSA_FEATURE_DOMARR // To answer queries of type a DOM b. @@ -205,8 +183,11 @@ private: int* m_pDomPostOrder; #endif - Compiler* m_pCompiler; - - // Used to allocate space for jitstd data structures. - jitstd::allocator<void> m_allocator; +#ifdef SSA_FEATURE_USEDEF + // Use Def information after SSA. To query the uses and def of a given ssa var, + // probe these data structures. + // Do not move these outside of this class, use accessors/interface methods. + VarToUses m_uses; + VarToDef m_defs; +#endif }; |