[PATCH] D142668: [BOLT] Add isParentOf and isSiblingOf BinaryFunction methods
Amir Ayupov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 26 14:11:31 PST 2023
Amir created this revision.
Amir added a reviewer: bolt.
Herald added a reviewer: rafauler.
Herald added subscribers: treapster, ayermolo.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.
Add helper methods and simplify cases where we want to check if two functions
are siblings of each other (parent-child or function-fragment relationship).
Repository:
rG LLVM Github Monorepo
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(isSiblingOf(*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
@@ -495,13 +495,7 @@
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);
+ return BF.containsAddress(Addr) || (TargetBF && TargetBF->isSiblingOf(BF));
};
ErrorOr<BinarySection &> Section = getSectionForAddress(Address);
@@ -751,8 +745,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]->isSiblingOf(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 isSiblingOf(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.492565.patch
Type: text/x-patch
Size: 2933 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230126/dfb636f3/attachment.bin>
More information about the llvm-commits
mailing list