[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 01:42:25 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:

Right, what about something along the lines of `RecursivelyAddMappingIfTypesAreIsomorphic`? I'm not completely sure `tryToEstablishTypeIsomorphism` is emblematic enough to convey the mapping add (though this is mentioned in the doc-comment). Not strong on this, up to you.

https://github.com/llvm/llvm-project/pull/138241


More information about the llvm-commits mailing list