Skip to content

Commit 38caf28

Browse files
[SHT_LLVM_BB_ADDR_MAP][AsmPrinter] Add none and all options to PGO Map (#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.
1 parent ccc15cd commit 38caf28

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,22 @@ using namespace llvm;
141141
// `object::PGOAnalysisMap::Features::decode(PgoAnalysisMapFeatures.getBits())`
142142
// succeeds.
143143
enum class PGOMapFeaturesEnum {
144+
None,
144145
FuncEntryCount,
145146
BBFreq,
146147
BrProb,
148+
All,
147149
};
148150
static cl::bits<PGOMapFeaturesEnum> PgoAnalysisMapFeatures(
149151
"pgo-analysis-map", cl::Hidden, cl::CommaSeparated,
150-
cl::values(clEnumValN(PGOMapFeaturesEnum::FuncEntryCount,
151-
"func-entry-count", "Function Entry Count"),
152-
clEnumValN(PGOMapFeaturesEnum::BBFreq, "bb-freq",
153-
"Basic Block Frequency"),
154-
clEnumValN(PGOMapFeaturesEnum::BrProb, "br-prob",
155-
"Branch Probability")),
152+
cl::values(
153+
clEnumValN(PGOMapFeaturesEnum::None, "none", "Disable all options"),
154+
clEnumValN(PGOMapFeaturesEnum::FuncEntryCount, "func-entry-count",
155+
"Function Entry Count"),
156+
clEnumValN(PGOMapFeaturesEnum::BBFreq, "bb-freq",
157+
"Basic Block Frequency"),
158+
clEnumValN(PGOMapFeaturesEnum::BrProb, "br-prob", "Branch Probability"),
159+
clEnumValN(PGOMapFeaturesEnum::All, "all", "Enable all options")),
156160
cl::desc(
157161
"Enable extended information within the SHT_LLVM_BB_ADDR_MAP that is "
158162
"extracted from PGO related analysis."));
@@ -1367,9 +1371,18 @@ static uint32_t getBBAddrMapMetadata(const MachineBasicBlock &MBB) {
13671371

13681372
static llvm::object::BBAddrMap::Features
13691373
getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges) {
1370-
return {PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::FuncEntryCount),
1371-
PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::BBFreq),
1372-
PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::BrProb),
1374+
bool NoFeatures = PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::None);
1375+
bool AllFeatures = PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::All);
1376+
bool FuncEntryCountEnabled =
1377+
AllFeatures || (!NoFeatures && PgoAnalysisMapFeatures.isSet(
1378+
PGOMapFeaturesEnum::FuncEntryCount));
1379+
bool BBFreqEnabled =
1380+
AllFeatures ||
1381+
(!NoFeatures && PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::BBFreq));
1382+
bool BrProbEnabled =
1383+
AllFeatures ||
1384+
(!NoFeatures && PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::BrProb));
1385+
return {FuncEntryCountEnabled, BBFreqEnabled, BrProbEnabled,
13731386
MF.hasBBSections() && NumMBBSectionRanges > 1};
13741387
}
13751388

llvm/test/CodeGen/X86/basic-block-address-map-pgo-features.ll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
; Check the basic block sections labels option
2-
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map | FileCheck %s --check-prefixes=CHECK,BASIC
2+
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map | FileCheck %s --check-prefixes=CHECK,BASIC,PGO-NONE
3+
; 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
34

45
;; Also verify this holds for all PGO features enabled
56
; 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
7+
; 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
68

79
;; Also verify that pgo extension only includes the enabled feature
810
; 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(...)
9395
; CHECK-NEXT: .byte 4
9496

9597
;; PGO Analysis Map
98+
; PGO-NONE-NOT: .byte 100 # function entry count
99+
; PGO-NONE-NOT: .ascii "\271\235\376\332\245\200\356\017" # basic block frequency
100+
; PGO-NONE-NOT: .byte 2 # basic block successor count
96101
; PGO-FEC-NEXT: .byte 100 # function entry count
97102
; PGO-BBF-NEXT: .ascii "\271\235\376\332\245\200\356\017" # basic block frequency
98103
; PGO-BRP-NEXT: .byte 2 # basic block successor count

0 commit comments

Comments
 (0)