summaryrefslogtreecommitdiff
path: root/bolt
diff options
context:
space:
mode:
authorAmir Ayupov <aaupov@fb.com>2023-02-09 10:56:55 -0800
committerAmir Ayupov <aaupov@fb.com>2023-02-09 10:57:10 -0800
commite88122f5f10dfe0309dc9f0f5bc7a3cfa49586a9 (patch)
tree44489543bf140cbe067ddddb936428a6d7041363 /bolt
parent701109b9b626f380546e479b61bd3be672faed5e (diff)
downloadllvm-e88122f5f10dfe0309dc9f0f5bc7a3cfa49586a9.tar.gz
[BOLT] Rename BF::isParentFragment -> isChildOf
`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. Reviewed By: #bolt, rafauler, maksfb Differential Revision: https://reviews.llvm.org/D142667
Diffstat (limited to 'bolt')
-rw-r--r--bolt/include/bolt/Core/BinaryFunction.h6
-rw-r--r--bolt/lib/Core/BinaryContext.cpp16
-rw-r--r--bolt/lib/Core/Exceptions.cpp7
3 files changed, 9 insertions, 20 deletions
diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h
index 1ee333bc1226..fd243a4f9fa8 100644
--- a/bolt/include/bolt/Core/BinaryFunction.h
+++ b/bolt/include/bolt/Core/BinaryFunction.h
@@ -1826,9 +1826,9 @@ public:
/// 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.
diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index 4087b31c0c8f..9942b5ddede7 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -502,8 +502,7 @@ bool BinaryContext::analyzeJumpTable(
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);
@@ -745,11 +744,6 @@ BinaryFunction *BinaryContext::createBinaryFunction(
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");
@@ -758,8 +752,8 @@ BinaryContext::getOrCreateJumpTable(BinaryFunction &Function, uint64_t Address,
// 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);
@@ -1100,7 +1094,7 @@ void BinaryContext::generateSymbolHashes() {
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);
@@ -1223,7 +1217,7 @@ void BinaryContext::processInterproceduralReferences() {
if (TargetFunction) {
if (TargetFunction->isFragment() &&
- !TargetFunction->isParentFragment(&Function)) {
+ !TargetFunction->isChildOf(Function)) {
errs() << "BOLT-WARNING: interprocedural reference between unrelated "
"fragments: "
<< Function.getPrintName() << " and "
diff --git a/bolt/lib/Core/Exceptions.cpp b/bolt/lib/Core/Exceptions.cpp
index 34e7454abfb0..d01c52853a7e 100644
--- a/bolt/lib/Core/Exceptions.cpp
+++ b/bolt/lib/Core/Exceptions.cpp
@@ -188,12 +188,7 @@ void BinaryFunction::parseLSDA(ArrayRef<uint8_t> LSDASectionData,
"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);