[llvm] 00e5553 - [GISel][CSE][NFC]: Handle mutual recursion when inserting node

Aditya Nandakumar via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 2 14:43:01 PST 2023


Author: Aditya Nandakumar
Date: 2023-03-02T14:42:38-08:00
New Revision: 00e55531df5e579dba79498ccdc36ec96403a020

URL: https://github.com/llvm/llvm-project/commit/00e55531df5e579dba79498ccdc36ec96403a020
DIFF: https://github.com/llvm/llvm-project/commit/00e55531df5e579dba79498ccdc36ec96403a020.diff

LOG: [GISel][CSE][NFC]: Handle mutual recursion when inserting node

GISel's CSE mechanism lazily inserts instructions into the CSE List
to improve on efficiency as well as efficacy of CSE
(for allowing partially built instructions to be fully built).

There's unfortunately a mutual recursion via
 `handleRecordedInsts -> handleRecordedInst -> insertNode-> handleRecordedInsts`.

So this change simply records that we're already draining this list so we can just bail out on the recursion.

No changes to codegen are expected as we're still draining/handling the temporary
list via pop_back and we should get the same sequence of instructions
whether we call pop_back in a loop at the top level or recursive.

https://reviews.llvm.org/D145006

reviewed by: dsanders

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/GlobalISel/CSEInfo.h
    llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/GlobalISel/CSEInfo.h b/llvm/include/llvm/CodeGen/GlobalISel/CSEInfo.h
index 87dae64c5f902..09d6192a2bd5c 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/CSEInfo.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/CSEInfo.h
@@ -111,6 +111,8 @@ class GISelCSEInfo : public GISelChangeObserver {
   /// into the CSEMap. MI should return true for shouldCSE(MI->getOpcode())
   void insertInstr(MachineInstr *MI, void *InsertPos = nullptr);
 
+  bool HandlingRecordedInstrs = false;
+
 public:
   GISelCSEInfo() = default;
 

diff  --git a/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp b/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp
index 356d208fc881d..6d8f5d55ad8ad 100644
--- a/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp
@@ -217,10 +217,14 @@ void GISelCSEInfo::handleRemoveInst(MachineInstr *MI) {
 }
 
 void GISelCSEInfo::handleRecordedInsts() {
+  if (HandlingRecordedInstrs)
+    return;
+  HandlingRecordedInstrs = true;
   while (!TemporaryInsts.empty()) {
     auto *MI = TemporaryInsts.pop_back_val();
     handleRecordedInst(MI);
   }
+  HandlingRecordedInstrs = false;
 }
 
 bool GISelCSEInfo::shouldCSE(unsigned Opc) const {


        


More information about the llvm-commits mailing list