[Bf-blender-cvs] [4828cf2] object_nodes: Optimization passes for the generated LLVM code.
Lukas Tönne
noreply at git.blender.org
Mon Apr 11 09:18:04 CEST 2016
Commit: 4828cf23137cf3d15c634b4696730fd7845c8e42
Author: Lukas Tönne
Date: Sat Apr 9 15:47:29 2016 +0200
Branches: object_nodes
https://developer.blender.org/rB4828cf23137cf3d15c634b4696730fd7845c8e42
Optimization passes for the generated LLVM code.
===================================================================
M source/blender/blenvm/llvm/llvm_codegen.cc
M source/blender/blenvm/llvm/llvm_codegen.h
M source/blender/blenvm/llvm/llvm_headers.h
===================================================================
diff --git a/source/blender/blenvm/llvm/llvm_codegen.cc b/source/blender/blenvm/llvm/llvm_codegen.cc
index 5ad1311..73548bb 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.cc
+++ b/source/blender/blenvm/llvm/llvm_codegen.cc
@@ -473,6 +473,20 @@ llvm::Function *LLVMCompiler::codegen_node_function(const string &name, const No
return func;
}
+void LLVMCompiler::optimize_function(llvm::Function *func, int opt_level)
+{
+ using namespace llvm;
+ using legacy::FunctionPassManager;
+
+ FunctionPassManager FPM(module());
+
+ PassManagerBuilder builder;
+ builder.OptLevel = opt_level;
+ builder.populateFunctionPassManager(FPM);
+
+ FPM.run(*func);
+}
+
FunctionLLVM *LLVMCompiler::compile_function(const string &name, const NodeGraph &graph)
{
using namespace llvm;
@@ -484,6 +498,8 @@ FunctionLLVM *LLVMCompiler::compile_function(const string &name, const NodeGraph
BLI_assert(m_module->getFunction(name) && "Function not registered in module!");
BLI_assert(func != NULL && "codegen_node_function returned NULL!");
+ optimize_function(func, 2);
+
printf("=== NODE FUNCTION ===\n");
fflush(stdout);
func->dump();
@@ -493,14 +509,6 @@ FunctionLLVM *LLVMCompiler::compile_function(const string &name, const NodeGraph
verifyFunction(*func, &outs());
verifyModule(*m_module, &outs());
- FunctionPassManager fpm(m_module);
- PassManagerBuilder builder;
- builder.OptLevel = 0;
- builder.populateFunctionPassManager(fpm);
-// builder.populateModulePassManager(MPM);
-
- fpm.run(*func);
-
/* Note: Adding module to exec engine before creating the function prevents compilation! */
llvm_execution_engine()->addModule(m_module);
uint64_t address = llvm_execution_engine()->getFunctionAddress(name);
diff --git a/source/blender/blenvm/llvm/llvm_codegen.h b/source/blender/blenvm/llvm/llvm_codegen.h
index 1ec56b4..2479b83 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.h
+++ b/source/blender/blenvm/llvm/llvm_codegen.h
@@ -75,6 +75,8 @@ protected:
llvm::LLVMContext &context() const;
llvm::Module *module() const { return m_module; }
+ void optimize_function(llvm::Function *func, int opt_level);
+
llvm::StructType *codegen_struct_type(const string &name, const StructSpec *s);
llvm::Type *codegen_type(const string &name, const TypeDesc *td);
llvm::Constant *codegen_constant(const NodeValue *node_value);
diff --git a/source/blender/blenvm/llvm/llvm_headers.h b/source/blender/blenvm/llvm/llvm_headers.h
index 2137f89..d964d83 100644
--- a/source/blender/blenvm/llvm/llvm_headers.h
+++ b/source/blender/blenvm/llvm/llvm_headers.h
@@ -36,11 +36,8 @@
#include "llvm/IR/AssemblyAnnotationWriter.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Function.h"
-#include "llvm/PassManager.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/IRPrintingPasses.h"
-#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/TypeBuilder.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Linker/Linker.h"
@@ -49,8 +46,12 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetSelect.h"
-#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/MCJIT.h"
+/* passes */
+#include "llvm/PassManager.h"
+#include "llvm/IR/LegacyPassManagers.h"
+#include "llvm/Transforms/IPO/PassManagerBuilder.h"
+
#endif /* __LLVM_HEADERS_H__ */
More information about the Bf-blender-cvs
mailing list