[Bf-blender-cvs] [6151808f1bd] functions: initial if then else construct helper
Jacques Lucke
noreply at git.blender.org
Mon May 13 10:16:33 CEST 2019
Commit: 6151808f1bd10146cd25e7e4637f3bffe562be99
Author: Jacques Lucke
Date: Thu May 9 10:45:07 2019 +0200
Branches: functions
https://developer.blender.org/rB6151808f1bd10146cd25e7e4637f3bffe562be99
initial if then else construct helper
===================================================================
M source/blender/functions/backends/llvm/builder.cpp
M source/blender/functions/backends/llvm/builder.hpp
===================================================================
diff --git a/source/blender/functions/backends/llvm/builder.cpp b/source/blender/functions/backends/llvm/builder.cpp
index 87adc230bc5..30de07bacbe 100644
--- a/source/blender/functions/backends/llvm/builder.cpp
+++ b/source/blender/functions/backends/llvm/builder.cpp
@@ -169,4 +169,23 @@ llvm::BasicBlock *IRConstruct_IterationsLoop::finalize()
return m_loop.finalize(condition);
}
+/* If Then Else
+ ************************************/
+
+IRConstruct_IfThenElse CodeBuilder::CreateIfThenElse(llvm::Value *condition, std::string name)
+{
+ auto then_block = this->NewBlockInFunction(name + " Then");
+ auto else_block = this->NewBlockInFunction(name + " Else");
+ this->CreateCondBr(condition, then_block, else_block);
+ return IRConstruct_IfThenElse(CodeBuilder(then_block), CodeBuilder(else_block));
+}
+
+llvm::BasicBlock *IRConstruct_IfThenElse::finalize()
+{
+ auto after_block = m_then_builder.NewBlockInFunction("After If");
+ m_then_builder.CreateBr(after_block);
+ m_else_builder.CreateBr(after_block);
+ return after_block;
+}
+
} /* namespace FN */
diff --git a/source/blender/functions/backends/llvm/builder.hpp b/source/blender/functions/backends/llvm/builder.hpp
index 16d55f48ce9..bc97ec9a7fc 100644
--- a/source/blender/functions/backends/llvm/builder.hpp
+++ b/source/blender/functions/backends/llvm/builder.hpp
@@ -12,6 +12,7 @@ using LLVMValuesRef = ArrayRef<llvm::Value *>;
class LLVMTypeInfo;
class IRConstruct_ForLoop;
class IRConstruct_IterationsLoop;
+class IRConstruct_IfThenElse;
template<typename T> static llvm::ArrayRef<T> to_llvm_array_ref(const SmallVector<T> &vector)
{
@@ -394,6 +395,7 @@ class CodeBuilder {
IRConstruct_ForLoop CreateForLoop(std::string name = "");
IRConstruct_IterationsLoop CreateNIterationsLoop(llvm::Value *iterations, std::string name = "");
+ IRConstruct_IfThenElse CreateIfThenElse(llvm::Value *condition, std::string name = "");
};
class IRConstruct_ForLoop {
@@ -460,4 +462,28 @@ class IRConstruct_IterationsLoop {
llvm::BasicBlock *finalize();
};
+class IRConstruct_IfThenElse {
+ private:
+ CodeBuilder m_then_builder;
+ CodeBuilder m_else_builder;
+
+ public:
+ IRConstruct_IfThenElse(CodeBuilder then_builder, CodeBuilder else_builder)
+ : m_then_builder(then_builder), m_else_builder(else_builder)
+ {
+ }
+
+ CodeBuilder &then_builder()
+ {
+ return m_then_builder;
+ }
+
+ CodeBuilder &else_builder()
+ {
+ return m_else_builder;
+ }
+
+ llvm::BasicBlock *finalize();
+};
+
} /* namespace FN */
More information about the Bf-blender-cvs
mailing list