Commit c91a1179b5742772b5f39b58a5479897bb8e2c9e

Authored by Josh Klontz
1 parent fe840eb4

exposed a bit more JIT

sdk/jitcv/jitcv.h
... ... @@ -97,6 +97,9 @@ void jit_binary_apply(const jit_binary_kernel &kernel, const jit_matrix &src, ji
97 97  
98 98 jit_unary_kernel jit_square();
99 99  
  100 +typedef void (*jit_unary_core_t)(const jit_matrix *src, jit_matrix *dst, uint32_t size);
  101 +typedef void (*jit_binary_core_t)(const jit_matrix *srcA, const jit_matrix *srcB, jit_matrix *dst, uint32_t size);
  102 +
100 103 #ifdef __cplusplus
101 104 }
102 105 #endif
... ...
sdk/plugins/llvm.cpp
... ... @@ -250,8 +250,7 @@ class UnaryKernel : public UntrainableMetaTransform
250 250 {
251 251 Q_OBJECT
252 252  
253   - typedef void (*kernel_t)(const jit_matrix*, jit_matrix*, quint32);
254   - kernel_t kernel;
  253 + jit_unary_core_t kernel;
255 254 quint16 hash;
256 255  
257 256 public:
... ... @@ -267,6 +266,19 @@ public:
267 266 invoke(src, dst, size);
268 267 }
269 268  
  269 + jit_unary_core_t getKernel(const jit_matrix *src) const
  270 + {
  271 + const QString functionName = mangledName(*src);
  272 + Function *function = TheModule->getFunction(qPrintable(functionName));
  273 + if (function == NULL) {
  274 + function = compile(*src);
  275 + while (TheFunctionPassManager->run(*function));
  276 + TheExtraFunctionPassManager->run(*function);
  277 + function = TheModule->getFunction(qPrintable(functionName));
  278 + }
  279 + return (jit_unary_core_t)TheExecutionEngine->getPointerToFunction(function);
  280 + }
  281 +
270 282 private:
271 283 QString mangledName() const
272 284 {
... ... @@ -362,17 +374,7 @@ private:
362 374 QMutexLocker locker(&compilerLock);
363 375  
364 376 if (src.hash != hash) {
365   - const QString functionName = mangledName(src);
366   -
367   - Function *function = TheModule->getFunction(qPrintable(functionName));
368   - if (function == NULL) {
369   - function = compile(src);
370   - while (TheFunctionPassManager->run(*function));
371   - TheExtraFunctionPassManager->run(*function);
372   - function = TheModule->getFunction(qPrintable(functionName));
373   - }
374   -
375   - const_cast<UnaryKernel*>(this)->kernel = (kernel_t)TheExecutionEngine->getPointerToFunction(function);
  377 + const_cast<UnaryKernel*>(this)->kernel = getKernel(&src);
376 378 const_cast<UnaryKernel*>(this)->hash = src.hash;
377 379 }
378 380 }
... ... @@ -389,8 +391,7 @@ class BinaryKernel: public UntrainableMetaTransform
389 391 {
390 392 Q_OBJECT
391 393  
392   - typedef void (*kernel_t)(const jit_matrix*, const jit_matrix*, jit_matrix*, quint32);
393   - kernel_t kernel;
  394 + jit_binary_core_t kernel;
394 395 quint16 hashA, hashB;
395 396  
396 397 public:
... ... @@ -467,7 +468,7 @@ private:
467 468 function = TheModule->getFunction(qPrintable(functionName));
468 469 }
469 470  
470   - const_cast<BinaryKernel*>(this)->kernel = (kernel_t)TheExecutionEngine->getPointerToFunction(function);
  471 + const_cast<BinaryKernel*>(this)->kernel = (jit_binary_core_t)TheExecutionEngine->getPointerToFunction(function);
471 472 const_cast<BinaryKernel*>(this)->hashA = srcA.hash;
472 473 const_cast<BinaryKernel*>(this)->hashB = srcB.hash;
473 474 }
... ... @@ -1003,4 +1004,9 @@ jit_unary_kernel jit_square()
1003 1004 return &transform;
1004 1005 }
1005 1006  
  1007 +jit_unary_core_t jit_compile_unary_core(const void *kernel, const jit_matrix &m)
  1008 +{
  1009 + return ((const UnaryKernel*)kernel)->getKernel(&m);
  1010 +}
  1011 +
1006 1012 #include "llvm.moc"
... ...