[Bf-blender-cvs] [bd480232ee1] functions: remove LLVMCompiledBody
Jacques Lucke
noreply at git.blender.org
Thu Mar 28 19:56:07 CET 2019
Commit: bd480232ee12ea349c1360014256a9f04d927b37
Author: Jacques Lucke
Date: Thu Mar 28 18:09:46 2019 +0100
Branches: functions
https://developer.blender.org/rBbd480232ee12ea349c1360014256a9f04d927b37
remove LLVMCompiledBody
===================================================================
M source/blender/functions/CMakeLists.txt
M source/blender/functions/FN_llvm.hpp
D source/blender/functions/backends/llvm/compiled_body.cpp
D source/blender/functions/backends/llvm/compiled_body.hpp
M source/blender/functions/backends/llvm/fgraph_ir_generation.cpp
M source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
M source/blender/functions/backends/llvm/ir_to_tuple_call.hpp
===================================================================
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 4ac1189eb4b..b8fee3654de 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -72,8 +72,6 @@ set(SRC
backends/llvm/ir_to_tuple_call.cpp
backends/llvm/ir_for_tuple_call.hpp
backends/llvm/ir_for_tuple_call.cpp
- backends/llvm/compiled_body.hpp
- backends/llvm/compiled_body.cpp
backends/llvm/compile.hpp
backends/llvm/compile.cpp
backends/llvm/fgraph_ir_generation.hpp
diff --git a/source/blender/functions/FN_llvm.hpp b/source/blender/functions/FN_llvm.hpp
index e4c63d4beef..85869fa4125 100644
--- a/source/blender/functions/FN_llvm.hpp
+++ b/source/blender/functions/FN_llvm.hpp
@@ -5,6 +5,6 @@
#include "backends/llvm/build_ir_body.hpp"
#include "backends/llvm/ir_to_tuple_call.hpp"
#include "backends/llvm/ir_for_tuple_call.hpp"
-#include "backends/llvm/compiled_body.hpp"
#include "backends/llvm/fgraph_ir_generation.hpp"
-#include "backends/llvm/builder.hpp"
\ No newline at end of file
+#include "backends/llvm/builder.hpp"
+#include "backends/llvm/compile.hpp"
diff --git a/source/blender/functions/backends/llvm/compiled_body.cpp b/source/blender/functions/backends/llvm/compiled_body.cpp
deleted file mode 100644
index 8ea8e72d2d1..00000000000
--- a/source/blender/functions/backends/llvm/compiled_body.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-#include "FN_llvm.hpp"
-
-#include <llvm/IR/Verifier.h>
-#include <llvm/ExecutionEngine/ExecutionEngine.h>
-
-namespace FN {
-
- BLI_COMPOSITION_IMPLEMENTATION(LLVMCompiledBody);
-
- void LLVMCompiledBody::build_ir(
- CodeBuilder &builder,
- CodeInterface &interface,
- const BuildIRSettings &UNUSED(settings)) const
- {
- auto *ftype = function_type_from_signature(
- this->owner()->signature(), builder.getContext());
-
- llvm::Value *output_struct = builder.CreateCallPointer(
- this->function_ptr(), ftype, interface.inputs());
- for (uint i = 0; i < ftype->getReturnType()->getStructNumElements(); i++) {
- llvm::Value *out = builder.CreateExtractValue(output_struct, i);
- interface.set_output(i, out);
- }
- }
-
- static LLVMCompiledBody *compile_body(
- SharedFunction &fn,
- llvm::LLVMContext &context)
- {
- auto input_type_infos = fn->signature().input_extensions<LLVMTypeInfo>();
- auto output_type_infos = fn->signature().output_extensions<LLVMTypeInfo>();
- LLVMTypes input_types = types_of_type_infos(input_type_infos, context);
- LLVMTypes output_types = types_of_type_infos(output_type_infos, context);
-
- llvm::Type *output_type = llvm::StructType::get(context, to_array_ref(output_types));
-
- llvm::FunctionType *function_type = llvm::FunctionType::get(
- output_type, to_array_ref(input_types), false);
-
- llvm::Module *module = new llvm::Module(fn->name(), context);
-
- llvm::Function *function = llvm::Function::Create(
- function_type,
- llvm::GlobalValue::LinkageTypes::ExternalLinkage,
- fn->name(),
- module);
-
- LLVMValues input_values;
- for (llvm::Value &value : function->args()) {
- input_values.append(&value);
- }
-
- llvm::BasicBlock *bb = llvm::BasicBlock::Create(context, "entry", function);
- CodeBuilder builder(bb);
-
- LLVMBuildIRBody *gen_body = fn->body<LLVMBuildIRBody>();
- BLI_assert(gen_body);
-
- LLVMValues output_values(output_types.size());
- BuildIRSettings settings;
- CodeInterface interface(input_values, output_values);
- gen_body->build_ir(builder, interface, settings);
-
- llvm::Value *return_value = llvm::UndefValue::get(output_type);
- for (uint i = 0; i < output_values.size(); i++) {
- return_value = builder.CreateInsertValue(return_value, output_values[i], i);
- }
- builder.CreateRet(return_value);
-
- auto compiled = CompiledLLVM::FromIR(module, function);
- return new LLVMCompiledBody(std::move(compiled));
- }
-
- void derive_LLVMCompiledBody_from_LLVMBuildIRBody(
- SharedFunction &fn,
- llvm::LLVMContext &context)
- {
- BLI_assert(fn->has_body<LLVMBuildIRBody>());
- BLI_assert(!fn->has_body<LLVMCompiledBody>());
-
- fn->add_body(compile_body(fn, context));
- }
-
-} /* namespace FN */
\ No newline at end of file
diff --git a/source/blender/functions/backends/llvm/compiled_body.hpp b/source/blender/functions/backends/llvm/compiled_body.hpp
deleted file mode 100644
index 4c2136a81e4..00000000000
--- a/source/blender/functions/backends/llvm/compiled_body.hpp
+++ /dev/null
@@ -1,43 +0,0 @@
-#pragma once
-
-#include "FN_core.hpp"
-#include "compile.hpp"
-#include "builder.hpp"
-
-namespace llvm {
- class ExecutionEngine;
- class Module;
- class LLVMContext;
- class FunctionType;
-}
-
-namespace FN {
-
- class LLVMCompiledBody : public FunctionBody {
- private:
- std::unique_ptr<CompiledLLVM> m_compiled;
-
- LLVMCompiledBody() = default;
-
- public:
- BLI_COMPOSITION_DECLARATION(LLVMCompiledBody);
-
- LLVMCompiledBody(std::unique_ptr<CompiledLLVM> compiled)
- : m_compiled(std::move(compiled)) {}
-
- void *function_ptr() const
- {
- return m_compiled->function_ptr();
- }
-
- void build_ir(
- CodeBuilder &builder,
- CodeInterface &interface,
- const BuildIRSettings &settings) const;
- };
-
- void derive_LLVMCompiledBody_from_LLVMBuildIRBody(
- SharedFunction &fn,
- llvm::LLVMContext &context);
-
-} /* namespace FN */
\ No newline at end of file
diff --git a/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp b/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp
index a9d2870682d..731a98a81c0 100644
--- a/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp
+++ b/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp
@@ -156,17 +156,10 @@ namespace FN {
SharedFunction &fn = node->function();
LLVMValues output_values(node->output_amount());
CodeInterface sub_interface(input_values, output_values, context_ptr);
- if (fn->has_body<LLVMCompiledBody>()) {
- auto *body = fn->body<LLVMCompiledBody>();
- body->build_ir(builder, sub_interface, settings);
- }
- else if (fn->has_body<LLVMBuildIRBody>()) {
- auto *body = fn->body<LLVMBuildIRBody>();
- body->build_ir(builder, sub_interface, settings);
- }
- else {
- BLI_assert(false);
- }
+
+ BLI_assert(fn->has_body<LLVMBuildIRBody>());
+ auto *body = fn->body<LLVMBuildIRBody>();
+ body->build_ir(builder, sub_interface, settings);
if (settings.maintain_stack()) {
this->pop_stack_frames_for_node(builder, context_ptr);
@@ -180,6 +173,8 @@ namespace FN {
llvm::Value *context_ptr,
Node *node) const
{
+ BLI_assert(context_ptr);
+
llvm::Value *node_info_frame_buf = builder.CreateAllocaBytes_VoidPtr(sizeof(SourceInfoStackFrame));
builder.CreateCallPointer_NoReturnValue(
(void *)BuildGraphIR::push_source_frame_on_stack,
@@ -199,6 +194,8 @@ namespace FN {
CodeBuilder &builder,
llvm::Value *context_ptr) const
{
+ BLI_assert(context_ptr);
+
for (uint i = 0; i < 2; i++) {
builder.CreateCallPointer_NoReturnValue(
(void *)BuildGraphIR::pop_frame_from_stack,
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 7edc78a2b9b..e667663c4c4 100644
--- a/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
+++ b/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
@@ -26,10 +26,10 @@ namespace FN {
static llvm::Function *insert_tuple_call_function(
SharedFunction &fn,
- BuildIRFunction build_ir,
llvm::Module *module)
{
llvm::LLVMContext &context = module->getContext();
+ LLVMBuildIRBody *body = fn->body<LLVMBuildIRBody>();
llvm::Type *void_ty = llvm::Type::getVoidTy(context);
llvm::Type *void_ptr_ty = void_ty->getPointerTo();
@@ -53,7 +53,6 @@ namespace FN {
fn->name(),
module);
-
llvm::BasicBlock *bb = llvm::BasicBlock::Create(context, "entry", function);
CodeBuilder builder(bb);
@@ -79,7 +78,7 @@ namespace FN {
LLVMValues output_values(fn->signature().outputs().size());
BuildIRSettings settings;
CodeInterface interface(input_values, output_values, context_ptr);
- build_ir(builder, interface, settings);
+ body->build_ir(builder, interface, settings);
for (uint i = 0; i < output_values.size(); i++) {
llvm::Value *value_byte_addr = lookup_tuple_address(
@@ -135,44 +134,15 @@ namespace FN {
static TupleCallBody *compile_ir_to_tuple_call(
SharedFunction &fn,
- llvm::LLVMContext &context,
- BuildIRFunction build_ir)
+ llvm::LLVMContext &context)
{
llvm::Module *module = new llvm::Module(fn->name(), context);
- llvm::Function *function = insert_tuple_call_function(fn, build_ir, module);
+ llvm::Function *function = insert_tuple_call_function(fn, module);
auto compiled = CompiledLLVM::FromIR(module, function);
return new LLVMTupleCall(std::move(compiled));
}
- static TupleCallBody *build_from_compiled(
- SharedFunction &fn,
- llvm::LLVMContext &context)
- {
- auto *body = fn->body<LLVMCompiledBody>();
- return compile_ir_to_tuple_call(fn, context, [body](
- CodeBuilder &builder,
- CodeInterface &interface,
- const BuildIRSettings &settings)
- {
- body->build_ir(builder, interface, settings);
- });
- }
-
- static TupleCallBody *build_from_ir_generator(
- SharedFunction &fn,
- llvm::LLVMContext &context)
- {
- auto *body = fn->body<LLVMBuildIRBody>();
- return compile_ir_to_tuple_call(fn, context, [body](
- CodeBuilder &builder,
- CodeInterface &interface,
- const BuildIRSettings &settings)
- {
- body->build_ir(builder, interface, settings);
- });
- }
-
void derive_TupleCallBody_from_LLVMBuildIRBody(
SharedFunction &fn,
llvm::LLVMContext &context)
@@ -180,17 +150,7 @@ namespace FN {
BLI_assert(fn->has_body<LLVMBuildIRBody>());
BLI_assert(!fn->has_body<TupleCallBody>());
- fn->add_body(build_from_ir_generator(fn, context));
- }
-
- void derive_TupleCallBody_from_LLVMCompiledBody(
- SharedFunction &fn,
- llvm::LLVMContext &context)
- {
- BLI_assert(fn->has_body<LLVMCompiledBody>());
- BLI_assert(!fn->has_body<TupleCallBody>());
-
- fn->add_body(build_from_compiled(fn, context));
+ fn->add_body(compile_ir_to_tuple_call(fn, context));
}
} /*
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list