[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
- [RFC PATCH v1 12/43] helper-to-tcg: Introduce custom LLVM pipeline, (continued)
- [RFC PATCH v1 12/43] helper-to-tcg: Introduce custom LLVM pipeline, Anton Johansson, 2024/11/20
- [RFC PATCH v1 11/43] helper-to-tcg: Introduce llvm-compat, Anton Johansson, 2024/11/20
- [RFC PATCH v1 14/43] helper-to-tcg: Introduce PrepareForOptPass, Anton Johansson, 2024/11/20
- [RFC PATCH v1 15/43] helper-to-tcg: PrepareForOptPass, map annotations, Anton Johansson, 2024/11/20
- [RFC PATCH v1 16/43] helper-to-tcg: PrepareForOptPass, Cull unused functions, Anton Johansson, 2024/11/20
- [RFC PATCH v1 17/43] helper-to-tcg: PrepareForOptPass, undef llvm.returnaddress, Anton Johansson, 2024/11/20
- [RFC PATCH v1 19/43] helper-to-tcg: Pipeline, run optimization pass, Anton Johansson, 2024/11/20
- [RFC PATCH v1 18/43] helper-to-tcg: PrepareForOptPass, Remove noinline attribute, Anton Johansson, 2024/11/20
- [RFC PATCH v1 21/43] helper-to-tcg: Introduce PrepareForTcgPass, Anton Johansson, 2024/11/20
- [RFC PATCH v1 20/43] helper-to-tcg: Introduce pseudo instructions, Anton Johansson, 2024/11/20
- [RFC PATCH v1 23/43] helper-to-tcg: PrepareForTcgPass, demote phi nodes,
Anton Johansson <=
- [RFC PATCH v1 22/43] helper-to-tcg: PrepareForTcgPass, remove functions w. cycles, Anton Johansson, 2024/11/20
- [RFC PATCH v1 24/43] helper-to-tcg: PrepareForTcgPass, map TCG globals, Anton Johansson, 2024/11/20
- [RFC PATCH v1 25/43] helper-to-tcg: PrepareForTcgPass, transform GEPs, Anton Johansson, 2024/11/20
- [RFC PATCH v1 27/43] helper-to-tcg: PrepareForTcgPass, identity map trivial expressions, Anton Johansson, 2024/11/20
- [RFC PATCH v1 26/43] helper-to-tcg: PrepareForTcgPass, canonicalize IR, Anton Johansson, 2024/11/20
- [RFC PATCH v1 29/43] helper-to-tcg: Introduce TCG register allocation, Anton Johansson, 2024/11/20
- [RFC PATCH v1 28/43] helper-to-tcg: Introduce TcgType.h, Anton Johansson, 2024/11/20
- [RFC PATCH v1 43/43] target/hexagon: Use helper-to-tcg, Anton Johansson, 2024/11/20
- [RFC PATCH v1 40/43] target/hexagon: Emit annotations for helpers, Anton Johansson, 2024/11/20