From c91a1179b5742772b5f39b58a5479897bb8e2c9e Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Sat, 5 Jan 2013 00:03:45 -0500 Subject: [PATCH] exposed a bit more JIT --- sdk/jitcv/jitcv.h | 3 +++ sdk/plugins/llvm.cpp | 38 ++++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/sdk/jitcv/jitcv.h b/sdk/jitcv/jitcv.h index 1c76b66..e5ee0a7 100644 --- a/sdk/jitcv/jitcv.h +++ b/sdk/jitcv/jitcv.h @@ -97,6 +97,9 @@ void jit_binary_apply(const jit_binary_kernel &kernel, const jit_matrix &src, ji jit_unary_kernel jit_square(); +typedef void (*jit_unary_core_t)(const jit_matrix *src, jit_matrix *dst, uint32_t size); +typedef void (*jit_binary_core_t)(const jit_matrix *srcA, const jit_matrix *srcB, jit_matrix *dst, uint32_t size); + #ifdef __cplusplus } #endif diff --git a/sdk/plugins/llvm.cpp b/sdk/plugins/llvm.cpp index bab9325..5d80ffa 100644 --- a/sdk/plugins/llvm.cpp +++ b/sdk/plugins/llvm.cpp @@ -250,8 +250,7 @@ class UnaryKernel : public UntrainableMetaTransform { Q_OBJECT - typedef void (*kernel_t)(const jit_matrix*, jit_matrix*, quint32); - kernel_t kernel; + jit_unary_core_t kernel; quint16 hash; public: @@ -267,6 +266,19 @@ public: invoke(src, dst, size); } + jit_unary_core_t getKernel(const jit_matrix *src) const + { + const QString functionName = mangledName(*src); + Function *function = TheModule->getFunction(qPrintable(functionName)); + if (function == NULL) { + function = compile(*src); + while (TheFunctionPassManager->run(*function)); + TheExtraFunctionPassManager->run(*function); + function = TheModule->getFunction(qPrintable(functionName)); + } + return (jit_unary_core_t)TheExecutionEngine->getPointerToFunction(function); + } + private: QString mangledName() const { @@ -362,17 +374,7 @@ private: QMutexLocker locker(&compilerLock); if (src.hash != hash) { - const QString functionName = mangledName(src); - - Function *function = TheModule->getFunction(qPrintable(functionName)); - if (function == NULL) { - function = compile(src); - while (TheFunctionPassManager->run(*function)); - TheExtraFunctionPassManager->run(*function); - function = TheModule->getFunction(qPrintable(functionName)); - } - - const_cast(this)->kernel = (kernel_t)TheExecutionEngine->getPointerToFunction(function); + const_cast(this)->kernel = getKernel(&src); const_cast(this)->hash = src.hash; } } @@ -389,8 +391,7 @@ class BinaryKernel: public UntrainableMetaTransform { Q_OBJECT - typedef void (*kernel_t)(const jit_matrix*, const jit_matrix*, jit_matrix*, quint32); - kernel_t kernel; + jit_binary_core_t kernel; quint16 hashA, hashB; public: @@ -467,7 +468,7 @@ private: function = TheModule->getFunction(qPrintable(functionName)); } - const_cast(this)->kernel = (kernel_t)TheExecutionEngine->getPointerToFunction(function); + const_cast(this)->kernel = (jit_binary_core_t)TheExecutionEngine->getPointerToFunction(function); const_cast(this)->hashA = srcA.hash; const_cast(this)->hashB = srcB.hash; } @@ -1003,4 +1004,9 @@ jit_unary_kernel jit_square() return &transform; } +jit_unary_core_t jit_compile_unary_core(const void *kernel, const jit_matrix &m) +{ + return ((const UnaryKernel*)kernel)->getKernel(&m); +} + #include "llvm.moc" -- libgit2 0.21.4