diff --git a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h index bba675f1d3eb7d1022a25669c9f18dc6a01ac8fa..1083c1483f8fb78e0bffad0436f9ee3d0663be78 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 af8db60b1e8e5ea4baa203d918c2bb078e5c1a41..5dfcc45b56529d66070555f0c61d26863b9f526e 100644 --- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h +++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h @@ -98,6 +98,7 @@ template <> struct DenseMapInfo { // the basic block sections profile. struct UniqueBBID { unsigned BaseID; + uint64_t Hash; unsigned CloneID; }; @@ -653,9 +654,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 1ba0f37e860f33fb12b9a5b2e34134282c7fc9d1..beb86e0b61b4738dca6669d4539f001bdc4bf1d7 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 8f045d6383623b0b48f86b8dda077e564149a093..b0456248d05e80c8072b3ca6d7b0f232c8974fbb 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 4f580ba93b89c6a1c9a2ca4e1a263c70aebe1d45..8d84560ae166ac10776962225efdd673f853c186 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1431,6 +1431,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 19f824850607ca377b6b7797e9941d1249268e95..9543eb03f14a142aa1e4669370adcb7cc1e5bf48 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 9e8fa23efe44e05e9d021e2e673bd4366b84d020..c5d6f1a98db76275839b2a9aa35b09f724585b10 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 @@ -291,12 +293,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. @@ -386,6 +419,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 39bca55b4788ca21a217ce20fe6ee384689e3851..5d198f152f9c76af19bee4cda519c5951ec6cdac 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 1cfc671abe85657ece696c7e28672223ebb2e812..518cb1e03543466f43840bfd3cd6606fd274096e 100644 --- a/llvm/lib/Object/ELF.cpp +++ b/llvm/lib/Object/ELF.cpp @@ -790,6 +790,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; @@ -801,7 +802,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 ef1307fee6d7c664bcda5d111e779764e235d4f3..19cab15ece6df4c14eaa3bf06c54d9e5c931968c 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 d34b94b767d1b50129c8e6413f08321fe1803291..b68e381368b001aa4a4080d7ae57cd178866bbb4 100644 --- a/llvm/lib/ObjectYAML/ELFYAML.cpp +++ b/llvm/lib/ObjectYAML/ELFYAML.cpp @@ -1813,6 +1813,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 6354e2ec6889feb238edfe3dcfbeb5a67b01790e..b96a606057ed47515bb3a7e3092b666f88c2c538 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 {{.+}} # 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 {{.+}} # 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 {{.+}} # 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 {{.+}} # 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 f2ceae08eb94ec48459155a0c34832f7f01cbf6f..248b13e316cd6f3493d2f2a922d6b3cfb0c501e3 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 {{.+}} # 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 {{.+}} # 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 {{.+}} # 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 6ab24b494936ab2eebd4531d34825496a7c469e8..5cedbd3c98edd9c117eee063436a60494011e47b 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 {{.+}} # 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 {{.+}} # 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 {{.+}} # 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 {{.+}} # 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 {{.+}} # 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 {{.+}} # 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 d6f3d5010b55673dc3fffb299701dfc7381b4d38..15a4862ca55d487b83c40d8f84cfc64d534d3a9e 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 ebfc003c50f5b062146f50b5fd9cf9c954daea91..8711caf94e0233275dc0d9d6d58c11e0c0da4cb6 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 {{.+}} # 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 {{.+}} # 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 {{.+}} # 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 {{.+}} # 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 {{.+}} # 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 {{.+}} # 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 cc7faea67bed2371d9301505b47ca5a9744810cd..0b6b6c79d268ae58a82e185b7aa85a684e9bfcac 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 706d386e467e75b369898f8d1aec84f0d4c7fb73..f582ac73ce29a3c0454b1641d286fa3ee46d390a 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 4d1e5408d86d4dad07e509f328ecfab2250a7688..34ce924796d965d04dfe26aa0a2012ae500b6fb6 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 5faafd4d83b2f201f999b7948fd4d0bf19a3fc70..6f95b760f89ac1741ecaf67ee266d57dc64efcc1 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 e7f78491a94737a816a6963f67780a2a177beb76..2abe47f69c9c2d3f98aa860478648212b4e5441f 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 c5d071c11d1de3c34540cfad5a06315743b09bd1..447f3d3d4a0b15607d9398742bb3c0bb3eda1f91 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 299bf463cf4bc9bb75b4b34f7bbbb85ce40bb09d..7e2c8d49726c805b8e0631df9ea8f87adbb2f315 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 8dbf97ef2bc12db5d08481ef7424c732095ba1be..215e727949d14394f32da915598ade6df4425902 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 4dfaf60be3c0edb90cf3ae24be798eaf8d0e2992..1def238301dd5d92bd5cbb61dd936d0a7f780183 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 709938babffbf3c5a889274e812c7230f0ba31f4..432f91953a1451e9befb43c8fe3ff0b85c8c2bf8 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 d144a025c9a81b5412a09d67fdee8aa2bf8d1050..0341606d1815395e69ebdb8db6075a99777c5f77 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -7152,6 +7152,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 f497abf5ce6f89f8246638654c4f1f8a5e240c30..b7ebeb09e78910a0abbe47e8f2ea4cc8dd2e8577 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 7a292bd632af9e63348b78b151128b2518ea924c..2ed34db73615bb4a97b072e484915db75c1126e9 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)},