[llvm] Add option to dump IR to files instead of stderr (PR #66412)

Nuri Amari via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 15 11:07:51 PDT 2023


================
@@ -697,17 +754,42 @@ PrintIRInstrumentation::popModuleDesc(StringRef PassID) {
   return ModuleDesc;
 }
 
+// Callers are responsible for closing the returned file descriptor
+static int prepareDumpIRFileDescriptor(StringRef DumpIRFilename) {
+  std::error_code EC;
+  auto ParentPath = llvm::sys::path::parent_path(DumpIRFilename);
+  if (!ParentPath.empty()) {
+    std::error_code EC = llvm::sys::fs::create_directories(ParentPath);
+    if (EC)
+      report_fatal_error(Twine("Failed to create directory ") + ParentPath +
+                         " to support -ir-dump-directory: " + EC.message());
+  }
+  int Result = 0;
+  EC =
+      sys::fs::openFile(DumpIRFilename, Result, sys::fs::CD_OpenAlways,
+                        sys::fs::FA_Write | sys::fs::FA_Read, sys::fs::OF_None);
----------------
NuriAmari wrote:

Yeah I thought about this, and maybe I'm misunderstanding how file permissions work, but I thought the user is likely about to read from the log files, it would be convenient to open them with read permissions as well.

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


More information about the llvm-commits mailing list