[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v1 22/43] helper-to-tcg: PrepareForTcgPass, remove functions
From: |
Anton Johansson |
Subject: |
[RFC PATCH v1 22/43] helper-to-tcg: PrepareForTcgPass, remove functions w. cycles |
Date: |
Thu, 21 Nov 2024 02:49:26 +0100 |
Functions with cycles are removed for two primary reasons:
* as a simplifying assumption for register allocation which occurs down
the line, and;
* if a function contains cycles post-optimization neither unrolling or
loop vectorization were beneficial, and the function _might_ be
better suited as a helper anyway.
Cycles are detected by iterating over Strongly Connected Components
(SCCs) which imply the existence of cycles if:
- a SCC contains more than one node, or;
- it has a self-edge.
Signed-off-by: Anton Johansson <anjo@rev.ng>
---
.../PrepareForTcgPass/PrepareForTcgPass.cpp | 32 +++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git
a/subprojects/helper-to-tcg/passes/PrepareForTcgPass/PrepareForTcgPass.cpp
b/subprojects/helper-to-tcg/passes/PrepareForTcgPass/PrepareForTcgPass.cpp
index f0ef1abd17..ccbe3820a0 100644
--- a/subprojects/helper-to-tcg/passes/PrepareForTcgPass/PrepareForTcgPass.cpp
+++ b/subprojects/helper-to-tcg/passes/PrepareForTcgPass/PrepareForTcgPass.cpp
@@ -16,10 +16,42 @@
//
#include <PrepareForTcgPass.h>
+#include <llvm/ADT/SCCIterator.h>
+#include <llvm/IR/Function.h>
+#include <llvm/IR/Module.h>
using namespace llvm;
+static void removeFunctionsWithLoops(Module &M, ModuleAnalysisManager &MAM)
+{
+ // Iterate over all Strongly Connected Components (SCCs), a SCC implies
+ // the existence of loops if:
+ // - it has more than one node, or;
+ // - it has a self-edge.
+ SmallVector<Function *, 16> FunctionsToRemove;
+ for (Function &F : M) {
+ if (F.isDeclaration()) {
+ continue;
+ }
+ for (auto It = scc_begin(&F); !It.isAtEnd(); ++It) {
+#if LLVM_VERSION_MAJOR > 10
+ if (It.hasCycle()) {
+#else
+ if (It.hasLoop()) {
+#endif
+ FunctionsToRemove.push_back(&F);
+ break;
+ }
+ }
+ }
+
+ for (auto *F : FunctionsToRemove) {
+ F->deleteBody();
+ }
+}
+
PreservedAnalyses PrepareForTcgPass::run(Module &M, ModuleAnalysisManager &MAM)
{
+ removeFunctionsWithLoops(M, MAM);
return PreservedAnalyses::none();
}
--
2.45.2
- [RFC PATCH v1 11/43] helper-to-tcg: Introduce llvm-compat, (continued)
- [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, 2024/11/20
- [RFC PATCH v1 22/43] helper-to-tcg: PrepareForTcgPass, remove functions w. cycles,
Anton Johansson <=
- [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
- [RFC PATCH v1 39/43] target/hexagon: Keep gen_slotval/check_noshuf for helper-to-tcg, Anton Johansson, 2024/11/20