diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 3a8cde7330efc..6d1fbf29580e3 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 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 73fe4f6ffedb0..1c3db738a9476 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