[Bf-blender-cvs] [468bba3d2ba] temp-llvm-testing: initial testing
Jacques Lucke
noreply at git.blender.org
Wed Dec 29 21:45:49 CET 2021
Commit: 468bba3d2ba391c8eeb6d1f8ce88b96623b97b3e
Author: Jacques Lucke
Date: Sat Nov 27 11:49:27 2021 +0100
Branches: temp-llvm-testing
https://developer.blender.org/rB468bba3d2ba391c8eeb6d1f8ce88b96623b97b3e
initial testing
===================================================================
M source/blender/functions/CMakeLists.txt
A source/blender/functions/FN_llvm.hh
A source/blender/functions/intern/llvm.cc
M source/blender/modifiers/intern/MOD_nodes.cc
===================================================================
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 63c11164275..041e3f750e4 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -24,6 +24,7 @@ set(INC
)
set(INC_SYS
+ ${LLVM_INCLUDE_DIRS}
)
set(SRC
@@ -32,6 +33,7 @@ set(SRC
intern/generic_vector_array.cc
intern/generic_virtual_array.cc
intern/generic_virtual_vector_array.cc
+ intern/llvm.cc
intern/multi_function.cc
intern/multi_function_builder.cc
intern/multi_function_params.cc
@@ -50,6 +52,7 @@ set(SRC
FN_generic_vector_array.hh
FN_generic_virtual_array.hh
FN_generic_virtual_vector_array.hh
+ FN_llvm.hh
FN_multi_function.hh
FN_multi_function_builder.hh
FN_multi_function_context.hh
@@ -64,6 +67,7 @@ set(SRC
set(LIB
bf_blenlib
+ ${LLVM_LIBS}
)
if(WITH_TBB)
diff --git a/source/blender/functions/FN_llvm.hh b/source/blender/functions/FN_llvm.hh
new file mode 100644
index 00000000000..2d02af906b0
--- /dev/null
+++ b/source/blender/functions/FN_llvm.hh
@@ -0,0 +1,23 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+namespace blender::fn {
+
+void playground();
+
+}
diff --git a/source/blender/functions/intern/llvm.cc b/source/blender/functions/intern/llvm.cc
new file mode 100644
index 00000000000..5ac9e2a406d
--- /dev/null
+++ b/source/blender/functions/intern/llvm.cc
@@ -0,0 +1,64 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <iostream>
+
+#include <llvm/ExecutionEngine/ExecutionEngine.h>
+#include <llvm/IR/IRBuilder.h>
+#include <llvm/IR/LLVMContext.h>
+#include <llvm/IR/Type.h>
+#include <llvm/IR/Verifier.h>
+#include <llvm/Support/TargetSelect.h>
+
+#include "FN_llvm.hh"
+
+#include "BLI_vector.hh"
+
+namespace blender::fn {
+
+void playground()
+{
+ llvm::InitializeNativeTarget();
+ llvm::InitializeNativeTargetAsmPrinter();
+ llvm::InitializeNativeTargetAsmParser();
+
+ llvm::LLVMContext context;
+ std::unique_ptr<llvm::Module> module = std::make_unique<llvm::Module>("My Module", context);
+
+ llvm::Type *ret_type = llvm::Type::getInt32Ty(context);
+ llvm::FunctionType *function_type = llvm::FunctionType::get(ret_type, false);
+ llvm::Function *function = llvm::Function::Create(
+ function_type, llvm::GlobalValue::LinkageTypes::ExternalLinkage, "My Func", *module);
+ llvm::BasicBlock *bb = llvm::BasicBlock::Create(context, "entry", function);
+ llvm::IRBuilder<> builder{bb};
+ llvm::Value *value = builder.getInt32(42);
+ builder.CreateRet(value);
+
+ BLI_assert(llvm::verifyModule(*module, &llvm::outs()));
+
+ llvm::ExecutionEngine *ee = llvm::EngineBuilder(std::move(module)).create();
+ ee->finalizeObject();
+
+ const uint64_t function_ptr = ee->getFunctionAddress(function->getName().str());
+ using FuncType = int (*)();
+ const FuncType generated_function = (FuncType)function_ptr;
+ const int result = generated_function();
+ std::cout << result << "\n";
+
+ // function->dump();
+}
+
+} // namespace blender::fn
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index 05e9bd7d233..8130d97804f 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -99,6 +99,7 @@
#include "FN_field.hh"
#include "FN_field_cpp_type.hh"
+#include "FN_llvm.hh"
#include "FN_multi_function.hh"
using blender::Array;
@@ -1079,6 +1080,7 @@ static void modifyGeometry(ModifierData *md,
const ModifierEvalContext *ctx,
GeometrySet &geometry_set)
{
+ blender::fn::playground();
NodesModifierData *nmd = reinterpret_cast<NodesModifierData *>(md);
if (nmd->node_group == nullptr) {
return;
More information about the Bf-blender-cvs
mailing list