[opengtl-commits] [301] * fix generation of expressions involving vectors |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 301
Author: cyrille
Date: 2008-07-07 14:27:34 +0200 (Mon, 07 Jul 2008)
Log Message:
-----------
* fix generation of expressions involving vectors
* convert floats/integers to a vector
* remove the need to give the type when using ExpressionResults to create (some) binary expressions
Modified Paths:
--------------
trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp
trunk/OpenGTL/OpenGTL/GTLCore/Debug.h
trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp 2008-07-04 13:29:31 UTC (rev 300)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp 2008-07-07 12:27:34 UTC (rev 301)
@@ -24,6 +24,7 @@
#include "../CodeGenerator_p.h"
#include "../ExpressionResult_p.h"
+#include "../Function.h"
#include "../Debug.h"
#include "../VariableNG_p.h"
#include "../Visitor_p.h"
@@ -40,7 +41,9 @@
GTL_ASSERT(ptr_);
const Visitor* visitor = Visitor::getVisitorFor( type() );
GTL_DEBUG("Type = " << *type() << " ptr = " << *ptr_);
- return visitor->get( _gc, _bb, ptr_, type() );
+ GTLCore::ExpressionResult result = visitor->get( _gc, _bb, ptr_, type() );
+ GTL_DEBUG("Result = " << result );
+ return result;
}
llvm::BasicBlock* AccessorExpression::affect( GenerationContext& _gc, llvm::BasicBlock* _bb, const ExpressionResult& _value )
@@ -210,6 +213,7 @@
GTLCore::ExpressionResult FunctionMemberAccessorExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
+ GTL_DEBUG("Call member funcion: " << m_member->function()->name());
return _gc.codeGenerator()->callFunction( _gc, bb, m_member->function(), m_arguments );
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp 2008-07-04 13:29:31 UTC (rev 300)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/BinaryExpression.cpp 2008-07-07 12:27:34 UTC (rev 301)
@@ -68,7 +68,7 @@
GTLCore::ExpressionResult OrBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createOrExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createOrExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
}
const GTLCore::Type* AndBinaryExpression::type() const
@@ -78,7 +78,7 @@
GTLCore::ExpressionResult AndBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createAndExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createAndExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb));
}
GTLCore::ExpressionResult BitOrBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
@@ -158,32 +158,32 @@
GTLCore::ExpressionResult RightShiftBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createRightShiftExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createRightShiftExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
}
GTLCore::ExpressionResult LeftShiftBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createLeftShiftExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createLeftShiftExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
}
GTLCore::ExpressionResult AdditionBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createAdditionExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createAdditionExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
}
GTLCore::ExpressionResult SubstractionBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createSubstractionExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createSubstractionExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb));
}
GTLCore::ExpressionResult MultiplicationBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createMultiplicationExpression( bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createMultiplicationExpression( bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
}
GTLCore::ExpressionResult DivisionBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
{
- return _gc.codeGenerator()->createDivisionExpression(bb, leftHandSide()->generateValue( _gc, bb), leftHandSide()->type(), rightHandSide()->generateValue( _gc, bb), rightHandSide()->type() );
+ return _gc.codeGenerator()->createDivisionExpression(bb, leftHandSide()->generateValue( _gc, bb), rightHandSide()->generateValue( _gc, bb) );
}
GTLCore::ExpressionResult ModuloBinaryExpression::generateValue( GenerationContext& _gc, llvm::BasicBlock* bb ) const
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2008-07-04 13:29:31 UTC (rev 300)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2008-07-07 12:27:34 UTC (rev 301)
@@ -154,6 +154,21 @@
{ // Don't cast the value as it has allready the correct type
return _value;
}
+ if( _targetType->dataType() == Type::VECTOR and _valueType->dataType() != Type::VECTOR )
+ {
+ // Create a vector
+ llvm::Value* result = new llvm::AllocaInst( _targetType->d->type(), integerToConstant(1), "", _currentBlock);
+ llvm::Value* resultLoad = new llvm::LoadInst( result, "", _currentBlock);
+ llvm::Value* vecElt = convertValueTo( _currentBlock, _value, _valueType, _targetType->embeddedType() );
+ // Affect the same value to each element of the vector
+ for(int i = 0; i < _targetType->vectorSize(); ++i)
+ {
+ llvm::InsertElementInst::Create( resultLoad, vecElt, i, "", _currentBlock );
+ }
+ // store back
+ new llvm::StoreInst( resultLoad, result, "", _currentBlock);
+ return result;
+ }
GTL_ASSERT(_targetType->d->type()->isFirstClassType());
GTL_ASSERT(_value->getType()->isFirstClassType());
return llvm::CastInst::create(
@@ -167,6 +182,18 @@
{ // Don't cast the value as it has allready the correct type
return _constant;
}
+ if( _targetType->dataType() == Type::VECTOR and _constantType->dataType() != Type::VECTOR )
+ {
+ llvm::Constant* vecElt = convertConstantTo( _constant, _constantType, _targetType->embeddedType() );
+ // Affect the same value to each element of the vector
+ std::vector<llvm::Constant*> constants;
+ for(int i = 0; i < _targetType->vectorSize(); ++i)
+ {
+ constants.push_back( vecElt );
+ }
+ // store back
+ return llvm::ConstantVector::get( llvm::cast<const llvm::VectorType>(_targetType->d->type()), constants );
+ }
GTL_ASSERT( _targetType->d->type()->isFirstClassType() );
GTL_ASSERT( _constant->getType()->isFirstClassType() );
return llvm::ConstantExpr::getCast(
@@ -324,8 +351,11 @@
UNIFORMIZE_CONSTANT_TYPES( lhs, rhs ) \
return llvm::ConstantExpr::_LLVM_Constant_Expr_( v1, v2 ); \
} \
- ExpressionResult CodeGenerator::_GTL_Function_Name_( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType) \
+ ExpressionResult CodeGenerator::_GTL_Function_Name_( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs) \
{ \
+ const Type* lhsType = lhs.type(); \
+ const Type* rhsType = rhs.type(); \
+ GTL_DEBUG( "lhs = " << lhs << " lhsType = " << *lhsType << " rhs = " << rhs << " rhsType = " << *rhsType ); \
UNIFORMIZE_TYPES(lhs, rhs); \
CREATE_BINARY_OPERATOR( _GTL_Function_Name_, v1, v2); \
}
@@ -361,8 +391,10 @@
}
}
-ExpressionResult CodeGenerator::createDivisionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType)
+ExpressionResult CodeGenerator::createDivisionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs)
{
+ const Type* lhsType = lhs.type();
+ const Type* rhsType = rhs.type();
UNIFORMIZE_TYPES(lhs, rhs);
CREATE_BINARY_OPERATOR( createDivisionExpression, v1, v2);
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h 2008-07-04 13:29:31 UTC (rev 300)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h 2008-07-07 12:27:34 UTC (rev 301)
@@ -97,10 +97,10 @@
static llvm::Value* createRound( llvm::BasicBlock* _currentBlock, llvm::Value* _val );
public: // Boolean Expression
llvm::Value* createOrExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
- ExpressionResult createOrExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ ExpressionResult createOrExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
llvm::Constant* createOrExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
llvm::Value* createAndExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
- ExpressionResult createAndExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ ExpressionResult createAndExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
llvm::Constant* createAndExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
public: // Bit expressions
llvm::Value* createBitXorExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
@@ -115,30 +115,30 @@
public: // Arithmetic expressions
// Addition
static llvm::Value* createAdditionExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
- static ExpressionResult createAdditionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ static ExpressionResult createAdditionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
static llvm::Constant* createAdditionExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
// Substraction
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 ExpressionResult createSubstractionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
static llvm::Constant* createSubstractionExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
// Multiplication
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 ExpressionResult createMultiplicationExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs );
static llvm::Constant* createMultiplicationExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
// Division
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);
+ static ExpressionResult createDivisionExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
// 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);
ExpressionResult createModuloExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
public: // Shift expressions
llvm::Value* createRightShiftExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
- ExpressionResult createRightShiftExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ ExpressionResult createRightShiftExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
llvm::Constant* createRightShiftExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
llvm::Value* createLeftShiftExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
- ExpressionResult createLeftShiftExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, const Type* lhsType, ExpressionResult rhs, const Type* rhsType);
+ ExpressionResult createLeftShiftExpression( llvm::BasicBlock* currentBlock, ExpressionResult lhs, ExpressionResult rhs);
llvm::Constant* createLeftShiftExpression( llvm::Constant* lhs, const Type* lhsType, llvm::Constant* rhs, const Type* rhsType);
public: // Comparison Expressions
llvm::Value* createEqualExpression(llvm::BasicBlock* currentBlock, llvm::Value* lhs, const Type* lhsType, llvm::Value* rhs, const Type* rhsType);
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp 2008-07-04 13:29:31 UTC (rev 300)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp 2008-07-07 12:27:34 UTC (rev 301)
@@ -22,9 +22,11 @@
#include <map>
#include <fstream>
+#include <llvm/Value.h>
#include <llvm/Type.h>
#include <llvm/System/Path.h>
+#include "ExpressionResult_p.h"
#include "Macros_p.h"
#include "PixelDescription.h"
#include "Region.h"
@@ -223,6 +225,12 @@
#endif
namespace GTLCore {
+ std::ostream& operator<< (std::ostream& _ostr, const ExpressionResult& _expressionResult)
+ {
+ _ostr << "[value = " << *_expressionResult.value() << " type = " << *_expressionResult.type();
+ return _ostr;
+ }
+
std::ostream& operator<< (std::ostream& _ostr, const PixelDescription& _pixelDescription)
{
_ostr << "[";
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Debug.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Debug.h 2008-07-04 13:29:31 UTC (rev 300)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Debug.h 2008-07-07 12:27:34 UTC (rev 301)
@@ -38,12 +38,14 @@
private:
struct Private;
};
+ class ExpressionResult;
class PixelDescription;
class Region;
class ScopedName;
class Type;
class Token;
+ std::ostream& operator<< (std::ostream& ostr, const ExpressionResult& expressionResult);
std::ostream& operator<< (std::ostream& ostr, const PixelDescription& pixelDescription);
std::ostream& operator<< (std::ostream& ostr, const Region& region);
std::ostream& operator<< (std::ostream& ostr, const ScopedName& name);
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp 2008-07-04 13:29:31 UTC (rev 300)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp 2008-07-07 12:27:34 UTC (rev 301)
@@ -66,6 +66,7 @@
GTLCore::ExpressionResult PixelVisitor::get( GTLCore::GenerationContext& _generationContext, llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, const GTLCore::Type* _pointerType) const
{
+ SHIVA_DEBUG( *_pointer << " " << *_pointerType );
llvm::Value* result = new llvm::LoadInst(
CodeGenerator::accessPixelDataPtr( _generationContext, _currentBlock, _pointer ),
"",