[Bf-blender-cvs] [d98433c] object_nodes: Leave the decision about passing arguments by pointer to the compiler class too.

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


Commit: d98433c4671ecc43dadcbf9e56577d93ceac8947
Author: Lukas Tönne
Date:   Thu May 19 18:22:53 2016 +0200
Branches: object_nodes
https://developer.blender.org/rBd98433c4671ecc43dadcbf9e56577d93ceac8947

Leave the decision about passing arguments by pointer to the compiler class too.

This removes the last "global" type function, so all the details of types are now
decided in the compiler implementation subclass.

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

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

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

diff --git a/source/blender/blenvm/llvm/llvm_codegen.cc b/source/blender/blenvm/llvm/llvm_codegen.cc
index 772c9e7..0fc0940 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.cc
+++ b/source/blender/blenvm/llvm/llvm_codegen.cc
@@ -234,7 +234,7 @@ llvm::Function *LLVMCompilerBase::codegen_node_function(const string &name, cons
 		const string &tname = input.typedesc.name();
 		const TypeSpec *typespec = input.typedesc.get_typespec();
 		Type *type = create_value_type(tname, typespec);
-		if (llvm_use_argument_pointer(typespec))
+		if (use_argument_pointer(typespec))
 			type = type->getPointerTo();
 		input_types.push_back(type);
 	}
@@ -376,7 +376,7 @@ void LLVMCompilerBase::expand_function_node(llvm::BasicBlock *block, const NodeI
 				Constant *cvalue = codegen_constant(input.value());
 				
 				Value *value;
-				if (llvm_use_argument_pointer(typespec)) {
+				if (use_argument_pointer(typespec)) {
 					AllocaInst *pvalue = builder.CreateAlloca(cvalue->getType());
 					builder.CreateStore(cvalue, pvalue);
 					value = pvalue;
@@ -391,7 +391,7 @@ void LLVMCompilerBase::expand_function_node(llvm::BasicBlock *block, const NodeI
 			case INPUT_EXPRESSION: {
 				Value *pvalue = m_output_values.at(input.link());
 				Value *value;
-				if (llvm_use_argument_pointer(typespec)) {
+				if (use_argument_pointer(typespec)) {
 					value = pvalue;
 				}
 				else {
@@ -550,7 +550,7 @@ void LLVMCompilerBase::define_node_function(llvm::Module *mod, OpCode op, const
 		Type *type = create_value_type(tname, typespec);
 		if (type == NULL)
 			break;
-		if (llvm_use_argument_pointer(typespec))
+		if (use_argument_pointer(typespec))
 			type = type->getPointerTo();
 		input_types.push_back(type);
 	}
@@ -641,6 +641,38 @@ llvm::Type *LLVMSimpleCompilerImpl::create_value_type(const string &name, const
 	return NULL;
 }
 
+bool LLVMSimpleCompilerImpl::use_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::Module *LLVMTextureCompilerImpl::m_nodes_module = NULL;
@@ -676,6 +708,38 @@ llvm::Type *LLVMTextureCompilerImpl::create_value_type(const string &name, const
 	return NULL;
 }
 
+bool LLVMTextureCompilerImpl::use_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;
+}
+
 /* ------------------------------------------------------------------------- */
 
 FunctionLLVM *LLVMCompiler::compile_function(const string &name, const NodeGraph &graph, int opt_level)
diff --git a/source/blender/blenvm/llvm/llvm_codegen.h b/source/blender/blenvm/llvm/llvm_codegen.h
index 0cd911c..899b714 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.h
+++ b/source/blender/blenvm/llvm/llvm_codegen.h
@@ -99,6 +99,7 @@ protected:
 	virtual void create_type_map(TypeMap &typemap);
 	virtual llvm::FunctionType *create_node_function_type(const std::vector<llvm::Type*> &inputs,
 	                                                      const std::vector<llvm::Type*> &outputs);
+	virtual bool use_argument_pointer(const TypeSpec *typespec) = 0;
 	
 	void define_node_function(llvm::Module *mod, OpCode op, const NodeType *nodetype, void *funcptr);
 	llvm::Module *define_nodes_module();
@@ -117,6 +118,8 @@ struct LLVMSimpleCompilerImpl : public LLVMCompilerBase {
 	llvm::Module *get_nodes_module() const { return m_nodes_module; }
 	void set_nodes_module(llvm::Module *mod) { m_nodes_module = mod; }
 	
+	bool use_argument_pointer(const TypeSpec *typespec);
+	
 private:
 	static llvm::Module *m_nodes_module;
 };
@@ -127,6 +130,8 @@ struct LLVMTextureCompilerImpl : public LLVMCompilerBase {
 	llvm::Module *get_nodes_module() const { return m_nodes_module; }
 	void set_nodes_module(llvm::Module *mod) { m_nodes_module = mod; }
 	
+	bool use_argument_pointer(const TypeSpec *typespec);
+	
 private:
 	static llvm::Module *m_nodes_module;
 };
diff --git a/source/blender/blenvm/llvm/llvm_types.cc b/source/blender/blenvm/llvm/llvm_types.cc
index 4df2a70..fc0435d 100644
--- a/source/blender/blenvm/llvm/llvm_types.cc
+++ b/source/blender/blenvm/llvm/llvm_types.cc
@@ -35,36 +35,4 @@
 
 namespace blenvm {
 
-bool llvm_use_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;
-}
-
 } /* namespace blenvm */
diff --git a/source/blender/blenvm/llvm/llvm_types.h b/source/blender/blenvm/llvm/llvm_types.h
index 3a93d94..689295a 100644
--- a/source/blender/blenvm/llvm/llvm_types.h
+++ b/source/blender/blenvm/llvm/llvm_types.h
@@ -104,13 +104,4 @@ public:
 
 } /* namespace llvm */
 
-
-namespace blenvm {
-
-struct TypeSpec;
-
-bool llvm_use_argument_pointer(const TypeSpec *typespec);
-
-} /* namespace blenvm */
-
 #endif /* __LLVM_TYPES_H__ */




More information about the Bf-blender-cvs mailing list