[opengtl-commits] [381] mark/unmark structures/arrays |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 381
Author: cyrille
Date: 2008-09-10 09:29:21 +0200 (Wed, 10 Sep 2008)
Log Message:
-----------
mark/unmark structures/arrays
Modified Paths:
--------------
trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp
trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.h
trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.h
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp 2008-09-09 20:16:25 UTC (rev 380)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp 2008-09-10 07:29:21 UTC (rev 381)
@@ -34,6 +34,7 @@
#include <GTLCore/Type.h>
#include <GTLCore/Utils_p.h>
#include <GTLCore/VariableNG_p.h>
+#include <GTLCore/Visitor_p.h>
// GTLCore
#include <GTLCore/Debug.h>
@@ -230,6 +231,10 @@
{
result = _context.codeGenerator()->convertValueTo(_bb, result, m_returnExpr->type(), _context.function()->returnType() );
}
+ // Mark the return value
+ const GTLCore::Type* returnType = m_returnExpr->type();
+ const Visitor* visitor = Visitor::getVisitorFor( returnType );
+ _bb = visitor->mark( _context, _bb, result, returnType, CodeGenerator::integerToConstant( -1 ) );
llvm::ReturnInst::Create( result, _bb);
} else {
for( std::list<VariableNG*>::const_iterator it = m_variablesToClean.begin();
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2008-09-09 20:16:25 UTC (rev 380)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2008-09-10 07:29:21 UTC (rev 381)
@@ -674,20 +674,12 @@
return new llvm::LoadInst( countFieldPointer( currentBlock, _pointer ) );
}
-llvm::Value* CodeGenerator::incrementCountFieldOf( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer )
+llvm::Value* CodeGenerator::incrementCountFieldOf( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _increment )
{
+ llvm::Value* pointerCF = countFieldPointer(_currentBlock, _pointer);
llvm::Value* val = createAdditionExpression( _currentBlock,
- new llvm::LoadInst( countFieldPointer(_currentBlock, _pointer), "", _currentBlock ),
- Type::Integer32, integerToConstant(1), Type::Integer32 );
- new llvm::StoreInst( val, _pointer, "", _currentBlock );
+ new llvm::LoadInst( pointerCF, "", _currentBlock ),
+ Type::Integer32, _increment, Type::Integer32 );
+ new llvm::StoreInst( val, pointerCF, "", _currentBlock );
return val;
}
-
-llvm::Value* CodeGenerator::decrementCountFieldOf( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer )
-{
- llvm::Value* val = createSubstractionExpression( _currentBlock,
- new llvm::LoadInst( countFieldPointer(_currentBlock, _pointer), "", _currentBlock ),
- Type::Integer32, integerToConstant(1), Type::Integer32 );
- new llvm::StoreInst( val, _pointer, "", _currentBlock );
- return val;
-}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h 2008-09-09 20:16:25 UTC (rev 380)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h 2008-09-10 07:29:21 UTC (rev 381)
@@ -239,11 +239,7 @@
/**
* Increment the count field.
*/
- static llvm::Value* incrementCountFieldOf( llvm::BasicBlock* currentBlock, llvm::Value* ptr );
- /**
- * Decrement the count field.
- */
- static llvm::Value* decrementCountFieldOf( llvm::BasicBlock* currentBlock, llvm::Value* ptr );
+ static llvm::Value* incrementCountFieldOf( llvm::BasicBlock* currentBlock, llvm::Value* ptr, llvm::Value* _increment );
private:
static llvm::Value* countFieldPointer( llvm::BasicBlock* currentBlock, llvm::Value* ptr );
public:
Modified: trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp 2008-09-09 20:16:25 UTC (rev 380)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp 2008-09-10 07:29:21 UTC (rev 381)
@@ -22,6 +22,7 @@
#include <llvm/Constants.h>
#include <llvm/Instructions.h>
+#include "CodeGenerator_p.h"
#include "Debug.h"
#include "ExpressionResult_p.h"
#include "GenerationContext_p.h"
@@ -125,6 +126,7 @@
GTL_ASSERT( not d->constantPointer );
_currentBlock = cleanUp( _generationContext, _currentBlock, 0 );
d->pointer = _pointer;
+ _currentBlock = d->visitor->mark( _generationContext, _currentBlock, d->pointer, d->type, CodeGenerator::integerToConstant( 1 ) );
return _currentBlock;
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp 2008-09-09 20:16:25 UTC (rev 380)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp 2008-09-10 07:29:21 UTC (rev 381)
@@ -131,6 +131,11 @@
return _currentBlock;
}
+llvm::BasicBlock* PrimitiveVisitor::mark( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value* increment ) const
+{
+ return _currentBlock;
+}
+
//--------- ArrayVisitor ---------///
ArrayVisitor::ArrayVisitor() : Visitor( )
@@ -333,6 +338,37 @@
return afterBlock;
}
+llvm::BasicBlock* ArrayVisitor::mark( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value* _increment ) const
+{
+ CodeGenerator::incrementCountFieldOf( _currentBlock, _pointer, _increment );
+
+ // int i = 0;
+ VariableNG* index = new VariableNG( Type::Integer32, false);
+ index->initialise( _generationContext, _currentBlock, ExpressionResult( _generationContext.codeGenerator()->integerToConstant(0), Type::Integer32), std::list<llvm::Value*>());
+
+ // Construct the body of the for loop
+ llvm::BasicBlock* bodyBlock = llvm::BasicBlock::Create("bodyBlock");
+ _generationContext.llvmFunction()->getBasicBlockList().push_back( bodyBlock);
+ GTL_DEBUG( " value = " << *_pointer << " type = " << *_pointer->getType() << " " << *_pointerType->embeddedType() << " " << *_pointerType );
+ const Visitor* visitor = Visitor::getVisitorFor( _pointerType->embeddedType() );
+ llvm::BasicBlock* endBodyBlock = visitor->mark(
+ _generationContext,
+ bodyBlock,
+ _generationContext.codeGenerator()->accessArrayValue( bodyBlock, _pointer, index->get( _generationContext, bodyBlock ) ),
+ _pointerType->embeddedType(), _increment );
+
+ llvm::BasicBlock* afterBlock = CodeGenerator::createIterationForStatement(
+ _generationContext,
+ _currentBlock,
+ index,
+ getSize( _generationContext, _currentBlock, _pointer),
+ Type::Integer32,
+ bodyBlock,
+ endBodyBlock );
+ delete index;
+ return afterBlock;
+}
+
//--------- VectorVisitor ---------///
@@ -381,6 +417,10 @@
return _currentBlock;
}
+llvm::BasicBlock* VectorVisitor::mark( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value* increment ) const
+{
+ return _currentBlock;
+}
//--------- StructureVisitor ---------///
@@ -468,3 +508,15 @@
}
return _currentBlock;
}
+
+llvm::BasicBlock* StructureVisitor::mark( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value* _increment ) const
+{
+ CodeGenerator::incrementCountFieldOf( _currentBlock, _pointer, _increment );
+ for( uint i = 0; i < _pointerType->countStructDataMembers(); ++i)
+ {
+ const Type* type = _pointerType->structDataMember(i).type();
+ const Visitor* visitor = Visitor::getVisitorFor( type );
+ _currentBlock = visitor->mark( _generationContext, _currentBlock, pointerToValue( _generationContext, _currentBlock, _pointer, i ), type, _increment );
+ }
+ return _currentBlock;
+}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.h 2008-09-09 20:16:25 UTC (rev 380)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.h 2008-09-10 07:29:21 UTC (rev 381)
@@ -94,6 +94,7 @@
*/
virtual llvm::BasicBlock* initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemory) const = 0;
virtual llvm::BasicBlock* cleanUp( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value* _donttouch, bool _allocatedInMemory ) const = 0;
+ virtual llvm::BasicBlock* mark( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value* increment ) const = 0;
public:
/**
* This function create the Visitor for the type given in argument
@@ -117,6 +118,7 @@
virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* pointer, const Type* _pointerType, llvm::Value*, const Type* _valueType, bool _allocatedInMemory) const;
virtual llvm::BasicBlock* initialise(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemory) const;
virtual llvm::BasicBlock* cleanUp( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value* _donttouch, bool _allocatedInMemory ) const;
+ virtual llvm::BasicBlock* mark( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value* increment ) const;
};
/**
* @internal
@@ -134,6 +136,7 @@
virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value*, const Type* _valueType, bool _allocatedInMemory) const;
virtual llvm::BasicBlock* initialise( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemory) const;
virtual llvm::BasicBlock* cleanUp( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value* _donttouch, bool _allocatedInMemory ) const;
+ virtual llvm::BasicBlock* mark( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value* increment ) const;
private:
/**
* Allow to access the size of an array.
@@ -168,6 +171,7 @@
virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* pointer, const Type* _pointerType, llvm::Value*, const Type* _valueType, bool _allocatedInMemory) const;
virtual llvm::BasicBlock* initialise( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemory) const;
virtual llvm::BasicBlock* cleanUp( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value* _donttouch, bool _allocatedInMemory ) const;
+ virtual llvm::BasicBlock* mark( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value* increment ) const;
};
/**
@@ -185,6 +189,7 @@
virtual llvm::BasicBlock* set(GenerationContext& _generationContext, llvm::BasicBlock* currentBlock, llvm::Value* pointer, const Type* _pointerType, llvm::Value*, const Type* _valueType, bool _allocatedInMemory) const;
virtual llvm::BasicBlock* initialise( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemory) const;
virtual llvm::BasicBlock* cleanUp( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value* _donttouch, bool _allocatedInMemory ) const;
+ virtual llvm::BasicBlock* mark( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const Type* _pointerType, llvm::Value* increment ) const;
private:
llvm::Value* pointerToValue(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, int index ) const;
};
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp 2008-09-09 20:16:25 UTC (rev 380)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp 2008-09-10 07:29:21 UTC (rev 381)
@@ -23,6 +23,7 @@
#include <llvm/Instructions.h>
#include "GTLCore/ExpressionResult_p.h"
+#include "GTLCore/CodeGenerator_p.h"
#include "GTLCore/Macros_p.h"
#include "GTLCore/Type.h"
@@ -105,3 +106,9 @@
{
return _currentBlock;
}
+
+llvm::BasicBlock* PixelVisitor::mark( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _increment ) const
+{
+ GTLCore::CodeGenerator::incrementCountFieldOf( _currentBlock, _pointer, _increment );
+ return _currentBlock;
+}
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.h 2008-09-09 20:16:25 UTC (rev 380)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.h 2008-09-10 07:29:21 UTC (rev 381)
@@ -44,6 +44,7 @@
virtual llvm::BasicBlock* set(GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _value, const GTLCore::Type* _valueType, bool _allocatedInMemory) const;
virtual llvm::BasicBlock* initialise(GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, const std::list< llvm::Value*>& _sizes, bool _allocatedInMemory) const;
virtual llvm::BasicBlock* cleanUp( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _donttouch, bool _allocatedInMemory ) const;
+ virtual llvm::BasicBlock* mark( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* increment ) const;
};
}