Commit: d8e000623777328b374dd65cd7c1a2d6cad4ab2c
Author: Lukas Tönne
Date: Sun May 29 13:34:02 2016 +0200
Branches: object_nodes
https://developer.blender.org/rBd8e000623777328b374dd65cd7c1a2d6cad4ab2c
Generate names for formal function parameters to make LLVM output more readable.
Note that these names are not identifiers and don't have to be unique, their
only
purpose is to aid in understanding the generated LLVM code.
===================================================================
M source/blender/blenvm/llvm/llvm_compiler.cc
M source/blender/blenvm/llvm/llvm_compiler.h
M source/blender/blenvm/llvm/llvm_compiler_dual.cc
M source/blender/blenvm/llvm/llvm_compiler_simple.cc
===================================================================
diff --git a/source/blender/blenvm/llvm/llvm_compiler.cc
b/source/blender/blenvm/llvm/llvm_compiler.cc
index 1537a3d..431cfad 100644
--- a/source/blender/blenvm/llvm/llvm_compiler.cc
+++ b/source/blender/blenvm/llvm/llvm_compiler.cc
@@ -170,21 +170,19 @@ llvm::Function
*LLVMCompilerBase::codegen_node_function(const string &name, cons
{
using namespace llvm;
- std::vector<llvm::Type*> input_types, output_types;
+ FunctionParameterList input_types, output_types;
for (int i = 0; i < graph.inputs.size(); ++i) {
const NodeGraph::Input &input = graph.inputs[i];
Type *type = get_argument_type(input.typedesc.get_typespec());
- input_types.push_back(type);
+ input_types.push_back(FunctionParameter(type, input.name));
}
for (int i = 0; i < graph.outputs.size(); ++i) {
const NodeGraph::Output &output = graph.outputs[i];
Type *type = get_return_type(output.typedesc.get_typespec());
- output_types.push_back(type);
+ output_types.push_back(FunctionParameter(type, output.name));
}
- FunctionType *functype = get_node_function_type(input_types,
output_types);
-
- Function *func = Function::Create(functype, Function::ExternalLinkage,
name, module());
+ Function *func = declare_function(module(), name, input_types,
output_types);
BLI_assert(func->getArgumentList().size() == graph.inputs.size() +
graph.outputs.size() &&
"Error: Function has wrong number of arguments for node
tree\n");
@@ -314,43 +312,52 @@ void
LLVMCompilerBase::expand_function_node(llvm::BasicBlock *block, const NodeI
UNUSED_VARS(call);
}
-llvm::FunctionType *LLVMCompilerBase::get_node_function_type(const
std::vector<llvm::Type*> &inputs,
- const
std::vector<llvm::Type*> &outputs)
+llvm::Function *LLVMCompilerBase::declare_function(llvm::Module *mod, const
string &name,
+ const FunctionParameterList
&input_types,
+ const FunctionParameterList
&output_types)
{
using namespace llvm;
std::vector<llvm::Type*> arg_types;
- for (int i = 0; i < outputs.size(); ++i) {
- Type *value_type = outputs[i];
+ for (int i = 0; i < output_types.size(); ++i) {
+ Type *type = output_types[i].type;
/* use a pointer to store output values */
- arg_types.push_back(value_type->getPointerTo());
+ arg_types.push_back(type->getPointerTo());
+ }
+ for (int i = 0; i < input_types.size(); ++i) {
+ Type *type = input_types[i].type;
+ arg_types.push_back(type);
+ }
+
+ FunctionType *functype = FunctionType::get(TypeBuilder<void,
true>::get(context()), arg_types, false);
+ Function *func = Function::Create(functype, Function::ExternalLinkage,
name, mod);
+
+ Function::arg_iterator it = func->arg_begin();
+ for (size_t i = 0; i < output_types.size(); ++i, ++it) {
+ it->setName(output_types[i].name);
+ }
+ for (size_t i = 0; i < input_types.size(); ++i, ++it) {
+ it->setName(input_types[i].name);
}
- arg_types.insert(arg_types.end(), inputs.begin(), inputs.end());
- return FunctionType::get(TypeBuilder<void, true>::get(context()),
arg_types, false);
+ return func;
}
llvm::Function *LLVMCompilerBase::declare_node_function(llvm::Module *mod,
const NodeType *nodetype)
{
using namespace llvm;
- std::vector<Type *> input_types, output_types;
+ FunctionParameterList input_types, output_types;
for (int i = 0; i < nodetype->num_inputs(); ++i) {
const NodeInput *input = nodetype->find_input(i);
- bool is_constant = (input->value_type == INPUT_CONSTANT);
-
- append_input_types(input_types, input->typedesc.get_typespec(),
is_constant);
+ append_input_types(input_types, input);
}
for (int i = 0; i < nodetype->num_outputs(); ++i) {
const NodeOutput *output = nodetype->find_output(i);
-
- append_output_types(output_types,
output->typedesc.get_typespec());
+ append_output_types(output_types, output);
}
- FunctionType *functype = get_node_function_type(input_types,
output_types);
-
- Function *func = Function::Create(functype, Function::ExternalLinkage,
nodetype->name(), mod);
- return func;
+ return declare_function(mod, nodetype->name(), input_types,
output_types);
}
/* ------------------------------------------------------------------------- */
diff --git a/source/blender/blenvm/llvm/llvm_compiler.h
b/source/blender/blenvm/llvm/llvm_compiler.h
index 993c94c..ea3566f 100644
--- a/source/blender/blenvm/llvm/llvm_compiler.h
+++ b/source/blender/blenvm/llvm/llvm_compiler.h
@@ -64,6 +64,16 @@ struct NodeInstance;
struct TypeDesc;
struct FunctionLLVM;
+struct FunctionParameter {
+ FunctionParameter(llvm::Type *type, const std::string &name) :
+ type(type), name(name)
+ {}
+
+ llvm::Type *type;
+ std::string name;
+};
+typedef std::vector<FunctionParameter> FunctionParameterList;
+
struct LLVMCompilerBase {
virtual ~LLVMCompilerBase();
@@ -89,8 +99,6 @@ protected:
void expand_pass_node(llvm::BasicBlock *block, const NodeInstance
*node);
void expand_argument_node(llvm::BasicBlock *block, const NodeInstance
*node);
void expand_function_node(llvm::BasicBlock *block, const NodeInstance
*node);
- llvm::FunctionType *get_node_function_type(const
std::vector<llvm::Type*> &inputs,
- const
std::vector<llvm::Type*> &outputs);
virtual void node_graph_begin() = 0;
virtual void node_graph_end() = 0;
@@ -108,10 +116,12 @@ protected:
virtual llvm::Type *get_argument_type(const TypeSpec *spec) const = 0;
virtual llvm::Type *get_return_type(const TypeSpec *spec) const = 0;
- virtual void append_input_types(std::vector<llvm::Type*> ¶ms,
- const TypeSpec *spec, bool is_constant)
const = 0;
- virtual void append_output_types(std::vector<llvm::Type*> ¶ms,
const TypeSpec *spec) const = 0;
+ virtual void append_input_types(FunctionParameterList ¶ms, const
NodeInput *input) const = 0;
+ virtual void append_output_types(FunctionParameterList ¶ms, const
NodeOutput *output) const = 0;
+ llvm::Function *declare_function(llvm::Module *mod, const string &name,
+ const FunctionParameterList
&input_types,
+ const FunctionParameterList
&output_types);
llvm::Function *declare_node_function(llvm::Module *mod, const NodeType
*nodetype);
virtual void define_nodes_module() = 0;
virtual llvm::Module *get_nodes_module() const = 0;
@@ -139,9 +149,8 @@ struct LLVMSimpleCompilerImpl : public LLVMCompilerBase {
llvm::Type *get_argument_type(const TypeSpec *spec) const;
llvm::Type *get_return_type(const TypeSpec *spec) const;
- void append_input_types(std::vector<llvm::Type*> ¶ms,
- const TypeSpec *spec, bool is_constant) const;
- void append_output_types(std::vector<llvm::Type*> ¶ms, const
TypeSpec *spec) const;
+ void append_input_types(FunctionParameterList ¶ms, const NodeInput
*input) const;
+ void append_output_types(FunctionParameterList ¶ms, const
NodeOutput *output) const;
llvm::Module *get_nodes_module() const { return m_nodes_module; }
@@ -175,9 +184,8 @@ struct LLVMTextureCompiler : public LLVMCompilerBase {
llvm::Type *get_argument_type(const TypeSpec *spec) const;
llvm::Type *get_return_type(const TypeSpec *spec) const;
- void append_input_types(std::vector<llvm::Type*> ¶ms,
- const TypeSpec *spec, bool is_constant) const;
- void append_output_types(std::vector<llvm::Type*> ¶ms, const
TypeSpec *spec) const;
+ void append_input_types(FunctionParameterList ¶ms, const NodeInput
*input) const;
+ void append_output_types(FunctionParameterList ¶ms, const
NodeOutput *output) const;
llvm::Module *get_nodes_module() const { return m_nodes_module; }
diff --git a/source/blender/blenvm/llvm/llvm_compiler_dual.cc
b/source/blender/blenvm/llvm/llvm_compiler_dual.cc
index 1919017..393d7fb 100644
--- a/source/blender/blenvm/llvm/llvm_compiler_dual.cc
+++ b/source/blender/blenvm/llvm/llvm_compiler_dual.cc
@@ -200,31 +200,42 @@ llvm::Type *LLVMTextureCompiler::get_return_type(const
TypeSpec *spec) const
return bvm_get_llvm_type(context(), spec, true);
}
-void LLVMTextureCompiler::append_input_types(std::vector<llvm::Type*> ¶ms,
- const TypeSpec *spec, bool
is_constant) const
+void LLVMTextureCompiler::append_input_types(FunctionParameterList ¶ms,
const NodeInput *input) const
{
- llvm::Type *type = bvm_get_llvm_type(context(), spec, false);
+ using namespace llvm;
+
+ const TypeSpec *spec = input->typedesc.get_typespec();
+ bool is_constant = (input->value_type == INPUT_CONSTANT);
+ Type *type = bvm_get_llvm_type(context(), spec, false);
if (use_argument_pointer(spec, false))
type = type->getPointerTo();
- params.push_back(type);
if (!is_constant && bvm_type_has_dual_value(spec)) {
+ params.push_back(FunctionParameter(type, "V_" + input->name));
/* two derivatives */
- params.push_back(type);
- params.push_back(type);
+ params.push_back(FunctionParameter(type, "DX_" + input->name));
+ params.push_back(FunctionParameter(type, "DY_" + input->name));
+ }
+ else {
+ params.push_back(FunctionParameter(type, input->name));
}
}
-void LLVMTextureCompiler::append_output_types(std::vector<llvm::Type*>
¶ms, const TypeSpec *spec) const
+void LLVMTextureCompiler::append_output_types(FunctionParameterList ¶ms,
const NodeOutput *output) const
{
using namespace llvm;
+ const TypeSpec *spec = output->typedesc.get_typespec();
Type *type = bvm_get_llvm_type(context(), spec, false);
- params.push_back(type);
+
if (bvm_type_has_dual_value(spec)) {
+ params.push_back(FunctionParameter(type, "V_" + output->name));
/* two derivatives */
- params.push_back(type);
- params.push_back(type);
+ params.push_back(FunctionParameter(type, "DX_" + output->name));
+ params.push_back(FunctionParameter(type, "DY_" + output->name));
+ }
+ else {
+ params.push_back(FunctionParameter(type, output->name));
}
}
@@ -309,10 +320,11 @@ llvm::Function
*LLVMTextureCompiler::declare_elementary_node_function(
bool error = false;
- std::vector<
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs