Skip to content

[SHT_LLVM_BB_ADDR_MAP][AsmPrinter] Add none and all options to PGO Map #111221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

boomanaiden154
Copy link
Contributor

This patch adds none and all options to the -pgo-analysis-map flag, which do basically what they say on the tin. The none option is added to enable forcing the pgo-analysis-map by overriding an earlier invocation of the flag. The all option is just added for convenience.

This patch adds none and all options to the -pgo-analysis-map flag,
which do basically what they say on the tin. The none option is added to
enable forcing the pgo-analysis-map by overriding an earlier invocation
of the flag. The all option is just added for convenience.
@llvmbot
Copy link
Member

llvmbot commented Oct 5, 2024

@llvm/pr-subscribers-backend-x86

Author: Aiden Grossman (boomanaiden154)

Changes

This patch adds none and all options to the -pgo-analysis-map flag, which do basically what they say on the tin. The none option is added to enable forcing the pgo-analysis-map by overriding an earlier invocation of the flag. The all option is just added for convenience.


Full diff: https://github.com/llvm/llvm-project/pull/111221.diff

2 Files Affected:

  • (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+22-9)
  • (modified) llvm/test/CodeGen/X86/basic-block-address-map-pgo-features.ll (+6-1)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3a8cde7330efc0..6d1fbf29580e3a 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -141,18 +141,22 @@ using namespace llvm;
 // `object::PGOAnalysisMap::Features::decode(PgoAnalysisMapFeatures.getBits())`
 // succeeds.
 enum class PGOMapFeaturesEnum {
+  None,
   FuncEntryCount,
   BBFreq,
   BrProb,
+  All,
 };
 static cl::bits<PGOMapFeaturesEnum> PgoAnalysisMapFeatures(
     "pgo-analysis-map", cl::Hidden, cl::CommaSeparated,
-    cl::values(clEnumValN(PGOMapFeaturesEnum::FuncEntryCount,
-                          "func-entry-count", "Function Entry Count"),
-               clEnumValN(PGOMapFeaturesEnum::BBFreq, "bb-freq",
-                          "Basic Block Frequency"),
-               clEnumValN(PGOMapFeaturesEnum::BrProb, "br-prob",
-                          "Branch Probability")),
+    cl::values(
+        clEnumValN(PGOMapFeaturesEnum::None, "none", "Disable all options"),
+        clEnumValN(PGOMapFeaturesEnum::FuncEntryCount, "func-entry-count",
+                   "Function Entry Count"),
+        clEnumValN(PGOMapFeaturesEnum::BBFreq, "bb-freq",
+                   "Basic Block Frequency"),
+        clEnumValN(PGOMapFeaturesEnum::BrProb, "br-prob", "Branch Probability"),
+        clEnumValN(PGOMapFeaturesEnum::All, "all", "Enable all options")),
     cl::desc(
         "Enable extended information within the SHT_LLVM_BB_ADDR_MAP that is "
         "extracted from PGO related analysis."));
@@ -1367,9 +1371,18 @@ static uint32_t getBBAddrMapMetadata(const MachineBasicBlock &MBB) {
 
 static llvm::object::BBAddrMap::Features
 getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges) {
-  return {PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::FuncEntryCount),
-          PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::BBFreq),
-          PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::BrProb),
+  bool NoFeatures = PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::None);
+  bool AllFeatures = PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::All);
+  bool FuncEntryCountEnabled =
+      AllFeatures || (!NoFeatures && PgoAnalysisMapFeatures.isSet(
+                                         PGOMapFeaturesEnum::FuncEntryCount));
+  bool BBFreqEnabled =
+      AllFeatures ||
+      (!NoFeatures && PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::BBFreq));
+  bool BrProbEnabled =
+      AllFeatures ||
+      (!NoFeatures && PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::BrProb));
+  return {FuncEntryCountEnabled, BBFreqEnabled, BrProbEnabled,
           MF.hasBBSections() && NumMBBSectionRanges > 1};
 }
 
diff --git a/llvm/test/CodeGen/X86/basic-block-address-map-pgo-features.ll b/llvm/test/CodeGen/X86/basic-block-address-map-pgo-features.ll
index 73fe4f6ffedb0e..1c3db738a94768 100644
--- a/llvm/test/CodeGen/X86/basic-block-address-map-pgo-features.ll
+++ b/llvm/test/CodeGen/X86/basic-block-address-map-pgo-features.ll
@@ -1,8 +1,10 @@
 ; Check the basic block sections labels option
-; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map | FileCheck %s --check-prefixes=CHECK,BASIC
+; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map | FileCheck %s --check-prefixes=CHECK,BASIC,PGO-NONE
+; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map -pgo-analysis-map=none | FileCheck %s --check-prefixes=CHECK,BASIC,PGO-NONE
 
 ;; Also verify this holds for all PGO features enabled
 ; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map -pgo-analysis-map=func-entry-count,bb-freq,br-prob | FileCheck %s --check-prefixes=CHECK,PGO-ALL,PGO-FEC,PGO-BBF,PGO-BRP
+; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map -pgo-analysis-map=all | FileCheck %s --check-prefixes=CHECK,PGO-ALL,PGO-FEC,PGO-BBF,PGO-BRP
 
 ;; Also verify that pgo extension only includes the enabled feature
 ; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map -pgo-analysis-map=func-entry-count | FileCheck %s --check-prefixes=CHECK,PGO-FEC,FEC-ONLY
@@ -93,6 +95,9 @@ declare i32 @__gxx_personality_v0(...)
 ; CHECK-NEXT:	.byte	4
 
 ;; PGO Analysis Map
+; PGO-NONE-NOT: .byte	100		# function entry count
+; PGO-NONE-NOT: .ascii	"\271\235\376\332\245\200\356\017"	# basic block frequency
+; PGO-NONE-NOT: .byte	2		# basic block successor count
 ; PGO-FEC-NEXT:	.byte	100		# function entry count
 ; PGO-BBF-NEXT:	.ascii	"\271\235\376\332\245\200\356\017"	# basic block frequency
 ; PGO-BRP-NEXT:	.byte	2		# basic block successor count

@red1bluelost
Copy link
Member

I think an 'all' option seems good. Why do we want a 'none'? My thought is that would just be omitting the pgo-analysis-map option.

@boomanaiden154
Copy link
Contributor Author

I think an 'all' option seems good. Why do we want a 'none'? My thought is that would just be omitting the pgo-analysis-map option.

With certain build systems (bazel in this case), it can be useful to have the ability to have the ability to append something to the compiler command line to force the option off when building certain applications/files that interact poorly with these options (like certain configurations of OpenSSL).

@red1bluelost
Copy link
Member

I think an 'all' option seems good. Why do we want a 'none'? My thought is that would just be omitting the pgo-analysis-map option.

With certain build systems (bazel in this case), it can be useful to have the ability to have the ability to append something to the compiler command line to force the option off when building certain applications/files that interact poorly with these options (like certain configurations of OpenSSL).

Good example! That makes sense.

Copy link
Member

@red1bluelost red1bluelost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@boomanaiden154 boomanaiden154 merged commit 38caf28 into llvm:main Oct 25, 2024
11 checks passed
@boomanaiden154 boomanaiden154 deleted the pgo-analysis-map-all-none-options branch October 25, 2024 22:39
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 25, 2024

LLVM Buildbot has detected a new failure on builder openmp-s390x-linux running on systemz-1 while building llvm at step 6 "test-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/3903

Here is the relevant piece of the build log for the reference
Step 6 (test-openmp) failure: test (failure)
******************** TEST 'libomp :: tasking/issue-94260-2.c' FAILED ********************
Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang -fopenmp   -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test -L /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src  -fno-omit-frame-pointer -mbackchain -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic && /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang -fopenmp -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test -L /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -fno-omit-frame-pointer -mbackchain -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic
# executed command: /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 26, 2024

LLVM Buildbot has detected a new failure on builder llvm-x86_64-debian-dylib running on gribozavr4 while building llvm at step 6 "test-build-unified-tree-check-clang".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/11122

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-clang) failure: test (failure)
******************** TEST 'Clang :: Modules/no-external-type-id.cppm' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: rm -rf /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp
+ rm -rf /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp
RUN: at line 4: split-file /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/Modules/no-external-type-id.cppm /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp
+ split-file /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/Modules/no-external-type-id.cppm /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp
RUN: at line 5: cd /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp
+ cd /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp
RUN: at line 7: /b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/20/include -nostdsysteminc -std=c++20 /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/a.cppm -emit-module-interface -o /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/a.pcm
+ /b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/20/include -nostdsysteminc -std=c++20 /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/a.cppm -emit-module-interface -o /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/a.pcm
RUN: at line 8: /b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/20/include -nostdsysteminc -std=c++20 /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/b.cppm -emit-module-interface -o /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/b.pcm      -fmodule-file=a=/b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/a.pcm
+ /b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/20/include -nostdsysteminc -std=c++20 /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/b.cppm -emit-module-interface -o /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/b.pcm -fmodule-file=a=/b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/a.pcm
RUN: at line 10: llvm-bcanalyzer --dump --disable-histogram /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/b.pcm | /b/1/llvm-x86_64-debian-dylib/build/bin/FileCheck /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/b.cppm
+ llvm-bcanalyzer --dump --disable-histogram /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/b.pcm
+ /b/1/llvm-x86_64-debian-dylib/build/bin/FileCheck /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/b.cppm
/b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/b.cppm:5:11: error: CHECK: expected string not found in input
// CHECK: <DECL_FUNCTION {{.*}} op8=4112
          ^
<stdin>:1:1: note: scanning from here
<BLOCKINFO_BLOCK/>
^
<stdin>:14:5: note: possible intended match here
 <TARGET_OPTIONS op0=24 op1=120 op2=56 op3=54 op4=95 op5=54 op6=52 op7=45 op8=117 op9=110 op10=107 op11=110 op12=111 op13=119 op14=110 op15=45 op16=108 op17=105 op18=110 op19=117 op20=120 op21=45 op22=103 op23=110 op24=117 op25=0 op26=0 op27=0 op28=0 op29=5 op30=4 op31=43 op32=99 op33=120 op34=56 op35=4 op36=43 op37=109 op38=109 op39=120 op40=4 op41=43 op42=115 op43=115 op44=101 op45=5 op46=43 op47=115 op48=115 op49=101 op50=50 op51=4 op52=43 op53=120 op54=56 op55=55/>
    ^

Input file: <stdin>
Check file: /b/1/llvm-x86_64-debian-dylib/build/tools/clang/test/Modules/Output/no-external-type-id.cppm.tmp/b.cppm

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           1: <BLOCKINFO_BLOCK/> 
check:5'0     X~~~~~~~~~~~~~~~~~~ error: no match found
           2: <UNHASHED_CONTROL_BLOCK NumWords=17 BlockCodeSize=5> 
check:5'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           3:  <SIGNATURE abbrevid=4/> blob data = unprintable, 20 bytes. 
check:5'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           4:  <DIAG_PRAGMA_MAPPINGS op0=33 op1=0 op2=0 op3=0 op4=0 op5=1/> 
check:5'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           5:  <UnknownCode6 abbrevid=5 op0=1/> blob data = unprintable, 1 bytes. 
check:5'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           6:  <UnknownCode7 abbrevid=6 op0=0/> blob data = '' 
check:5'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           .
           .
           .
...

winner245 pushed a commit to winner245/llvm-project that referenced this pull request Oct 26, 2024
llvm#111221)

This patch adds none and all options to the -pgo-analysis-map flag,
which do basically what they say on the tin. The none option is added to
enable forcing the pgo-analysis-map by overriding an earlier invocation
of the flag. The all option is just added for convenience.
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
llvm#111221)

This patch adds none and all options to the -pgo-analysis-map flag,
which do basically what they say on the tin. The none option is added to
enable forcing the pgo-analysis-map by overriding an earlier invocation
of the flag. The all option is just added for convenience.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants