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

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 10 02:53:43 PDT 2024


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

…ally 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

>From 890dabbf5eb17303996bd18117e54540ff3cbed6 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 | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/CodeGen/MachinePipeliner.cpp b/llvm/lib/CodeGen/MachinePipeliner.cpp
index 8d500398f55e0..94e2ae3931f1e 100644
--- a/llvm/lib/CodeGen/MachinePipeliner.cpp
+++ b/llvm/lib/CodeGen/MachinePipeliner.cpp
@@ -127,6 +127,11 @@ 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 +434,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)
     ;
 
-  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