Skip to content

Commit 7c9cf0c

Browse files
[SHT_LLVM_BB_ADDR_MAP][AsmPrinter] Emit error on bad option combinatons
This patch makes it so that specifying all or none for -pgo-analysis-map along with an explicit option causes an error as this set of options does not really make sense.
1 parent 3fc0d94 commit 7c9cf0c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,16 @@ static uint32_t getBBAddrMapMetadata(const MachineBasicBlock &MBB) {
13711371

13721372
static llvm::object::BBAddrMap::Features
13731373
getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges) {
1374+
// Ensure that the user has not passed in additional options while also
1375+
// specifying all or none.
1376+
if ((PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::None) ||
1377+
PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::All)) &&
1378+
popcount(PgoAnalysisMapFeatures.getBits()) != 1) {
1379+
MF.getFunction().getContext().emitError(
1380+
"-pgo-anaylsis-map can accept only all or none with no additional "
1381+
"values.");
1382+
}
1383+
13741384
bool NoFeatures = PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::None);
13751385
bool AllFeatures = PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::All);
13761386
bool FuncEntryCountEnabled =

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map -pgo-analysis-map=bb-freq | FileCheck %s --check-prefixes=CHECK,PGO-BBF,BBF-ONLY
1212
; RUN: llc < %s -mtriple=x86_64 -function-sections -unique-section-names=true -basic-block-address-map -pgo-analysis-map=br-prob | FileCheck %s --check-prefixes=CHECK,PGO-BRP,BRP-ONLY
1313

14+
;; Verify that we emit an error if we try and specify values in addition to all/none
15+
; RUN: not llc < %s -mtriple=x86_64 -basic-block-address-map -pgo-analysis-map=all,bb-freq
16+
; RUN: not llc < %s -mtriple=x86_64 -basic-block-address-map -pgo-analysis-map=none,bb-freq
17+
1418

1519
define void @_Z3bazb(i1 zeroext, i1 zeroext) personality ptr @__gxx_personality_v0 !prof !0 {
1620
br i1 %0, label %3, label %8, !prof !1

0 commit comments

Comments
 (0)