@@ -348,6 +348,7 @@ struct LateLowerGCFrame: private JuliaPassContext {
348348 void ComputeLiveSets (State &S);
349349 SmallVector<int , 0 > ColorRoots (const State &S);
350350 void PlaceGCFrameStore (State &S, unsigned R, unsigned MinColorRoot, ArrayRef<int > Colors, Value *GCFrame, Instruction *InsertBefore);
351+ void PlaceGCFrameReset (State &S, unsigned R, unsigned MinColorRoot, ArrayRef<int > Colors, Value *GCFrame, Instruction *InsertBefore);
351352 void PlaceGCFrameStores (State &S, unsigned MinColorRoot, ArrayRef<int > Colors, Value *GCFrame);
352353 void PlaceRootsAndUpdateCalls (SmallVectorImpl<int > &Colors, State &S, std::map<Value *, std::pair<int , int >>);
353354 bool CleanupIR (Function &F, State *S, bool *CFGModified);
@@ -2665,6 +2666,18 @@ void LateLowerGCFrame::PlaceGCFrameStore(State &S, unsigned R, unsigned MinColor
26652666 }
26662667 new StoreInst (Val, slotAddress, InsertBefore);
26672668}
2669+ void LateLowerGCFrame::PlaceGCFrameReset (State &S, unsigned R, unsigned MinColorRoot,
2670+ ArrayRef<int > Colors, Value *GCFrame,
2671+ Instruction *InsertBefore) {
2672+ // Get the slot address.
2673+ auto slotAddress = CallInst::Create (
2674+ getOrDeclare (jl_intrinsics::getGCFrameSlot),
2675+ {GCFrame, ConstantInt::get (Type::getInt32Ty (InsertBefore->getContext ()), Colors[R] + MinColorRoot)},
2676+ " gc_slot_addr_" + StringRef (std::to_string (Colors[R] + MinColorRoot)), InsertBefore);
2677+ // Reset the slot to NULL.
2678+ Value *Val = ConstantPointerNull::get (T_prjlvalue);
2679+ new StoreInst (Val, slotAddress, InsertBefore);
2680+ }
26682681
26692682void LateLowerGCFrame::PlaceGCFrameStores (State &S, unsigned MinColorRoot,
26702683 ArrayRef<int > Colors, Value *GCFrame)
@@ -2680,6 +2693,15 @@ void LateLowerGCFrame::PlaceGCFrameStores(State &S, unsigned MinColorRoot,
26802693 for (auto rit = BBS.Safepoints .rbegin ();
26812694 rit != BBS.Safepoints .rend (); ++rit ) {
26822695 const LargeSparseBitVector &NowLive = S.LiveSets [*rit];
2696+ // reset slots which are no longer alive
2697+ for (int Idx : *LastLive) {
2698+ if (!HasBitSet (NowLive, Idx)) {
2699+ PlaceGCFrameReset (S, Idx, MinColorRoot, Colors, GCFrame,
2700+ S.ReverseSafepointNumbering [*rit]);
2701+ }
2702+ }
2703+ // store values which are alive in this safepoint but
2704+ // haven't been stored in the GC frame before
26832705 for (int Idx : NowLive) {
26842706 if (!HasBitSet (*LastLive, Idx)) {
26852707 PlaceGCFrameStore (S, Idx, MinColorRoot, Colors, GCFrame,
0 commit comments