diff options
author | Amir Ayupov <aaupov@fb.com> | 2024-08-10 23:35:25 -0700 |
---|---|---|
committer | Amir Ayupov <aaupov@fb.com> | 2024-08-10 23:35:25 -0700 |
commit | 3cba776dfefd2f4ca275016e5fe8b6d317b9926b (patch) | |
tree | 7274026cfcd045513666e9b1e45f53e9eefaadb4 | |
parent | 9492426092eaa33abce43ad897b65939857dd7e9 (diff) | |
download | llvm-users/aaupov/spr/main.profgennfc-pass-parameter-as-const_ref.zip llvm-users/aaupov/spr/main.profgennfc-pass-parameter-as-const_ref.tar.gz llvm-users/aaupov/spr/main.profgennfc-pass-parameter-as-const_ref.tar.bz2 |
[𝘀𝗽𝗿] changes introduced through rebaseusers/aaupov/spr/main.profgennfc-pass-parameter-as-const_ref
Created using spr 1.3.4
[skip ci]
-rw-r--r-- | bolt/lib/Rewrite/PseudoProbeRewriter.cpp | 1 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCPseudoProbe.h | 5 | ||||
-rw-r--r-- | llvm/lib/MC/MCPseudoProbe.cpp | 143 |
3 files changed, 37 insertions, 112 deletions
diff --git a/bolt/lib/Rewrite/PseudoProbeRewriter.cpp b/bolt/lib/Rewrite/PseudoProbeRewriter.cpp index 37a5b93..886bbdb 100644 --- a/bolt/lib/Rewrite/PseudoProbeRewriter.cpp +++ b/bolt/lib/Rewrite/PseudoProbeRewriter.cpp @@ -143,6 +143,7 @@ void PseudoProbeRewriter::parsePseudoProbe() { if (!ProbeDecoder.buildAddress2ProbeMap( reinterpret_cast<const uint8_t *>(Contents.data()), Contents.size(), GuidFilter, FuncStartAddrs)) { + ProbeDecoder.getAddress2ProbesMap().clear(); errs() << "BOLT-WARNING: fail in building Address2ProbeMap\n"; return; } diff --git a/llvm/include/llvm/MC/MCPseudoProbe.h b/llvm/include/llvm/MC/MCPseudoProbe.h index b42bbf2..54a7f83 100644 --- a/llvm/include/llvm/MC/MCPseudoProbe.h +++ b/llvm/include/llvm/MC/MCPseudoProbe.h @@ -369,11 +369,6 @@ public: // Decode pseudo_probe_desc section to build GUID to PseudoProbeFuncDesc map. bool buildGUID2FuncDescMap(const uint8_t *Start, std::size_t Size); - // Decode pseudo_probe section to count the number of probes and inlined - // function records for each function record. - bool countRecords(bool IsTopLevelFunc, bool &Discard, uint32_t &ProbeCount, - uint32_t &InlinedCount, const Uint64Set &GuidFilter); - // Decode pseudo_probe section to build address to probes map for specifed // functions only. bool buildAddress2ProbeMap(const uint8_t *Start, std::size_t Size, diff --git a/llvm/lib/MC/MCPseudoProbe.cpp b/llvm/lib/MC/MCPseudoProbe.cpp index bb9538d..a5a030e 100644 --- a/llvm/lib/MC/MCPseudoProbe.cpp +++ b/llvm/lib/MC/MCPseudoProbe.cpp @@ -18,7 +18,6 @@ #include "llvm/MC/MCObjectStreamer.h" #include "llvm/MC/MCSymbol.h" #include "llvm/Support/Endian.h" -#include "llvm/Support/Error.h" #include "llvm/Support/LEB128.h" #include "llvm/Support/MD5.h" #include "llvm/Support/raw_ostream.h" @@ -430,11 +429,17 @@ bool MCPseudoProbeDecoder::buildAddress2ProbeMap( Index = Cur->getChildren().size(); } else { // Read inline site for inlinees - Index = cantFail(errorOrToExpected(readUnsignedNumber<uint32_t>())); + auto ErrorOrIndex = readUnsignedNumber<uint32_t>(); + if (!ErrorOrIndex) + return false; + Index = std::move(*ErrorOrIndex); } // Read guid - uint64_t Guid = cantFail(errorOrToExpected(readUnencodedNumber<uint64_t>())); + auto ErrorOrCurGuid = readUnencodedNumber<uint64_t>(); + if (!ErrorOrCurGuid) + return false; + uint64_t Guid = std::move(*ErrorOrCurGuid); // Decide if top-level node should be disgarded. if (IsTopLevelFunc && !GuidFilter.empty() && !GuidFilter.count(Guid)) @@ -452,27 +457,41 @@ bool MCPseudoProbeDecoder::buildAddress2ProbeMap( } // Read number of probes in the current node. - uint32_t NodeCount = - cantFail(errorOrToExpected(readUnsignedNumber<uint32_t>())); + auto ErrorOrNodeCount = readUnsignedNumber<uint32_t>(); + if (!ErrorOrNodeCount) + return false; + uint32_t NodeCount = std::move(*ErrorOrNodeCount); // Read number of direct inlinees - uint32_t ChildrenToProcess = - cantFail(errorOrToExpected(readUnsignedNumber<uint32_t>())); + auto ErrorOrCurChildrenToProcess = readUnsignedNumber<uint32_t>(); + if (!ErrorOrCurChildrenToProcess) + return false; // Read all probes in this node for (std::size_t I = 0; I < NodeCount; I++) { // Read index - uint32_t Index = - cantFail(errorOrToExpected(readUnsignedNumber<uint32_t>())); + auto ErrorOrIndex = readUnsignedNumber<uint32_t>(); + if (!ErrorOrIndex) + return false; + uint32_t Index = std::move(*ErrorOrIndex); // Read type | flag. - uint8_t Value = cantFail(errorOrToExpected(readUnencodedNumber<uint8_t>())); + auto ErrorOrValue = readUnencodedNumber<uint8_t>(); + if (!ErrorOrValue) + return false; + uint8_t Value = std::move(*ErrorOrValue); uint8_t Kind = Value & 0xf; uint8_t Attr = (Value & 0x70) >> 4; // Read address uint64_t Addr = 0; if (Value & 0x80) { - int64_t Offset = cantFail(errorOrToExpected(readSignedNumber<int64_t>())); + auto ErrorOrOffset = readSignedNumber<int64_t>(); + if (!ErrorOrOffset) + return false; + int64_t Offset = std::move(*ErrorOrOffset); Addr = LastAddr + Offset; } else { - Addr = cantFail(errorOrToExpected(readUnencodedNumber<int64_t>())); + auto ErrorOrAddr = readUnencodedNumber<int64_t>(); + if (!ErrorOrAddr) + return false; + Addr = std::move(*ErrorOrAddr); if (isSentinelProbe(Attr)) { // For sentinel probe, the addr field actually stores the GUID of the // split function. Convert it to the real address. @@ -489,8 +508,10 @@ bool MCPseudoProbeDecoder::buildAddress2ProbeMap( uint32_t Discriminator = 0; if (hasDiscriminator(Attr)) { - Discriminator = - cantFail(errorOrToExpected(readUnsignedNumber<uint32_t>())); + auto ErrorOrDiscriminator = readUnsignedNumber<uint32_t>(); + if (!ErrorOrDiscriminator) + return false; + Discriminator = std::move(*ErrorOrDiscriminator); } if (Cur && !isSentinelProbe(Attr)) { @@ -503,109 +524,17 @@ bool MCPseudoProbeDecoder::buildAddress2ProbeMap( LastAddr = Addr; } + uint32_t ChildrenToProcess = std::move(*ErrorOrCurChildrenToProcess); for (uint32_t I = 0; I < ChildrenToProcess; I++) { buildAddress2ProbeMap(Cur, LastAddr, GuidFilter, FuncStartAddrs); } - return true; -} - -bool MCPseudoProbeDecoder::countRecords(bool IsTopLevelFunc, bool &Discard, - uint32_t &ProbeCount, - uint32_t &InlinedCount, - const Uint64Set &GuidFilter) { - if (!IsTopLevelFunc) - // Read inline site for inlinees - if (!readUnsignedNumber<uint32_t>()) - return false; - - // Read guid - auto ErrorOrCurGuid = readUnencodedNumber<uint64_t>(); - if (!ErrorOrCurGuid) - return false; - uint64_t Guid = std::move(*ErrorOrCurGuid); - - // Decide if top-level node should be disgarded. - if (IsTopLevelFunc) { - Discard = !GuidFilter.empty() && !GuidFilter.count(Guid); - if (!Discard) - // Allocate an entry for top-level function record. - ++InlinedCount; - } - - // Read number of probes in the current node. - auto ErrorOrNodeCount = readUnsignedNumber<uint32_t>(); - if (!ErrorOrNodeCount) - return false; - uint32_t NodeCount = std::move(*ErrorOrNodeCount); - uint32_t CurrentProbeCount = 0; - - // Read number of direct inlinees - auto ErrorOrCurChildrenToProcess = readUnsignedNumber<uint32_t>(); - if (!ErrorOrCurChildrenToProcess) - return false; - uint32_t ChildrenToProcess = std::move(*ErrorOrCurChildrenToProcess); - - // Read all probes in this node - for (std::size_t I = 0; I < NodeCount; I++) { - // Read index - if (!readUnsignedNumber<uint32_t>()) - return false; - - // Read type | flag. - auto ErrorOrValue = readUnencodedNumber<uint8_t>(); - if (!ErrorOrValue) - return false; - uint8_t Value = std::move(*ErrorOrValue); - - uint8_t Attr = (Value & 0x70) >> 4; - if (Value & 0x80) { - // Offset - if (!readSignedNumber<int64_t>()) - return false; - } else { - // Addr - if (!readUnencodedNumber<int64_t>()) - return false; - } - - if (hasDiscriminator(Attr)) - // Discriminator - if (!readUnsignedNumber<uint32_t>()) - return false; - - if (!Discard && !isSentinelProbe(Attr)) - ++CurrentProbeCount; - } - if (!Discard) { - ProbeCount += CurrentProbeCount; - InlinedCount += ChildrenToProcess; - } - - for (uint32_t I = 0; I < ChildrenToProcess; I++) - if (!countRecords(false, Discard, ProbeCount, InlinedCount, GuidFilter)) - return false; return true; } bool MCPseudoProbeDecoder::buildAddress2ProbeMap( const uint8_t *Start, std::size_t Size, const Uint64Set &GuidFilter, const Uint64Map &FuncStartAddrs) { - // For function records in the order of their appearance in the encoded data - // (DFS), count the number of contained probes and inlined function records. - uint32_t ProbeCount = 0; - uint32_t InlinedCount = 0; - uint32_t TopLevelFuncs = 0; - Data = Start; - End = Data + Size; - bool Discard = false; - while (Data < End) { - if (!countRecords(true, Discard, ProbeCount, InlinedCount, GuidFilter)) - return false; - TopLevelFuncs += !Discard; - } - assert(Data == End && "Have unprocessed data in pseudo_probe section"); - Data = Start; End = Data + Size; uint64_t LastAddr = 0; |