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

Aditya Nandakumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 28 14:10:28 PST 2023


aditya_nandakumar created this revision.
aditya_nandakumar added reviewers: arsenm, aemerson, paquette, foad, dsanders.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
aditya_nandakumar requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145006

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


Index: llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp
+++ llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp
@@ -217,10 +217,14 @@
 }
 
 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 {
Index: llvm/include/llvm/CodeGen/GlobalISel/CSEInfo.h
===================================================================
--- llvm/include/llvm/CodeGen/GlobalISel/CSEInfo.h
+++ llvm/include/llvm/CodeGen/GlobalISel/CSEInfo.h
@@ -111,6 +111,8 @@
   /// into the CSEMap. MI should return true for shouldCSE(MI->getOpcode())
   void insertInstr(MachineInstr *MI, void *InsertPos = nullptr);
 
+  bool HandlingRecordedInstrs = false;
+
 public:
   GISelCSEInfo() = default;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145006.501289.patch
Type: text/x-patch
Size: 1033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230228/3f54e708/attachment.bin>


More information about the llvm-commits mailing list