// Strip any named types of their names. static void StripTypeNames(Module &M, bool PreserveDbgInfo) { TypeFinder StructTypes; StructTypes.run(M, false); for (unsigned i = 0, e = StructTypes.size(); i != e; ++i) { StructType *STy = StructTypes[i]; if (STy->isLiteral() || STy->getName().empty()) continue; if (PreserveDbgInfo && STy->getName().startswith("llvm.dbg")) continue; STy->setName(""); } }
void TypeListItem::CreateChildren( wxTreeCtrl* tree, const wxTreeItemId & id) { std::vector<StructType*> structTypes; module_->findUsedStructTypes(structTypes); for (unsigned i = 0, e = structTypes.size(); i != e; ++i) { StructType *sty = structTypes[i]; llvm::StringRef name; if (sty->isLiteral()) { name = "literal struct"; } else if (sty->hasName()) { name = sty->getName(); } else { continue; } CreateChild(tree, id, new TypeItem(module_, sty, toWxStr(name))); } tree->SortChildren(id); }
// return value: -1 recursive dependence // 0 not isomorphic // 1 isomorphic int MCallGraph::areTypesIsomorphic(Type *DstTy, Type *SrcTy) { if (DstTy == NULL || SrcTy == NULL) return DstTy == SrcTy; // normalize parameter order if (DstTy > SrcTy) return areTypesIsomorphic(SrcTy, DstTy); // TODO: this is a hack to fix-up an error in clang's LLVM code generator, // which messes up certain structs. if (isEmptyStructPointer(DstTy) && SrcTy->isPointerTy()) return 1; // TODO: this is a hack to fix-up an error in clang's LLVM code generator, // which messes up certain structs. if (isEmptyStructPointer(SrcTy) && DstTy->isPointerTy()) return 1; // Two types with differing kinds are clearly not isomorphic. if (DstTy->getTypeID() != SrcTy->getTypeID()) return 0; // check for recursion and known equivalent types equivalent_types_t::const_iterator tmp(EQ.find(std::make_pair(DstTy, SrcTy))); if (tmp != EQ.end()) { return tmp->second; } // Two identical types are clearly isomorphic. Remember this // non-speculatively. if (DstTy == SrcTy) { return 1; } // Okay, we have two types with identical kinds that we haven't seen before. // assume types are not identical for now EQ[std::make_pair(DstTy, SrcTy)] = 0; // If this is an opaque struct type, special case it. if (StructType *SSTy = dyn_cast<StructType>(SrcTy)) { if (SSTy->isOpaque()) { assert(false); return 1; } if (cast<StructType>(DstTy)->isOpaque()) { assert(false); return 1; } } // If the number of subtypes disagree between the two types, then we fail. if (SrcTy->getNumContainedTypes() != DstTy->getNumContainedTypes()) return 0; // Fail if any of the extra properties (e.g. array size) of the type disagree. if (isa<IntegerType>(DstTy)) return 0; // bitwidth disagrees. if (PointerType *PT = dyn_cast<PointerType>(DstTy)) { if (PT->getAddressSpace() != cast<PointerType>(SrcTy)->getAddressSpace()) return 0; } else if (FunctionType *FT = dyn_cast<FunctionType>(DstTy)) { if (FT->isVarArg() != cast<FunctionType>(SrcTy)->isVarArg()) return 0; } else if (StructType *DSTy = dyn_cast<StructType>(DstTy)) { StructType *SSTy = cast<StructType>(SrcTy); if (DSTy->isLiteral() != SSTy->isLiteral() || DSTy->isPacked() != SSTy->isPacked()) return 0; } else if (ArrayType *DATy = dyn_cast<ArrayType>(DstTy)) { if (DATy->getNumElements() != cast<ArrayType>(SrcTy)->getNumElements()) return 0; } else if (VectorType *DVTy = dyn_cast<VectorType>(DstTy)) { if (DVTy->getNumElements() != cast<ArrayType>(SrcTy)->getNumElements()) return 0; } // Otherwise, we speculate that these two types will line up and recursively // check the subelements. // ok, we need to recurs, mark the types accordingly. EQ[std::make_pair(DstTy, SrcTy)] = -1; int retval = 1; for (unsigned i = 0, e = SrcTy->getNumContainedTypes(); i != e; ++i) { switch (areTypesIsomorphic(DstTy->getContainedType(i), SrcTy->getContainedType(i))) { case 0: // ok, types do not match EQ[std::make_pair(DstTy, SrcTy)] = 0; return 0; case -1: retval = -1; break; } } // seems the types match EQ[std::make_pair(DstTy, SrcTy)] = retval; // If everything seems to have lined up, then everything is great. return retval; }
/// Recursively walk this pair of types, returning true if they are isomorphic, /// false if they are not. bool TypeMapTy::areTypesIsomorphic(Type *DstTy, Type *SrcTy) { // Two types with differing kinds are clearly not isomorphic. if (DstTy->getTypeID() != SrcTy->getTypeID()) return false; // If we have an entry in the MappedTypes table, then we have our answer. Type *&Entry = MappedTypes[SrcTy]; if (Entry) return Entry == DstTy; // Two identical types are clearly isomorphic. Remember this // non-speculatively. if (DstTy == SrcTy) { Entry = DstTy; return true; } // Okay, we have two types with identical kinds that we haven't seen before. // If this is an opaque struct type, special case it. if (StructType *SSTy = dyn_cast<StructType>(SrcTy)) { // Mapping an opaque type to any struct, just keep the dest struct. if (SSTy->isOpaque()) { Entry = DstTy; SpeculativeTypes.push_back(SrcTy); return true; } // Mapping a non-opaque source type to an opaque dest. If this is the first // type that we're mapping onto this destination type then we succeed. Keep // the dest, but fill it in later. If this is the second (different) type // that we're trying to map onto the same opaque type then we fail. if (cast<StructType>(DstTy)->isOpaque()) { // We can only map one source type onto the opaque destination type. if (!DstResolvedOpaqueTypes.insert(cast<StructType>(DstTy)).second) return false; SrcDefinitionsToResolve.push_back(SSTy); SpeculativeTypes.push_back(SrcTy); SpeculativeDstOpaqueTypes.push_back(cast<StructType>(DstTy)); Entry = DstTy; return true; } } // If the number of subtypes disagree between the two types, then we fail. if (SrcTy->getNumContainedTypes() != DstTy->getNumContainedTypes()) return false; // Fail if any of the extra properties (e.g. array size) of the type disagree. if (isa<IntegerType>(DstTy)) return false; // bitwidth disagrees. if (PointerType *PT = dyn_cast<PointerType>(DstTy)) { if (PT->getAddressSpace() != cast<PointerType>(SrcTy)->getAddressSpace()) return false; } else if (FunctionType *FT = dyn_cast<FunctionType>(DstTy)) { if (FT->isVarArg() != cast<FunctionType>(SrcTy)->isVarArg()) return false; } else if (StructType *DSTy = dyn_cast<StructType>(DstTy)) { StructType *SSTy = cast<StructType>(SrcTy); if (DSTy->isLiteral() != SSTy->isLiteral() || DSTy->isPacked() != SSTy->isPacked()) return false; } else if (ArrayType *DATy = dyn_cast<ArrayType>(DstTy)) { if (DATy->getNumElements() != cast<ArrayType>(SrcTy)->getNumElements()) return false; } else if (VectorType *DVTy = dyn_cast<VectorType>(DstTy)) { if (DVTy->getNumElements() != cast<VectorType>(SrcTy)->getNumElements()) return false; } // Otherwise, we speculate that these two types will line up and recursively // check the subelements. Entry = DstTy; SpeculativeTypes.push_back(SrcTy); for (unsigned I = 0, E = SrcTy->getNumContainedTypes(); I != E; ++I) if (!areTypesIsomorphic(DstTy->getContainedType(I), SrcTy->getContainedType(I))) return false; // If everything seems to have lined up, then everything is great. return true; }