From 28cbe1f3d73b93adf5d563d843740f960f683493 Mon Sep 17 00:00:00 2001 From: xiajingze Date: Mon, 28 Apr 2025 15:59:33 +0800 Subject: [PATCH] [Propeller] Match the hash value of BB to adapt to source drift Add the BB Hash to the generated `.llvm_bb_addr_map` section. The Propeller tool reads it and write to the output file. When building updated code, llvm matches the file with the current BB Hash and generates BBCluster based on the Hash matching results. This feature is controlled by the `bbsections-match-hash` option and is disabled by default. --- .../CodeGen/BasicBlockSectionsProfileReader.h | 14 +- llvm/include/llvm/CodeGen/MachineBasicBlock.h | 5 + llvm/include/llvm/Object/ELFTypes.h | 6 +- llvm/include/llvm/ObjectYAML/ELFYAML.h | 1 + llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 + llvm/lib/CodeGen/BasicBlockPathCloning.cpp | 3 +- llvm/lib/CodeGen/BasicBlockSections.cpp | 34 ++++ .../BasicBlockSectionsProfileReader.cpp | 26 ++- llvm/lib/Object/ELF.cpp | 3 +- llvm/lib/ObjectYAML/ELFEmitter.cpp | 1 + llvm/lib/ObjectYAML/ELFYAML.cpp | 1 + ...k-address-map-with-basic-block-sections.ll | 4 + .../X86/basic-block-address-map-with-mfs.ll | 3 + .../CodeGen/X86/basic-block-address-map.ll | 6 + .../basic-block-sections-clusters-error.ll | 2 +- ...asic-block-sections-labels-pgo-features.ll | 6 + ...ddrmap-disassemble-symbolize-operands.yaml | 18 ++ .../elf-bbaddrmap-symbolize-relocatable.yaml | 10 +- .../llvm-objdump/X86/elf-pgoanalysismap.yaml | 9 + .../ELF/bb-addr-map-pgo-analysis-map.test | 14 +- .../ELF/bb-addr-map-relocatable.test | 9 +- .../tools/llvm-readobj/ELF/bb-addr-map.test | 12 +- .../ELF/bb-addr-map-pgo-analysis-map.yaml | 10 ++ llvm/test/tools/obj2yaml/ELF/bb-addr-map.yaml | 10 ++ .../ELF/bb-addr-map-pgo-analysis-map.yaml | 9 +- llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml | 3 + llvm/tools/llvm-readobj/ELFDumper.cpp | 1 + llvm/tools/obj2yaml/elf2yaml.cpp | 3 +- llvm/unittests/Object/ELFObjectFileTest.cpp | 157 +++++++++++++----- 29 files changed, 323 insertions(+), 59 deletions(-) diff --git a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h index bba675f1d3eb..1083c1483f8f 100644 --- a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h +++ b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h @@ -28,11 +28,14 @@ #include "llvm/Support/LineIterator.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Support/CommandLine.h" using namespace llvm; namespace llvm { +extern cl::opt BBSectionsMatchHash; + // This struct represents the cluster information for a machine basic block, // which is specifed by a unique ID (`MachineBasicBlock::BBID`). struct BBClusterInfo { @@ -65,13 +68,22 @@ template <> struct DenseMapInfo { return UniqueBBID{TombstoneKey, TombstoneKey}; } static unsigned getHashValue(const UniqueBBID &Val) { + if (BBSectionsMatchHash) { + std::pair PairVal = + std::make_pair(Val.Hash, Val.CloneID); + return DenseMapInfo>::getHashValue(PairVal); + } std::pair PairVal = std::make_pair(Val.BaseID, Val.CloneID); return DenseMapInfo>::getHashValue(PairVal); } static bool isEqual(const UniqueBBID &LHS, const UniqueBBID &RHS) { + if (BBSectionsMatchHash) { + return DenseMapInfo::isEqual(LHS.Hash, RHS.Hash) && + DenseMapInfo::isEqual(LHS.CloneID, RHS.CloneID); + } return DenseMapInfo::isEqual(LHS.BaseID, RHS.BaseID) && - DenseMapInfo::isEqual(LHS.CloneID, RHS.CloneID); + DenseMapInfo::isEqual(LHS.CloneID, RHS.CloneID); } }; diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h index 1d16aac7f445..51660e4ded13 100644 --- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h +++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h @@ -101,6 +101,7 @@ template <> struct DenseMapInfo { // the basic block sections profile. struct UniqueBBID { unsigned BaseID; + uint64_t Hash; unsigned CloneID; }; @@ -666,9 +667,13 @@ public: std::optional getBBID() const { return BBID; } + uint64_t getHash() const { return BBID->Hash; } + /// Returns the section ID of this basic block. MBBSectionID getSectionID() const { return SectionID; } + void setHash(uint64_t Hash) { BBID->Hash = Hash; } + /// Sets the fixed BBID of this basic block. void setBBID(const UniqueBBID &V) { assert(!BBID.has_value() && "Cannot change BBID."); diff --git a/llvm/include/llvm/Object/ELFTypes.h b/llvm/include/llvm/Object/ELFTypes.h index c413f0741a4f..6ef741588936 100644 --- a/llvm/include/llvm/Object/ELFTypes.h +++ b/llvm/include/llvm/Object/ELFTypes.h @@ -886,9 +886,11 @@ struct BBAddrMap { uint32_t Size = 0; // Size of the basic block. Metadata MD = {false, false, false, false, false}; // Metdata for this basic block. + uint64_t Hash = 0; // Hash value of the basic block. - BBEntry(uint32_t ID, uint32_t Offset, uint32_t Size, Metadata MD) - : ID(ID), Offset(Offset), Size(Size), MD(MD){}; + BBEntry(uint32_t ID, uint32_t Offset, uint32_t Size, Metadata MD, + uint64_t Hash) + : ID(ID), Offset(Offset), Size(Size), MD(MD), Hash(Hash){}; bool operator==(const BBEntry &Other) const { return ID == Other.ID && Offset == Other.Offset && Size == Other.Size && diff --git a/llvm/include/llvm/ObjectYAML/ELFYAML.h b/llvm/include/llvm/ObjectYAML/ELFYAML.h index 8f045d638362..b0456248d05e 100644 --- a/llvm/include/llvm/ObjectYAML/ELFYAML.h +++ b/llvm/include/llvm/ObjectYAML/ELFYAML.h @@ -162,6 +162,7 @@ struct BBAddrMapEntry { llvm::yaml::Hex64 AddressOffset; llvm::yaml::Hex64 Size; llvm::yaml::Hex64 Metadata; + llvm::yaml::Hex64 Hash; }; uint8_t Version; llvm::yaml::Hex8 Feature; diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index fda2904216e1..f3f21450949a 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1432,6 +1432,8 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) { emitLabelDifferenceAsULEB128(MBB.getEndSymbol(), MBBSymbol); // Emit the Metadata. OutStreamer->emitULEB128IntValue(getBBAddrMapMetadata(MBB)); + OutStreamer->AddComment("hash value"); + OutStreamer->emitULEB128IntValue(MBB.getHash()); PrevMBBEndSymbol = MBB.getEndSymbol(); } diff --git a/llvm/lib/CodeGen/BasicBlockPathCloning.cpp b/llvm/lib/CodeGen/BasicBlockPathCloning.cpp index 19f824850607..9543eb03f14a 100644 --- a/llvm/lib/CodeGen/BasicBlockPathCloning.cpp +++ b/llvm/lib/CodeGen/BasicBlockPathCloning.cpp @@ -56,7 +56,8 @@ MachineBasicBlock *CloneMachineBasicBlock(MachineBasicBlock &OrigBB, auto TII = MF.getSubtarget().getInstrInfo(); // Create the clone block and set its BBID based on the original block. MachineBasicBlock *CloneBB = MF.CreateMachineBasicBlock( - OrigBB.getBasicBlock(), UniqueBBID{OrigBB.getBBID()->BaseID, CloneID}); + OrigBB.getBasicBlock(), UniqueBBID{OrigBB.getBBID()->BaseID, + OrigBB.getBBID()->Hash, CloneID}); MF.push_back(CloneBB); // Copy the instructions. diff --git a/llvm/lib/CodeGen/BasicBlockSections.cpp b/llvm/lib/CodeGen/BasicBlockSections.cpp index 09e45ea5794b..6824b71f02d9 100644 --- a/llvm/lib/CodeGen/BasicBlockSections.cpp +++ b/llvm/lib/CodeGen/BasicBlockSections.cpp @@ -70,6 +70,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Hashing.h" #include "llvm/CodeGen/BasicBlockSectionUtils.h" #include "llvm/CodeGen/BasicBlockSectionsProfileReader.h" #include "llvm/CodeGen/MachineFunction.h" @@ -77,6 +78,7 @@ #include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/TargetInstrInfo.h" #include "llvm/InitializePasses.h" +#include "llvm/IR/Constants.h" #include "llvm/Target/TargetMachine.h" #include @@ -289,12 +291,43 @@ bool llvm::hasInstrProfHashMismatch(MachineFunction &MF) { return false; } +void computeBBHash(MachineFunction &MF) { + for (auto &MBB : MF) { + llvm::hash_code Hash = llvm::hash_value(0); + for (const MachineInstr &MI : MBB) { + if (MI.isPseudo() || MI.isDebugOrPseudoInstr()) + continue; + if (MI.isUnconditionalBranch()) + continue; + Hash = llvm::hash_combine(Hash, MI.getOpcode()); + + for (const MachineOperand &MO : MI.operands()) { + if (MO.isReg()) { + Hash = llvm::hash_combine(Hash, MO.getReg()); + } else if (MO.isImm()) { + Hash = llvm::hash_combine(Hash, MO.getImm()); + } else if (MO.isCImm()) { + Hash = llvm::hash_combine(Hash, MO.getCImm()->getZExtValue()); + } else if (MO.isFPImm()) { + Hash = llvm::hash_combine(Hash, MO.getFPImm()->getValueAPF().bitcastToAPInt().getZExtValue()); + } else if (MO.isGlobal()) { + Hash = llvm::hash_combine(Hash, MO.getGlobal()->getName()); + } else if (MO.isSymbol()) { + Hash = llvm::hash_combine(Hash, MO.getSymbolName()); + } + } + } + MBB.setHash(Hash); + } +} + // Identify, arrange, and modify basic blocks which need separate sections // according to the specification provided by the -fbasic-block-sections flag. bool BasicBlockSections::handleBBSections(MachineFunction &MF) { auto BBSectionsType = MF.getTarget().getBBSectionsType(); if (BBSectionsType == BasicBlockSection::None) return false; + computeBBHash(MF); // Check for source drift. If the source has changed since the profiles // were obtained, optimizing basic blocks might be sub-optimal. @@ -384,6 +417,7 @@ bool BasicBlockSections::handleBBAddrMap(MachineFunction &MF) { return false; if (!MF.getTarget().Options.BBAddrMap) return false; + computeBBHash(MF); MF.RenumberBlocks(); return true; } diff --git a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp index 39bca55b4788..5d198f152f9c 100644 --- a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp +++ b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp @@ -30,6 +30,13 @@ using namespace llvm; +namespace llvm { +cl::opt BBSectionsMatchHash( + "bbsections-match-hash", + cl::desc("This matches basic blocks by hash to fit source drift"), + cl::init(false), cl::Hidden); +} + char BasicBlockSectionsProfileReaderWrapperPass::ID = 0; INITIALIZE_PASS(BasicBlockSectionsProfileReaderWrapperPass, "bbsections-profile-reader", @@ -41,18 +48,29 @@ BasicBlockSectionsProfileReader::parseUniqueBBID(StringRef S) const { SmallVector Parts; S.split(Parts, '.'); if (Parts.size() > 2) - return createProfileParseError(Twine("unable to parse basic block id: '") + + return createProfileParseError(Twine("unable to parse unique basic block id: '") + S + "'"); - unsigned long long BaseBBID; - if (getAsUnsignedInteger(Parts[0], 10, BaseBBID)) + SmallVector IdAndHash; + Parts[0].split(IdAndHash, '-'); + if (IdAndHash.size() > 2) + return createProfileParseError(Twine("unable to parse basic block id and hash: '") + + Parts[0] + "'"); + unsigned long long BaseBBID = 0; + if (getAsUnsignedInteger(IdAndHash[0], 10, BaseBBID)) return createProfileParseError( - Twine("unable to parse BB id: '" + Parts[0]) + + Twine("unable to parse BB id: '" + IdAndHash[0]) + "': unsigned integer expected"); + unsigned long long BBHash = 0; + if (IdAndHash.size() > 1 && getAsUnsignedInteger(IdAndHash[1], 16, BBHash)) + return createProfileParseError( + Twine("unable to parse BB hash: '" + IdAndHash[1]) + + "': hex unsigned integer expected"); unsigned long long CloneID = 0; if (Parts.size() > 1 && getAsUnsignedInteger(Parts[1], 10, CloneID)) return createProfileParseError(Twine("unable to parse clone id: '") + Parts[1] + "': unsigned integer expected"); return UniqueBBID{static_cast(BaseBBID), + static_cast(BBHash), static_cast(CloneID)}; } diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp index 2faa78b14974..2e28bd39e1d0 100644 --- a/llvm/lib/Object/ELF.cpp +++ b/llvm/lib/Object/ELF.cpp @@ -821,6 +821,7 @@ decodeBBAddrMapImpl(const ELFFile &EF, uint32_t Offset = readULEB128As(Data, Cur, ULEBSizeErr); uint32_t Size = readULEB128As(Data, Cur, ULEBSizeErr); uint32_t MD = readULEB128As(Data, Cur, ULEBSizeErr); + uint64_t Hash = readULEB128As(Data, Cur, ULEBSizeErr); if (Version >= 1) { // Offset is calculated relative to the end of the previous BB. Offset += PrevBBEndOffset; @@ -832,7 +833,7 @@ decodeBBAddrMapImpl(const ELFFile &EF, MetadataDecodeErr = MetadataOrErr.takeError(); break; } - BBEntries.push_back({ID, Offset, Size, *MetadataOrErr}); + BBEntries.push_back({ID, Offset, Size, *MetadataOrErr, Hash}); } TotalNumBlocks += BBEntries.size(); BBRangeEntries.push_back({RangeBaseAddress, std::move(BBEntries)}); diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp index ef1307fee6d7..19cab15ece6d 100644 --- a/llvm/lib/ObjectYAML/ELFEmitter.cpp +++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -1461,6 +1461,7 @@ void ELFState::writeSectionContent( SHeader.sh_size += CBA.writeULEB128(BBE.AddressOffset); SHeader.sh_size += CBA.writeULEB128(BBE.Size); SHeader.sh_size += CBA.writeULEB128(BBE.Metadata); + SHeader.sh_size += CBA.writeULEB128(BBE.Hash); } } if (!PGOAnalyses) diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp index 1dae7223f8ab..052b72dbced9 100644 --- a/llvm/lib/ObjectYAML/ELFYAML.cpp +++ b/llvm/lib/ObjectYAML/ELFYAML.cpp @@ -1825,6 +1825,7 @@ void MappingTraits::mapping( IO.mapRequired("AddressOffset", E.AddressOffset); IO.mapRequired("Size", E.Size); IO.mapRequired("Metadata", E.Metadata); + IO.mapRequired("Hash", E.Hash); } void MappingTraits::mapping( diff --git a/llvm/test/CodeGen/X86/basic-block-address-map-with-basic-block-sections.ll b/llvm/test/CodeGen/X86/basic-block-address-map-with-basic-block-sections.ll index 6354e2ec6889..914c5779592f 100644 --- a/llvm/test/CodeGen/X86/basic-block-address-map-with-basic-block-sections.ll +++ b/llvm/test/CodeGen/X86/basic-block-address-map-with-basic-block-sections.ll @@ -54,18 +54,22 @@ declare i32 @__gxx_personality_v0(...) ; CHECK-NEXT: .uleb128 .Lfunc_begin0-.Lfunc_begin0 ; CHECK-NEXT: .uleb128 .LBB_END0_0-.Lfunc_begin0 ; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .ascii "\303\200\334\274\251\374\267\262<" # hash value ; CHECK-NEXT: .byte 2 # BB id ; CHECK-NEXT: .uleb128 .LBB0_1-.LBB_END0_0 ; CHECK-NEXT: .uleb128 .LBB_END0_1-.LBB0_1 ; CHECK-NEXT: .byte 5 +; CHECK-NEXT: .ascii "\327\300\366\245\367\337\275\345d" # hash value ; CHECK-NEXT: .quad _Z3bazb.cold # base address ; CHECK-NEXT: .byte 2 # number of basic blocks ; CHECK-NEXT: .byte 1 # BB id ; CHECK-NEXT: .uleb128 _Z3bazb.cold-_Z3bazb.cold ; CHECK-NEXT: .uleb128 .LBB_END0_2-_Z3bazb.cold ; CHECK-NEXT: .byte 8 +; CHECK-NEXT: .ascii "\263\327\252\372\303\255\341\321\022" # hash value ; CHECK-NEXT: .byte 3 # BB id ; CHECK-NEXT: .uleb128 .LBB0_3-.LBB_END0_2 ; CHECK-NEXT: .uleb128 .LBB_END0_3-.LBB0_3 ; CHECK-NEXT: .byte 1 +; CHECK-NEXT: .ascii "\221\300\354\233\225\361\207\221\231\001" # hash value diff --git a/llvm/test/CodeGen/X86/basic-block-address-map-with-mfs.ll b/llvm/test/CodeGen/X86/basic-block-address-map-with-mfs.ll index f2ceae08eb94..76baa57f49d7 100644 --- a/llvm/test/CodeGen/X86/basic-block-address-map-with-mfs.ll +++ b/llvm/test/CodeGen/X86/basic-block-address-map-with-mfs.ll @@ -64,16 +64,19 @@ declare i32 @qux() ; CHECK-NEXT: .uleb128 .Lfunc_begin0-.Lfunc_begin0 ; CHECK-NEXT: .uleb128 .LBB_END0_0-.Lfunc_begin0 ; CHECK-NEXT: .byte 8 +; CHECK-NEXT: .ascii "\303\200\334\274\251\374\267\262<" # hash value ; CHECK-NEXT: .byte 1 # BB id ; CHECK-NEXT: .uleb128 .LBB0_1-.LBB_END0_0 ; CHECK-NEXT: .uleb128 .LBB_END0_1-.LBB0_1 ; CHECK-NEXT: .byte 3 +; CHECK-NEXT: .ascii "\327\340\345\332\255\374\300\305\223\001" # hash value ; CHECK-NEXT: .quad foo.cold # base address ; CHECK-NEXT: .byte 1 # number of basic blocks ; CHECK-NEXT: .byte 2 # BB id ; CHECK-NEXT: .uleb128 foo.cold-foo.cold ; CHECK-NEXT: .uleb128 .LBB_END0_2-foo.cold ; CHECK-NEXT: .byte 3 +; CHECK-NEXT: .ascii "\225\367\322\342\214\252\331\231\301\001" # hash value ;; PGO Analysis Map ; PGO: .ascii "\3306" # function entry count diff --git a/llvm/test/CodeGen/X86/basic-block-address-map.ll b/llvm/test/CodeGen/X86/basic-block-address-map.ll index 6ab24b494936..baceb65319e6 100644 --- a/llvm/test/CodeGen/X86/basic-block-address-map.ll +++ b/llvm/test/CodeGen/X86/basic-block-address-map.ll @@ -60,23 +60,29 @@ declare i32 @__gxx_personality_v0(...) ; CHECK-NEXT: .uleb128 .Lfunc_begin0-.Lfunc_begin0 ; CHECK-NEXT: .uleb128 .LBB_END0_0-.Lfunc_begin0 ; CHECK-NEXT: .byte 8 +; CHECK-NEXT: .ascii "\360\271\333\306\325\246\370\236\032" # hash value ; CHECK-NEXT: .byte 1 # BB id ; CHECK-NEXT: .uleb128 .LBB0_1-.LBB_END0_0 ; CHECK-NEXT: .uleb128 .LBB_END0_1-.LBB0_1 ; CHECK-NEXT: .byte 8 +; CHECK-NEXT: .ascii "\263\327\252\372\303\255\341\321\022" # hash value ; CHECK-NEXT: .byte 3 # BB id ; CHECK-NEXT: .uleb128 .LBB0_2-.LBB_END0_1 ; CHECK-NEXT: .uleb128 .LBB_END0_2-.LBB0_2 ; CHECK-NEXT: .byte 8 +; CHECK-NEXT: .ascii "\220\227\205\337\215\230\345\203\313\001" # hash value ; CHECK-NEXT: .byte 4 # BB id ; CHECK-NEXT: .uleb128 .LBB0_3-.LBB_END0_2 ; CHECK-NEXT: .uleb128 .LBB_END0_3-.LBB0_3 ; CHECK-NEXT: .byte 16 +; CHECK-NEXT: .ascii "\264\373\313\206\340\360\363\365C" # hash value ; CHECK-NEXT: .byte 5 # BB id ; CHECK-NEXT: .uleb128 .LBB0_4-.LBB_END0_3 ; CHECK-NEXT: .uleb128 .LBB_END0_4-.LBB0_4 ; CHECK-NEXT: .byte 1 +; CHECK-NEXT: .ascii "\346\346\246\226\304\321\256\375D" # hash value ; CHECK-NEXT: .byte 2 # BB id ; CHECK-NEXT: .uleb128 .LBB0_5-.LBB_END0_4 ; CHECK-NEXT: .uleb128 .LBB_END0_5-.LBB0_5 ; CHECK-NEXT: .byte 5 +; CHECK-NEXT: .ascii "\346\346\246\226\304\321\256\375D" # hash value diff --git a/llvm/test/CodeGen/X86/basic-block-sections-clusters-error.ll b/llvm/test/CodeGen/X86/basic-block-sections-clusters-error.ll index d6f3d5010b55..15a4862ca55d 100644 --- a/llvm/test/CodeGen/X86/basic-block-sections-clusters-error.ll +++ b/llvm/test/CodeGen/X86/basic-block-sections-clusters-error.ll @@ -39,7 +39,7 @@ ; RUN: echo 'f dummy1' >> %t10 ; RUN: echo 'c 0 1.1.1' >> %t10 ; RUN: not --crash llc < %s -O0 -mtriple=x86_64 -function-sections -basic-block-sections=%t10 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR10 -; CHECK-ERROR10: LLVM ERROR: invalid profile {{.*}} at line 3: unable to parse basic block id: '1.1.1' +; CHECK-ERROR10: LLVM ERROR: invalid profile {{.*}} at line 3: unable to parse unique basic block id: '1.1.1' ; RUN: echo 'v1' > %t11 ; RUN: echo 'f dummy1' >> %t11 ; RUN: echo 'c 0 1.a' >> %t11 diff --git a/llvm/test/CodeGen/X86/basic-block-sections-labels-pgo-features.ll b/llvm/test/CodeGen/X86/basic-block-sections-labels-pgo-features.ll index ebfc003c50f5..017a2ed96865 100644 --- a/llvm/test/CodeGen/X86/basic-block-sections-labels-pgo-features.ll +++ b/llvm/test/CodeGen/X86/basic-block-sections-labels-pgo-features.ll @@ -71,26 +71,32 @@ declare i32 @__gxx_personality_v0(...) ; CHECK-NEXT: .uleb128 .Lfunc_begin0-.Lfunc_begin0 ; CHECK-NEXT: .uleb128 .LBB_END0_0-.Lfunc_begin0 ; CHECK-NEXT: .byte 8 +; CHECK-NEXT: .ascii "\360\271\333\306\325\246\370\236\032" # hash value ; CHECK-NEXT: .byte 1 # BB id ; CHECK-NEXT: .uleb128 .LBB0_1-.LBB_END0_0 ; CHECK-NEXT: .uleb128 .LBB_END0_1-.LBB0_1 ; CHECK-NEXT: .byte 8 +; CHECK-NEXT: .ascii "\263\327\252\372\303\255\341\321\022" # hash value ; CHECK-NEXT: .byte 3 # BB id ; CHECK-NEXT: .uleb128 .LBB0_2-.LBB_END0_1 ; CHECK-NEXT: .uleb128 .LBB_END0_2-.LBB0_2 ; CHECK-NEXT: .byte 8 +; CHECK-NEXT: .ascii "\314\223\213\277\342\235\347\304." # hash value ; CHECK-NEXT: .byte 5 # BB id ; CHECK-NEXT: .uleb128 .LBB0_3-.LBB_END0_2 ; CHECK-NEXT: .uleb128 .LBB_END0_3-.LBB0_3 ; CHECK-NEXT: .byte 1 +; CHECK-NEXT: .ascii "\346\346\246\226\304\321\256\375D" # hash value ; CHECK-NEXT: .byte 4 # BB id ; CHECK-NEXT: .uleb128 .LBB0_4-.LBB_END0_3 ; CHECK-NEXT: .uleb128 .LBB_END0_4-.LBB0_4 ; CHECK-NEXT: .byte 16 +; CHECK-NEXT: .ascii "\264\373\313\206\340\360\363\365C" # hash value ; CHECK-NEXT: .byte 2 # BB id ; CHECK-NEXT: .uleb128 .LBB0_5-.LBB_END0_4 ; CHECK-NEXT: .uleb128 .LBB_END0_5-.LBB0_5 ; CHECK-NEXT: .byte 4 +; CHECK-NEXT: .ascii "\315\254\220\356\210\355\223\331\262\001" # hash value ;; PGO Analysis Map ; PGO-FEC-NEXT: .byte 100 # function entry count diff --git a/llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-disassemble-symbolize-operands.yaml b/llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-disassemble-symbolize-operands.yaml index cc7faea67bed..0b6b6c79d268 100644 --- a/llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-disassemble-symbolize-operands.yaml +++ b/llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-disassemble-symbolize-operands.yaml @@ -113,28 +113,34 @@ Sections: AddressOffset: 0x0 Size: 0x1 Metadata: 0x1 + Hash: 0x1 - ID: 1 AddressOffset: 0x0 Size: 0x6 Metadata: 0x0 + Hash: 0x1 - ID: 2 AddressOffset: 0x1 Size: 0x4 Metadata: 0x0 + Hash: 0x1 - ID: 4 AddressOffset: 0x0 Size: 0x6 Metadata: 0x1 + Hash: 0x1 - ID: 5 AddressOffset: 0x0 Size: 0x1 Metadata: 0x2 + Hash: 0x1 - BaseAddress: 0x6000 BBEntries: - ID: 6 AddressOffset: 0x0 Size: 0x1 Metadata: 0x2 + Hash: 0x1 - Name: .llvm_bb_addr_map.bar Type: SHT_LLVM_BB_ADDR_MAP Link: .text.bar @@ -146,12 +152,15 @@ Sections: - AddressOffset: 0x0 Size: 0x1 Metadata: 0x1 + Hash: 0x1 - AddressOffset: 0x4 Size: 0x2 Metadata: 0x0 + Hash: 0x1 - AddressOffset: 0x0 Size: 0x6 Metadata: 0x0 + Hash: 0x1 Symbols: - Name: foo @@ -208,28 +217,34 @@ Sections: AddressOffset: 0x0 Size: 0x1 Metadata: 0x1 + Hash: 0x1 - ID: 1 AddressOffset: 0x0 Size: 0x6 Metadata: 0x0 + Hash: 0x1 - ID: 2 AddressOffset: 0x1 Size: 0x4 Metadata: 0x0 + Hash: 0x1 - ID: 4 AddressOffset: 0x0 Size: 0x6 Metadata: 0x1 + Hash: 0x1 - ID: 5 AddressOffset: 0x0 Size: 0x1 Metadata: 0x2 + Hash: 0x1 - BaseAddress: 0x6000 BBEntries: - ID: 6 AddressOffset: 0x0 Size: 0x1 Metadata: 0x2 + Hash: 0x1 - Version: 1 BBRanges: - BaseAddress: 0x5000 @@ -237,12 +252,15 @@ Sections: - AddressOffset: 0x0 Size: 0x1 Metadata: 0x1 + Hash: 0x1 - AddressOffset: 0x4 Size: 0x2 Metadata: 0x0 + Hash: 0x1 - AddressOffset: 0x0 Size: 0x6 Metadata: 0x0 + Hash: 0x1 Symbols: - Name: foo diff --git a/llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-symbolize-relocatable.yaml b/llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-symbolize-relocatable.yaml index 706d386e467e..f582ac73ce29 100644 --- a/llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-symbolize-relocatable.yaml +++ b/llvm/test/tools/llvm-objdump/X86/elf-bbaddrmap-symbolize-relocatable.yaml @@ -30,6 +30,7 @@ Sections: AddressOffset: 0x0 Size: 0x1 Metadata: 0xa + Hash: 0x10 - Version: 2 BBRanges: - BBEntries: @@ -37,6 +38,7 @@ Sections: AddressOffset: 0x0 Size: 0x1 Metadata: 0xb + Hash: 0x11 - Version: 2 Feature: 0x8 BBRanges: @@ -45,11 +47,13 @@ Sections: AddressOffset: 0x0 Size: 0x1 Metadata: 0xc + Hash: 0x12 - BBEntries: - ID: 1 AddressOffset: 0x0 Size: 0x1 Metadata: 0xd + Hash: 0x13 - Name: .rela.llvm_bb_addr_map Type: SHT_RELA Flags: [ SHF_INFO_LINK ] @@ -59,15 +63,15 @@ Sections: - Offset: 0x2 Symbol: .text Type: R_X86_64_64 - - Offset: 0x11 + - Offset: 0x12 Symbol: .text Type: R_X86_64_64 Addend: 1 - - Offset: 0x21 + - Offset: 0x23 Symbol: .text Type: R_X86_64_64 Addend: 0x2 - - Offset: 0x2e + - Offset: 0x31 Symbol: .text Type: R_X86_64_64 Addend: 0x3 diff --git a/llvm/test/tools/llvm-objdump/X86/elf-pgoanalysismap.yaml b/llvm/test/tools/llvm-objdump/X86/elf-pgoanalysismap.yaml index 4d1e5408d86d..34ce924796d9 100644 --- a/llvm/test/tools/llvm-objdump/X86/elf-pgoanalysismap.yaml +++ b/llvm/test/tools/llvm-objdump/X86/elf-pgoanalysismap.yaml @@ -33,6 +33,7 @@ Sections: AddressOffset: 0x0 Size: 0x1 Metadata: 0x1 + Hash: 0x1 PGOAnalyses: - FuncEntryCount: 1000 Symbols: @@ -76,18 +77,22 @@ Sections: AddressOffset: 0x0 Size: 0x1 Metadata: 0x1 + Hash: 0x1 - ID: 1 AddressOffset: 0x0 Size: 0x6 Metadata: 0x0 + Hash: 0x1 - ID: 2 AddressOffset: 0x1 Size: 0x4 Metadata: 0x0 + Hash: 0x1 - ID: 5 AddressOffset: 0x0 Size: 0x1 Metadata: 0x2 + Hash: 0x1 PGOAnalyses: - FuncEntryCount: 1000 PGOBBEntries: @@ -148,18 +153,22 @@ Sections: AddressOffset: 0x0 Size: 0x1 Metadata: 0x1 + Hash: 0x1 - ID: 1 AddressOffset: 0x0 Size: 0x6 Metadata: 0x0 + Hash: 0x1 - ID: 2 AddressOffset: 0x1 Size: 0x4 Metadata: 0x0 + Hash: 0x1 - ID: 5 AddressOffset: 0x0 Size: 0x1 Metadata: 0x2 + Hash: 0x1 PGOAnalyses: - FuncEntryCount: 1000 PGOBBEntries: diff --git a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test index 5faafd4d83b2..6f95b760f89a 100644 --- a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test +++ b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test @@ -15,7 +15,7 @@ ## Check that a malformed section can be handled. # RUN: yaml2obj %s -DBITS=32 -DSIZE=24 -o %t2.o -# RUN: llvm-readobj %t2.o --bb-addr-map 2>&1 | FileCheck --match-full-lines %s -DOFFSET=0x00000018 -DFILE=%t2.o --check-prefix=TRUNCATED +# RUN: llvm-readobj %t2.o --bb-addr-map 2>&1 | FileCheck --match-full-lines %s -DOFFSET=0x00000015 -DFILE=%t2.o --check-prefix=TRUNCATED ## Check that missing features can be handled. # RUN: yaml2obj %s -DBITS=32 -DFEATURE=0x2 -o %t3.o @@ -39,6 +39,7 @@ # CHECK-NEXT: IsEHPad: No # CHECK-NEXT: CanFallThrough: No # CHECK-NEXT: HasIndirectBranch: No +# CHECK-NEXT: Hash: 0x1 # CHECK-NEXT: } # CHECK-NEXT: { # CHECK-NEXT: ID: 2 @@ -49,6 +50,7 @@ # CHECK-NEXT: IsEHPad: Yes # CHECK-NEXT: CanFallThrough: No # CHECK-NEXT: HasIndirectBranch: Yes +# CHECK-NEXT: Hash: 0x1 # CHECK-NEXT: } # CHECK-NEXT: ] # CHECK-NEXT: } @@ -92,6 +94,7 @@ # CHECK-NEXT: IsEHPad: No # CHECK-NEXT: CanFallThrough: Yes # CHECK-NEXT: HasIndirectBranch: No +# CHECK-NEXT: Hash: 0x1 # CHECK-NEXT: } # CHECK-NEXT: ] # CHECK-NEXT: } @@ -133,6 +136,7 @@ # TRUNCATED-NEXT: IsEHPad: No # TRUNCATED-NEXT: CanFallThrough: Yes # TRUNCATED-NEXT: HasIndirectBranch: Yes +# TRUNCATED-NEXT: Hash: 0x1 # TRUNCATED-NEXT: } # TRUNCATED-NEXT: { # TRUNCATED-NEXT: ID: 7 @@ -143,6 +147,7 @@ # TRUNCATED-NEXT: IsEHPad: Yes # TRUNCATED-NEXT: CanFallThrough: Yes # TRUNCATED-NEXT: HasIndirectBranch: No +# TRUNCATED-NEXT: Hash: 0x1 # TRUNCATED-NEXT: } # TRUNCATED-NEXT: ] # TRUNCATED-NEXT: } @@ -153,7 +158,7 @@ # TRUNCATED-NEXT: } # TRUNCATED-NEXT: ] -# INVALIDFT: warning: '[[FILE]]': unable to dump SHT_LLVM_BB_ADDR_MAP section with index 5: unable to decode LEB128 at offset 0x00000010: malformed uleb128, extends past end +# INVALIDFT: warning: '[[FILE]]': unable to dump SHT_LLVM_BB_ADDR_MAP section with index 5: unable to decode LEB128 at offset 0x00000012: malformed uleb128, extends past end --- !ELF FileHeader: @@ -181,10 +186,12 @@ Sections: AddressOffset: 0x0 Size: 0x1 Metadata: 0x2 + Hash: 0x1 - ID: 2 AddressOffset: 0x3 Size: 0x4 Metadata: 0x15 + Hash: 0x1 - Version: 2 Feature: 0x3 BBRanges: @@ -194,6 +201,7 @@ Sections: AddressOffset: 0x6 Size: 0x7 Metadata: 0x8 + Hash: 0x1 PGOAnalyses: - FuncEntryCount: 100 PGOBBEntries: @@ -222,10 +230,12 @@ Sections: AddressOffset: 0x9 Size: 0xa Metadata: 0x1b + Hash: 0x1 - ID: 7 AddressOffset: 0xc Size: 0xd Metadata: 0xe + Hash: 0x1 PGOAnalyses: - FuncEntryCount: 89 Symbols: diff --git a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-relocatable.test b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-relocatable.test index e7f78491a947..2abe47f69c9c 100644 --- a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-relocatable.test +++ b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-relocatable.test @@ -21,6 +21,7 @@ # CHECK-NEXT: IsEHPad: No # CHECK-NEXT: CanFallThrough: No # CHECK-NEXT: HasIndirectBranch: No +# CHECK-NEXT: Hash: 0x1 # CHECK-NEXT: } # CHECK-NEXT: ] # CHECK-NEXT: } @@ -42,6 +43,7 @@ # CHECK-NEXT: IsEHPad: No # CHECK-NEXT: CanFallThrough: Yes # CHECK-NEXT: HasIndirectBranch: No +# CHECK-NEXT: Hash: 0x1 # CHECK-NEXT: } # CHECK-NEXT: ] # CHECK-NEXT: } @@ -70,6 +72,7 @@ Sections: AddressOffset: 0x0 Size: 0xF Metadata: 0x1 + Hash: 0x1 - Version: 2 BBRanges: - BBEntries: @@ -77,6 +80,7 @@ Sections: AddressOffset: 0x0 Size: 0x11 Metadata: 0x8 + Hash: 0x1 - Name: .rela.llvm_bb_addr_map Type: SHT_RELA Flags: [ SHF_INFO_LINK ] @@ -86,7 +90,7 @@ Sections: - Offset: 0x2 Symbol: .text Type: R_X86_64_64 - - Offset: 0x11 + - Offset: 0x12 Symbol: .text Type: R_X86_64_64 Addend: 16 @@ -146,6 +150,7 @@ Sections: AddressOffset: 0x0 Size: 0xF Metadata: 0x1 + Hash: 0x1 - Name: .rela.llvm_bb_addr_map Type: SHT_RELA Flags: [ SHF_INFO_LINK ] @@ -201,6 +206,7 @@ Sections: AddressOffset: 0x0 Size: 0xF Metadata: 0x1 + Hash: 0x1 # RUN: yaml2obj %s --docnum=5 -o %t5.o # RUN: llvm-readobj %t5.o --bb-addr-map 2>&1 | FileCheck %s --check-prefix=ET-DYN-NO-WARNING -DFILE=%t5.o @@ -222,6 +228,7 @@ Sections: # ET-DYN-NO-WARNING: IsEHPad: No # ET-DYN-NO-WARNING: CanFallThrough: No # ET-DYN-NO-WARNING: HasIndirectBranch: No +# ET-DYN-NO-WARNING: Hash: 0x1 # ET-DYN-NO-WARNING: } # ET-DYN-NO-WARNING: ] # ET-DYN-NO-WARNING: } diff --git a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map.test b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map.test index c5d071c11d1d..447f3d3d4a0b 100644 --- a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map.test +++ b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map.test @@ -40,6 +40,7 @@ # CHECK-NEXT: IsEHPad: No # CHECK-NEXT: CanFallThrough: No # CHECK-NEXT: HasIndirectBranch: No +# CHECK-NEXT: Hash: 0x1 # CHECK-NEXT: } # CHECK-NEXT: ] # CHECK-NEXT: } @@ -55,6 +56,7 @@ # CHECK-NEXT: IsEHPad: Yes # CHECK-NEXT: CanFallThrough: No # CHECK-NEXT: HasIndirectBranch: Yes +# CHECK-NEXT: Hash: 0x1 # CHECK-NEXT: } # CHECK-NEXT: ] # CHECK-NEXT: } @@ -75,7 +77,8 @@ # CHECK-NEXT: HasTailCall: No # CHECK-NEXT: IsEHPad: No # CHECK-NEXT: CanFallThrough: Yes -# CHECK-NEXT: HasIndirectBranch: No +# CHECK-NEXT: HasIndirectBranch: No +# CHECK-NEXT: Hash: 0x1 # CHECK-NEXT: } # CHECK-NEXT: ] # CHECK-NEXT: } @@ -106,6 +109,7 @@ # TRUNCATED-NEXT: IsEHPad: No # TRUNCATED-NEXT: CanFallThrough: Yes # TRUNCATED-NEXT: HasIndirectBranch: Yes +# TRUNCATED-NEXT: Hash: 0x1 # TRUNCATED-NEXT: } # TRUNCATED-NEXT: { # TRUNCATED-NEXT: ID: 7 @@ -116,6 +120,7 @@ # TRUNCATED-NEXT: IsEHPad: Yes # TRUNCATED-NEXT: CanFallThrough: Yes # TRUNCATED-NEXT: HasIndirectBranch: No +# TRUNCATED-NEXT: Hash: 0x1 # TRUNCATED-NEXT: } # TRUNCATED-NEXT: ] # TRUNCATED-NEXT: } @@ -152,12 +157,14 @@ Sections: AddressOffset: 0x0 Size: 0x1 Metadata: [[METADATA=0x2]] + Hash: 0x1 - BaseAddress: 0x44444 BBEntries: - ID: 2 AddressOffset: 0x3 Size: 0x4 Metadata: 0x15 + Hash: 0x1 - Version: 2 BBRanges: - BaseAddress: 0x22222 @@ -166,6 +173,7 @@ Sections: AddressOffset: 0x6 Size: 0x7 Metadata: 0x8 + Hash: 0x1 - Name: dummy_section Type: SHT_PROGBITS Size: 16 @@ -181,10 +189,12 @@ Sections: AddressOffset: 0x9 Size: 0xa Metadata: 0x1b + Hash: 0x1 - ID: 7 AddressOffset: 0xc Size: 0xd Metadata: 0xe + Hash: 0x1 Symbols: - Name: foo Section: .text diff --git a/llvm/test/tools/obj2yaml/ELF/bb-addr-map-pgo-analysis-map.yaml b/llvm/test/tools/obj2yaml/ELF/bb-addr-map-pgo-analysis-map.yaml index 299bf463cf4b..7e2c8d49726c 100644 --- a/llvm/test/tools/obj2yaml/ELF/bb-addr-map-pgo-analysis-map.yaml +++ b/llvm/test/tools/obj2yaml/ELF/bb-addr-map-pgo-analysis-map.yaml @@ -23,14 +23,17 @@ # VALID-NEXT: AddressOffset: 0x1 # VALID-NEXT: Size: 0x2 # VALID-NEXT: Metadata: 0x3 +# VALID-NEXT: Hash: 0x4 # VALID-NEXT: - ID: 2 # VALID-NEXT: AddressOffset: 0x4 # VALID-NEXT: Size: 0x5 # VALID-NEXT: Metadata: 0x6 +# VALID-NEXT: Hash: 0x7 # VALID-NEXT: - ID: 4 # VALID-NEXT: AddressOffset: 0xFFFFFFFFFFFFFFF7 # VALID-NEXT: Size: 0xFFFFFFFFFFFFFFF8 # VALID-NEXT: Metadata: 0xFFFFFFFFFFFFFFF9 +# VALID-NEXT: Hash: 0xFFFFFFFFFFFFFFFA # VALID-NEXT: - Version: 2 # VALID-NEXT: Feature: 0xA # VALID-NEXT: BBRanges: @@ -40,6 +43,7 @@ # VALID-NEXT: AddressOffset: 0xA # VALID-NEXT: Size: 0xB # VALID-NEXT: Metadata: 0xC +# VALID-NEXT: Hash: 0xD # VALID-NEXT: PGOAnalyses: # VALID-NEXT: - FuncEntryCount: 100 # VALID-NEXT: PGOBBEntries: @@ -77,14 +81,17 @@ Sections: AddressOffset: 0x1 Size: 0x2 Metadata: 0x3 + Hash: 0x4 - ID: 2 AddressOffset: 0x4 Size: 0x5 Metadata: 0x6 + Hash: 0x7 - ID: 4 AddressOffset: 0xFFFFFFFFFFFFFFF7 Size: 0xFFFFFFFFFFFFFFF8 Metadata: 0xFFFFFFFFFFFFFFF9 + Hash: 0xFFFFFFFFFFFFFFFA - Version: 2 Feature: 0xA BBRanges: @@ -94,6 +101,7 @@ Sections: AddressOffset: 0xA Size: 0xB Metadata: 0xC + Hash: 0xD PGOAnalyses: - FuncEntryCount: 100 PGOBBEntries: @@ -135,6 +143,7 @@ Sections: # MULTI-NEXT: AddressOffset: 0x1 # MULTI-NEXT: Size: 0x2 # MULTI-NEXT: Metadata: 0x3 +# MULTI-NEXT: Hash: 0x4 # MULTI-NEXT: PGOAnalyses: # MULTI-NEXT: - FuncEntryCount: 0 # MULTI-NEXT: PGOBBEntries: @@ -169,6 +178,7 @@ Sections: - AddressOffset: 0x1 Size: 0x2 Metadata: 0x3 + Hash: 0x4 PGOAnalyses: - FuncEntryCount: 0 PGOBBEntries: diff --git a/llvm/test/tools/obj2yaml/ELF/bb-addr-map.yaml b/llvm/test/tools/obj2yaml/ELF/bb-addr-map.yaml index 8dbf97ef2bc1..215e727949d1 100644 --- a/llvm/test/tools/obj2yaml/ELF/bb-addr-map.yaml +++ b/llvm/test/tools/obj2yaml/ELF/bb-addr-map.yaml @@ -22,14 +22,17 @@ # VALID-NEXT: AddressOffset: 0x1 # VALID-NEXT: Size: 0x2 # VALID-NEXT: Metadata: 0x3 +# VALID-NEXT: Hash: 0x4 # VALID-NEXT: - ID: 2 # VALID-NEXT: AddressOffset: 0x4 # VALID-NEXT: Size: 0x5 # VALID-NEXT: Metadata: 0x6 +# VALID-NEXT: Hash: 0x7 # VALID-NEXT: - ID: 4 # VALID-NEXT: AddressOffset: 0xFFFFFFFFFFFFFFF7 # VALID-NEXT: Size: 0xFFFFFFFFFFFFFFF8 # VALID-NEXT: Metadata: 0xFFFFFFFFFFFFFFF9 +# VALID-NEXT: Hash: 0xFFFFFFFFFFFFFFFA # VALID-NEXT: - Version: 2 # VALID-NEXT: Feature: 0x8 # VALID-NEXT: BBRanges: @@ -39,6 +42,7 @@ # VALID-NEXT: AddressOffset: 0xA # VALID-NEXT: Size: 0xB # VALID-NEXT: Metadata: 0xC +# VALID-NEXT: Hash: 0xD --- !ELF FileHeader: @@ -59,14 +63,17 @@ Sections: AddressOffset: 0x1 Size: 0x2 Metadata: 0x3 + Hash: 0x4 - ID: 2 AddressOffset: 0x4 Size: 0x5 Metadata: 0x6 + Hash: 0x7 - ID: 4 AddressOffset: 0xFFFFFFFFFFFFFFF7 Size: 0xFFFFFFFFFFFFFFF8 Metadata: 0xFFFFFFFFFFFFFFF9 + Hash: 0xFFFFFFFFFFFFFFFA - Version: 2 Feature: 0x8 NumBBRanges: [[NUMBBRANGES=]] @@ -78,6 +85,7 @@ Sections: AddressOffset: 0xA Size: 0xB Metadata: 0xC + Hash: 0xD ## Check obj2yaml can dump empty .llvm_bb_addr_map sections. @@ -126,6 +134,7 @@ Sections: # MULTI-NEXT: AddressOffset: 0x1 # MULTI-NEXT: Size: 0x2 # MULTI-NEXT: Metadata: 0x3 +# MULTI-NEXT: Hash: 0x4 # MULTI-NEXT: - Name: '.llvm_bb_addr_map (1)' # MULTI-NEXT: Type: SHT_LLVM_BB_ADDR_MAP # MULTI-NEXT: Entries: @@ -153,6 +162,7 @@ Sections: - AddressOffset: 0x1 Size: 0x2 Metadata: 0x3 + Hash: 0x4 - Name: '.llvm_bb_addr_map (1)' Type: SHT_LLVM_BB_ADDR_MAP Entries: diff --git a/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml b/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml index 4dfaf60be3c0..1def238301dd 100644 --- a/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml +++ b/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml @@ -6,14 +6,15 @@ # Case 4: Specify Entries. # CHECK: Name: .llvm_bb_addr_map (1) # CHECK: SectionData ( -# CHECK-NEXT: 0000: 02072000 00000000 0000010B 010203E8 -# CHECK-NEXT: 0010: 07E80702 0CEEDDBB F70E0D91 A2C48801 +# CHECK-NEXT: 0000: 02072000 00000000 0000010B 01020304 +# CHECK-NEXT: 0010: E807E807 020CEEDD BBF70E0D 91A2C488 +# CHECK-NEXT: 0020: 01 # CHECK-NEXT: ) # Case 7: Not including a field which is enabled in feature doesn't emit value # CHECK: Name: .llvm_bb_addr_map (1) # CHECK: SectionData ( -# CHECK-NEXT: 0000: 02012000 00000000 0000020D 010203 | +# CHECK-NEXT: 0000: 02012000 00000000 0000020D 01020304 | # CHECK-NEXT: ) --- !ELF @@ -39,6 +40,7 @@ Sections: AddressOffset: 0x00000001 Size: 0x00000002 Metadata: 0x00000003 + Hash: 0x00000004 PGOAnalyses: - FuncEntryCount: 1000 PGOBBEntries: @@ -63,6 +65,7 @@ Sections: AddressOffset: 0x00000001 Size: 0x00000002 Metadata: 0x00000003 + Hash: 0x00000004 ## Check that yaml2obj generates a warning when we use unsupported feature. # RUN: yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=INVALID-FEATURE diff --git a/llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml b/llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml index 709938babffb..432f91953a14 100644 --- a/llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml +++ b/llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml @@ -108,6 +108,7 @@ Sections: AddressOffset: 0x00000001 Size: 0x00000002 Metadata: 0x00000003 + Hash: 0x00000004 ## 5) When specifying the description with Entries, the 'Address' field will be ## zero when omitted. @@ -121,6 +122,7 @@ Sections: AddressOffset: 0x00000001 Size: 0x00000002 Metadata: 0x00000003 + Hash: 0x00000004 ## 6) We can override the NumBlocks field with a value different from the ## actual number of BB Entries. @@ -136,6 +138,7 @@ Sections: AddressOffset: 0x00000001 Size: 0x00000002 Metadata: 0x00000003 + Hash: 0x00000004 ## 7) We can produce a SHT_LLVM_BB_ADDR_MAP section from a description ## with one entry with empty BBRanges. diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index b7a2ff8dd5f3..ca2103efe20e 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -7480,6 +7480,7 @@ void LLVMELFDumper::printBBAddrMaps(bool PrettyPGOAnalysis) { W.printBoolean("IsEHPad", BBE.isEHPad()); W.printBoolean("CanFallThrough", BBE.canFallThrough()); W.printBoolean("HasIndirectBranch", BBE.hasIndirectBranch()); + W.printHex("Hash", BBE.Hash); } } } diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp index 12b621262c6d..bb72c9ce70b9 100644 --- a/llvm/tools/obj2yaml/elf2yaml.cpp +++ b/llvm/tools/obj2yaml/elf2yaml.cpp @@ -935,7 +935,8 @@ ELFDumper::dumpBBAddrMapSection(const Elf_Shdr *Shdr) { uint64_t Offset = Data.getULEB128(Cur); uint64_t Size = Data.getULEB128(Cur); uint64_t Metadata = Data.getULEB128(Cur); - BBEntries.push_back({ID, Offset, Size, Metadata}); + uint64_t Hash = Data.getULEB128(Cur); + BBEntries.push_back({ID, Offset, Size, Metadata, Hash}); } TotalNumBlocks += BBEntries.size(); BBRanges.push_back({BaseAddress, /*NumBlocks=*/{}, BBEntries}); diff --git a/llvm/unittests/Object/ELFObjectFileTest.cpp b/llvm/unittests/Object/ELFObjectFileTest.cpp index ae3d2ea22804..831cfe4ade90 100644 --- a/llvm/unittests/Object/ELFObjectFileTest.cpp +++ b/llvm/unittests/Object/ELFObjectFileTest.cpp @@ -504,6 +504,7 @@ Sections: - AddressOffset: 0x0 Size: 0x1 Metadata: 0x2 + Hash: 0x1234567812345678 )"; { @@ -534,6 +535,7 @@ Sections: - AddressOffset: 0x0 Size: 0x1 Metadata: 0x2 + Hash: 0x1234567812345678 )"; // Check that we can detect the malformed encoding when the section is @@ -558,6 +560,7 @@ Sections: AddressOffset: 0x100000000 Size: 0xFFFFFFFF Metadata: 0xFFFFFFFF + Hash: 0x1234567812345678 )"; OverInt32LimitYamlStrings[1] += R"( @@ -565,6 +568,7 @@ Sections: AddressOffset: 0xFFFFFFFF Size: 0x100000000 Metadata: 0xFFFFFFFF + Hash: 0x1234567812345678 )"; OverInt32LimitYamlStrings[2] += R"( @@ -572,16 +576,17 @@ Sections: AddressOffset: 0xFFFFFFFF Size: 0xFFFFFFFF Metadata: 0x100000000 + Hash: 0x1234567812345678 )"; { SCOPED_TRACE("overlimit fields"); DoCheck(OverInt32LimitYamlStrings[0], - "ULEB128 value at offset 0x10 exceeds UINT32_MAX (0x100000000)"); + "ULEB128 value at offset 0x19 exceeds UINT32_MAX (0x100000000)"); DoCheck(OverInt32LimitYamlStrings[1], - "ULEB128 value at offset 0x15 exceeds UINT32_MAX (0x100000000)"); + "ULEB128 value at offset 0x1e exceeds UINT32_MAX (0x100000000)"); DoCheck(OverInt32LimitYamlStrings[2], - "ULEB128 value at offset 0x1a exceeds UINT32_MAX (0x100000000)"); + "ULEB128 value at offset 0x23 exceeds UINT32_MAX (0x100000000)"); } // Check the proper error handling when the section has fields exceeding @@ -591,26 +596,26 @@ Sections: 3, OverInt32LimitYamlStrings[1]); // Truncate before the end of the 5-byte field. OverInt32LimitAndTruncated[0] += R"( - ShSize: 0x19 + ShSize: 0x22 )"; // Truncate at the end of the 5-byte field. OverInt32LimitAndTruncated[1] += R"( - ShSize: 0x1a + ShSize: 0x23 )"; // Truncate after the end of the 5-byte field. OverInt32LimitAndTruncated[2] += R"( - ShSize: 0x1b + ShSize: 0x24 )"; { SCOPED_TRACE("overlimit fields, truncated section"); DoCheck(OverInt32LimitAndTruncated[0], - "unable to decode LEB128 at offset 0x00000015: malformed uleb128, " + "unable to decode LEB128 at offset 0x0000001e: malformed uleb128, " "extends past end"); DoCheck(OverInt32LimitAndTruncated[1], - "ULEB128 value at offset 0x15 exceeds UINT32_MAX (0x100000000)"); + "ULEB128 value at offset 0x1e exceeds UINT32_MAX (0x100000000)"); DoCheck(OverInt32LimitAndTruncated[2], - "ULEB128 value at offset 0x15 exceeds UINT32_MAX (0x100000000)"); + "ULEB128 value at offset 0x1e exceeds UINT32_MAX (0x100000000)"); } // Check for proper error handling when the 'NumBlocks' field is overridden @@ -658,6 +663,7 @@ Sections: AddressOffset: 0x0 Size: 0x1 Metadata: 0x2 + Hash: 0x1234567812345678 - Name: .llvm_bb_addr_map_2 Type: SHT_LLVM_BB_ADDR_MAP Link: 1 @@ -671,12 +677,14 @@ Sections: AddressOffset: 0x0 Size: 0x2 Metadata: 0x4 + Hash: 0x1234567812345678 - BaseAddress: 0xFFFFF BBEntries: - ID: 15 AddressOffset: 0xF0 Size: 0xF1 Metadata: 0x1F + Hash: 0x1234567812345678 - Name: .llvm_bb_addr_map_3 Type: SHT_LLVM_BB_ADDR_MAP Link: 2 @@ -689,6 +697,7 @@ Sections: AddressOffset: 0x0 Size: 0x3 Metadata: 0x6 + Hash: 0x1234567812345678 - Name: .llvm_bb_addr_map_4 Type: SHT_LLVM_BB_ADDR_MAP # Link: 0 (by default, can be overriden) @@ -701,17 +710,39 @@ Sections: AddressOffset: 0x0 Size: 0x4 Metadata: 0x18 + Hash: 0x1234567812345678 )"); - BBAddrMap E1 = { - {{0x11111, {{1, 0x0, 0x1, {false, true, false, false, false}}}}}}; - BBAddrMap E2 = { - {{0x22222, {{2, 0x0, 0x2, {false, false, true, false, false}}}}, - {0xFFFFF, {{15, 0xF0, 0xF1, {true, true, true, true, true}}}}}}; - BBAddrMap E3 = { - {{0x33333, {{0, 0x0, 0x3, {false, true, true, false, false}}}}}}; - BBAddrMap E4 = { - {{0x44444, {{0, 0x0, 0x4, {false, false, false, true, true}}}}}}; + BBAddrMap E1 = {{{0x11111, + {{1, + 0x0, + 0x1, + {false, true, false, false, false}, + 0x1234567812345678}}}}}; + BBAddrMap E2 = {{{0x22222, + {{2, + 0x0, + 0x2, + {false, false, true, false, false}, + 0x1234567812345678}}}, + {0xFFFFF, + {{15, + 0xF0, + 0xF1, + {true, true, true, true, true}, + 0x1234567812345678}}}}}; + BBAddrMap E3 = {{{0x33333, + {{0, + 0x0, + 0x3, + {false, true, true, false, false}, + 0x1234567812345678}}}}}; + BBAddrMap E4 = {{{0x44444, + {{0, + 0x0, + 0x4, + {false, false, false, true, true}, + 0x1234567812345678}}}}}; std::vector Section0BBAddrMaps = {E4}; std::vector Section1BBAddrMaps = {E3}; @@ -853,6 +884,7 @@ Sections: - AddressOffset: 0x0 Size: 0x1 Metadata: 0x2 + Hash: 0x1234567812345678 )"; { @@ -871,6 +903,7 @@ Sections: AddressOffset: 0x0 Size: 0x1 Metadata: 0x2 + Hash: 0x1234567812345678 )"; // Check that we fail when function entry count is enabled but not provided. @@ -897,11 +930,12 @@ Sections: AddressOffset: 0x0 Size: 0x1 Metadata: 0x2 + Hash: 0x1234567812345678 )"; { SCOPED_TRACE("missing bb frequency"); - DoCheck(MissingBBFreq, "unable to decode LEB128 at offset 0x0000000f: " + DoCheck(MissingBBFreq, "unable to decode LEB128 at offset 0x00000018: " "malformed uleb128, extends past end"); } @@ -916,14 +950,17 @@ Sections: AddressOffset: 0x0 Size: 0x1 Metadata: 0x6 + Hash: 0x1234567812345678 - ID: 2 AddressOffset: 0x1 Size: 0x1 Metadata: 0x2 + Hash: 0x1234567812345678 - ID: 3 AddressOffset: 0x2 Size: 0x1 Metadata: 0x2 + Hash: 0x1234567812345678 PGOAnalyses: - PGOBBEntries: - Successors: @@ -938,7 +975,7 @@ Sections: { SCOPED_TRACE("missing branch probability"); - DoCheck(MissingBrProb, "unable to decode LEB128 at offset 0x00000017: " + DoCheck(MissingBrProb, "unable to decode LEB128 at offset 0x00000032: " "malformed uleb128, extends past end"); } } @@ -965,6 +1002,7 @@ Sections: AddressOffset: 0x0 Size: 0x1 Metadata: 0x2 + Hash: 0x1234567812345678 PGOAnalyses: - FuncEntryCount: 892 - Name: .llvm_bb_addr_map_2 @@ -980,6 +1018,7 @@ Sections: AddressOffset: 0x0 Size: 0x2 Metadata: 0x4 + Hash: 0x1234567812345678 PGOAnalyses: - PGOBBEntries: - BBFreq: 343 @@ -996,14 +1035,17 @@ Sections: AddressOffset: 0x0 Size: 0x3 Metadata: 0x6 + Hash: 0x1234567812345678 - ID: 1 AddressOffset: 0x0 Size: 0x3 Metadata: 0x4 + Hash: 0x1234567812345678 - ID: 2 AddressOffset: 0x0 Size: 0x3 Metadata: 0x0 + Hash: 0x1234567812345678 PGOAnalyses: - PGOBBEntries: - Successors: @@ -1028,18 +1070,22 @@ Sections: AddressOffset: 0x0 Size: 0x4 Metadata: 0x18 + Hash: 0x1234567812345678 - ID: 1 AddressOffset: 0x0 Size: 0x4 Metadata: 0x0 + Hash: 0x1234567812345678 - ID: 2 AddressOffset: 0x0 Size: 0x4 Metadata: 0x0 + Hash: 0x1234567812345678 - ID: 3 AddressOffset: 0x0 Size: 0x4 Metadata: 0x0 + Hash: 0x1234567812345678 PGOAnalyses: - FuncEntryCount: 1000 PGOBBEntries: @@ -1076,6 +1122,7 @@ Sections: AddressOffset: 0x0 Size: 0x2 Metadata: 0x4 + Hash: 0x1234567812345678 PGOAnalyses: [{}] - Name: .llvm_bb_addr_map_6 Type: SHT_LLVM_BB_ADDR_MAP @@ -1090,16 +1137,19 @@ Sections: AddressOffset: 0x0 Size: 0x6 Metadata: 0x6 + Hash: 0x1234567812345678 - ID: 1 AddressOffset: 0x0 Size: 0x6 Metadata: 0x4 + Hash: 0x1234567812345678 - BaseAddress: 0x666661 BBEntries: - ID: 2 AddressOffset: 0x0 Size: 0x6 Metadata: 0x0 + Hash: 0x1234567812345678 PGOAnalyses: - PGOBBEntries: - Successors: @@ -1113,17 +1163,30 @@ Sections: - Successors: [] )"); - BBAddrMap E1 = { - {{0x11111, {{1, 0x0, 0x1, {false, true, false, false, false}}}}}}; + BBAddrMap E1 = {{{0x11111, + {{1, + 0x0, + 0x1, + {false, true, false, false, false}, + 0x1234567812345678}}}}}; PGOAnalysisMap P1 = {892, {}, {true, false, false, false}}; - BBAddrMap E2 = { - {{0x22222, {{2, 0x0, 0x2, {false, false, true, false, false}}}}}}; + BBAddrMap E2 = {{{0x22222, + {{2, + 0x0, + 0x2, + {false, false, true, false, false}, + 0x1234567812345678}}}}}; PGOAnalysisMap P2 = { {}, {{BlockFrequency(343), {}}}, {false, true, false, false}}; - BBAddrMap E3 = {{{0x33333, - {{0, 0x0, 0x3, {false, true, true, false, false}}, - {1, 0x3, 0x3, {false, false, true, false, false}}, - {2, 0x6, 0x3, {false, false, false, false, false}}}}}}; + BBAddrMap E3 = { + {{0x33333, + {{0, 0x0, 0x3, {false, true, true, false, false}, 0x1234567812345678}, + {1, 0x3, 0x3, {false, false, true, false, false}, 0x1234567812345678}, + {2, + 0x6, + 0x3, + {false, false, false, false, false}, + 0x1234567812345678}}}}}; PGOAnalysisMap P3 = {{}, {{{}, {{1, BranchProbability::getRaw(0x1111'1111)}, @@ -1131,11 +1194,16 @@ Sections: {{}, {{2, BranchProbability::getRaw(0xffff'ffff)}}}, {{}, {}}}, {false, false, true, false}}; - BBAddrMap E4 = {{{0x44444, - {{0, 0x0, 0x4, {false, false, false, true, true}}, - {1, 0x4, 0x4, {false, false, false, false, false}}, - {2, 0x8, 0x4, {false, false, false, false, false}}, - {3, 0xc, 0x4, {false, false, false, false, false}}}}}}; + BBAddrMap E4 = { + {{0x44444, + {{0, 0x0, 0x4, {false, false, false, true, true}, 0x1234567812345678}, + {1, 0x4, 0x4, {false, false, false, false, false}, 0x1234567812345678}, + {2, 0x8, 0x4, {false, false, false, false, false}, 0x1234567812345678}, + {3, + 0xc, + 0x4, + {false, false, false, false, false}, + 0x1234567812345678}}}}}; PGOAnalysisMap P4 = { 1000, {{BlockFrequency(1000), @@ -1148,14 +1216,27 @@ Sections: {BlockFrequency(18), {{3, BranchProbability::getRaw(0xffff'ffff)}}}, {BlockFrequency(1000), {}}}, {true, true, true, false}}; - BBAddrMap E5 = { - {{0x55555, {{2, 0x0, 0x2, {false, false, true, false, false}}}}}}; + BBAddrMap E5 = {{{0x55555, + {{2, + 0x0, + 0x2, + {false, false, true, false, false}, + 0x1234567812345678}}}}}; PGOAnalysisMap P5 = {{}, {}, {false, false, false, false}}; BBAddrMap E6 = { {{0x66666, - {{0, 0x0, 0x6, {false, true, true, false, false}}, - {1, 0x6, 0x6, {false, false, true, false, false}}}}, - {0x666661, {{2, 0x0, 0x6, {false, false, false, false, false}}}}}}; + {{0, 0x0, 0x6, {false, true, true, false, false}, 0x1234567812345678}, + {1, + 0x6, + 0x6, + {false, false, true, false, false}, + 0x1234567812345678}}}, + {0x666661, + {{2, + 0x0, + 0x6, + {false, false, false, false, false}, + 0x1234567812345678}}}}}; PGOAnalysisMap P6 = {{}, {{{}, {{1, BranchProbability::getRaw(0x2222'2222)}, -- Gitee