-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[CodeGen] Construct SmallVector with iterator ranges (NFC) #136258
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
Merged
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_SmallVector_iter_range_llvm_CodeGen
Apr 18, 2025
Merged
[CodeGen] Construct SmallVector with iterator ranges (NFC) #136258
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_SmallVector_iter_range_llvm_CodeGen
Apr 18, 2025
+10
−16
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-llvm-globalisel @llvm/pr-subscribers-llvm-regalloc Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/136258.diff 5 Files Affected:
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 1bbd1b6f71b14..0cc9fb88b4293 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -834,9 +834,8 @@ bool CodeGenPrepare::eliminateFallThrough(Function &F, DominatorTree *DT) {
// Scan all of the blocks in the function, except for the entry block.
// Use a temporary array to avoid iterator being invalidated when
// deleting blocks.
- SmallVector<WeakTrackingVH, 16> Blocks;
- for (auto &Block : llvm::drop_begin(F))
- Blocks.push_back(&Block);
+ SmallVector<WeakTrackingVH, 16> Blocks(
+ llvm::make_pointer_range(llvm::drop_begin(F)));
SmallSet<WeakTrackingVH, 16> Preds;
for (auto &Block : Blocks) {
diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
index dbc838a3782ca..333f0c17bacc5 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -867,9 +867,8 @@ void CombinerHelper::applyCombineExtendingLoads(
// Rewrite all the uses to fix up the types.
auto &LoadValue = MI.getOperand(0);
- SmallVector<MachineOperand *, 4> Uses;
- for (auto &UseMO : MRI.use_operands(LoadValue.getReg()))
- Uses.push_back(&UseMO);
+ SmallVector<MachineOperand *, 4> Uses(
+ llvm::make_pointer_range(MRI.use_operands(LoadValue.getReg())));
for (auto *UseMO : Uses) {
MachineInstr *UseMI = UseMO->getParent();
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index 7e4a32f67fe6a..33910d0ec6aeb 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -2442,9 +2442,8 @@ static const DIExpression *computeExprForSpill(
static const DIExpression *computeExprForSpill(const MachineInstr &MI,
Register SpillReg) {
assert(MI.hasDebugOperandForReg(SpillReg) && "Spill Reg is not used in MI.");
- SmallVector<const MachineOperand *> SpillOperands;
- for (const MachineOperand &Op : MI.getDebugOperandsForReg(SpillReg))
- SpillOperands.push_back(&Op);
+ SmallVector<const MachineOperand *> SpillOperands(
+ llvm::make_pointer_range(MI.getDebugOperandsForReg(SpillReg)));
return computeExprForSpill(MI, SpillOperands);
}
diff --git a/llvm/lib/CodeGen/RegAllocFast.cpp b/llvm/lib/CodeGen/RegAllocFast.cpp
index 857cf85a8acbc..bb118dd9e1867 100644
--- a/llvm/lib/CodeGen/RegAllocFast.cpp
+++ b/llvm/lib/CodeGen/RegAllocFast.cpp
@@ -1733,9 +1733,8 @@ void RegAllocFastImpl::handleDebugValue(MachineInstr &MI) {
// See if this virtual register has already been allocated to a physical
// register or spilled to a stack slot.
LiveRegMap::iterator LRI = findLiveVirtReg(Reg);
- SmallVector<MachineOperand *> DbgOps;
- for (MachineOperand &Op : MI.getDebugOperandsForReg(Reg))
- DbgOps.push_back(&Op);
+ SmallVector<MachineOperand *> DbgOps(
+ llvm::make_pointer_range(MI.getDebugOperandsForReg(Reg)));
if (LRI != LiveVirtRegs.end() && LRI->PhysReg) {
// Update every use of Reg within MI.
diff --git a/llvm/lib/CodeGen/RegisterUsageInfo.cpp b/llvm/lib/CodeGen/RegisterUsageInfo.cpp
index 6a3e34be6d391..7a4628a6e91d4 100644
--- a/llvm/lib/CodeGen/RegisterUsageInfo.cpp
+++ b/llvm/lib/CodeGen/RegisterUsageInfo.cpp
@@ -72,11 +72,9 @@ PhysicalRegisterUsageInfo::getRegUsageInfo(const Function &FP) {
void PhysicalRegisterUsageInfo::print(raw_ostream &OS, const Module *M) const {
using FuncPtrRegMaskPair = std::pair<const Function *, std::vector<uint32_t>>;
- SmallVector<const FuncPtrRegMaskPair *, 64> FPRMPairVector;
-
// Create a vector of pointer to RegMasks entries
- for (const auto &RegMask : RegMasks)
- FPRMPairVector.push_back(&RegMask);
+ SmallVector<const FuncPtrRegMaskPair *, 64> FPRMPairVector(
+ llvm::make_pointer_range(RegMasks));
// sort the vector to print analysis in alphabatic order of function name.
llvm::sort(
|
arsenm
approved these changes
Apr 18, 2025
kuhar
approved these changes
Apr 18, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.