Skip to content

Commit 78fe6a3

Browse files
committed
[NFC] Extract the code to write instr profile into function writeInstrProfile
So that the function writeInstrProfile can be used in other places. Differential Revision: https://reviews.llvm.org/D83521
1 parent 722475a commit 78fe6a3

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

llvm/tools/llvm-profdata/llvm-profdata.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,22 @@ static void mergeWriterContexts(WriterContext *Dst, WriterContext *Src) {
291291
});
292292
}
293293

294+
static void writeInstrProfile(StringRef OutputFilename,
295+
ProfileFormat OutputFormat,
296+
InstrProfWriter &Writer) {
297+
std::error_code EC;
298+
raw_fd_ostream Output(OutputFilename.data(), EC, sys::fs::OF_None);
299+
if (EC)
300+
exitWithErrorCode(EC, OutputFilename);
301+
302+
if (OutputFormat == PF_Text) {
303+
if (Error E = Writer.writeText(Output))
304+
exitWithError(std::move(E));
305+
} else {
306+
Writer.write(Output);
307+
}
308+
}
309+
294310
static void mergeInstrProfile(const WeightedFileVector &Inputs,
295311
SymbolRemapper *Remapper,
296312
StringRef OutputFilename,
@@ -366,18 +382,7 @@ static void mergeInstrProfile(const WeightedFileVector &Inputs,
366382
(NumErrors > 0 && FailMode == failIfAnyAreInvalid))
367383
exitWithError("No profiles could be merged.");
368384

369-
std::error_code EC;
370-
raw_fd_ostream Output(OutputFilename.data(), EC, sys::fs::OF_None);
371-
if (EC)
372-
exitWithErrorCode(EC, OutputFilename);
373-
374-
InstrProfWriter &Writer = Contexts[0]->Writer;
375-
if (OutputFormat == PF_Text) {
376-
if (Error E = Writer.writeText(Output))
377-
exitWithError(std::move(E));
378-
} else {
379-
Writer.write(Output);
380-
}
385+
writeInstrProfile(OutputFilename, OutputFormat, Contexts[0]->Writer);
381386
}
382387

383388
/// Make a copy of the given function samples with all symbol names remapped

0 commit comments

Comments
 (0)