Index: llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h =================================================================== --- llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h +++ llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h @@ -786,6 +786,13 @@ /// Used as the result type for the variable value dataflow problem. using LiveInsT = SmallVector, 8>; + /// Type for a table of values in a block. + using ValueTable = std::unique_ptr; + + /// Type for a table-of-table-of-values, i.e., the collection of either + /// live-in or live-out values for each block in the function. + using FuncValueTable = std::unique_ptr; + private: MachineDominatorTree *DomTree; const TargetRegisterInfo *TRI; @@ -894,8 +901,8 @@ extractSpillBaseRegAndOffset(const MachineInstr &MI); /// Observe a single instruction while stepping through a block. - void process(MachineInstr &MI, ValueIDNum **MLiveOuts = nullptr, - ValueIDNum **MLiveIns = nullptr); + void process(MachineInstr &MI, FuncValueTable *MLiveOuts = nullptr, + FuncValueTable *MLiveIns = nullptr); /// Examines whether \p MI is a DBG_VALUE and notifies trackers. /// \returns true if MI was recognized and processed. @@ -903,8 +910,8 @@ /// Examines whether \p MI is a DBG_INSTR_REF and notifies trackers. /// \returns true if MI was recognized and processed. - bool transferDebugInstrRef(MachineInstr &MI, ValueIDNum **MLiveOuts, - ValueIDNum **MLiveIns); + bool transferDebugInstrRef(MachineInstr &MI, FuncValueTable *MLiveOuts, + FuncValueTable *MLiveIns); /// Stores value-information about where this PHI occurred, and what /// instruction number is associated with it. @@ -936,8 +943,9 @@ /// \p InstrNum Debug instruction number defined by DBG_PHI instructions. /// \returns The machine value number at position Here, or None. Optional resolveDbgPHIs(MachineFunction &MF, - ValueIDNum **MLiveOuts, - ValueIDNum **MLiveIns, MachineInstr &Here, + FuncValueTable &MLiveOuts, + FuncValueTable &MLiveIns, + MachineInstr &Here, uint64_t InstrNum); /// Step through the function, recording register definitions and movements @@ -954,8 +962,8 @@ /// live-out arrays to the (initialized to zero) multidimensional arrays in /// \p MInLocs and \p MOutLocs. The outer dimension is indexed by block /// number, the inner by LocIdx. - void buildMLocValueMap(MachineFunction &MF, ValueIDNum **MInLocs, - ValueIDNum **MOutLocs, + void buildMLocValueMap(MachineFunction &MF, FuncValueTable &MInLocs, + FuncValueTable &MOutLocs, SmallVectorImpl &MLocTransfer); /// Examine the stack indexes (i.e. offsets within the stack) to find the @@ -966,7 +974,7 @@ /// the IDF of each register. void placeMLocPHIs(MachineFunction &MF, SmallPtrSetImpl &AllBlocks, - ValueIDNum **MInLocs, + FuncValueTable &MInLocs, SmallVectorImpl &MLocTransfer); /// Propagate variable values to blocks in the common case where there's @@ -996,7 +1004,7 @@ /// was made, the second whether a lattice downgrade occurred. If the latter /// is true, revisiting this block is necessary. bool mlocJoin(MachineBasicBlock &MBB, - ValueIDNum **OutLocs, ValueIDNum *InLocs); + FuncValueTable &OutLocs, ValueTable &InLocs); /// Solve the variable value dataflow problem, for a single lexical scope. /// Uses the algorithm from the file comment to resolve control flow joins @@ -1013,8 +1021,8 @@ void buildVLocValueMap(const DILocation *DILoc, const SmallSet &VarsWeCareAbout, SmallPtrSetImpl &AssignBlocks, - LiveInsT &Output, ValueIDNum **MOutLocs, - ValueIDNum **MInLocs, + LiveInsT &Output, FuncValueTable &MOutLocs, + FuncValueTable &MInLocs, SmallVectorImpl &AllTheVLocs); /// Attempt to eliminate un-necessary PHIs on entry to a block. Examines the @@ -1033,7 +1041,7 @@ /// \returns Value ID of a machine PHI if an appropriate one is available. Optional pickVPHILoc(const MachineBasicBlock &MBB, const DebugVariable &Var, - const LiveIdxT &LiveOuts, ValueIDNum **MOutLocs, + const LiveIdxT &LiveOuts, FuncValueTable &MOutLocs, const SmallVectorImpl &BlockOrders); /// Given the solutions to the two dataflow problems, machine value locations @@ -1044,7 +1052,7 @@ /// right now "order of appearence in function, when explored in RPO", so /// that we can compare explictly against VarLocBasedImpl. void emitLocations(MachineFunction &MF, LiveInsT SavedLiveIns, - ValueIDNum **MOutLocs, ValueIDNum **MInLocs, + FuncValueTable &MOutLocs, FuncValueTable &MInLocs, DenseMap &AllVarsNumbering, const TargetPassConfig &TPC); Index: llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp =================================================================== --- llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp +++ llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp @@ -1026,8 +1026,8 @@ } bool InstrRefBasedLDV::transferDebugInstrRef(MachineInstr &MI, - ValueIDNum **MLiveOuts, - ValueIDNum **MLiveIns) { + FuncValueTable *MLiveOuts, + FuncValueTable *MLiveIns) { if (!MI.isDebugRef()) return false; @@ -1109,7 +1109,7 @@ } else if (PHIIt != DebugPHINumToValue.end() && PHIIt->InstrNum == InstNo) { // It's actually a PHI value. Which value it is might not be obvious, use // the resolver helper to find out. - NewID = resolveDbgPHIs(*MI.getParent()->getParent(), MLiveOuts, MLiveIns, + NewID = resolveDbgPHIs(*MI.getParent()->getParent(), *MLiveOuts, *MLiveIns, MI, InstNo); } @@ -1759,8 +1759,8 @@ AllSeenFragments.insert(ThisFragment); } -void InstrRefBasedLDV::process(MachineInstr &MI, ValueIDNum **MLiveOuts, - ValueIDNum **MLiveIns) { +void InstrRefBasedLDV::process(MachineInstr &MI, FuncValueTable *MLiveOuts, + FuncValueTable *MLiveIns) { // Try to interpret an MI as a debug or transfer instruction. Only if it's // none of these should we interpret it's register defs as new value // definitions. @@ -1898,7 +1898,7 @@ } bool InstrRefBasedLDV::mlocJoin( - MachineBasicBlock &MBB, ValueIDNum **OutLocs, ValueIDNum *InLocs) { + MachineBasicBlock &MBB, FuncValueTable &OutLocs, ValueTable &InLocs) { LLVM_DEBUG(dbgs() << "join MBB: " << MBB.getNumber() << "\n"); bool Changed = false; @@ -1999,7 +1999,7 @@ void InstrRefBasedLDV::placeMLocPHIs( MachineFunction &MF, SmallPtrSetImpl &AllBlocks, - ValueIDNum **MInLocs, SmallVectorImpl &MLocTransfer) { + FuncValueTable &MInLocs, SmallVectorImpl &MLocTransfer) { SmallVector StackUnits; findStackIndexInterference(StackUnits); @@ -2124,7 +2124,7 @@ } void InstrRefBasedLDV::buildMLocValueMap( - MachineFunction &MF, ValueIDNum **MInLocs, ValueIDNum **MOutLocs, + MachineFunction &MF, FuncValueTable &MInLocs, FuncValueTable &MOutLocs, SmallVectorImpl &MLocTransfer) { std::priority_queue, std::greater> @@ -2190,7 +2190,7 @@ continue; // Load the current set of live-ins into MLocTracker. - MTracker->loadFromArray(MInLocs[CurBB], CurBB); + MTracker->loadFromArray(MInLocs[CurBB].get(), CurBB); // Each element of the transfer function can be a new def, or a read of // a live-in value. Evaluate each element, and store to "ToRemap". @@ -2309,7 +2309,7 @@ Optional InstrRefBasedLDV::pickVPHILoc( const MachineBasicBlock &MBB, const DebugVariable &Var, - const LiveIdxT &LiveOuts, ValueIDNum **MOutLocs, + const LiveIdxT &LiveOuts, FuncValueTable &MOutLocs, const SmallVectorImpl &BlockOrders) { // Collect a set of locations from predecessor where its live-out value can // be found. @@ -2514,7 +2514,7 @@ void InstrRefBasedLDV::buildVLocValueMap(const DILocation *DILoc, const SmallSet &VarsWeCareAbout, SmallPtrSetImpl &AssignBlocks, LiveInsT &Output, - ValueIDNum **MOutLocs, ValueIDNum **MInLocs, + FuncValueTable &MOutLocs, FuncValueTable &MInLocs, SmallVectorImpl &AllTheVLocs) { // This method is much like buildMLocValueMap: but focuses on a single // LexicalScope at a time. Pick out a set of blocks and variables that are @@ -2875,8 +2875,9 @@ #endif void InstrRefBasedLDV::emitLocations( - MachineFunction &MF, LiveInsT SavedLiveIns, ValueIDNum **MOutLocs, - ValueIDNum **MInLocs, DenseMap &AllVarsNumbering, + MachineFunction &MF, LiveInsT SavedLiveIns, FuncValueTable &MOutLocs, + FuncValueTable &MInLocs, + DenseMap &AllVarsNumbering, const TargetPassConfig &TPC) { TTracker = new TransferTracker(TII, MTracker, MF, *TRI, CalleeSavedRegs, TPC); unsigned NumLocs = MTracker->getNumLocs(); @@ -2888,14 +2889,14 @@ for (MachineBasicBlock &MBB : MF) { unsigned bbnum = MBB.getNumber(); MTracker->reset(); - MTracker->loadFromArray(MInLocs[bbnum], bbnum); - TTracker->loadInlocs(MBB, MInLocs[bbnum], SavedLiveIns[MBB.getNumber()], + MTracker->loadFromArray(MInLocs[bbnum].get(), bbnum); + TTracker->loadInlocs(MBB, MInLocs[bbnum].get(), SavedLiveIns[MBB.getNumber()], NumLocs); CurBB = bbnum; CurInst = 1; for (auto &MI : MBB) { - process(MI, MOutLocs, MInLocs); + process(MI, &MOutLocs, &MInLocs); TTracker->checkInstForNewValues(CurInst, MI.getIterator()); ++CurInst; } @@ -2903,8 +2904,8 @@ // 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]; + MInLocs[bbnum].reset(); + MOutLocs[bbnum].reset(); SavedLiveIns[bbnum].clear(); } @@ -3038,13 +3039,13 @@ // Allocate and initialize two array-of-arrays for the live-in and live-out // machine values. The outer dimension is the block number; while the inner // dimension is a LocIdx from MLocTracker. - ValueIDNum **MOutLocs = new ValueIDNum *[MaxNumBlocks]; - ValueIDNum **MInLocs = new ValueIDNum *[MaxNumBlocks]; + FuncValueTable MOutLocs = FuncValueTable(new ValueTable[MaxNumBlocks]); + FuncValueTable MInLocs = FuncValueTable(new ValueTable[MaxNumBlocks]); unsigned NumLocs = MTracker->getNumLocs(); for (unsigned i = 0; i < MaxNumBlocks; ++i) { // These all auto-initialize to ValueIDNum::EmptyValue - MOutLocs[i] = new ValueIDNum[NumLocs]; - MInLocs[i] = new ValueIDNum[NumLocs]; + MOutLocs[i] = ValueTable(new ValueIDNum[NumLocs]); + MInLocs[i] = ValueTable(new ValueIDNum[NumLocs]); } // Solve the machine value dataflow problem using the MLocTransfer function, @@ -3078,10 +3079,9 @@ CurBB = MBB->getNumber(); VTracker = &vlocs[CurBB]; VTracker->MBB = MBB; - MTracker->loadFromArray(MInLocs[CurBB], CurBB); - CurInst = 1; + MTracker->loadFromArray(MInLocs[CurBB].get(), CurBB); for (auto &MI : *MBB) { - process(MI, MOutLocs, MInLocs); + process(MI, &MOutLocs, &MInLocs); ++CurInst; } MTracker->reset(); @@ -3142,8 +3142,8 @@ // Perform memory cleanup that emitLocations would do otherwise. for (int Idx = 0; Idx < MaxNumBlocks; ++Idx) { - delete[] MOutLocs[Idx]; - delete[] MInLocs[Idx]; + MOutLocs[Idx].reset(); + MInLocs[Idx].reset(); } } else { // Compute the extended ranges, iterating over scopes. There might be @@ -3169,8 +3169,8 @@ } // Elements of these arrays will be deleted by emitLocations. - delete[] MOutLocs; - delete[] MInLocs; + MOutLocs.reset(); + MInLocs.reset(); delete MTracker; delete TTracker; @@ -3197,6 +3197,7 @@ namespace { class LDVSSABlock; class LDVSSAUpdater; +using FuncValueTable = LiveDebugValues::InstrRefBasedLDV::FuncValueTable; // Pick a type to identify incoming block values as we construct SSA. We // can't use anything more robust than an integer unfortunately, as SSAUpdater @@ -3287,9 +3288,9 @@ /// Machine location where any PHI must occur. LocIdx Loc; /// Table of live-in machine value numbers for blocks / locations. - ValueIDNum **MLiveIns; + FuncValueTable &MLiveIns; - LDVSSAUpdater(LocIdx L, ValueIDNum **MLiveIns) : Loc(L), MLiveIns(MLiveIns) {} + LDVSSAUpdater(LocIdx L, FuncValueTable &MLiveIns) : Loc(L), MLiveIns(MLiveIns) {} void reset() { for (auto &Block : BlockMap) @@ -3447,8 +3448,8 @@ } // end namespace llvm Optional InstrRefBasedLDV::resolveDbgPHIs(MachineFunction &MF, - ValueIDNum **MLiveOuts, - ValueIDNum **MLiveIns, + FuncValueTable &MLiveOuts, + FuncValueTable &MLiveIns, MachineInstr &Here, uint64_t InstrNum) { // This function will be called twice per DBG_INSTR_REF, and might end up @@ -3559,7 +3560,7 @@ } ValueIDNum ValueToCheck; - ValueIDNum *BlockLiveOuts = MLiveOuts[PHIIt.first->BB.getNumber()]; + ValueTable &BlockLiveOuts = MLiveOuts[PHIIt.first->BB.getNumber()]; auto VVal = ValidatedValues.find(PHIIt.first); if (VVal == ValidatedValues.end()) {