[Bf-blender-cvs] [5ad9010ebfb] functions: initial llvm integration (include path is still hardcoded...)

Jacques Lucke noreply at git.blender.org
Fri Mar 1 19:30:28 CET 2019


Commit: 5ad9010ebfbbf3e337fcf887c767040172a77448
Author: Jacques Lucke
Date:   Fri Mar 1 19:30:20 2019 +0100
Branches: functions
https://developer.blender.org/rB5ad9010ebfbbf3e337fcf887c767040172a77448

initial llvm integration (include path is still hardcoded...)

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

M	source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M	source/blender/functions/CMakeLists.txt
M	source/blender/functions/FN_all.hpp
A	source/blender/functions/FN_llvm.hpp
A	source/blender/functions/backends/llvm/llvm_types.cpp
A	source/blender/functions/backends/llvm/llvm_types.hpp
M	source/blender/functions/types/numeric.cpp
M	source/blender/functions/types/numeric.hpp

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

diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
index 46c32821315..20769f4752d 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
@@ -111,7 +111,7 @@ extern "C" {
 
 #include "intern/depsgraph_type.h"
 
-#include "FN_all.hpp"
+#include "FN_dependencies.hpp"
 
 namespace DEG {
 
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 58552c06882..184ced13bb8 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -7,7 +7,9 @@ set(INC
 	../depsgraph
 )
 
+# TODO: figure out how not to hard code this
 set(INC_SYS
+	/usr/lib/llvm-6.0/include
 )
 
 set(SRC
@@ -48,6 +50,9 @@ set(SRC
 	backends/dependencies/fgraph_dependencies.hpp
 	backends/dependencies/fgraph_dependencies.cpp
 
+	backends/llvm/llvm_types.hpp
+	backends/llvm/llvm_types.cpp
+
 	types/numeric.cpp
 	types/numeric.hpp
 
diff --git a/source/blender/functions/FN_all.hpp b/source/blender/functions/FN_all.hpp
index 8c92032891e..0c412deb3ff 100644
--- a/source/blender/functions/FN_all.hpp
+++ b/source/blender/functions/FN_all.hpp
@@ -5,4 +5,5 @@
 #include "FN_functions.hpp"
 #include "FN_tuple_call.hpp"
 #include "FN_dependencies.hpp"
-#include "FN_data_flow_nodes.hpp"
\ No newline at end of file
+#include "FN_data_flow_nodes.hpp"
+#include "FN_llvm.hpp"
\ No newline at end of file
diff --git a/source/blender/functions/FN_llvm.hpp b/source/blender/functions/FN_llvm.hpp
new file mode 100644
index 00000000000..c1cf8027cb7
--- /dev/null
+++ b/source/blender/functions/FN_llvm.hpp
@@ -0,0 +1,3 @@
+#pragma once
+
+#include "backends/llvm/llvm_types.hpp"
\ No newline at end of file
diff --git a/source/blender/functions/backends/llvm/llvm_types.cpp b/source/blender/functions/backends/llvm/llvm_types.cpp
new file mode 100644
index 00000000000..4be4374629f
--- /dev/null
+++ b/source/blender/functions/backends/llvm/llvm_types.cpp
@@ -0,0 +1,39 @@
+#include "llvm_types.hpp"
+
+namespace FN {
+
+	const char *LLVMTypeInfo::identifier_in_composition()
+	{
+		return "LLVM Type Info";
+	}
+
+	void LLVMTypeInfo::free_self(void *value)
+	{
+		LLVMTypeInfo *value_ = (LLVMTypeInfo *)value;
+		delete value_;
+	}
+
+	llvm::Type *LLVMTypeInfo::get_type(llvm::LLVMContext &context)
+	{
+		if (!m_type_per_context.contains(&context)) {
+			llvm::Type *type = this->create_type(context);
+			m_type_per_context.add(&context, type);
+		}
+		return m_type_per_context.lookup(&context);
+	}
+
+	llvm::Value *LLVMTypeInfo::build_copy_ir(
+		llvm::IRBuilder<> &UNUSED(builder),
+		llvm::Value *value)
+	{
+		return value;
+	}
+
+	void LLVMTypeInfo::build_free_ir(
+		llvm::IRBuilder<> &UNUSED(builder),
+		llvm::Value *UNUSED(value))
+	{
+		return;
+	}
+
+};
\ No newline at end of file
diff --git a/source/blender/functions/backends/llvm/llvm_types.hpp b/source/blender/functions/backends/llvm/llvm_types.hpp
new file mode 100644
index 00000000000..0ac15482e91
--- /dev/null
+++ b/source/blender/functions/backends/llvm/llvm_types.hpp
@@ -0,0 +1,51 @@
+#pragma once
+
+#include "FN_core.hpp"
+
+#include "llvm/IR/IRBuilder.h"
+
+#include <functional>
+
+namespace FN {
+
+	class LLVMTypeInfo {
+	public:
+		static const char *identifier_in_composition();
+		static void free_self(void *value);
+
+		virtual ~LLVMTypeInfo() {}
+
+		llvm::Type *get_type(
+			llvm::LLVMContext &context);
+
+		virtual llvm::Value *build_copy_ir(
+			llvm::IRBuilder<> &builder,
+			llvm::Value *value);
+
+		virtual void build_free_ir(
+			llvm::IRBuilder<> &builder,
+			llvm::Value *value);
+
+	private:
+		SmallMap<llvm::LLVMContext *, llvm::Type *> m_type_per_context;
+
+		virtual llvm::Type *create_type(
+			llvm::LLVMContext &context) = 0;
+	};
+
+	class SimpleLLVMTypeInfo : public LLVMTypeInfo {
+	private:
+		typedef std::function<llvm::Type *(llvm::LLVMContext &context)> CreateFunc;
+		CreateFunc m_create_func;
+
+		llvm::Type *create_type(llvm::LLVMContext &context)
+		{
+			return m_create_func(context);
+		}
+
+	public:
+		SimpleLLVMTypeInfo(CreateFunc create_func)
+			: m_create_func(create_func) {}
+	};
+
+} /* namespace FN */
\ No newline at end of file
diff --git a/source/blender/functions/types/numeric.cpp b/source/blender/functions/types/numeric.cpp
index 5c2ed3fe4f6..e116cc2e982 100644
--- a/source/blender/functions/types/numeric.cpp
+++ b/source/blender/functions/types/numeric.cpp
@@ -2,6 +2,7 @@
 #include "BLI_lazy_init.hpp"
 
 #include "FN_tuple_call.hpp"
+#include "FN_llvm.hpp"
 
 namespace FN { namespace Types {
 
@@ -9,6 +10,9 @@ namespace FN { namespace Types {
 	{
 		SharedType type = SharedType::New("Float");
 		type->extend(new CPPTypeInfoForType<float>());
+		type->extend(new SimpleLLVMTypeInfo([](llvm::LLVMContext &context) {
+			return llvm::Type::getFloatTy(context);
+		}));
 		return type;
 	}
 
@@ -16,6 +20,9 @@ namespace FN { namespace Types {
 	{
 		SharedType type = SharedType::New("Int32");
 		type->extend(new CPPTypeInfoForType<int32_t>());
+		type->extend(new SimpleLLVMTypeInfo([](llvm::LLVMContext &context) {
+			return llvm::Type::getIntNTy(context, 32);
+		}));
 		return type;
 	}
 
@@ -23,13 +30,10 @@ namespace FN { namespace Types {
 	{
 		SharedType type = SharedType::New("FloatVector3D");
 		type->extend(new CPPTypeInfoForType<Vector>());
-		return type;
-	}
-
-	LAZY_INIT_REF__NO_ARG(SharedType, get_float_list_type)
-	{
-		SharedType type = SharedType::New("Float List");
-		type->extend(new CPPTypeInfoForType<SmallVector<float>>());
+		type->extend(new SimpleLLVMTypeInfo([](llvm::LLVMContext &context) {
+			llvm::Type *base = llvm::Type::getFloatTy(context);
+			return llvm::StructType::get(context, {base, base, base}, true);
+		}));
 		return type;
 	}
 
diff --git a/source/blender/functions/types/numeric.hpp b/source/blender/functions/types/numeric.hpp
index 472cd5f05ba..bcf40752cb3 100644
--- a/source/blender/functions/types/numeric.hpp
+++ b/source/blender/functions/types/numeric.hpp
@@ -16,6 +16,5 @@ namespace FN { namespace Types {
 	SharedType &get_float_type();
 	SharedType &get_int32_type();
 	SharedType &get_fvec3_type();
-	SharedType &get_float_list_type();
 
 } } /* namespace FN::Types */
\ No newline at end of file



More information about the Bf-blender-cvs mailing list