[opengtl-commits] [713] implement the conversion from array to vector |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 713
Author: cyrille
Date: 2009-04-09 14:59:34 +0200 (Thu, 09 Apr 2009)
Log Message:
-----------
implement the conversion from array to vector
Modified Paths:
--------------
trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.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/GenerationContext_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.cpp 2009-04-08 21:50:38 UTC (rev 712)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/ConvertExpression.cpp 2009-04-09 12:59:34 UTC (rev 713)
@@ -94,6 +94,6 @@
{
return GTLCore::ExpressionResult( CodeGenerator::convertConstantArrayToVector( result.constant(), result.type(), m_dstType ), m_dstType);
} else {
- return GTLCore::ExpressionResult( CodeGenerator::convertArrayToVector( _egc.currentBasicBlock(), result.value(), result.type(), m_dstType ), m_dstType);
+ return GTLCore::ExpressionResult( CodeGenerator::convertArrayToVector( _gc, _egc, result.value(), result.type(), m_dstType ), m_dstType);
}
}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp 2009-04-08 21:50:38 UTC (rev 712)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/Statement.cpp 2009-04-09 12:59:34 UTC (rev 713)
@@ -47,10 +47,7 @@
llvm::BasicBlock* Statement::createBlock( GenerationContext& context) const
{
- GTL_ASSERT( context.llvmFunction() );
- llvm::BasicBlock* bb = llvm::BasicBlock::Create();
- context.llvmFunction()->getBasicBlockList().push_back( bb );
- return bb;
+ return context.createBasicBlock();
}
llvm::BasicBlock* StatementsList::generateStatement( GenerationContext& _context, llvm::BasicBlock* _bb ) const
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2009-04-08 21:50:38 UTC (rev 712)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2009-04-09 12:59:34 UTC (rev 713)
@@ -43,6 +43,8 @@
#include "wrappers/ArrayWrap.h"
#include "MemoryModelConfig_p.h"
#include "GenerationContext_p.h"
+#include "Visitor_p.h"
+#include "Visitor_p.h"
#define UNIFORMIZE_TYPES( _v1_, _v2_) \
GTL_ASSERT( _v1_.value() ); \
@@ -264,7 +266,7 @@
}
-llvm::Value* CodeGenerator::convertArrayToVector(llvm::BasicBlock* currentBlock, llvm::Value* value, const Type* valueType, const Type* type)
+llvm::Value* CodeGenerator::convertArrayToVector(GenerationContext& gc, ExpressionGenerationContext& _egc, llvm::Value* value, const Type* valueType, const Type* type)
{
// int arraySize = value->size;
// if( arraySize > type->vectorSize() ) arraySize = type->vectorSize();
@@ -274,15 +276,45 @@
// result[i] = array[i];
// }
-#if s0
// int arraySize = value->size;
- llvm::Value* arraySize = accessArraySize(_currentBlock, value);
+ llvm::Value* arraySize = accessArraySize(_egc.currentBasicBlock(), value);
+ llvm::Value* vectorSize = integerToConstant( type->vectorSize() );
+ llvm::Value* arraySizeAlloc = new llvm::AllocaInst( llvm::Type::Int32Ty, "", _egc.currentBasicBlock() );
+
// arraySize > type->vectorSize()
- llvm::Value aStVComp = createStrictSupperiorExpression(currentBlock, , );
- type->vectorSize()
-#endif
- GTL_ABORT("Unimplemented");
- return 0;
+ llvm::Value* aStVComp = createStrictSupperiorExpression(_egc.currentBasicBlock(),
+ arraySize, GTLCore::Type::Integer32, vectorSize, GTLCore::Type::Integer32);
+ // arraySize = type->vectorSize
+ llvm::BasicBlock* block1 = gc.createBasicBlock();
+ new llvm::StoreInst( vectorSize, arraySizeAlloc, block1 );
+ // arraySize = arraySize
+ llvm::BasicBlock* block2 = gc.createBasicBlock();
+ new llvm::StoreInst( arraySize, arraySizeAlloc, block2 );
+ // if( arraySize > type->vectorSize() ) arraySize = type->vectorSize();
+ llvm::BasicBlock* after = gc.createBasicBlock();
+ createIfElseStatement( _egc.currentBasicBlock(), aStVComp, Type::Boolean, block1, block1, block2, block2, after);
+
+ arraySize = new llvm::LoadInst( arraySizeAlloc, "", after );
+ llvm::Value* result = createVector( type, floatToConstant( 0.0 ) );
+
+ // int i = 0;
+ VariableNG idx(GTLCore::Type::Integer32, false, false );
+ idx.initialise( gc, after,
+ GTLCore::ExpressionResult(integerToConstant(0), GTLCore::Type::Integer32),
+ std::list<llvm::Value*>());
+
+ // result[i] = array[i];
+ llvm::BasicBlock* forBlock = gc.createBasicBlock();
+ llvm::Value* cidx = idx.get( gc, forBlock );
+ llvm::Value* val = accessArrayValue( forBlock, value, cidx );
+ llvm::InsertElementInst::Create(result, val, cidx, "", forBlock );
+
+ // for(int i = 0; i < arraySize; ++i )
+ llvm::BasicBlock* afterFor = createIterationForStatement(gc, after, &idx, arraySize, GTLCore::Type::Integer32, forBlock, forBlock);
+
+ _egc.setCurrentBasicBlock(afterFor);
+
+ return result;
}
llvm::Constant* CodeGenerator::convertConstantArrayToVector(llvm::Constant* constant, const Type* constantType, const Type* type)
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h 2009-04-08 21:50:38 UTC (rev 712)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.h 2009-04-09 12:59:34 UTC (rev 713)
@@ -107,7 +107,7 @@
static llvm::Constant* convertConstantTo(llvm::Constant* constant, const Type* constantType, const Type* type);
static llvm::Value* convertToHalf( GenerationContext& generationContext, llvm::BasicBlock* currentBlock, llvm::Value* value, const Type* _valueType);
static llvm::Value* convertFromHalf( GenerationContext& generationContext, llvm::BasicBlock* currentBlock, llvm::Value* value);
- static llvm::Value* convertArrayToVector(llvm::BasicBlock* currentBlock, llvm::Value* value, const Type* valueType, const Type* type);
+ static llvm::Value* convertArrayToVector(GenerationContext& gc, ExpressionGenerationContext& _egc, llvm::Value* value, const Type* valueType, const Type* type);
static llvm::Constant* convertConstantArrayToVector(llvm::Constant* constant, const Type* constantType, const Type* type);
static llvm::Value* vectorValueAt( llvm::BasicBlock* _currentBlock, llvm::Value* _vector, llvm::Value* _index);
static llvm::Value* createRound( llvm::BasicBlock* _currentBlock, llvm::Value* _val );
@@ -209,7 +209,7 @@
* @param after the basic block after the if statement
*/
static void createIfStatement( llvm::BasicBlock* before, llvm::Value* test, const Type* testType, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* after);
- void createIfElseStatement( llvm::BasicBlock* before, llvm::Value* test, const Type* testType, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* firstElseAction, llvm::BasicBlock* lastElseAction, llvm::BasicBlock* after);
+ static void createIfElseStatement( llvm::BasicBlock* before, llvm::Value* test, const Type* testType, llvm::BasicBlock* firstAction, llvm::BasicBlock* lastAction, llvm::BasicBlock* firstElseAction, llvm::BasicBlock* lastElseAction, llvm::BasicBlock* after);
/**
* Create a for statement.
* @param before the basic block before the for statement
@@ -265,7 +265,7 @@
* @param _index the index of the value in the array
* @return a pointer on the value of an array
*/
- llvm::Value* accessArrayValue( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _index );
+ static llvm::Value* accessArrayValue( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer, llvm::Value* _index );
static llvm::Value* accessArraySizePointer( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer );
static llvm::Value* accessArraySize( llvm::BasicBlock* _currentBlock, llvm::Value* _pointer );
public:
Modified: trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.cpp 2009-04-08 21:50:38 UTC (rev 712)
+++ trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.cpp 2009-04-09 12:59:34 UTC (rev 713)
@@ -22,6 +22,9 @@
#include "ModuleData_p.h"
#include "Debug.h"
+#include "llvm/BasicBlock.h"
+#include "llvm/Function.h"
+
#include "AST/Statement.h"
using namespace GTLCore;
@@ -75,3 +78,11 @@
m_delayedStatements.clear();
return _bb;
}
+
+llvm::BasicBlock* GenerationContext::createBasicBlock( )
+{
+ GTL_ASSERT( llvmFunction() );
+ llvm::BasicBlock* bb = llvm::BasicBlock::Create();
+ llvmFunction()->getBasicBlockList().push_back( bb );
+ return bb;
+}
Modified: trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h 2009-04-08 21:50:38 UTC (rev 712)
+++ trunk/OpenGTL/OpenGTL/GTLCore/GenerationContext_p.h 2009-04-09 12:59:34 UTC (rev 713)
@@ -57,6 +57,10 @@
* Generate the statement that were delayed
*/
llvm::BasicBlock* flushDelayedStatement(llvm::BasicBlock*);
+ /**
+ * Create a new block and add it to the current function.
+ */
+ llvm::BasicBlock* createBasicBlock( );
private:
GTLCore::CodeGenerator* m_codeGenerator;
llvm::Function* m_llvmFunction;