[llvm] [llvm] Optimize print-on-crash serialization (PR #205682)

Miguel A. Arroyo via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 28 21:04:56 PDT 2026


================
@@ -331,6 +332,52 @@ void unwrapAndPrint(raw_ostream &OS, Any IR) {
   llvm_unreachable("Unknown wrapped IR type");
 }
 
+std::optional<std::pair<std::unique_ptr<Module>, std::vector<Function *>>>
+unwrapAndSaveClone(Any IR) {
+  std::vector<Function *> ValuesToSave;
+
+  if (!shouldPrintIR(IR))
+    return std::nullopt;
+
+  auto *OrigM = unwrapModule(IR);
+  auto M = CloneModule(*OrigM);
----------------
mayanez wrote:

Good question! 

The challenge I found with cloning functions is that `CloneFunction` clones into the existing module. 

This means we'd either need to:
  a) cleanup the module to remove the temporary clones (IIUC this requires traversal as opposed to just deallocation of the cloned module) or 
  b) create a temporary module and create copies of the functions there (AFAIK there doesn't seem to be a good API for this, but happy to be pointed in the right direction as this should be most optimal as you mention).

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


More information about the llvm-commits mailing list