[llvm] [MachinePipeliner] Give up machine pipeliner when the loop body is re… (PR #98292)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 11 04:33:44 PDT 2024


https://github.com/coderchenlin updated https://github.com/llvm/llvm-project/pull/98292

>From 54fcbe2be0c6300658fd9f781024c43649436191 Mon Sep 17 00:00:00 2001
From: chenlin <chenlin138 at huawei.com>
Date: Wed, 10 Jul 2024 17:36:51 +0800
Subject: [PATCH] [MachinePipeliner] Give up machine pipeliner when the loop
 body is really huge, and sms won't be success for huge body because of
 resource limit mostly. Also, the compile time will be reduce with this patch.
 (#98288)

fixs: https://github.com/llvm/llvm-project/issues/98288
---
 llvm/lib/CodeGen/MachinePipeliner.cpp | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/CodeGen/MachinePipeliner.cpp b/llvm/lib/CodeGen/MachinePipeliner.cpp
index 8d500398f55e0..f6e1a1a5a7585 100644
--- a/llvm/lib/CodeGen/MachinePipeliner.cpp
+++ b/llvm/lib/CodeGen/MachinePipeliner.cpp
@@ -127,6 +127,12 @@ static cl::opt<int>
                  cl::desc("Maximum stages allowed in the generated scheduled."),
                  cl::Hidden, cl::init(3));
 
+/// A command line argument to limit the number of instructions for loop body.
+static cl::opt<unsigned>
+    SwpMaxSize("pipeliner-max-body-size",
+               cl::desc("Size limit for the loop body to schedule."),
+               cl::Hidden, cl::init(2000));
+
 /// A command line option to disable the pruning of chain dependences due to
 /// an unrelated Phi.
 static cl::opt<bool>
@@ -429,13 +435,19 @@ bool MachinePipeliner::swingModuloScheduler(MachineLoop &L) {
 
   // Compute the number of 'real' instructions in the basic block by
   // ignoring terminators.
-  unsigned size = MBB->size();
+  unsigned Size = MBB->size();
   for (MachineBasicBlock::iterator I = MBB->getFirstTerminator(),
                                    E = MBB->instr_end();
-       I != E; ++I, --size)
+       I != E; ++I, --Size)
     ;
 
-  SMS.enterRegion(MBB, MBB->begin(), MBB->getFirstTerminator(), size);
+  // If the size exceeds the limit, mostly the sms will not be success,
+  // give up early to reduce compile time.
+  if (Size > SwpMaxSize) {
+    return false;
+  }
+
+  SMS.enterRegion(MBB, MBB->begin(), MBB->getFirstTerminator(), Size);
   SMS.schedule();
   SMS.exitRegion();
 



More information about the llvm-commits mailing list