From 65f437ce7b477b19f2d54fee1f95100de75a628d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 28 Jun 2004 00:44:18 +0000 Subject: [PATCH] These passes are long dead/obsolete. They never worked in the first place and are a maintenence burden. Nuke nuke nuke git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14457 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/SimpleStructMutation.cpp | 188 -------------------- 1 file changed, 188 deletions(-) delete mode 100644 lib/Transforms/IPO/SimpleStructMutation.cpp diff --git a/lib/Transforms/IPO/SimpleStructMutation.cpp b/lib/Transforms/IPO/SimpleStructMutation.cpp deleted file mode 100644 index 401677a8817..00000000000 --- a/lib/Transforms/IPO/SimpleStructMutation.cpp +++ /dev/null @@ -1,188 +0,0 @@ -//===- SimpleStructMutation.cpp - Swap structure elements around ----------===// -// -// The LLVM Compiler Infrastructure -// -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This pass does a simple transformation that swaps all of the elements of the -// struct types in the program around. -// -//===----------------------------------------------------------------------===// - -#include "llvm/Transforms/IPO.h" -#include "llvm/Transforms/MutateStructTypes.h" -#include "llvm/Analysis/FindUsedTypes.h" -#include "llvm/Analysis/FindUnsafePointerTypes.h" -#include "llvm/Target/TargetData.h" -#include "llvm/DerivedTypes.h" -#include -using namespace llvm; - -namespace { - struct SimpleStructMutation : public MutateStructTypes { - enum Transform { SwapElements, SortElements }; - - virtual bool run(Module &M) = 0; - - // getAnalysisUsage - This function needs the results of the - // FindUsedTypes and FindUnsafePointerTypes analysis passes... - // - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.addRequired(); - AU.addRequired(); - AU.addRequired(); - MutateStructTypes::getAnalysisUsage(AU); - } - - protected: - TransformsType getTransforms(Module &M, enum Transform); - }; - - struct SwapStructElements : public SimpleStructMutation { - virtual bool run(Module &M) { - setTransforms(getTransforms(M, SwapElements)); - bool Changed = MutateStructTypes::run(M); - clearTransforms(); - return Changed; - } - }; - - struct SortStructElements : public SimpleStructMutation { - virtual bool run(Module &M) { - setTransforms(getTransforms(M, SortElements)); - bool Changed = MutateStructTypes::run(M); - clearTransforms(); - return Changed; - } - }; - - RegisterOpt X("swapstructs", - "Swap structure types around"); - RegisterOpt Y("sortstructs", - "Sort structure elements by size"); -} // end anonymous namespace - -Pass *createSwapElementsPass() { return new SwapStructElements(); } -Pass *createSortElementsPass() { return new SortStructElements(); } - - -// PruneTypes - Given a type Ty, make sure that neither it, or one of its -// subtypes, occur in TypesToModify. -// -static void PruneTypes(const Type *Ty, - std::set &TypesToModify, - std::set &ProcessedTypes) { - if (ProcessedTypes.count(Ty)) return; // Already been checked - ProcessedTypes.insert(Ty); - - // If the element is in TypesToModify, remove it now... - if (const StructType *ST = dyn_cast(Ty)) { - TypesToModify.erase(ST); // This doesn't fail if the element isn't present - std::cerr << "Unable to swap type: " << ST << "\n"; - } - - // 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) { - if (!isa(I->get())) - PruneTypes(*I, TypesToModify, ProcessedTypes); - } -} - -static bool FirstLess(const std::pair &LHS, - const std::pair &RHS) { - return LHS.second < RHS.second; -} - -static unsigned getIndex(const std::vector > &Vec, - unsigned Field) { - for (unsigned i = 0; ; ++i) - if (Vec[i].first == Field) return i; -} - -static inline void GetTransformation(const TargetData &TD, const StructType *ST, - std::vector &Transform, - enum SimpleStructMutation::Transform XForm) { - unsigned NumElements = ST->getNumElements(); - Transform.reserve(NumElements); - - switch (XForm) { - case SimpleStructMutation::SwapElements: - // The transformation to do is: just simply swap the elements - for (unsigned i = 0; i < NumElements; ++i) - Transform.push_back(NumElements-i-1); - break; - - case SimpleStructMutation::SortElements: { - std::vector > ElList; - - // Build mapping from index to size - for (unsigned i = 0; i < NumElements; ++i) - ElList.push_back(std::make_pair(i,TD.getTypeSize(ST->getElementType(i)))); - - sort(ElList.begin(), ElList.end(), ptr_fun(FirstLess)); - - for (unsigned i = 0; i < NumElements; ++i) - Transform.push_back(getIndex(ElList, i)); - - break; - } - } -} - - -SimpleStructMutation::TransformsType - SimpleStructMutation::getTransforms(Module &, enum Transform XForm) { - // We need to know which types to modify, and which types we CAN'T modify - // TODO: Do symbol tables as well - - // Get the results out of the analyzers... - FindUsedTypes &FUT = getAnalysis(); - const std::set &UsedTypes = FUT.getTypes(); - - FindUnsafePointerTypes &FUPT = getAnalysis(); - const std::set &UnsafePTys = FUPT.getUnsafeTypes(); - - - // Combine the two sets, weeding out non structure types. Closures in C++ - // sure would be nice. - std::set TypesToModify; - for (std::set::const_iterator I = UsedTypes.begin(), - E = UsedTypes.end(); I != E; ++I) - if (const StructType *ST = dyn_cast(*I)) - TypesToModify.insert(ST); - - - // Go through the Unsafe types and remove all types from TypesToModify that we - // are not allowed to modify, because that would be unsafe. - // - std::set ProcessedTypes; - for (std::set::const_iterator I = UnsafePTys.begin(), - E = UnsafePTys.end(); I != E; ++I) { - //cerr << "Pruning type: " << *I << "\n"; - PruneTypes(*I, TypesToModify, ProcessedTypes); - } - - - // Build up a set of structure types that we are going to modify, and - // information describing how to modify them. - std::map > Transforms; - TargetData &TD = getAnalysis(); - - for (std::set::iterator I = TypesToModify.begin(), - E = TypesToModify.end(); I != E; ++I) { - const StructType *ST = *I; - - std::vector &Transform = Transforms[ST]; // Fill in the map directly - GetTransformation(TD, ST, Transform, XForm); - } - - return Transforms; -} -