-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Transforms][NFC] Tiny fixes in SplitModule #95903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-llvm-transforms Author: Ilia Sergachev (sergachev) ChangesFix repeated map lookup, variable name, formatting and a missing space. Full diff: https://github.com/llvm/llvm-project/pull/95903.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Utils/SplitModule.cpp b/llvm/lib/Transforms/Utils/SplitModule.cpp
index 9c39c26d8b7af..6fa0d69c29bd6 100644
--- a/llvm/lib/Transforms/Utils/SplitModule.cpp
+++ b/llvm/lib/Transforms/Utils/SplitModule.cpp
@@ -105,7 +105,8 @@ static void findPartitions(Module &M, ClusterIDMapType &ClusterIDMap,
// At this point module should have the proper mix of globals and locals.
// As we attempt to partition this module, we must not change any
// locals to globals.
- LLVM_DEBUG(dbgs() << "Partition module with (" << M.size() << ")functions\n");
+ LLVM_DEBUG(dbgs() << "Partition module with (" << M.size()
+ << ") functions\n");
ClusterMapType GVtoClusterMap;
ComdatMembersType ComdatMembers;
@@ -164,10 +165,10 @@ static void findPartitions(Module &M, ClusterIDMapType &ClusterIDMap,
std::priority_queue<std::pair<unsigned, unsigned>,
std::vector<std::pair<unsigned, unsigned>>,
decltype(CompareClusters)>
- BalancinQueue(CompareClusters);
+ BalancingQueue(CompareClusters);
// Pre-populate priority queue with N slot blanks.
for (unsigned i = 0; i < N; ++i)
- BalancinQueue.push(std::make_pair(i, 0));
+ BalancingQueue.push(std::make_pair(i, 0));
using SortType = std::pair<unsigned, ClusterMapType::iterator>;
@@ -177,11 +178,13 @@ static void findPartitions(Module &M, ClusterIDMapType &ClusterIDMap,
// To guarantee determinism, we have to sort SCC according to size.
// When size is the same, use leader's name.
for (ClusterMapType::iterator I = GVtoClusterMap.begin(),
- E = GVtoClusterMap.end(); I != E; ++I)
+ E = GVtoClusterMap.end();
+ I != E; ++I)
if (I->isLeader())
Sets.push_back(
std::make_pair(std::distance(GVtoClusterMap.member_begin(I),
- GVtoClusterMap.member_end()), I));
+ GVtoClusterMap.member_end()),
+ I));
llvm::sort(Sets, [](const SortType &a, const SortType &b) {
if (a.first == b.first)
@@ -191,9 +194,9 @@ static void findPartitions(Module &M, ClusterIDMapType &ClusterIDMap,
});
for (auto &I : Sets) {
- unsigned CurrentClusterID = BalancinQueue.top().first;
- unsigned CurrentClusterSize = BalancinQueue.top().second;
- BalancinQueue.pop();
+ unsigned CurrentClusterID = BalancingQueue.top().first;
+ unsigned CurrentClusterSize = BalancingQueue.top().second;
+ BalancingQueue.pop();
LLVM_DEBUG(dbgs() << "Root[" << CurrentClusterID << "] cluster_size("
<< I.first << ") ----> " << I.second->getData()->getName()
@@ -211,7 +214,7 @@ static void findPartitions(Module &M, ClusterIDMapType &ClusterIDMap,
CurrentClusterSize++;
}
// Add this set size to the number of entries in this cluster.
- BalancinQueue.push(std::make_pair(CurrentClusterID, CurrentClusterSize));
+ BalancingQueue.push(std::make_pair(CurrentClusterID, CurrentClusterSize));
}
}
@@ -275,8 +278,8 @@ void llvm::SplitModule(
ValueToValueMapTy VMap;
std::unique_ptr<Module> MPart(
CloneModule(M, VMap, [&](const GlobalValue *GV) {
- if (ClusterIDMap.count(GV))
- return (ClusterIDMap[GV] == I);
+ if (auto It = ClusterIDMap.find(GV); It != ClusterIDMap.end())
+ return (It->second == I);
else
return isInPartition(GV, I, N);
}));
|
@@ -275,8 +278,8 @@ void llvm::SplitModule( | |||
ValueToValueMapTy VMap; | |||
std::unique_ptr<Module> MPart( | |||
CloneModule(M, VMap, [&](const GlobalValue *GV) { | |||
if (ClusterIDMap.count(GV)) | |||
return (ClusterIDMap[GV] == I); | |||
if (auto It = ClusterIDMap.find(GV); It != ClusterIDMap.end()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For readability it would probably be better to move out the assignment of It.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it? It's a common pattern that reduces the scope of 'It':
llvm-project/clang/lib/AST/Interp/Program.cpp
Line 117 in 9d45077
if (auto It = GlobalIndices.find(P); It != GlobalIndices.end()) { |
llvm-project/llvm/lib/IR/DebugLoc.cpp
Line 79 in 9d45077
if (auto It = Cache.find(Loc); It != Cache.end()) { |
if (auto It = Names->find(getAtom()); It != Names->end()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also use this pattern a lot and I think it's more readable than 2 separate line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right I guess sits down to personal preference.
ping |
@@ -275,8 +278,8 @@ void llvm::SplitModule( | |||
ValueToValueMapTy VMap; | |||
std::unique_ptr<Module> MPart( | |||
CloneModule(M, VMap, [&](const GlobalValue *GV) { | |||
if (ClusterIDMap.count(GV)) | |||
return (ClusterIDMap[GV] == I); | |||
if (auto It = ClusterIDMap.find(GV); It != ClusterIDMap.end()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also use this pattern a lot and I think it's more readable than 2 separate line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
@@ -275,8 +278,8 @@ void llvm::SplitModule( | |||
ValueToValueMapTy VMap; | |||
std::unique_ptr<Module> MPart( | |||
CloneModule(M, VMap, [&](const GlobalValue *GV) { | |||
if (ClusterIDMap.count(GV)) | |||
return (ClusterIDMap[GV] == I); | |||
if (auto It = ClusterIDMap.find(GV); It != ClusterIDMap.end()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right I guess sits down to personal preference.
@sergachev Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested Please check whether problems have been caused by your change specifically, as How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/107/builds/587 Here is the relevant piece of the build log for the reference:
|
Fix repeated map lookup, variable name, formatting and a missing space.
Fix repeated map lookup, variable name, formatting and a missing space.
Fix repeated map lookup, variable name, formatting and a missing space.