qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH v1 23/43] helper-to-tcg: PrepareForTcgPass, demote phi nodes


From: Anton Johansson
Subject: [RFC PATCH v1 23/43] helper-to-tcg: PrepareForTcgPass, demote phi nodes
Date: Thu, 21 Nov 2024 02:49:27 +0100

PHI nodes have no clear analogue in TCG, this commits converts them to
stack accesses using a built-in LLVM transformation.

Signed-off-by: Anton Johansson <anjo@rev.ng>
---
 .../PrepareForTcgPass/PrepareForTcgPass.cpp   | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git 
a/subprojects/helper-to-tcg/passes/PrepareForTcgPass/PrepareForTcgPass.cpp 
b/subprojects/helper-to-tcg/passes/PrepareForTcgPass/PrepareForTcgPass.cpp
index ccbe3820a0..a2808eafed 100644
--- a/subprojects/helper-to-tcg/passes/PrepareForTcgPass/PrepareForTcgPass.cpp
+++ b/subprojects/helper-to-tcg/passes/PrepareForTcgPass/PrepareForTcgPass.cpp
@@ -18,7 +18,10 @@
 #include <PrepareForTcgPass.h>
 #include <llvm/ADT/SCCIterator.h>
 #include <llvm/IR/Function.h>
+#include <llvm/IR/InstIterator.h>
+#include <llvm/IR/Instructions.h>
 #include <llvm/IR/Module.h>
+#include <llvm/Transforms/Utils/Local.h>
 
 using namespace llvm;
 
@@ -50,8 +53,29 @@ static void removeFunctionsWithLoops(Module &M, 
ModuleAnalysisManager &MAM)
     }
 }
 
+inline void demotePhis(Function &F)
+{
+    if (F.isDeclaration()) {
+        return;
+    }
+
+    SmallVector<PHINode *, 10> Phis;
+    for (auto &I : instructions(F)) {
+        if (auto *Phi = dyn_cast<PHINode>(&I)) {
+            Phis.push_back(Phi);
+        }
+    }
+
+    for (auto *Phi : Phis) {
+        DemotePHIToStack(Phi);
+    }
+}
+
 PreservedAnalyses PrepareForTcgPass::run(Module &M, ModuleAnalysisManager &MAM)
 {
     removeFunctionsWithLoops(M, MAM);
+    for (Function &F : M) {
+        demotePhis(F);
+    }
     return PreservedAnalyses::none();
 }
-- 
2.45.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]