[opengtl-commits] [345] * if channels == 1, the vector of data isn't a vector |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 345
Author: cyrille
Date: 2008-09-02 00:09:00 +0200 (Tue, 02 Sep 2008)
Log Message:
-----------
* if channels == 1, the vector of data isn't a vector
* support for different images types in the evaluatePixel function
Modified Paths:
--------------
trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp
trunk/OpenGTL/OpenGTL/GTLCore/Debug.h
trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp 2008-09-01 20:53:29 UTC (rev 344)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp 2008-09-01 22:09:00 UTC (rev 345)
@@ -325,3 +325,29 @@
}
+
+#ifndef NDEBUG
+
+#include <llvm/DerivedTypes.h>
+#include <llvm/Function.h>
+#include <llvm/Type.h>
+
+void compareFunctionParameters( llvm::Function* func, const std::vector<llvm::Value*>& params )
+{
+ const llvm::FunctionType *FTy =
+ llvm::cast<llvm::FunctionType>(llvm::cast<llvm::PointerType>(func->getType())->getElementType());
+
+ GTL_ASSERT( params.size() == FTy->getNumParams() or
+ (FTy->isVarArg() and params.size() > FTy->getNumParams()) );
+
+ for (unsigned i = 0; i < params.size(); ++i) {
+ if( i < FTy->getNumParams() and (FTy->getParamType(i) != params[i]->getType()) )
+ {
+ GTL_DEBUG( "Wrong parameter " << i << " : " << FTy->getParamType(i) << " => " << *FTy->getParamType(i) << " but got " << params[i] << " => " << *params[i]->getType() );
+ } else {
+ GTL_DEBUG( "Parameter " << i << " : " << FTy->getParamType(i) << " => " << *FTy->getParamType(i) << " but got " << params[i]->getType() << " => " << *params[i]->getType() );
+ }
+ }
+}
+#endif
+
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Debug.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Debug.h 2008-09-01 20:53:29 UTC (rev 344)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Debug.h 2008-09-01 22:09:00 UTC (rev 345)
@@ -95,12 +95,26 @@
GTL_ABORT( #val1 << " != " << #val2 ); \
}
+
+#include <vector>
+
+namespace llvm {
+ class Function;
+ class Value;
+}
+
+void compareFunctionParameters( llvm::Function* func, const std::vector<llvm::Value*>& params );
+
+#define GTL_COMPARE_FUNCTION_PARAMETERS( _FUNC_, _PARAMS_ ) \
+ compareFunctionParameters( _FUNC_, _PARAMS_ );
+
#else
#define GTL_DEBUG(msg)
#define GTL_ASSERT(assrt)
#define GTL_CHECK_PTR(ptr) (void)ptr;
#define GTL_CHECK_EQUAL(val1, val2) (void)val1; (void)val2;
+#define GTL_COMPARE_FUNCTION_PARAMETERS( _FUNC_, _PARAMS_ ) (void)_FUNC_; (void)_PARMAS_; \
#endif
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp 2008-09-01 20:53:29 UTC (rev 344)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp 2008-09-01 22:09:00 UTC (rev 345)
@@ -202,9 +202,7 @@
params.push_back( llvm::Type::Int32Ty );
params.push_back( llvm::Type::Int32Ty );
SHIVA_ASSERT( _moduleData->typeManager()->getStructure( "image" ) );
- params.push_back(
- llvm::PointerType::get(
- llvm::PointerType::get( _moduleData->typeManager()->getStructure( "image" )->d->type(), 0 ), 0 ) );
+ 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 ) );
llvm::FunctionType* definitionType = llvm::FunctionType::get( llvm::Type::VoidTy, params, false );
int evaluatePixelesId = ++CodeGenerator::s_evaluatePixelesId;
@@ -246,10 +244,10 @@
std::vector<llvm::Value*> evaluatePixel_params;
for(unsigned int i = 0; i < countArguments - 1; ++i )
{
- evaluatePixel_params.push_back(
- new llvm::LoadInst(
+ llvm::Value* imgPtr = new llvm::LoadInst(
llvm::GetElementPtrInst::Create( arg_sources, GTLCore::CodeGenerator::integerToConstant( i ), "", initialBlock ),
- "", initialBlock ) );
+ "", initialBlock );
+ evaluatePixel_params.push_back( GTLCore::CodeGenerator::convertPointerTo( initialBlock, imgPtr, ePFunction->parameters()[i].type()->d->type() ) );
}
evaluatePixel_params.push_back( resultVar->pointer() );
SHIVA_ASSERT( evaluatePixel_params.size() == countArguments );
@@ -283,6 +281,7 @@
llvm::Function* llvmEPFunction = ePFunction->d->data->function( countArguments );
SHIVA_ASSERT( llvmEPFunction );
SHIVA_DEBUG( evaluatePixel_params.size() );
+ GTL_COMPARE_FUNCTION_PARAMETERS( llvmEPFunction, evaluatePixel_params );
llvm::CallInst::Create( llvmEPFunction, evaluatePixel_params.begin(), evaluatePixel_params.end(), "", firstBlockILoop );
// Synchronize the output pixel with input
@@ -403,7 +402,12 @@
}
// result[i] = convert(_imgData + pos(i) )
- floatVec = llvm::InsertElementInst::Create( floatVec, floatValue, i, "", currentBlock);
+ if( channelsNb == 1 )
+ { // Special case, special hack, for a pixel of one channel, the vec isn't a vec
+ floatVec = floatValue;
+ } else {
+ floatVec = llvm::InsertElementInst::Create( floatVec, floatValue, i, "", currentBlock);
+ }
GTL_ASSERT(channelType->bitsSize() % 8 == 0);
currentPos += channelType->bitsSize() / 8;
// }
@@ -487,7 +491,13 @@
{
const GTLCore::Type* channelType = _pixelDescription.channelTypes()[i];
// _src[i]
- llvm::Value* floatValue = new llvm::ExtractElementInst( floatVec, i, "", currentBlock );
+ llvm::Value* floatValue;
+ if( channelsNb == 1 )
+ {
+ floatValue = floatVec;
+ } else {
+ floatValue = new llvm::ExtractElementInst( floatVec, i, "", currentBlock );
+ }
// convert( _src[i] );
// Scale
switch( channelType->dataType() )
@@ -541,6 +551,7 @@
llvm::Value* CodeGenerator::callImageWrapData( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, const GTLCore::Type* _imageType, llvm::Value* _imageWrap, llvm::Value* _x, llvm::Value* _y )
{
+ GTL_DEBUG( "CodeGenerator::callImageWrapData " << *_imageType << " " << *_imageWrap << " " << *_x << " " << *_y);
GTL_ASSERT( _imageType );
std::vector<llvm::Value*> image_wrap_data_params;
image_wrap_data_params.push_back( _imageWrap );
@@ -548,25 +559,7 @@
image_wrap_data_params.push_back( _y );
llvm::Function* func = Wrapper::image_wrap_dataFunction( _gc.llvmModule(), _imageType );
-#ifndef _NDEBUG_
- {
- const llvm::FunctionType *FTy =
- llvm::cast<llvm::FunctionType>(llvm::cast<llvm::PointerType>(func->getType())->getElementType());
-
- GTL_ASSERT( image_wrap_data_params.size() == FTy->getNumParams() or
- (FTy->isVarArg() and image_wrap_data_params.size() > FTy->getNumParams()) );
-
- for (unsigned i = 0; i < image_wrap_data_params.size(); ++i) {
- if( i < FTy->getNumParams() and (FTy->getParamType(i) != image_wrap_data_params[i]->getType()) )
- {
- GTL_DEBUG( "Wrong parameter " << i << " : " << FTy->getParamType(i) << " => " << *FTy->getParamType(i) << " but got " << image_wrap_data_params[i] << " => " << *image_wrap_data_params[i]->getType() );
- } else {
- GTL_DEBUG( "Parameter " << i << " : " << FTy->getParamType(i) << " => " << *FTy->getParamType(i) << " but got " << image_wrap_data_params[i]->getType() << " => " << *image_wrap_data_params[i]->getType() );
- }
- }
- }
-#endif
-
+ GTL_COMPARE_FUNCTION_PARAMETERS( func, image_wrap_data_params );
return llvm::CallInst::Create(
func, image_wrap_data_params.begin(), image_wrap_data_params.end(), "", _currentBlock ); // TODO get the real type of the output image (even if it doesn't matter much currently)
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp 2008-09-01 20:53:29 UTC (rev 344)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp 2008-09-01 22:09:00 UTC (rev 345)
@@ -77,6 +77,7 @@
ImageWrap* Wrapper::wrapImage(GTLCore::AbstractImage* _abstractImage)
{
+ SHIVA_DEBUG("wrapImage");
ImageWrap* owrap = new ImageWrap;
owrap->image = _abstractImage;
pdToWF_it it = d->imageFunctions.find( _abstractImage->pixelDescription() );
@@ -96,6 +97,7 @@
owrap->memToVec = it->second.memToVec;
owrap->vecToMem = it->second.vecToMem;
}
+ SHIVA_DEBUG("Image wrapped");
return owrap;
}
@@ -247,6 +249,10 @@
const GTLCore::Type* Wrapper::vectorType( GTLCore::TypeManager* _typeManager, int _channels )
{
+ if( _channels == 1)
+ {
+ return GTLCore::Type::Float;
+ }
// Compute the size of the vector
int size_vector = 1;
while( size_vector < _channels )