[PATCH] D95273: AMDGPU: Reduce the number of expensive calls in SIFormMemoryClause

Changpeng Fang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 22 16:21:11 PST 2021


cfang created this revision.
cfang added reviewers: rampitec, arsenm.
Herald added subscribers: kerbowa, hiraditya, t-tye, tpr, dstuttard, yaxunl, nhaehnle, jvesely, kzhuravl.
cfang requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

RPTracker::reset(MI) is a very expensive call when the number of virtual registers is huge.
We observed a long compilation time issue when RPT::reset() is called once for each cluster.

In this work, we call RPT.reset() only at the first seen cluster, and use advance() to get
the register pressure for the later clusters in the same basic block. This could effectively reduce the number 
of the expensive calls and thus reduce the compile time.

Note: I am still seeing a couple LIT failures with the current state of this patch.


https://reviews.llvm.org/D95273

Files:
  llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp


Index: llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp
+++ llvm/lib/Target/AMDGPU/SIFormMemoryClauses.cpp
@@ -317,6 +317,8 @@
       MF.getFunction(), "amdgpu-max-memory-clause", MaxClause);
 
   for (MachineBasicBlock &MBB : MF) {
+    GCNDownwardRPTracker RPT(*LIS);
+    bool InitializedInBlock = false;
     MachineBasicBlock::instr_iterator Next;
     for (auto I = MBB.instr_begin(), E = MBB.instr_end(); I != E; I = Next) {
       MachineInstr &MI = *I;
@@ -327,12 +329,21 @@
       if (!isValidClauseInst(MI, IsVMEM))
         continue;
 
-      RegUse Defs, Uses;
-      GCNDownwardRPTracker RPT(*LIS);
-      RPT.reset(MI);
+      if (!InitializedInBlock) {
+        RPT.reset(MI);
+        InitializedInBlock = true;
+      } else {// Advance the state to the current MI.
+        RPT.advance(MachineBasicBlock::const_iterator(MI));
+        RPT.advance();
+      }
 
-      if (!processRegUses(MI, Defs, Uses, RPT))
+      auto LiveRegs = RPT.getLiveRegs();
+      RegUse Defs, Uses;
+      if (!processRegUses(MI, Defs, Uses, RPT)) {
+        // Restore the state before continue.
+        RPT.reset(MI, &LiveRegs);
         continue;
+      }
 
       unsigned Length = 1;
       for ( ; Next != E && Length < FuncMaxClause; ++Next) {
@@ -347,6 +358,10 @@
 
         ++Length;
       }
+
+      // Restore the state after processing the bundle.
+      RPT.reset(MI, &LiveRegs);
+
       if (Length < 2)
         continue;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95273.318673.patch
Type: text/x-patch
Size: 1556 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210123/0bc2b11f/attachment.bin>


More information about the llvm-commits mailing list