[Bf-blender-cvs] [b220c9e] object_nodes: Moved type definition functions for LLVM types into own file.

Lukas Tönne noreply at git.blender.org
Tue May 10 11:25:09 CEST 2016


Commit: b220c9e5c638b74c0fc6b39cf3cc3c133c1b1c4c
Author: Lukas Tönne
Date:   Mon May 9 09:11:46 2016 +0200
Branches: object_nodes
https://developer.blender.org/rBb220c9e5c638b74c0fc6b39cf3cc3c133c1b1c4c

Moved type definition functions for LLVM types into own file.

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

M	source/blender/blenvm/intern/bvm_api.cc
M	source/blender/blenvm/llvm/CMakeLists.txt
M	source/blender/blenvm/llvm/llvm_codegen.cc
M	source/blender/blenvm/llvm/llvm_codegen.h
A	source/blender/blenvm/llvm/llvm_types.cc
A	source/blender/blenvm/llvm/llvm_types.h

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

diff --git a/source/blender/blenvm/intern/bvm_api.cc b/source/blender/blenvm/intern/bvm_api.cc
index 6177dea..ac3e288 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -86,11 +86,11 @@ void BVM_init(void)
 	
 	create_empty_mesh(__empty_mesh__);
 	
+	nodes_init();
+	
 #ifdef WITH_LLVM
 	llvm_init();
 #endif
-	
-	nodes_init();
 }
 
 void BVM_free(void)
@@ -100,14 +100,11 @@ void BVM_free(void)
 	blenvm::function_bvm_cache_clear();
 #ifdef WITH_LLVM
 	blenvm::function_llvm_cache_clear();
+	llvm_free();
 #endif
 	
 	nodes_free();
 	
-#ifdef WITH_LLVM
-	llvm_free();
-#endif
-	
 	destroy_empty_mesh(__empty_mesh__);
 }
 
diff --git a/source/blender/blenvm/llvm/CMakeLists.txt b/source/blender/blenvm/llvm/CMakeLists.txt
index 5d16683..299296e 100644
--- a/source/blender/blenvm/llvm/CMakeLists.txt
+++ b/source/blender/blenvm/llvm/CMakeLists.txt
@@ -51,6 +51,8 @@ set(SRC
 	llvm_headers.h
 	llvm_modules.cc
 	llvm_modules.h
+	llvm_types.cc
+	llvm_types.h
 )
 
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${RTTI_DISABLE_FLAGS}")
diff --git a/source/blender/blenvm/llvm/llvm_codegen.cc b/source/blender/blenvm/llvm/llvm_codegen.cc
index 8e568c6..ac75926 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.cc
+++ b/source/blender/blenvm/llvm/llvm_codegen.cc
@@ -40,6 +40,7 @@
 #include "llvm_function.h"
 #include "llvm_headers.h"
 #include "llvm_modules.h"
+#include "llvm_types.h"
 
 /* call signature convention in llvm modules:
  * BYVALUE:   Pass struct types directly into (inlined) functions,
@@ -55,64 +56,6 @@
 //#define BVM_NODE_CALL_BYVALUE
 #define BVM_NODE_CALL_BYPOINTER
 
-/* TypeBuilder specializations for own structs */
-
-namespace llvm {
-
-template <bool xcompile>
-class TypeBuilder<blenvm::float3, xcompile> {
-public:
-	static StructType *get(LLVMContext &context) {
-		return StructType::get(
-		            TypeBuilder<types::ieee_float, xcompile>::get(context),
-		            TypeBuilder<types::ieee_float, xcompile>::get(context),
-		            TypeBuilder<types::ieee_float, xcompile>::get(context),
-		            NULL);
-	}
-	
-	enum Fields {
-		FIELD_X = 0,
-		FIELD_Y = 1,
-		FIELD_Z = 2,
-	};
-};
-
-template <bool xcompile>
-class TypeBuilder<blenvm::float4, xcompile> {
-public:
-	static StructType *get(LLVMContext &context) {
-		return StructType::get(
-		            TypeBuilder<types::ieee_float, xcompile>::get(context),
-		            TypeBuilder<types::ieee_float, xcompile>::get(context),
-		            TypeBuilder<types::ieee_float, xcompile>::get(context),
-		            TypeBuilder<types::ieee_float, xcompile>::get(context),
-		            NULL);
-	}
-	
-	enum Fields {
-		FIELD_X = 0,
-		FIELD_Y = 1,
-		FIELD_Z = 2,
-		FIELD_W = 3,
-	};
-};
-
-template <bool xcompile>
-class TypeBuilder<blenvm::matrix44, xcompile> {
-public:
-	static StructType *get(LLVMContext &context) {
-		return StructType::get(
-		            ArrayType::get(
-		                ArrayType::get(
-		                    TypeBuilder<types::ieee_float, xcompile>::get(context),
-		                    4),
-		                4),
-		            NULL);
-	}
-};
-
-} /* namespace llvm */
-
 
 namespace blenvm {
 
@@ -160,50 +103,6 @@ void LLVMCompilerBase::destroy_module()
 	m_module = NULL;
 }
 
-llvm::StructType *LLVMCompilerBase::codegen_struct_type(const string &name, const StructSpec *s)
-{
-	using namespace llvm;
-	
-	std::vector<Type*> elemtypes;
-	for (int i = 0; i < s->num_fields(); ++s) {
-		Type *ftype = codegen_type(s->field(i).name, &s->field(i).typedesc);
-		elemtypes.push_back(ftype);
-	}
-	
-	return StructType::create(context(), ArrayRef<Type*>(elemtypes), name);
-}
-
-llvm::Type *LLVMCompilerBase::codegen_type(const string &name, const TypeDesc *td)
-{
-	using namespace llvm;
-	
-	if (td->is_structure()) {
-		return codegen_struct_type(name, td->structure());
-	}
-	else {
-		switch (td->base_type()) {
-			case BVM_FLOAT:
-				return TypeBuilder<types::ieee_float, true>::get(context());
-			case BVM_FLOAT3:
-				return TypeBuilder<float3, true>::get(context());
-			case BVM_FLOAT4:
-				return TypeBuilder<float4, true>::get(context());
-			case BVM_INT:
-				return TypeBuilder<types::i<32>, true>::get(context());
-			case BVM_MATRIX44:
-				return TypeBuilder<matrix44, true>::get(context());
-				
-			case BVM_STRING:
-			case BVM_RNAPOINTER:
-			case BVM_MESH:
-			case BVM_DUPLIS:
-				/* TODO */
-				return NULL;
-		}
-	}
-	return NULL;
-}
-
 llvm::Constant *LLVMCompilerBase::codegen_constant(const NodeValue *node_value)
 {
 	using namespace llvm;
@@ -288,7 +187,7 @@ llvm::FunctionType *LLVMCompilerBase::codegen_node_function_type(const NodeGraph
 	
 	for (int i = 0; i < graph.outputs.size(); ++i) {
 		const NodeGraph::Output &output = graph.outputs[i];
-		Type *type = codegen_type(dummy_type_name(output.key), &output.typedesc);
+		Type *type = codegen_type(context(), dummy_type_name(output.key), &output.typedesc);
 		output_types.push_back(type);
 	}
 	StructType *return_type = StructType::get(context(), output_types);
@@ -296,7 +195,7 @@ llvm::FunctionType *LLVMCompilerBase::codegen_node_function_type(const NodeGraph
 	input_types.push_back(PointerType::get(return_type, 0));
 	for (int i = 0; i < graph.inputs.size(); ++i) {
 		const NodeGraph::Input &input = graph.inputs[i];
-		Type *type = codegen_type(dummy_type_name(input.key), &input.typedesc);
+		Type *type = codegen_type(context(), dummy_type_name(input.key), &input.typedesc);
 //		type = PointerType::get(type, 0);
 		input_types.push_back(type);
 	}
@@ -336,7 +235,7 @@ llvm::CallInst *LLVMCompilerBase::codegen_node_call(llvm::BasicBlock *block,
 #ifdef BVM_NODE_CALL_BYPOINTER
 	for (int i = 0; i < node->num_outputs(); ++i) {
 		ConstOutputKey output = node->output(i);
-		Type *output_type = codegen_type(dummy_type_name(output), &output.socket->typedesc);
+		Type *output_type = codegen_type(context(), dummy_type_name(output), &output.socket->typedesc);
 		AllocaInst *outputmem = builder.CreateAlloca(output_type);
 		
 		Type *arg_type = evalfunc->getFunctionType()->getParamType(args.size());
diff --git a/source/blender/blenvm/llvm/llvm_codegen.h b/source/blender/blenvm/llvm/llvm_codegen.h
index 693c9c2..8a2eb67 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.h
+++ b/source/blender/blenvm/llvm/llvm_codegen.h
@@ -78,8 +78,6 @@ protected:
 	
 	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);
 	
 	llvm::CallInst *codegen_node_call(llvm::BasicBlock *block, const NodeInstance *node, OutputValueMap &output_values);
diff --git a/source/blender/blenvm/llvm/llvm_types.cc b/source/blender/blenvm/llvm/llvm_types.cc
new file mode 100644
index 0000000..ca0f9fa
--- /dev/null
+++ b/source/blender/blenvm/llvm/llvm_types.cc
@@ -0,0 +1,110 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenvm/llvm/llvm_types.cc
+ *  \ingroup llvm
+ */
+
+#include "llvm_headers.h"
+#include "llvm_types.h"
+
+
+namespace blenvm {
+
+llvm::StructType *codegen_struct_type(llvm::LLVMContext &context, const string &name, const StructSpec *s)
+{
+	using namespace llvm;
+	
+	std::vector<Type*> elemtypes;
+	for (int i = 0; i < s->num_fields(); ++s) {
+		Type *ftype = codegen_type(context, s->field(i).name, &s->field(i).typedesc);
+		elemtypes.push_back(ftype);
+	}
+	
+	return StructType::create(context, ArrayRef<Type*>(elemtypes), name);
+}
+
+llvm::Type *codegen_type(llvm::LLVMContext &context, const string &name, const TypeDesc *td)
+{
+	using namespace llvm;
+	
+	if (td->is_structure()) {
+		return codegen_struct_type(context, name, td->structure());
+	}
+	else {
+		switch (td->base_type()) {
+			case BVM_FLOAT:
+				return TypeBuilder<types::ieee_float, true>::get(context);
+			case BVM_FLOAT3:
+				return TypeBuilder<float3, true>::get(context);
+			case BVM_FLOAT4:
+				return TypeBuilder<float4, true>::get(context);
+			case BVM_INT:
+				return TypeBuilder<types::i<32>, true>::get(context);
+			case BVM_MATRIX44:
+				return TypeBuilder<matrix44, true>::get(context);
+				
+			case BVM_STRING:
+			case BVM_RNAPOINTER:
+			case BVM_MESH:
+			case BVM_DUPLIS:
+				/* TODO */
+				return NULL;
+		}
+	}
+	return NULL;
+}
+
+#if 0 // TODO
+llvm::FunctionType *codegen_node_function_type(llvm::LLVMContext &context,
+                                               const TypeDescList &inputs,
+                                               const TypeDescList &outputs)
+{
+	using namespace llvm;
+	
+	std::vector<Type *> input_types, output_types;
+	
+	for (int i = 0; i < outputs.size(); ++i) {
+		const TypeDesc *desc = outputs[i];
+		Type *type = codegen_type(context, dummy_type_name(output.key), &output.typedesc);
+		output_types.push_back(type);
+	}
+	StructType *return_type = StructType::get(context(), output_types);
+	
+	input_types.push_back(PointerType::get(return_type, 0));
+	for (int i = 0; i < graph.inputs.size(); ++i) {
+		const NodeGraph::Input &input = graph.inputs[i];
+		Type *type = codegen_type(dummy_type_name(input.key), &input.typedesc);
+//		type = PointerType::get(type, 0);
+		input_types.push_back

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list