From fa323e5b30540cba689ecc647f6dee019ac972af Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Fri, 3 Feb 2023 11:18:38 -0800 Subject: [PATCH] JIT: rename flowList to FlowEdge and encapsulate all fields Restructure this type in anticipation of modifying how it represents data. Rename some of the fields (and now related accessor methods) because subsequent changes may do things like add the target block or successor edge links. Also, remove some stray references to fgComputePreds --- src/coreclr/jit/block.cpp | 82 +++++++++------- src/coreclr/jit/block.h | 162 +++++++++++++++++++------------ src/coreclr/jit/compiler.cpp | 2 +- src/coreclr/jit/compiler.h | 34 +++---- src/coreclr/jit/compmemkind.h | 2 +- src/coreclr/jit/dataflow.h | 6 +- src/coreclr/jit/fgbasic.cpp | 38 ++++---- src/coreclr/jit/fgdiagnostic.cpp | 20 ++-- src/coreclr/jit/fgehopt.cpp | 12 +-- src/coreclr/jit/fgflow.cpp | 86 ++++++++-------- src/coreclr/jit/fgopt.cpp | 62 ++++++------ src/coreclr/jit/fgprofile.cpp | 146 ++++++++++++++-------------- src/coreclr/jit/flowgraph.cpp | 4 +- src/coreclr/jit/jit.h | 2 +- src/coreclr/jit/lower.cpp | 4 +- src/coreclr/jit/lsra.cpp | 9 +- src/coreclr/jit/morph.cpp | 4 +- src/coreclr/jit/optimizer.cpp | 34 +++---- src/coreclr/jit/ssabuilder.cpp | 22 ++--- src/coreclr/jit/valuenum.cpp | 12 +-- 20 files changed, 391 insertions(+), 352 deletions(-) diff --git a/src/coreclr/jit/block.cpp b/src/coreclr/jit/block.cpp index c3830972f612b..1d046cdf6c723 100644 --- a/src/coreclr/jit/block.cpp +++ b/src/coreclr/jit/block.cpp @@ -31,17 +31,20 @@ unsigned BasicBlock::s_nMaxTrees; #endif // DEBUG #ifdef DEBUG -flowList* ShuffleHelper(unsigned hash, flowList* res) +FlowEdge* ShuffleHelper(unsigned hash, FlowEdge* res) { - flowList* head = res; - for (flowList *prev = nullptr; res != nullptr; prev = res, res = res->flNext) + FlowEdge* head = res; + for (FlowEdge *prev = nullptr; res != nullptr; prev = res, res = res->getNextPredEdge()) { - unsigned blkHash = (hash ^ (res->getBlock()->bbNum << 16) ^ res->getBlock()->bbNum); + unsigned blkHash = (hash ^ (res->getSourceBlock()->bbNum << 16) ^ res->getSourceBlock()->bbNum); if (((blkHash % 1879) & 1) && prev != nullptr) { // Swap res with head. - prev->flNext = head; - std::swap(head->flNext, res->flNext); + prev->setNextPredEdge(head); + FlowEdge* const resNext = res->getNextPredEdge(); + FlowEdge* const headNext = head->getNextPredEdge(); + head->setNextPredEdge(resNext); + res->setNextPredEdge(headNext); std::swap(head, res); } } @@ -147,10 +150,10 @@ BasicBlock* EHSuccessorIterPosition::Current(Compiler* comp, BasicBlock* block) return m_curTry->ExFlowBlock(); } -flowList* Compiler::BlockPredsWithEH(BasicBlock* blk) +FlowEdge* Compiler::BlockPredsWithEH(BasicBlock* blk) { - BlockToFlowListMap* ehPreds = GetBlockToEHPreds(); - flowList* res; + BlockToFlowEdgeMap* ehPreds = GetBlockToEHPreds(); + FlowEdge* res; if (ehPreds->Lookup(blk, &res)) { return res; @@ -165,11 +168,11 @@ flowList* Compiler::BlockPredsWithEH(BasicBlock* blk) BasicBlock* tryStart = ehblk->ebdTryBeg; for (BasicBlock* const tryStartPredBlock : tryStart->PredBlocks()) { - res = new (this, CMK_FlowList) flowList(tryStartPredBlock, res); + res = new (this, CMK_FlowEdge) FlowEdge(tryStartPredBlock, res); #if MEASURE_BLOCK_SIZE genFlowNodeCnt += 1; - genFlowNodeSize += sizeof(flowList); + genFlowNodeSize += sizeof(FlowEdge); #endif // MEASURE_BLOCK_SIZE } @@ -185,11 +188,11 @@ flowList* Compiler::BlockPredsWithEH(BasicBlock* blk) { if (bbInExnFlowRegions(tryIndex, bb) && !bb->isBBCallAlwaysPairTail()) { - res = new (this, CMK_FlowList) flowList(bb, res); + res = new (this, CMK_FlowEdge) FlowEdge(bb, res); #if MEASURE_BLOCK_SIZE genFlowNodeCnt += 1; - genFlowNodeSize += sizeof(flowList); + genFlowNodeSize += sizeof(FlowEdge); #endif // MEASURE_BLOCK_SIZE } } @@ -201,7 +204,6 @@ flowList* Compiler::BlockPredsWithEH(BasicBlock* blk) res = ShuffleHelper(hash, res); } #endif // DEBUG - ehPreds->Set(blk, res); } return res; @@ -260,7 +262,7 @@ void BasicBlock::reorderPredList(Compiler* compiler) // Count number or entries. // int count = 0; - for (flowList* const pred : PredEdges()) + for (FlowEdge* const pred : PredEdges()) { count++; } @@ -276,37 +278,37 @@ void BasicBlock::reorderPredList(Compiler* compiler) // if (compiler->fgPredListSortVector == nullptr) { - CompAllocator allocator = compiler->getAllocator(CMK_FlowList); - compiler->fgPredListSortVector = new (allocator) jitstd::vector(allocator); + CompAllocator allocator = compiler->getAllocator(CMK_FlowEdge); + compiler->fgPredListSortVector = new (allocator) jitstd::vector(allocator); } - jitstd::vector* const sortVector = compiler->fgPredListSortVector; + jitstd::vector* const sortVector = compiler->fgPredListSortVector; sortVector->clear(); // Fill in the vector from the list. // - for (flowList* const pred : PredEdges()) + for (FlowEdge* const pred : PredEdges()) { sortVector->push_back(pred); } // Sort by increasing bbNum // - struct flowListBBNumCmp + struct FlowEdgeBBNumCmp { - bool operator()(const flowList* f1, const flowList* f2) + bool operator()(const FlowEdge* f1, const FlowEdge* f2) { - return f1->getBlock()->bbNum < f2->getBlock()->bbNum; + return f1->getSourceBlock()->bbNum < f2->getSourceBlock()->bbNum; } }; - jitstd::sort(sortVector->begin(), sortVector->end(), flowListBBNumCmp()); + jitstd::sort(sortVector->begin(), sortVector->end(), FlowEdgeBBNumCmp()); // Rethread the list. // - flowList* last = nullptr; + FlowEdge* last = nullptr; - for (flowList* current : *sortVector) + for (FlowEdge* current : *sortVector) { if (last == nullptr) { @@ -314,17 +316,21 @@ void BasicBlock::reorderPredList(Compiler* compiler) } else { - last->flNext = current; + last->setNextPredEdge(current); } last = current; } - last->flNext = nullptr; + last->setNextPredEdge(nullptr); - // Note this lastPred is only used transiently. + // Note bbLastPred is only used transiently, during + // initial pred list construction. // - bbLastPred = last; + if (!compiler->fgPredsComputed) + { + bbLastPred = last; + } } #ifdef DEBUG @@ -527,28 +533,28 @@ void BasicBlock::dspFlags() unsigned BasicBlock::dspPreds() { unsigned count = 0; - for (flowList* const pred : PredEdges()) + for (FlowEdge* const pred : PredEdges()) { if (count != 0) { printf(","); count += 1; } - printf(FMT_BB, pred->getBlock()->bbNum); + printf(FMT_BB, pred->getSourceBlock()->bbNum); count += 4; // Account for %02u only handling 2 digits, but we can display more than that. - unsigned digits = CountDigits(pred->getBlock()->bbNum); + unsigned digits = CountDigits(pred->getSourceBlock()->bbNum); if (digits > 2) { count += digits - 2; } // Does this predecessor have an interesting dup count? If so, display it. - if (pred->flDupCount > 1) + if (pred->getDupCount() > 1) { - printf("(%u)", pred->flDupCount); - count += 2 + CountDigits(pred->flDupCount); + printf("(%u)", pred->getDupCount()); + count += 2 + CountDigits(pred->getDupCount()); } } return count; @@ -870,13 +876,15 @@ GenTree* BasicBlock::lastNode() const BasicBlock* BasicBlock::GetUniquePred(Compiler* compiler) const { - if ((bbPreds == nullptr) || (bbPreds->flNext != nullptr) || (this == compiler->fgFirstBB)) + assert(compiler->fgPredsComputed); + + if ((bbPreds == nullptr) || (bbPreds->getNextPredEdge() != nullptr) || (this == compiler->fgFirstBB)) { return nullptr; } else { - return bbPreds->getBlock(); + return bbPreds->getSourceBlock(); } } diff --git a/src/coreclr/jit/block.h b/src/coreclr/jit/block.h index 13700337e4152..9e30168bbc1ea 100644 --- a/src/coreclr/jit/block.h +++ b/src/coreclr/jit/block.h @@ -82,7 +82,7 @@ struct BasicBlock; class Compiler; class typeInfo; struct BasicBlockList; -struct flowList; +struct FlowEdge; struct EHblkDsc; struct BBswtDesc; @@ -308,31 +308,31 @@ class AllSuccessorIterPosition // PredEdgeList: adapter class for forward iteration of the predecessor edge linked list using range-based `for`, // normally used via BasicBlock::PredEdges(), e.g.: -// for (flowList* const edge : block->PredEdges()) ... +// for (FlowEdge* const edge : block->PredEdges()) ... // class PredEdgeList { - flowList* m_begin; + FlowEdge* m_begin; // Forward iterator for the predecessor edges linked list. // The caller can't make changes to the preds list when using this. // class iterator { - flowList* m_pred; + FlowEdge* m_pred; #ifdef DEBUG // Try to guard against the user of the iterator from making changes to the IR that would invalidate // the iterator: cache the edge we think should be next, then check it when we actually do the `++` // operation. This is a bit conservative, but attempts to protect against callers assuming too much about // this iterator implementation. - flowList* m_next; + FlowEdge* m_next; #endif public: - iterator(flowList* pred); + iterator(FlowEdge* pred); - flowList* operator*() const + FlowEdge* operator*() const { return m_pred; } @@ -346,7 +346,7 @@ class PredEdgeList }; public: - PredEdgeList(flowList* pred) : m_begin(pred) + PredEdgeList(FlowEdge* pred) : m_begin(pred) { } @@ -367,25 +367,25 @@ class PredEdgeList // class PredBlockList { - flowList* m_begin; + FlowEdge* m_begin; // Forward iterator for the predecessor edges linked list, yielding the predecessor block, not the edge. // The caller can't make changes to the preds list when using this. // class iterator { - flowList* m_pred; + FlowEdge* m_pred; #ifdef DEBUG // Try to guard against the user of the iterator from making changes to the IR that would invalidate // the iterator: cache the edge we think should be next, then check it when we actually do the `++` // operation. This is a bit conservative, but attempts to protect against callers assuming too much about // this iterator implementation. - flowList* m_next; + FlowEdge* m_next; #endif public: - iterator(flowList* pred); + iterator(FlowEdge* pred); BasicBlock* operator*() const; @@ -398,7 +398,7 @@ class PredBlockList }; public: - PredBlockList(flowList* pred) : m_begin(pred) + PredBlockList(FlowEdge* pred) : m_begin(pred) { } @@ -1055,10 +1055,10 @@ struct BasicBlock : private LIR::Range // in 'bbPreds', and then maintained throughout compilation. 'fgPredsComputed' will be 'true' after the // predecessor lists are created. // - flowList* bbPreds; // ptr to list of predecessors + FlowEdge* bbPreds; // ptr to list of predecessors // PredEdges: convenience method for enabling range-based `for` iteration over predecessor edges, e.g.: - // for (flowList* const edge : block->PredEdges()) ... + // for (FlowEdge* const edge : block->PredEdges()) ... // PredEdgeList PredEdges() const { @@ -1084,7 +1084,7 @@ struct BasicBlock : private LIR::Range union { BasicBlock* bbIDom; // Represent the closest dominator to this block (called the Immediate // Dominator) used to compute the dominance tree. - flowList* bbLastPred; // Used early on by fgComputePreds + FlowEdge* bbLastPred; // Used early on by fgLinkBasicBlock/fgAddRefPred }; union { @@ -1730,24 +1730,44 @@ inline BBArrayIterator BasicBlock::BBSuccList::end() const return BBArrayIterator(m_end); } +// We have a simpler struct, BasicBlockList, which is simply a singly-linked +// list of blocks. + +struct BasicBlockList +{ + BasicBlockList* next; // The next BasicBlock in the list, nullptr for end of list. + BasicBlock* block; // The BasicBlock of interest. + + BasicBlockList() : next(nullptr), block(nullptr) + { + } + + BasicBlockList(BasicBlock* blk, BasicBlockList* rest) : next(rest), block(blk) + { + } +}; + +//------------------------------------------------------------------------- +// FlowEdge -- control flow edge +// // In compiler terminology the control flow between two BasicBlocks // is typically referred to as an "edge". Most well known are the // backward branches for loops, which are often called "back-edges". // -// "struct flowList" is the type that represents our control flow edges. +// "struct FlowEdge" is the type that represents our control flow edges. // This type is a linked list of zero or more "edges". // (The list of zero edges is represented by NULL.) // Every BasicBlock has a field called bbPreds of this type. This field // represents the list of "edges" that flow into this BasicBlock. -// The flowList type only stores the BasicBlock* of the source for the +// The FlowEdge type only stores the BasicBlock* of the source for the // control flow edge. The destination block for the control flow edge // is implied to be the block which contained the bbPreds field. // // For a switch branch target there may be multiple "edges" that have // the same source block (and destination block). We need to count the // number of these edges so that during optimization we will know when -// we have zero of them. Rather than have extra flowList entries we -// increment the flDupCount field. +// we have zero of them. Rather than have extra FlowEdge entries we +// track this via the DupCount property. // // When we have Profile weight for the BasicBlocks we can usually compute // the number of times each edge was executed by examining the adjacent @@ -1760,68 +1780,71 @@ inline BBArrayIterator BasicBlock::BBSuccList::end() const // Sometimes we are left with a rage of possible values between [Min..Max] // which represents an inexact edge weight. // -// The bbPreds list is initially created by Compiler::fgComputePreds() +// The bbPreds list is initially created by Compiler::fgLinkBasicBlocks() // and is incrementally kept up to date. // // The edge weight are computed by Compiler::fgComputeEdgeWeights() // the edge weights are used to straighten conditional branches // by Compiler::fgReorderBlocks() // -// We have a simpler struct, BasicBlockList, which is simply a singly-linked -// list of blocks. - -struct BasicBlockList +struct FlowEdge { - BasicBlockList* next; // The next BasicBlock in the list, nullptr for end of list. - BasicBlock* block; // The BasicBlock of interest. +private: + // The next predecessor edge in the list, nullptr for end of list. + FlowEdge* m_nextPredEdge; - BasicBlockList() : next(nullptr), block(nullptr) + // The source of the control flow + BasicBlock* m_sourceBlock; + + // Edge weights + weight_t m_edgeWeightMin; + weight_t m_edgeWeightMax; + + // The count of duplicate "edges" (used for switch stmts or degenerate branches) + unsigned m_dupCount; + +public: + FlowEdge(BasicBlock* block, FlowEdge* rest) + : m_nextPredEdge(rest), m_sourceBlock(block), m_edgeWeightMin(0), m_edgeWeightMax(0), m_dupCount(0) { } - BasicBlockList(BasicBlock* blk, BasicBlockList* rest) : next(rest), block(blk) + FlowEdge* getNextPredEdge() const { + return m_nextPredEdge; } -}; -// flowList -- control flow edge -// -struct flowList -{ -public: - flowList* flNext; // The next BasicBlock in the list, nullptr for end of list. - -private: - BasicBlock* m_block; // The BasicBlock of interest. - weight_t flEdgeWeightMin; - weight_t flEdgeWeightMax; + FlowEdge** getNextPredEdgeRef() + { + return &m_nextPredEdge; + } -public: - unsigned flDupCount; // The count of duplicate "edges" (use only for switch stmts) + void setNextPredEdge(FlowEdge* newEdge) + { + m_nextPredEdge = newEdge; + } -public: - BasicBlock* getBlock() const + BasicBlock* getSourceBlock() const { - return m_block; + return m_sourceBlock; } - void setBlock(BasicBlock* newBlock) + void setSourceBlock(BasicBlock* newBlock) { - m_block = newBlock; + m_sourceBlock = newBlock; } weight_t edgeWeightMin() const { - return flEdgeWeightMin; + return m_edgeWeightMin; } weight_t edgeWeightMax() const { - return flEdgeWeightMax; + return m_edgeWeightMax; } - // These two methods are used to set new values for flEdgeWeightMin and flEdgeWeightMax - // they are used only during the computation of the edge weights + // These two methods are used to set new values for edge weights. // They return false if the newWeight is not between the current [min..max] // when slop is non-zero we allow for the case where our weights might be off by 'slop' // @@ -1829,55 +1852,66 @@ struct flowList bool setEdgeWeightMaxChecked(weight_t newWeight, BasicBlock* bDst, weight_t slop, bool* wbUsedSlop); void setEdgeWeights(weight_t newMinWeight, weight_t newMaxWeight, BasicBlock* bDst); - flowList(BasicBlock* block, flowList* rest) - : flNext(rest), m_block(block), flEdgeWeightMin(0), flEdgeWeightMax(0), flDupCount(0) + unsigned getDupCount() const + { + return m_dupCount; + } + + void incrementDupCount() + { + m_dupCount++; + } + + void decrementDupCount() { + assert(m_dupCount >= 1); + m_dupCount--; } }; -// Pred list iterator implementations (that are required to be defined after the declaration of BasicBlock and flowList) +// Pred list iterator implementations (that are required to be defined after the declaration of BasicBlock and FlowEdge) -inline PredEdgeList::iterator::iterator(flowList* pred) : m_pred(pred) +inline PredEdgeList::iterator::iterator(FlowEdge* pred) : m_pred(pred) { #ifdef DEBUG - m_next = (m_pred == nullptr) ? nullptr : m_pred->flNext; + m_next = (m_pred == nullptr) ? nullptr : m_pred->getNextPredEdge(); #endif } inline PredEdgeList::iterator& PredEdgeList::iterator::operator++() { - flowList* next = m_pred->flNext; + FlowEdge* next = m_pred->getNextPredEdge(); #ifdef DEBUG // Check that the next block is the one we expect to see. assert(next == m_next); - m_next = (next == nullptr) ? nullptr : next->flNext; + m_next = (next == nullptr) ? nullptr : next->getNextPredEdge(); #endif // DEBUG m_pred = next; return *this; } -inline PredBlockList::iterator::iterator(flowList* pred) : m_pred(pred) +inline PredBlockList::iterator::iterator(FlowEdge* pred) : m_pred(pred) { #ifdef DEBUG - m_next = (m_pred == nullptr) ? nullptr : m_pred->flNext; + m_next = (m_pred == nullptr) ? nullptr : m_pred->getNextPredEdge(); #endif } inline BasicBlock* PredBlockList::iterator::operator*() const { - return m_pred->getBlock(); + return m_pred->getSourceBlock(); } inline PredBlockList::iterator& PredBlockList::iterator::operator++() { - flowList* next = m_pred->flNext; + FlowEdge* next = m_pred->getNextPredEdge(); #ifdef DEBUG // Check that the next block is the one we expect to see. assert(next == m_next); - m_next = (next == nullptr) ? nullptr : next->flNext; + m_next = (next == nullptr) ? nullptr : next->getNextPredEdge(); #endif // DEBUG m_pred = next; diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 20a6d976da706..42f0dc6825b5f 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -1629,7 +1629,7 @@ void Compiler::compShutdown() fprintf(fout, "\n"); fprintf(fout, "---------------------------------------------------\n"); - fprintf(fout, "BasicBlock and flowList/BasicBlockList allocation stats\n"); + fprintf(fout, "BasicBlock and FlowEdge/BasicBlockList allocation stats\n"); fprintf(fout, "---------------------------------------------------\n"); fprintf(fout, "Allocated %6u basic blocks (%7u bytes total, avg %4u bytes per method)\n", BasicBlock::s_Count, diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 80b9729ac3389..bd3a7725619cc 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -2313,21 +2313,21 @@ class Compiler } // Get the index to use as the cache key for sharing throw blocks #endif // !FEATURE_EH_FUNCLETS - // Returns a flowList representing the "EH predecessors" of "blk". These are the normal predecessors of - // "blk", plus one special case: if "blk" is the first block of a handler, considers the predecessor(s) of the first + // Returns a FlowEdge representing the "EH predecessors" of "blk". These are the normal predecessors of + // "blk", plus one special case: if "blk" is the first block of a handler, considers the predecessor(s) of the // first block of the corresponding try region to be "EH predecessors". (If there is a single such predecessor, // for example, we want to consider that the immediate dominator of the catch clause start block, so it's // convenient to also consider it a predecessor.) - flowList* BlockPredsWithEH(BasicBlock* blk); + FlowEdge* BlockPredsWithEH(BasicBlock* blk); // This table is useful for memoization of the method above. - typedef JitHashTable, flowList*> BlockToFlowListMap; - BlockToFlowListMap* m_blockToEHPreds; - BlockToFlowListMap* GetBlockToEHPreds() + typedef JitHashTable, FlowEdge*> BlockToFlowEdgeMap; + BlockToFlowEdgeMap* m_blockToEHPreds; + BlockToFlowEdgeMap* GetBlockToEHPreds() { if (m_blockToEHPreds == nullptr) { - m_blockToEHPreds = new (getAllocator()) BlockToFlowListMap(getAllocator()); + m_blockToEHPreds = new (getAllocator()) BlockToFlowEdgeMap(getAllocator()); } return m_blockToEHPreds; } @@ -4595,7 +4595,7 @@ class Compiler bool fgPrintInlinedMethods; #endif - jitstd::vector* fgPredListSortVector; + jitstd::vector* fgPredListSortVector; //------------------------------------------------------------------------- @@ -4634,11 +4634,11 @@ class Compiler void fgTailMergeThrowsFallThroughHelper(BasicBlock* predBlock, BasicBlock* nonCanonicalBlock, BasicBlock* canonicalBlock, - flowList* predEdge); + FlowEdge* predEdge); void fgTailMergeThrowsJumpToHelper(BasicBlock* predBlock, BasicBlock* nonCanonicalBlock, BasicBlock* canonicalBlock, - flowList* predEdge); + FlowEdge* predEdge); bool fgRetargetBranchesToCanonicalCallFinally(BasicBlock* block, BasicBlock* handler, @@ -5301,13 +5301,13 @@ class Compiler bool fgIsFirstBlockOfFilterOrHandler(BasicBlock* block); - flowList* fgGetPredForBlock(BasicBlock* block, BasicBlock* blockPred); + FlowEdge* fgGetPredForBlock(BasicBlock* block, BasicBlock* blockPred); - flowList* fgGetPredForBlock(BasicBlock* block, BasicBlock* blockPred, flowList*** ptrToPred); + FlowEdge* fgGetPredForBlock(BasicBlock* block, BasicBlock* blockPred, FlowEdge*** ptrToPred); - flowList* fgRemoveRefPred(BasicBlock* block, BasicBlock* blockPred); + FlowEdge* fgRemoveRefPred(BasicBlock* block, BasicBlock* blockPred); - flowList* fgRemoveAllRefPreds(BasicBlock* block, BasicBlock* blockPred); + FlowEdge* fgRemoveAllRefPreds(BasicBlock* block, BasicBlock* blockPred); void fgRemoveBlockAsPred(BasicBlock* block); @@ -5319,11 +5319,11 @@ class Compiler void fgReplacePred(BasicBlock* block, BasicBlock* oldPred, BasicBlock* newPred); - flowList* fgAddRefPred(BasicBlock* block, + FlowEdge* fgAddRefPred(BasicBlock* block, BasicBlock* blockPred, - flowList* oldEdge = nullptr, + FlowEdge* oldEdge = nullptr, bool initializingPreds = false); // Only set to 'true' when we are computing preds in - // fgComputePreds() + // fgLinkBasicBlocks() void fgFindBasicBlocks(); diff --git a/src/coreclr/jit/compmemkind.h b/src/coreclr/jit/compmemkind.h index ad435a96230be..03a8f56d28bc9 100644 --- a/src/coreclr/jit/compmemkind.h +++ b/src/coreclr/jit/compmemkind.h @@ -16,7 +16,7 @@ CompMemKindMacro(InstDesc) CompMemKindMacro(ImpStack) CompMemKindMacro(BasicBlock) CompMemKindMacro(CallArgs) -CompMemKindMacro(FlowList) +CompMemKindMacro(FlowEdge) CompMemKindMacro(TreeStatementList) CompMemKindMacro(SiScope) CompMemKindMacro(DominatorMemory) diff --git a/src/coreclr/jit/dataflow.h b/src/coreclr/jit/dataflow.h index 7e84642dce692..8460ffbd41bca 100644 --- a/src/coreclr/jit/dataflow.h +++ b/src/coreclr/jit/dataflow.h @@ -58,10 +58,10 @@ void DataFlow::ForwardAnalysis(TCallback& callback) } else { - flowList* preds = m_pCompiler->BlockPredsWithEH(block); - for (flowList* pred = preds; pred; pred = pred->flNext) + FlowEdge* preds = m_pCompiler->BlockPredsWithEH(block); + for (FlowEdge* pred = preds; pred; pred = pred->getNextPredEdge()) { - callback.Merge(block, pred->getBlock(), pred->flDupCount); + callback.Merge(block, pred->getSourceBlock(), pred->getDupCount()); } } diff --git a/src/coreclr/jit/fgbasic.cpp b/src/coreclr/jit/fgbasic.cpp index 52f641c08ce82..54de2b54f4868 100644 --- a/src/coreclr/jit/fgbasic.cpp +++ b/src/coreclr/jit/fgbasic.cpp @@ -486,9 +486,9 @@ void Compiler::fgReplaceSwitchJumpTarget(BasicBlock* blockSwitch, BasicBlock* ne // // Create the new edge [newTarget from blockSwitch] // - flowList* const newEdge = fgAddRefPred(newTarget, blockSwitch); + FlowEdge* const newEdge = fgAddRefPred(newTarget, blockSwitch); - // Now set the correct value of newEdge->flDupCount + // Now set the correct value of newEdge's lDupCount // and replace any other jumps in jumpTab[] that go to oldTarget. // i++; @@ -501,11 +501,7 @@ void Compiler::fgReplaceSwitchJumpTarget(BasicBlock* blockSwitch, BasicBlock* ne // jumpTab[i] = newTarget; newTarget->bbRefs++; - - // - // Increment the flDupCount - // - newEdge->flDupCount++; + newEdge->incrementDupCount(); } i++; // Check the next entry in jumpTab[] } @@ -599,10 +595,10 @@ void Compiler::fgReplaceJumpTarget(BasicBlock* block, BasicBlock* newTarget, Bas // // Notes: // -// A block can only appear once in the preds list (for normal preds, not -// cheap preds): if a predecessor has multiple ways to get to this block, then -// flDupCount will be >1, but the block will still appear exactly once. Thus, this -// function assumes that all branches from the predecessor (practically, that all +// A block can only appear once in the preds list. If a predecessor has multiple +// ways to get to this block, then the pred edge DupCount will be >1. +// +// This function assumes that all branches from the predecessor (practically, that all // switch cases that target this block) are changed to branch from the new predecessor, // with the same dup count. // @@ -619,11 +615,11 @@ void Compiler::fgReplacePred(BasicBlock* block, BasicBlock* oldPred, BasicBlock* bool modified = false; - for (flowList* const pred : block->PredEdges()) + for (FlowEdge* const pred : block->PredEdges()) { - if (oldPred == pred->getBlock()) + if (oldPred == pred->getSourceBlock()) { - pred->setBlock(newPred); + pred->setSourceBlock(newPred); modified = true; break; } @@ -2732,7 +2728,7 @@ void Compiler::fgLinkBasicBlocks() // Special args to fgAddRefPred so it will use the initialization fast path. // - flowList* const oldEdge = nullptr; + FlowEdge* const oldEdge = nullptr; bool const initializingPreds = true; for (BasicBlock* const curBBdesc : Blocks()) @@ -5088,9 +5084,9 @@ void Compiler::fgRemoveBlock(BasicBlock* block, bool unreachable) fgRemoveRefPred(succBlock, block); - for (flowList* const pred : block->PredEdges()) + for (FlowEdge* const pred : block->PredEdges()) { - BasicBlock* predBlock = pred->getBlock(); + BasicBlock* predBlock = pred->getSourceBlock(); /* Are we changing a loop backedge into a forward jump? */ @@ -5106,7 +5102,7 @@ void Compiler::fgRemoveBlock(BasicBlock* block, bool unreachable) { // Even if the pred is not a switch, we could have a conditional branch // to the fallthrough, so duplicate there could be preds - for (unsigned i = 0; i < pred->flDupCount; i++) + for (unsigned i = 0; i < pred->getDupCount(); i++) { fgAddRefPred(succBlock, predBlock); } @@ -5269,7 +5265,7 @@ BasicBlock* Compiler::fgConnectFallThrough(BasicBlock* bSrc, BasicBlock* bDst) // if (fgHaveValidEdgeWeights && fgHaveProfileWeights()) { - flowList* const newEdge = fgGetPredForBlock(jmpBlk, bSrc); + FlowEdge* const newEdge = fgGetPredForBlock(jmpBlk, bSrc); jmpBlk->bbWeight = (newEdge->edgeWeightMin() + newEdge->edgeWeightMax()) / 2; if (bSrc->bbWeight == BB_ZERO_WEIGHT) @@ -6091,8 +6087,8 @@ bool Compiler::fgIsBetterFallThrough(BasicBlock* bCur, BasicBlock* bAlt) if (fgHaveValidEdgeWeights) { // We will compare the edge weight for our two choices - flowList* edgeFromAlt = fgGetPredForBlock(bCur, bAlt); - flowList* edgeFromCur = fgGetPredForBlock(bNext, bCur); + FlowEdge* edgeFromAlt = fgGetPredForBlock(bCur, bAlt); + FlowEdge* edgeFromCur = fgGetPredForBlock(bNext, bCur); noway_assert(edgeFromCur != nullptr); noway_assert(edgeFromAlt != nullptr); diff --git a/src/coreclr/jit/fgdiagnostic.cpp b/src/coreclr/jit/fgdiagnostic.cpp index 7fab034eb6fda..0919e2131de8d 100644 --- a/src/coreclr/jit/fgdiagnostic.cpp +++ b/src/coreclr/jit/fgdiagnostic.cpp @@ -21,9 +21,9 @@ void Compiler::fgPrintEdgeWeights() if (bDst->bbPreds != nullptr) { printf(" Edge weights into " FMT_BB " :", bDst->bbNum); - for (flowList* const edge : bDst->PredEdges()) + for (FlowEdge* const edge : bDst->PredEdges()) { - BasicBlock* bSrc = edge->getBlock(); + BasicBlock* bSrc = edge->getSourceBlock(); // This is the control flow edge (bSrc -> bDst) printf(FMT_BB " ", bSrc->bbNum); @@ -48,7 +48,7 @@ void Compiler::fgPrintEdgeWeights() } } printf(")"); - if (edge->flNext != nullptr) + if (edge->getNextPredEdge() != nullptr) { printf(", "); } @@ -1059,9 +1059,9 @@ bool Compiler::fgDumpFlowGraph(Phases phase, PhasePosition pos) targetWeightDivisor = (double)bTarget->bbWeight; } - for (flowList* const edge : bTarget->PredEdges()) + for (FlowEdge* const edge : bTarget->PredEdges()) { - BasicBlock* bSource = edge->getBlock(); + BasicBlock* bSource = edge->getSourceBlock(); double sourceWeightDivisor; if (bSource->bbWeight == BB_ZERO_WEIGHT) { @@ -1110,9 +1110,9 @@ bool Compiler::fgDumpFlowGraph(Phases phase, PhasePosition pos) fprintf(fgxFile, "\n target=\"%d\"", bTarget->bbNum); if (bSource->bbJumpKind == BBJ_SWITCH) { - if (edge->flDupCount >= 2) + if (edge->getDupCount() >= 2) { - fprintf(fgxFile, "\n switchCases=\"%d\"", edge->flDupCount); + fprintf(fgxFile, "\n switchCases=\"%d\"", edge->getDupCount()); } if (bSource->bbJumpSwt->getDefault() == bTarget) { @@ -2502,11 +2502,11 @@ unsigned BBPredsChecker::CheckBBPreds(BasicBlock* block, unsigned curTraversalSt } unsigned blockRefs = 0; - for (flowList* const pred : block->PredEdges()) + for (FlowEdge* const pred : block->PredEdges()) { - blockRefs += pred->flDupCount; + blockRefs += pred->getDupCount(); - BasicBlock* blockPred = pred->getBlock(); + BasicBlock* blockPred = pred->getSourceBlock(); // Make sure this pred is part of the BB list. assert(blockPred->bbTraversalStamp == curTraversalStamp); diff --git a/src/coreclr/jit/fgehopt.cpp b/src/coreclr/jit/fgehopt.cpp index 01a5c5be27cff..4e16bb875131a 100644 --- a/src/coreclr/jit/fgehopt.cpp +++ b/src/coreclr/jit/fgehopt.cpp @@ -2144,15 +2144,15 @@ PhaseStatus Compiler::fgTailMergeThrows() { BasicBlock* const nonCanonicalBlock = iter->GetKey(); BasicBlock* const canonicalBlock = iter->GetValue(); - flowList* nextPredEdge = nullptr; + FlowEdge* nextPredEdge = nullptr; bool updated = false; // Walk pred list of the non canonical block, updating flow to target // the canonical block instead. - for (flowList* predEdge = nonCanonicalBlock->bbPreds; predEdge != nullptr; predEdge = nextPredEdge) + for (FlowEdge* predEdge = nonCanonicalBlock->bbPreds; predEdge != nullptr; predEdge = nextPredEdge) { - BasicBlock* const predBlock = predEdge->getBlock(); - nextPredEdge = predEdge->flNext; + BasicBlock* const predBlock = predEdge->getSourceBlock(); + nextPredEdge = predEdge->getNextPredEdge(); switch (predBlock->bbJumpKind) { @@ -2247,7 +2247,7 @@ PhaseStatus Compiler::fgTailMergeThrows() void Compiler::fgTailMergeThrowsFallThroughHelper(BasicBlock* predBlock, BasicBlock* nonCanonicalBlock, BasicBlock* canonicalBlock, - flowList* predEdge) + FlowEdge* predEdge) { assert(predBlock->bbNext == nonCanonicalBlock); @@ -2290,7 +2290,7 @@ void Compiler::fgTailMergeThrowsFallThroughHelper(BasicBlock* predBlock, void Compiler::fgTailMergeThrowsJumpToHelper(BasicBlock* predBlock, BasicBlock* nonCanonicalBlock, BasicBlock* canonicalBlock, - flowList* predEdge) + FlowEdge* predEdge) { assert(predBlock->bbJumpDest == nonCanonicalBlock); diff --git a/src/coreclr/jit/fgflow.cpp b/src/coreclr/jit/fgflow.cpp index 2f976e4e84bf6..66ec116681232 100644 --- a/src/coreclr/jit/fgflow.cpp +++ b/src/coreclr/jit/fgflow.cpp @@ -17,17 +17,17 @@ // blockPred -- The predecessor block to find in the predecessor list. // // Return Value: -// The flowList edge corresponding to "blockPred". If "blockPred" is not in the predecessor list of "block", +// The FlowEdge edge corresponding to "blockPred". If "blockPred" is not in the predecessor list of "block", // then returns nullptr. // -flowList* Compiler::fgGetPredForBlock(BasicBlock* block, BasicBlock* blockPred) +FlowEdge* Compiler::fgGetPredForBlock(BasicBlock* block, BasicBlock* blockPred) { assert(block); assert(blockPred); - for (flowList* const pred : block->PredEdges()) + for (FlowEdge* const pred : block->PredEdges()) { - if (blockPred == pred->getBlock()) + if (blockPred == pred->getSourceBlock()) { return pred; } @@ -47,22 +47,22 @@ flowList* Compiler::fgGetPredForBlock(BasicBlock* block, BasicBlock* blockPred) // ptrToPred -- Out parameter: set to the address of the pointer that points to the returned predecessor edge. // // Return Value: -// The flowList edge corresponding to "blockPred". If "blockPred" is not in the predecessor list of "block", +// The FlowEdge edge corresponding to "blockPred". If "blockPred" is not in the predecessor list of "block", // then returns nullptr. // -flowList* Compiler::fgGetPredForBlock(BasicBlock* block, BasicBlock* blockPred, flowList*** ptrToPred) +FlowEdge* Compiler::fgGetPredForBlock(BasicBlock* block, BasicBlock* blockPred, FlowEdge*** ptrToPred) { assert(block); assert(blockPred); assert(ptrToPred); - flowList** predPrevAddr; - flowList* pred; + FlowEdge** predPrevAddr; + FlowEdge* pred; for (predPrevAddr = &block->bbPreds, pred = *predPrevAddr; pred != nullptr; - predPrevAddr = &pred->flNext, pred = *predPrevAddr) + predPrevAddr = pred->getNextPredEdgeRef(), pred = *predPrevAddr) { - if (blockPred == pred->getBlock()) + if (blockPred == pred->getSourceBlock()) { *ptrToPred = predPrevAddr; return pred; @@ -94,9 +94,9 @@ flowList* Compiler::fgGetPredForBlock(BasicBlock* block, BasicBlock* blockPred, // -- fgModified is set if a new flow edge is created (but not if an existing flow edge dup count is incremented), // indicating that the flow graph shape has changed. // -flowList* Compiler::fgAddRefPred(BasicBlock* block, +FlowEdge* Compiler::fgAddRefPred(BasicBlock* block, BasicBlock* blockPred, - flowList* oldEdge /* = nullptr */, + FlowEdge* oldEdge /* = nullptr */, bool initializingPreds /* = false */) { assert(block != nullptr); @@ -115,11 +115,11 @@ flowList* Compiler::fgAddRefPred(BasicBlock* block, // Thus, inserting all the edges for a block is quadratic in the number of edges. We need to either // not bother sorting for debuggable code, or sort in optFindNaturalLoops, or better, make the code in // optFindNaturalLoops not depend on order. This also requires ensuring that nobody else has taken a - // dependency on this order. Note also that we don't allow duplicates in the list; we maintain a flDupCount + // dependency on this order. Note also that we don't allow duplicates in the list; we maintain a DupCount // count of duplication. This also necessitates walking the flow list for every edge we add. // - flowList* flow = nullptr; - flowList** listp = &block->bbPreds; + FlowEdge* flow = nullptr; + FlowEdge** listp = &block->bbPreds; if (initializingPreds) { @@ -127,14 +127,14 @@ flowList* Compiler::fgAddRefPred(BasicBlock* block, // increasing blockPred->bbNum order. The only possible // dup list entry is the last one. // - flowList* flowLast = block->bbLastPred; + FlowEdge* flowLast = block->bbLastPred; if (flowLast != nullptr) { - listp = &flowLast->flNext; + listp = flowLast->getNextPredEdgeRef(); - assert(flowLast->getBlock()->bbNum <= blockPred->bbNum); + assert(flowLast->getSourceBlock()->bbNum <= blockPred->bbNum); - if (flowLast->getBlock() == blockPred) + if (flowLast->getSourceBlock() == blockPred) { flow = flowLast; } @@ -144,12 +144,12 @@ flowList* Compiler::fgAddRefPred(BasicBlock* block, { // References are added randomly, so we have to search. // - while ((*listp != nullptr) && ((*listp)->getBlock()->bbNum < blockPred->bbNum)) + while ((*listp != nullptr) && ((*listp)->getSourceBlock()->bbNum < blockPred->bbNum)) { - listp = &(*listp)->flNext; + listp = (*listp)->getNextPredEdgeRef(); } - if ((*listp != nullptr) && ((*listp)->getBlock() == blockPred)) + if ((*listp != nullptr) && ((*listp)->getSourceBlock() == blockPred)) { flow = *listp; } @@ -158,15 +158,15 @@ flowList* Compiler::fgAddRefPred(BasicBlock* block, if (flow != nullptr) { // The predecessor block already exists in the flow list; simply add to its duplicate count. - noway_assert(flow->flDupCount > 0); - flow->flDupCount++; + noway_assert(flow->getDupCount()); + flow->incrementDupCount(); } else { #if MEASURE_BLOCK_SIZE genFlowNodeCnt += 1; - genFlowNodeSize += sizeof(flowList); + genFlowNodeSize += sizeof(FlowEdge); #endif // MEASURE_BLOCK_SIZE // Any changes to the flow graph invalidate the dominator sets. @@ -174,9 +174,9 @@ flowList* Compiler::fgAddRefPred(BasicBlock* block, // Create new edge in the list in the correct ordered location. // - flow = new (this, CMK_FlowList) flowList(blockPred, *listp); - flow->flDupCount = 1; - *listp = flow; + flow = new (this, CMK_FlowEdge) FlowEdge(blockPred, *listp); + flow->incrementDupCount(); + *listp = flow; if (initializingPreds) { @@ -252,7 +252,7 @@ flowList* Compiler::fgAddRefPred(BasicBlock* block, // -- fgModified is set if a flow edge is removed (but not if an existing flow edge dup count is decremented), // indicating that the flow graph shape has changed. // -flowList* Compiler::fgRemoveRefPred(BasicBlock* block, BasicBlock* blockPred) +FlowEdge* Compiler::fgRemoveRefPred(BasicBlock* block, BasicBlock* blockPred) { noway_assert(block != nullptr); noway_assert(blockPred != nullptr); @@ -260,17 +260,17 @@ flowList* Compiler::fgRemoveRefPred(BasicBlock* block, BasicBlock* blockPred) assert(fgPredsComputed); block->bbRefs--; - flowList** ptrToPred; - flowList* pred = fgGetPredForBlock(block, blockPred, &ptrToPred); + FlowEdge** ptrToPred; + FlowEdge* pred = fgGetPredForBlock(block, blockPred, &ptrToPred); noway_assert(pred != nullptr); - noway_assert(pred->flDupCount > 0); + noway_assert(pred->getDupCount() > 0); - pred->flDupCount--; + pred->decrementDupCount(); - if (pred->flDupCount == 0) + if (pred->getDupCount() == 0) { // Splice out the predecessor edge since it's no longer necessary. - *ptrToPred = pred->flNext; + *ptrToPred = pred->getNextPredEdge(); // Any changes to the flow graph invalidate the dominator sets. fgModified = true; @@ -299,23 +299,23 @@ flowList* Compiler::fgRemoveRefPred(BasicBlock* block, BasicBlock* blockPred) // Notes: // block->bbRefs is decremented to account for the reduction in incoming edges. // -flowList* Compiler::fgRemoveAllRefPreds(BasicBlock* block, BasicBlock* blockPred) +FlowEdge* Compiler::fgRemoveAllRefPreds(BasicBlock* block, BasicBlock* blockPred) { assert(block != nullptr); assert(blockPred != nullptr); assert(fgPredsComputed); assert(block->countOfInEdges() > 0); - flowList** ptrToPred; - flowList* pred = fgGetPredForBlock(block, blockPred, &ptrToPred); + FlowEdge** ptrToPred; + FlowEdge* pred = fgGetPredForBlock(block, blockPred, &ptrToPred); assert(pred != nullptr); - assert(pred->flDupCount > 0); + assert(pred->getDupCount() > 0); - assert(block->bbRefs >= pred->flDupCount); - block->bbRefs -= pred->flDupCount; + assert(block->bbRefs >= pred->getDupCount()); + block->bbRefs -= pred->getDupCount(); // Now splice out the predecessor edge. - *ptrToPred = pred->flNext; + *ptrToPred = pred->getNextPredEdge(); // Any changes to the flow graph invalidate the dominator sets. fgModified = true; @@ -351,7 +351,7 @@ void Compiler::fgRemoveBlockAsPred(BasicBlock* block) while (bNext->countOfInEdges() > 0) { - fgRemoveRefPred(bNext, bNext->bbPreds->getBlock()); + fgRemoveRefPred(bNext, bNext->bbPreds->getSourceBlock()); } } diff --git a/src/coreclr/jit/fgopt.cpp b/src/coreclr/jit/fgopt.cpp index f55400dd4479a..e57425f22ba60 100644 --- a/src/coreclr/jit/fgopt.cpp +++ b/src/coreclr/jit/fgopt.cpp @@ -964,7 +964,7 @@ void Compiler::fgComputeDoms() bbRoot.bbPostOrderNum = 0; bbRoot.bbFlags = BBF_EMPTY; - flowList flRoot(&bbRoot, nullptr); + FlowEdge flRoot(&bbRoot, nullptr); fgBBInvPostOrder[0] = &bbRoot; @@ -1018,7 +1018,7 @@ void Compiler::fgComputeDoms() // Process each actual block; don't process the imaginary predecessor block. for (unsigned i = 1; i <= fgBBNumMax; ++i) { - flowList* first = nullptr; + FlowEdge* first = nullptr; BasicBlock* newidom = nullptr; block = fgBBInvPostOrder[i]; @@ -1031,9 +1031,9 @@ void Compiler::fgComputeDoms() } // Pick up the first processed predecessor of the current block. - for (first = block->bbPreds; first != nullptr; first = first->flNext) + for (first = block->bbPreds; first != nullptr; first = first->getNextPredEdge()) { - if (BlockSetOps::IsMember(this, processedBlks, first->getBlock()->bbNum)) + if (BlockSetOps::IsMember(this, processedBlks, first->getSourceBlock()->bbNum)) { break; } @@ -1042,21 +1042,21 @@ void Compiler::fgComputeDoms() // We assume the first processed predecessor will be the // immediate dominator and then compute the forward flow analysis. - newidom = first->getBlock(); - for (flowList* p = block->bbPreds; p != nullptr; p = p->flNext) + newidom = first->getSourceBlock(); + for (FlowEdge* p = block->bbPreds; p != nullptr; p = p->getNextPredEdge()) { - if (p->getBlock() == first->getBlock()) + if (p->getSourceBlock() == first->getSourceBlock()) { continue; } - if (p->getBlock()->bbIDom != nullptr) + if (p->getSourceBlock()->bbIDom != nullptr) { // fgIntersectDom is basically the set intersection between // the dominance sets of the new IDom and the current predecessor // Since the nodes are ordered in DFS inverse post order and // IDom induces a tree, fgIntersectDom actually computes // the lowest common ancestor in the dominator tree. - newidom = fgIntersectDom(p->getBlock(), newidom); + newidom = fgIntersectDom(p->getSourceBlock(), newidom); } } @@ -2562,13 +2562,13 @@ void Compiler::fgRemoveConditionalJump(BasicBlock* block) noway_assert(block->bbJumpKind == BBJ_COND && block->bbJumpDest == block->bbNext); assert(compRationalIRForm == block->IsLIR()); - flowList* flow = fgGetPredForBlock(block->bbNext, block); - noway_assert(flow->flDupCount == 2); + FlowEdge* flow = fgGetPredForBlock(block->bbNext, block); + noway_assert(flow->getDupCount() == 2); // Change the BBJ_COND to BBJ_NONE, and adjust the refCount and dupCount. block->bbJumpKind = BBJ_NONE; --block->bbNext->bbRefs; - --flow->flDupCount; + flow->decrementDupCount(); #ifdef DEBUG block->bbJumpDest = nullptr; @@ -2733,7 +2733,7 @@ bool Compiler::fgOptimizeBranchToEmptyUnconditional(BasicBlock* block, BasicBloc // if (fgHaveValidEdgeWeights && bDest->hasProfileWeight()) { - flowList* edge1 = fgGetPredForBlock(bDest, block); + FlowEdge* edge1 = fgGetPredForBlock(bDest, block); noway_assert(edge1 != nullptr); weight_t edgeWeight; @@ -2770,7 +2770,7 @@ bool Compiler::fgOptimizeBranchToEmptyUnconditional(BasicBlock* block, BasicBloc bDest->bbFlags |= BBF_RUN_RARELY; // Set the RarelyRun flag } - flowList* edge2 = fgGetPredForBlock(bDest->bbJumpDest, bDest); + FlowEdge* edge2 = fgGetPredForBlock(bDest->bbJumpDest, bDest); if (edge2 != nullptr) { @@ -3111,7 +3111,7 @@ bool Compiler::fgOptimizeSwitchBranches(BasicBlock* block) { if (fgHaveValidEdgeWeights) { - flowList* edge = fgGetPredForBlock(bDest, block); + FlowEdge* edge = fgGetPredForBlock(bDest, block); weight_t branchThroughWeight = edge->edgeWeightMin(); if (bDest->bbWeight > branchThroughWeight) @@ -4343,10 +4343,10 @@ bool Compiler::fgOptimizeSwitchJumps() // block->bbJumpKind = BBJ_COND; block->bbJumpDest = dominantTarget; - flowList* const blockToTargetEdge = fgAddRefPred(dominantTarget, block); - flowList* const blockToNewBlockEdge = newBlock->bbPreds; - assert(blockToNewBlockEdge->getBlock() == block); - assert(blockToTargetEdge->getBlock() == block); + FlowEdge* const blockToTargetEdge = fgAddRefPred(dominantTarget, block); + FlowEdge* const blockToNewBlockEdge = newBlock->bbPreds; + assert(blockToNewBlockEdge->getSourceBlock() == block); + assert(blockToTargetEdge->getSourceBlock() == block); // Update profile data // @@ -4363,11 +4363,11 @@ bool Compiler::fgOptimizeSwitchJumps() // one edge in the flowgraph. So we need to subtract off the profile data that now flows // along the peeled edge. // - for (flowList* pred = dominantTarget->bbPreds; pred != nullptr; pred = pred->flNext) + for (FlowEdge* pred = dominantTarget->bbPreds; pred != nullptr; pred = pred->getNextPredEdge()) { - if (pred->getBlock() == newBlock) + if (pred->getSourceBlock() == newBlock) { - if (pred->flDupCount == 1) + if (pred->getDupCount() == 1) { // The only switch case leading to the dominant target was the one we peeled. // So the edge from the switch now has zero weight. @@ -4471,7 +4471,7 @@ bool Compiler::fgExpandRarelyRunBlocks() #endif } - flowList* pred = bPrev->bbPreds; + FlowEdge* pred = bPrev->bbPreds; if (pred != nullptr) { @@ -4483,19 +4483,19 @@ bool Compiler::fgExpandRarelyRunBlocks() if (bPrevPrev == nullptr) { // Initially we select the first block in the bbPreds list - bPrevPrev = pred->getBlock(); + bPrevPrev = pred->getSourceBlock(); continue; } // Walk the flow graph lexically forward from pred->getBlock() // if we find (block == bPrevPrev) then // pred->getBlock() is an earlier predecessor. - for (tmpbb = pred->getBlock(); tmpbb != nullptr; tmpbb = tmpbb->bbNext) + for (tmpbb = pred->getSourceBlock(); tmpbb != nullptr; tmpbb = tmpbb->bbNext) { if (tmpbb == bPrevPrev) { /* We found an earlier predecessor */ - bPrevPrev = pred->getBlock(); + bPrevPrev = pred->getSourceBlock(); break; } else if (tmpbb == bPrev) @@ -4507,7 +4507,7 @@ bool Compiler::fgExpandRarelyRunBlocks() } // Onto the next predecessor - pred = pred->flNext; + pred = pred->getNextPredEdge(); } } @@ -4905,11 +4905,11 @@ bool Compiler::fgReorderBlocks(bool useProfile) // The edge bPrev -> bDest must have a higher minimum weight // than every other edge into bDest // - flowList* edgeFromPrev = fgGetPredForBlock(bDest, bPrev); + FlowEdge* edgeFromPrev = fgGetPredForBlock(bDest, bPrev); noway_assert(edgeFromPrev != nullptr); // Examine all of the other edges into bDest - for (flowList* const edge : bDest->PredEdges()) + for (FlowEdge* const edge : bDest->PredEdges()) { if (edge != edgeFromPrev) { @@ -4997,8 +4997,8 @@ bool Compiler::fgReorderBlocks(bool useProfile) // V // bDest ---------------> [BB08, weight 21] // - flowList* edgeToDest = fgGetPredForBlock(bDest, bPrev); - flowList* edgeToBlock = fgGetPredForBlock(block, bPrev); + FlowEdge* edgeToDest = fgGetPredForBlock(bDest, bPrev); + FlowEdge* edgeToBlock = fgGetPredForBlock(block, bPrev); noway_assert(edgeToDest != nullptr); noway_assert(edgeToBlock != nullptr); // diff --git a/src/coreclr/jit/fgprofile.cpp b/src/coreclr/jit/fgprofile.cpp index bc05a27da850c..d50a0f1b7b7e1 100644 --- a/src/coreclr/jit/fgprofile.cpp +++ b/src/coreclr/jit/fgprofile.cpp @@ -3476,7 +3476,7 @@ void Compiler::fgIncorporateEdgeCounts() // false if the edge weight update was inconsistent with the // edge's current [min,max} // -bool flowList::setEdgeWeightMinChecked(weight_t newWeight, BasicBlock* bDst, weight_t slop, bool* wbUsedSlop) +bool FlowEdge::setEdgeWeightMinChecked(weight_t newWeight, BasicBlock* bDst, weight_t slop, bool* wbUsedSlop) { // Negative weights are nonsensical. // @@ -3498,46 +3498,46 @@ bool flowList::setEdgeWeightMinChecked(weight_t newWeight, BasicBlock* bDst, wei bool result = false; - if ((newWeight <= flEdgeWeightMax) && (newWeight >= flEdgeWeightMin)) + if ((newWeight <= m_edgeWeightMax) && (newWeight >= m_edgeWeightMin)) { - flEdgeWeightMin = newWeight; + m_edgeWeightMin = newWeight; result = true; } else if (slop > 0) { // We allow for a small amount of inaccuracy in block weight counts. - if (flEdgeWeightMax < newWeight) + if (m_edgeWeightMax < newWeight) { // We have already determined that this edge's weight // is less than newWeight, so we just allow for the slop - if (newWeight <= (flEdgeWeightMax + slop)) + if (newWeight <= (m_edgeWeightMax + slop)) { result = true; usedSlop = true; - if (flEdgeWeightMax != BB_ZERO_WEIGHT) + if (m_edgeWeightMax != BB_ZERO_WEIGHT) { - // We will raise flEdgeWeightMin and Max towards newWeight - flEdgeWeightMin = flEdgeWeightMax; - flEdgeWeightMax = newWeight; + // We will raise m_edgeWeightMin and Max towards newWeight + m_edgeWeightMin = m_edgeWeightMax; + m_edgeWeightMax = newWeight; } } } - else if (flEdgeWeightMin > newWeight) + else if (m_edgeWeightMin > newWeight) { // We have already determined that this edge's weight // is more than newWeight, so we just allow for the slop - if ((newWeight + slop) >= flEdgeWeightMin) + if ((newWeight + slop) >= m_edgeWeightMin) { result = true; usedSlop = true; - if (flEdgeWeightMax != BB_ZERO_WEIGHT) + if (m_edgeWeightMax != BB_ZERO_WEIGHT) { - // We will lower flEdgeWeightMin towards newWeight + // We will lower m_edgeWeightMin towards newWeight // But not below zero. // - flEdgeWeightMin = max(BB_ZERO_WEIGHT, newWeight); + m_edgeWeightMin = max(BB_ZERO_WEIGHT, newWeight); } } } @@ -3547,8 +3547,8 @@ bool flowList::setEdgeWeightMinChecked(weight_t newWeight, BasicBlock* bDst, wei // if (result) { - assert((flEdgeWeightMax == BB_ZERO_WEIGHT) || - ((newWeight <= flEdgeWeightMax) && (newWeight >= flEdgeWeightMin))); + assert((m_edgeWeightMax == BB_ZERO_WEIGHT) || + ((newWeight <= m_edgeWeightMax) && (newWeight >= m_edgeWeightMin))); } } @@ -3560,14 +3560,14 @@ bool flowList::setEdgeWeightMinChecked(weight_t newWeight, BasicBlock* bDst, wei #if DEBUG if (result) { - JITDUMP("Updated min weight of " FMT_BB " -> " FMT_BB " to [" FMT_WT ".." FMT_WT "]\n", getBlock()->bbNum, - bDst->bbNum, flEdgeWeightMin, flEdgeWeightMax); + JITDUMP("Updated min weight of " FMT_BB " -> " FMT_BB " to [" FMT_WT ".." FMT_WT "]\n", getSourceBlock()->bbNum, + bDst->bbNum, m_edgeWeightMin, m_edgeWeightMax); } else { JITDUMP("Not adjusting min weight of " FMT_BB " -> " FMT_BB "; new value " FMT_WT " not in range [" FMT_WT ".." FMT_WT "] (+/- " FMT_WT ")\n", - getBlock()->bbNum, bDst->bbNum, newWeight, flEdgeWeightMin, flEdgeWeightMax, slop); + getSourceBlock()->bbNum, bDst->bbNum, newWeight, m_edgeWeightMin, m_edgeWeightMax, slop); result = false; // break here } #endif // DEBUG @@ -3589,7 +3589,7 @@ bool flowList::setEdgeWeightMinChecked(weight_t newWeight, BasicBlock* bDst, wei // false if the edge weight update was inconsistent with the // edge's current [min,max} // -bool flowList::setEdgeWeightMaxChecked(weight_t newWeight, BasicBlock* bDst, weight_t slop, bool* wbUsedSlop) +bool FlowEdge::setEdgeWeightMaxChecked(weight_t newWeight, BasicBlock* bDst, weight_t slop, bool* wbUsedSlop) { // Negative weights are nonsensical. // @@ -3611,44 +3611,44 @@ bool flowList::setEdgeWeightMaxChecked(weight_t newWeight, BasicBlock* bDst, wei bool result = false; - if ((newWeight >= flEdgeWeightMin) && (newWeight <= flEdgeWeightMax)) + if ((newWeight >= m_edgeWeightMin) && (newWeight <= m_edgeWeightMax)) { - flEdgeWeightMax = newWeight; + m_edgeWeightMax = newWeight; result = true; } else if (slop > 0) { // We allow for a small amount of inaccuracy in block weight counts. - if (flEdgeWeightMax < newWeight) + if (m_edgeWeightMax < newWeight) { // We have already determined that this edge's weight // is less than newWeight, so we just allow for the slop - if (newWeight <= (flEdgeWeightMax + slop)) + if (newWeight <= (m_edgeWeightMax + slop)) { result = true; usedSlop = true; - if (flEdgeWeightMax != BB_ZERO_WEIGHT) + if (m_edgeWeightMax != BB_ZERO_WEIGHT) { - // We will allow this to raise flEdgeWeightMax towards newWeight - flEdgeWeightMax = newWeight; + // We will allow this to raise m_edgeWeightMax towards newWeight + m_edgeWeightMax = newWeight; } } } - else if (flEdgeWeightMin > newWeight) + else if (m_edgeWeightMin > newWeight) { // We have already determined that this edge's weight // is more than newWeight, so we just allow for the slop - if ((newWeight + slop) >= flEdgeWeightMin) + if ((newWeight + slop) >= m_edgeWeightMin) { result = true; usedSlop = true; - if (flEdgeWeightMax != BB_ZERO_WEIGHT) + if (m_edgeWeightMax != BB_ZERO_WEIGHT) { - // We will allow this to lower flEdgeWeightMin and Max towards newWeight - flEdgeWeightMax = flEdgeWeightMin; - flEdgeWeightMin = newWeight; + // We will allow this to lower m_edgeWeightMin and Max towards newWeight + m_edgeWeightMax = m_edgeWeightMin; + m_edgeWeightMin = newWeight; } } } @@ -3657,8 +3657,8 @@ bool flowList::setEdgeWeightMaxChecked(weight_t newWeight, BasicBlock* bDst, wei // the newWeight is in new range [Min..Max] or fgEdgeWeightMax is zero if (result) { - assert((flEdgeWeightMax == BB_ZERO_WEIGHT) || - ((newWeight <= flEdgeWeightMax) && (newWeight >= flEdgeWeightMin))); + assert((m_edgeWeightMax == BB_ZERO_WEIGHT) || + ((newWeight <= m_edgeWeightMax) && (newWeight >= m_edgeWeightMin))); } } @@ -3670,14 +3670,14 @@ bool flowList::setEdgeWeightMaxChecked(weight_t newWeight, BasicBlock* bDst, wei #if DEBUG if (result) { - JITDUMP("Updated max weight of " FMT_BB " -> " FMT_BB " to [" FMT_WT ".." FMT_WT "]\n", getBlock()->bbNum, - bDst->bbNum, flEdgeWeightMin, flEdgeWeightMax); + JITDUMP("Updated max weight of " FMT_BB " -> " FMT_BB " to [" FMT_WT ".." FMT_WT "]\n", getSourceBlock()->bbNum, + bDst->bbNum, m_edgeWeightMin, m_edgeWeightMax); } else { JITDUMP("Not adjusting max weight of " FMT_BB " -> " FMT_BB "; new value " FMT_WT " not in range [" FMT_WT ".." FMT_WT "] (+/- " FMT_WT ")\n", - getBlock()->bbNum, bDst->bbNum, newWeight, flEdgeWeightMin, flEdgeWeightMax, slop); + getSourceBlock()->bbNum, bDst->bbNum, newWeight, m_edgeWeightMin, m_edgeWeightMax, slop); result = false; // break here } #endif // DEBUG @@ -3686,26 +3686,26 @@ bool flowList::setEdgeWeightMaxChecked(weight_t newWeight, BasicBlock* bDst, wei } //------------------------------------------------------------------------ -// setEdgeWeights: Sets the minimum lower (flEdgeWeightMin) value -// and the maximum upper (flEdgeWeightMax) value +// setEdgeWeights: Sets the minimum lower (m_edgeWeightMin) value +// and the maximum upper (m_edgeWeightMax) value // Asserts that the max value is greater or equal to the min value // // Arguments: -// theMinWeight - the new minimum lower (flEdgeWeightMin) -// theMaxWeight - the new maximum upper (flEdgeWeightMin) +// theMinWeight - the new minimum lower (m_edgeWeightMin) +// theMaxWeight - the new maximum upper (m_edgeWeightMin) // bDst - the destination block for the edge // -void flowList::setEdgeWeights(weight_t theMinWeight, weight_t theMaxWeight, BasicBlock* bDst) +void FlowEdge::setEdgeWeights(weight_t theMinWeight, weight_t theMaxWeight, BasicBlock* bDst) { assert(theMinWeight <= theMaxWeight); assert(theMinWeight >= 0.0); assert(theMaxWeight >= 0.0); - JITDUMP("Setting edge weights for " FMT_BB " -> " FMT_BB " to [" FMT_WT " .. " FMT_WT "]\n", getBlock()->bbNum, - bDst->bbNum, theMinWeight, theMaxWeight); + JITDUMP("Setting edge weights for " FMT_BB " -> " FMT_BB " to [" FMT_WT " .. " FMT_WT "]\n", + getSourceBlock()->bbNum, bDst->bbNum, theMinWeight, theMaxWeight); - flEdgeWeightMin = theMinWeight; - flEdgeWeightMax = theMaxWeight; + m_edgeWeightMin = theMinWeight; + m_edgeWeightMax = theMaxWeight; } //------------------------------------------------------------- @@ -3796,7 +3796,7 @@ bool Compiler::fgComputeMissingBlockWeights(weight_t* returnWeight) if (bDst->countOfInEdges() == 1) { // Only one block flows into bDst - bSrc = bDst->bbPreds->getBlock(); + bSrc = bDst->bbPreds->getSourceBlock(); // Does this block flow into only one other block if (bSrc->bbJumpKind == BBJ_NONE) @@ -3838,7 +3838,7 @@ bool Compiler::fgComputeMissingBlockWeights(weight_t* returnWeight) // Does only one block flow into bOnlyNext if (bOnlyNext->countOfInEdges() == 1) { - noway_assert(bOnlyNext->bbPreds->getBlock() == bDst); + noway_assert(bOnlyNext->bbPreds->getSourceBlock() == bDst); // We know the exact weight of bDst newWeight = bOnlyNext->bbWeight; @@ -3850,7 +3850,7 @@ bool Compiler::fgComputeMissingBlockWeights(weight_t* returnWeight) // an exception is thrown, and thus should inherit weight. if (bbIsHandlerBeg(bDst)) { - bSrc = bDst->bbPreds->getBlock(); + bSrc = bDst->bbPreds->getSourceBlock(); // To minimize asmdiffs for now, modify weights only if splitting. if (fgFirstColdBlock != nullptr) @@ -4024,7 +4024,7 @@ PhaseStatus Compiler::fgComputeEdgeWeights() JITDUMP("Initial weight assignments\n\n"); - // Now we will compute the initial flEdgeWeightMin and flEdgeWeightMax values + // Now we will compute the initial m_edgeWeightMin and m_edgeWeightMax values for (bDst = fgFirstBB; bDst != nullptr; bDst = bDst->bbNext) { weight_t bDstWeight = bDst->bbWeight; @@ -4037,11 +4037,11 @@ PhaseStatus Compiler::fgComputeEdgeWeights() bDstWeight -= fgCalledCount; } - for (flowList* const edge : bDst->PredEdges()) + for (FlowEdge* const edge : bDst->PredEdges()) { bool assignOK = true; - bSrc = edge->getBlock(); + bSrc = edge->getSourceBlock(); // We are processing the control flow edge (bSrc -> bDst) numEdges++; @@ -4117,18 +4117,18 @@ PhaseStatus Compiler::fgComputeEdgeWeights() JITDUMP("\n -- step 1 --\n"); for (bDst = fgFirstBB; bDst != nullptr; bDst = bDst->bbNext) { - for (flowList* const edge : bDst->PredEdges()) + for (FlowEdge* const edge : bDst->PredEdges()) { bool assignOK = true; // We are processing the control flow edge (bSrc -> bDst) - bSrc = edge->getBlock(); + bSrc = edge->getSourceBlock(); slop = BasicBlock::GetSlopFraction(bSrc, bDst) + 1; if (bSrc->bbJumpKind == BBJ_COND) { weight_t diff; - flowList* otherEdge; + FlowEdge* otherEdge; BasicBlock* otherDst; if (bSrc->bbNext == bDst) { @@ -4149,7 +4149,7 @@ PhaseStatus Compiler::fgComputeEdgeWeights() if (assignOK) { - // Adjust edge->flEdgeWeightMin up or adjust otherEdge->flEdgeWeightMax down + // Adjust edge->m_edgeWeightMin up or adjust otherEdge->m_edgeWeightMax down diff = bSrc->bbWeight - (edge->edgeWeightMin() + otherEdge->edgeWeightMax()); if (diff > 0) { @@ -4162,7 +4162,7 @@ PhaseStatus Compiler::fgComputeEdgeWeights() slop, &usedSlop); } - // Adjust otherEdge->flEdgeWeightMin up or adjust edge->flEdgeWeightMax down + // Adjust otherEdge->m_edgeWeightMin up or adjust edge->m_edgeWeightMax down diff = bSrc->bbWeight - (otherEdge->edgeWeightMin() + edge->edgeWeightMax()); if (diff > 0) { @@ -4184,7 +4184,7 @@ PhaseStatus Compiler::fgComputeEdgeWeights() goto EARLY_EXIT; } #ifdef DEBUG - // Now edge->flEdgeWeightMin and otherEdge->flEdgeWeightMax) should add up to bSrc->bbWeight + // Now edge->m_edgeWeightMin and otherEdge->m_edgeWeightMax) should add up to bSrc->bbWeight diff = bSrc->bbWeight - (edge->edgeWeightMin() + otherEdge->edgeWeightMax()); if (!((-slop) <= diff) && (diff <= slop)) @@ -4195,7 +4195,7 @@ PhaseStatus Compiler::fgComputeEdgeWeights() otherEdge->edgeWeightMax(), diff, slop); } - // Now otherEdge->flEdgeWeightMin and edge->flEdgeWeightMax) should add up to bSrc->bbWeight + // Now otherEdge->m_edgeWeightMin and edge->m_edgeWeightMax) should add up to bSrc->bbWeight diff = bSrc->bbWeight - (otherEdge->edgeWeightMin() + edge->edgeWeightMax()); if (!((-slop) <= diff) && (diff <= slop)) { @@ -4235,24 +4235,24 @@ PhaseStatus Compiler::fgComputeEdgeWeights() weight_t maxEdgeWeightSum = 0; // Calculate the sums of the minimum and maximum edge weights - for (flowList* const edge : bDst->PredEdges()) + for (FlowEdge* const edge : bDst->PredEdges()) { maxEdgeWeightSum += edge->edgeWeightMax(); minEdgeWeightSum += edge->edgeWeightMin(); } - // maxEdgeWeightSum is the sum of all flEdgeWeightMax values into bDst - // minEdgeWeightSum is the sum of all flEdgeWeightMin values into bDst + // maxEdgeWeightSum is the sum of all m_edgeWeightMax values into bDst + // minEdgeWeightSum is the sum of all m_edgeWeightMin values into bDst - for (flowList* const edge : bDst->PredEdges()) + for (FlowEdge* const edge : bDst->PredEdges()) { bool assignOK = true; // We are processing the control flow edge (bSrc -> bDst) - bSrc = edge->getBlock(); + bSrc = edge->getSourceBlock(); slop = BasicBlock::GetSlopFraction(bSrc, bDst) + 1; - // otherMaxEdgesWeightSum is the sum of all of the other edges flEdgeWeightMax values + // otherMaxEdgesWeightSum is the sum of all of the other edges m_edgeWeightMax values // This can be used to compute a lower bound for our minimum edge weight // weight_t const otherMaxEdgesWeightSum = maxEdgeWeightSum - edge->edgeWeightMax(); @@ -4261,7 +4261,7 @@ PhaseStatus Compiler::fgComputeEdgeWeights() { if (bDstWeight >= otherMaxEdgesWeightSum) { - // minWeightCalc is our minWeight when every other path to bDst takes it's flEdgeWeightMax + // minWeightCalc is our minWeight when every other path to bDst takes it's m_edgeWeightMax // value weight_t minWeightCalc = (weight_t)(bDstWeight - otherMaxEdgesWeightSum); if (minWeightCalc > edge->edgeWeightMin()) @@ -4271,7 +4271,7 @@ PhaseStatus Compiler::fgComputeEdgeWeights() } } - // otherMinEdgesWeightSum is the sum of all of the other edges flEdgeWeightMin values + // otherMinEdgesWeightSum is the sum of all of the other edges m_edgeWeightMin values // This can be used to compute an upper bound for our maximum edge weight // weight_t const otherMinEdgesWeightSum = minEdgeWeightSum - edge->edgeWeightMin(); @@ -4280,7 +4280,7 @@ PhaseStatus Compiler::fgComputeEdgeWeights() { if (bDstWeight >= otherMinEdgesWeightSum) { - // maxWeightCalc is our maxWeight when every other path to bDst takes it's flEdgeWeightMin + // maxWeightCalc is our maxWeight when every other path to bDst takes it's m_edgeWeightMin // value weight_t maxWeightCalc = (weight_t)(bDstWeight - otherMinEdgesWeightSum); if (maxWeightCalc < edge->edgeWeightMax()) @@ -4303,7 +4303,7 @@ PhaseStatus Compiler::fgComputeEdgeWeights() goto EARLY_EXIT; } - // When flEdgeWeightMin equals flEdgeWeightMax we have a "good" edge weight + // When m_edgeWeightMin equals m_edgeWeightMax we have a "good" edge weight if (edge->edgeWeightMin() == edge->edgeWeightMax()) { // Count how many "good" edge weights we have @@ -4369,7 +4369,7 @@ EARLY_EXIT:; { if (bDst->bbPreds != nullptr) { - for (flowList* const edge : bDst->PredEdges()) + for (FlowEdge* const edge : bDst->PredEdges()) { // This is the control flow edge (edge->getBlock() -> bDst) @@ -4609,7 +4609,7 @@ bool Compiler::fgDebugCheckIncomingProfileData(BasicBlock* block) weight_t incomingWeightMax = 0; bool foundPreds = false; - for (flowList* const predEdge : block->PredEdges()) + for (FlowEdge* const predEdge : block->PredEdges()) { incomingWeightMin += predEdge->edgeWeightMin(); incomingWeightMax += predEdge->edgeWeightMax(); @@ -4691,7 +4691,7 @@ bool Compiler::fgDebugCheckOutgoingProfileData(BasicBlock* block) for (unsigned i = 0; i < numSuccs; i++) { BasicBlock* succBlock = block->GetSucc(i, this); - flowList* succEdge = fgGetPredForBlock(succBlock, block); + FlowEdge* succEdge = fgGetPredForBlock(succBlock, block); if (succEdge == nullptr) { diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index b2d01c7811a22..fbc2d94078dd1 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -3171,9 +3171,9 @@ BasicBlock* Compiler::fgGetDomSpeculatively(const BasicBlock* block) BasicBlock* lastReachablePred = nullptr; // Check if we have unreachable preds - for (const flowList* predEdge : block->PredEdges()) + for (const FlowEdge* predEdge : block->PredEdges()) { - BasicBlock* predBlock = predEdge->getBlock(); + BasicBlock* predBlock = predEdge->getSourceBlock(); if (predBlock == block) { continue; diff --git a/src/coreclr/jit/jit.h b/src/coreclr/jit/jit.h index 7bd1647cd767e..eef88bee6c977 100644 --- a/src/coreclr/jit/jit.h +++ b/src/coreclr/jit/jit.h @@ -428,7 +428,7 @@ class GlobalJitOptions // the number of loop exits, etc. #define DATAFLOW_ITER 0 // Count iterations in lexical CSE and constant folding dataflow. #define DISPLAY_SIZES 0 // Display generated code, data, and GC information sizes. -#define MEASURE_BLOCK_SIZE 0 // Collect stats about basic block and flowList node sizes and memory allocations. +#define MEASURE_BLOCK_SIZE 0 // Collect stats about basic block and FlowEdge node sizes and memory allocations. #define MEASURE_FATAL 0 // Count the number of calls to fatal(), including NYIs and noway_asserts. #define MEASURE_NODE_SIZE 0 // Collect stats about GenTree node allocations. #define MEASURE_PTRTAB_SIZE 0 // Collect stats about GC pointer table allocations. diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 79c6657717694..b25165f3f38b0 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -706,7 +706,7 @@ GenTree* Lowering::LowerSwitch(GenTree* node) // Fix the pred for the default case: the default block target still has originalSwitchBB // as a predecessor, but the fgSplitBlockAfterStatement() moved all predecessors to point // to afterDefaultCondBlock. - flowList* oldEdge = comp->fgRemoveRefPred(jumpTab[jumpCnt - 1], afterDefaultCondBlock); + FlowEdge* oldEdge = comp->fgRemoveRefPred(jumpTab[jumpCnt - 1], afterDefaultCondBlock); comp->fgAddRefPred(jumpTab[jumpCnt - 1], originalSwitchBB, oldEdge); bool useJumpSequence = jumpCnt < minSwitchTabJumpCnt; @@ -798,7 +798,7 @@ GenTree* Lowering::LowerSwitch(GenTree* node) // Remove the switch from the predecessor list of this case target's block. // We'll add the proper new predecessor edge later. - flowList* oldEdge = comp->fgRemoveRefPred(jumpTab[i], afterDefaultCondBlock); + FlowEdge* oldEdge = comp->fgRemoveRefPred(jumpTab[i], afterDefaultCondBlock); if (jumpTab[i] == followingBB) { diff --git a/src/coreclr/jit/lsra.cpp b/src/coreclr/jit/lsra.cpp index d8754cb3d2655..ecc946c65a1ff 100644 --- a/src/coreclr/jit/lsra.cpp +++ b/src/coreclr/jit/lsra.cpp @@ -7796,7 +7796,8 @@ void LinearScan::handleOutgoingCriticalEdges(BasicBlock* block) else if (liveOnlyAtSplitEdge) { // Is the var live only at those target blocks which are connected by a split edge to this block - liveOnlyAtSplitEdge = ((succBlock->bbPreds->flNext == nullptr) && (succBlock != compiler->fgFirstBB)); + liveOnlyAtSplitEdge = + ((succBlock->bbPreds->getNextPredEdge() == nullptr) && (succBlock != compiler->fgFirstBB)); } regNumber toReg = getVarReg(getInVarToRegMap(succBlock->bbNum), outResolutionSetVarIndex); @@ -7901,7 +7902,7 @@ void LinearScan::handleOutgoingCriticalEdges(BasicBlock* block) // Any "diffResolutionSet" resolution for a block with no other predecessors will be handled later // as split resolution. - if ((succBlock->bbPreds->flNext == nullptr) && (succBlock != compiler->fgFirstBB)) + if ((succBlock->bbPreds->getNextPredEdge() == nullptr) && (succBlock != compiler->fgFirstBB)) { continue; } @@ -10839,8 +10840,8 @@ void LinearScan::verifyFinalAllocation() { dumpRegRecordTitle(); printf(shortRefPositionFormat, 0, 0); - assert(currentBlock->bbPreds != nullptr && currentBlock->bbPreds->getBlock() != nullptr); - printf(bbRefPosFormat, currentBlock->bbNum, currentBlock->bbPreds->getBlock()->bbNum); + assert(currentBlock->bbPreds != nullptr && currentBlock->bbPreds->getSourceBlock() != nullptr); + printf(bbRefPosFormat, currentBlock->bbNum, currentBlock->bbPreds->getSourceBlock()->bbNum); dumpRegRecords(); } diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index efe8a77a12c68..4d207050a8875 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -13091,7 +13091,7 @@ Compiler::FoldResult Compiler::fgFoldConditional(BasicBlock* block) // and we have already computed the edge weights, so // we will try to adjust some of the weights // - flowList* edgeTaken = fgGetPredForBlock(bTaken, block); + FlowEdge* edgeTaken = fgGetPredForBlock(bTaken, block); BasicBlock* bUpdated = nullptr; // non-NULL if we updated the weight of an internal block // We examine the taken edge (block -> bTaken) @@ -13133,7 +13133,7 @@ Compiler::FoldResult Compiler::fgFoldConditional(BasicBlock* block) weight_t newMinWeight; weight_t newMaxWeight; - flowList* edge; + FlowEdge* edge; // Now fix the weights of the edges out of 'bUpdated' switch (bUpdated->bbJumpKind) { diff --git a/src/coreclr/jit/optimizer.cpp b/src/coreclr/jit/optimizer.cpp index 182ccccb4df2d..36aa1b1fde4af 100644 --- a/src/coreclr/jit/optimizer.cpp +++ b/src/coreclr/jit/optimizer.cpp @@ -163,18 +163,18 @@ void Compiler::optScaleLoopBlocks(BasicBlock* begBlk, BasicBlock* endBlk) #endif // Build list of back edges for block begBlk. - flowList* backedgeList = nullptr; + FlowEdge* backedgeList = nullptr; for (BasicBlock* const predBlock : begBlk->PredBlocks()) { // Is this a back edge? if (predBlock->bbNum >= begBlk->bbNum) { - backedgeList = new (this, CMK_FlowList) flowList(predBlock, backedgeList); + backedgeList = new (this, CMK_FlowEdge) FlowEdge(predBlock, backedgeList); #if MEASURE_BLOCK_SIZE genFlowNodeCnt += 1; - genFlowNodeSize += sizeof(flowList); + genFlowNodeSize += sizeof(FlowEdge); #endif // MEASURE_BLOCK_SIZE } } @@ -217,9 +217,9 @@ void Compiler::optScaleLoopBlocks(BasicBlock* begBlk, BasicBlock* endBlk) bool reachable = false; bool dominates = false; - for (flowList* tmp = backedgeList; tmp != nullptr; tmp = tmp->flNext) + for (FlowEdge* tmp = backedgeList; tmp != nullptr; tmp = tmp->getNextPredEdge()) { - BasicBlock* backedge = tmp->getBlock(); + BasicBlock* backedge = tmp->getSourceBlock(); reachable |= fgReachable(curBlk, backedge); dominates |= fgDominate(curBlk, backedge); @@ -2021,8 +2021,8 @@ class LoopSearch // This must be a block we inserted to connect fall-through after moving blocks. // To determine if it's in the loop or not, use the number of its unique predecessor // block. - assert(block->bbPreds->getBlock() == block->bbPrev); - assert(block->bbPreds->flNext == nullptr); + assert(block->bbPreds->getSourceBlock() == block->bbPrev); + assert(block->bbPreds->getNextPredEdge() == nullptr); return block->bbPrev->bbNum; } return block->bbNum; @@ -5201,8 +5201,8 @@ bool Compiler::optInvertWhileLoop(BasicBlock* block) weight_t const testToNextWeight = weightNext * testToNextLikelihood; weight_t const testToAfterWeight = weightNext * testToAfterLikelihood; - flowList* const edgeTestToNext = fgGetPredForBlock(bTest->bbJumpDest, bTest); - flowList* const edgeTestToAfter = fgGetPredForBlock(bTest->bbNext, bTest); + FlowEdge* const edgeTestToNext = fgGetPredForBlock(bTest->bbJumpDest, bTest); + FlowEdge* const edgeTestToAfter = fgGetPredForBlock(bTest->bbNext, bTest); JITDUMP("Setting weight of " FMT_BB " -> " FMT_BB " to " FMT_WT " (iterate loop)\n", bTest->bbNum, bTest->bbJumpDest->bbNum, testToNextWeight); @@ -5222,8 +5222,8 @@ bool Compiler::optInvertWhileLoop(BasicBlock* block) weight_t const blockToNextWeight = weightBlock * blockToNextLikelihood; weight_t const blockToAfterWeight = weightBlock * blockToAfterLikelihood; - flowList* const edgeBlockToNext = fgGetPredForBlock(bNewCond->bbNext, bNewCond); - flowList* const edgeBlockToAfter = fgGetPredForBlock(bNewCond->bbJumpDest, bNewCond); + FlowEdge* const edgeBlockToNext = fgGetPredForBlock(bNewCond->bbNext, bNewCond); + FlowEdge* const edgeBlockToAfter = fgGetPredForBlock(bNewCond->bbJumpDest, bNewCond); JITDUMP("Setting weight of " FMT_BB " -> " FMT_BB " to " FMT_WT " (enter loop)\n", bNewCond->bbNum, bNewCond->bbNext->bbNum, blockToNextWeight); @@ -8166,8 +8166,8 @@ bool Compiler::fgCreateLoopPreHeader(unsigned lnum) if (useEdgeWeights) { - const flowList* edgeToEntry = fgGetPredForBlock(entry, head); - const flowList* edgeToSkipLoop = fgGetPredForBlock(skipLoopBlock, head); + const FlowEdge* edgeToEntry = fgGetPredForBlock(entry, head); + const FlowEdge* edgeToSkipLoop = fgGetPredForBlock(skipLoopBlock, head); noway_assert(edgeToEntry != nullptr); noway_assert(edgeToSkipLoop != nullptr); @@ -8385,12 +8385,12 @@ bool Compiler::fgCreateLoopPreHeader(unsigned lnum) } } - flowList* const edgeToPreHeader = fgGetPredForBlock(preHead, head); + FlowEdge* const edgeToPreHeader = fgGetPredForBlock(preHead, head); noway_assert(edgeToPreHeader != nullptr); edgeToPreHeader->setEdgeWeights(preHead->bbWeight, preHead->bbWeight, preHead); noway_assert(fgGetPredForBlock(entry, preHead) == nullptr); - flowList* const edgeFromPreHeader = fgAddRefPred(entry, preHead); + FlowEdge* const edgeFromPreHeader = fgAddRefPred(entry, preHead); edgeFromPreHeader->setEdgeWeights(preHead->bbWeight, preHead->bbWeight, entry); /* @@ -9541,8 +9541,8 @@ void OptBoolsDsc::optOptimizeBoolsUpdateTrees() { // Update edges if m_b1: BBJ_COND and m_b2: BBJ_COND - flowList* edge1 = m_comp->fgGetPredForBlock(m_b1->bbJumpDest, m_b1); - flowList* edge2; + FlowEdge* edge1 = m_comp->fgGetPredForBlock(m_b1->bbJumpDest, m_b1); + FlowEdge* edge2; if (m_sameTarget) { diff --git a/src/coreclr/jit/ssabuilder.cpp b/src/coreclr/jit/ssabuilder.cpp index 9edb34f0157ef..845750b6b84eb 100644 --- a/src/coreclr/jit/ssabuilder.cpp +++ b/src/coreclr/jit/ssabuilder.cpp @@ -252,11 +252,11 @@ void SsaBuilder::ComputeImmediateDom(BasicBlock** postOrder, int count) // Find the first processed predecessor block. BasicBlock* predBlock = nullptr; - for (flowList* pred = m_pCompiler->BlockPredsWithEH(block); pred; pred = pred->flNext) + for (FlowEdge* pred = m_pCompiler->BlockPredsWithEH(block); pred; pred = pred->getNextPredEdge()) { - if (BitVecOps::IsMember(&m_visitedTraits, m_visited, pred->getBlock()->bbNum)) + if (BitVecOps::IsMember(&m_visitedTraits, m_visited, pred->getSourceBlock()->bbNum)) { - predBlock = pred->getBlock(); + predBlock = pred->getSourceBlock(); break; } } @@ -269,11 +269,11 @@ void SsaBuilder::ComputeImmediateDom(BasicBlock** postOrder, int count) // Intersect DOM, if computed, for all predecessors. BasicBlock* bbIDom = predBlock; - for (flowList* pred = m_pCompiler->BlockPredsWithEH(block); pred; pred = pred->flNext) + for (FlowEdge* pred = m_pCompiler->BlockPredsWithEH(block); pred; pred = pred->getNextPredEdge()) { - if (predBlock != pred->getBlock()) + if (predBlock != pred->getSourceBlock()) { - BasicBlock* domAncestor = IntersectDom(pred->getBlock(), bbIDom); + BasicBlock* domAncestor = IntersectDom(pred->getSourceBlock(), bbIDom); // The result may be NULL if "block" and "pred->getBlock()" are part of a // cycle -- neither is guaranteed ordered wrt the other in reverse postorder, // so we may be computing the IDom of "block" before the IDom of "pred->getBlock()" has @@ -341,10 +341,10 @@ void SsaBuilder::ComputeDominanceFrontiers(BasicBlock** postOrder, int count, Bl // of its immediate predecessors. If there are zero or one preds, then there // is no pred, or else the single pred dominates "block", so no B2 exists. - flowList* blockPreds = m_pCompiler->BlockPredsWithEH(block); + FlowEdge* blockPreds = m_pCompiler->BlockPredsWithEH(block); // If block has 0/1 predecessor, skip. - if ((blockPreds == nullptr) || (blockPreds->flNext == nullptr)) + if ((blockPreds == nullptr) || (blockPreds->getNextPredEdge() == nullptr)) { DBG_SSA_JITDUMP(" Has %d preds; skipping.\n", blockPreds == nullptr ? 0 : 1); continue; @@ -353,9 +353,9 @@ void SsaBuilder::ComputeDominanceFrontiers(BasicBlock** postOrder, int count, Bl // Otherwise, there are > 1 preds. Each is a candidate B2 in the definition -- // *unless* it dominates "block"/B3. - for (flowList* pred = blockPreds; pred != nullptr; pred = pred->flNext) + for (FlowEdge* pred = blockPreds; pred != nullptr; pred = pred->getNextPredEdge()) { - DBG_SSA_JITDUMP(" Considering predecessor " FMT_BB ".\n", pred->getBlock()->bbNum); + DBG_SSA_JITDUMP(" Considering predecessor " FMT_BB ".\n", pred->getSourceBlock()->bbNum); // If we've found a B2, then consider the possible B1's. We start with // B2, since a block dominates itself, then traverse upwards in the dominator @@ -365,7 +365,7 @@ void SsaBuilder::ComputeDominanceFrontiers(BasicBlock** postOrder, int count, Bl // Along this way, make "block"/B3 part of the dom frontier of the B1. // When we reach this immediate dominator, the definition no longer applies, since this // potential B1 *does* dominate "block"/B3, so we stop. - for (BasicBlock* b1 = pred->getBlock(); (b1 != nullptr) && (b1 != block->bbIDom); // !root && !loop + for (BasicBlock* b1 = pred->getSourceBlock(); (b1 != nullptr) && (b1 != block->bbIDom); // !root && !loop b1 = b1->bbIDom) { DBG_SSA_JITDUMP(" Adding " FMT_BB " to dom frontier of pred dom " FMT_BB ".\n", block->bbNum, diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index cd91c27b117c8..8e8d372cd5e74 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -7562,9 +7562,9 @@ struct ValueNumberState } bool allNonLoopPredsDone = true; - for (flowList* pred = m_comp->BlockPredsWithEH(cand); pred != nullptr; pred = pred->flNext) + for (FlowEdge* pred = m_comp->BlockPredsWithEH(cand); pred != nullptr; pred = pred->getNextPredEdge()) { - BasicBlock* predBlock = pred->getBlock(); + BasicBlock* predBlock = pred->getSourceBlock(); if (!m_comp->optLoopTable[lnum].lpContains(predBlock)) { if (!GetVisitBit(predBlock->bbNum, BVB_complete)) @@ -7619,9 +7619,9 @@ struct ValueNumberState #endif // DEBUG_VN_VISIT bool allPredsVisited = true; - for (flowList* pred = m_comp->BlockPredsWithEH(succ); pred != nullptr; pred = pred->flNext) + for (FlowEdge* pred = m_comp->BlockPredsWithEH(succ); pred != nullptr; pred = pred->getNextPredEdge()) { - BasicBlock* predBlock = pred->getBlock(); + BasicBlock* predBlock = pred->getSourceBlock(); if (!GetVisitBit(predBlock->bbNum, BVB_complete)) { allPredsVisited = false; @@ -8138,9 +8138,9 @@ ValueNum Compiler::fgMemoryVNForLoopSideEffects(MemoryKind memoryKind, // use a new unique VN. BasicBlock* nonLoopPred = nullptr; bool multipleNonLoopPreds = false; - for (flowList* pred = BlockPredsWithEH(entryBlock); pred != nullptr; pred = pred->flNext) + for (FlowEdge* pred = BlockPredsWithEH(entryBlock); pred != nullptr; pred = pred->getNextPredEdge()) { - BasicBlock* predBlock = pred->getBlock(); + BasicBlock* predBlock = pred->getSourceBlock(); if (!optLoopTable[loopNum].lpContains(predBlock)) { if (nonLoopPred == nullptr)