[Bf-blender-cvs] [1ab8b7f658e] functions: move c functions to access lists to lists.cpp
Jacques Lucke
noreply at git.blender.org
Wed May 1 19:32:05 CEST 2019
Commit: 1ab8b7f658eb6cbadce26b58bbb6fc7ac3fd01cb
Author: Jacques Lucke
Date: Wed May 1 18:26:42 2019 +0200
Branches: functions
https://developer.blender.org/rB1ab8b7f658eb6cbadce26b58bbb6fc7ac3fd01cb
move c functions to access lists to lists.cpp
===================================================================
M source/blender/functions/functions/auto_vectorization.cpp
M source/blender/functions/functions/lists.cpp
M source/blender/functions/functions/lists.hpp
===================================================================
diff --git a/source/blender/functions/functions/auto_vectorization.cpp b/source/blender/functions/functions/auto_vectorization.cpp
index 44c491d4996..dba2f629ccf 100644
--- a/source/blender/functions/functions/auto_vectorization.cpp
+++ b/source/blender/functions/functions/auto_vectorization.cpp
@@ -8,87 +8,27 @@
namespace FN {
namespace Functions {
-template<typename T> uint get_list_length(const Types::List<T> *list)
-{
- return list->size();
-}
-
static llvm::Value *build_ir__get_list_length(CodeBuilder &builder,
SharedType &base_type,
- llvm::Value *list,
- CodeInterface &parent_interface,
- const BuildIRSettings &settings)
+ llvm::Value *list)
{
- if (base_type == Types::GET_TYPE_float()) {
- return builder.CreateCallPointer((void *)get_list_length<float>, {list}, builder.getInt32Ty());
- }
- else if (base_type == Types::GET_TYPE_fvec3()) {
- return builder.CreateCallPointer(
- (void *)get_list_length<Types::Vector>, {list}, builder.getInt32Ty());
- }
- else {
- BLI_assert(!"not yet supported");
- return nullptr;
- }
-
- SharedFunction &get_length_fn = GET_FN_list_length(base_type);
- if (!get_length_fn->has_body<LLVMBuildIRBody>()) {
- derive_LLVMBuildIRBody_from_TupleCallBody(get_length_fn);
- }
-
- auto *body = get_length_fn->body<LLVMBuildIRBody>();
- LLVMValues inputs = {list};
- LLVMValues outputs(1);
- CodeInterface interface(
- inputs, outputs, parent_interface.context_ptr(), parent_interface.function_ir_cache());
- body->build_ir(builder, interface, settings);
- return outputs[0];
-}
-
-template<typename T> T *get_value_ptr(const Types::List<T> *list)
-{
- return list->data_ptr();
+ return builder.CreateCallPointer(
+ (void *)GET_C_FN_list_length(base_type), {list}, builder.getInt32Ty());
}
static llvm::Value *build_ir__get_list_value_ptr(CodeBuilder &builder,
SharedType &base_type,
llvm::Value *list)
{
- if (base_type == Types::GET_TYPE_float()) {
- return builder.CreateCallPointer_RetVoidPtr((void *)get_value_ptr<float>, {list});
- }
- else if (base_type == Types::GET_TYPE_fvec3()) {
- return builder.CreateCallPointer_RetVoidPtr((void *)get_value_ptr<Types::Vector>, {list});
- }
- else {
- BLI_assert(!"not yet supported");
- return nullptr;
- }
-}
-
-template<typename T> Types::List<T> *new_list_with_prepared_memory(uint length)
-{
- auto *list = new Types::List<T>(length);
- return list;
+ return builder.CreateCallPointer_RetVoidPtr((void *)GET_C_FN_list_data_ptr(base_type), {list});
}
static llvm::Value *build_ir__new_list_with_prepared_memory(CodeBuilder &builder,
SharedType &base_type,
llvm::Value *length)
{
- LLVMValues args = {length};
- if (base_type == Types::GET_TYPE_float()) {
- return builder.CreateCallPointer_RetVoidPtr((void *)new_list_with_prepared_memory<float>,
- args);
- }
- else if (base_type == Types::GET_TYPE_fvec3()) {
- return builder.CreateCallPointer_RetVoidPtr(
- (void *)new_list_with_prepared_memory<Types::Vector>, args);
- }
- else {
- BLI_assert(!"not yet supported");
- return nullptr;
- }
+ return builder.CreateCallPointer_RetVoidPtr(
+ (void *)GET_C_FN_new_list_with_allocated_buffer(base_type), {length});
}
class AutoVectorizationGen : public LLVMBuildIRBody {
@@ -119,7 +59,7 @@ class AutoVectorizationGen : public LLVMBuildIRBody {
for (uint index : m_list_inputs) {
llvm::Value *length = build_ir__get_list_length(
- builder, this->input_type(index), interface.get_input(index), interface, settings);
+ builder, this->input_type(index), interface.get_input(index));
list_lengths.append(length);
}
diff --git a/source/blender/functions/functions/lists.cpp b/source/blender/functions/functions/lists.cpp
index a223f907638..3b81c2aeb4b 100644
--- a/source/blender/functions/functions/lists.cpp
+++ b/source/blender/functions/functions/lists.cpp
@@ -178,6 +178,27 @@ SharedFunction build_list_length_function(SharedType &base_type, SharedType &lis
return fn;
}
+/* C Functions for List access
+ **************************************/
+
+template<typename T> uint get_list_length(void *list)
+{
+ const List<T> *list_ = (Types::List<T> *)list;
+ return list_->size();
+}
+
+template<typename T> void *get_value_ptr(void *list)
+{
+ const List<T> *list_ = (Types::List<T> *)list;
+ return (void *)list_->data_ptr();
+}
+
+template<typename T> void *new_list_with_prepared_memory(uint length)
+{
+ auto *list = new Types::List<T>(length);
+ return (void *)list;
+}
+
/* Build List Functions
*************************************/
@@ -188,6 +209,10 @@ struct ListFunctions {
FunctionPerType m_get_element;
FunctionPerType m_combine;
FunctionPerType m_length;
+
+ SmallMap<SharedType, GetListLength> m_c_length;
+ SmallMap<SharedType, GetListDataPtr> m_c_data_ptr;
+ SmallMap<SharedType, NewListWithAllocatedBuffer> m_c_new_allocated;
};
template<typename T>
@@ -203,6 +228,10 @@ void insert_list_functions_for_type(ListFunctions &functions,
functions.m_get_element.add(base_type, build_get_element_function<T>(base_type, list_type));
functions.m_combine.add(base_type, build_combine_lists_function<T>(base_type, list_type));
functions.m_length.add(base_type, build_list_length_function<T>(base_type, list_type));
+
+ functions.m_c_length.add(base_type, get_list_length<T>);
+ functions.m_c_data_ptr.add(base_type, get_value_ptr<T>);
+ functions.m_c_new_allocated.add(base_type, new_list_with_prepared_memory<T>);
}
LAZY_INIT_REF_STATIC__NO_ARG(ListFunctions, get_list_functions)
@@ -266,5 +295,18 @@ SharedType &get_list_type(SharedType &base_type)
return fn->signature().inputs()[0].type();
}
+GetListLength GET_C_FN_list_length(SharedType &base_type)
+{
+ return get_list_functions().m_c_length.lookup(base_type);
+}
+GetListDataPtr GET_C_FN_list_data_ptr(SharedType &base_type)
+{
+ return get_list_functions().m_c_data_ptr.lookup(base_type);
+}
+NewListWithAllocatedBuffer GET_C_FN_new_list_with_allocated_buffer(SharedType &base_type)
+{
+ return get_list_functions().m_c_new_allocated.lookup(base_type);
+}
+
} // namespace Functions
} // namespace FN
diff --git a/source/blender/functions/functions/lists.hpp b/source/blender/functions/functions/lists.hpp
index cf3a59c45b3..2570b27c87b 100644
--- a/source/blender/functions/functions/lists.hpp
+++ b/source/blender/functions/functions/lists.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "FN_core.hpp"
+#include "FN_types.hpp"
namespace FN {
namespace Functions {
@@ -14,5 +15,13 @@ SharedFunction &GET_FN_get_list_element(SharedType &base_type);
SharedFunction &GET_FN_combine_lists(SharedType &base_type);
SharedFunction &GET_FN_list_length(SharedType &base_type);
+typedef uint (*GetListLength)(void *list);
+typedef void *(*GetListDataPtr)(void *list);
+typedef void *(*NewListWithAllocatedBuffer)(uint length);
+
+GetListLength GET_C_FN_list_length(SharedType &base_type);
+GetListDataPtr GET_C_FN_list_data_ptr(SharedType &base_type);
+NewListWithAllocatedBuffer GET_C_FN_new_list_with_allocated_buffer(SharedType &base_type);
+
} // namespace Functions
} // namespace FN
More information about the Bf-blender-cvs
mailing list