[Bf-blender-cvs] [51aa004a393] functions: initial list types implementation
Jacques Lucke
noreply at git.blender.org
Wed Mar 6 14:00:08 CET 2019
Commit: 51aa004a393558b5cc2659d9d8e5595679b3a9d9
Author: Jacques Lucke
Date: Wed Mar 6 13:59:00 2019 +0100
Branches: functions
https://developer.blender.org/rB51aa004a393558b5cc2659d9d8e5595679b3a9d9
initial list types implementation
===================================================================
A source/blender/blenlib/BLI_shared_immutable.hpp
M source/blender/functions/CMakeLists.txt
M source/blender/functions/FN_functions.hpp
M source/blender/functions/FN_types.hpp
M source/blender/functions/backends/llvm/llvm_types.cpp
M source/blender/functions/backends/llvm/llvm_types.hpp
M source/blender/functions/c_wrapper.cpp
A source/blender/functions/functions/lists.cpp
A source/blender/functions/functions/lists.hpp
A source/blender/functions/types/lists.hpp
A source/blender/functions/types/numeric_lists.cpp
A source/blender/functions/types/numeric_lists.hpp
===================================================================
diff --git a/source/blender/blenlib/BLI_shared_immutable.hpp b/source/blender/blenlib/BLI_shared_immutable.hpp
new file mode 100644
index 00000000000..6935339b09f
--- /dev/null
+++ b/source/blender/blenlib/BLI_shared_immutable.hpp
@@ -0,0 +1,55 @@
+#pragma once
+
+#include <atomic>
+#include "BLI_utildefines.h"
+
+namespace BLI {
+
+ class SharedImmutable {
+ private:
+ std::atomic<int> m_users;
+
+ SharedImmutable(SharedImmutable &other) = delete;
+
+ public:
+ SharedImmutable()
+ : m_users(1) {}
+
+ virtual ~SharedImmutable() {}
+
+
+ void new_user()
+ {
+ std::atomic_fetch_add(&m_users, 1);
+ }
+
+ void remove_user()
+ {
+ int previous = std::atomic_fetch_sub(&m_users, 1);
+ if (previous == 1) {
+ delete this;
+ }
+ }
+
+ int users() const
+ {
+ return m_users;
+ }
+
+ bool is_mutable() const
+ {
+ return m_users == 1;
+ }
+
+ bool is_immutable() const
+ {
+ return m_users > 1;
+ }
+
+ void assert_mutable() const
+ {
+ BLI_assert(this->is_mutable());
+ }
+ };
+
+} /* namespace BLI */
\ No newline at end of file
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 4a833c0d3ac..1d0e6bf5c14 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -68,6 +68,9 @@ set(SRC
backends/llvm/fgraph_ir_generation.hpp
backends/llvm/fgraph_ir_generation.cpp
+ types/lists.hpp
+ types/numeric_lists.hpp
+ types/numeric_lists.cpp
types/numeric.cpp
types/numeric.hpp
@@ -79,6 +82,8 @@ set(SRC
functions/scalar_math.cpp
functions/vectors.hpp
functions/vectors.cpp
+ functions/lists.hpp
+ functions/lists.cpp
frontends/data_flow_nodes/builder.hpp
frontends/data_flow_nodes/builder.cpp
diff --git a/source/blender/functions/FN_functions.hpp b/source/blender/functions/FN_functions.hpp
index e70482398a8..0491d778c55 100644
--- a/source/blender/functions/FN_functions.hpp
+++ b/source/blender/functions/FN_functions.hpp
@@ -3,4 +3,5 @@
#include "./functions/object_input.hpp"
#include "./functions/random.hpp"
#include "./functions/scalar_math.hpp"
-#include "./functions/vectors.hpp"
\ No newline at end of file
+#include "./functions/vectors.hpp"
+#include "./functions/lists.hpp"
\ No newline at end of file
diff --git a/source/blender/functions/FN_types.hpp b/source/blender/functions/FN_types.hpp
index a6e12ad5f52..3c03f8c7259 100644
--- a/source/blender/functions/FN_types.hpp
+++ b/source/blender/functions/FN_types.hpp
@@ -1,3 +1,4 @@
#pragma once
-#include "types/numeric.hpp"
\ No newline at end of file
+#include "types/numeric.hpp"
+#include "types/numeric_lists.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
index 6484c6a9aba..9db73d130fb 100644
--- a/source/blender/functions/backends/llvm/llvm_types.cpp
+++ b/source/blender/functions/backends/llvm/llvm_types.cpp
@@ -1,7 +1,10 @@
#include "llvm_types.hpp"
+#include "ir_utils.hpp"
namespace FN {
+ /******************** LLVMTypeInfo ********************/
+
const char *LLVMTypeInfo::identifier_in_composition()
{
return "LLVM Type Info";
@@ -29,21 +32,24 @@ namespace FN {
return this->get_type(context)->getPointerTo();
}
- llvm::Value *LLVMTypeInfo::build_copy_ir(
+
+ /******************** SimpleLLVMTypeInfo ********************/
+
+ llvm::Value *SimpleLLVMTypeInfo::build_copy_ir(
llvm::IRBuilder<> &UNUSED(builder),
llvm::Value *value) const
{
return value;
}
- void LLVMTypeInfo::build_free_ir(
+ void SimpleLLVMTypeInfo::build_free_ir(
llvm::IRBuilder<> &UNUSED(builder),
llvm::Value *UNUSED(value)) const
{
return;
}
- void LLVMTypeInfo::build_store_ir__relocate(
+ void SimpleLLVMTypeInfo::build_store_ir__relocate(
llvm::IRBuilder<> &builder,
llvm::Value *value,
llvm::Value *byte_addr) const
@@ -53,7 +59,7 @@ namespace FN {
builder.CreateStore(value, addr, false);
}
- llvm::Value *LLVMTypeInfo::build_load_ir__copy(
+ llvm::Value *SimpleLLVMTypeInfo::build_load_ir__copy(
llvm::IRBuilder<> &builder,
llvm::Value *byte_addr) const
{
@@ -62,11 +68,96 @@ namespace FN {
return builder.CreateLoad(addr);
}
- llvm::Value *LLVMTypeInfo::build_load_ir__relocate(
+ llvm::Value *SimpleLLVMTypeInfo::build_load_ir__relocate(
llvm::IRBuilder<> &builder,
llvm::Value *byte_addr) const
{
return this->build_load_ir__copy(builder, byte_addr);
}
+
+ /******************** PointerLLVMTypeInfo ********************/
+
+ void *PointerLLVMTypeInfo::copy_value(
+ PointerLLVMTypeInfo *info, void *value)
+ {
+ return info->m_copy_func(value);
+ }
+
+ void PointerLLVMTypeInfo::free_value(
+ PointerLLVMTypeInfo *info, void *value)
+ {
+ info->m_free_func(value);
+ }
+
+ void *PointerLLVMTypeInfo::default_value(
+ PointerLLVMTypeInfo *info)
+ {
+ return info->m_default_func();
+ }
+
+ llvm::Value *PointerLLVMTypeInfo::build_copy_ir(
+ llvm::IRBuilder<> &builder,
+ llvm::Value *value) const
+ {
+ auto *void_ptr_ty = builder.getVoidTy()->getPointerTo();
+ auto *copy_ftype = llvm::FunctionType::get(
+ void_ptr_ty, {void_ptr_ty, void_ptr_ty}, false);
+
+ return call_pointer(
+ builder,
+ (void *)PointerLLVMTypeInfo::copy_value,
+ copy_ftype,
+ {void_ptr_to_ir(builder, (void *)this), value});
+ }
+
+ void PointerLLVMTypeInfo::build_free_ir(
+ llvm::IRBuilder<> &builder,
+ llvm::Value *value) const
+ {
+ auto *void_ty = builder.getVoidTy();
+ auto *void_ptr_ty = void_ty->getPointerTo();
+ auto free_ftype = llvm::FunctionType::get(
+ void_ty, {void_ptr_ty, void_ptr_ty}, false);
+
+ call_pointer(
+ builder,
+ (void *)PointerLLVMTypeInfo::free_value,
+ free_ftype,
+ {void_ptr_to_ir(builder, (void *)this), value});
+ }
+
+ void PointerLLVMTypeInfo::build_store_ir__relocate(
+ llvm::IRBuilder<> &builder,
+ llvm::Value *value,
+ llvm::Value *byte_addr) const
+ {
+ auto *void_ty = builder.getVoidTy();
+ auto *void_ptr_ty = void_ty->getPointerTo();
+ auto *void_ptr_ptr_ty = void_ptr_ty->getPointerTo();
+
+ auto *addr = builder.CreatePointerCast(byte_addr, void_ptr_ptr_ty);
+ builder.CreateStore(value, addr);
+ }
+
+ llvm::Value *PointerLLVMTypeInfo::build_load_ir__copy(
+ llvm::IRBuilder<> &builder,
+ llvm::Value *byte_addr) const
+ {
+ auto *value = this->build_load_ir__relocate(builder, byte_addr);
+ this->build_copy_ir(builder, value);
+ return value;
+ }
+
+ llvm::Value *PointerLLVMTypeInfo::build_load_ir__relocate(
+ llvm::IRBuilder<> &builder,
+ llvm::Value *byte_addr) const
+ {
+ auto *void_ty = builder.getVoidTy();
+ auto *void_ptr_ty = void_ty->getPointerTo();
+ auto *void_ptr_ptr_ty = void_ptr_ty->getPointerTo();
+
+ auto *addr = builder.CreatePointerCast(byte_addr, void_ptr_ptr_ty);
+ return builder.CreateLoad(addr);
+ }
};
\ 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
index 9cd211b6715..c90d6caa798 100644
--- a/source/blender/functions/backends/llvm/llvm_types.hpp
+++ b/source/blender/functions/backends/llvm/llvm_types.hpp
@@ -23,26 +23,27 @@ namespace FN {
virtual llvm::Value *build_copy_ir(
llvm::IRBuilder<> &builder,
- llvm::Value *value) const;
+ llvm::Value *value) const = 0;
virtual void build_free_ir(
llvm::IRBuilder<> &builder,
- llvm::Value *value) const;
+ llvm::Value *value) const = 0;
virtual void build_store_ir__relocate(
llvm::IRBuilder<> &builder,
llvm::Value *value,
- llvm::Value *byte_addr) const;
+ llvm::Value *byte_addr) const = 0;
virtual llvm::Value *build_load_ir__copy(
llvm::IRBuilder<> &builder,
- llvm::Value *byte_addr) const;
+ llvm::Value *byte_addr) const = 0;
virtual llvm::Value *build_load_ir__relocate(
llvm::IRBuilder<> &builder,
- llvm::Value *byte_addr) const;
+ llvm::Value *byte_addr) const = 0;
private:
+ /* TODO: accessing this has to be made thread safe. */
mutable SmallMap<llvm::LLVMContext *, llvm::Type *> m_type_per_context;
virtual llvm::Type *create_type(
@@ -54,7 +55,7 @@ namespace FN {
typedef std::function<llvm::Type *(llvm::LLVMContext &context)> CreateFunc;
CreateFunc m_create_func;
- llvm::Type *create_type(llvm::LLVMContext &context) const
+ llvm::Type *create_type(llvm::LLVMContext &context) const override
{
return m_create_func(context);
}
@@ -62,6 +63,74 @@ namespace FN {
public:
SimpleLLVMTypeInfo(CreateFunc create_func)
: m_create_func(create_func) {}
+
+ llvm::Value *build_copy_ir(
+ llvm::IRBuilder<> &builder,
+ llvm::Value *value) const override;
+
+ void build_free_ir(
+ llvm::IRBuilder<> &builder,
+ llvm::Value *value) const override;
+
+ void build_store_ir__relocate(
+ llvm::IRBuilder<> &builder,
+ llvm::Value *value,
+ llvm::Value *byte_addr) const override;
+
+ llvm::Value *build_load_ir__copy(
+ llvm::IRBuilder<> &builder,
+ llvm::Value *byte_addr) const override;
+
+ llvm::Value *build_load_ir__relocate(
+ llvm::IRBuilder<> &builder,
+ llvm::Value *byte_addr) const override;
+ };
+
+ class PointerLLVMTypeInfo : public LLVMTypeInfo {
+ private:
+ typedef std::function<void *(void *)> CopyFunc;
+ typedef std::function<void (void *)> FreeFunc;
+ typedef std::function<void *()> DefaultFunc;
+
+ CopyFunc m_copy_func;
+ FreeFunc m_free_func;
+ DefaultFunc m_default_func;
+
+ llvm::Type *create_type(llvm::LLVMContext &context) const override
+ {
+ return llvm::Type::getVoidTy(context)->getPointerTo();
+ }
+
+ static void *copy_value(PointerLLVMTypeInfo *info, void *value);
+ static void free_value(PointerLLVMTypeInfo *info, void *value);
+ static void *default_value(PointerLLVMTypeInfo *info);
+
+ public:
+ PointerLLVMTypeInfo(CopyFunc copy_func, FreeFunc free_func, DefaultFunc default_func)
+ : m_copy_func(copy_func),
+ m_free_func(free_func),
+ m_default_func(default_func) {}
+
+ llvm::Value *build_copy_ir(
+ llvm::IRBuilder<> &builder,
+ llvm::Value *value) const override;
+
+ void build_free_ir(
+ llvm::IRBuilder<> &builder,
+ llvm::Value *value) const override;
+
+ void build_store_ir__relocate(
+ llvm:
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list