[llvm] [CodeGen] Let RDA recompute live-ins. (PR #166773)

Mikhail Gudim via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 6 06:55:13 PST 2025


https://github.com/mgudim updated https://github.com/llvm/llvm-project/pull/166773

>From 2e6545021248bf4cbcfd0b7c818cbf6c36cbb5a2 Mon Sep 17 00:00:00 2001
From: Mikhail Gudim <mgudim at ventanamicro.com>
Date: Thu, 6 Nov 2025 05:27:28 -0800
Subject: [PATCH] [CodeGen] Let RDA recompute live-ins.

We plan to use `ReachingDefinitionsAnalysis` in
`PrologEpilogInsertion`. In some tests this will be a problem because
`ReachingDefinitionAnalysis` will have to run on a function that  does
not have live-in info. This PR lets `ReachingDefinitionsAnalysis`
recompute live-ins.
---
 llvm/lib/CodeGen/ReachingDefAnalysis.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
index 40a89078bcf59..b4b7e0b64ab4e 100644
--- a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
+++ b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
@@ -7,8 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/CodeGen/ReachingDefAnalysis.h"
+#include "llvm/ADT/PostOrderIterator.h"
 #include "llvm/ADT/SetOperations.h"
 #include "llvm/ADT/SmallSet.h"
+#include "llvm/CodeGen/LivePhysRegs.h"
 #include "llvm/CodeGen/LiveRegUnits.h"
 #include "llvm/CodeGen/MachineFrameInfo.h"
 #include "llvm/CodeGen/TargetInstrInfo.h"
@@ -287,6 +289,16 @@ void ReachingDefInfo::run(MachineFunction &mf) {
   TRI = STI.getRegisterInfo();
   TII = STI.getInstrInfo();
   LLVM_DEBUG(dbgs() << "********** REACHING DEFINITION ANALYSIS **********\n");
+
+  MachineFunctionProperties &Props = MF->getProperties();
+  if (!Props.hasTracksLiveness()) {
+    Props.setTracksLiveness();
+
+    SmallVector<MachineBasicBlock *> AllMBBsInPostOrder;
+    for (MachineBasicBlock *MBB : post_order(MF))
+      AllMBBsInPostOrder.push_back(MBB);
+    fullyRecomputeLiveIns(AllMBBsInPostOrder);
+  }
   init();
   traverse();
 }



More information about the llvm-commits mailing list