[llvm-commits] [dragonegg] r166675 - in /dragonegg/trunk/src: ConstantConversion.cpp Convert.cpp TypeConversion.cpp
Duncan Sands
baldrick at free.fr
Thu Oct 25 03:15:09 PDT 2012
Author: baldrick
Date: Thu Oct 25 05:15:09 2012
New Revision: 166675
URL: http://llvm.org/viewvc/llvm-project?rev=166675&view=rev
Log:
Convert GCC vectors of pointers to LLVM vectors of pointers, in the hope that
these work OK nowadays.
Modified:
dragonegg/trunk/src/ConstantConversion.cpp
dragonegg/trunk/src/Convert.cpp
dragonegg/trunk/src/TypeConversion.cpp
Modified: dragonegg/trunk/src/ConstantConversion.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/ConstantConversion.cpp?rev=166675&r1=166674&r2=166675&view=diff
==============================================================================
--- dragonegg/trunk/src/ConstantConversion.cpp (original)
+++ dragonegg/trunk/src/ConstantConversion.cpp Thu Oct 25 05:15:09 2012
@@ -559,17 +559,9 @@
unsigned NumElts = TYPE_VECTOR_SUBPARTS(type);
unsigned Stride = GET_MODE_BITSIZE(TYPE_MODE(elt_type));
SmallVector<Constant*, 16> Vals(NumElts);
- for (unsigned i = 0; i != NumElts; ++i) {
+ for (unsigned i = 0; i != NumElts; ++i)
Vals[i] = ExtractRegisterFromConstantImpl(C, elt_type,
StartingBit+i*Stride, Folder);
- // LLVM does not support vectors of pointers, so turn any pointers into
- // integers.
- if (isa<PointerType>(Vals[i]->getType())) {
- IntegerType *IntPtrTy =
- getDataLayout().getIntPtrType(Vals[i]->getType());
- Vals[i] = Folder.CreatePtrToInt(Vals[i], IntPtrTy);
- }
- }
return ConstantVector::get(Vals);
}
@@ -982,15 +974,8 @@
// Make the IR more pleasant by returning as a vector if the GCC type was a
// vector. However this is only correct if the initial values had the same
// type as the vector element type, rather than some random other type.
- if (isa<VECTOR_TYPE>(init_type) && ActualEltTy == EltTy) {
- // If this is a vector of pointers, convert it to a vector of integers.
- if (isa<PointerType>(EltTy)) {
- IntegerType *IntPtrTy = getDataLayout().getIntPtrType(EltTy);
- for (unsigned i = 0, e = Elts.size(); i != e; ++i)
- Elts[i] = Folder.CreatePtrToInt(Elts[i], IntPtrTy);
- }
+ if (isa<VECTOR_TYPE>(init_type) && ActualEltTy == EltTy)
return ConstantVector::get(Elts);
- }
return ConstantArray::get(ArrayType::get(ActualEltTy, Elts.size()), Elts);
}
Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=166675&r1=166674&r2=166675&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Thu Oct 25 05:15:09 2012
@@ -459,16 +459,10 @@
}
// Otherwise, load the vector component by component.
Value *Res = UndefValue::get(RegTy);
- bool isVectorOfPointers = isa<PointerType>(EltRegTy);
unsigned Stride = GET_MODE_SIZE(TYPE_MODE(elt_type));
- IntegerType *IntPtrTy = getDataLayout().getIntPtrType(EltRegTy);
for (unsigned i = 0; i != NumElts; ++i) {
Value *Idx = Builder.getInt32(i);
Value *Elt = LoadRegisterFromMemory(Loc, elt_type, AliasTag, Builder);
- // LLVM does not support vectors of pointers, so turn any pointers into
- // integers.
- if (isVectorOfPointers)
- Elt = Builder.CreatePtrToInt(Elt, IntPtrTy);
Res = Builder.CreateInsertElement(Res, Elt, Idx);
if (i + 1 != NumElts)
Loc = DisplaceLocationByUnits(Loc, Stride, Builder);
@@ -1839,8 +1833,7 @@
if (EltTy->isPointerTy()) {
// A pointer/vector of pointer - use inttoptr.
assert(OrigEltTy->getPrimitiveSizeInBits() ==
- DL.getPointerSizeInBits(
- cast<PointerType>(EltTy)->getAddressSpace())
+ DL.getPointerSizeInBits(cast<PointerType>(EltTy)->getAddressSpace())
&& "Pointer type not same size!");
return Builder.CreateIntToPtr(V, Ty);
}
@@ -2902,10 +2895,6 @@
BuildVecOps.push_back(Builder.CreateExtractElement(Elt, Index));
}
} else {
- // LLVM does not support vectors of pointers, so turn any pointers into
- // integers.
- if (isa<PointerType>(Elt->getType()))
- Elt = Builder.CreatePtrToInt(Elt, DL.getIntPtrType(Elt->getType()));
assert(Elt->getType() == VTy->getElementType() &&
"Unexpected type for vector constructor!");
BuildVecOps.push_back(Elt);
@@ -6600,16 +6589,8 @@
// Convert the elements.
SmallVector<Constant*, 16> Elts;
- for (tree elt = TREE_VECTOR_CST_ELTS(reg); elt; elt = TREE_CHAIN(elt)) {
- Constant *Elt = EmitRegisterConstant(TREE_VALUE(elt));
- // LLVM does not support vectors of pointers, so turn any pointers into
- // integers.
- if (isa<PointerType>(Elt->getType())) {
- IntegerType *IntTy = getDataLayout().getIntPtrType(Elt->getType());
- Elt = Builder.getFolder().CreatePtrToInt(Elt, IntTy);
- }
- Elts.push_back(Elt);
- }
+ for (tree elt = TREE_VECTOR_CST_ELTS(reg); elt; elt = TREE_CHAIN(elt))
+ Elts.push_back(EmitRegisterConstant(TREE_VALUE(elt)));
// If there weren't enough elements then set the rest of the vector to the
// default value.
Modified: dragonegg/trunk/src/TypeConversion.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/TypeConversion.cpp?rev=166675&r1=166674&r2=166675&view=diff
==============================================================================
--- dragonegg/trunk/src/TypeConversion.cpp (original)
+++ dragonegg/trunk/src/TypeConversion.cpp Thu Oct 25 05:15:09 2012
@@ -460,10 +460,12 @@
return getDataLayout().getIntPtrType(Context, TYPE_ADDR_SPACE(type));
case POINTER_TYPE:
- case REFERENCE_TYPE:
+ case REFERENCE_TYPE: {
// void* -> byte*
- return isa<VOID_TYPE>(TREE_TYPE(type)) ? GetUnitPointerType(Context) :
- ConvertType(TREE_TYPE(type))->getPointerTo();
+ unsigned AS = TYPE_ADDR_SPACE(type);
+ return isa<VOID_TYPE>(TREE_TYPE(type)) ? GetUnitPointerType(Context, AS) :
+ ConvertType(TREE_TYPE(type))->getPointerTo(AS);
+ }
case REAL_TYPE:
if (TYPE_PRECISION(type) == 32)
@@ -482,15 +484,8 @@
debug_tree(type);
llvm_unreachable("Unknown FP type!");
- case VECTOR_TYPE: {
- // LLVM does not support vectors of pointers, so turn any pointers into
- // integers. <-- This isn't true since at least 3.1 as far as I know - MicahV
- // FIXME ^-- Yes, but does it work reliably? - Duncan
- Type *EltTy = isa<ACCESS_TYPE>(TREE_TYPE(type)) ?
- getDataLayout().getIntPtrType(Context, TYPE_ADDR_SPACE(TREE_TYPE(type))) :
- getRegType(TREE_TYPE(type));
- return VectorType::get(EltTy, TYPE_VECTOR_SUBPARTS(type));
- }
+ case VECTOR_TYPE:
+ return VectorType::get(getRegType(TREE_TYPE(type)), TYPE_VECTOR_SUBPARTS(type));
}
}
@@ -974,7 +969,7 @@
PointeeTy = StructType::get(Context);
}
- return PointeeTy->getPointerTo();
+ return PointeeTy->getPointerTo(TYPE_ADDR_SPACE(type));
}
typedef Range<uint64_t> BitRange;
@@ -1244,6 +1239,11 @@
return STy;
}
+static Type *ConvertVectorTypeRecursive(tree type) {
+ Type *EltTy = ConvertType(TREE_TYPE(type));
+ return VectorType::get(EltTy, TYPE_VECTOR_SUBPARTS(type));
+}
+
/// mayRecurse - Return true if converting this type may require breaking a
/// self-referential type loop. For example, converting the struct type
/// struct S;
@@ -1276,15 +1276,16 @@
return false;
case COMPLEX_TYPE:
- case VECTOR_TYPE:
- // Converting these types does involve converting another type, however that
+ // Converting this type does involve converting another type, however that
// conversion cannot refer back to the initial type.
- // NOTE: GCC supports vectors of pointers, and the pointer could refer back
- // to the vector. However as LLVM does not support vectors of pointers we
- // don't convert the pointer type and just use an integer instead, so as far
- // as we are concerned such vector types are not self-referential.
return false;
+ case VECTOR_TYPE:
+ // If this is a vector of pointers then the pointer could refer back to the
+ // vector, but this can only cause recursion if the vector was not converted
+ // yet.
+ return isa<ACCESS_TYPE>(TREE_TYPE(type)) && getCachedType(type) == 0;
+
case ARRAY_TYPE:
case FUNCTION_TYPE:
case METHOD_TYPE:
@@ -1371,6 +1372,9 @@
case UNION_TYPE:
case QUAL_UNION_TYPE:
return RememberTypeConversion(type, ConvertRecordTypeRecursive(type));
+
+ case VECTOR_TYPE:
+ return RememberTypeConversion(type, ConvertVectorTypeRecursive(type));
}
}
@@ -1410,7 +1414,8 @@
}
case COMPLEX_TYPE: {
- if (Type *Ty = getCachedType(type)) return Ty;
+ if (Type *Ty = getCachedType(type))
+ return CheckTypeConversion(type, Ty);
Type *Ty = ConvertTypeNonRecursive(main_type(type));
Ty = StructType::get(Ty, Ty, NULL);
return RememberTypeConversion(type, Ty);
@@ -1456,15 +1461,10 @@
getDescriptiveName(type)));
case VECTOR_TYPE: {
- if (Type *Ty = getCachedType(type)) return Ty;
- Type *Ty;
- // LLVM does not support vectors of pointers, so turn any pointers into
- // integers.
- if (isa<ACCESS_TYPE>(TREE_TYPE(type)))
- Ty = getDataLayout().getIntPtrType(Context,
- TYPE_ADDR_SPACE(TREE_TYPE(type)));
- else
- Ty = ConvertTypeNonRecursive(main_type(type));
+ if (Type *Ty = getCachedType(type))
+ return CheckTypeConversion(type, Ty);
+ assert(!isa<ACCESS_TYPE>(TREE_TYPE(type)) && "Type not already converted!");
+ Type *Ty = ConvertTypeNonRecursive(main_type(type));
Ty = VectorType::get(Ty, TYPE_VECTOR_SUBPARTS(type));
return RememberTypeConversion(type, Ty);
}
@@ -1653,7 +1653,8 @@
// SCC as the pointer (since the SCC contains more than one type).
Type *PointeeTy = getCachedType(pointee);
assert(PointeeTy && "Pointee not converted!");
- RememberTypeConversion(some_type, PointeeTy->getPointerTo());
+ unsigned AS = TYPE_ADDR_SPACE(some_type);
+ RememberTypeConversion(some_type, PointeeTy->getPointerTo(AS));
}
}
}
More information about the llvm-commits
mailing list