[Bf-blender-cvs] [f6d994faac7] functions: stack allocate tuple

Jacques Lucke noreply at git.blender.org
Sun Mar 10 13:14:23 CET 2019


Commit: f6d994faac7fbf8247e566a6dd71d728f799969c
Author: Jacques Lucke
Date:   Sun Mar 10 10:00:51 2019 +0100
Branches: functions
https://developer.blender.org/rBf6d994faac7fbf8247e566a6dd71d728f799969c

stack allocate tuple

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

M	source/blender/functions/CMakeLists.txt
M	source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
A	source/blender/functions/backends/tuple_call/tuple.cpp
M	source/blender/functions/backends/tuple_call/tuple.hpp
M	source/blender/functions/frontends/data_flow_nodes/function_generation.cpp

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

diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 1d0e6bf5c14..ed83e02ea34 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -43,6 +43,7 @@ set(SRC
 	backends/tuple_call/fgraph_tuple_call.hpp
 	backends/tuple_call/fgraph_tuple_call.cpp
 	backends/tuple_call/tuple.hpp
+	backends/tuple_call/tuple.cpp
 
 	backends/dependencies/dependencies.hpp
 	backends/dependencies/dependencies.cpp
diff --git a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
index 3768f3613e8..6d61cd6cef0 100644
--- a/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
+++ b/source/blender/functions/backends/tuple_call/fgraph_tuple_call.cpp
@@ -1,4 +1,5 @@
 #include "fgraph_tuple_call.hpp"
+#include "FN_llvm.hpp"
 
 namespace FN {
 
@@ -34,13 +35,18 @@ namespace FN {
 				Node *node = socket.node();
 				const Signature &signature = node->signature();
 
-				Tuple tmp_in(signature.input_types());
-				Tuple tmp_out(signature.output_types());
+				auto meta_in = SharedTupleMeta::New(signature.input_types());
+				auto meta_out = SharedTupleMeta::New(signature.output_types());
+
+				FN_TUPLE_STACK_ALLOC(tmp_in, meta_in);
+				FN_TUPLE_STACK_ALLOC(tmp_out, meta_out);
 
 				for (uint i = 0; i < signature.inputs().size(); i++) {
 					this->compute_socket(fn_in, tmp_in, i, node->input(i));
 				}
-
+				if (!node->function()->has_body<TupleCallBody>()) {
+					derive_TupleCallBody_from_LLVMBuildIRBody(node->function(), *(new llvm::LLVMContext()));
+				}
 				TupleCallBody *body = node->function()->body<TupleCallBody>();
 				body->call(tmp_in, tmp_out);
 
diff --git a/source/blender/functions/backends/tuple_call/tuple.cpp b/source/blender/functions/backends/tuple_call/tuple.cpp
new file mode 100644
index 00000000000..ad8f944e99b
--- /dev/null
+++ b/source/blender/functions/backends/tuple_call/tuple.cpp
@@ -0,0 +1,13 @@
+#include "tuple.hpp"
+
+namespace FN {
+
+	void Tuple::print_initialized(std::string name)
+	{
+		std::cout << "Tuple: " << name << std::endl;
+		for (uint i = 0; i < m_meta->element_amount(); i++) {
+			std::cout << "  Initialized " << i << ": " << m_initialized[i] << std::endl;
+		}
+	}
+
+} /* namespace FN */
\ No newline at end of file
diff --git a/source/blender/functions/backends/tuple_call/tuple.hpp b/source/blender/functions/backends/tuple_call/tuple.hpp
index 89a01270d10..59ee1ad75ff 100644
--- a/source/blender/functions/backends/tuple_call/tuple.hpp
+++ b/source/blender/functions/backends/tuple_call/tuple.hpp
@@ -68,7 +68,12 @@ namespace FN {
 			m_owns_mem = true;
 		}
 
-		Tuple(SharedTupleMeta meta, void *data, bool *initialized, bool take_ownership)
+		Tuple(
+			SharedTupleMeta meta,
+			void *data,
+			bool *initialized,
+			bool take_ownership,
+			bool was_initialized = false)
 			: m_meta(std::move(meta))
 		{
 			BLI_assert(data != nullptr);
@@ -76,6 +81,9 @@ namespace FN {
 			m_data = data;
 			m_initialized = initialized;
 			m_owns_mem = take_ownership;
+			if (!was_initialized) {
+				this->set_all_uninitialized();
+			}
 		}
 
 		Tuple(SmallTypeVector types)
@@ -269,6 +277,8 @@ namespace FN {
 			}
 		}
 
+		void print_initialized(std::string name = "");
+
 	private:
 		inline void *element_ptr(uint index) const
 		{
@@ -287,4 +297,10 @@ namespace FN {
 		SharedTupleMeta m_meta;
 	};
 
-} /* namespace FN */
\ No newline at end of file
+} /* namespace FN */
+
+#define FN_TUPLE_STACK_ALLOC(name, meta_expr) \
+	SharedTupleMeta &name##_meta = (meta_expr); \
+	void *name##_data = alloca(name##_meta->total_data_size()); \
+	bool *name##_initialized = (bool *)alloca(name##_meta->element_amount()); \
+	Tuple name(name##_meta, name##_data, name##_initialized, false);
diff --git a/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp b/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
index 4534bf2719e..b2493657b3f 100644
--- a/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/function_generation.cpp
@@ -19,9 +19,9 @@ namespace FN { namespace DataFlowNodes {
 
 		auto fn = SharedFunction::New(btree->id.name, fgraph.signature());
 		fgraph_add_DependenciesBody(fn, fgraph);
-		// fgraph_add_TupleCallBody(fn, fgraph);
-		fgraph_add_LLVMBuildIRBody(fn, fgraph);
-		derive_TupleCallBody_from_LLVMBuildIRBody(fn, *(new llvm::LLVMContext()));
+		fgraph_add_TupleCallBody(fn, fgraph);
+		//fgraph_add_LLVMBuildIRBody(fn, fgraph);
+		//derive_TupleCallBody_from_LLVMBuildIRBody(fn, *(new llvm::LLVMContext()));
 		return fn;
 	}



More information about the Bf-blender-cvs mailing list