[PATCH] D142667: [BOLT] Rename BF::isParentFragment -> isChildOf
Amir Ayupov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 26 14:09:58 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.
`isChildOf` is a more concise name for the check. Also, there's no need to
test if the function is a fragment before doing `isChildOf` check.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D142667
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,12 +188,7 @@
"BOLT-ERROR: cannot find landing pad fragment");
BC.addInterproceduralReference(this, Fragment->getAddress());
BC.processInterproceduralReferences();
- auto isFragmentOf = [](BinaryFunction *Fragment,
- BinaryFunction *Parent) -> bool {
- return (Fragment->isFragment() && Fragment->isParentFragment(Parent));
- };
- (void)isFragmentOf;
- assert((isFragmentOf(this, Fragment) || isFragmentOf(Fragment, this)) &&
+ assert((isChildOf(*Fragment) || Fragment->isChildOf(*this)) &&
"BOLT-ERROR: cannot have landing pads in different "
"functions");
setHasIndirectTargetToSplitFragment(true);
Index: bolt/lib/Core/BinaryContext.cpp
===================================================================
--- bolt/lib/Core/BinaryContext.cpp
+++ bolt/lib/Core/BinaryContext.cpp
@@ -501,8 +501,7 @@
if (!TargetBF)
return false;
// Check if BF is a fragment of TargetBF or vice versa.
- return (BF.isFragment() && BF.isParentFragment(TargetBF)) ||
- (TargetBF->isFragment() && TargetBF->isParentFragment(&BF));
+ return BF.isChildOf(*TargetBF) || TargetBF->isChildOf(BF);
};
ErrorOr<BinarySection &> Section = getSectionForAddress(Address);
@@ -744,11 +743,6 @@
const MCSymbol *
BinaryContext::getOrCreateJumpTable(BinaryFunction &Function, uint64_t Address,
JumpTable::JumpTableType Type) {
- auto isFragmentOf = [](BinaryFunction *Fragment, BinaryFunction *Parent) {
- return (Fragment->isFragment() && Fragment->isParentFragment(Parent));
- };
- (void)isFragmentOf;
-
// Two fragments of same function access same jump table
if (JumpTable *JT = getJumpTableContainingAddress(Address)) {
assert(JT->Type == Type && "jump table types have to match");
@@ -757,8 +751,8 @@
// 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((isFragmentOf(JT->Parents[0], &Function) ||
- isFragmentOf(&Function, JT->Parents[0])) &&
+ assert((JT->Parents[0]->isChildOf(Function) ||
+ Function.isChildOf(*JT->Parents[0])) &&
"cannot re-use jump table of a different function");
// Duplicate the entry for the parent function for easy access
JT->Parents.push_back(&Function);
@@ -1099,7 +1093,7 @@
bool BinaryContext::registerFragment(BinaryFunction &TargetFunction,
BinaryFunction &Function) const {
assert(TargetFunction.isFragment() && "TargetFunction must be a fragment");
- if (TargetFunction.isParentFragment(&Function))
+ if (TargetFunction.isChildOf(Function))
return true;
TargetFunction.addParentFragment(Function);
Function.addFragment(TargetFunction);
@@ -1222,7 +1216,7 @@
if (TargetFunction) {
if (TargetFunction->isFragment() &&
- !TargetFunction->isParentFragment(&Function)) {
+ !TargetFunction->isChildOf(Function)) {
errs() << "BOLT-WARNING: interprocedural reference between unrelated "
"fragments: "
<< Function.getPrintName() << " and "
Index: bolt/include/bolt/Core/BinaryFunction.h
===================================================================
--- bolt/include/bolt/Core/BinaryFunction.h
+++ bolt/include/bolt/Core/BinaryFunction.h
@@ -1826,9 +1826,9 @@
/// Return true if the function is a secondary fragment of another function.
bool isFragment() const { return IsFragment; }
- /// Returns if the given function is a parent fragment of this function.
- bool isParentFragment(BinaryFunction *Parent) const {
- return ParentFragments.count(Parent);
+ /// Returns if this function is a child of \p Other function.
+ bool isChildOf(const BinaryFunction &Other) const {
+ return llvm::is_contained(ParentFragments, &Other);
}
/// Set the profile data for the number of times the function was called.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142667.492564.patch
Type: text/x-patch
Size: 4299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230126/6332228c/attachment.bin>
More information about the llvm-commits
mailing list