[opengtl-commits] [437] use the correct types for generating the "evaluatePixeles" function

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 437
Author:   cyrille
Date:     2008-10-10 00:02:03 +0200 (Fri, 10 Oct 2008)

Log Message:
-----------
use the correct types for generating the "evaluatePixeles" function

Modified Paths:
--------------
    trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel_p.h


Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2008-10-09 22:01:19 UTC (rev 436)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2008-10-09 22:02:03 UTC (rev 437)
@@ -167,9 +167,10 @@
   new llvm::StoreInst( result, ptr, "", _currentBlock );
 }
 
-llvm::Function* CodeGenerator::generateEvaluatePixeles( Kernel* _kernel, GTLCore::ModuleData* _moduleData, int _channels)
+llvm::Function* CodeGenerator::generateEvaluatePixeles( Kernel* _kernel, int _channels)
 {
-  GTLCore::CodeGenerator codeGenerator( _moduleData );
+  GTLCore::ModuleData* moduleData = _kernel->d->moduleData();
+  GTLCore::CodeGenerator codeGenerator( moduleData );
   
   // Pseudo-code explaining step-by-step what an evaluatePixeles function does :
   //
@@ -201,14 +202,14 @@
   params.push_back( llvm::Type::Int32Ty );
   params.push_back( llvm::Type::Int32Ty );
   params.push_back( llvm::Type::Int32Ty );
-  SHIVA_ASSERT( _moduleData->typeManager()->getStructure( "image" ) );
+  SHIVA_ASSERT( _kernel->d->outputImageType() );
   params.push_back( llvm::PointerType::get( GTLCore::Type::Pointer->d->type(), 0 ) );
-  params.push_back( llvm::PointerType::get( _moduleData->typeManager()->getStructure( "image" )->d->type(), 0 ) );
+  params.push_back( llvm::PointerType::get( _kernel->d->outputImageType()->d->type(), 0 ) );
   llvm::FunctionType* definitionType = llvm::FunctionType::get( llvm::Type::VoidTy, params, false );
   int evaluatePixelesId = ++CodeGenerator::s_evaluatePixelesId;
   llvm::Function* func = codeGenerator.createFunction( definitionType, "evaluatePixeles" + GTLCore::String::number(evaluatePixelesId));
   // Initialise a generation context
-  GTLCore::GenerationContext generationContext( &codeGenerator, func, 0, _moduleData );
+  GTLCore::GenerationContext generationContext( &codeGenerator, func, 0, moduleData );
   
   // {
     llvm::BasicBlock* initialBlock = llvm::BasicBlock::Create();
@@ -233,10 +234,10 @@
     ++arg_it;
     llvm::Value* arg_result = arg_it;
   // Create the pixel
-    GTLCore::VariableNG* resultVar = new GTLCore::VariableNG( _moduleData->typeManager()->getStructure( "pixel" ), false );
+    GTLCore::VariableNG* resultVar = new GTLCore::VariableNG( _kernel->d->outputPixelType(), false );
   resultVar->initialise( generationContext, initialBlock, GTLCore::ExpressionResult(), std::list<llvm::Value*>());
   // Get the evaluatePixel function
-    GTLCore::Function* ePFunction = _moduleData->function( _kernel->name(), "evaluatePixel" );
+    GTLCore::Function* ePFunction = moduleData->function( _kernel->name(), "evaluatePixel" );
     SHIVA_ASSERT( ePFunction );
     unsigned int countArguments = ePFunction->parameters().size();
     
@@ -286,7 +287,7 @@
         
         // Synchronize the output pixel with input
         // Call image_wrap_data on the result to get the pointer on destination data
-        llvm::Value* pointer = callImageWrapData( generationContext, firstBlockILoop, generationContext.module()->typeManager()->getStructure( "image" ), arg_result, iVal, jVal);
+        llvm::Value* pointer = callImageWrapData( generationContext, firstBlockILoop, _kernel->d->outputImageType(), arg_result, iVal, jVal);
         llvm::BasicBlock* lastBlockILoop = pixelToMem( generationContext, firstBlockILoop, resultVar->pointer(firstBlockILoop), pointer, arg_result );
       // }
       

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h	2008-10-09 22:01:19 UTC (rev 436)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h	2008-10-09 22:02:03 UTC (rev 437)
@@ -21,6 +21,7 @@
 #define _OPENSHIVA_CODE_GENERATOR_P_H_
 
 #include <vector>
+#include "Kernel_p.h"
 
 namespace llvm {
   class BasicBlock;
@@ -51,7 +52,7 @@
        */
       static llvm::BasicBlock* memToPixel( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dataPointer, llvm::Value* _pixel, llvm::Value* _image );
       static llvm::BasicBlock* pixelToMem( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pixel, llvm::Value* _dataPointer, llvm::Value* _image );
-      static llvm::Function* generateEvaluatePixeles( Kernel* _kernel, GTLCore::ModuleData* _moduleData, int _channels );
+      static llvm::Function* generateEvaluatePixeles( Kernel* _kernel, int _channels );
       static llvm::Function* generateMemToVec( GTLCore::ModuleData* _moduleData, const GTLCore::PixelDescription& _pixelDescription );
       static llvm::Function* generateVecToMem( GTLCore::ModuleData* _moduleData, const GTLCore::PixelDescription& _pixelDescription );
       /**

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-10-09 22:01:19 UTC (rev 436)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-10-09 22:02:03 UTC (rev 437)
@@ -54,7 +54,7 @@
   d->compiled = false;
   d->enableHydraCompatibility = false;
   d->moduleProvider = 0;
-  d->moduleData = 0;
+  d->m_moduleData = 0;
   d->count_channels_generic = _channelsNb;
   d->evaluatePixelesFunction = 0;
   d->wrapper = 0;
@@ -74,9 +74,9 @@
     delete d->moduleProvider;
     d->moduleProvider = 0;
   }
-  delete d->moduleData;
+  delete d->m_moduleData;
   delete d->wrapper;
-  d->moduleData = 0;
+  d->m_moduleData = 0;
   d->evaluatePixelesFunction = 0; // It's deleted by the moduleData
 }
 
@@ -115,24 +115,24 @@
 {
   if(d->source.empty()) return;
   cleanup();
-  d->moduleData = new GTLCore::ModuleData(new llvm::Module(d->name));
+  d->m_moduleData = new GTLCore::ModuleData(new llvm::Module(d->name));
   Compiler c;
-  Wrapper::fillTypeManager( d->moduleData, d->moduleData->typeManager(), c.convertCenter() , d->count_channels_generic );
+  Wrapper::fillTypeManager( d->m_moduleData, d->m_moduleData->typeManager(), c.convertCenter() , d->count_channels_generic );
   GTLCore::String nameSpace;
-  bool result = c.compile( d->source, d->name, d->moduleData, nameSpace );
+  bool result = c.compile( d->source, d->name, d->m_moduleData, nameSpace );
 
   if(result)
   {
     d->compiled = true;
     // Register the compiled module in the virtual machine
-    d->moduleProvider = new llvm::ExistingModuleProvider( d->moduleData->llvmModule() );
+    d->moduleProvider = new llvm::ExistingModuleProvider( d->m_moduleData->llvmModule() );
     GTLCore::VirtualMachine::instance()->registerModule( d->moduleProvider );
     
     // Create a wrapper
-    d->wrapper = new Wrapper(this, d->moduleData);
+    d->wrapper = new Wrapper(this, d->m_moduleData);
     d->determineTypes();
     // Create the generateEvaluatePixeles LLVM function
-    d->evaluatePixelesFunction = CodeGenerator::generateEvaluatePixeles( this, d->moduleData, d->count_channels_generic );
+    d->evaluatePixelesFunction = CodeGenerator::generateEvaluatePixeles( this, d->count_channels_generic );
     d->name = nameSpace;
   } else {
     cleanup();
@@ -160,6 +160,7 @@
   ImageWrap* owrap = d->wrapper->wrapImage( _outputImage );
   
   // Call function
+  SHIVA_DEBUG("Call function");
   void (*func)( int, int, int, int, const void**, void*) = ( void(*)(int, int, int, int, const void**, void*))GTLCore::VirtualMachine::instance()->getPointerToFunction( d->evaluatePixelesFunction);
   SHIVA_ASSERT(func);
   (*func)( _region.x(), _region.y(), _region.width(), _region.height(), inputImages, owrap);
@@ -175,7 +176,7 @@
 int Kernel::runTest() const
 {
   SHIVA_ASSERT( isCompiled() );
-  const GTLCore::Function* f = d->moduleData->function( "MyKernel", "runTest");
+  const GTLCore::Function* f = d->m_moduleData->function( "MyKernel", "runTest");
   SHIVA_ASSERT( f );
   GTLCore::Value v = f->call( std::vector< GTLCore::Value >() );
   return v.asInt32();
@@ -183,12 +184,12 @@
 
 bool Kernel::hasTestFunction() const
 {
-  return d->moduleData->function( "MyKernel", "runTest");
+  return d->m_moduleData->function( "MyKernel", "runTest");
 }
 
 GTLCore::Region Kernel::needed( GTLCore::Region output_region, int input_index, const std::list< GTLCore::Region>& input_DOD)
 {
-  GTLCore::Function* neededFunction = d->moduleData->function( "MyKernel", "needed");
+  GTLCore::Function* neededFunction = d->m_moduleData->function( "MyKernel", "needed");
   RegionWrap* (*func)( RegionWrap*, int, ArrayWrap* ) = ( RegionWrap* (*)( RegionWrap*, int, ArrayWrap* ) )GTLCore::VirtualMachine::instance()->getPointerToFunction( neededFunction, 3);
   RegionWrap* rwrap = (*func)( regionToRegionWrap( output_region ), input_index, regionListToArrayWrap( input_DOD ) );
   
@@ -199,12 +200,12 @@
 
 bool Kernel::hasNeededFunction() const
 {
-  return d->moduleData->function( "MyKernel", "needed");
+  return d->m_moduleData->function( "MyKernel", "needed");
 }
 
 GTLCore::Region Kernel::changed( GTLCore::Region changed_input_region, int input_index, const std::list< GTLCore::Region>& input_DOD)
 {
-  GTLCore::Function* changedFunction = d->moduleData->function( "MyKernel", "changed");
+  GTLCore::Function* changedFunction = d->m_moduleData->function( "MyKernel", "changed");
   RegionWrap* (*func)( RegionWrap*, int, ArrayWrap* ) = ( RegionWrap* (*)( RegionWrap*, int, ArrayWrap* ) )GTLCore::VirtualMachine::instance()->getPointerToFunction( changedFunction, 3);
   RegionWrap* rwrap = (*func)( regionToRegionWrap( changed_input_region ), input_index, regionListToArrayWrap( input_DOD ) );
   
@@ -215,12 +216,12 @@
 
 bool Kernel::hasChangedFunction() const
 {
-  return d->moduleData->function( "MyKernel", "changed");
+  return d->m_moduleData->function( "MyKernel", "changed");
 }
 
 GTLCore::Region Kernel::generated()
 {
- GTLCore::Function* f = d->moduleData->function( "MyKernel", "generated");
+ GTLCore::Function* f = d->m_moduleData->function( "MyKernel", "generated");
  SHIVA_ASSERT( f );
 
  RegionWrap* (*func)() = (RegionWrap* (*)())GTLCore::VirtualMachine::instance()->getPointerToFunction( f, 0 );
@@ -233,7 +234,7 @@
 
 bool Kernel::hasGeneratedFunction() const
 {
-  return d->moduleData->function( "MyKernel", "generated");
+  return d->m_moduleData->function( "MyKernel", "generated");
 }
 
 
@@ -262,12 +263,12 @@
 GTLCore::String Kernel::asmSourceCode() const
 {
   std::ostringstream os;
-  os << *d->moduleData->llvmModule() << std::endl;
+  os << *d->m_moduleData->llvmModule() << std::endl;
   return os.str();
 }
 
 GTLCore::String Kernel::cSourceCode() const
 {
-  return d->moduleData->asCCode();
+  return d->m_moduleData->asCCode();
 }
 

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h	2008-10-09 22:01:19 UTC (rev 436)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h	2008-10-09 22:02:03 UTC (rev 437)
@@ -39,6 +39,7 @@
    * @ingroup OpenShiva
    */
   class Kernel {
+    friend class CodeGenerator;
     public:
       Kernel(const GTLCore::String& _name, int _channelsNb = 4 );
       ~Kernel();

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel_p.cpp	2008-10-09 22:01:19 UTC (rev 436)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel_p.cpp	2008-10-09 22:02:03 UTC (rev 437)
@@ -25,19 +25,25 @@
 #include "GTLCore/ModuleData_p.h"
 #include "GTLCore/Macros_p.h"
 #include "GTLCore/Type.h"
+#include "GTLCore/TypeManager.h"
 
 #include "Debug.h"
 
 using namespace OpenShiva;
 
-Kernel::Private::Private()
+Kernel::Private::Private() : m_moduleData(0)
 {
 }
 
+GTLCore::ModuleData* Kernel::Private::moduleData()
+{
+  return m_moduleData;
+}
+
 void Kernel::Private::determineTypes()
 {
   m_inputsTypes.clear();
-  GTLCore::Function* ePFunction = moduleData->function( self->name(), "evaluatePixel" );
+  GTLCore::Function* ePFunction = m_moduleData->function( self->name(), "evaluatePixel" );
   bool hasOutput = false;
   foreach( GTLCore::Parameter arg, ePFunction->parameters() )
   {
@@ -45,8 +51,16 @@
     {
       SHIVA_ASSERT(not hasOutput );
       hasOutput = true;
-      SHIVA_ASSERT( arg.type()->dataType() == GTLCore::Type::STRUCTURE );
-      SHIVA_ASSERT( arg.type()->structName().head( 5 ) == "pixel" );
+      m_outputPixelType = arg.type();
+      SHIVA_ASSERT( m_outputPixelType->dataType() == GTLCore::Type::STRUCTURE );
+      SHIVA_ASSERT( m_outputPixelType->structName().head( 5 ) == "pixel" );
+      if(  m_outputPixelType->structName() == "pixel" )
+      {
+        m_outputImageType = m_moduleData->typeManager()->getStructure( "image" );
+      } else {
+        m_outputImageType = m_moduleData->typeManager()->getStructure( "image" + m_outputPixelType->structName().tail(1) );
+      }
+      GTL_ASSERT( m_outputImageType );
     } else {
       SHIVA_ASSERT( arg.type()->dataType() == GTLCore::Type::STRUCTURE );
       SHIVA_ASSERT( arg.type()->structName().head( 5 ) == "image" );

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel_p.h	2008-10-09 22:01:19 UTC (rev 436)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel_p.h	2008-10-09 22:02:03 UTC (rev 437)
@@ -42,6 +42,7 @@
       const std::list< const GTLCore::Type* >& inputsTypes();
       const GTLCore::Type* outputPixelType();
       const GTLCore::Type* outputImageType();
+      GTLCore::ModuleData* moduleData();
     private:
       /**
        * Determines output and input types.
@@ -54,7 +55,7 @@
       bool compiled;
       std::list<GTLCore::ErrorMessage> compilationErrors;
       llvm::ModuleProvider* moduleProvider;
-      GTLCore::ModuleData* moduleData;
+      GTLCore::ModuleData* m_moduleData;
       llvm::Function* evaluatePixelesFunction;
       int count_channels_generic;
       Wrapper* wrapper;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/