Index: llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h =================================================================== --- llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h +++ llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h @@ -678,7 +678,7 @@ /// movement of values between locations inside of a block is handled at a /// much later stage, in the TransferTracker class. MapVector Vars; - DenseMap Scopes; + SmallDenseMap Scopes; MachineBasicBlock *MBB = nullptr; const OverlapMap &OverlappingFragments; DbgValueProperties EmptyProperties; @@ -747,6 +747,11 @@ Scopes[Overlapped] = Loc; } } + + void clear() { + Vars.clear(); + Scopes.clear(); + } }; // XXX XXX docs Index: llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp =================================================================== --- llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp +++ llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp @@ -1000,7 +1000,7 @@ // Only handle this instruction when we are building the variable value // transfer function. - if (!VTracker) + if (!VTracker && !TTracker) return false; unsigned InstNo = MI.getOperand(0).getImm(); @@ -1156,7 +1156,8 @@ // for DBG_INSTR_REFs as DBG_VALUEs (just, the former can refer to values that // aren't immediately available). DbgValueProperties Properties(Expr, false); - VTracker->defVar(MI, Properties, NewID); + if (VTracker) + VTracker->defVar(MI, Properties, NewID); // If we're on the final pass through the function, decompose this INSTR_REF // into a plain DBG_VALUE. @@ -2786,6 +2787,7 @@ const TargetPassConfig &TPC) { TTracker = new TransferTracker(TII, MTracker, MF, *TRI, CalleeSavedRegs, TPC); unsigned NumLocs = MTracker->getNumLocs(); + VTracker = nullptr; // For each block, load in the machine value locations and variable value // live-ins, then step through each instruction in the block. New DBG_VALUEs @@ -2804,6 +2806,13 @@ TTracker->checkInstForNewValues(CurInst, MI.getIterator()); ++CurInst; } + + // Our block information has now been converted into DBG_VALUEs, to be + // inserted below. Free the memory we allocated to track variable / register + // values. If we don't, we needlessy record the same info in memory twice. + delete[] MInLocs[bbnum]; + delete[] MOutLocs[bbnum]; + SavedLiveIns[bbnum].clear(); } // Go through all the transfers recorded in the TransferTracker -- this is @@ -3033,6 +3042,12 @@ << " has " << MaxNumBlocks << " basic blocks and " << VarAssignCount << " variable assignments, exceeding limits.\n"); + + // Perform memory cleanup that emitLocations would do otherwise. + for (int Idx = 0; Idx < MaxNumBlocks; ++Idx) { + delete[] MOutLocs[Idx]; + delete[] MInLocs[Idx]; + } } else { // Compute the extended ranges, iterating over scopes. There might be // something to be said for ordering them by size/locality, but that's for @@ -3044,6 +3059,9 @@ vlocs); } + // Now that we've analysed variable assignments, free any tracking data. + vlocs.clear(); + // Using the computed value locations and variable values for each block, // create the DBG_VALUE instructions representing the extended variable // locations. @@ -3053,11 +3071,7 @@ Changed = TTracker->Transfers.size() != 0; } - // Common clean-up of memory. - for (int Idx = 0; Idx < MaxNumBlocks; ++Idx) { - delete[] MOutLocs[Idx]; - delete[] MInLocs[Idx]; - } + // Elements of these arrays will be deleted by emitLocations. delete[] MOutLocs; delete[] MInLocs;