[llvm] Add option to dump IR to files instead of stderr (PR #66412)
Nuri Amari via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 28 13:58:25 PDT 2023
================
@@ -733,21 +822,31 @@ void PrintIRInstrumentation::printAfterPass(StringRef PassID, Any IR) {
!shouldPrintAtPassNumber())
return;
- const Module *M;
- std::string IRName;
- StringRef StoredPassID;
- std::tie(M, IRName, StoredPassID) = popModuleDesc(PassID);
+ auto [M, DumpIRFilename, IRName, StoredPassID] = popPassRunDescriptor(PassID);
assert(StoredPassID == PassID && "mismatched PassID");
if (!shouldPrintIR(IR) || !shouldPrintAfterPass(PassID))
return;
- dbgs() << "*** IR Dump "
- << (shouldPrintAtPassNumber()
- ? StringRef(formatv("At {0}-{1}", CurrentPassNumber, PassID))
- : StringRef(formatv("After {0}", PassID)))
- << " on " << IRName << " ***\n";
- unwrapAndPrint(dbgs(), IR);
+ auto WriteIRToStream = [&](raw_ostream &Stream, const StringRef IRName) {
+ Stream << "; *** IR Dump "
+ << (shouldPrintAtPassNumber()
+ ? StringRef(formatv("At {0}-{1}", CurrentPassNumber, PassID))
+ : StringRef(formatv("After {0}", PassID)))
+ << " on " << IRName << " ***\n";
+ unwrapAndPrint(Stream, IR);
+ };
+
+ if (!irDumpDirectory().empty()) {
+ assert(!DumpIRFilename.empty() && "DumpIRFilename must not be empty and "
+ "should be set in printBeforePass");
+ DumpIRFilename += getFileSuffix(SuffixType::After);
+ llvm::raw_fd_ostream DumpIRFileStream{
+ prepareDumpIRFileDescriptor(DumpIRFilename), /* shouldClose */ true};
+ WriteIRToStream(DumpIRFileStream, IRName);
+ } else {
+ WriteIRToStream(dbgs(), IRName);
+ }
}
void PrintIRInstrumentation::printAfterPassInvalidated(StringRef PassID) {
----------------
NuriAmari wrote:
Worked, thanks
https://github.com/llvm/llvm-project/pull/66412
More information about the llvm-commits
mailing list