[PATCH] D100162: [Debug] Fix unnecessary deep-copy for vecto to save compiling time

Qing Shan Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 8 21:02:19 PDT 2021


steven.zhang created this revision.
steven.zhang added reviewers: djtodoro, aprantl, vsk, probinson.
Herald added subscribers: pengfei, hiraditya.
steven.zhang requested review of this revision.
Herald added a project: LLVM.

We saw some big compiling time impact after enabling the debug entry value feature for X86 platform(D73534 <https://reviews.llvm.org/D73534>).  Compiling time goes from 900s->1600s with our testcase. It is caused by allocating/freeing the memory busily.

`using FwdRegWorklist = MapVector<unsigned, SmallVector<FwdRegParamInfo, 2>>;`

The value for this map vector is vector, and we miss the reference when access the element. The same happens for ``auto CalleesMap = MF->getCallSitesInfo();`` which is a DenseMap.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100162

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp


Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -717,7 +717,7 @@
     for (const MachineOperand &MO : MI.operands()) {
       if (MO.isReg() && MO.isDef() &&
           Register::isPhysicalRegister(MO.getReg())) {
-        for (auto FwdReg : ForwardedRegWorklist)
+        for (auto &FwdReg : ForwardedRegWorklist)
           if (TRI.regsOverlap(FwdReg.first, MO.getReg()))
             Defs.insert(FwdReg.first);
       }
@@ -766,7 +766,7 @@
 
   // Now that we are done handling this instruction, add items from the
   // temporary worklist to the real one.
-  for (auto New : TmpWorklistItems)
+  for (auto &New : TmpWorklistItems)
     addToFwdRegWorklist(ForwardedRegWorklist, New.first, EmptyExpr, New.second);
   TmpWorklistItems.clear();
 }
@@ -801,8 +801,8 @@
 static void collectCallSiteParameters(const MachineInstr *CallMI,
                                       ParamSet &Params) {
   const MachineFunction *MF = CallMI->getMF();
-  auto CalleesMap = MF->getCallSitesInfo();
-  auto CallFwdRegsInfo = CalleesMap.find(CallMI);
+  const auto &CalleesMap = MF->getCallSitesInfo();
+  const auto &CallFwdRegsInfo = CalleesMap.find(CallMI);
 
   // There is no information for the call instruction.
   if (CallFwdRegsInfo == CalleesMap.end())
@@ -819,7 +819,7 @@
       DIExpression::get(MF->getFunction().getContext(), {});
 
   // Add all the forwarding registers into the ForwardedRegWorklist.
-  for (auto ArgReg : CallFwdRegsInfo->second) {
+  for (auto &ArgReg : CallFwdRegsInfo->second) {
     bool InsertedReg =
         ForwardedRegWorklist.insert({ArgReg.Reg, {{ArgReg.Reg, EmptyExpr}}})
             .second;
@@ -867,7 +867,7 @@
     // Create an expression where the register's entry value is used.
     DIExpression *EntryExpr = DIExpression::get(
         MF->getFunction().getContext(), {dwarf::DW_OP_LLVM_entry_value, 1});
-    for (auto RegEntry : ForwardedRegWorklist) {
+    for (auto &RegEntry : ForwardedRegWorklist) {
       MachineLocation MLoc(RegEntry.first);
       finishCallSiteParams(MLoc, EntryExpr, RegEntry.second, Params);
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100162.336307.patch
Type: text/x-patch
Size: 2238 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210409/1d8ecef0/attachment.bin>


More information about the llvm-commits mailing list