Commit: 926bdb8a055f4bde6026043d2fee5c3390bf819b
Author: Lukas Tönne
Date:   Tue May 31 10:09:35 2016 +0200
Branches: object_nodes
https://developer.blender.org/rB926bdb8a055f4bde6026043d2fee5c3390bf819b

Removed the WITH_IRMODULES option, used previously for loading IR code from 
text files.

This approach suffers from difficulty of generating machine-independent IR code
and is better generated using the C++ API directly. The llc tool can be used to 
suggest
implementations with C++ API usage, see for example
http://fdiv.net/2012/11/16/llvm-generates-code-that-generates-code

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

M       CMakeLists.txt
M       source/blender/blenvm/CMakeLists.txt
M       source/blender/blenvm/llvm/CMakeLists.txt
M       source/blender/blenvm/llvm/llvm_compiler.cc
M       source/blender/blenvm/llvm/llvm_compiler_dual.cc
M       source/blender/blenvm/llvm/llvm_engine.cc
M       source/blender/blenvm/llvm/llvm_modules.cc
M       source/blender/blenvm/llvm/llvm_modules.h

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

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 104e957..2b40b92 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -232,8 +232,6 @@ option(WITH_GAMEENGINE    "Enable Game Engine" 
${_init_GAMEENGINE})
 option(WITH_PLAYER        "Build Player" OFF)
 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" 
${_init_OPENCOLORIO})
 
-option(WITH_BLENVM_IRMODULES   "Enable LLVM IR module compilation" OFF)
-
 # Compositor
 option(WITH_COMPOSITOR         "Enable the tile based nodal compositor" ON)
 
diff --git a/source/blender/blenvm/CMakeLists.txt 
b/source/blender/blenvm/CMakeLists.txt
index e2d4e77..9b264a5 100644
--- a/source/blender/blenvm/CMakeLists.txt
+++ b/source/blender/blenvm/CMakeLists.txt
@@ -49,6 +49,14 @@ set(SRC
        intern/function_cache.cc
        intern/function_cache.h
 
+       modules/modules.cc
+       modules/modules.h
+       modules/mod_defines.h
+       modules/mod_base.h
+       modules/mod_color.h
+       modules/mod_math.h
+       modules/mod_texture.h
+
        util/util_opcode.h
        util/util_data_ptr.h
        util/util_debug.h
@@ -63,6 +71,11 @@ set(SRC
        BVM_types.h
 )
 
+add_definitions(
+       -DBVM_MOD_NAMESPACE_BEGIN=namespace\ blenvm\ {\ namespace\ modules\ {
+       -DBVM_MOD_NAMESPACE_END=}}
+)
+
 TEST_UNORDERED_MAP_SUPPORT()
 if(HAVE_STD_UNORDERED_MAP_HEADER)
        if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
diff --git a/source/blender/blenvm/llvm/CMakeLists.txt 
b/source/blender/blenvm/llvm/CMakeLists.txt
index 8f9f15d..cff2c8d 100644
--- a/source/blender/blenvm/llvm/CMakeLists.txt
+++ b/source/blender/blenvm/llvm/CMakeLists.txt
@@ -57,79 +57,8 @@ set(SRC
        llvm_types.h
 )
 
-set(LLVM_SRC
-       ../modules/modules.cc
-       ../modules/modules.h
-       ../modules/mod_defines.h
-
-       ../modules/mod_base.h
-       ../modules/mod_color.h
-       ../modules/mod_math.h
-       ../modules/mod_texture.h
-)
-set(LLVM_HEADERS
-       ../modules/mod_base.h
-       ../modules/mod_color.h
-       ../modules/mod_math.h
-       ../modules/mod_texture.h
-)
-
-if(NOT WITH_BLENVM_IRMODULES)
-       list(APPEND SRC ${LLVM_SRC})
-endif()
-
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${RTTI_DISABLE_FLAGS}")
 
 add_definitions(-DWITH_LLVM -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS 
-std=c++0x)
-add_definitions(
-       -DBVM_MOD_NAMESPACE_BEGIN=namespace\ blenvm\ {\ namespace\ modules\ {
-       -DBVM_MOD_NAMESPACE_END=}}
-)
 
 blender_add_lib(bf_blenvm_llvm "${SRC}" "${INC}" "${INC_SYS}")
-
-
-# Modules
-
-if(WITH_BLENVM_IRMODULES)
-       # XXX TODO
-       set(LLVM_IR_COMPILER "clang-3.5")
-       set(LLVM_IR_INSTALL_PATH "scripts/llvm")
-       set(llvm_irs)
-
-       macro(BLENVM_LLVM_MODULE_ADD src)
-               get_filename_component(llvm_name ${src} NAME_WE)
-               set(llvm_ir "${llvm_name}.ll")
-
-               add_custom_command(
-                       OUTPUT ${llvm_ir}
-                       COMMAND ${LLVM_IR_COMPILER}
-                                       -S
-                                       ${CMAKE_CURRENT_SOURCE_DIR}/${src}
-                                       -emit-llvm
-                                       -std=c++0x
-                                       -o 
${CMAKE_CURRENT_BINARY_DIR}/${llvm_ir}
-                                       -DBLENVM_RUNTIME
-                                       -D__STDC_CONSTANT_MACROS 
-D__STDC_LIMIT_MACROS
-                                       -DBVM_MOD_NAMESPACE_BEGIN
-                                       -DBVM_MOD_NAMESPACE_END
-                                       -DBVM_MOD_ANNOTATE_FUNCTIONS
-                                       
-I${CMAKE_CURRENT_SOURCE_DIR}/../../blenlib
-                       DEPENDS ${LLVM_SRC})
-       
-               delayed_install("${CMAKE_CURRENT_BINARY_DIR}" "${llvm_ir}" 
${LLVM_IR_INSTALL_PATH}/modules/)
-               list(APPEND llvm_irs ${llvm_ir})
-       endmacro()
-
-       add_definitions(-DWITH_BLENVM_IRMODULES)
-
-       foreach(src ${LLVM_SRC})
-               # Compile LLVM IR code
-               BLENVM_LLVM_MODULE_ADD(${src})
-       endforeach()
-
-       add_custom_target(bf_blenvm_llvm_modules ALL DEPENDS ${llvm_irs})
-       add_dependencies(bf_blenvm_llvm bf_blenvm_llvm_modules)
-
-       delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${LLVM_HEADERS}" 
${LLVM_IR_INSTALL_PATH})
-endif()
diff --git a/source/blender/blenvm/llvm/llvm_compiler.cc 
b/source/blender/blenvm/llvm/llvm_compiler.cc
index 431cfad..432cb43 100644
--- a/source/blender/blenvm/llvm/llvm_compiler.cc
+++ b/source/blender/blenvm/llvm/llvm_compiler.cc
@@ -272,8 +272,7 @@ void 
LLVMCompilerBase::expand_function_node(llvm::BasicBlock *block, const NodeI
        builder.SetInsertPoint(block);
        
        /* get evaluation function */
-       const std::string &evalname = node->type->name();
-       Function *evalfunc = llvm_find_external_function(module(), evalname);
+       Function *evalfunc = module()->getFunction(node->type->name());
        BLI_assert(evalfunc != NULL && "Could not find node function!");
        
        /* function call arguments */
diff --git a/source/blender/blenvm/llvm/llvm_compiler_dual.cc 
b/source/blender/blenvm/llvm/llvm_compiler_dual.cc
index 393d7fb..3352339 100644
--- a/source/blender/blenvm/llvm/llvm_compiler_dual.cc
+++ b/source/blender/blenvm/llvm/llvm_compiler_dual.cc
@@ -441,12 +441,10 @@ void 
LLVMTextureCompiler::define_dual_function_wrapper(llvm::Module *mod, OpCode
        using namespace llvm;
        
        /* get evaluation function(s) */
-       string value_name = bvm_value_function_name(nodetype->name());
-       Function *value_func = llvm_find_external_function(mod, value_name);
+       Function *value_func = 
mod->getFunction(bvm_value_function_name(nodetype->name()));
        BLI_assert(value_func != NULL && "Could not find node function!");
        
-       string deriv_name = bvm_deriv_function_name(nodetype->name());
-       Function *deriv_func = llvm_find_external_function(mod, deriv_name);
+       Function *deriv_func = 
mod->getFunction(bvm_deriv_function_name(nodetype->name()));
        
        /* wrapper function */
        Function *func = declare_node_function(mod, nodetype);
diff --git a/source/blender/blenvm/llvm/llvm_engine.cc 
b/source/blender/blenvm/llvm/llvm_engine.cc
index 976af9e..1228c94 100644
--- a/source/blender/blenvm/llvm/llvm_engine.cc
+++ b/source/blender/blenvm/llvm/llvm_engine.cc
@@ -141,15 +141,10 @@ void llvm_init()
        
        BLI_assert(theEngine == NULL);
        theEngine = create_execution_engine();
-       
-       /* load modules */
-       llvm_load_all_modules("", false);
 }
 
 void llvm_free()
 {
-       llvm_unload_all_modules();
-       
        if (theEngine) {
                delete theEngine;
                theEngine = NULL;
diff --git a/source/blender/blenvm/llvm/llvm_modules.cc 
b/source/blender/blenvm/llvm/llvm_modules.cc
index f99ec6d..03d2170 100644
--- a/source/blender/blenvm/llvm/llvm_modules.cc
+++ b/source/blender/blenvm/llvm/llvm_modules.cc
@@ -56,155 +56,6 @@ extern "C" {
 
 namespace blenvm {
 
-typedef std::map<string, llvm::Module*> ModuleMap;
-
-static ModuleMap theModules;
-
-#ifdef WITH_BLENVM_IRMODULES
-/* Based on
- * http://homes.cs.washington.edu/~bholt/posts/llvm-quick-tricks.html
- */
-static void llvm_parse_function_annotations(llvm::Module *mod)
-{
-       using namespace llvm;
-       
-       GlobalVariable *global_annos = 
mod->getNamedGlobal("llvm.global.annotations");
-       if (global_annos) {
-               ConstantArray *a = 
static_cast<ConstantArray*>(global_annos->getOperand(0));
-               for (int i = 0; i < a->getNumOperands(); i++) {
-                       ConstantStruct *e = 
static_cast<ConstantStruct*>(a->getOperand(i));
-                       StringRef anno = 
static_cast<ConstantDataArray*>(static_cast<GlobalVariable*>(e->getOperand(1)->getOperand(0))->getOperand(0))->getAsCString();
-                       
-                       if (e->getOperand(0)->getOperand(0)->getValueID() == 
Value::FunctionVal) {
-                               Function *fn = 
static_cast<Function*>(e->getOperand(0)->getOperand(0));
-                               fn->addFnAttr("name", anno); /* add function 
annotation */
-                       }
-               }
-       }
-}
-
-static bool llvm_function_has_external_name(const llvm::Function *func)
-{
-       return func->hasFnAttribute("name");
-}
-
-static string llvm_function_get_external_name(const llvm::Function *func)
-{
-       if (func->hasFnAttribute("name"))
-               return func->getFnAttribute("name").getValueAsString().str();
-       else
-               return func->getName().str();
-}
-#endif
-
-llvm::Function *llvm_find_external_function(llvm::Module *mod, const string 
&name)
-{
-       using namespace llvm;
-       
-#ifdef WITH_BLENVM_IRMODULES
-       for (Module::FunctionListType::iterator it = 
mod->getFunctionList().begin(); it != mod->getFunctionList().end(); ++it) {
-               Function *func = &(*it);
-               if (func->hasFnAttribute("name")) {
-                       std::string value = 
func->getFnAttribute("name").getValueAsString();
-                       if (value == name)
-                               return func;
-               }
-       }
-#else
-       return mod->getFunction(name);
-#endif
-       
-       return NULL;
-}
-
-void llvm_load_module(const string &modfile, const string &modname)
-{
-       using namespace llvm;
-       
-#ifdef WITH_BLENVM_IRMODULES
-       printf("Loading module '%s'\n", modfile.c_str());
-       LLVMContext &llvmctx = getGlobalContext();
-       SMDiagnostic err;
-       
-       Module *mod = getLazyIRFileModule(modfile, err, llvmctx);
-//     Module *mod = ParseIRFile(modfile, err, llvmctx);
-       if (!mod) {
-               err.print(modfile.c_str(), errs());
-               return;
-       }
-       
-       llvm_parse_function_annotations(mod);
-       mod->setModuleIdentifier(modname);
-       
-       verifyModule(*mod, &outs());
-       
-       llvm_execution_engine()->addModule(mod);
-       theModules[mod->getModuleIdentifier()] = mod;
-       
-       printf("Module Functions for '%s'\n", 
mod->getModuleIdentifier().c_str());
-       for (Module::FunctionListType::const_iterator it = 
mod->getFunctionList().begin(); it != mod->getFunctionList().end(); ++it) {
-               const Function &func = *it;
-               
-               if (!llvm_function_has_external_name(&func))
-                       continue;
-               printf("    %s\n", 
llvm_function_get_external_name(&func).c_str());
-               
-//             printf("    %s\n", func.getName().str().c_str());
-               
-//             func.dump();
-//             printf("++++++++++++++++++++++++++++++++++\n");
-       }
-#else
-       UNUSED_VARS(modfile, modname);
-#endif
-}
-
-void llvm_load_all_modules(const string &modpath, bool reload)
-{
-       using namespace llvm;
-       
-       if (reload) {
-               llvm_unload_all_modules();
-       }
-       
-#ifdef WITH_BLENVM_IRMODULES
-       string path = modpath;
-       if (path.empty()) {
-               const char *moddir = 
BKE_appdir_folder_id(BLENDER_SYSTEM_SCRIPTS, "llvm/modules/");
-               path = (moddir != NULL ? string(moddir) : "");
-       }
-       if (path.empty())
-               return;
-       
-       struct direntry *dir;
-       int totfile = BLI_filelist_dir_contents(path.c_str(), &dir);
-       for (int i = 0; i < totfile; ++i) {
-               if ((dir[i].type & S_IFREG)) {
-                       const char *filename = dir[i].relname;
-                       const char *filepath = dir[i].path;
-                       
-                       if (BLI_testextensie(filename, ".ll")) {
-                               /* found a potential llvm IR module, try 
parsing it */
-                               llvm_load_module(filepath, filename);
-                       }
-               }
-       }
-       BLI_filelist_free(dir, totfile);
-#else
-       UNUSED_VARS(modpath);
-#endif
-}
-
-void llvm_unload_all_modules()
-{
-       using namespace llvm;
-       
-       // TODO
-       theModules.clear();
-}
-
-/* ------------------------------------------------------------------------- */
-
 void def_

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to