[Bf-blender-cvs] [fd6a3c8] object_nodes: Generate dual values for input constants to match the declared function signatures.
Lukas Tönne
noreply at git.blender.org
Fri May 20 08:02:10 CEST 2016
Commit: fd6a3c863fdde03713d03ac5d2895f9f185cb3f5
Author: Lukas Tönne
Date: Fri May 20 08:00:38 2016 +0200
Branches: object_nodes
https://developer.blender.org/rBfd6a3c863fdde03713d03ac5d2895f9f185cb3f5
Generate dual values for input constants to match the declared function signatures.
Note that actual functions currently don't use Dual2<> values, but because they
only read/write the 'value' field it works anyway ...
===================================================================
M source/blender/blenvm/llvm/llvm_codegen.cc
M source/blender/blenvm/llvm/llvm_codegen.h
M source/blender/blenvm/llvm/llvm_types.h
M source/blender/blenvm/util/util_math.h
===================================================================
diff --git a/source/blender/blenvm/llvm/llvm_codegen.cc b/source/blender/blenvm/llvm/llvm_codegen.cc
index a6d4694..ec211bd 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.cc
+++ b/source/blender/blenvm/llvm/llvm_codegen.cc
@@ -89,82 +89,6 @@ void LLVMCompilerBase::destroy_module()
m_module = NULL;
}
-llvm::Constant *LLVMCompilerBase::codegen_constant(const NodeValue *node_value)
-{
- using namespace llvm;
-
- const TypeSpec *typespec = node_value->typedesc().get_typespec();
- if (typespec->is_structure()) {
-// const StructSpec *s = typespec->structure();
- /* TODO don't have value storage for this yet */
- return NULL;
- }
- else {
- switch (typespec->base_type()) {
- case BVM_FLOAT: {
- float f = 0.0f;
- node_value->get(&f);
- return ConstantFP::get(context(), APFloat(f));
- }
- case BVM_FLOAT3: {
- StructType *stype = TypeBuilder<float3, true>::get(context());
-
- float3 f = float3(0.0f, 0.0f, 0.0f);
- node_value->get(&f);
- return ConstantStruct::get(stype,
- ConstantFP::get(context(), APFloat(f.x)),
- ConstantFP::get(context(), APFloat(f.y)),
- ConstantFP::get(context(), APFloat(f.z)),
- NULL);
- }
- case BVM_FLOAT4: {
- StructType *stype = TypeBuilder<float4, true>::get(context());
-
- float4 f = float4(0.0f, 0.0f, 0.0f, 0.0f);
- node_value->get(&f);
- return ConstantStruct::get(stype,
- ConstantFP::get(context(), APFloat(f.x)),
- ConstantFP::get(context(), APFloat(f.y)),
- ConstantFP::get(context(), APFloat(f.z)),
- ConstantFP::get(context(), APFloat(f.w)),
- NULL);
- }
- case BVM_INT: {
- int i = 0;
- node_value->get(&i);
- return ConstantInt::get(context(), APInt(32, i, true));
- }
- case BVM_MATRIX44: {
- Type *elem_t = TypeBuilder<types::ieee_float, true>::get(context());
- ArrayType *inner_t = ArrayType::get(elem_t, 4);
- ArrayType *outer_t = ArrayType::get(inner_t, 4);
- StructType *matrix_t = StructType::get(outer_t, NULL);
-
- matrix44 m = matrix44::identity();
- node_value->get(&m);
- Constant *constants[4][4];
- for (int i = 0; i < 4; ++i)
- for (int j = 0; j < 4; ++j)
- constants[i][j] = ConstantFP::get(context(), APFloat(m.data[i][j]));
- Constant *cols[4];
- for (int i = 0; i < 4; ++i)
- cols[i] = ConstantArray::get(inner_t, ArrayRef<Constant*>(constants[i], 4));
- Constant *data = ConstantArray::get(outer_t, ArrayRef<Constant*>(cols, 4));
- return ConstantStruct::get(matrix_t,
- data, NULL);
- }
-
- case BVM_STRING:
- case BVM_RNAPOINTER:
- case BVM_MESH:
- case BVM_DUPLIS:
- /* TODO */
- return NULL;
- }
- }
- return NULL;
-}
-
void LLVMCompilerBase::codegen_node(llvm::BasicBlock *block,
const NodeInstance *node)
{
@@ -321,6 +245,24 @@ void LLVMCompilerBase::optimize_function(llvm::Function *func, int opt_level)
FPM.run(*func);
}
+void LLVMCompilerBase::map_argument(llvm::BasicBlock *block, const OutputKey &output, llvm::Argument *arg)
+{
+ m_output_values[output] = arg;
+ UNUSED_VARS(block);
+}
+
+void LLVMCompilerBase::store_return_value(llvm::BasicBlock *block, const OutputKey &output, llvm::Value *arg)
+{
+ using namespace llvm;
+
+ IRBuilder<> builder(context());
+ builder.SetInsertPoint(block);
+
+ Value *value = m_output_values.at(output);
+ Value *rvalue = builder.CreateLoad(value);
+ builder.CreateStore(rvalue, arg);
+}
+
void LLVMCompilerBase::expand_pass_node(llvm::BasicBlock *block, const NodeInstance *node)
{
using namespace llvm;
@@ -389,7 +331,7 @@ void LLVMCompilerBase::expand_function_node(llvm::BasicBlock *block, const NodeI
switch (input.value_type()) {
case INPUT_CONSTANT: {
/* create storage for the global value */
- Constant *cvalue = codegen_constant(input.value());
+ Constant *cvalue = create_node_value_constant(input.value());
Value *value;
if (use_argument_pointer(typespec)) {
@@ -429,24 +371,6 @@ void LLVMCompilerBase::expand_function_node(llvm::BasicBlock *block, const NodeI
UNUSED_VARS(call);
}
-void LLVMCompilerBase::map_argument(llvm::BasicBlock *block, const OutputKey &output, llvm::Argument *arg)
-{
- m_output_values[output] = arg;
- UNUSED_VARS(block);
-}
-
-void LLVMCompilerBase::store_return_value(llvm::BasicBlock *block, const OutputKey &output, llvm::Value *arg)
-{
- using namespace llvm;
-
- IRBuilder<> builder(context());
- builder.SetInsertPoint(block);
-
- Value *value = m_output_values.at(output);
- Value *rvalue = builder.CreateLoad(value);
- builder.CreateStore(rvalue, arg);
-}
-
llvm::StructType *LLVMCompilerBase::create_struct_type(const string &name, const StructSpec *spec)
{
using namespace llvm;
@@ -689,6 +613,55 @@ bool LLVMSimpleCompilerImpl::use_argument_pointer(const TypeSpec *typespec)
return false;
}
+llvm::Constant *LLVMSimpleCompilerImpl::create_node_value_constant(const NodeValue *node_value)
+{
+ using namespace llvm;
+
+ const TypeSpec *typespec = node_value->typedesc().get_typespec();
+ if (typespec->is_structure()) {
+// const StructSpec *s = typespec->structure();
+ /* TODO don't have value storage for this yet */
+ return NULL;
+ }
+ else {
+ switch (typespec->base_type()) {
+ case BVM_FLOAT: {
+ float f = 0.0f;
+ node_value->get(&f);
+ return make_constant(context(), f);
+ }
+ case BVM_FLOAT3: {
+ float3 f = float3(0.0f, 0.0f, 0.0f);
+ node_value->get(&f);
+ return make_constant(context(), f);
+ }
+ case BVM_FLOAT4: {
+ float4 f = float4(0.0f, 0.0f, 0.0f, 0.0f);
+ node_value->get(&f);
+ return make_constant(context(), f);
+ }
+ case BVM_INT: {
+ int i = 0;
+ node_value->get(&i);
+ return make_constant(context(), i);
+ }
+ case BVM_MATRIX44: {
+ matrix44 m = matrix44::identity();
+ node_value->get(&m);
+ return make_constant(context(), m);
+ }
+
+ case BVM_STRING:
+ case BVM_RNAPOINTER:
+ case BVM_MESH:
+ case BVM_DUPLIS:
+ /* TODO */
+ return NULL;
+ }
+ }
+ return NULL;
+}
+
/* ------------------------------------------------------------------------- */
llvm::Module *LLVMTextureCompilerImpl::m_nodes_module = NULL;
@@ -703,11 +676,11 @@ llvm::Type *LLVMTextureCompilerImpl::create_value_type(const string &name, const
else {
switch (spec->base_type()) {
case BVM_FLOAT:
- return TypeBuilder<types::ieee_float, true>::get(context());
+ return TypeBuilder<Dual2<types::ieee_float>, true>::get(context());
case BVM_FLOAT3:
- return TypeBuilder<float3, true>::get(context());
+ return TypeBuilder<Dual2<float3>, true>::get(context());
case BVM_FLOAT4:
- return TypeBuilder<float4, true>::get(context());
+ return TypeBuilder<Dual2<float4>, true>::get(context());
case BVM_INT:
return TypeBuilder<types::i<32>, true>::get(context());
case BVM_MATRIX44:
@@ -756,6 +729,55 @@ bool LLVMTextureCompilerImpl::use_argument_pointer(const TypeSpec *typespec)
return false;
}
+llvm::Constant *LLVMTextureCompilerImpl::create_node_value_constant(const NodeValue *node_value)
+{
+ using namespace llvm;
+
+ const TypeSpec *typespec = node_value->typedesc().get_typespec();
+ if (typespec->is_structure()) {
+// const StructSpec *s = typespec->structure();
+ /* TODO don't have value storage for this yet */
+ return NULL;
+ }
+ else {
+ switch (typespec->base_type()) {
+ case BVM_FLOAT: {
+ float f = 0.0f;
+ node_value->get(&f);
+ return make_constant(context(), Dual2<float>(f));
+ }
+ case BVM_FLOAT3: {
+ float3 f = float3(0.0f, 0.0f, 0.0f);
+ node_value->get(&f);
+ return make_constant(context(), Dual2<float3>(f));
+ }
+ case BVM_FLOAT4: {
+ float4 f = float4(0.0f, 0.0f, 0.0f, 0.0f);
+ node_value->get(&f);
+ return make_constant(context(), Dual2<float4>(f));
+ }
+ case BVM_INT: {
+ int i = 0;
+ node_value->get(&i);
+ return make_constant(context(), i);
+ }
+ case BVM_MATRIX44: {
+ matrix44 m = matrix44::identity();
+ node_value->get(&m);
+ return make_constant(context(), m);
+ }
+
+ case BVM_STRING:
+ case BVM_RNAPOINTER:
+ case BVM_MESH:
+ case BVM_DUPLIS:
+ /* TODO */
+ return NULL;
+ }
+ }
+ return NULL;
+}
+
/* ------------------------------------------------------------------------- */
FunctionLLVM *LLVMCompiler::compile_function(const string &name, const NodeGraph &graph, int opt_level)
diff --git a/source/blender/blenvm/llvm/llvm_codegen.h b/source/blender/blenvm/llvm/llvm_codegen.h
index 899b714..09da6f6 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.h
+++ b/source/blender/blenvm/llvm/llvm_codegen.h
@@ -41,6 +41,7 @@
#include "util_opcode.h"
#include "util_string.h"
+#include "util_math.h"
namespace llvm {
class LLVMContext;
@@ -79,8 +80,6 @@ protected:
void optimize_function(llvm::Function *func, int opt_level);
- llvm::Constant *codegen_constant(const NodeValue *node_value);
-
void codegen_node(llvm::BasicBlock *block,
const NodeInstance *node);
@@ -100,6 +99,8 @@ protected:
virtual llvm::FunctionType *create_node_function_type(const std::vector<llvm::Type*> &inputs,
const std::vector<llvm::Type*> &outputs);
virtual bool use_argument_pointer(const TypeSpec *typespec) = 0;
+
+ virtual llvm::Constant *create_node_value_constant(const NodeValue *node_value) = 0;
void define_node_function(llvm::Module *mod, OpCode op, const NodeType *nodetype, void *funcptr);
llvm::Module *define_nodes_module();
@@ -120,6 +121,8 @@ struct LLVMSimpleCompilerImpl : public LLVMCompilerBase {
bool use_argument_pointer(const TypeSpec *typespec);
+ llvm::Constant *create_node_value_constant(const NodeValue *node_value);
+
private:
static llvm::Module *m_nodes_module;
};
@@ -132,6 +135,8 @@ struct LLVMTextureCompilerImpl : public LLVMCompilerBase {
bool use_argument_pointer(const TypeSpec *typespec)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list