[llvm] [IRMover] Don't consider opaque types isomorphic to other types (PR #138241)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 2 00:08:30 PDT 2025
================
@@ -88,45 +69,18 @@ class TypeMapTy : public ValueMapTypeRemapper {
private:
Type *remapType(Type *SrcTy) override { return get(SrcTy); }
- bool areTypesIsomorphic(Type *DstTy, Type *SrcTy);
+ bool tryToEstablishTypeIsomorphism(Type *DstTy, Type *SrcTy);
};
}
void TypeMapTy::addTypeMapping(Type *DstTy, Type *SrcTy) {
- assert(SpeculativeTypes.empty());
- assert(SpeculativeDstOpaqueTypes.empty());
-
- // Check to see if these types are recursively isomorphic and establish a
- // mapping between them if so.
- if (!areTypesIsomorphic(DstTy, SrcTy)) {
- // Oops, they aren't isomorphic. Just discard this request by rolling out
- // any speculative mappings we've established.
- for (Type *Ty : SpeculativeTypes)
- MappedTypes.erase(Ty);
-
- SrcDefinitionsToResolve.resize(SrcDefinitionsToResolve.size() -
- SpeculativeDstOpaqueTypes.size());
- for (StructType *Ty : SpeculativeDstOpaqueTypes)
- DstResolvedOpaqueTypes.erase(Ty);
- } else {
- // SrcTy and DstTy are recursively ismorphic. We clear names of SrcTy
- // and all its descendants to lower amount of renaming in LLVM context
- // Renaming occurs because we load all source modules to the same context
- // and declaration with existing name gets renamed (i.e Foo -> Foo.42).
- // As a result we may get several different types in the destination
- // module, which are in fact the same.
- for (Type *Ty : SpeculativeTypes)
- if (auto *STy = dyn_cast<StructType>(Ty))
- if (STy->hasName())
- STy->setName("");
- }
- SpeculativeTypes.clear();
- SpeculativeDstOpaqueTypes.clear();
+ tryToEstablishTypeIsomorphism(DstTy, SrcTy);
----------------
antoniofrighetto wrote:
Doesn't it sound like type mapping insertion and clear name should be up to addTypeMapping, and just check if types are isomorphic? Or, at least, it feels like now the wrapper could be `tryAddTypeMapping` (and the function itself maybe `addIfTypesAreIsomorphic`).
https://github.com/llvm/llvm-project/pull/138241
More information about the llvm-commits
mailing list