[llvm-commits] [dragonegg] r137510 - /dragonegg/trunk/src/Types.cpp
Duncan Sands
baldrick at free.fr
Fri Aug 12 13:49:58 PDT 2011
Author: baldrick
Date: Fri Aug 12 15:49:58 2011
New Revision: 137510
URL: http://llvm.org/viewvc/llvm-project?rev=137510&view=rev
Log:
Adjust the way pointer types are converted so that if T is a
self-referential type then T* only gets converted to {}* when
used inside T (or the other types making up the type loop).
All other uses of T* will result in it being converted to a
convert(T)*, which results in nicer IR.
Modified:
dragonegg/trunk/src/Types.cpp
Modified: dragonegg/trunk/src/Types.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Types.cpp?rev=137510&r1=137509&r2=137510&view=diff
==============================================================================
--- dragonegg/trunk/src/Types.cpp (original)
+++ dragonegg/trunk/src/Types.cpp Fri Aug 12 15:49:58 2011
@@ -1994,6 +1994,27 @@
for (unsigned i = 0, e = SCC.size(); i != e; ++i)
ConvertType(SCC[i]);
SCCInProgress = 0;
+
+ // Finally, replace pointer types with a pointer to the pointee type (which
+ // has now been computed). This means that while uses of the pointer type
+ // by types in the SCC will most likely have been converted into nasty {}*,
+ // uses by types outside the SCC will see a sensible pointer type. This is
+ // not needed for correctness - it just makes the IR nicer.
+ if (SCC.size() > 1)
+ for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
+ tree some_type = SCC[i];
+ if (POINTER_TYPE_P(some_type)) {
+ tree pointee = TYPE_MAIN_VARIANT(TREE_TYPE(some_type));
+ // The pointee cannot have void type since the SCC contains more than
+ // one type.
+ assert(!VOID_TYPE_P(pointee) && "Self-recursive void*!");
+ // The pointee must have been converted since it has to be in the same
+ // SCC as the pointer (since the SCC contains more than one type).
+ Type *PointeeTy = getCachedType(pointee);
+ assert(PointeeTy && "Pointee not converted!");
+ llvm_set_type(some_type, PointeeTy->getPointerTo());
+ }
+ }
}
// At this point every type reachable from this one has been converted, and
More information about the llvm-commits
mailing list