[llvm] [SHT_LLVM_BB_ADDR_MAP][AsmPrinter] Add none and all options to PGO Map (PR #111221)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 4 17:12:12 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-x86
Author: Aiden Grossman (boomanaiden154)
<details>
<summary>Changes</summary>
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
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/111221
More information about the llvm-commits
mailing list