[PATCH] D58073: [GlobalISel][NFC]: Add interface to reserve memory in GISelWorklist

Aditya Nandakumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 11 13:22:14 PST 2019


aditya_nandakumar created this revision.
aditya_nandakumar added reviewers: arsenm, aemerson, bogner, dsanders, qcolombet, volkan, paquette.
Herald added subscribers: Petar.Avramovic, kristof.beyls, rovka, wdng.
Herald added a project: LLVM.

Added an interface to specify how many elements to reserve to GISelWorkList.
This change resulted in a 12% compile time improvement in the combiner pass(es), and 2.5% improvement in the legalizer.


Repository:
  rL LLVM

https://reviews.llvm.org/D58073

Files:
  include/llvm/CodeGen/GlobalISel/GISelWorkList.h
  lib/CodeGen/GlobalISel/Combiner.cpp
  lib/CodeGen/GlobalISel/Legalizer.cpp


Index: lib/CodeGen/GlobalISel/Legalizer.cpp
===================================================================
--- lib/CodeGen/GlobalISel/Legalizer.cpp
+++ lib/CodeGen/GlobalISel/Legalizer.cpp
@@ -129,7 +129,6 @@
   if (MF.getProperties().hasProperty(
           MachineFunctionProperties::Property::FailedISel))
     return false;
-  LLVM_DEBUG(dbgs() << "Legalize Machine IR for: " << MF.getName() << '\n');
   init(MF);
   const TargetPassConfig &TPC = getAnalysis<TargetPassConfig>();
   GISelCSEAnalysisWrapper &Wrapper =
@@ -142,6 +141,12 @@
   // Populate Insts
   InstListTy InstList;
   ArtifactListTy ArtifactList;
+  LLVM_DEBUG(dbgs() << "Legalize Machine IR for: " << MF.getName() << '\n');
+  unsigned MF_Size = 0;
+  for (auto &MBB : MF)
+    MF_Size += MBB.size();
+  InstList.reserve(MF_Size);
+  ArtifactList.reserve(MF_Size);
   ReversePostOrderTraversal<MachineFunction *> RPOT(&MF);
   // Perform legalization bottom up so we can DCE as we legalize.
   // Traverse BB in RPOT and within each basic block, add insts top down,
Index: lib/CodeGen/GlobalISel/Combiner.cpp
===================================================================
--- lib/CodeGen/GlobalISel/Combiner.cpp
+++ lib/CodeGen/GlobalISel/Combiner.cpp
@@ -111,7 +111,11 @@
     // insert with list bottom up, so while we pop_back_val, we'll traverse top
     // down RPOT.
     Changed = false;
+    unsigned MF_Size = 0;
+    for (auto &MBB : MF)
+      MF_Size += MBB.size();
     GISelWorkList<512> WorkList;
+    WorkList.reserve(MF_Size);
     WorkListMaintainer Observer(WorkList);
     GISelObserverWrapper WrapperObserver(&Observer);
     if (CSEInfo)
Index: include/llvm/CodeGen/GlobalISel/GISelWorkList.h
===================================================================
--- include/llvm/CodeGen/GlobalISel/GISelWorkList.h
+++ include/llvm/CodeGen/GlobalISel/GISelWorkList.h
@@ -39,6 +39,13 @@
 
   unsigned size() const { return WorklistMap.size(); }
 
+  void reserve(unsigned Size) {
+    if (Size > N) {
+      Worklist.reserve(Size);
+      WorklistMap.reserve(Size);
+    }
+  }
+
   /// Add the specified instruction to the worklist if it isn't already in it.
   void insert(MachineInstr *I) {
     if (WorklistMap.try_emplace(I, Worklist.size()).second)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58073.186319.patch
Type: text/x-patch
Size: 2259 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190211/f93dbe11/attachment.bin>


More information about the llvm-commits mailing list