[Bf-blender-cvs] [030a327] object_nodes: Preparatory changes for differing node compiler implementations.

Lukas Tönne noreply at git.blender.org
Thu May 19 19:29:28 CEST 2016


Commit: 030a327f405dd1c06204ed83d795a330f0c82bb8
Author: Lukas Tönne
Date:   Wed May 18 17:40:55 2016 +0200
Branches: object_nodes
https://developer.blender.org/rB030a327f405dd1c06204ed83d795a330f0c82bb8

Preparatory changes for differing node compiler implementations.

Uses some virtual functions of the node compiler to allow different
implementation of values. This will be used for calculating values
and partial derivatives in texture nodes.

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

M	source/blender/blenvm/CMakeLists.txt
M	source/blender/blenvm/compile/node_graph.cc
M	source/blender/blenvm/llvm/llvm_codegen.cc
M	source/blender/blenvm/llvm/llvm_codegen.h

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

diff --git a/source/blender/blenvm/CMakeLists.txt b/source/blender/blenvm/CMakeLists.txt
index b5208e4..e2d4e77 100644
--- a/source/blender/blenvm/CMakeLists.txt
+++ b/source/blender/blenvm/CMakeLists.txt
@@ -96,6 +96,8 @@ add_subdirectory(compile)
 if(WITH_LLVM)
 	add_subdirectory(llvm)
 	add_definitions(-DWITH_LLVM)
+
+	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${RTTI_DISABLE_FLAGS}")
 endif()
 
 blender_add_lib(bf_blenvm "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/blenvm/compile/node_graph.cc b/source/blender/blenvm/compile/node_graph.cc
index 26d94d5..6a6bdb5 100644
--- a/source/blender/blenvm/compile/node_graph.cc
+++ b/source/blender/blenvm/compile/node_graph.cc
@@ -1221,22 +1221,32 @@ static void register_typedefs()
 {
 	
 	TypeSpec *float_t = TypeSpec::add_typedef("FLOAT", BVM_FLOAT);
+	TypeSpec *float_dual_t = TypeSpec::add_typedef("FLOAT_DUAL", BVM_FLOAT);
+	UNUSED_VARS(float_t, float_dual_t);
 	
 	TypeSpec *float3_t = TypeSpec::add_typedef("FLOAT3", BVM_FLOAT3);
+	UNUSED_VARS(float3_t);
 	
 	TypeSpec *float4_t = TypeSpec::add_typedef("FLOAT4", BVM_FLOAT4);
+	UNUSED_VARS(float4_t);
 	
 	TypeSpec *int_t = TypeSpec::add_typedef("INT", BVM_INT);
+	UNUSED_VARS(int_t);
 	
 	TypeSpec *matrix44_t = TypeSpec::add_typedef("MATRIX44", BVM_MATRIX44);
+	UNUSED_VARS(matrix44_t);
 	
 	TypeSpec *string_t = TypeSpec::add_typedef("STRING", BVM_STRING);
+	UNUSED_VARS(string_t);
 	
 	TypeSpec *rnapointer_t = TypeSpec::add_typedef("RNAPOINTER", BVM_RNAPOINTER);
+	UNUSED_VARS(rnapointer_t);
 	
 	TypeSpec *mesh_t = TypeSpec::add_typedef("MESH", BVM_MESH);
+	UNUSED_VARS(mesh_t);
 	
 	TypeSpec *duplis_t = TypeSpec::add_typedef("DUPLIS", BVM_DUPLIS);
+	UNUSED_VARS(duplis_t);
 	
 	
 	TypeSpec::add_typedef("FLOAT_ARRAY", BVM_FLOAT, BVM_BUFFER_ARRAY);
@@ -1256,8 +1266,6 @@ static void register_typedefs()
 	TypeSpec::add_typedef("MESH_ARRAY", BVM_MESH, BVM_BUFFER_ARRAY);
 	
 	TypeSpec::add_typedef("DUPLIS_ARRAY", BVM_DUPLIS, BVM_BUFFER_ARRAY);
-	
-	UNUSED_VARS(float_t, float3_t, float4_t, matrix44_t, int_t, string_t, rnapointer_t, mesh_t, duplis_t);
 }
 
 OpCode get_opcode_from_node_type(const string &node)
diff --git a/source/blender/blenvm/llvm/llvm_codegen.cc b/source/blender/blenvm/llvm/llvm_codegen.cc
index d377d74..508020c 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.cc
+++ b/source/blender/blenvm/llvm/llvm_codegen.cc
@@ -145,134 +145,19 @@ llvm::Constant *LLVMCompilerBase::codegen_constant(const NodeValue *node_value)
 	return NULL;
 }
 
-void LLVMCompilerBase::codegen_node_function_call(llvm::BasicBlock *block,
-                                                  const NodeInstance *node,
-                                                  OutputValueMap &output_values)
-{
-	using namespace llvm;
-	
-	IRBuilder<> builder(context());
-	builder.SetInsertPoint(block);
-	
-	/* get evaluation function */
-	const std::string &evalname = node->type->name();
-	Function *evalfunc = llvm_find_external_function(module(), evalname);
-	BLI_assert(evalfunc != NULL && "Could not find node function!");
-	
-	/* function call arguments (including possible return struct if MRV is used) */
-	std::vector<Value *> args;
-	
-	for (int i = 0; i < node->num_outputs(); ++i) {
-		ConstOutputKey output = node->output(i);
-		const string &tname = output.socket->typedesc.name();
-		const TypeSpec *typespec = output.socket->typedesc.get_typespec();
-		Type *type = llvm_create_value_type(context(), tname, typespec);
-		BLI_assert(type != NULL);
-		Value *value = builder.CreateAlloca(type);
-		
-		args.push_back(value);
-		
-		/* use as node output values */
-		bool ok = output_values.insert(OutputValuePair(output, value)).second;
-		BLI_assert(ok && "Value for node output already defined!");
-		UNUSED_VARS(ok);
-	}
-	
-	/* set input arguments */
-	for (int i = 0; i < node->num_inputs(); ++i) {
-		ConstInputKey input = node->input(i);
-		const TypeSpec *typespec = input.socket->typedesc.get_typespec();
-		
-		switch (input.value_type()) {
-			case INPUT_CONSTANT: {
-				/* create storage for the global value */
-				Constant *cvalue = codegen_constant(input.value());
-				
-				Value *value;
-				if (llvm_use_argument_pointer(typespec)) {
-					AllocaInst *pvalue = builder.CreateAlloca(cvalue->getType());
-					builder.CreateStore(cvalue, pvalue);
-					value = pvalue;
-				}
-				else {
-					value = cvalue;
-				}
-				
-				args.push_back(value);
-				break;
-			}
-			case INPUT_EXPRESSION: {
-				Value *pvalue = output_values.at(input.link());
-				Value *value;
-				if (llvm_use_argument_pointer(typespec)) {
-					value = pvalue;
-				}
-				else {
-					value = builder.CreateLoad(pvalue);
-				}
-				
-				args.push_back(value);
-				break;
-			}
-			case INPUT_VARIABLE: {
-				/* TODO */
-				BLI_assert(false && "Variable inputs not supported yet!");
-				break;
-			}
-		}
-	}
-	
-	CallInst *call = builder.CreateCall(evalfunc, args);
-	UNUSED_VARS(call);
-}
-
-void LLVMCompilerBase::codegen_node_pass(llvm::BasicBlock *block,
-                                         const NodeInstance *node,
-                                         OutputValueMap &output_values)
-{
-	using namespace llvm;
-	
-	IRBuilder<> builder(context());
-	builder.SetInsertPoint(block);
-	
-	BLI_assert(node->num_inputs() == 1);
-	BLI_assert(node->num_outputs() == 1);
-	
-	ConstInputKey input = node->input(0);
-	ConstOutputKey output = node->output(0);
-	BLI_assert(input.value_type() == INPUT_EXPRESSION);
-	
-	Value *value = output_values.at(input.link());
-	bool ok = output_values.insert(OutputValuePair(output, value)).second;
-	BLI_assert(ok && "Value for node output already defined!");
-	UNUSED_VARS(ok);
-}
-
-void LLVMCompilerBase::codegen_node_arg(llvm::BasicBlock *block,
-                                        const NodeInstance *node,
-                                        OutputValueMap &output_values)
-{
-	using namespace llvm;
-	/* input arguments are mapped in advance */
-	BLI_assert(output_values.find(node->output(0)) != output_values.end() &&
-	           "Input argument value node mapped!");
-	UNUSED_VARS(block, node, output_values);
-}
-
 void LLVMCompilerBase::codegen_node(llvm::BasicBlock *block,
-                                    const NodeInstance *node,
-                                    OutputValueMap &output_values)
+                                    const NodeInstance *node)
 {
 	switch (node->type->kind()) {
 		case NODE_TYPE_FUNCTION:
 		case NODE_TYPE_KERNEL:
-			codegen_node_function_call(block, node, output_values);
+			expand_function_node(block, node);
 			break;
 		case NODE_TYPE_PASS:
-			codegen_node_pass(block, node, output_values);
+			expand_pass_node(block, node);
 			break;
 		case NODE_TYPE_ARG:
-			codegen_node_arg(block, node, output_values);
+			expand_argument_node(block, node);
 			break;
 	}
 }
@@ -294,8 +179,6 @@ llvm::BasicBlock *LLVMCompilerBase::codegen_function_body_expression(const NodeG
 	int num_inputs = graph.inputs.size();
 	int num_outputs = graph.outputs.size();
 	
-	OutputValueMap output_values;
-	
 	Argument *retarg = func->getArgumentList().begin();
 	{
 		Function::ArgumentListType::iterator it = retarg;
@@ -304,9 +187,9 @@ llvm::BasicBlock *LLVMCompilerBase::codegen_function_body_expression(const NodeG
 		}
 		for (int i = 0; i < num_inputs; ++i) {
 			const NodeGraph::Input &input = graph.inputs[i];
-			
 			Argument *arg = &(*it++);
-			output_values[input.key] = arg;
+			
+			map_argument(block, input.key, arg);
 		}
 	}
 	
@@ -317,17 +200,16 @@ llvm::BasicBlock *LLVMCompilerBase::codegen_function_body_expression(const NodeG
 	for (OrderedNodeSet::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
 		const NodeInstance &node = **it;
 		
-		codegen_node(block, &node, output_values);
+		codegen_node(block, &node);
 	}
 	
 	{
 		Function::ArgumentListType::iterator it = func->getArgumentList().begin();
 		for (int i = 0; i < num_outputs; ++i) {
 			const NodeGraph::Output &output = graph.outputs[i];
-			Value *value = output_values.at(output.key);
 			Argument *arg = &(*it++);
-			Value *rvalue = builder.CreateLoad(value);
-			builder.CreateStore(rvalue, arg);
+			
+			store_return_value(block, output.key, arg);
 		}
 	}
 	
@@ -419,10 +301,286 @@ void LLVMCompilerBase::optimize_function(llvm::Function *func, int opt_level)
 
 /* ------------------------------------------------------------------------- */
 
+void LLVMSimpleCompilerImpl::codegen_begin()
+{
+}
+
+void LLVMSimpleCompilerImpl::codegen_end()
+{
+	m_output_values.clear();
+}
+
+void LLVMSimpleCompilerImpl::map_argument(llvm::BasicBlock *block, const OutputKey &output, llvm::Argument *arg)
+{
+	m_output_values[output] = arg;
+	UNUSED_VARS(block);
+}
+
+void LLVMSimpleCompilerImpl::store_return_value(llvm::BasicBlock *block, const OutputKey &output, llvm::Value *arg)
+{
+	using namespace llvm;
+	
+	IRBuilder<> builder(context());
+	builder.SetInsertPoint(block);
+	
+	Value *value = m_output_values.at(output);
+	Value *rvalue = builder.CreateLoad(value);
+	builder.CreateStore(rvalue, arg);
+}
+
+void LLVMSimpleCompilerImpl::expand_pass_node(llvm::BasicBlock *block, const NodeInstance *node)
+{
+	using namespace llvm;
+	
+	IRBuilder<> builder(context());
+	builder.SetInsertPoint(block);
+	
+	BLI_assert(node->num_inputs() == 1);
+	BLI_assert(node->num_outputs() == 1);
+	
+	ConstInputKey input = node->input(0);
+	ConstOutputKey output = node->output(0);
+	BLI_assert(input.value_type() == INPUT_EXPRESSION);
+	
+	Value *value = m_output_values.at(input.link());
+	bool ok = m_output_values.insert(OutputValueMap::value_type(output, value)).second;
+	BLI_assert(ok && "Value for node output already defined!");
+	UNUSED_VARS(ok);
+}
+
+void LLVMSimpleCompilerImpl::expand_argument_node(llvm::BasicBlock *block, const NodeInstance *node)
+{
+	using namespace llvm;
+	/* input arguments are mapped in advance */
+	BLI_assert(m_output_values.find(node->output(0)) != m_output_values.end() &&
+	           "Input argument value node mapped!");
+	UNUSED_VARS(block, node);
+}
+
+void LLVMSimpleCompilerImpl::expand_function_node(llvm::BasicBlock *block, const NodeInstance *node)
+{
+	using namespace llvm;
+	
+	IRBuilder<> builder(context());
+	builder.SetInsertPoint(block);
+	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list