[opengtl-commits] [267] * add GTLCore:: Type* and wether the result comes from a function to ExpressionResult, and use those new features wherever it is possible |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 267
Author: cyrille
Date: 2008-06-30 21:48:47 +0200 (Mon, 30 Jun 2008)
Log Message:
-----------
* add GTLCore::Type* and wether the result comes from a function to ExpressionResult, and use those new features wherever it is possible
* give AccessorExpression control over affect (on a short term it allows to replace a pointer to a structure when needed)
* include vectors in selection of the best type for operations
* initialize Variable from a pointer coming of the result of a function
* vectorized operation makes llvm 2.2 JIT code crash, so disable MMX, SSEx
* give access to the buffer of a BufferImage
* wrap images from Kernel::evaluatePixeles (fix crash)
* parse structures in OpenShiva
* can affect the value of a pixel returned from a function to an other pixel
* make a blur.shiva that work with the current capabilities of OpenShiva
* add test for copy of vectors
Modified Paths:
--------------
trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp
trunk/OpenGTL/OpenCTL/tests/statements/return.ctl
trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h
trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp
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/ExpressionResult_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/ExpressionResult_p.h
trunk/OpenGTL/OpenGTL/GTLCore/Type.h
trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h
trunk/OpenGTL/OpenGTL/GTLCore/VirtualMachine_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.h
trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp
trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva
trunk/OpenGTL/OpenShiva/tests/vectors/CMakeLists.txt
trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp
trunk/OpenGTL/OpenShiva/tools/tester/CMakeLists.txt
trunk/OpenGTL/TODO
Added Paths:
-----------
trunk/OpenGTL/OpenShiva/tests/vectors/copy.shiva
trunk/OpenGTL/OpenShiva/tests/vectors/copy4.shiva
Modified: trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/Program.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -24,6 +24,7 @@
#include "GTLCore/CodeGenerator_p.h"
#include "GTLCore/GenerationContext_p.h"
#include "GTLCore/PixelDescription.h"
+#include "GTLCore/ExpressionResult_p.h"
#include "GTLCore/Function.h"
#include "GTLCore/Function_p.h"
#include "GTLCore/Parameter.h"
@@ -189,7 +190,7 @@
} else {
vng = new GTLCore::VariableNG(GTLCore::Type::Integer32, false );
}
- vng->initialise( gc, initialBlock, 0, 0, std::list<llvm::Value*>());
+ vng->initialise( gc, initialBlock, GTLCore::ExpressionResult(), std::list<llvm::Value*>());
buffer[i] = vng;
} else {
buffer[i] = 0;
@@ -208,9 +209,9 @@
// Construct the "conditions" of the loop
// int i = 0;
GTLCore::VariableNG* posSrc = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
- posSrc->initialise( gc, initialBlock, cg.integerToConstant(0), GTLCore::Type::Integer32, std::list<llvm::Value*>());
+ posSrc->initialise( gc, initialBlock, GTLCore::ExpressionResult(cg.integerToConstant(0), GTLCore::Type::Integer32), std::list<llvm::Value*>());
GTLCore::VariableNG* posDst = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
- posDst->initialise( gc, initialBlock, cg.integerToConstant(0), GTLCore::Type::Integer32, std::list<llvm::Value*>());
+ posDst->initialise( gc, initialBlock, GTLCore::ExpressionResult(cg.integerToConstant(0), GTLCore::Type::Integer32), std::list<llvm::Value*>());
// i < size
llvm::BasicBlock* forTestBlock = new llvm::BasicBlock("forTestBlock");
func->getBasicBlockList().push_back( forTestBlock);
Modified: trunk/OpenGTL/OpenCTL/tests/statements/return.ctl
===================================================================
--- trunk/OpenGTL/OpenCTL/tests/statements/return.ctl 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenCTL/tests/statements/return.ctl 2008-06-30 19:48:47 UTC (rev 267)
@@ -20,5 +20,7 @@
assert( floatFunction( 42 ) == 42 );
assert( boolFunction( true ) == true );
assert( boolFunction( false ) == false );
+ int v = intFunction( 10 );
+ assert( v == 10 );
return 0;
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -39,9 +39,16 @@
llvm::Value* ptr_ = pointer( _gc, _bb );
GTL_ASSERT(ptr_);
const Visitor* visitor = Visitor::getVisitorFor( type() );
- return GTLCore::ExpressionResult( visitor->get( _gc, _bb, ptr_ ) );
+ return GTLCore::ExpressionResult( visitor->get( _gc, _bb, ptr_ ), type() );
}
+llvm::BasicBlock* AccessorExpression::affect( GenerationContext& _gc, llvm::BasicBlock* _bb, const ExpressionResult& _value )
+{
+ llvm::Value* ptr_ = pointer( _gc, _bb );
+ const Visitor* visitor = Visitor::getVisitorFor( type() );
+ return visitor->set( _gc, _bb, ptr_, type(), _value.value(), _value.type(), allocatedInMemory());
+}
+
//------------------- ArraySizeAccessorExpression -------------------//
ArraySizeAccessorExpression::ArraySizeAccessorExpression(AccessorExpression* _parent )
@@ -170,6 +177,16 @@
return m_variable->allocatedInMemory();
}
+llvm::BasicBlock* VariableAccessorExpression::affect( GenerationContext& _gc, llvm::BasicBlock* _bb, const ExpressionResult& _value )
+{
+ if( _value.functionResult() and (type()->dataType() == Type::ARRAY or type()->dataType() == Type::STRUCTURE ) and not m_variable->constantPointer() )
+ {
+ return m_variable->replacePointer( _gc, _bb, _value.value() );
+ } else {
+ return AccessorExpression::affect( _gc, _bb, _value );
+ }
+}
+
//------------------- FunctionMemberAccessorExpression -------------------//
FunctionMemberAccessorExpression::FunctionMemberAccessorExpression( AccessorExpression * _parent,
@@ -192,7 +209,7 @@
GTLCore::ExpressionResult FunctionMemberAccessorExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return GTLCore::ExpressionResult( _gc.codeGenerator()->callFunction( _gc, bb, m_member->function(), m_arguments ) );
+ return _gc.codeGenerator()->callFunction( _gc, bb, m_member->function(), m_arguments );
}
llvm::Value* FunctionMemberAccessorExpression::pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h 2008-06-30 19:48:47 UTC (rev 267)
@@ -24,7 +24,7 @@
#include "../Type.h"
namespace GTLCore {
-
+ class ExpressionResult;
namespace AST {
class AccessorExpression : public Expression {
public:
@@ -32,6 +32,7 @@
public:
virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* _bb) const = 0;
virtual bool allocatedInMemory() const = 0;
+ virtual llvm::BasicBlock* affect( GenerationContext& _gc, llvm::BasicBlock* _bb, const ExpressionResult& _value );
};
class ArraySizeAccessorExpression : public AccessorExpression {
public:
@@ -79,6 +80,7 @@
virtual llvm::Value* pointer(GenerationContext& _gc, llvm::BasicBlock* bb) const;
virtual void markAsReturnExpression();
virtual bool allocatedInMemory() const;
+ virtual llvm::BasicBlock* affect( GenerationContext& _gc, llvm::BasicBlock* _bb, const ExpressionResult& _value );
private:
GTLCore::VariableNG* m_variable;
};
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -28,6 +28,9 @@
#include <GTLCore/VariableNG_p.h>
#include <GTLCore/Visitor_p.h>
+#include "AccessorExpression.h"
+#include "Expression.h"
+
using namespace GTLCore::AST;
BinaryExpression::~BinaryExpression()
@@ -191,12 +194,10 @@
llvm::BasicBlock* AssignementBinaryExpression::generateStatement( GenerationContext& _gc, llvm::BasicBlock* _bb) const
{
GTL_ASSERT( m_lhs);
- llvm::Value* ptr_ = m_lhs->pointer( _gc, _bb );
- const Visitor* visitor = Visitor::getVisitorFor( m_lhs->type() );
GTL_DEBUG( *m_lhs->type() );
GTL_DEBUG( *rightHandSide()->type() );
- return visitor->set( _gc, _bb, ptr_, m_lhs->type(),
- rightHandSide()->generateValue( _gc, _bb).value(), rightHandSide()->type(), false );
+ ExpressionResult rhsValue = rightHandSide()->generateValue( _gc, _bb);
+ return m_lhs->affect( _gc, _bb, rhsValue );
}
GTLCore::ExpressionResult AssignementBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* _bb ) const
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/CoumpoundExpression.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -86,7 +86,7 @@
GTL_DEBUG( arrayStruct[1] );*/
return GTLCore::ExpressionResult(
- llvm::ConstantStruct::get( structType, arrayStruct ) );
+ llvm::ConstantStruct::get( structType, arrayStruct ), type() );
} else if( m_type->dataType() == Type::STRUCTURE )
{
std::vector<llvm::Constant*> members;
@@ -96,7 +96,7 @@
}
const llvm::StructType* structType = dynamic_cast<const llvm::StructType*>( m_type->d->type() );
return GTLCore::ExpressionResult(
- llvm::ConstantStruct::get( structType, members ) );
+ llvm::ConstantStruct::get( structType, members ), type() );
}
GTL_ABORT("Can't generate coumpound value, neither array, neither expression.");
return GTLCore::ExpressionResult();
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Expression.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -71,7 +71,7 @@
GTLCore::ExpressionResult GlobalDataExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
llvm::Constant* value = m_expression->generateValue( _gc, 0 ).constant();
- return GTLCore::ExpressionResult( new llvm::GlobalVariable( value->getType(), true, llvm::GlobalValue::InternalLinkage, value, "", _gc.llvmModule() ) );
+ return GTLCore::ExpressionResult( new llvm::GlobalVariable( value->getType(), true, llvm::GlobalValue::InternalLinkage, value, "", _gc.llvmModule() ), type() );
}
//------------------------------------------//
@@ -119,7 +119,7 @@
template<>
GTLCore::ExpressionResult NumberExpression<float>::generateValue( GenerationContext& _gc, llvm::BasicBlock* ) const
{
- return GTLCore::ExpressionResult(_gc.codeGenerator()->floatToConstant( m_val ));
+ return GTLCore::ExpressionResult(_gc.codeGenerator()->floatToConstant( m_val ), type());
}
template<>
@@ -130,7 +130,7 @@
template<>
GTLCore::ExpressionResult NumberExpression<int>::generateValue( GenerationContext& _gc, llvm::BasicBlock* ) const
{
- return GTLCore::ExpressionResult(_gc.codeGenerator()->integerToConstant( m_val ));
+ return GTLCore::ExpressionResult(_gc.codeGenerator()->integerToConstant( m_val ), type());
}
template<>
@@ -141,12 +141,12 @@
template<>
GTLCore::ExpressionResult NumberExpression<bool>::generateValue( GenerationContext& _gc, llvm::BasicBlock* ) const
{
- return GTLCore::ExpressionResult(_gc.codeGenerator()-> boolToConstant(m_val ));
+ return GTLCore::ExpressionResult(_gc.codeGenerator()-> boolToConstant(m_val ), type());
}
}
}
GTLCore::ExpressionResult StringExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return GTLCore::ExpressionResult(llvm::ConstantArray::get(m_string, true )); // return a null terminated string
+ return GTLCore::ExpressionResult(llvm::ConstantArray::get(m_string, true ), Type::Integer8 ); // return a null terminated string
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/FunctionDeclaration.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -172,7 +172,7 @@
{
(*pv_it)->initialise( generationContext, arg_it );
} else {
- firstBlock = (*pv_it)->initialise( generationContext, firstBlock, arg_it, it->type(), std::list<llvm::Value*>() );
+ firstBlock = (*pv_it)->initialise( generationContext, firstBlock, ExpressionResult( arg_it, it->type()), std::list<llvm::Value*>() );
}
}
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -86,12 +86,10 @@
llvm::BasicBlock* VariableDeclaration::generateStatement( GenerationContext& _context, llvm::BasicBlock* _bb ) const
{
- llvm::Value* initialiserValue = 0;
- const Type* initialiserType = 0;
+ ExpressionResult initialiserValue;
if( m_initialiser )
{
- initialiserValue = m_initialiser->generateValue( _context, _bb).value();
- initialiserType = m_initialiser->type();
+ initialiserValue = m_initialiser->generateValue( _context, _bb);
}
std::list<llvm::Value*> initialSizeValues;
if( not m_initialSizes.empty() )
@@ -107,7 +105,7 @@
}
}
}
- _bb = m_variable->initialise( _context, _bb, initialiserValue, initialiserType, initialSizeValues);
+ _bb = m_variable->initialise( _context, _bb, initialiserValue, initialSizeValues);
if(m_functionInitialiser)
{
return m_functionInitialiser->generateStatement( _context, _bb );
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -308,9 +308,9 @@
#define CREATE_BINARY_OPERATOR( _creator_, _v1_, _v2_) \
if( _v1_.isConstant() and _v2_.isConstant() ) \
{ \
- return GTLCore::ExpressionResult( _creator_(_v1_.constant(), lhsType, _v2_.constant(), rhsType )); \
+ return GTLCore::ExpressionResult( _creator_(_v1_.constant(), lhsType, _v2_.constant(), rhsType ), highestPriorityType); \
} else { \
- return GTLCore::ExpressionResult( _creator_( currentBlock, _v1_.value(), lhsType, _v2_.value(), rhsType )); \
+ return GTLCore::ExpressionResult( _creator_( currentBlock, _v1_.value(), lhsType, _v2_.value(), rhsType ), highestPriorityType); \
}
#define CREATE_BINARY_EXPRESSION(_GTL_Function_Name_, _LLVM_Constant_Expr_, _LLVM_Binary_Operator ) \
@@ -483,18 +483,18 @@
UNIFORMIZE_TYPES(lhs, rhs);
if( v1.isConstant() and v2.isConstant() )
{
- return GTLCore::ExpressionResult(createComparisonExpression( v1.constant(), lhsType, v2.constant(), rhsType, unsignedIntegerPred, signedIntegerPred, floatPred));
+ return GTLCore::ExpressionResult(createComparisonExpression( v1.constant(), lhsType, v2.constant(), rhsType, unsignedIntegerPred, signedIntegerPred, floatPred), Type::Boolean);
} else {
- return GTLCore::ExpressionResult(createComparisonExpression( currentBlock, v1.value(), lhsType, v2.value(), rhsType, unsignedIntegerPred, signedIntegerPred, floatPred));
+ return GTLCore::ExpressionResult(createComparisonExpression( currentBlock, v1.value(), lhsType, v2.value(), rhsType, unsignedIntegerPred, signedIntegerPred, floatPred), Type::Boolean);
}
}
#define CREATE_UNARY_OPERATOR( _creator_, _v1_) \
if( _v1_.isConstant() ) \
{ \
- return GTLCore::ExpressionResult( _creator_(_v1_.constant(), rhsType)); \
+ return GTLCore::ExpressionResult( _creator_(_v1_.constant(), rhsType), rhsType); \
} else { \
- return GTLCore::ExpressionResult( _creator_( currentBlock, _v1_.value(), rhsType ) ); \
+ return GTLCore::ExpressionResult( _creator_( currentBlock, _v1_.value(), rhsType ), rhsType ); \
}
ExpressionResult CodeGenerator::createMinusExpression( llvm::BasicBlock* currentBlock, ExpressionResult rhs, const Type* rhsType)
@@ -544,8 +544,20 @@
const Type* CodeGenerator::selectType(const Type* type1, const Type* type2)
{
- if( type1 == Type::Float or type2 == Type::Float )
+ if( type1 == type2 )
{
+ return type1;
+ } else if( type1->dataType() == Type::VECTOR and type2->dataType() == Type::VECTOR )
+ {
+ const Type* best = selectType( type1->embeddedType(), type2->embeddedType() );
+ if( type1->embeddedType() == best) return type1;
+ else return type2;
+ } else if( type1->dataType() == Type::VECTOR ) {
+ return type1;
+ } else if( type2->dataType() == Type::VECTOR ) {
+ return type2;
+ } else if( type1 == Type::Float or type2 == Type::Float )
+ {
return Type::Float;
} else if( type1 == Type::Integer32 or type2 == Type::Integer32 )
{
@@ -644,5 +656,5 @@
llvm::CallInst *CallFunc = new llvm::CallInst(llvmFunction, convertedParams.begin(), convertedParams.end(), "", bb);
CallFunc->setTailCall();
- return GTLCore::ExpressionResult( CallFunc );
+ return GTLCore::ExpressionResult( CallFunc, _function->returnType(), true );
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h 2008-06-30 19:48:47 UTC (rev 267)
@@ -118,17 +118,17 @@
static ExpressionResult createAdditionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
static llvm::Constant* createAdditionExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
// Substraction
- llvm::Value* createSubstractionExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
- ExpressionResult createSubstractionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
- llvm::Constant* createSubstractionExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
+ static llvm::Value* createSubstractionExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ static ExpressionResult createSubstractionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ static llvm::Constant* createSubstractionExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
// Multiplication
- llvm::Value* createMultiplicationExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
- ExpressionResult createMultiplicationExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
- llvm::Constant* createMultiplicationExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
+ static llvm::Value* createMultiplicationExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ static ExpressionResult createMultiplicationExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ static llvm::Constant* createMultiplicationExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
// Division
- llvm::Value* createDivisionExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
- llvm::Constant* createDivisionExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
- ExpressionResult createDivisionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ static llvm::Value* createDivisionExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
+ static llvm::Constant* createDivisionExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
+ static ExpressionResult createDivisionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
// Modulo
llvm::Value* createModuloExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
llvm::Constant* createModuloExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
Modified: trunk/OpenGTL/OpenGTL/GTLCore/ExpressionResult_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ExpressionResult_p.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ExpressionResult_p.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -20,9 +20,12 @@
#include "ExpressionResult_p.h"
#include "llvm/Constant.h"
+#include "llvm/DerivedTypes.h"
+#include "Type.h"
+#include "Type_p.h"
+
#include "Debug.h"
-#include "ScopedName.h"
using namespace GTLCore;
@@ -33,45 +36,40 @@
llvm::Constant* constant;
} valueOrConstant;
bool isConstant;
- GTLCore::ScopedName name; ///< name of the variable, or empty if not directly a variable
+ bool functionResult;
+ const GTLCore::Type* type;
};
ExpressionResult::ExpressionResult() : d(new Private)
{
d->valueOrConstant.value = 0;
d->isConstant = false;
+ d->functionResult = false;
+ d->type = Type::Undefined;
}
-ExpressionResult::ExpressionResult(llvm::Value* value, const GTLCore::ScopedName& _name) : d(new Private)
+ExpressionResult::ExpressionResult(llvm::Value* _value, const GTLCore::Type* _type, bool _functionResult) : d(new Private)
{
- GTL_ASSERT( value );
- d->name = _name;
- d->valueOrConstant.value = value;
+ GTL_ASSERT( _value );
+ GTL_ASSERT( _type );
+ GTL_ASSERT( _value->getType() == _type->d->type() or _value->getType() == _type->d->asArgumentType() );
+ d->valueOrConstant.value = _value;
d->isConstant = false;
+ d->functionResult = _functionResult;
+ d->type = _type;
}
-ExpressionResult::ExpressionResult(llvm::Constant* constant, const GTLCore::ScopedName& _name) : d(new Private)
+ExpressionResult::ExpressionResult(llvm::Constant* _constant, const GTLCore::Type* _type, bool _functionResult) : d(new Private)
{
- GTL_ASSERT( constant );
- d->name = _name;
- d->valueOrConstant.constant = constant;
+ GTL_ASSERT( _constant );
+ GTL_ASSERT( _type );
+ GTL_ASSERT( _constant->getType() == _type->d->type() or _constant->getType() == _type->d->asArgumentType() or llvm::isa<llvm::ArrayType>(_constant->getType()) );
+ d->valueOrConstant.constant = _constant;
d->isConstant = true;
+ d->functionResult = _functionResult;
+ d->type = _type;
}
-ExpressionResult::ExpressionResult(llvm::Value* value) : d(new Private)
-{
- GTL_ASSERT( value );
- d->valueOrConstant.value = value;
- d->isConstant = false;
-}
-
-ExpressionResult::ExpressionResult(llvm::Constant* constant) : d(new Private)
-{
- GTL_ASSERT( constant );
- d->valueOrConstant.constant = constant;
- d->isConstant = true;
-}
-
ExpressionResult::ExpressionResult(const ExpressionResult& rhs ) : d(new Private(*rhs.d))
{
}
@@ -87,24 +85,41 @@
delete d;
}
-bool ExpressionResult::isConstant() const { return d->isConstant; }
-const GTLCore::ScopedName& ExpressionResult::name() const { return d->name; }
-llvm::Value* ExpressionResult::value() { return d->valueOrConstant.value; }
+bool ExpressionResult::isConstant() const
+{
+ return d->isConstant;
+}
+
+llvm::Value* ExpressionResult::value() const
+{
+ return d->valueOrConstant.value;
+}
+
void ExpressionResult::setValue( llvm::Value* v)
{
d->valueOrConstant.value = v;
d->isConstant = false;
- d->name = GTLCore::ScopedName();
}
-llvm::Constant* ExpressionResult::constant()
+
+llvm::Constant* ExpressionResult::constant() const
{
GTL_ASSERT( dynamic_cast<llvm::Constant*>(d->valueOrConstant.value));
if(d->isConstant) return d->valueOrConstant.constant;
return 0;
}
+
void ExpressionResult::setConstant( llvm::Constant* v)
{
d->valueOrConstant.constant = v;
d->isConstant = true;
- d->name = GTLCore::ScopedName();
}
+
+const GTLCore::Type* ExpressionResult::type() const
+{
+ return d->type;
+}
+
+bool ExpressionResult::functionResult() const
+{
+ return d->functionResult;
+}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/ExpressionResult_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ExpressionResult_p.h 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ExpressionResult_p.h 2008-06-30 19:48:47 UTC (rev 267)
@@ -26,7 +26,7 @@
}
namespace GTLCore {
- class ScopedName;
+ class Type;
/**
* @internal
*
@@ -41,19 +41,18 @@
* Construct an empty expression result.
*/
ExpressionResult();
- ExpressionResult(llvm::Value* value, const GTLCore::ScopedName& _name);
- ExpressionResult(llvm::Constant* constant, const GTLCore::ScopedName& _name);
- explicit ExpressionResult(llvm::Value* value);
- explicit ExpressionResult(llvm::Constant* constant);
+ explicit ExpressionResult(llvm::Value* _value, const GTLCore::Type* _type, bool _functionResult = false);
+ explicit ExpressionResult(llvm::Constant* _constant, const GTLCore::Type* _type, bool _functionResult = false);
ExpressionResult(const ExpressionResult& rhs );
ExpressionResult operator=(const ExpressionResult& rhs );
~ExpressionResult();
bool isConstant() const;
- const GTLCore::ScopedName& name() const;
- llvm::Value* value();
+ llvm::Value* value() const;
void setValue( llvm::Value* v);
- llvm::Constant* constant();
+ llvm::Constant* constant() const;
void setConstant( llvm::Constant* v);
+ const GTLCore::Type* type() const;
+ bool functionResult() const;
private:
struct Private;
Private* const d;
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Type.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Type.h 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Type.h 2008-06-30 19:48:47 UTC (rev 267)
@@ -63,6 +63,7 @@
friend class TypeManager;
friend class Visitor;
friend class VectorVisitor;
+ friend class ExpressionResult;
friend std::ostream& operator<< (std::ostream& ostr, const Type& type);
public:
enum DataType {
Modified: trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -23,6 +23,7 @@
#include <llvm/Instructions.h>
#include "Debug.h"
+#include "ExpressionResult_p.h"
#include "GenerationContext_p.h"
#include "Type.h"
#include "Type_p.h"
@@ -39,6 +40,7 @@
bool isInitialised;
llvm::Value* pointer;
bool allocatedInMemory;
+ bool constantPointer;
};
VariableNG::VariableNG(const GTLCore::Type* _type, bool _constant ) : d(new Private)
@@ -49,7 +51,9 @@
d->visitor = Visitor::getVisitorFor( _type );
d->pointer = 0;
d->allocatedInMemory = false;
+ d->constantPointer = false;
}
+
VariableNG::~VariableNG()
{
delete d;
@@ -63,24 +67,31 @@
return d->type;
}
-llvm::BasicBlock* VariableNG::initialise( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _bb, llvm::Value* _initialiser, const GTLCore::Type* _initialiserType, const std::list<llvm::Value*>& _initialSize )
+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;
- if( d->allocatedInMemory
+ if( _initialiser.value() and _initialiser.functionResult()
and (type()->dataType() == Type::ARRAY or type()->dataType() == Type::STRUCTURE ) )
{
- pointer = new llvm::MallocInst( d->type->d->type(), llvm::ConstantInt::get(llvm::Type::Int32Ty, 1), "", _bb);
+ initialise( _generationContext, _initialiser.value() );
} else {
- pointer = new llvm::AllocaInst( d->type->d->type(), llvm::ConstantInt::get(llvm::Type::Int32Ty, 1), "", _bb);
+ if( d->allocatedInMemory
+ and (type()->dataType() == Type::ARRAY or type()->dataType() == Type::STRUCTURE ) )
+ {
+ 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);
+ }
+ initialise( _generationContext, pointer );
+ _bb = d->visitor->initialise( _generationContext, _bb, d->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);
+ }
}
- initialise( _generationContext, pointer );
- _bb = d->visitor->initialise( _generationContext, _bb, d->pointer, d->type, _initialSize, d->allocatedInMemory);
-
- if( _initialiser )
- {
- _bb = d->visitor->set( _generationContext, _bb, d->pointer, d->type, _initialiser, _initialiserType , d->allocatedInMemory);
- }
+ d->constantPointer = false;
return _bb;
}
@@ -89,6 +100,7 @@
GTL_ASSERT(not d->isInitialised);
d->isInitialised = true;
d->pointer = _pointer;
+ d->constantPointer = true;
}
llvm::Value* VariableNG::get(GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock)
@@ -106,6 +118,7 @@
llvm::BasicBlock* VariableNG::replacePointer( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer)
{
GTL_ASSERT( _pointer->getType() == d->pointer->getType() );
+ GTL_ASSERT( not d->constantPointer );
_currentBlock = cleanUp( _generationContext, _currentBlock, 0 );
d->pointer = _pointer;
return _currentBlock;
@@ -119,7 +132,10 @@
void VariableNG::setAllocateInMemory( bool v )
{
GTL_ASSERT( not d->isInitialised );
- d->allocatedInMemory = v;
+ if(type()->dataType() == Type::ARRAY or type()->dataType() == Type::STRUCTURE )
+ {
+ d->allocatedInMemory = v;
+ }
}
bool VariableNG::allocatedInMemory() const
@@ -127,6 +143,11 @@
return d->allocatedInMemory;
}
+bool VariableNG::constantPointer() const
+{
+ return d->constantPointer;
+}
+
llvm::BasicBlock* VariableNG::cleanUp( GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _donttouch )
{
if( d->allocatedInMemory )
Modified: trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VariableNG_p.h 2008-06-30 19:48:47 UTC (rev 267)
@@ -29,6 +29,7 @@
namespace GTLCore {
class GenerationContext;
+ class ExpressionResult;
class Type;
/**
* VariableNG is the class for manipulating variables, getting and settng the values.
@@ -47,7 +48,7 @@
* @param _initialiser initial value of the variable
* @param _initialSize the initial size of the variable
*/
- llvm::BasicBlock* initialise( GenerationContext&, llvm::BasicBlock* _bb, llvm::Value* _initialiser, const GTLCore::Type* _initialiserType, const std::list<llvm::Value*>& _initialSize );
+ llvm::BasicBlock* initialise( GenerationContext&, llvm::BasicBlock* _bb, const ExpressionResult& _initialiser, const std::list<llvm::Value*>& _initialSize );
/**
* 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
@@ -96,6 +97,10 @@
*/
bool allocatedInMemory() const;
/**
+ * @return true if the pointer is constant (which means it can't be replaced)
+ */
+ bool constantPointer() const;
+ /**
* Cleanup the variable, free memory if needed, but don't touch the
* value in argument.
* @param _donttouch variable protected in memory
Modified: trunk/OpenGTL/OpenGTL/GTLCore/VirtualMachine_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/VirtualMachine_p.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/VirtualMachine_p.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -30,6 +30,8 @@
#include <llvm/ModuleProvider.h>
#include <llvm/DerivedTypes.h>
+#include "llvm/Support/CommandLine.h"
+
using namespace GTLCore;
struct VirtualMachine::Private {
@@ -42,6 +44,11 @@
VirtualMachine::VirtualMachine() : d(new Private)
{
d->executionEngine = 0;
+ char** argv = new char*[2];
+ argv[0] = const_cast<char*>( "GTLVM");
+// argv[1] = const_cast<char*>( "-mcpu=i386" ); // WE ARE NOT AT A HACK MORE
+ argv[1] = const_cast<char*>( "-mattr=-3dnow,-3dnowa,-mmx,-sse,-sse2,-sse3,-ssse3" ); // WE ARE NOT AT A HACK MORE
+ llvm::cl::ParseCommandLineOptions(2, argv, ""); // DISABLE MMX/SSE TODO check if more recent version of llvm support vectors in structure
GTLCore::String errorMessage;
d->executionEngine = llvm::ExecutionEngine::create( new llvm::ExistingModuleProvider( new llvm::Module("dummy") ), false, &errorMessage);
GTL_DEBUG("Error while creating execution engine : " << errorMessage);
@@ -55,12 +62,8 @@
void VirtualMachine::registerModule( llvm::ModuleProvider* mp)
{
- if(d->executionEngine)
- {
- d->executionEngine->addModuleProvider(mp);
- } else {
-// d->executionEngine = llvm::ExecutionEngine::create(mp, false);
- }
+ GTL_ASSERT(d->executionEngine);
+ d->executionEngine->addModuleProvider(mp);
}
void VirtualMachine::unregisterModule( llvm::ModuleProvider* mp)
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Visitor_p.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -173,7 +173,7 @@
}
// int i = 0;
VariableNG* index = new VariableNG( Type::Integer32, false);
- index->initialise( _generationContext, _currentBlock, _generationContext.codeGenerator()->integerToConstant(0), Type::Integer32, std::list<llvm::Value*>());
+ 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 = new llvm::BasicBlock("bodyBlock");
@@ -255,7 +255,7 @@
sizeAfter.pop_front();
// int i = 0;
VariableNG* index = new VariableNG( Type::Integer32, false);
- index->initialise( _generationContext, _currentBlock, _generationContext.codeGenerator()->integerToConstant(0), Type::Integer32, std::list<llvm::Value*>());
+ 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 = new llvm::BasicBlock("bodyBlock");
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -42,6 +42,7 @@
d->height = _height;
d->defaultPixel = new char[ pixelSize() ];
memset( d->defaultPixel, 0, pixelSize() );
+ SHIVA_DEBUG( d->buffer->size() << " " << d->lineWidth << " " << _height);
SHIVA_ASSERT( d->buffer->size() == d->lineWidth * _height );
}
@@ -76,3 +77,8 @@
{
return d->height;
}
+
+const GTLCore::Buffer* BufferImage::buffer() const
+{
+ return d->buffer;
+}
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.h 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.h 2008-06-30 19:48:47 UTC (rev 267)
@@ -57,6 +57,7 @@
int height() const;
protected:
int lineWidth() const;
+ const GTLCore::Buffer* buffer() const;
private:
struct Private;
Private* const d;
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -31,6 +31,7 @@
#include <llvm/ParameterAttributes.h>
#include "GTLCore/CodeGenerator_p.h"
+#include "GTLCore/ExpressionResult_p.h"
#include "GTLCore/Function.h"
#include "GTLCore/Function_p.h"
#include "GTLCore/GenerationContext_p.h"
@@ -234,7 +235,7 @@
llvm::Value* arg_result = arg_it;
// Create the pixel
GTLCore::VariableNG* resultVar = new GTLCore::VariableNG( _moduleData->typeManager()->getStructure( "pixel" ), false );
- resultVar->initialise( generationContext, initialBlock, 0, 0, std::list<llvm::Value*>());
+ resultVar->initialise( generationContext, initialBlock, GTLCore::ExpressionResult(), std::list<llvm::Value*>());
// Get the evaluatePixel function
GTLCore::Function* ePFunction = _moduleData->function( _kernel->name(), "evaluatePixel" );
SHIVA_ASSERT( ePFunction );
@@ -255,8 +256,8 @@
// int j = 0;
GTLCore::VariableNG* incJ = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
incJ->initialise( generationContext, initialBlock,
- arg_x,
- GTLCore::Type::Integer32, std::list<llvm::Value*>());
+ GTLCore::ExpressionResult( arg_x, GTLCore::Type::Integer32),
+ std::list<llvm::Value*>());
// {
llvm::BasicBlock* firstBlockJLoop = new llvm::BasicBlock;
@@ -265,8 +266,8 @@
// int i = 0;
GTLCore::VariableNG* incI = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
incI->initialise( generationContext, firstBlockJLoop,
- arg_y,
- GTLCore::Type::Integer32, std::list<llvm::Value*>());
+ GTLCore::ExpressionResult( arg_y, GTLCore::Type::Integer32),
+ std::list<llvm::Value*>());
// {
llvm::BasicBlock* firstBlockILoop = new llvm::BasicBlock;
@@ -280,6 +281,7 @@
// Call evaluatePixel
llvm::Function* llvmEPFunction = ePFunction->d->data->function( countArguments );
SHIVA_ASSERT( llvmEPFunction );
+ SHIVA_DEBUG( evaluatePixel_params.size() );
new llvm::CallInst( llvmEPFunction, evaluatePixel_params.begin(), evaluatePixel_params.end(), "", firstBlockILoop );
// Synchronize the output pixel with input
@@ -323,18 +325,15 @@
// template<bool _TAllFloat_, int _TChannels_>
// void memToVec( vec4* _dst, char* _imgData)
// {
- // char *src;
// if( _TAllFloat_ )
// {
- // src = _imgData;
+ // memcpy( (char*)result, src, _TChannels * 4 );
// } else {
- // src = float[ _TChannels_ ];
// for(int i = 0; i < _TChannels; ++i)
// {
- // convert( i, _imgData, src );
+ // result[i] = convert(_imgData + pos(i) )
// }
// }
- // memcpy( (char*)result, src, _TChannels * 4 );
// }
GTLCore::CodeGenerator codeGenerator( _moduleData );
@@ -356,33 +355,61 @@
// {
llvm::BasicBlock* currentBlock = new llvm::BasicBlock;
func->getBasicBlockList().push_back( currentBlock );
- // char *src;
- llvm::Value* srcPtr = 0;
// if( _TAllFloat_ )
if( allFloat )
// {
{
- // src = _imgData;
- srcPtr = arg_imgData;
+ // memcpy( (char*)result, src, _TChannels * 4 );
+ callMemcpy( generationContext, currentBlock,
+ GTLCore::CodeGenerator::convertPointerToCharP( currentBlock, arg_dst),
+ arg_imgData, GTLCore::CodeGenerator::integerToConstant( sizeof(float) * 4 ) );
// } else {
} else {
- // src = (char*)new float[ _TChannels_ ];
- srcPtr = new llvm::AllocaInst( llvm::IntegerType::get(8),
- GTLCore::CodeGenerator::integerToConstant( 32 * channelsNb / 4 ),
- "", currentBlock );
// for(int i = 0; i < _TChannels; ++i)
+ int currentPos = 0;
+ llvm::Value* floatVec = new llvm::LoadInst( arg_dst, "", currentBlock );
+ for( int i = 0; i < channelsNb; ++i)
// {
- // convert( i, _imgData, src );
+ {
+ // result[i] = convert(_imgData + pos(i) )
+ // _imgData + pos(i);
+ const GTLCore::Type* channelType = _pixelDescription.channelTypes()[i];
+ llvm::Value* posInP = new llvm::GetElementPtrInst( arg_imgData, GTLCore::CodeGenerator::integerToConstant( currentPos ), "", currentBlock );
+ llvm::Value* posInPNative = GTLCore::CodeGenerator::convertPointerTo( currentBlock, posInP, channelType->d->type() );
+ llvm::Value* nativeValue = new llvm::LoadInst( posInPNative, "", currentBlock );
+ // convert(_imgData + pos(i) )
+ llvm::Value* floatValue = GTLCore::CodeGenerator::convertValueTo( currentBlock, nativeValue, channelType, GTLCore::Type::Float );
+ switch( channelType->dataType() )
+ {
+ case GTLCore::Type::INTEGER8:
+ floatValue = GTLCore::CodeGenerator::createAdditionExpression( currentBlock, floatValue, GTLCore::Type::Float, GTLCore::CodeGenerator::floatToConstant( 127.0 ), GTLCore::Type::Float);
+ case GTLCore::Type::UNSIGNED_INTEGER8:
+ floatValue = GTLCore::CodeGenerator::createDivisionExpression( currentBlock, floatValue, GTLCore::Type::Float, GTLCore::CodeGenerator::floatToConstant( 255.0 ), GTLCore::Type::Float);
+ break;
+ case GTLCore::Type::INTEGER16:
+ floatValue = GTLCore::CodeGenerator::createAdditionExpression( currentBlock, floatValue, GTLCore::Type::Float, GTLCore::CodeGenerator::floatToConstant( 32767.0 ), GTLCore::Type::Float);
+ case GTLCore::Type::UNSIGNED_INTEGER16:
+ floatValue = GTLCore::CodeGenerator::createDivisionExpression( currentBlock, floatValue, GTLCore::Type::Float, GTLCore::CodeGenerator::floatToConstant( 65535.0 ), GTLCore::Type::Float);
+ break;
+ case GTLCore::Type::INTEGER32:
+ floatValue = GTLCore::CodeGenerator::createAdditionExpression( currentBlock, floatValue, GTLCore::Type::Float, GTLCore::CodeGenerator::floatToConstant( 2147483647.0 ), GTLCore::Type::Float);
+ case GTLCore::Type::UNSIGNED_INTEGER32:
+ floatValue = GTLCore::CodeGenerator::createDivisionExpression( currentBlock, floatValue, GTLCore::Type::Float, GTLCore::CodeGenerator::floatToConstant( 4294967295.0 ), GTLCore::Type::Float);
+ break;
+ default:
+ GTL_ABORT("unimplemented");
+ }
+
+ // result[i] = convert(_imgData + pos(i) )
+ floatVec = new llvm::InsertElementInst( floatVec, floatValue, i, "", currentBlock);
+ GTL_ASSERT(channelType->bitsSize() % 8 == 0);
+ currentPos += channelType->bitsSize() / 8;
// }
- GTL_ABORT("unimplemented");
+ }
+ new llvm::StoreInst( floatVec, arg_dst, "", currentBlock);
// }
}
- GTL_ASSERT( srcPtr );
- // memcpy( (char*)result, src, _TChannels * 4 );
- callMemcpy( generationContext, currentBlock,
- GTLCore::CodeGenerator::convertPointerToCharP( currentBlock, arg_dst),
- srcPtr, GTLCore::CodeGenerator::integerToConstant( 4 * channelsNb ) );
// }
new llvm::ReturnInst( currentBlock );
return func;
@@ -413,16 +440,11 @@
// char *dst;
// if( _TAllFloat_ )
// {
- // dst = _imgData;
+ // memcpy( dst, (char*)_src, _TChannels * sizeof(float) );
// } else {
- // dst = float[ _TChannels_ ];
- // }
- // memcpy( dst, (char*)_src, _TChannels * sizeof(float) );
- // if( not _TAllFloat_ )
- // {
// for(int i = 0; i < _TChannels; ++i)
// {
- // convert( i, dst, _imgData );
+ // *(_imgData + pos(i) ) = conver( _src[i] );
// }
// }
// }
@@ -446,35 +468,60 @@
// {
llvm::BasicBlock* currentBlock = new llvm::BasicBlock;
func->getBasicBlockList().push_back( currentBlock );
- // char *src;
- llvm::Value* dstPtr = 0;
// if( _TAllFloat_ )
if( allFloat )
// {
{
// src = _imgData;
- dstPtr = arg_imgData;
+ callMemcpy( generationContext, currentBlock, arg_imgData,
+ GTLCore::CodeGenerator::convertPointerToCharP( currentBlock, arg_src),
+ GTLCore::CodeGenerator::integerToConstant( sizeof(float) * channelsNb ) );
// } else {
} else {
- // src = (char*)new float[ _TChannels_ ];
- dstPtr = new llvm::AllocaInst( llvm::IntegerType::get(8),
- GTLCore::CodeGenerator::integerToConstant( 32 * channelsNb / 4 ),
- "", currentBlock );
- // }
- }
- GTL_ASSERT( dstPtr );
- // memcpy( dst, (char*)_src, _TChannels * sizeof(float) );
- callMemcpy( generationContext, currentBlock, dstPtr,
- GTLCore::CodeGenerator::convertPointerToCharP( currentBlock, arg_src),
- GTLCore::CodeGenerator::integerToConstant( 4 * channelsNb ) );
-
- if( not allFloat )
- {
// for(int i = 0; i < _TChannels; ++i)
+ int currentPos = 0;
+ llvm::Value* floatVec = new llvm::LoadInst( arg_src, "", currentBlock );
+ for( int i = 0; i < channelsNb; ++i)
// {
- // convert( i, dst, _imgData );
+ {
+ const GTLCore::Type* channelType = _pixelDescription.channelTypes()[i];
+ // _src[i]
+ llvm::Value* floatValue = new llvm::ExtractElementInst( floatVec, i, "", currentBlock );
+ // convert( _src[i] );
+ // Scale
+ switch( channelType->dataType() )
+ {
+ case GTLCore::Type::INTEGER8:
+ floatValue = GTLCore::CodeGenerator::createSubstractionExpression( currentBlock, floatValue, GTLCore::Type::Float, GTLCore::CodeGenerator::floatToConstant( 0.5 ), GTLCore::Type::Float);
+ case GTLCore::Type::UNSIGNED_INTEGER8:
+ floatValue = GTLCore::CodeGenerator::createMultiplicationExpression( currentBlock, floatValue, GTLCore::Type::Float, GTLCore::CodeGenerator::floatToConstant( 255.0 ), GTLCore::Type::Float);
+ break;
+ case GTLCore::Type::INTEGER16:
+ floatValue = GTLCore::CodeGenerator::createSubstractionExpression( currentBlock, floatValue, GTLCore::Type::Float, GTLCore::CodeGenerator::floatToConstant( 0.5 ), GTLCore::Type::Float);
+ case GTLCore::Type::UNSIGNED_INTEGER16:
+ floatValue = GTLCore::CodeGenerator::createMultiplicationExpression( currentBlock, floatValue, GTLCore::Type::Float, GTLCore::CodeGenerator::floatToConstant( 65535.0 ), GTLCore::Type::Float);
+ break;
+ case GTLCore::Type::INTEGER32:
+ floatValue = GTLCore::CodeGenerator::createSubstractionExpression( currentBlock, floatValue, GTLCore::Type::Float, GTLCore::CodeGenerator::floatToConstant( 0.5 ), GTLCore::Type::Float);
+ case GTLCore::Type::UNSIGNED_INTEGER32:
+ floatValue = GTLCore::CodeGenerator::createMultiplicationExpression( currentBlock, floatValue, GTLCore::Type::Float, GTLCore::CodeGenerator::floatToConstant( 4294967295.0 ), GTLCore::Type::Float);
+ break;
+ default:
+ GTL_ABORT("unimplemented");
+ }
+ // Convert back to native
+ llvm::Value* nativeValue = GTLCore::CodeGenerator::convertValueTo( currentBlock, floatValue, GTLCore::Type::Float, channelType);
+ // *(_imgData + pos(i) ) = convert( _src[i] );
+ llvm::Value* posInP = new llvm::GetElementPtrInst( arg_imgData, GTLCore::CodeGenerator::integerToConstant( currentPos ), "", currentBlock );
+ llvm::Value* posInPNative = GTLCore::CodeGenerator::convertPointerTo( currentBlock, posInP, channelType->d->type() );
+ new llvm::StoreInst( nativeValue, posInPNative, "", currentBlock );
// }
- GTL_ABORT("unimplemented");
+ // result[i] = convert(_imgData + pos(i) )
+ GTL_ASSERT(channelType->bitsSize() % 8 == 0);
+ currentPos += channelType->bitsSize() / 8;
+ // }
+ }
+ // }
}
// }
new llvm::ReturnInst( currentBlock );
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -150,6 +150,7 @@
void Kernel::evaluatePixeles( const GTLCore::Region& _region, const std::list< AbstractImage* >& _inputImages, AbstractImage* _outputImage) const
{
+ SHIVA_DEBUG( _region.x() << " " << _region.y() << " " << _region.width() << " " << _region.height());
SHIVA_ASSERT( d->evaluatePixelesFunction );
// Wrap input images
@@ -159,7 +160,7 @@
for( std::list< AbstractImage* >::const_iterator it = _inputImages.begin();
it != _inputImages.end(); ++it)
{
- inputImages[i] = (const void*)*it;
+ inputImages[i] = (const void*)d->wrapper->wrapImage( *it );
}
// Wrap output image
@@ -171,6 +172,7 @@
(*func)( _region.x(), _region.y(), _region.width(), _region.height(), inputImages, owrap); // TODO s/200/width s/300/height
delete[] inputImages;
delete owrap;
+ SHIVA_DEBUG( "done" );
}
int Kernel::runTest() const
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Parser_p.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -82,6 +82,9 @@
case GTLCore::Token::END_OF_FILE:
case GTLCore::Token::ENDBRACE:
return;
+ case GTLCore::Token::STRUCT:
+ parseStructDefinition();
+ break;
default:
{
if( currentToken().isFunctionType() )
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -75,8 +75,14 @@
llvm::BasicBlock* PixelVisitor::set( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType, llvm::Value* _value, const GTLCore::Type* _valueType, bool _allocatedInMemory) const
{
- SHIVA_DEBUG( *_pointerType << " " << *_valueType );
- SHIVA_DEBUG( *_pointer << " " << *_value );
+ SHIVA_DEBUG( "Pointer Type = " << *_pointerType << " Value Type = " << *_valueType );
+ SHIVA_DEBUG( "Pointer = " << *_pointer << " Value = " << *_value );
+ if( _valueType->dataType() == GTLCore::Type::STRUCTURE )
+ {
+ GTL_ASSERT( _valueType == _pointerType );
+ _value = new llvm::LoadInst( CodeGenerator::accessPixelDataPtr( _generationContext, _currentBlock, _value ), "", _currentBlock);
+ }
+ GTL_DEBUG( "Value = " << *_value );
new llvm::StoreInst( _value,
CodeGenerator::accessPixelDataPtr( _generationContext, _currentBlock, _pointer ),
"",
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -27,7 +27,9 @@
char* image_wrap_data( ImageWrap* _imageWrap, int _x, int _y )
{
-// GTL_DEBUG( _x << " " << _y );
+// SHIVA_DEBUG( _imageWrap << " " << _x << " " << _y );
+ SHIVA_ASSERT( _imageWrap );
+ SHIVA_ASSERT( _imageWrap->image );
return _imageWrap->image->data(_x, _y);
}
Modified: trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva 2008-06-30 19:48:47 UTC (rev 267)
@@ -2,7 +2,21 @@
{
void evaluatePixel(image img, out pixel result)
{
-// result = ( img.sampleNearest( result.x - 1, result.y) + img.sampleNearest( result.x, result.y )
-// + img.sampleNearest( result.x + 1, result.y) ) / 3;
+ float2 point1;
+ point1[0] = result.x;
+ point1[1] = result.y;
+ float2 point2;
+ point2[0] = result.x - 1;
+ point2[1] = result.y - 1;
+ float2 point3;
+ point3[0] = result.x + 1;
+ point3[1] = result.y + 1;
+ pixel v1 = img.sampleNearest( point1 );
+ pixel v2 = img.sampleNearest( point2 );
+ pixel v3 = img.sampleNearest( point3 );
+ for(int i = 0; i < 3; ++i)
+ {
+ result[i] = (v1[i] + v2[i] + v3[i]) / 3;
+ }
}
}
Modified: trunk/OpenGTL/OpenShiva/tests/vectors/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/vectors/CMakeLists.txt 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenShiva/tests/vectors/CMakeLists.txt 2008-06-30 19:48:47 UTC (rev 267)
@@ -1,6 +1,8 @@
set( TESTS_FILES
creation.shiva
+ copy.shiva
+ copy4.shiva
)
FOREACH( TEST_FILE ${TESTS_FILES} )
Added: trunk/OpenGTL/OpenShiva/tests/vectors/copy.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/vectors/copy.shiva (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/vectors/copy.shiva 2008-06-30 19:48:47 UTC (rev 267)
@@ -0,0 +1,18 @@
+kernel MyKernel
+{
+ void evaluatePixel(output pixel result)
+ {
+ }
+ int runTest()
+ {
+ int count = 0;
+ float2 v;
+ float2 v2;
+ v[0] = 1.0;
+ v[1] = -1.0;
+ v2 = v;
+ if( v2[0] != 1.0 ) ++count;
+ if( v2[1] != -1.0 ) ++count;
+ return count;
+ }
+}
Added: trunk/OpenGTL/OpenShiva/tests/vectors/copy4.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/vectors/copy4.shiva (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/vectors/copy4.shiva 2008-06-30 19:48:47 UTC (rev 267)
@@ -0,0 +1,41 @@
+kernel MyKernel
+{
+ struct MyS {
+ float4 v;
+ };
+ void evaluatePixel(output pixel result)
+ {
+ float4 v;
+ float4 v2;
+ }
+ void func(pixel px)
+ {
+ float4 v;
+ float4 v2;
+ v = v2;
+ }
+ void func3(MyS mys)
+ {
+ float4 v;
+ float4 v2;
+ v = v2;
+ }
+ void func2(float4 t)
+ {
+ float4 v;
+ float4 v2;
+ v = v2;
+ }
+ int runTest()
+ {
+ int count = 0;
+ float4 v;
+ float4 v2;
+ v[0] = 1.0;
+ v[1] = -1.0;
+ v2 = v;
+ if( v2[0] != 1.0 ) ++count;
+ if( v2[1] != -1.0 ) ++count;
+ return count;
+ }
+}
Modified: trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenShiva/tools/interpreter/Shiva.cpp 2008-06-30 19:48:47 UTC (rev 267)
@@ -109,8 +109,9 @@
source += "\n";
std::getline(in,str);
}
- GTLCore::PixelDescription pixel( GTLCore::Type::Float, 4 );
- OpenShiva::Kernel p(fileName, 1);
+ int channelsCount = 3;
+ GTLCore::PixelDescription pixel( GTLCore::Type::UnsignedInteger8, channelsCount );
+ OpenShiva::Kernel p(fileName, channelsCount);
p.setSource( source );
p.compile();
if(not p.isCompiled())
@@ -119,9 +120,11 @@
return EXIT_FAILURE;
}
OpenShiva::Image image(200,300, pixel );
- memset( image.data(0, 0), 1, 200 * 300 );
- p.evaluatePixeles( GTLCore::Region(0,0, 200, 300), std::list<OpenShiva::AbstractImage*>(), &image );
- std::cout << *((float*)image.data( 0, 0));
+// memset( image.data(0, 0), 1, 200 * 300 );
+ std::list<OpenShiva::AbstractImage*> images;
+ images.push_back( new OpenShiva::Image(0,0, pixel ) );
+ p.evaluatePixeles( GTLCore::Region(0,0, 200, 300), images, &image );
+ std::cout << *((char*)image.data( 0, 0));
if( showAssembly )
{
std::cout << p.asmSourceCode();
Modified: trunk/OpenGTL/OpenShiva/tools/tester/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/tools/tester/CMakeLists.txt 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/OpenShiva/tools/tester/CMakeLists.txt 2008-06-30 19:48:47 UTC (rev 267)
@@ -6,3 +6,4 @@
add_executable(shivatester ${shivatester_SRCS})
target_link_libraries(shivatester OpenShiva )
+install( TARGETS shivatester DESTINATION ${BIN_INSTALL_DIR} )
Modified: trunk/OpenGTL/TODO
===================================================================
--- trunk/OpenGTL/TODO 2008-06-29 09:58:04 UTC (rev 266)
+++ trunk/OpenGTL/TODO 2008-06-30 19:48:47 UTC (rev 267)
@@ -1,3 +1,4 @@
Important TODO
* array overflow
- * array/structure leak in return function
\ No newline at end of file
+ * array/structure leak in return function (when assigne to a member or an index of an array)
+ * access to vector using specific vector instructions
\ No newline at end of file