[Bf-blender-cvs] [cb158219e0d] functions: Generate LLVM IR for Mul and Sin
Jacques Lucke
noreply at git.blender.org
Fri Apr 5 18:44:08 CEST 2019
Commit: cb158219e0d25007527f041dfc5a8ff8d40b389a
Author: Jacques Lucke
Date: Fri Apr 5 18:44:01 2019 +0200
Branches: functions
https://developer.blender.org/rBcb158219e0d25007527f041dfc5a8ff8d40b389a
Generate LLVM IR for Mul and Sin
===================================================================
M source/blender/functions/backends/llvm/builder.hpp
M source/blender/functions/functions/scalar_math.cpp
===================================================================
diff --git a/source/blender/functions/backends/llvm/builder.hpp b/source/blender/functions/backends/llvm/builder.hpp
index ecd49d6158b..ca3cfcb698b 100644
--- a/source/blender/functions/backends/llvm/builder.hpp
+++ b/source/blender/functions/backends/llvm/builder.hpp
@@ -131,6 +131,11 @@ namespace FN {
return m_builder.CreateFAdd(a, b);
}
+ llvm::Value *CreateFMul(llvm::Value *a, llvm::Value *b)
+ {
+ return m_builder.CreateFMul(a, b);
+ }
+
llvm::Value *CreateAllocaBytes_VoidPtr(uint amount)
{
llvm::Type *size_type = this->getFixedSizeType(amount);
@@ -205,6 +210,13 @@ namespace FN {
{
return m_builder.CreateGEP(addr, index);
}
+
+ llvm::Value *CreateSin(llvm::Value *value)
+ {
+ auto *function = llvm::Intrinsic::getDeclaration(
+ this->getModule(), llvm::Intrinsic::sin, value->getType());
+ return m_builder.CreateCall(function, value);
+ }
};
} /* namespace FN */
\ No newline at end of file
diff --git a/source/blender/functions/functions/scalar_math.cpp b/source/blender/functions/functions/scalar_math.cpp
index cb0bc76b92d..71533aab758 100644
--- a/source/blender/functions/functions/scalar_math.cpp
+++ b/source/blender/functions/functions/scalar_math.cpp
@@ -73,10 +73,24 @@ namespace FN { namespace Functions {
}
};
+ class MultiplyFloatsGen : public LLVMBuildIRBody {
+ void build_ir(
+ CodeBuilder &builder,
+ CodeInterface &interface,
+ const BuildIRSettings &UNUSED(settings)) const override
+ {
+ auto output = builder.CreateFMul(
+ interface.get_input(0),
+ interface.get_input(1));
+ interface.set_output(0, output);
+ }
+ };
+
LAZY_INIT_REF__NO_ARG(SharedFunction, multiply_floats)
{
auto fn = get_math_function__two_inputs("Multiply Floats");
fn->add_body(new MultiplyFloats());
+ fn->add_body(new MultiplyFloatsGen());
return fn;
}
@@ -165,10 +179,22 @@ namespace FN { namespace Functions {
}
};
+ class SinFloatGen : public LLVMBuildIRBody {
+ void build_ir(
+ CodeBuilder &builder,
+ CodeInterface &interface,
+ const BuildIRSettings &UNUSED(settings)) const override
+ {
+ auto output = builder.CreateSin(interface.get_input(0));
+ interface.set_output(0, output);
+ }
+ };
+
LAZY_INIT_REF__NO_ARG(SharedFunction, sin_float)
{
auto fn = get_math_function__one_input("Sin");
fn->add_body(new SinFloat());
+ fn->add_body(new SinFloatGen());
return fn;
}
More information about the Bf-blender-cvs
mailing list