Commit: c1bad0da7a29f98eb5faf65c1a8ea8a58eb210db
Author: Jacques Lucke
Date:   Mon Mar 4 16:29:56 2019 +0100
Branches: functions
https://developer.blender.org/rBc1bad0da7a29f98eb5faf65c1a8ea8a58eb210db

improve LLVMCompiledBody

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

M       source/blender/functions/backends/llvm/compile.cpp
M       source/blender/functions/backends/llvm/compiled_body.cpp
M       source/blender/functions/backends/llvm/compiled_body.hpp
M       source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
M       source/blender/functions/core/function.hpp

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

diff --git a/source/blender/functions/backends/llvm/compile.cpp 
b/source/blender/functions/backends/llvm/compile.cpp
index f49cb41a273..e8415bd06e5 100644
--- a/source/blender/functions/backends/llvm/compile.cpp
+++ b/source/blender/functions/backends/llvm/compile.cpp
@@ -17,13 +17,13 @@ namespace FN {
                llvm::Function *main_function)
        {
                BLI_assert(!llvm::verifyModule(*module, &llvm::outs()));
+               module->print(llvm::outs(), nullptr);
 
                llvm::ExecutionEngine *ee = llvm::EngineBuilder(
                        std::unique_ptr<llvm::Module>(module)).create();
                ee->finalizeObject();
                ee->generateCodeForModule(module);
 
-               //module->print(llvm::outs(), nullptr);
 
                uint64_t function_ptr = ee->getFunctionAddress(
                        main_function->getName().str());
diff --git a/source/blender/functions/backends/llvm/compiled_body.cpp 
b/source/blender/functions/backends/llvm/compiled_body.cpp
index 512c948f24d..6f6a9c96a66 100644
--- a/source/blender/functions/backends/llvm/compiled_body.cpp
+++ b/source/blender/functions/backends/llvm/compiled_body.cpp
@@ -17,6 +17,25 @@ namespace FN {
                delete v;
        }
 
+       void LLVMCompiledBody::build_ir(
+               llvm::IRBuilder<> &builder,
+               const LLVMValues &inputs,
+               LLVMValues &r_outputs) const
+       {
+               auto *ftype = function_type_from_signature(
+                       this->owner()->signature(), builder.getContext());
+
+               llvm::Value *output_struct = call_pointer(
+                       builder,
+                       this->function_ptr(),
+                       ftype,
+                       inputs);
+               for (uint i = 0; i < 
ftype->getReturnType()->getStructNumElements(); i++) {
+                       llvm::Value *out = 
builder.CreateExtractValue(output_struct, i);
+                       r_outputs.append(out);
+               }
+       }
+
        static LLVMCompiledBody *compile_body(
                SharedFunction &fn,
                llvm::LLVMContext &context)
diff --git a/source/blender/functions/backends/llvm/compiled_body.hpp 
b/source/blender/functions/backends/llvm/compiled_body.hpp
index c1e7b049dc7..ca00bc61bda 100644
--- a/source/blender/functions/backends/llvm/compiled_body.hpp
+++ b/source/blender/functions/backends/llvm/compiled_body.hpp
@@ -25,10 +25,15 @@ namespace FN {
                LLVMCompiledBody(std::unique_ptr<CompiledLLVM> compiled)
                        : m_compiled(std::move(compiled)) {}
 
-               void *function_ptr()
+               void *function_ptr() const
                {
                        return m_compiled->function_ptr();
                }
+
+               void build_ir(
+                       llvm::IRBuilder<> &builder,
+                       const LLVMValues &inputs,
+                       LLVMValues &r_outputs) const;
        };
 
        void derive_LLVMCompiledBody_from_LLVMBuildIRBody(
diff --git a/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp 
b/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
index edb1f0da973..a787390d4f8 100644
--- a/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
+++ b/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
@@ -130,21 +130,12 @@ namespace FN {
                llvm::LLVMContext &context)
        {
                auto *body = fn->body<LLVMCompiledBody>();
-               return compile_ir_to_tuple_call(fn, context, [&fn, body](
+               return compile_ir_to_tuple_call(fn, context, [body](
                                llvm::IRBuilder<> &builder,
                                const LLVMValues &inputs,
                                LLVMValues &outputs)
                        {
-                               auto *ftype = 
function_type_from_signature(fn->signature(), builder.getContext());
-                               llvm::Value *output_struct = call_pointer(
-                                       builder,
-                                       body->function_ptr(),
-                                       ftype,
-                                       inputs);
-                               for (uint i = 0; i < 
ftype->getReturnType()->getStructNumElements(); i++) {
-                                       llvm::Value *out = 
builder.CreateExtractValue(output_struct, i);
-                                       outputs.append(out);
-                               }
+                               body->build_ir(builder, inputs, outputs);
                        });
        }
 
diff --git a/source/blender/functions/core/function.hpp 
b/source/blender/functions/core/function.hpp
index 1f8c1d5198c..988121cc4b9 100644
--- a/source/blender/functions/core/function.hpp
+++ b/source/blender/functions/core/function.hpp
@@ -18,7 +18,7 @@ namespace FN {
                friend class Function;
 
        public:
-               Function *owner()
+               Function *owner() const
                {
                        return m_owner;
                }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to