From d5b48ca422089a17fa6ba2945d3f8b46fff7d689 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 14 Nov 2001 11:02:49 +0000 Subject: Better heuristics for handling arrays git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1296 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/SimpleStructMutation.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'lib/Transforms/IPO/SimpleStructMutation.cpp') diff --git a/lib/Transforms/IPO/SimpleStructMutation.cpp b/lib/Transforms/IPO/SimpleStructMutation.cpp index 8ec7f4b7a8..c8f8896766 100644 --- a/lib/Transforms/IPO/SimpleStructMutation.cpp +++ b/lib/Transforms/IPO/SimpleStructMutation.cpp @@ -12,6 +12,8 @@ #include "llvm/Analysis/FindUnsafePointerTypes.h" #include "llvm/DerivedTypes.h" +#include "llvm/Assembly/Writer.h" + // PruneTypes - Given a type Ty, make sure that neither it, or one of its // subtypes, occur in TypesToModify. // @@ -21,14 +23,20 @@ static void PruneTypes(const Type *Ty, set &TypesToModify, ProcessedTypes.insert(Ty); // If the element is in TypesToModify, remove it now... - if (const StructType *ST = dyn_cast(Ty)) + if (const StructType *ST = dyn_cast(Ty)) { TypesToModify.erase(ST); // This doesn't fail if the element isn't present + cerr << "Unable to swap type: " << ST << endl; + } - // Remove all types that this type contains as well... + // Remove all types that this type contains as well... do not remove types + // that are referenced only through pointers, because we depend on the size of + // the pointer, not on what the structure points to. // for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end(); - I != E; ++I) - PruneTypes(*I, TypesToModify, ProcessedTypes); + I != E; ++I) { + if (!isa(*I)) + PruneTypes(*I, TypesToModify, ProcessedTypes); + } } @@ -54,8 +62,8 @@ bool SwapStructContents::doPassInitialization(Module *M) { const set &UsedTypes = FUT.getTypes(); - // Combine the two sets, weeding out non structure types. Closures should - // would be nice. + // Combine the two sets, weeding out non structure types. Closures in C++ + // sure would be nice. set TypesToModify; for (set::const_iterator I = UsedTypes.begin(), E = UsedTypes.end(); I != E; ++I) @@ -68,8 +76,10 @@ bool SwapStructContents::doPassInitialization(Module *M) { // set ProcessedTypes; for (set::const_iterator I = UnsafePTys.begin(), - E = UnsafePTys.end(); I != E; ++I) + E = UnsafePTys.end(); I != E; ++I) { + cerr << "Pruning type: " << *I << endl; PruneTypes(*I, TypesToModify, ProcessedTypes); + } // Build up a set of structure types that we are going to modify, and -- cgit v1.2.3