[Bf-blender-cvs] [2c16ec4] object_nodes: Inlining of base node functions in LLVM IR code.

Lukas Tönne noreply at git.blender.org
Mon Apr 11 09:18:05 CEST 2016


Commit: 2c16ec47ed4fab412fe9b70e961d5928919c49be
Author: Lukas Tönne
Date:   Mon Apr 11 09:16:05 2016 +0200
Branches: object_nodes
https://developer.blender.org/rB2c16ec47ed4fab412fe9b70e961d5928919c49be

Inlining of base node functions in LLVM IR code.

This requires a somewhat hackish stub function to force linking of inlined
functions in the modules, so that clang doesn't just omit them when
producing IR code. Not very nice, but also not directly related to the
actual Blender code.

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

M	source/blender/blenvm/llvm/llvm_codegen.cc
M	source/blender/blenvm/llvm/llvm_headers.h
M	source/blender/blenvm/modules/mod_value.cc
M	source/blender/blenvm/modules/mod_value.h

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

diff --git a/source/blender/blenvm/llvm/llvm_codegen.cc b/source/blender/blenvm/llvm/llvm_codegen.cc
index 73548bb..8dc94c4 100644
--- a/source/blender/blenvm/llvm/llvm_codegen.cc
+++ b/source/blender/blenvm/llvm/llvm_codegen.cc
@@ -477,13 +477,41 @@ void LLVMCompiler::optimize_function(llvm::Function *func, int opt_level)
 {
 	using namespace llvm;
 	using legacy::FunctionPassManager;
+	using legacy::PassManager;
 	
 	FunctionPassManager FPM(module());
+	PassManager MPM;
+	
+#if 0
+	/* Set up the optimizer pipeline.
+	 * Start with registering info about how the
+	 * target lays out data structures.
+	 */
+	FPM.add(new DataLayoutPass(*llvm_execution_engine()->getDataLayout()));
+	/* Provide basic AliasAnalysis support for GVN. */
+	FPM.add(createBasicAliasAnalysisPass());
+	/* Do simple "peephole" optimizations and bit-twiddling optzns. */
+	FPM.add(createInstructionCombiningPass());
+	/* Reassociate expressions. */
+	FPM.add(createReassociatePass());
+	/* Eliminate Common SubExpressions. */
+	FPM.add(createGVNPass());
+	/* Simplify the control flow graph (deleting unreachable blocks, etc). */
+	FPM.add(createCFGSimplificationPass());
+	
+	FPM.doInitialization();
+#endif
 	
 	PassManagerBuilder builder;
 	builder.OptLevel = opt_level;
+	
+	builder.populateModulePassManager(MPM);
+	/* Basic function inlining */
+	MPM.add(createFunctionInliningPass());
+	
 	builder.populateFunctionPassManager(FPM);
 	
+	MPM.run(*module());
 	FPM.run(*func);
 }
 
diff --git a/source/blender/blenvm/llvm/llvm_headers.h b/source/blender/blenvm/llvm/llvm_headers.h
index d964d83..c425ce8 100644
--- a/source/blender/blenvm/llvm/llvm_headers.h
+++ b/source/blender/blenvm/llvm/llvm_headers.h
@@ -53,5 +53,7 @@
 #include "llvm/PassManager.h"
 #include "llvm/IR/LegacyPassManagers.h"
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/Transforms/IPO.h"
+#include "llvm/Transforms/Scalar.h"
 
 #endif /* __LLVM_HEADERS_H__ */
diff --git a/source/blender/blenvm/modules/mod_value.cc b/source/blender/blenvm/modules/mod_value.cc
index 40bb82a..c891b82 100644
--- a/source/blender/blenvm/modules/mod_value.cc
+++ b/source/blender/blenvm/modules/mod_value.cc
@@ -28,27 +28,16 @@
 #include "mod_math.h"
 #include "mod_value.h"
 
-void VALUE_FLOAT(float &result, const float &value)
+inline int force_linking()
 {
-	result = value;
+	int i = 0;
+	i += (long int)VALUE_FLOAT;
+	i += (long int)VALUE_FLOAT3;
+	i += (long int)VALUE_FLOAT4;
+	i += (long int)VALUE_INT;
+	i += (long int)VALUE_MATRIX44;
+	
+	return i;
 }
 
-void VALUE_FLOAT3(float3 &result, const float3 &value)
-{
-	result = value;
-}
-
-void VALUE_FLOAT4(float4 &result, const float4 &value)
-{
-	result = value;
-}
-
-void VALUE_INT(int &result, const int &value)
-{
-	result = value;
-}
-
-void VALUE_MATRIX44(matrix44 &result, const matrix44 &value)
-{
-	result = value;
-}
+static int f = force_linking();
diff --git a/source/blender/blenvm/modules/mod_value.h b/source/blender/blenvm/modules/mod_value.h
index 0ae585d..9609f66 100644
--- a/source/blender/blenvm/modules/mod_value.h
+++ b/source/blender/blenvm/modules/mod_value.h
@@ -28,10 +28,34 @@
 #ifndef __MOD_VALUE_H__
 #define __MOD_VALUE_H__
 
-__attribute__((annotate("VALUE_FLOAT"))) void VALUE_FLOAT(float &result, const float &value);
-__attribute__((annotate("VALUE_FLOAT3"))) void VALUE_FLOAT3(float3 &result, const float3 &value);
-__attribute__((annotate("VALUE_FLOAT4"))) void VALUE_FLOAT4(float4 &result, const float4 &value);
-__attribute__((annotate("VALUE_INT"))) void VALUE_INT(int &result, const int &value);
-__attribute__((annotate("VALUE_MATRIX44"))) void VALUE_MATRIX44(matrix44 &result, const matrix44 &value);
+__attribute__((annotate("VALUE_FLOAT")))
+inline void VALUE_FLOAT(float &result, const float &value)
+{
+	result = value;
+}
+
+__attribute__((annotate("VALUE_FLOAT3")))
+inline void VALUE_FLOAT3(float3 &result, const float3 &value)
+{
+	result = value;
+}
+
+__attribute__((annotate("VALUE_FLOAT4")))
+inline void VALUE_FLOAT4(float4 &result, const float4 &value)
+{
+	result = value;
+}
+
+__attribute__((annotate("VALUE_INT")))
+inline void VALUE_INT(int &result, const int &value)
+{
+	result = value;
+}
+
+__attribute__((annotate("VALUE_MATRIX44")))
+inline void VALUE_MATRIX44(matrix44 &result, const matrix44 &value)
+{
+	result = value;
+}
 
 #endif /* __MOD_VALUE_H__ */




More information about the Bf-blender-cvs mailing list