[clang-tools-extra] [llvm] [clang] [AsmPrinter] Remove mbb-profile-dump flag (PR #76595)

Aiden Grossman via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 23 16:48:15 PST 2024


https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/76595

>From 55cf94d98c38cd2b5cd8fbf76e5fd83b5a47f4af Mon Sep 17 00:00:00 2001
From: Aiden Grossman <agrossman154 at yahoo.com>
Date: Fri, 29 Dec 2023 16:14:15 -0800
Subject: [PATCH] [AsmPrinter] Remove mbb-profile-dump flag

Now that the work embedding PGO information in SHT_LLVM_BB_ADDR_MAP ELF
sections has landed, there is no longer a need to keep around the
mbb-profile-dump flag.
---
 llvm/include/llvm/CodeGen/AsmPrinter.h       |  4 --
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp   | 51 -----------------
 llvm/test/CodeGen/Generic/bb-profile-dump.ll | 59 --------------------
 3 files changed, 114 deletions(-)
 delete mode 100644 llvm/test/CodeGen/Generic/bb-profile-dump.ll

diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h
index 5ec246ee7015c4..fbd198a75a2436 100644
--- a/llvm/include/llvm/CodeGen/AsmPrinter.h
+++ b/llvm/include/llvm/CodeGen/AsmPrinter.h
@@ -236,10 +236,6 @@ class AsmPrinter : public MachineFunctionPass {
   /// split stack prologue.
   bool HasNoSplitStack = false;
 
-  /// Raw FDOstream for outputting machine basic block frequncies if the
-  /// --mbb-profile-dump flag is set for downstream cost modelling applications
-  std::unique_ptr<raw_fd_ostream> MBBProfileDumpFileOutput;
-
 protected:
   explicit AsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer);
 
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 4dd27702786e42..93857b05488b77 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -133,13 +133,6 @@ using namespace llvm;
 
 #define DEBUG_TYPE "asm-printer"
 
-static cl::opt<std::string> 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 -basic-block-sections=labels. Enabling this "
-             "flag during in-process ThinLTO is not supported."));
-
 const char DWARFGroupName[] = "dwarf";
 const char DWARFGroupDescription[] = "DWARF Emission";
 const char DbgTimerName[] = "emit";
@@ -624,16 +617,6 @@ bool AsmPrinter::doInitialization(Module &M) {
     HI.Handler->beginModule(&M);
   }
 
-  if (!BasicBlockProfileDump.empty()) {
-    std::error_code PossibleFileError;
-    MBBProfileDumpFileOutput = std::make_unique<raw_fd_ostream>(
-        BasicBlockProfileDump, PossibleFileError);
-    if (PossibleFileError) {
-      M.getContext().emitError("Failed to open file for MBB Profile Dump: " +
-                               PossibleFileError.message() + "\n");
-    }
-  }
-
   return false;
 }
 
@@ -1952,40 +1935,6 @@ void AsmPrinter::emitFunctionBody() {
     OutStreamer->getCommentOS() << "-- End function\n";
 
   OutStreamer->addBlankLine();
-
-  // Output MBB ids, function names, and frequencies if the flag to dump
-  // MBB profile information has been set
-  if (MBBProfileDumpFileOutput && !MF->empty() &&
-      MF->getFunction().getEntryCount()) {
-    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");
-    } else {
-      MachineBlockFrequencyInfo &MBFI =
-          getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI();
-      // The entry count and the entry basic block frequency aren't the same. We
-      // want to capture "absolute" frequencies, i.e. the frequency with which a
-      // MBB is executed when the program is executed. From there, we can derive
-      // Function-relative frequencies (divide by the value for the first MBB).
-      // We also have the information about frequency with which functions
-      // were called. This helps, for example, in a type of integration tests
-      // where we want to cross-validate the compiler's profile with a real
-      // profile.
-      // Using double precision because uint64 values used to encode mbb
-      // "frequencies" may be quite large.
-      const double EntryCount =
-          static_cast<double>(MF->getFunction().getEntryCount()->getCount());
-      for (const auto &MBB : *MF) {
-        const double MBBRelFreq = MBFI.getBlockFreqRelativeToEntryBlock(&MBB);
-        const double AbsMBBFreq = MBBRelFreq * EntryCount;
-        *MBBProfileDumpFileOutput.get()
-            << MF->getName() << "," << MBB.getBBID()->BaseID << ","
-            << AbsMBBFreq << "\n";
-      }
-    }
-  }
 }
 
 /// Compute the number of Global Variables that uses a Constant.
diff --git a/llvm/test/CodeGen/Generic/bb-profile-dump.ll b/llvm/test/CodeGen/Generic/bb-profile-dump.ll
deleted file mode 100644
index 7391a6ee6f9128..00000000000000
--- a/llvm/test/CodeGen/Generic/bb-profile-dump.ll
+++ /dev/null
@@ -1,59 +0,0 @@
-; REQUIRES: x86-registered-target
-;
-; Check that the basic block profile dump outputs data and in the correct
-; format.
-;
-; RUN: llc -mtriple=x86_64-linux-unknown -o /dev/null -basic-block-sections=labels -mbb-profile-dump=- %s | FileCheck %s
-
-; Check that given a simple case, we can return the default MBFI
-
-define i64 @f2(i64 %a, i64 %b) !prof !1{
-    %sum = add i64 %a, %b
-    ret i64 %sum
-}
-
-; CHECK: f2,0,1.000000e+03
-
-define i64 @f1() !prof !2{
-    %sum = call i64 @f2(i64 2, i64 2)
-    %isEqual = icmp eq i64 %sum, 4
-    br i1 %isEqual, label %ifEqual, label %ifNotEqual, !prof !3
-ifEqual:
-    ret i64 0
-ifNotEqual:
-    ret i64 %sum
-}
-
-; CHECK-NEXT: f1,0,1.000000e+01
-; CHECK-NEXT: f1,2,6.000000e+00
-; CHECK-NEXT: f1,1,4.000000e+00
-
-define void @f3(i32 %iter) !prof !4 {
-entry:
-    br label %loop
-loop:
-    %i = phi i32 [0, %entry], [%i_next, %loop]
-    %i_next = add i32 %i, 1
-    %exit_cond = icmp slt i32 %i_next, %iter
-    br i1 %exit_cond, label %loop, label %exit, !prof !5
-exit:
-    ret void
-}
-
-; CHECK-NEXT: f3,0,2.000000e+00
-; CHECK-NEXT: f3,1,2.002000e+03
-; CHECK-NEXT: f3,2,2.000000e+00
-
-!1 = !{!"function_entry_count", i64 1000}
-!2 = !{!"function_entry_count", i64 10}
-!3 = !{!"branch_weights", i32 2, i32 3}
-!4 = !{!"function_entry_count", i64 2}
-!5 = !{!"branch_weights", i32 1000, i32 1}
-
-; 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: <unknown>:0: error: Unable to find BB labels for MBB profile dump. -mbb-profile-dump must be called with -basic-block-sections=labels
-



More information about the cfe-commits mailing list