[Bf-blender-cvs] [f19a6f3] object_nodes: Cleanup: renamed "codegen" files to "compiler" and split the implementation.
Lukas Tönne
noreply at git.blender.org
Tue May 24 12:08:00 CEST 2016
Commit: f19a6f39c562586599711d507682aef70c5d1db9
Author: Lukas Tönne
Date: Tue May 24 11:36:16 2016 +0200
Branches: object_nodes
https://developer.blender.org/rBf19a6f39c562586599711d507682aef70c5d1db9
Cleanup: renamed "codegen" files to "compiler" and split the implementation.
===================================================================
M source/blender/blenvm/intern/bvm_api.cc
M source/blender/blenvm/llvm/CMakeLists.txt
D source/blender/blenvm/llvm/llvm_codegen.cc
D source/blender/blenvm/llvm/llvm_codegen.h
A source/blender/blenvm/llvm/llvm_compiler.cc
A source/blender/blenvm/llvm/llvm_compiler.h
A source/blender/blenvm/llvm/llvm_compiler_dual.cc
A source/blender/blenvm/llvm/llvm_compiler_simple.cc
===================================================================
diff --git a/source/blender/blenvm/intern/bvm_api.cc b/source/blender/blenvm/intern/bvm_api.cc
index 586f713..5e83d62 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -64,7 +64,7 @@ extern "C" {
#include "bvm_function.h"
#ifdef WITH_LLVM
-#include "llvm_codegen.h"
+#include "llvm_compiler.h"
#include "llvm_engine.h"
#include "llvm_function.h"
#endif
diff --git a/source/blender/blenvm/llvm/CMakeLists.txt b/source/blender/blenvm/llvm/CMakeLists.txt
index 34a9193..8f9f15d 100644
--- a/source/blender/blenvm/llvm/CMakeLists.txt
+++ b/source/blender/blenvm/llvm/CMakeLists.txt
@@ -42,8 +42,10 @@ set(INC_SYS
)
set(SRC
- llvm_codegen.cc
- llvm_codegen.h
+ llvm_compiler.cc
+ llvm_compiler_simple.cc
+ llvm_compiler_dual.cc
+ llvm_compiler.h
llvm_engine.cc
llvm_engine.h
llvm_function.cc
diff --git a/source/blender/blenvm/llvm/llvm_codegen.cc b/source/blender/blenvm/llvm/llvm_compiler.cc
similarity index 53%
rename from source/blender/blenvm/llvm/llvm_codegen.cc
rename to source/blender/blenvm/llvm/llvm_compiler.cc
index 95b2c66..deaafc2 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.cc
+++ b/source/blender/blenvm/llvm/llvm_compiler.cc
@@ -25,7 +25,7 @@
* ***** END GPL LICENSE BLOCK *****
*/
-/** \file blender/blenvm/llvm/llvm_codegen.cc
+/** \file blender/blenvm/llvm/llvm_compiler.cc
* \ingroup llvm
*/
@@ -35,7 +35,7 @@
#include "node_graph.h"
-#include "llvm_codegen.h"
+#include "llvm_compiler.h"
#include "llvm_engine.h"
#include "llvm_function.h"
#include "llvm_headers.h"
@@ -427,455 +427,6 @@ llvm::Function *LLVMCompilerBase::declare_node_function(llvm::Module *mod, const
/* ------------------------------------------------------------------------- */
-llvm::Module *LLVMSimpleCompilerImpl::m_nodes_module = NULL;
-
-llvm::Type *LLVMSimpleCompilerImpl::get_value_type(const TypeSpec *spec, bool UNUSED(is_constant))
-{
- return bvm_get_llvm_type(context(), spec, false);
-}
-
-bool LLVMSimpleCompilerImpl::use_argument_pointer(const TypeSpec *typespec, bool UNUSED(is_constant))
-{
- using namespace llvm;
-
- if (typespec->is_structure()) {
- /* pass by reference */
- return true;
- }
- else {
- switch (typespec->base_type()) {
- case BVM_FLOAT:
- case BVM_INT:
- /* pass by value */
- return false;
- case BVM_FLOAT3:
- case BVM_FLOAT4:
- case BVM_MATRIX44:
- /* pass by reference */
- return true;
-
- case BVM_STRING:
- case BVM_RNAPOINTER:
- case BVM_MESH:
- case BVM_DUPLIS:
- /* TODO */
- break;
- }
- }
-
- return false;
-}
-
-llvm::Constant *LLVMSimpleCompilerImpl::create_node_value_constant(const NodeValue *node_value)
-{
- return bvm_create_llvm_constant(context(), node_value);
-}
-
-bool LLVMSimpleCompilerImpl::set_node_function_impl(OpCode op, const NodeType *UNUSED(nodetype),
- llvm::Function *func)
-{
- using namespace llvm;
-
- std::vector<Value*> args;
- args.reserve(func->arg_size());
- for (Function::arg_iterator a = func->arg_begin(); a != func->arg_end(); ++a)
- args.push_back(a);
-
- switch (op) {
- case OP_VALUE_FLOAT: {
- BasicBlock *block = BasicBlock::Create(context(), "entry", func);
- def_node_VALUE_FLOAT(context(), block, args[0], args[1]);
- return true;
- }
- case OP_VALUE_INT: {
- BasicBlock *block = BasicBlock::Create(context(), "entry", func);
- def_node_VALUE_INT(context(), block, args[0], args[1]);
- return true;
- }
- case OP_VALUE_FLOAT3: {
- BasicBlock *block = BasicBlock::Create(context(), "entry", func);
- def_node_VALUE_FLOAT3(context(), block, args[0], args[1]);
- return true;
- }
- case OP_VALUE_FLOAT4: {
- BasicBlock *block = BasicBlock::Create(context(), "entry", func);
- def_node_VALUE_FLOAT4(context(), block, args[0], args[1]);
- return true;
- }
- case OP_VALUE_MATRIX44: {
- BasicBlock *block = BasicBlock::Create(context(), "entry", func);
- def_node_VALUE_MATRIX44(context(), block, args[0], args[1]);
- return true;
- }
-
- default:
- return false;
- }
-}
-
-void LLVMSimpleCompilerImpl::define_nodes_module()
-{
- using namespace llvm;
-
- Module *mod = new llvm::Module("simple_nodes", context());
-
-#define DEF_OPCODE(op) \
- { \
- const NodeType *nodetype = NodeGraph::find_node_type(STRINGIFY(op)); \
- if (nodetype != NULL) { \
- Function *func = declare_node_function(mod, nodetype); \
- if (func != NULL) { \
- bool has_impl = set_node_function_impl(OP_##op, nodetype, func); \
- if (!has_impl) { \
- /* use C callback as implementation of the function */ \
- void *cb_ptr = modules::get_node_impl_value<OP_##op>(); \
- BLI_assert(cb_ptr != NULL && "No implementation for OpCode!"); \
- llvm_execution_engine()->addGlobalMapping(func, cb_ptr); \
- } \
- } \
- } \
- }
-
- BVM_DEFINE_OPCODES
-
-#undef DEF_OPCODE
-
- llvm_execution_engine()->addModule(mod);
-
- m_nodes_module = mod;
-}
-
-/* ------------------------------------------------------------------------- */
-
-llvm::Module *LLVMTextureCompilerImpl::m_nodes_module = NULL;
-
-llvm::Type *LLVMTextureCompilerImpl::get_value_type(const TypeSpec *spec, bool is_constant)
-{
- return bvm_get_llvm_type(context(), spec, !is_constant);
-}
-
-bool LLVMTextureCompilerImpl::use_argument_pointer(const TypeSpec *typespec, bool is_constant)
-{
- using namespace llvm;
-
- if (typespec->is_structure()) {
- /* pass by reference */
- return true;
- }
- else if (!is_constant && bvm_type_has_dual_value(typespec)) {
- return true;
- }
- else {
- switch (typespec->base_type()) {
- case BVM_FLOAT:
- case BVM_INT:
- /* pass by value */
- return false;
- case BVM_FLOAT3:
- case BVM_FLOAT4:
- case BVM_MATRIX44:
- /* pass by reference */
- return true;
-
- case BVM_STRING:
- case BVM_RNAPOINTER:
- case BVM_MESH:
- case BVM_DUPLIS:
- /* TODO */
- break;
- }
- }
-
- return false;
-}
-
-bool LLVMTextureCompilerImpl::use_elementary_argument_pointer(const TypeSpec *typespec)
-{
- using namespace llvm;
-
- if (typespec->is_structure()) {
- /* pass by reference */
- return true;
- }
- else {
- switch (typespec->base_type()) {
- case BVM_FLOAT:
- case BVM_INT:
- /* pass by value */
- return false;
- case BVM_FLOAT3:
- case BVM_FLOAT4:
- case BVM_MATRIX44:
- /* pass by reference */
- return true;
-
- case BVM_STRING:
- case BVM_RNAPOINTER:
- case BVM_MESH:
- case BVM_DUPLIS:
- /* TODO */
- break;
- }
- }
-
- return false;
-}
-
-llvm::Constant *LLVMTextureCompilerImpl::create_node_value_constant(const NodeValue *node_value)
-{
- return bvm_create_llvm_constant(context(), node_value);
-}
-
-llvm::Function *LLVMTextureCompilerImpl::declare_elementary_node_function(llvm::Module *mod, const NodeType *nodetype, const string &name)
-{
- using namespace llvm;
-
- std::vector<Type *> input_types, output_types;
- for (int i = 0; i < nodetype->num_inputs(); ++i) {
- const NodeInput *input = nodetype->find_input(i);
- const TypeSpec *typespec = input->typedesc.get_typespec();
- Type *type = bvm_get_llvm_type(context(), typespec, false);
- if (type == NULL)
- break;
- if (use_elementary_argument_pointer(typespec))
- type = type->getPointerTo();
- input_types.push_back(type);
- }
- for (int i = 0; i < nodetype->num_outputs(); ++i) {
- const NodeOutput *output = nodetype->find_output(i);
- const TypeSpec *typespec = output->typedesc.get_typespec();
- Type *type = bvm_get_llvm_type(context(), typespec, false);
- if (type == NULL)
- break;
- output_types.push_back(type);
- }
- if (input_types.size() != nodetype->num_inputs() ||
- output_types.size() != nodetype->num_outputs()) {
- /* some arguments could not be handled */
- return NULL;
- }
-
- FunctionType *functype = get_node_function_type(input_types, output_types);
-
- Function *func = Function::Create(functype, Function::ExternalLinkage, name, mod);
- return func;
-}
-
-bool LLVMTextureCompilerImpl::set_node_function_impl(OpCode op, const NodeType *nodetype,
- llvm::Function *value_func,
- std::vector<llvm::Function*> deriv_funcs)
-{
- using namespace llvm;
-
- typedef std::vector<Value*> ValueList;
-
- ValueList value_args;
- value_args.reserve(value_func->arg_size());
- for (Function::arg_iterator a = value_func->arg_begin(); a != value_func->arg_end(); ++a)
- value_args.push_back(a);
-
-#if 0 /* TODO only do the value function for now */
- std::vector<ValueList> deriv_args(nodetype->num_inputs());
- for (int n = 0; n < nodetype->num_inputs(); ++n) {
- deriv_args[n].reserve(deriv_funcs[n]->arg_size());
- for (Function::arg_iterator a = deriv_funcs[n]->arg_begin(); a != deriv_funcs[n]->arg_end(); ++a)
- deriv_args[n].push_back(a);
- }
-#endif
-
- switch (op) {
- case OP_VALUE_FLOAT: {
- BasicBlock *block = BasicBlock::Create(context(), "entry", value_func);
- def_node_VALUE_FLOAT(context(), block, value_args[0], value_args[1]);
- return true;
- }
- case OP_VALUE_INT: {
- BasicBlock *block = BasicBlock::Create(context(), "entry", value_func);
- def_node_VALUE_INT(context(), block, value_args[0], value_args[1]);
- return true;
- }
- case OP_VALUE_FLOAT3: {
- BasicBlock *block = BasicBlock::Create(context(), "entry", value_func);
- def_node_VALUE_FLOAT3(context(), block, value_args[0], value_args[1]);
- return true;
- }
- case OP_VALUE_FLOAT4: {
- BasicBlock *block = BasicBlock::Create(context(), "entry", value_func);
- def_node_VALUE_FLOAT4(context(), block, value_args[0], value_args[1]);
- return true;
- }
- case OP_VALUE_MATRIX44: {
- BasicBlock *block = BasicBlock::Create(context(), "entry", value_func);
- def_node_VALUE_MATRIX44(context(), block, value_args[0], value_args[1]);
- return true;
- }
-
- default:
- return false;
- }
-}
-
-template <OpCode op>
-static void define_elementary_functions(LLVMTextureCompilerImpl &C, llvm::Module *mod, const string &nodetype_name)
-{
- using namespace llvm;
-
- const NodeType *nodetype = NodeGraph::find_node_type(nodetype_name);
- if (nodetype == NULL)
- return;
-
- stri
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list