[opengtl-commits] [390] structures and arrays' s pointer is stored in a pointer value to allow replacing them as needed |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 390
Author: cyrille
Date: 2008-09-13 23:07:14 +0200 (Sat, 13 Sep 2008)
Log Message:
-----------
structures and arrays's pointer is stored in a pointer value to allow replacing them as needed
Modified Paths:
--------------
trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp
trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h
trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
Modified: trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp 2008-09-13 07:31:21 UTC (rev 389)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp 2008-09-13 21:07:14 UTC (rev 390)
@@ -273,7 +273,7 @@
{
OCTL_ASSERT(buffer[i]);
buffer[i]->set( gc, bodyBlock, new llvm::LoadInst(pointer,"", bodyBlock), dstPixelDescription.channelTypes()[i]);
- arguments.push_back( buffer[i]->pointer());
+ arguments.push_back( buffer[i]->pointer(bodyBlock));
} else {
arguments.push_back(pointer);
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp 2008-09-13 07:31:21 UTC (rev 389)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp 2008-09-13 21:07:14 UTC (rev 390)
@@ -177,7 +177,7 @@
llvm::Value* VariableAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const
{
GTL_DEBUG("VariableAccessorExpression::pointer");
- return m_variable->pointer();
+ return m_variable->pointer(bb);
}
bool VariableAccessorExpression::isConstant() const
@@ -192,7 +192,6 @@
void VariableAccessorExpression::markAsReturnExpression()
{
- GTL_DEBUG( m_variable->allocatedInMemory() );
}
bool VariableAccessorExpression::allocatedInMemory() const
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp 2008-09-13 07:31:21 UTC (rev 389)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp 2008-09-13 21:07:14 UTC (rev 390)
@@ -171,11 +171,11 @@
{
if( it->output())
{
- (*pv_it)->initialise( generationContext, arg_it );
+ (*pv_it)->initialise( generationContext, firstBlock, arg_it );
} else {
if( it->type()->dataType() == Type::STRUCTURE or it->type()->dataType() == Type::ARRAY )
{
- (*pv_it)->initialise( generationContext, arg_it );
+ (*pv_it)->initialise( generationContext, firstBlock, arg_it );
} else {
firstBlock = (*pv_it)->initialise( generationContext, firstBlock, ExpressionResult( arg_it, it->type()), std::list<llvm::Value*>() );
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp 2008-09-13 07:31:21 UTC (rev 389)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Tree.cpp 2008-09-13 21:07:14 UTC (rev 390)
@@ -54,7 +54,7 @@
llvm::Constant* value = _codeGenerator->convertConstantTo( m_initialiser->generateValue( gc, 0 ).constant(), m_initialiser->type() , m_type );
llvm::Value* pointer = new llvm::GlobalVariable( value->getType(), true, llvm::GlobalValue::InternalLinkage, value, "", _module->llvmModule() );
- m_variable->initialise( gc, pointer);
+ m_variable->initialise( gc, 0, pointer);
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp 2008-09-13 07:31:21 UTC (rev 389)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp 2008-09-13 21:07:14 UTC (rev 390)
@@ -40,6 +40,7 @@
bool constant;
bool isInitialised;
llvm::Value* pointer;
+ bool directlyOnTheStack;
bool allocatedInMemory;
bool constantPointer;
};
@@ -71,36 +72,43 @@
llvm::BasicBlock* VariableNG::initialise( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _bb, const ExpressionResult& _initialiser, const std::list<llvm::Value*>& _initialSize )
{
GTL_DEBUG( _initialSize.size() );
- llvm::Value* pointer = 0;
+ llvm::Value* pointer_ = 0;
if( _initialiser.value() and _initialiser.functionResult()
and (type()->dataType() == Type::ARRAY or type()->dataType() == Type::STRUCTURE ) )
{
- initialise( _generationContext, _initialiser.value() );
- _bb = d->visitor->mark( _generationContext, _bb, d->pointer, d->type, CodeGenerator::integerToConstant( 1 ) );
+ initialise( _generationContext, _bb, _initialiser.value() );
+ _bb = d->visitor->mark( _generationContext, _bb, pointer(_bb), d->type, CodeGenerator::integerToConstant( 1 ) );
} else {
if( d->allocatedInMemory )
{
- pointer = new llvm::MallocInst( d->type->d->type(), llvm::ConstantInt::get(llvm::Type::Int32Ty, 1), "", _bb);
+ pointer_ = new llvm::MallocInst( d->type->d->type(), llvm::ConstantInt::get(llvm::Type::Int32Ty, 1), "", _bb);
} else {
- pointer = new llvm::AllocaInst( d->type->d->type(), llvm::ConstantInt::get(llvm::Type::Int32Ty, 1), "", _bb);
+ pointer_ = new llvm::AllocaInst( d->type->d->type(), llvm::ConstantInt::get(llvm::Type::Int32Ty, 1), "", _bb);
}
- initialise( _generationContext, pointer );
- _bb = d->visitor->initialise( _generationContext, _bb, d->pointer, d->type, _initialSize, d->allocatedInMemory);
+ initialise( _generationContext, _bb, pointer_ );
+ _bb = d->visitor->initialise( _generationContext, _bb, pointer_, d->type, _initialSize, d->allocatedInMemory);
if( _initialiser.value() )
{
- _bb = d->visitor->set( _generationContext, _bb, d->pointer, d->type, _initialiser.value(), _initialiser.type() , d->allocatedInMemory);
+ _bb = d->visitor->set( _generationContext, _bb, pointer_, d->type, _initialiser.value(), _initialiser.type() , d->allocatedInMemory);
}
}
d->constantPointer = false;
return _bb;
}
-void VariableNG::initialise( GTLCore::GenerationContext& /*_generationContext*/, llvm::Value* _pointer )
+void VariableNG::initialise( GTLCore::GenerationContext& /*_generationContext*/, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer )
{
GTL_ASSERT(not d->isInitialised);
d->isInitialised = true;
- d->pointer = _pointer;
+ d->directlyOnTheStack = _currentBlock and ( d->type->dataType() == Type::ARRAY or d->type->dataType() == Type::STRUCTURE );
+ if( d->directlyOnTheStack )
+ {
+ d->pointer = new llvm::AllocaInst( llvm::PointerType::get( d->type->d->type(), 0 ), "", _currentBlock );
+ new llvm::StoreInst( _pointer, d->pointer, "", _currentBlock );
+ } else {
+ d->pointer = _pointer;
+ }
d->constantPointer = true;
}
@@ -127,9 +135,14 @@
return _currentBlock;
}
-llvm::Value* VariableNG::pointer()
+llvm::Value* VariableNG::pointer(llvm::BasicBlock* _currentBlock)
{
- return d->pointer;
+ if( d->directlyOnTheStack )
+ {
+ return new llvm::LoadInst( d->pointer, "", _currentBlock );
+ } else {
+ return d->pointer;
+ }
}
bool VariableNG::allocatedInMemory() const
@@ -146,8 +159,8 @@
{
if( d->allocatedInMemory and not d->constantPointer )
{
- llvm::BasicBlock* bb = d->visitor->cleanUp( _generationContext, _currentBlock, d->pointer, d->type, _donttouch, d->allocatedInMemory, true );
- new llvm::FreeInst( d->pointer, bb);
+ llvm::BasicBlock* bb = d->visitor->cleanUp( _generationContext, _currentBlock, pointer( _currentBlock), d->type, _donttouch, d->allocatedInMemory, true );
+ new llvm::FreeInst( pointer( _currentBlock ), bb);
return bb;
}
return _currentBlock;
Modified: trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h 2008-09-13 07:31:21 UTC (rev 389)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h 2008-09-13 21:07:14 UTC (rev 390)
@@ -53,7 +53,7 @@
* Initialise a Variable with a given pointer. This function will not call \ref Accessor::initialise
* @param _pointer a pointer that will be used by this variable
*/
- void initialise( GenerationContext&, llvm::Value* _pointer );
+ void initialise( GenerationContext&, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer );
/**
* @return true if this variable is a constant.
*/
@@ -87,7 +87,7 @@
/**
* @return the pointer for this variable
*/
- llvm::Value* pointer();
+ llvm::Value* pointer(llvm::BasicBlock* _currentBlock);
/**
* @return true if the variable is allocated in memory, false otherwise
*/
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp 2008-09-13 07:31:21 UTC (rev 389)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp 2008-09-13 21:07:14 UTC (rev 390)
@@ -249,7 +249,7 @@
"", initialBlock );
evaluatePixel_params.push_back( GTLCore::CodeGenerator::convertPointerTo( initialBlock, imgPtr, ePFunction->parameters()[i].type()->d->type() ) );
}
- evaluatePixel_params.push_back( resultVar->pointer() );
+ evaluatePixel_params.push_back( resultVar->pointer(initialBlock) );
SHIVA_ASSERT( evaluatePixel_params.size() == countArguments );
// Construct the "conditions" of the first loop
// int j = 0;
@@ -275,7 +275,7 @@
llvm::Value* iVal = incI->get( generationContext, firstBlockILoop );
// Set the coordinates of the pixel
- setPixelCoordinates( generationContext, firstBlockILoop, resultVar->pointer(), iVal, GTLCore::Type::Integer32, jVal, GTLCore::Type::Integer32 );
+ setPixelCoordinates( generationContext, firstBlockILoop, resultVar->pointer(firstBlockILoop), iVal, GTLCore::Type::Integer32, jVal, GTLCore::Type::Integer32 );
// Call evaluatePixel
llvm::Function* llvmEPFunction = ePFunction->d->data->function( countArguments );
@@ -287,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::BasicBlock* lastBlockILoop = pixelToMem( generationContext, firstBlockILoop, resultVar->pointer(), pointer, arg_result );
+ llvm::BasicBlock* lastBlockILoop = pixelToMem( generationContext, firstBlockILoop, resultVar->pointer(firstBlockILoop), pointer, arg_result );
// }
llvm::BasicBlock* lastBlockJLoop = GTLCore::CodeGenerator::createIterationForStatement( generationContext, firstBlockJLoop, incI, arg_width, GTLCore::Type::Integer32, firstBlockILoop, lastBlockILoop);