@@ -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();
}
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(+)