Skip to content

Commit c2e3481

Browse files
author
Meghana Gupta
committed
[MERGE #6102 @meg-gupta] Cleanup some region propagation code from flowgraph
Merge pull request #6102 from meg-gupta:cleanupfg We don't really need UpdateRegionFromEHPred. UpdateRegionFromPred is sufficient. I had added UpdateRegionFromEHPred when we would get different region for a block, based on the predecessor we chose. But since then, we add all possible flow edges for try/finallys and hence we don't have this issue anymore. This change does the cleanup.
2 parents 65a465a + 5869366 commit c2e3481

File tree

2 files changed

+4
-132
lines changed

2 files changed

+4
-132
lines changed

lib/Backend/FlowGraph.cpp

Lines changed: 4 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,9 +1137,9 @@ FlowGraph::MoveBlocksBefore(BasicBlock *blockStart, BasicBlock *blockEnd, BasicB
11371137
// We have to update region info for blocks whose predecessors changed
11381138
if (assignRegionsBeforeGlobopt)
11391139
{
1140-
UpdateRegionForBlockFromEHPred(dstPredBlock, true);
1141-
UpdateRegionForBlockFromEHPred(blockStart, true);
1142-
UpdateRegionForBlockFromEHPred(srcNextBlock, true);
1140+
UpdateRegionForBlock(dstPredBlock);
1141+
UpdateRegionForBlock(blockStart);
1142+
UpdateRegionForBlock(srcNextBlock);
11431143
}
11441144
}
11451145

@@ -1871,30 +1871,6 @@ FlowGraph::Destroy(void)
18711871
this->func->isFlowGraphValid = false;
18721872
}
18731873

1874-
bool FlowGraph::IsEHTransitionInstr(IR::Instr *instr)
1875-
{
1876-
Js::OpCode op = instr->m_opcode;
1877-
return (op == Js::OpCode::TryCatch || op == Js::OpCode::TryFinally || op == Js::OpCode::Leave || op == Js::OpCode::LeaveNull);
1878-
}
1879-
1880-
BasicBlock * FlowGraph::GetPredecessorForRegionPropagation(BasicBlock *block)
1881-
{
1882-
BasicBlock *ehPred = nullptr;
1883-
FOREACH_PREDECESSOR_BLOCK(predBlock, block)
1884-
{
1885-
Region * predRegion = predBlock->GetFirstInstr()->AsLabelInstr()->GetRegion();
1886-
if (IsEHTransitionInstr(predBlock->GetLastInstr()) && predRegion)
1887-
{
1888-
// MGTODO : change this to return, once you know there can exist only one eh transitioning pred
1889-
Assert(ehPred == nullptr);
1890-
ehPred = predBlock;
1891-
}
1892-
AssertMsg(predBlock->GetBlockNum() < this->blockCount, "Misnumbered block at teardown time?");
1893-
}
1894-
NEXT_PREDECESSOR_BLOCK;
1895-
return ehPred;
1896-
}
1897-
18981874
// Propagate the region forward from the block's predecessor(s), tracking the effect
18991875
// of the flow transition. Record the region in the block-to-region map provided
19001876
// and on the label at the entry to the block (if any).
@@ -1958,7 +1934,6 @@ FlowGraph::UpdateRegionForBlock(BasicBlock * block)
19581934
}
19591935
}
19601936

1961-
Assert(region || block->GetPredList()->Count() == 0);
19621937
if (region && !region->ehBailoutData)
19631938
{
19641939
region->AllocateEHBailoutData(this->func, tryInstr);
@@ -1997,106 +1972,6 @@ FlowGraph::UpdateRegionForBlock(BasicBlock * block)
19971972
}
19981973
}
19991974

2000-
void
2001-
FlowGraph::UpdateRegionForBlockFromEHPred(BasicBlock * block, bool reassign)
2002-
{
2003-
Region *region = nullptr;
2004-
Region * predRegion = nullptr;
2005-
IR::Instr * tryInstr = nullptr;
2006-
IR::Instr * firstInstr = block->GetFirstInstr();
2007-
if (!reassign && firstInstr->IsLabelInstr() && firstInstr->AsLabelInstr()->GetRegion())
2008-
{
2009-
Assert(this->func->HasTry() && (this->func->DoOptimizeTry() || (this->func->IsSimpleJit() && this->func->hasBailout)));
2010-
return;
2011-
}
2012-
if (block->isDead || block->isDeleted)
2013-
{
2014-
// We can end up calling this function with such blocks, return doing nothing
2015-
// See test5() in tryfinallytests.js
2016-
return;
2017-
}
2018-
2019-
if (block == this->blockList)
2020-
{
2021-
// Head of the graph: create the root region.
2022-
region = Region::New(RegionTypeRoot, nullptr, this->func);
2023-
}
2024-
else if (block->GetPredList()->Count() == 1)
2025-
{
2026-
BasicBlock *predBlock = block->GetPredList()->Head()->GetPred();
2027-
AssertMsg(predBlock->GetBlockNum() < this->blockCount, "Misnumbered block at teardown time?");
2028-
predRegion = predBlock->GetFirstInstr()->AsLabelInstr()->GetRegion();
2029-
Assert(predRegion);
2030-
region = this->PropagateRegionFromPred(block, predBlock, predRegion, tryInstr);
2031-
}
2032-
else
2033-
{
2034-
// Propagate the region forward by finding a predecessor we've already processed.
2035-
// Since we do break block remval after region propagation, we cannot pick the first predecessor which has an assigned region
2036-
// If there is a eh transitioning pred, we pick that
2037-
// There cannot be more than one eh transitioning pred (?)
2038-
BasicBlock *ehPred = this->GetPredecessorForRegionPropagation(block);
2039-
if (ehPred)
2040-
{
2041-
predRegion = ehPred->GetFirstInstr()->AsLabelInstr()->GetRegion();
2042-
Assert(predRegion != nullptr);
2043-
region = this->PropagateRegionFromPred(block, ehPred, predRegion, tryInstr);
2044-
}
2045-
else
2046-
{
2047-
FOREACH_PREDECESSOR_BLOCK(predBlock, block)
2048-
{
2049-
predRegion = predBlock->GetFirstInstr()->AsLabelInstr()->GetRegion();
2050-
if (predRegion != nullptr)
2051-
{
2052-
if ((predBlock->GetLastInstr()->m_opcode == Js::OpCode::BrOnException || predBlock->GetLastInstr()->m_opcode == Js::OpCode::BrOnNoException) &&
2053-
predBlock->GetLastInstr()->AsBranchInstr()->m_brFinallyToEarlyExit)
2054-
{
2055-
Assert(predRegion->IsNonExceptingFinally());
2056-
// BrOnException from finally region to early exit
2057-
// Skip this edge
2058-
continue;
2059-
}
2060-
if (predBlock->GetLastInstr()->m_opcode == Js::OpCode::Br &&
2061-
predBlock->GetLastInstr()->GetPrevRealInstr()->m_opcode == Js::OpCode::BrOnNoException)
2062-
{
2063-
Assert(predBlock->GetLastInstr()->GetPrevRealInstr()->AsBranchInstr()->m_brFinallyToEarlyExit);
2064-
Assert(predRegion->IsNonExceptingFinally());
2065-
// BrOnException from finally region to early exit changed to BrOnNoException and Br during break block removal
2066-
continue;
2067-
}
2068-
region = this->PropagateRegionFromPred(block, predBlock, predRegion, tryInstr);
2069-
break;
2070-
}
2071-
}
2072-
NEXT_PREDECESSOR_BLOCK;
2073-
}
2074-
}
2075-
2076-
Assert(region || block->GetPredList()->Count() == 0 || block->firstInstr->AsLabelInstr()->GetRegion());
2077-
2078-
if (region)
2079-
{
2080-
if (!region->ehBailoutData)
2081-
{
2082-
region->AllocateEHBailoutData(this->func, tryInstr);
2083-
}
2084-
2085-
Assert(firstInstr->IsLabelInstr());
2086-
if (firstInstr->IsLabelInstr())
2087-
{
2088-
// Record the region on the label and make sure it stays around as a region
2089-
// marker if we're entering a region at this point.
2090-
IR::LabelInstr * labelInstr = firstInstr->AsLabelInstr();
2091-
labelInstr->SetRegion(region);
2092-
if (region != predRegion)
2093-
{
2094-
labelInstr->m_hasNonBranchRef = true;
2095-
}
2096-
}
2097-
}
2098-
}
2099-
21001975
Region *
21011976
FlowGraph::PropagateRegionFromPred(BasicBlock * block, BasicBlock * predBlock, Region * predRegion, IR::Instr * &tryInstr)
21021977
{
@@ -2488,7 +2363,7 @@ FlowGraph::InsertCompensationCodeForBlockMove(FlowEdge * edge, bool insertToLoo
24882363

24892364
if (assignRegionsBeforeGlobopt)
24902365
{
2491-
UpdateRegionForBlockFromEHPred(compBlock);
2366+
UpdateRegionForBlock(compBlock);
24922367
}
24932368
}
24942369
else

lib/Backend/FlowGraph.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,7 @@ class FlowGraph
201201
void BuildLoop(BasicBlock *headBlock, BasicBlock *tailBlock, Loop *parentLoop = nullptr);
202202
void WalkLoopBlocks(BasicBlock *block, Loop *loop, JitArenaAllocator *tempAlloc);
203203
void AddBlockToLoop(BasicBlock *block, Loop *loop);
204-
bool IsEHTransitionInstr(IR::Instr *instr);
205-
BasicBlock * GetPredecessorForRegionPropagation(BasicBlock *block);
206204
void UpdateRegionForBlock(BasicBlock *block);
207-
void UpdateRegionForBlockFromEHPred(BasicBlock *block, bool reassign = false);
208205
Region * PropagateRegionFromPred(BasicBlock *block, BasicBlock *predBlock, Region *predRegion, IR::Instr * &tryInstr);
209206
IR::Instr * PeepCm(IR::Instr *instr);
210207
IR::Instr * PeepTypedCm(IR::Instr *instr);

0 commit comments

Comments
 (0)