@@ -133,7 +133,7 @@ unsigned ObjectAllocator::LocalToIndex(unsigned lclNum)
133
133
{
134
134
unsigned result = BAD_VAR_NUM;
135
135
136
- if (lclNum < comp-> lvaCount )
136
+ if (lclNum < m_firstPseudoLocalNum )
137
137
{
138
138
assert (IsTrackedLocal (lclNum));
139
139
LclVarDsc* const varDsc = comp->lvaGetDesc (lclNum);
@@ -297,6 +297,7 @@ void ObjectAllocator::MarkLclVarAsEscaping(unsigned int lclNum)
297
297
void ObjectAllocator::MarkLclVarAsPossiblyStackPointing (unsigned int lclNum)
298
298
{
299
299
const unsigned bvIndex = LocalToIndex (lclNum);
300
+ JITDUMP (" Marking V%02u (0x%02x) as possibly stack-pointing\n " , lclNum, bvIndex);
300
301
BitVecOps::AddElemD (&m_bitVecTraits, m_PossiblyStackPointingPointers, bvIndex);
301
302
}
302
303
@@ -839,6 +840,11 @@ void ObjectAllocator::ComputeEscapingNodes(BitVecTraits* bitVecTraits, BitVec& e
839
840
840
841
void ObjectAllocator::ComputeStackObjectPointers (BitVecTraits* bitVecTraits)
841
842
{
843
+ // Keep track of locals that we know may point at the heap
844
+ //
845
+ BitVec possiblyHeapPointingPointers = BitVecOps::MakeEmpty (&m_bitVecTraits);
846
+ BitVecOps::AddElemD (bitVecTraits, possiblyHeapPointingPointers, m_unknownSourceIndex);
847
+
842
848
bool changed = true ;
843
849
unsigned pass = 0 ;
844
850
while (changed)
@@ -859,23 +865,36 @@ void ObjectAllocator::ComputeStackObjectPointers(BitVecTraits* bitVecTraits)
859
865
m_ConnGraphAdjacencyMatrix[lclIndex]))
860
866
{
861
867
// We discovered a new pointer that may point to the stack.
868
+ JITDUMPEXEC (DumpIndex (lclIndex));
869
+ JITDUMP (" may point to the stack\n " );
862
870
MarkLclVarAsPossiblyStackPointing (lclNum);
871
+ changed = true ;
872
+ }
863
873
864
- // If all locals assignable to this local are stack pointing, so is this local.
865
- //
866
- const bool isStackPointing = BitVecOps::IsSubset (bitVecTraits, m_ConnGraphAdjacencyMatrix[lclIndex],
867
- m_DefinitelyStackPointingPointers);
868
-
869
- if (isStackPointing)
870
- {
871
- MarkLclVarAsDefinitelyStackPointing (lclNum);
872
- JITDUMP (" V%02u is stack pointing\n " , lclNum);
873
- }
874
-
874
+ if (!BitVecOps::IsMember (bitVecTraits, possiblyHeapPointingPointers, lclIndex) &&
875
+ !BitVecOps::IsEmptyIntersection (bitVecTraits, possiblyHeapPointingPointers,
876
+ m_ConnGraphAdjacencyMatrix[lclIndex]))
877
+ {
878
+ // We discovered a new pointer that may point to the heap.
879
+ JITDUMPEXEC (DumpIndex (lclIndex));
880
+ JITDUMP (" may point to the heap\n " );
881
+ BitVecOps::AddElemD (bitVecTraits, possiblyHeapPointingPointers, lclIndex);
875
882
changed = true ;
876
883
}
877
884
}
878
885
}
886
+ JITDUMP (" \n ---- done computing stack pointing locals\n " );
887
+
888
+ // If a local is possibly stack pointing and not possibly heap pointing, then it is definitely stack pointing.
889
+ //
890
+ BitVec newDefinitelyStackPointingPointers = BitVecOps::UninitVal ();
891
+ BitVecOps::Assign (bitVecTraits, newDefinitelyStackPointingPointers, m_PossiblyStackPointingPointers);
892
+ BitVecOps::DiffD (bitVecTraits, newDefinitelyStackPointingPointers, possiblyHeapPointingPointers);
893
+
894
+ // We should have only added to the set of things that are definitely stack pointing.
895
+ //
896
+ assert (BitVecOps::IsSubset (bitVecTraits, m_DefinitelyStackPointingPointers, newDefinitelyStackPointingPointers));
897
+ BitVecOps::AssignNoCopy (bitVecTraits, m_DefinitelyStackPointingPointers, newDefinitelyStackPointingPointers);
879
898
880
899
#ifdef DEBUG
881
900
if (comp->verbose )
@@ -1117,10 +1136,10 @@ bool ObjectAllocator::MorphAllocObjNodes()
1117
1136
continue ;
1118
1137
}
1119
1138
1120
- bool canStack = false ;
1121
- bool bashCall = false ;
1122
- const char * onHeapReason = nullptr ;
1123
- unsigned int lclNum = stmtExpr->AsLclVar ()->GetLclNum ();
1139
+ bool canStack = false ;
1140
+ bool bashCall = false ;
1141
+ const char * onHeapReason = nullptr ;
1142
+ const unsigned int lclNum = stmtExpr->AsLclVar ()->GetLclNum ();
1124
1143
1125
1144
// Don't attempt to do stack allocations inside basic blocks that may be in a loop.
1126
1145
//
@@ -1306,6 +1325,11 @@ bool ObjectAllocator::MorphAllocObjNodes()
1306
1325
stmtExpr->AsLclVar ()->Data () = newData;
1307
1326
stmtExpr->AddAllEffectsFlags (newData);
1308
1327
}
1328
+
1329
+ if (IsTrackedLocal (lclNum))
1330
+ {
1331
+ AddConnGraphEdge (lclNum, m_unknownSourceLocalNum);
1332
+ }
1309
1333
}
1310
1334
}
1311
1335
}
0 commit comments