[Bf-blender-cvs] [40c12c675fb] functions: move execution context pointer through llvm
Jacques Lucke
noreply at git.blender.org
Thu Mar 28 17:50:58 CET 2019
Commit: 40c12c675fbe5c2eb58884fb723bff85691b6437
Author: Jacques Lucke
Date: Thu Mar 28 17:25:29 2019 +0100
Branches: functions
https://developer.blender.org/rB40c12c675fbe5c2eb58884fb723bff85691b6437
move execution context pointer through llvm
===================================================================
M source/blender/functions/backends/llvm/build_ir_body.hpp
M source/blender/functions/backends/llvm/fgraph_ir_generation.cpp
M source/blender/functions/backends/llvm/ir_for_tuple_call.cpp
M source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
===================================================================
diff --git a/source/blender/functions/backends/llvm/build_ir_body.hpp b/source/blender/functions/backends/llvm/build_ir_body.hpp
index 742baac849d..ca7575a63ea 100644
--- a/source/blender/functions/backends/llvm/build_ir_body.hpp
+++ b/source/blender/functions/backends/llvm/build_ir_body.hpp
@@ -12,10 +12,16 @@ namespace FN {
private:
LLVMValues &m_inputs;
LLVMValues &m_outputs;
+ llvm::Value *m_context_ptr;
public:
- CodeInterface(LLVMValues &inputs, LLVMValues &outputs)
- : m_inputs(inputs), m_outputs(outputs) {}
+ CodeInterface(
+ LLVMValues &inputs,
+ LLVMValues &outputs,
+ llvm::Value *context_ptr = nullptr)
+ : m_inputs(inputs),
+ m_outputs(outputs),
+ m_context_ptr(context_ptr) {}
llvm::Value *get_input(uint index)
{
@@ -31,6 +37,11 @@ namespace FN {
{
return m_inputs;
}
+
+ llvm::Value *context_ptr() const
+ {
+ return m_context_ptr;
+ }
};
class LLVMBuildIRBody : public FunctionBody {
diff --git a/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp b/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp
index fdbc7f00d93..1092f23b9ab 100644
--- a/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp
+++ b/source/blender/functions/backends/llvm/fgraph_ir_generation.cpp
@@ -35,8 +35,9 @@ namespace FN {
void build_ir(
CodeBuilder &builder,
CodeInterface &interface,
- const BuildIRSettings &UNUSED(settings)) const override
+ const BuildIRSettings &settings) const override
{
+
SocketValueMap values;
for (uint i = 0; i < interface.inputs().size(); i++) {
values.add(m_inputs[i], interface.get_input(i));
@@ -45,7 +46,8 @@ namespace FN {
SocketSet forwarded_sockets;
for (uint i = 0; i < m_outputs.size(); i++) {
Socket socket = m_outputs[i];
- this->generate_for_socket(builder, socket, values, forwarded_sockets);
+ this->generate_for_socket(
+ builder, interface.context_ptr(), settings, socket, values, forwarded_sockets);
interface.set_output(i, values.lookup(socket));
}
@@ -54,6 +56,8 @@ namespace FN {
private:
void generate_for_socket(
CodeBuilder &builder,
+ llvm::Value *context_ptr,
+ const BuildIRSettings &settings,
Socket socket,
SocketValueMap &values,
SocketSet &forwarded_sockets) const
@@ -63,18 +67,21 @@ namespace FN {
}
else if (socket.is_input()) {
Socket origin = socket.origin();
- this->generate_for_socket(builder, origin, values, forwarded_sockets);
+ this->generate_for_socket(
+ builder, context_ptr, settings, origin, values, forwarded_sockets);
this->forward_output_if_necessary(builder, origin, values, forwarded_sockets);
}
else if (socket.is_output()) {
Node *node = socket.node();
LLVMValues input_values;
for (Socket input : node->inputs()) {
- this->generate_for_socket(builder, input, values, forwarded_sockets);
+ this->generate_for_socket(
+ builder, context_ptr, settings, input, values, forwarded_sockets);
input_values.append(values.lookup(input));
}
- LLVMValues output_values = this->build_node_ir(builder, node, input_values);
+ LLVMValues output_values = this->build_node_ir(
+ builder, context_ptr, settings, node, input_values);
for (uint i = 0; i < output_values.size(); i++) {
Socket output = node->output(i);
@@ -137,28 +144,80 @@ namespace FN {
LLVMValues build_node_ir(
CodeBuilder &builder,
+ llvm::Value *context_ptr,
+ const BuildIRSettings &settings,
Node *node,
LLVMValues &input_values) const
{
- BuildIRSettings settings;
- SharedFunction &fn = node->function();
+ this->push_stack_frames_for_node(builder, context_ptr, node);
+ SharedFunction &fn = node->function();
LLVMValues output_values(node->output_amount());
- CodeInterface interface(input_values, output_values);
-
+ CodeInterface sub_interface(input_values, output_values, context_ptr);
if (fn->has_body<LLVMCompiledBody>()) {
auto *body = fn->body<LLVMCompiledBody>();
- body->build_ir(builder, interface, settings);
+ body->build_ir(builder, sub_interface, settings);
}
else if (fn->has_body<LLVMBuildIRBody>()) {
auto *body = fn->body<LLVMBuildIRBody>();
- body->build_ir(builder, interface, settings);
+ body->build_ir(builder, sub_interface, settings);
}
else {
BLI_assert(false);
}
+
+ this->pop_stack_frames_for_node(builder, context_ptr);
+
return output_values;
}
+
+ void push_stack_frames_for_node(
+ CodeBuilder &builder,
+ llvm::Value *context_ptr,
+ Node *node) const
+ {
+ llvm::Value *node_info_frame_buf = builder.CreateAllocaBytes_VoidPtr(sizeof(SourceInfoStackFrame));
+ builder.CreateCallPointer_NoReturnValue(
+ (void *)BuildGraphIR::push_source_frame_on_stack,
+ { context_ptr,
+ node_info_frame_buf,
+ builder.getVoidPtr(node) });
+
+ llvm::Value *function_info_frame_buf = builder.CreateAllocaBytes_VoidPtr(sizeof(TextStackFrame));
+ builder.CreateCallPointer_NoReturnValue(
+ (void *)BuildGraphIR::push_text_frame_on_stack,
+ { context_ptr,
+ function_info_frame_buf,
+ builder.getVoidPtr((void *)node->function()->name().c_str())});
+ }
+
+ void pop_stack_frames_for_node(
+ CodeBuilder &builder,
+ llvm::Value *context_ptr) const
+ {
+ for (uint i = 0; i < 2; i++) {
+ builder.CreateCallPointer_NoReturnValue(
+ (void *)BuildGraphIR::pop_frame_from_stack,
+ { context_ptr });
+ }
+ }
+
+ static void push_source_frame_on_stack(ExecutionContext *ctx, void *frame_buf, Node *node)
+ {
+ StackFrame *frame = new(frame_buf) SourceInfoStackFrame(node->source());
+ ctx->stack().push(frame);
+ }
+
+ static void push_text_frame_on_stack(ExecutionContext *ctx, void *frame_buf, const char *text)
+ {
+ StackFrame *frame = new(frame_buf) TextStackFrame(text);
+ ctx->stack().push(frame);
+ }
+
+ static void pop_frame_from_stack(ExecutionContext *ctx)
+ {
+ ctx->stack().pop();
+ }
};
void fgraph_add_LLVMBuildIRBody(
diff --git a/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp b/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp
index 054e881713f..6903b0852a2 100644
--- a/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp
+++ b/source/blender/functions/backends/llvm/ir_for_tuple_call.cpp
@@ -67,6 +67,7 @@ namespace FN {
auto output_type_infos = fn->signature().output_extensions<LLVMTypeInfo>();
LLVMTypes input_types = builder.types_of_values(interface.inputs());
+ input_types.append(builder.getVoidPtrTy());
LLVMTypes output_types;
for (auto type_info : output_type_infos) {
output_types.append(type_info->get_type(context));
@@ -91,7 +92,9 @@ namespace FN {
wrapper_output_type);
/* Call wrapper function. */
- llvm::Value *output_struct = builder.CreateCall(wrapper_function, interface.inputs());
+ LLVMValues call_inputs = interface.inputs();
+ call_inputs.append(interface.context_ptr());
+ llvm::Value *output_struct = builder.CreateCall(wrapper_function, call_inputs);
/* Extract output values. */
for (uint i = 0; i < output_type_infos.size(); i++) {
@@ -127,7 +130,7 @@ namespace FN {
}
/* Execute tuple call body. */
- llvm::Value *exec_ctx = build__stack_allocate_ExecutionContext(builder);
+ llvm::Value *exec_ctx = function->arg_begin() + input_type_infos.size();
builder.CreateCallPointer_NoReturnValue(
(void *)run_TupleCallBody,
{builder.getVoidPtr(m_tuple_call),
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 29ae8b8b053..7edc78a2b9b 100644
--- a/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
+++ b/source/blender/functions/backends/llvm/ir_to_tuple_call.cpp
@@ -32,6 +32,7 @@ namespace FN {
llvm::LLVMContext &context = module->getContext();
llvm::Type *void_ty = llvm::Type::getVoidTy(context);
+ llvm::Type *void_ptr_ty = void_ty->getPointerTo();
llvm::Type *byte_ptr_ty = llvm::Type::getInt8PtrTy(context);
llvm::Type *int_ptr_ty = llvm::Type::getInt32PtrTy(context);
@@ -40,6 +41,7 @@ namespace FN {
int_ptr_ty,
byte_ptr_ty,
int_ptr_ty,
+ void_ptr_ty,
};
llvm::FunctionType *function_type = llvm::FunctionType::get(
@@ -59,6 +61,7 @@ namespace FN {
llvm::Value *fn_in_offsets = function->arg_begin() + 1;
llvm::Value *fn_out_data = function->arg_begin() + 2;
llvm::Value *fn_out_offsets = function->arg_begin() + 3;
+ llvm::Value *context_ptr = function->arg_begin() + 4;
LLVMValues input_values;
for (uint i = 0; i < fn->signature().inputs().size(); i++) {
@@ -75,7 +78,7 @@ namespace FN {
LLVMValues output_values(fn->signature().outputs().size());
BuildIRSettings settings;
- CodeInterface interface(input_values, output_values);
+ CodeInterface interface(input_values, output_values, context_ptr);
build_ir(builder, interface, settings);
for (uint i = 0; i < output_values.size(); i++) {
@@ -97,7 +100,8 @@ namespace FN {
void *data_in,
const uint *offsets_in,
void *data_out,
- const uint *offsets_out);
+ const uint *offsets_out,
+ ExecutionContext *ctx);
class LLVMTupleCall : public TupleCallBody {
private:
@@ -111,7 +115,7 @@ namespace FN {
m_call = (LLVMCallFN)m_compiled->function_ptr();
}
- void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &UNUSED(ctx)) const override
+ void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &ctx) const override
{
fn_out.destruct_all();
BLI_assert(fn_in.all_initialized());
@@ -121,7 +125,8 @@ namespace FN {
fn_in.data_ptr(),
fn_in.offsets_ptr(),
fn_out.data_ptr(),
- fn_out.offsets_ptr());
+ fn_out.offsets_ptr(),
+ &ctx);
fn_in.set_all_uninitialized();
fn_out.set_all_initialized();
More information about the Bf-blender-cvs
mailing list