Skip to content

Commit

Permalink
JIT: build pred lists before object allocation phase (dotnet#80891)
Browse files Browse the repository at this point in the history
Move the pred list building up a bit further.

Contributes to dotnet#80193.
  • Loading branch information
AndyAyersMS authored and mdh1418 committed Jan 24, 2023
1 parent b747386 commit d708b26
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
30 changes: 15 additions & 15 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4467,21 +4467,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
// Record "start" values for post-inlining cycles and elapsed time.
RecordStateAtEndOfInlining();

// Transform each GT_ALLOCOBJ node into either an allocation helper call or
// local variable allocation on the stack.
ObjectAllocator objectAllocator(this); // PHASE_ALLOCATE_OBJECTS

if (compObjectStackAllocation() && opts.OptimizationEnabled())
{
objectAllocator.EnableObjectStackAllocation();
}

objectAllocator.Run();

// Add any internal blocks/trees we may need
//
DoPhase(this, PHASE_MORPH_ADD_INTERNAL, &Compiler::fgAddInternal);

// Compute bbNum, bbRefs and bbPreds
//
// This is the first time full (not cheap) preds will be computed.
Expand All @@ -4500,6 +4485,21 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
};
DoPhase(this, PHASE_COMPUTE_PREDS, computePredsPhase);

// Transform each GT_ALLOCOBJ node into either an allocation helper call or
// local variable allocation on the stack.
ObjectAllocator objectAllocator(this); // PHASE_ALLOCATE_OBJECTS

if (compObjectStackAllocation() && opts.OptimizationEnabled())
{
objectAllocator.EnableObjectStackAllocation();
}

objectAllocator.Run();

// Add any internal blocks/trees we may need
//
DoPhase(this, PHASE_MORPH_ADD_INTERNAL, &Compiler::fgAddInternal);

// Remove empty try regions
//
DoPhase(this, PHASE_EMPTY_TRY, &Compiler::fgRemoveEmptyTry);
Expand Down
9 changes: 6 additions & 3 deletions src/coreclr/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1565,8 +1565,8 @@ void Compiler::fgAddSyncMethodEnterExit()
// We need to do this transformation before funclets are created.
assert(!fgFuncletsCreated);

// Assume we don't need to update the bbPreds lists.
assert(!fgComputePredsDone);
// We need to update the bbPreds lists.
assert(fgComputePredsDone);

#if !FEATURE_EH
// If we don't support EH, we can't add the EH needed by synchronized methods.
Expand Down Expand Up @@ -1595,6 +1595,7 @@ void Compiler::fgAddSyncMethodEnterExit()
}

// Create a block for the fault.
// It gets an artificial ref count.

assert(!tryLastBB->bbFallsThrough());
BasicBlock* faultBB = fgNewBBafter(BBJ_EHFINALLYRET, tryLastBB, false);
Expand All @@ -1603,6 +1604,8 @@ void Compiler::fgAddSyncMethodEnterExit()
assert(faultBB->bbNext == nullptr);
assert(faultBB == fgLastBB);

faultBB->bbRefs = 1;

{ // Scope the EH region creation

// Add the new EH region at the end, since it is the least nested,
Expand Down Expand Up @@ -2184,7 +2187,6 @@ class MergedReturns
BasicBlock* CreateReturnBB(unsigned index, GenTreeIntConCommon* returnConst = nullptr)
{
BasicBlock* newReturnBB = comp->fgNewBBinRegion(BBJ_RETURN);
newReturnBB->bbRefs = 1; // bbRefs gets update later, for now it should be 1
comp->fgReturnCount++;

noway_assert(newReturnBB->bbNext == nullptr);
Expand Down Expand Up @@ -2344,6 +2346,7 @@ class MergedReturns
assert((comp->info.compFlags & CORINFO_FLG_SYNCH) == 0);
returnBlock->bbJumpKind = BBJ_ALWAYS;
returnBlock->bbJumpDest = constReturnBlock;
comp->fgAddRefPred(constReturnBlock, returnBlock);

// Remove GT_RETURN since constReturnBlock returns the constant.
assert(returnBlock->lastStmt()->GetRootNode()->OperIs(GT_RETURN));
Expand Down

0 comments on commit d708b26

Please sign in to comment.