diff options
author | Jeremy Morse <jeremy.morse@sony.com> | 2024-07-18 15:05:57 +0100 |
---|---|---|
committer | Jeremy Morse <jeremy.morse@sony.com> | 2024-07-18 15:05:57 +0100 |
commit | 50b657c8f655a86826e94131729b0f13a58acbca (patch) | |
tree | bb5d0996b0eb2422bc0a96b45cb9f3f8e71243f2 /llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp | |
parent | 078198f310d55925ccd9e1aa5b6ff4af3b36bbc7 (diff) | |
download | llvm-50b657c8f655a86826e94131729b0f13a58acbca.zip llvm-50b657c8f655a86826e94131729b0f13a58acbca.tar.gz llvm-50b657c8f655a86826e94131729b0f13a58acbca.tar.bz2 |
Revert "[DebugInfo][InstrRef] Index DebugVariables and some DILocations (#99318)"
This reverts commit 078198f310d55925ccd9e1aa5b6ff4af3b36bbc7.
Buildbots unhappy, I must have fluffed it
Diffstat (limited to 'llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp')
-rw-r--r-- | llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp | 201 |
1 files changed, 98 insertions, 103 deletions
diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp index b9cf36a..247258a 100644 --- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp +++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp @@ -183,7 +183,6 @@ public: /// information from it. (XXX make it const?) MLocTracker *MTracker; MachineFunction &MF; - const DebugVariableMap &DVMap; bool ShouldEmitDebugEntryValues; /// Record of all changes in variable locations at a block position. Awkwardly @@ -192,9 +191,7 @@ public: struct Transfer { MachineBasicBlock::instr_iterator Pos; /// Position to insert DBG_VALUes MachineBasicBlock *MBB; /// non-null if we should insert after. - /// Vector of DBG_VALUEs to insert. Store with their DebugVariableID so that - /// they can be sorted into a stable order for emission at a later time. - SmallVector<std::pair<DebugVariableID, MachineInstr *>, 4> Insts; + SmallVector<MachineInstr *, 4> Insts; /// Vector of DBG_VALUEs to insert. }; /// Stores the resolved operands (machine locations and constants) and @@ -230,15 +227,15 @@ public: /// Map from LocIdxes to which DebugVariables are based that location. /// Mantained while stepping through the block. Not accurate if /// VarLocs[Idx] != MTracker->LocIdxToIDNum[Idx]. - DenseMap<LocIdx, SmallSet<DebugVariableID, 4>> ActiveMLocs; + DenseMap<LocIdx, SmallSet<DebugVariable, 4>> ActiveMLocs; /// Map from DebugVariable to it's current location and qualifying meta /// information. To be used in conjunction with ActiveMLocs to construct /// enough information for the DBG_VALUEs for a particular LocIdx. - DenseMap<DebugVariableID, ResolvedDbgValue> ActiveVLocs; + DenseMap<DebugVariable, ResolvedDbgValue> ActiveVLocs; /// Temporary cache of DBG_VALUEs to be entered into the Transfers collection. - SmallVector<std::pair<DebugVariableID, MachineInstr *>, 4> PendingDbgValues; + SmallVector<MachineInstr *, 4> PendingDbgValues; /// Record of a use-before-def: created when a value that's live-in to the /// current block isn't available in any machine location, but it will be @@ -247,12 +244,12 @@ public: /// Value of this variable, def'd in block. SmallVector<DbgOp> Values; /// Identity of this variable. - DebugVariableID VarID; + DebugVariable Var; /// Additional variable properties. DbgValueProperties Properties; - UseBeforeDef(ArrayRef<DbgOp> Values, DebugVariableID VarID, + UseBeforeDef(ArrayRef<DbgOp> Values, const DebugVariable &Var, const DbgValueProperties &Properties) - : Values(Values.begin(), Values.end()), VarID(VarID), + : Values(Values.begin(), Values.end()), Var(Var), Properties(Properties) {} }; @@ -263,16 +260,15 @@ public: /// The set of variables that are in UseBeforeDefs and can become a location /// once the relevant value is defined. An element being erased from this /// collection prevents the use-before-def materializing. - DenseSet<DebugVariableID> UseBeforeDefVariables; + DenseSet<DebugVariable> UseBeforeDefVariables; const TargetRegisterInfo &TRI; const BitVector &CalleeSavedRegs; TransferTracker(const TargetInstrInfo *TII, MLocTracker *MTracker, - MachineFunction &MF, const DebugVariableMap &DVMap, - const TargetRegisterInfo &TRI, + MachineFunction &MF, const TargetRegisterInfo &TRI, const BitVector &CalleeSavedRegs, const TargetPassConfig &TPC) - : TII(TII), MTracker(MTracker), MF(MF), DVMap(DVMap), TRI(TRI), + : TII(TII), MTracker(MTracker), MF(MF), TRI(TRI), CalleeSavedRegs(CalleeSavedRegs) { TLI = MF.getSubtarget().getTargetLowering(); auto &TM = TPC.getTM<TargetMachine>(); @@ -356,7 +352,7 @@ public: /// determine the values used by Value. void loadVarInloc(MachineBasicBlock &MBB, DbgOpIDMap &DbgOpStore, const SmallVectorImpl<ValueLocPair> &ValueToLoc, - DebugVariableID VarID, DbgValue Value) { + DebugVariable Var, DbgValue Value) { SmallVector<DbgOp> DbgOps; SmallVector<ResolvedDbgOp> ResolvedDbgOps; bool IsValueValid = true; @@ -405,7 +401,7 @@ public: static_cast<unsigned>(Num.getInst())); continue; } - recoverAsEntryValue(VarID, Value.Properties, Num); + recoverAsEntryValue(Var, Value.Properties, Num); IsValueValid = false; break; } @@ -423,7 +419,8 @@ public: // Add UseBeforeDef entry for the last value to be defined in this block. if (LastUseBeforeDef) { - addUseBeforeDef(VarID, Value.Properties, DbgOps, LastUseBeforeDef); + addUseBeforeDef(Var, Value.Properties, DbgOps, + LastUseBeforeDef); return; } @@ -431,15 +428,13 @@ public: // the transfer. for (const ResolvedDbgOp &Op : ResolvedDbgOps) if (!Op.IsConst) - ActiveMLocs[Op.Loc].insert(VarID); + ActiveMLocs[Op.Loc].insert(Var); auto NewValue = ResolvedDbgValue{ResolvedDbgOps, Value.Properties}; - auto Result = ActiveVLocs.insert(std::make_pair(VarID, NewValue)); + auto Result = ActiveVLocs.insert(std::make_pair(Var, NewValue)); if (!Result.second) Result.first->second = NewValue; - auto &[Var, DILoc] = DVMap.lookupDVID(VarID); PendingDbgValues.push_back( - std::make_pair(VarID, &*MTracker->emitLoc(ResolvedDbgOps, Var, DILoc, - Value.Properties))); + MTracker->emitLoc(ResolvedDbgOps, Var, Value.Properties)); } /// Load object with live-in variable values. \p mlocs contains the live-in @@ -450,7 +445,7 @@ public: /// FIXME: could just examine mloctracker instead of passing in \p mlocs? void loadInlocs(MachineBasicBlock &MBB, ValueTable &MLocs, DbgOpIDMap &DbgOpStore, - const SmallVectorImpl<std::pair<DebugVariableID, DbgValue>> &VLocs, + const SmallVectorImpl<std::pair<DebugVariable, DbgValue>> &VLocs, unsigned NumLocs) { ActiveMLocs.clear(); ActiveVLocs.clear(); @@ -511,11 +506,11 @@ public: /// Record that \p Var has value \p ID, a value that becomes available /// later in the function. - void addUseBeforeDef(DebugVariableID VarID, + void addUseBeforeDef(const DebugVariable &Var, const DbgValueProperties &Properties, const SmallVectorImpl<DbgOp> &DbgOps, unsigned Inst) { - UseBeforeDefs[Inst].emplace_back(DbgOps, VarID, Properties); - UseBeforeDefVariables.insert(VarID); + UseBeforeDefs[Inst].emplace_back(DbgOps, Var, Properties); + UseBeforeDefVariables.insert(Var); } /// After the instruction at index \p Inst and position \p pos has been @@ -534,7 +529,7 @@ public: // Populate ValueToLoc with illegal default mappings for every value used by // any UseBeforeDef variables for this instruction. for (auto &Use : MIt->second) { - if (!UseBeforeDefVariables.count(Use.VarID)) + if (!UseBeforeDefVariables.count(Use.Var)) continue; for (DbgOp &Op : Use.Values) { @@ -573,7 +568,7 @@ public: // Using the map of values to locations, produce a final set of values for // this variable. for (auto &Use : MIt->second) { - if (!UseBeforeDefVariables.count(Use.VarID)) + if (!UseBeforeDefVariables.count(Use.Var)) continue; SmallVector<ResolvedDbgOp> DbgOps; @@ -596,9 +591,8 @@ public: continue; // Otherwise, we're good to go. - auto &[Var, DILoc] = DVMap.lookupDVID(Use.VarID); - PendingDbgValues.push_back(std::make_pair( - Use.VarID, MTracker->emitLoc(DbgOps, Var, DILoc, Use.Properties))); + PendingDbgValues.push_back( + MTracker->emitLoc(DbgOps, Use.Var, Use.Properties)); } flushDbgValues(pos, nullptr); } @@ -648,7 +642,7 @@ public: return Reg != SP && Reg != FP; } - bool recoverAsEntryValue(DebugVariableID VarID, + bool recoverAsEntryValue(const DebugVariable &Var, const DbgValueProperties &Prop, const ValueIDNum &Num) { // Is this variable location a candidate to be an entry value. First, @@ -669,8 +663,6 @@ public: DIExpr = *NonVariadicExpression; } - auto &[Var, DILoc] = DVMap.lookupDVID(VarID); - // Is the variable appropriate for entry values (i.e., is a parameter). if (!isEntryValueVariable(Var, DIExpr)) return false; @@ -684,8 +676,9 @@ public: DIExpression::prepend(DIExpr, DIExpression::EntryValue); Register Reg = MTracker->LocIdxToLocID[Num.getLoc()]; MachineOperand MO = MachineOperand::CreateReg(Reg, false); - PendingDbgValues.push_back(std::make_pair( - VarID, &*emitMOLoc(MO, Var, {NewExpr, Prop.Indirect, false}))); + + PendingDbgValues.push_back( + emitMOLoc(MO, Var, {NewExpr, Prop.Indirect, false})); return true; } @@ -694,20 +687,19 @@ public: DebugVariable Var(MI.getDebugVariable(), MI.getDebugExpression(), MI.getDebugLoc()->getInlinedAt()); DbgValueProperties Properties(MI); - DebugVariableID VarID = DVMap.getDVID(Var); // Ignore non-register locations, we don't transfer those. if (MI.isUndefDebugValue() || all_of(MI.debug_operands(), [](const MachineOperand &MO) { return !MO.isReg(); })) { - auto It = ActiveVLocs.find(VarID); + auto It = ActiveVLocs.find(Var); if (It != ActiveVLocs.end()) { for (LocIdx Loc : It->second.loc_indices()) - ActiveMLocs[Loc].erase(VarID); + ActiveMLocs[Loc].erase(Var); ActiveVLocs.erase(It); } // Any use-before-defs no longer apply. - UseBeforeDefVariables.erase(VarID); + UseBeforeDefVariables.erase(Var); return; } @@ -733,15 +725,14 @@ public: SmallVectorImpl<ResolvedDbgOp> &NewLocs) { DebugVariable Var(MI.getDebugVariable(), MI.getDebugExpression(), MI.getDebugLoc()->getInlinedAt()); - DebugVariableID VarID = DVMap.getDVID(Var); // Any use-before-defs no longer apply. - UseBeforeDefVariables.erase(VarID); + UseBeforeDefVariables.erase(Var); // Erase any previous location. - auto It = ActiveVLocs.find(VarID); + auto It = ActiveVLocs.find(Var); if (It != ActiveVLocs.end()) { for (LocIdx Loc : It->second.loc_indices()) - ActiveMLocs[Loc].erase(VarID); + ActiveMLocs[Loc].erase(Var); } // If there _is_ no new location, all we had to do was erase. @@ -751,7 +742,7 @@ public: return; } - SmallVector<std::pair<LocIdx, DebugVariableID>> LostMLocs; + SmallVector<std::pair<LocIdx, DebugVariable>> LostMLocs; for (ResolvedDbgOp &Op : NewLocs) { if (Op.IsConst) continue; @@ -778,17 +769,17 @@ public: for (const auto &LostMLoc : LostMLocs) ActiveMLocs[LostMLoc.first].erase(LostMLoc.second); LostMLocs.clear(); - It = ActiveVLocs.find(VarID); + It = ActiveVLocs.find(Var); ActiveMLocs[NewLoc.asU64()].clear(); VarLocs[NewLoc.asU64()] = MTracker->readMLoc(NewLoc); } - ActiveMLocs[NewLoc].insert(VarID); + ActiveMLocs[NewLoc].insert(Var); } if (It == ActiveVLocs.end()) { ActiveVLocs.insert( - std::make_pair(VarID, ResolvedDbgValue(NewLocs, Properties))); + std::make_pair(Var, ResolvedDbgValue(NewLocs, Properties))); } else { It->second.Ops.assign(NewLocs); It->second.Properties = Properties; @@ -831,21 +822,21 @@ public: // explicitly undef, then stop here. if (!NewLoc && !MakeUndef) { // Try and recover a few more locations with entry values. - for (DebugVariableID VarID : ActiveMLocIt->second) { - auto &Prop = ActiveVLocs.find(VarID)->second.Properties; - recoverAsEntryValue(VarID, Prop, OldValue); + for (const auto &Var : ActiveMLocIt->second) { + auto &Prop = ActiveVLocs.find(Var)->second.Properties; + recoverAsEntryValue(Var, Prop, OldValue); } flushDbgValues(Pos, nullptr); return; } // Examine all the variables based on this location. - DenseSet<DebugVariableID> NewMLocs; + DenseSet<DebugVariable> NewMLocs; // If no new location has been found, every variable that depends on this // MLoc is dead, so end their existing MLoc->Var mappings as well. - SmallVector<std::pair<LocIdx, DebugVariableID>> LostMLocs; - for (DebugVariableID VarID : ActiveMLocIt->second) { - auto ActiveVLocIt = ActiveVLocs.find(VarID); + SmallVector<std::pair<LocIdx, DebugVariable>> LostMLocs; + for (const auto &Var : ActiveMLocIt->second) { + auto ActiveVLocIt = ActiveVLocs.find(Var); // Re-state the variable location: if there's no replacement then NewLoc // is std::nullopt and a $noreg DBG_VALUE will be created. Otherwise, a // DBG_VALUE identifying the alternative location will be emitted. @@ -864,21 +855,19 @@ public: replace_copy(ActiveVLocIt->second.Ops, DbgOps.begin(), OldOp, NewOp); } - auto &[Var, DILoc] = DVMap.lookupDVID(VarID); - PendingDbgValues.push_back(std::make_pair( - VarID, &*MTracker->emitLoc(DbgOps, Var, DILoc, Properties))); + PendingDbgValues.push_back(MTracker->emitLoc(DbgOps, Var, Properties)); // Update machine locations <=> variable locations maps. Defer updating // ActiveMLocs to avoid invalidating the ActiveMLocIt iterator. if (!NewLoc) { for (LocIdx Loc : ActiveVLocIt->second.loc_indices()) { if (Loc != MLoc) - LostMLocs.emplace_back(Loc, VarID); + LostMLocs.emplace_back(Loc, Var); } ActiveVLocs.erase(ActiveVLocIt); } else { ActiveVLocIt->second.Ops = DbgOps; - NewMLocs.insert(VarID); + NewMLocs.insert(Var); } } @@ -902,8 +891,8 @@ public: // Commit ActiveMLoc changes. ActiveMLocIt->second.clear(); if (!NewMLocs.empty()) - for (DebugVariableID VarID : NewMLocs) - ActiveMLocs[*NewLoc].insert(VarID); + for (auto &Var : NewMLocs) + ActiveMLocs[*NewLoc].insert(Var); } /// Transfer variables based on \p Src to be based on \p Dst. This handles @@ -926,18 +915,17 @@ public: // For each variable based on Src; create a location at Dst. ResolvedDbgOp SrcOp(Src); ResolvedDbgOp DstOp(Dst); - for (DebugVariableID VarID : MovingVars) { - auto ActiveVLocIt = ActiveVLocs.find(VarID); + for (const auto &Var : MovingVars) { + auto ActiveVLocIt = ActiveVLocs.find(Var); assert(ActiveVLocIt != ActiveVLocs.end()); // Update all instances of Src in the variable's tracked values to Dst. std::replace(ActiveVLocIt->second.Ops.begin(), ActiveVLocIt->second.Ops.end(), SrcOp, DstOp); - auto &[Var, DILoc] = DVMap.lookupDVID(VarID); - MachineInstr *MI = MTracker->emitLoc(ActiveVLocIt->second.Ops, Var, DILoc, + MachineInstr *MI = MTracker->emitLoc(ActiveVLocIt->second.Ops, Var, ActiveVLocIt->second.Properties); - PendingDbgValues.push_back(std::make_pair(VarID, MI)); + PendingDbgValues.push_back(MI); } ActiveMLocs[Src].clear(); flushDbgValues(Pos, nullptr); @@ -1188,9 +1176,11 @@ LLVM_DUMP_METHOD void MLocTracker::dump_mloc_map() { MachineInstrBuilder MLocTracker::emitLoc(const SmallVectorImpl<ResolvedDbgOp> &DbgOps, - const DebugVariable &Var, const DILocation *DILoc, + const DebugVariable &Var, const DbgValueProperties &Properties) { - DebugLoc DL = DebugLoc(DILoc); + DebugLoc DL = DILocation::get(Var.getVariable()->getContext(), 0, 0, + Var.getVariable()->getScope(), + const_cast<DILocation *>(Var.getInlinedAt())); const MCInstrDesc &Desc = Properties.IsVariadic ? TII.get(TargetOpcode::DBG_VALUE_LIST) @@ -1736,8 +1726,7 @@ bool InstrRefBasedLDV::transferDebugInstrRef(MachineInstr &MI, LastUseBeforeDef = std::max(LastUseBeforeDef, NewID.getInst()); } if (IsValidUseBeforeDef) { - DebugVariableID VID = DVMap.insertDVID(V, MI.getDebugLoc().get()); - TTracker->addUseBeforeDef(VID, {MI.getDebugExpression(), false, true}, + TTracker->addUseBeforeDef(V, {MI.getDebugExpression(), false, true}, DbgOps, LastUseBeforeDef); } } @@ -1746,11 +1735,9 @@ bool InstrRefBasedLDV::transferDebugInstrRef(MachineInstr &MI, // This DBG_VALUE is potentially a $noreg / undefined location, if // FoundLoc is illegal. // (XXX -- could morph the DBG_INSTR_REF in the future). - MachineInstr *DbgMI = - MTracker->emitLoc(NewLocs, V, MI.getDebugLoc().get(), Properties); - DebugVariableID ID = DVMap.getDVID(V); + MachineInstr *DbgMI = MTracker->emitLoc(NewLocs, V, Properties); - TTracker->PendingDbgValues.push_back(std::make_pair(ID, DbgMI)); + TTracker->PendingDbgValues.push_back(DbgMI); TTracker->flushDbgValues(MI.getIterator(), nullptr); return true; } @@ -3125,8 +3112,7 @@ void InstrRefBasedLDV::getBlocksForScope( } void InstrRefBasedLDV::buildVLocValueMap( - const DILocation *DILoc, - const SmallSet<DebugVariableID, 4> &VarsWeCareAbout, + const DILocation *DILoc, const SmallSet<DebugVariable, 4> &VarsWeCareAbout, SmallPtrSetImpl<MachineBasicBlock *> &AssignBlocks, LiveInsT &Output, FuncValueTable &MOutLocs, FuncValueTable &MInLocs, SmallVectorImpl<VLocTracker> &AllTheVLocs) { @@ -3202,7 +3188,7 @@ void InstrRefBasedLDV::buildVLocValueMap( // between blocks. This keeps the locality of working on one lexical scope at // at time, but avoids re-processing variable values because some other // variable has been assigned. - for (DebugVariableID VarID : VarsWeCareAbout) { + for (const auto &Var : VarsWeCareAbout) { // Re-initialize live-ins and live-outs, to clear the remains of previous // variables live-ins / live-outs. for (unsigned int I = 0; I < NumBlocks; ++I) { @@ -3216,7 +3202,7 @@ void InstrRefBasedLDV::buildVLocValueMap( SmallPtrSet<MachineBasicBlock *, 32> DefBlocks; for (const MachineBasicBlock *ExpMBB : BlocksToExplore) { auto &TransferFunc = AllTheVLocs[ExpMBB->getNumber()].Vars; - if (TransferFunc.contains(VarID)) + if (TransferFunc.contains(Var)) DefBlocks.insert(const_cast<MachineBasicBlock *>(ExpMBB)); } @@ -3226,7 +3212,7 @@ void InstrRefBasedLDV::buildVLocValueMap( // only one value definition, things are very simple. if (DefBlocks.size() == 1) { placePHIsForSingleVarDefinition(MutBlocksToExplore, *DefBlocks.begin(), - AllTheVLocs, VarID, Output); + AllTheVLocs, Var, Output); continue; } @@ -3299,7 +3285,7 @@ void InstrRefBasedLDV::buildVLocValueMap( // Do transfer function. auto &VTracker = AllTheVLocs[MBB->getNumber()]; - auto TransferIt = VTracker.Vars.find(VarID); + auto TransferIt = VTracker.Vars.find(Var); if (TransferIt != VTracker.Vars.end()) { // Erase on empty transfer (DBG_VALUE $noreg). if (TransferIt->second.Kind == DbgValue::Undef) { @@ -3361,11 +3347,9 @@ void InstrRefBasedLDV::buildVLocValueMap( continue; if (BlockLiveIn->Kind == DbgValue::VPHI) BlockLiveIn->Kind = DbgValue::Def; - auto &[Var, DILoc] = DVMap.lookupDVID(VarID); assert(BlockLiveIn->Properties.DIExpr->getFragmentInfo() == - Var.getFragment() && - "Fragment info missing during value prop"); - Output[MBB->getNumber()].push_back(std::make_pair(VarID, *BlockLiveIn)); + Var.getFragment() && "Fragment info missing during value prop"); + Output[MBB->getNumber()].push_back(std::make_pair(Var, *BlockLiveIn)); } } // Per-variable loop. @@ -3376,7 +3360,7 @@ void InstrRefBasedLDV::buildVLocValueMap( void InstrRefBasedLDV::placePHIsForSingleVarDefinition( const SmallPtrSetImpl<MachineBasicBlock *> &InScopeBlocks, MachineBasicBlock *AssignMBB, SmallVectorImpl<VLocTracker> &AllTheVLocs, - DebugVariableID VarID, LiveInsT &Output) { + const DebugVariable &Var, LiveInsT &Output) { // If there is a single definition of the variable, then working out it's // value everywhere is very simple: it's every block dominated by the // definition. At the dominance frontier, the usual algorithm would: @@ -3389,7 +3373,7 @@ void InstrRefBasedLDV::placePHIsForSingleVarDefinition( // Pick out the variables value from the block transfer function. VLocTracker &VLocs = AllTheVLocs[AssignMBB->getNumber()]; - auto ValueIt = VLocs.Vars.find(VarID); + auto ValueIt = VLocs.Vars.find(Var); const DbgValue &Value = ValueIt->second; // If it's an explicit assignment of "undef", that means there is no location @@ -3404,7 +3388,7 @@ void InstrRefBasedLDV::placePHIsForSingleVarDefinition( if (!DomTree->properlyDominates(AssignMBB, ScopeBlock)) continue; - Output[ScopeBlock->getNumber()].push_back({VarID, Value}); + Output[ScopeBlock->getNumber()].push_back({Var, Value}); } // All blocks that aren't dominated have no live-in value, thus no variable @@ -3531,9 +3515,9 @@ bool InstrRefBasedLDV::depthFirstVLocAndEmit( const ScopeToVarsT &ScopeToVars, ScopeToAssignBlocksT &ScopeToAssignBlocks, LiveInsT &Output, FuncValueTable &MOutLocs, FuncValueTable &MInLocs, SmallVectorImpl<VLocTracker> &AllTheVLocs, MachineFunction &MF, + DenseMap<DebugVariable, unsigned> &AllVarsNumbering, const TargetPassConfig &TPC) { - TTracker = - new TransferTracker(TII, MTracker, MF, DVMap, *TRI, CalleeSavedRegs, TPC); + TTracker = new TransferTracker(TII, MTracker, MF, *TRI, CalleeSavedRegs, TPC); unsigned NumLocs = MTracker->getNumLocs(); VTracker = nullptr; @@ -3638,24 +3622,31 @@ bool InstrRefBasedLDV::depthFirstVLocAndEmit( if (MInLocs.hasTableFor(*MBB)) EjectBlock(*MBB); - return emitTransfers(); + return emitTransfers(AllVarsNumbering); } -bool InstrRefBasedLDV::emitTransfers() { +bool InstrRefBasedLDV::emitTransfers( + DenseMap<DebugVariable, unsigned> &AllVarsNumbering) { // Go through all the transfers recorded in the TransferTracker -- this is // both the live-ins to a block, and any movements of values that happen // in the middle. - for (auto &P : TTracker->Transfers) { + for (const auto &P : TTracker->Transfers) { // We have to insert DBG_VALUEs in a consistent order, otherwise they // appear in DWARF in different orders. Use the order that they appear // when walking through each block / each instruction, stored in - // DVMap. - llvm::sort(P.Insts, llvm::less_first()); + // AllVarsNumbering. + SmallVector<std::pair<unsigned, MachineInstr *>> Insts; + for (MachineInstr *MI : P.Insts) { + DebugVariable Var(MI->getDebugVariable(), MI->getDebugExpression(), + MI->getDebugLoc()->getInlinedAt()); + Insts.emplace_back(AllVarsNumbering.find(Var)->second, MI); + } + llvm::sort(Insts, llvm::less_first()); // Insert either before or after the designated point... if (P.MBB) { MachineBasicBlock &MBB = *P.MBB; - for (const auto &Pair : P.Insts) + for (const auto &Pair : Insts) MBB.insert(P.Pos, Pair.second); } else { // Terminators, like tail calls, can clobber things. Don't try and place @@ -3664,7 +3655,7 @@ bool InstrRefBasedLDV::emitTransfers() { continue; MachineBasicBlock &MBB = *P.Pos->getParent(); - for (const auto &Pair : P.Insts) + for (const auto &Pair : Insts) MBB.insertAfterBundle(P.Pos, Pair.second); } } @@ -3719,7 +3710,7 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF, initialSetup(MF); MLocTransfer.resize(MaxNumBlocks); - vlocs.resize(MaxNumBlocks, VLocTracker(DVMap, OverlapFragments, EmptyExpr)); + vlocs.resize(MaxNumBlocks, VLocTracker(OverlapFragments, EmptyExpr)); SavedLiveIns.resize(MaxNumBlocks); produceMLocTransferFunction(MF, MLocTransfer, MaxNumBlocks); @@ -3775,6 +3766,10 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF, MTracker->reset(); } + // Number all variables in the order that they appear, to be used as a stable + // insertion order later. + DenseMap<DebugVariable, unsigned> AllVarsNumbering; + // Map from one LexicalScope to all the variables in that scope. ScopeToVarsT ScopeToVars; @@ -3793,15 +3788,16 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF, auto *VTracker = &vlocs[MBB->getNumber()]; // Collect each variable with a DBG_VALUE in this block. for (auto &idx : VTracker->Vars) { - DebugVariableID VarID = idx.first; - const DILocation *ScopeLoc = VTracker->Scopes[VarID]; + const auto &Var = idx.first; + const DILocation *ScopeLoc = VTracker->Scopes[Var]; assert(ScopeLoc != nullptr); auto *Scope = LS.findLexicalScope(ScopeLoc); // No insts in scope -> shouldn't have been recorded. assert(Scope != nullptr); - ScopeToVars[Scope].insert(VarID); + AllVarsNumbering.insert(std::make_pair(Var, AllVarsNumbering.size())); + ScopeToVars[Scope].insert(Var); ScopeToAssignBlocks[Scope].insert(VTracker->MBB); ScopeToDILocation[Scope] = ScopeLoc; ++VarAssignCount; @@ -3825,7 +3821,7 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF, // the "else" block of this condition. Changed = depthFirstVLocAndEmit( MaxNumBlocks, ScopeToDILocation, ScopeToVars, ScopeToAssignBlocks, - SavedLiveIns, MOutLocs, MInLocs, vlocs, MF, *TPC); + SavedLiveIns, MOutLocs, MInLocs, vlocs, MF, AllVarsNumbering, *TPC); } delete MTracker; @@ -3844,7 +3840,6 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF, SeenFragments.clear(); SeenDbgPHIs.clear(); DbgOpStore.clear(); - DVMap.clear(); return Changed; } |