[Bf-blender-cvs] [939810a] object_nodes: Handle all node type kinds appropriately.

Lukas Tönne noreply at git.blender.org
Sat May 14 09:55:45 CEST 2016


Commit: 939810add53646bd5d6ff2bb5d1f4cc67511ec79
Author: Lukas Tönne
Date:   Sat May 14 09:53:33 2016 +0200
Branches: object_nodes
https://developer.blender.org/rB939810add53646bd5d6ff2bb5d1f4cc67511ec79

Handle all node type kinds appropriately.

The LLVM backend also supports PASS nodes, even though these are usually
removed from the node graph in a preprocessing step for clarity.

ARG nodes have their output values mapped in advance, so no extra code
needs to be generated for them.

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

M	source/blender/blenvm/llvm/llvm_codegen.cc
M	source/blender/blenvm/llvm/llvm_codegen.h

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

diff --git a/source/blender/blenvm/llvm/llvm_codegen.cc b/source/blender/blenvm/llvm/llvm_codegen.cc
index 6862de4..7a34cff 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.cc
+++ b/source/blender/blenvm/llvm/llvm_codegen.cc
@@ -164,9 +164,9 @@ llvm::Constant *LLVMCompilerBase::codegen_constant(const NodeValue *node_value)
 	return NULL;
 }
 
-llvm::CallInst *LLVMCompilerBase::codegen_node_call(llvm::BasicBlock *block,
-                                                    const NodeInstance *node,
-                                                    OutputValueMap &output_values)
+void LLVMCompilerBase::codegen_node_function_call(llvm::BasicBlock *block,
+                                                  const NodeInstance *node,
+                                                  OutputValueMap &output_values)
 {
 	using namespace llvm;
 	
@@ -238,8 +238,58 @@ llvm::CallInst *LLVMCompilerBase::codegen_node_call(llvm::BasicBlock *block,
 	}
 	
 	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);
 	
-	return call;
+	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)
+{
+	switch (node->type->kind()) {
+		case NODE_TYPE_FUNCTION:
+		case NODE_TYPE_KERNEL:
+			codegen_node_function_call(block, node, output_values);
+			break;
+		case NODE_TYPE_PASS:
+			codegen_node_pass(block, node, output_values);
+			break;
+		case NODE_TYPE_ARG:
+			codegen_node_arg(block, node, output_values);
+			break;
+	}
 }
 
 /* Compile nodes as a simple expression.
@@ -282,9 +332,7 @@ llvm::BasicBlock *LLVMCompilerBase::codegen_function_body_expression(const NodeG
 	for (OrderedNodeSet::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
 		const NodeInstance &node = **it;
 		
-		CallInst *call = codegen_node_call(block, &node, output_values);
-		if (!call)
-			continue;
+		codegen_node(block, &node, output_values);
 	}
 	
 	{
diff --git a/source/blender/blenvm/llvm/llvm_codegen.h b/source/blender/blenvm/llvm/llvm_codegen.h
index f9dc37b..8df686b 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.h
+++ b/source/blender/blenvm/llvm/llvm_codegen.h
@@ -80,7 +80,19 @@ protected:
 	
 	llvm::Constant *codegen_constant(const NodeValue *node_value);
 	
-	llvm::CallInst *codegen_node_call(llvm::BasicBlock *block, const NodeInstance *node, OutputValueMap &output_values);
+	void codegen_node_function_call(llvm::BasicBlock *block,
+	                                const NodeInstance *node,
+	                                OutputValueMap &output_values);
+	void codegen_node_pass(llvm::BasicBlock *block,
+	                       const NodeInstance *node,
+	                       OutputValueMap &output_values);
+	void codegen_node_arg(llvm::BasicBlock *block,
+	                      const NodeInstance *node,
+	                      OutputValueMap &output_values);
+	void codegen_node(llvm::BasicBlock *block,
+	                  const NodeInstance *node,
+	                  OutputValueMap &output_values);
+	
 	llvm::BasicBlock *codegen_function_body_expression(const NodeGraph &graph, llvm::Function *func);
 	llvm::Function *codegen_node_function(const string &name, const NodeGraph &graph);




More information about the Bf-blender-cvs mailing list