Simplify a bunch of code by using CollectionType to collect struct

codepaths in with array/vector codepaths. (Issue #37).
This commit is contained in:
Matt Pharr
2011-06-29 07:59:43 +01:00
parent 214fb3197a
commit 6b153566f3
2 changed files with 51 additions and 88 deletions

27
ctx.cpp
View File

@@ -1516,29 +1516,18 @@ FunctionEmitContext::maskedStore(llvm::Value *rvalue, llvm::Value *lvalue,
assert(llvm::isa<const llvm::PointerType>(lvalue->getType()));
const StructType *structType = dynamic_cast<const StructType *>(rvalueType);
if (structType != NULL) {
// Assigning a structure
for (int i = 0; i < structType->GetElementCount(); ++i) {
const CollectionType *collectionType =
dynamic_cast<const CollectionType *>(rvalueType);
if (collectionType != NULL) {
// Assigning a structure / array / vector. Handle each element
// individually with what turns into a recursive call to
// makedStore()
for (int i = 0; i < collectionType->GetElementCount(); ++i) {
llvm::Value *eltValue = ExtractInst(rvalue, i, "rvalue_member");
llvm::Value *eltLValue = GetElementPtrInst(lvalue, 0, i,
"struct_lvalue_ptr");
StoreInst(eltValue, eltLValue, storeMask,
structType->GetElementType(i));
}
return;
}
const SequentialType *sequentialType =
dynamic_cast<const SequentialType *>(rvalueType);
if (sequentialType != NULL) {
// Assigning arrays and vectors. Handle each element individually
// with what turns into a recursive call to makedStore()
for (int i = 0; i < sequentialType->GetElementCount(); ++i) {
llvm::Value *eltLValue = GetElementPtrInst(lvalue, 0, i, "lval_i_ptr");
llvm::Value *eltValue = ExtractInst(rvalue, i, "array_i_val");
StoreInst(eltValue, eltLValue, storeMask,
sequentialType->GetElementType());
collectionType->GetElementType(i));
}
return;
}