[PATCH] D142668: [BOLT] Add isParentOf and isSiblingOf BinaryFunction methods
Amir Ayupov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 19 11:36:37 PDT 2023
Amir updated this revision to Diff 523876.
Amir added a comment.
s/isSiblingOf/isParentOrChildOf
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142668/new/
https://reviews.llvm.org/D142668
Files:
bolt/include/bolt/Core/BinaryFunction.h
bolt/lib/Core/BinaryContext.cpp
bolt/lib/Core/Exceptions.cpp
Index: bolt/lib/Core/Exceptions.cpp
===================================================================
--- bolt/lib/Core/Exceptions.cpp
+++ bolt/lib/Core/Exceptions.cpp
@@ -188,9 +188,8 @@
"BOLT-ERROR: cannot find landing pad fragment");
BC.addInterproceduralReference(this, Fragment->getAddress());
BC.processInterproceduralReferences();
- assert((isChildOf(*Fragment) || Fragment->isChildOf(*this)) &&
- "BOLT-ERROR: cannot have landing pads in different "
- "functions");
+ assert(isParentOrChildOf(*Fragment) &&
+ "BOLT-ERROR: cannot have landing pads in different functions");
setHasIndirectTargetToSplitFragment(true);
BC.addFragmentsToSkip(this);
return;
Index: bolt/lib/Core/BinaryContext.cpp
===================================================================
--- bolt/lib/Core/BinaryContext.cpp
+++ bolt/lib/Core/BinaryContext.cpp
@@ -493,17 +493,6 @@
EntriesAsAddress->emplace_back(EntryAddress);
};
- auto doesBelongToFunction = [&](const uint64_t Addr,
- BinaryFunction *TargetBF) -> bool {
- if (BF.containsAddress(Addr))
- return true;
- // Nothing to do if we failed to identify the containing function.
- if (!TargetBF)
- return false;
- // Check if BF is a fragment of TargetBF or vice versa.
- return BF.isChildOf(*TargetBF) || TargetBF->isChildOf(BF);
- };
-
ErrorOr<BinarySection &> Section = getSectionForAddress(Address);
if (!Section)
return false;
@@ -563,8 +552,11 @@
// Function or one of its fragments.
BinaryFunction *TargetBF = getBinaryFunctionContainingAddress(Value);
+ bool DoesBelongToFunction =
+ BF.containsAddress(Value) || (TargetBF && TargetBF->isParentOrChildOf(BF));
+
// We assume that a jump table cannot have function start as an entry.
- if (!doesBelongToFunction(Value, TargetBF) || Value == BF.getAddress()) {
+ if (!DoesBelongToFunction || Value == BF.getAddress()) {
LLVM_DEBUG({
if (!BF.containsAddress(Value)) {
dbgs() << "FAIL: function doesn't contain this address\n";
@@ -751,8 +743,7 @@
// Prevent associating a jump table to a specific fragment twice.
// This simple check arises from the assumption: no more than 2 fragments.
if (JT->Parents.size() == 1 && JT->Parents[0] != &Function) {
- assert((JT->Parents[0]->isChildOf(Function) ||
- Function.isChildOf(*JT->Parents[0])) &&
+ assert(JT->Parents[0]->isParentOrChildOf(Function) &&
"cannot re-use jump table of a different function");
// Duplicate the entry for the parent function for easy access
JT->Parents.push_back(&Function);
Index: bolt/include/bolt/Core/BinaryFunction.h
===================================================================
--- bolt/include/bolt/Core/BinaryFunction.h
+++ bolt/include/bolt/Core/BinaryFunction.h
@@ -1831,6 +1831,16 @@
return llvm::is_contained(ParentFragments, &Other);
}
+ /// Returns if this function is a parent of \p Other function.
+ bool isParentOf(const BinaryFunction &Other) const {
+ return llvm::is_contained(Fragments, &Other);
+ }
+
+ /// Returns if this function is a parent or child of \p Other function.
+ bool isParentOrChildOf(const BinaryFunction &Other) const {
+ return isChildOf(Other) || isParentOf(Other);
+ }
+
/// Set the profile data for the number of times the function was called.
BinaryFunction &setExecutionCount(uint64_t Count) {
ExecutionCount = Count;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142668.523876.patch
Type: text/x-patch
Size: 3575 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230519/cb716404/attachment.bin>
More information about the llvm-commits
mailing list