/// findUsedStructTypes - Walk the entire module and find all of the
/// struct types that are in use, returning them in a vector.
- void findUsedStructTypes(std::vector<StructType*> &StructTypes) const;
+ void findUsedStructTypes(std::vector<StructType*> &StructTypes,
+ bool OnlyNamed = false) const;
/// getTypeByName - Return the type with the specified name, or null if there
/// is none by that name.
// example. When the source module got loaded into the same LLVMContext, if
// it had the same type, it would have been renamed to "%foo.42 = { i32 }".
std::vector<StructType*> SrcStructTypes;
- SrcM->findUsedStructTypes(SrcStructTypes);
+ SrcM->findUsedStructTypes(SrcStructTypes, true);
SmallPtrSet<StructType*, 32> SrcStructTypesSet(SrcStructTypes.begin(),
SrcStructTypes.end());
std::vector<StructType*> DstStructTypes;
- DstM->findUsedStructTypes(DstStructTypes);
+ DstM->findUsedStructTypes(DstStructTypes, true);
SmallPtrSet<StructType*, 32> DstStructTypesSet(DstStructTypes.begin(),
DstStructTypes.end());
DenseSet<Type*> VisitedTypes;
std::vector<StructType*> &StructTypes;
+ bool OnlyNamed;
public:
- TypeFinder(std::vector<StructType*> &structTypes)
- : StructTypes(structTypes) {}
+ TypeFinder(std::vector<StructType*> &structTypes, bool onlyNamed)
+ : StructTypes(structTypes), OnlyNamed(onlyNamed) {}
void run(const Module &M) {
// Get types from global variables.
// If this is a structure or opaque type, add a name for the type.
if (StructType *STy = dyn_cast<StructType>(Ty))
- StructTypes.push_back(STy);
+ if (!OnlyNamed || STy->hasName())
+ StructTypes.push_back(STy);
// Recursively walk all contained types.
for (Type::subtype_iterator I = Ty->subtype_begin(),
};
} // end anonymous namespace
-void Module::findUsedStructTypes(std::vector<StructType*> &StructTypes) const {
- TypeFinder(StructTypes).run(*this);
+void Module::findUsedStructTypes(std::vector<StructType*> &StructTypes,
+ bool OnlyNamed) const {
+ TypeFinder(StructTypes, OnlyNamed).run(*this);
}