diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index a663c957dac02..10b6e52dc9649 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -133,7 +133,7 @@ static cl::opt BasicBlockProfileDump( "mbb-profile-dump", cl::Hidden, cl::desc("Basic block profile dump for external cost modelling. If " "matching up BBs with afterwards, the compilation must be " - "performed with -fbasic-block-sections=labels. Enabling this " + "performed with -basic-block-sections=labels. Enabling this " "flag during in-process ThinLTO is not supported.")); const char DWARFGroupName[] = "dwarf"; @@ -1924,14 +1924,19 @@ void AsmPrinter::emitFunctionBody() { OutStreamer->addBlankLine(); - // Output MBB numbers, function names, and frequencies if the flag to dump + // Output MBB ids, function names, and frequencies if the flag to dump // MBB profile information has been set if (MBBProfileDumpFileOutput) { + if (!MF->hasBBLabels()) + MF->getContext().reportError( + SMLoc(), + "Unable to find BB labels for MBB profile dump. -mbb-profile-dump " + "must be called with -basic-block-sections=labels"); MachineBlockFrequencyInfo &MBFI = getAnalysis().getBFI(); for (const auto &MBB : *MF) { *MBBProfileDumpFileOutput.get() - << MF->getName() << "," << MBB.getNumber() << "," + << MF->getName() << "," << MBB.getBBID() << "," << MBFI.getBlockFreqRelativeToEntryBlock(&MBB) << "\n"; } } diff --git a/llvm/test/CodeGen/MLRegalloc/bb-profile-dump.ll b/llvm/test/CodeGen/MLRegalloc/bb-profile-dump.ll index d876d73997482..34244e7500173 100644 --- a/llvm/test/CodeGen/MLRegalloc/bb-profile-dump.ll +++ b/llvm/test/CodeGen/MLRegalloc/bb-profile-dump.ll @@ -3,11 +3,13 @@ ; Check that the basic block profile dump outputs data and in the correct ; format. ; -; RUN: llc -mtriple=x86_64-linux-unknown -o /dev/null -mbb-profile-dump=- %s | FileCheck %s +; RUN: llc -mtriple=x86_64-linux-unknown -o /dev/null -basic-block-sections=labels -mbb-profile-dump=- %s | FileCheck %s ; bb profile dump is not supported on NVPTX ; UNSUPPORTED: target=nvptx{{.*}} +; Check that given a simple case, we can return the default MBFI + define i64 @f2(i64 %a, i64 %b) { %sum = add i64 %a, %b ret i64 %sum @@ -27,3 +29,11 @@ ifNotEqual: ; CHECK-NEXT: f1,0,1.000000e+00 ; CHECK-NEXT: f1,1,5.000000e-01 ; CHECK-NEXT: f1,2,1.000000e+00 + +; Check that if we pass -mbb-profile-dump but don't set -basic-block-sections, +; we get an appropriate error message + +; RUN: not llc -mtriple=x86_64-linux-unknown -o /dev/null -mbb-profile-dump=- %s 2>&1 | FileCheck --check-prefix=NO-SECTIONS %s + +; NO-SECTIONS: :0: error: Unable to find BB labels for MBB profile dump. -mbb-profile-dump must be called with -basic-block-sections=labels +