Commit: 13a84fcb330841393cda92211f5c48f07683cfb2
Author: Lukas Tönne
Date:   Tue Jun 21 16:50:04 2016 +0200
Branches: object_nodes
https://developer.blender.org/rB13a84fcb330841393cda92211f5c48f07683cfb2

Define names for most values in generated LLVM code.

These are purely for debugging the code, they help a lot in reading
LLVM dumps.

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

M       source/blender/blenvm/bvm/bvm_codegen.cc
M       source/blender/blenvm/bvm/bvm_codegen.h
M       source/blender/blenvm/compile/compiler.cc
M       source/blender/blenvm/compile/compiler.h
M       source/blender/blenvm/llvm/llvm_codegen.cc
M       source/blender/blenvm/llvm/llvm_codegen.h

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

diff --git a/source/blender/blenvm/bvm/bvm_codegen.cc 
b/source/blender/blenvm/bvm/bvm_codegen.cc
index efba057..369f2db 100644
--- a/source/blender/blenvm/bvm/bvm_codegen.cc
+++ b/source/blender/blenvm/bvm/bvm_codegen.cc
@@ -127,7 +127,7 @@ Value *BVMCodeGenerator::create_value(const TypeSpec 
*typespec)
        return value;
 }
 
-ValueHandle BVMCodeGenerator::alloc_node_value(const TypeSpec *typespec)
+ValueHandle BVMCodeGenerator::alloc_node_value(const TypeSpec *typespec, const 
string &UNUSED(name))
 {
        Value *value = create_value(typespec);
        ValueHandle handle = get_handle(value);
diff --git a/source/blender/blenvm/bvm/bvm_codegen.h 
b/source/blender/blenvm/bvm/bvm_codegen.h
index b6fa88a..d048e7a 100644
--- a/source/blender/blenvm/bvm/bvm_codegen.h
+++ b/source/blender/blenvm/bvm/bvm_codegen.h
@@ -84,7 +84,7 @@ struct BVMCodeGenerator : public CodeGenerator {
        void store_return_value(size_t output_index, const TypeSpec *typespec, 
ValueHandle value);
        ValueHandle map_argument(size_t input_index, const TypeSpec *typespec);
        
-       ValueHandle alloc_node_value(const TypeSpec *typespec);
+       ValueHandle alloc_node_value(const TypeSpec *typespec, const string 
&name);
        ValueHandle create_constant(const TypeSpec *typespec, const 
NodeConstant *node_value);
        
        void eval_node(const NodeType *nodetype,
diff --git a/source/blender/blenvm/compile/compiler.cc 
b/source/blender/blenvm/compile/compiler.cc
index 0d2a9b7..803c8e1 100644
--- a/source/blender/blenvm/compile/compiler.cc
+++ b/source/blender/blenvm/compile/compiler.cc
@@ -209,7 +209,8 @@ void Compiler::expand_expression_node(const NodeInstance 
*node, Scope &scope)
                ConstOutputKey output = node->output(i);
                const TypeSpec *typespec = 
output.socket->typedesc.get_typespec();
                
-               ValueHandle value = m_codegen->alloc_node_value(typespec);
+               ValueHandle value = m_codegen->alloc_node_value(typespec,
+                                                               
output.node->name + "__" + output.socket->name);
                output_args.push_back(value);
                
                scope.set_value(output, value);
diff --git a/source/blender/blenvm/compile/compiler.h 
b/source/blender/blenvm/compile/compiler.h
index 375c0bd..954bb71 100644
--- a/source/blender/blenvm/compile/compiler.h
+++ b/source/blender/blenvm/compile/compiler.h
@@ -78,7 +78,7 @@ struct CodeGenerator {
        virtual void store_return_value(size_t output_index, const TypeSpec 
*typespec, ValueHandle value) = 0;
        virtual ValueHandle map_argument(size_t input_index, const TypeSpec 
*typespec) = 0;
        
-       virtual ValueHandle alloc_node_value(const TypeSpec *typespec) = 0;
+       virtual ValueHandle alloc_node_value(const TypeSpec *typespec, const 
string &name) = 0;
        virtual ValueHandle create_constant(const TypeSpec *typespec, const 
NodeConstant *node_value) = 0;
 
        virtual void eval_node(const NodeType *nodetype,
diff --git a/source/blender/blenvm/llvm/llvm_codegen.cc 
b/source/blender/blenvm/llvm/llvm_codegen.cc
index 509eb07..fef7e7b 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.cc
+++ b/source/blender/blenvm/llvm/llvm_codegen.cc
@@ -29,6 +29,7 @@
  *  \ingroup llvm
  */
 
+#include <cctype>
 #include <cstdio>
 #include <set>
 #include <sstream>
@@ -76,6 +77,18 @@ class debug_assembly_annotation_writer : public 
llvm::AssemblyAnnotationWriter
 
 /* ------------------------------------------------------------------------- */
 
+/* replace non-alphanumeric chars with underscore */
+static string sanitize_name(const string &name)
+{
+       string s = name;
+       for (string::iterator it = s.begin(); it != s.end(); ++it) {
+               char &c = *it;
+               if (c != '_' && !isalnum(c))
+                       c = '_';
+       }
+       return s;
+}
+
 /* forward declaration */
 static llvm::Function *declare_graph_function(
         llvm::LLVMContext &context,
@@ -245,9 +258,9 @@ void LLVMCodeGenerator::store_return_value(size_t 
output_index, const TypeSpec *
        builder.SetInsertPoint(m_block);
        
        Argument *arg = m_output_args[output_index];
-       Value *value_ptr = builder.CreateStructGEP(arg, 0);
-       Value *dx_ptr = builder.CreateStructGEP(arg, 1);
-       Value *dy_ptr = builder.CreateStructGEP(arg, 2);
+       Value *value_ptr = builder.CreateStructGEP(arg, 0, 
sanitize_name(arg->getName().str() + "_V"));
+       Value *dx_ptr = builder.CreateStructGEP(arg, 1, 
sanitize_name(arg->getName().str() + "_DX"));
+       Value *dy_ptr = builder.CreateStructGEP(arg, 2, 
sanitize_name(arg->getName().str() + "_DY"));
        
        DualValue dual = m_values.at(handle);
        bvm_llvm_copy_value(context(), m_block, value_ptr, dual.value(), 
typespec);
@@ -266,9 +279,9 @@ ValueHandle LLVMCodeGenerator::map_argument(size_t 
input_index, const TypeSpec *
        DualValue dval;
        if (bvm_type_has_dual_value(typespec)) {
                /* argument is a struct, use GEP instructions to get the 
individual elements */
-               dval = DualValue(builder.CreateStructGEP(arg, 0),
-                                builder.CreateStructGEP(arg, 1),
-                                builder.CreateStructGEP(arg, 2));
+               dval = DualValue(builder.CreateStructGEP(arg, 0, 
sanitize_name(arg->getName().str() + "_V")),
+                                builder.CreateStructGEP(arg, 1, 
sanitize_name(arg->getName().str() + "_DX")),
+                                builder.CreateStructGEP(arg, 2, 
sanitize_name(arg->getName().str() + "_DY")));
        }
        else {
                dval = DualValue(arg, NULL, NULL);
@@ -282,7 +295,7 @@ ValueHandle LLVMCodeGenerator::map_argument(size_t 
input_index, const TypeSpec *
        return handle;
 }
 
-ValueHandle LLVMCodeGenerator::alloc_node_value(const TypeSpec *typespec)
+ValueHandle LLVMCodeGenerator::alloc_node_value(const TypeSpec *typespec, 
const string &name)
 {
        using namespace llvm;
        
@@ -292,9 +305,9 @@ ValueHandle LLVMCodeGenerator::alloc_node_value(const 
TypeSpec *typespec)
        Type *type = bvm_get_llvm_type(context(), typespec, false);
        BLI_assert(type != NULL);
        
-       DualValue dval(builder.CreateAlloca(type),
-                      builder.CreateAlloca(type),
-                      builder.CreateAlloca(type));
+       DualValue dval(builder.CreateAlloca(type, NULL, sanitize_name(name + 
"_V")),
+                      builder.CreateAlloca(type, NULL, sanitize_name(name + 
"_DX")),
+                      builder.CreateAlloca(type, NULL, sanitize_name(name + 
"_DY")));
        
        ValueHandle handle = get_handle(dval);
        bool ok = m_values.insert(HandleValueMap::value_type(handle, 
dval)).second;
@@ -463,7 +476,7 @@ static llvm::Function *declare_graph_function(
        
        Function::arg_iterator arg_it = func->arg_begin();
        for (int i = 0; arg_it != func->arg_end(); ++arg_it, ++i) {
-               arg_it->setName(arg_names[i]);
+               arg_it->setName(sanitize_name(arg_names[i]));
        }
        
        return func;
@@ -560,7 +573,7 @@ static llvm::Function *declare_node_function(
        
        Function::arg_iterator arg_it = func->arg_begin();
        for (int i = 0; arg_it != func->arg_end(); ++arg_it, ++i) {
-               arg_it->setName(arg_names[i]);
+               arg_it->setName(sanitize_name(arg_names[i]));
        }
        
        return func;
@@ -643,7 +656,7 @@ static llvm::Function *declare_elementary_node_function(
        
        Function::arg_iterator arg_it = func->arg_begin();
        for (int i = 0; arg_it != func->arg_end(); ++arg_it, ++i) {
-               arg_it->setName(arg_names[i]);
+               arg_it->setName(sanitize_name(arg_names[i]));
        }
        
        return func;
diff --git a/source/blender/blenvm/llvm/llvm_codegen.h 
b/source/blender/blenvm/llvm/llvm_codegen.h
index 5313610..0736d25 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.h
+++ b/source/blender/blenvm/llvm/llvm_codegen.h
@@ -87,7 +87,7 @@ struct LLVMCodeGenerator : public CodeGenerator {
        void store_return_value(size_t output_index, const TypeSpec *typespec, 
ValueHandle value);
        ValueHandle map_argument(size_t input_index, const TypeSpec *typespec);
        
-       ValueHandle alloc_node_value(const TypeSpec *typespec);
+       ValueHandle alloc_node_value(const TypeSpec *typespec, const string 
&name);
        ValueHandle create_constant(const TypeSpec *typespec, const 
NodeConstant *node_value);
        
        void eval_node(const NodeType *nodetype,

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

Reply via email to