[Bf-blender-cvs] [b0f77c11d1e] functions: utility functions to optimize and print generated code

Jacques Lucke noreply at git.blender.org
Thu Mar 28 19:56:12 CET 2019


Commit: b0f77c11d1e7b022b4b8cd8ee211fc830f441375
Author: Jacques Lucke
Date:   Thu Mar 28 19:55:44 2019 +0100
Branches: functions
https://developer.blender.org/rBb0f77c11d1e7b022b4b8cd8ee211fc830f441375

utility functions to optimize and print generated code

===================================================================

M	source/blender/functions/backends/llvm/compile.cpp

===================================================================

diff --git a/source/blender/functions/backends/llvm/compile.cpp b/source/blender/functions/backends/llvm/compile.cpp
index b50bac7f106..8f8e47c94af 100644
--- a/source/blender/functions/backends/llvm/compile.cpp
+++ b/source/blender/functions/backends/llvm/compile.cpp
@@ -1,8 +1,10 @@
-#include "compile.hpp"
-#include "BLI_utildefines.h"
+#include "FN_llvm.hpp"
 
 #include <llvm/IR/Verifier.h>
+#include <llvm/IR/LegacyPassManager.h>
 #include <llvm/ExecutionEngine/ExecutionEngine.h>
+#include <llvm/Transforms/IPO/PassManagerBuilder.h>
+
 
 namespace FN {
 
@@ -11,6 +13,33 @@ namespace FN {
 		delete m_engine;
 	}
 
+	static void UNUSED_FUNCTION(optimize_module)(llvm::Module *module)
+	{
+		llvm::PassManagerBuilder builder;
+		builder.OptLevel = 3;
+
+		llvm::legacy::FunctionPassManager fpm(module);
+		builder.populateFunctionPassManager(fpm);
+
+		for (llvm::Function &function : module->functions()) {
+			fpm.run(function);
+		}
+
+	}
+
+	static void UNUSED_FUNCTION(save_machine_code)(
+		std::string filepath,
+		llvm::TargetMachine *target_machine,
+		llvm::Module *module)
+	{
+		LLVMTargetMachineEmitToFile(
+			(LLVMTargetMachineRef)target_machine,
+			llvm::wrap(module),
+			(char *)filepath.c_str(),
+			LLVMAssemblyFile,
+			NULL);
+	}
+
 	std::unique_ptr<CompiledLLVM>
 	CompiledLLVM::FromIR(
 		llvm::Module *module,
@@ -24,7 +53,6 @@ namespace FN {
 		ee->finalizeObject();
 		ee->generateCodeForModule(module);
 
-
 		uint64_t function_ptr = ee->getFunctionAddress(
 			main_function->getName().str());



More information about the Bf-blender-cvs mailing list