[PATCH] D118098: [InstrProf][correlation] Read DWARFv5 `OP_addrx` location
Ellis Hoag via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 24 20:13:02 PST 2022
ellis created this revision.
Herald added a subscriber: hiraditya.
ellis requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Correctly read `OP_addrx` type encodings for DWARFv5 locations.
Also, return an error when no profile metadata is found rather than crashing.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D118098
Files:
llvm/lib/ProfileData/InstrProfCorrelator.cpp
Index: llvm/lib/ProfileData/InstrProfCorrelator.cpp
===================================================================
--- llvm/lib/ProfileData/InstrProfCorrelator.cpp
+++ llvm/lib/ProfileData/InstrProfCorrelator.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ProfileData/InstrProfCorrelator.h"
+#include "llvm/DebugInfo/DWARF/DWARFDebugAddr.h"
#include "llvm/Object/MachO.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FileSystem.h"
@@ -127,6 +128,10 @@
Error InstrProfCorrelatorImpl<IntPtrT>::correlateProfileData() {
assert(Data.empty() && CompressedNames.empty() && Names.empty());
correlateProfileDataImpl();
+ if (Data.empty() || Names.empty())
+ return make_error<InstrProfError>(
+ instrprof_error::unable_to_correlate_profile,
+ "could not find any profile metadata in debug info");
auto Result =
collectPGOFuncNameStrings(Names, /*doCompression=*/true, CompressedNames);
CounterOffsets.clear();
@@ -167,13 +172,27 @@
return {};
}
auto &DU = *Die.getDwarfUnit();
+ bool isLE = DICtx->isLittleEndian();
+ auto AddressSize = DU.getAddressByteSize();
+ const auto &DObj = DICtx->getDWARFObj();
+ DWARFDataExtractor AddrSectionData(DObj, DObj.getAddrSection(), isLE,
+ AddressSize);
for (auto &Location : *Locations) {
- auto AddressSize = DU.getAddressByteSize();
- DataExtractor Data(Location.Expr, DICtx->isLittleEndian(), AddressSize);
+ DataExtractor Data(Location.Expr, isLE, AddressSize);
DWARFExpression Expr(Data, AddressSize);
- for (auto &Op : Expr)
- if (Op.getCode() == dwarf::DW_OP_addr)
+ for (auto &Op : Expr) {
+ if (Op.getCode() == dwarf::DW_OP_addr) {
return Op.getRawOperand(0);
+ } else if (Op.getCode() == dwarf::DW_OP_addrx) {
+ uint64_t Index = Op.getRawOperand(0);
+ auto Offset = DU.getAddrOffsetSectionBase();
+ if (!Offset.hasValue())
+ continue;
+ // FIXME: Perhaps we should be using DWARFDebugAddrTable
+ uint64_t RawOffset = *Offset + Index * AddressSize;
+ return AddrSectionData.getAddress(&RawOffset);
+ }
+ }
}
return {};
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118098.402757.patch
Type: text/x-patch
Size: 2255 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220125/5f2a7c72/attachment.bin>
More information about the llvm-commits
mailing list