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

Commit cb2d6ee

Browse files
authored
Move ObjectAllocator phase to run right after inlining. (#20377)
This change will support object stack allocation for the following reasons: 1. Objects should be allocated on the stack before struct promotion phase so that their fields have a chance to be promoted. 2. Eventually object stack allocation will be performed in the same phase as inlining since inlining heuristics will need to be aware of object stack allocation opportunities. I verified no x64 diffs with jit-diffs --frameworks --tests --pmi
1 parent d6c35b6 commit cb2d6ee

File tree

7 files changed

+27
-14
lines changed

7 files changed

+27
-14
lines changed

src/jit/compiler.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4665,11 +4665,6 @@ void Compiler::compCompile(void** methodCodePtr, ULONG* methodCodeSize, JitFlags
46654665
EndPhase(PHASE_COMPUTE_REACHABILITY);
46664666
}
46674667

4668-
// Transform each GT_ALLOCOBJ node into either an allocation helper call or
4669-
// local variable allocation on the stack.
4670-
ObjectAllocator objectAllocator(this);
4671-
objectAllocator.Run();
4672-
46734668
if (!opts.MinOpts() && !opts.compDbgCode)
46744669
{
46754670
/* Perform loop inversion (i.e. transform "while" loops into

src/jit/compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5012,7 +5012,7 @@ class Compiler
50125012

50135013
GenTree* fgMorphCastIntoHelper(GenTree* tree, int helper, GenTree* oper);
50145014

5015-
GenTree* fgMorphIntoHelperCall(GenTree* tree, int helper, GenTreeArgList* args);
5015+
GenTree* fgMorphIntoHelperCall(GenTree* tree, int helper, GenTreeArgList* args, bool morphArgs = true);
50165016

50175017
GenTree* fgMorphStackArgForVarArgs(unsigned lclNum, var_types varType, unsigned lclOffs);
50185018

src/jit/compphases.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ CompPhaseNameMacro(PHASE_IMPORTATION, "Importation",
2929
CompPhaseNameMacro(PHASE_POST_IMPORT, "Post-import", "POST-IMP", false, -1, false)
3030
CompPhaseNameMacro(PHASE_MORPH_INIT, "Morph - Init", "MOR-INIT" ,false, -1, false)
3131
CompPhaseNameMacro(PHASE_MORPH_INLINE, "Morph - Inlining", "MOR-INL", false, -1, true)
32+
CompPhaseNameMacro(PHASE_ALLOCATE_OBJECTS, "Allocate Objects", "ALLOC-OBJ", false, -1, false)
3233
CompPhaseNameMacro(PHASE_EMPTY_TRY, "Remove empty try", "EMPTYTRY", false, -1, false)
3334
CompPhaseNameMacro(PHASE_EMPTY_FINALLY, "Remove empty finally", "EMPTYFIN", false, -1, false)
3435
CompPhaseNameMacro(PHASE_MERGE_FINALLY_CHAINS, "Merge callfinally chains", "MRGCFCHN", false, -1, false)
@@ -46,7 +47,6 @@ CompPhaseNameMacro(PHASE_CREATE_FUNCLETS, "Create EH funclets",
4647
#endif // FEATURE_EH_FUNCLETS
4748
CompPhaseNameMacro(PHASE_OPTIMIZE_LAYOUT, "Optimize layout", "LAYOUT", false, -1, false)
4849
CompPhaseNameMacro(PHASE_COMPUTE_REACHABILITY, "Compute blocks reachability", "BL_REACH", false, -1, false)
49-
CompPhaseNameMacro(PHASE_ALLOCATE_OBJECTS, "Allocate Objects", "ALLOC-OBJ",false, -1, false)
5050
CompPhaseNameMacro(PHASE_OPTIMIZE_LOOPS, "Optimize loops", "LOOP-OPT", false, -1, false)
5151
CompPhaseNameMacro(PHASE_CLONE_LOOPS, "Clone loops", "LP-CLONE", false, -1, false)
5252
CompPhaseNameMacro(PHASE_UNROLL_LOOPS, "Unroll loops", "UNROLL", false, -1, false)

src/jit/morph.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ GenTree* Compiler::fgMorphCastIntoHelper(GenTree* tree, int helper, GenTree* ope
5858
* the given argument list.
5959
*/
6060

61-
GenTree* Compiler::fgMorphIntoHelperCall(GenTree* tree, int helper, GenTreeArgList* args)
61+
GenTree* Compiler::fgMorphIntoHelperCall(GenTree* tree, int helper, GenTreeArgList* args, bool morphArgs)
6262
{
6363
// The helper call ought to be semantically equivalent to the original node, so preserve its VN.
6464
tree->ChangeOper(GT_CALL, GenTree::PRESERVE_VN);
@@ -112,7 +112,10 @@ GenTree* Compiler::fgMorphIntoHelperCall(GenTree* tree, int helper, GenTreeArgLi
112112

113113
/* Perform the morphing */
114114

115-
tree = fgMorphArgs(tree->AsCall());
115+
if (morphArgs)
116+
{
117+
tree = fgMorphArgs(tree->AsCall());
118+
}
116119

117120
return tree;
118121
}
@@ -16873,6 +16876,11 @@ void Compiler::fgMorph()
1687316876

1687416877
EndPhase(PHASE_MORPH_INLINE);
1687516878

16879+
// Transform each GT_ALLOCOBJ node into either an allocation helper call or
16880+
// local variable allocation on the stack.
16881+
ObjectAllocator objectAllocator(this); // PHASE_ALLOCATE_OBJECTS
16882+
objectAllocator.Run();
16883+
1687616884
/* Add any internal blocks/trees we may need */
1687716885

1687816886
fgAddInternal();

src/jit/objectalloc.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ GenTree* ObjectAllocator::MorphAllocObjNodeIntoHelperCall(GenTreeAllocObj* alloc
155155

156156
GenTree* op1 = allocObj->gtGetOp1();
157157

158-
GenTree* helperCall = comp->fgMorphIntoHelperCall(allocObj, allocObj->gtNewHelper, comp->gtNewArgList(op1));
158+
const bool morphArgs = false;
159+
GenTree* helperCall =
160+
comp->fgMorphIntoHelperCall(allocObj, allocObj->gtNewHelper, comp->gtNewArgList(op1), morphArgs);
159161

160162
return helperCall;
161163
}

src/jit/objectalloc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ inline ObjectAllocator::ObjectAllocator(Compiler* comp)
5353
, m_IsObjectStackAllocationEnabled(false)
5454
, m_AnalysisDone(false)
5555
{
56+
// Disable checks since this phase runs before fgComputePreds phase.
57+
// Checks are not expected to pass before fgComputePreds.
58+
doChecks = false;
5659
}
5760

5861
inline bool ObjectAllocator::IsObjectStackAllocationEnabled() const

src/jit/phase.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class Phase
1212
virtual void Run();
1313

1414
protected:
15-
Phase(Compiler* _comp, const char* _name, Phases _phase = PHASE_NUMBER_OF) : comp(_comp), name(_name), phase(_phase)
15+
Phase(Compiler* _comp, const char* _name, Phases _phase = PHASE_NUMBER_OF)
16+
: comp(_comp), name(_name), phase(_phase), doChecks(true)
1617
{
1718
}
1819

@@ -23,6 +24,7 @@ class Phase
2324
Compiler* comp;
2425
const char* name;
2526
Phases phase;
27+
bool doChecks;
2628
};
2729

2830
inline void Phase::Run()
@@ -42,7 +44,7 @@ inline void Phase::PrePhase()
4244
comp->fgDispBasicBlocks(true);
4345
}
4446

45-
if (comp->expensiveDebugCheckLevel >= 2)
47+
if (doChecks && comp->expensiveDebugCheckLevel >= 2)
4648
{
4749
// If everyone used the Phase class, this would duplicate the PostPhase() from the previous phase.
4850
// But, not everyone does, so go ahead and do the check here, too.
@@ -69,8 +71,11 @@ inline void Phase::PostPhase()
6971
}
7072

7173
#ifdef DEBUG
72-
comp->fgDebugCheckBBlist();
73-
comp->fgDebugCheckLinks();
74+
if (doChecks)
75+
{
76+
comp->fgDebugCheckBBlist();
77+
comp->fgDebugCheckLinks();
78+
}
7479
#endif // DEBUG
7580
}
7681

0 commit comments

Comments
 (0)