[clang] [llvm] [WIP][NFC] Implicit copy cleanup (PR #174702)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 6 22:47:53 PST 2026
https://github.com/sfu2 updated https://github.com/llvm/llvm-project/pull/174702
>From 3034d30639a6e6c2cf35cb0c8657ec39b8b283fd Mon Sep 17 00:00:00 2001
From: sfu <afwbu8tp6 at mozmail.com>
Date: Wed, 7 Jan 2026 03:25:17 +0000
Subject: [PATCH 1/9] [LifetimeSafety] Avoid map copy for dump methods (NFC)
---
.../clang/Analysis/Analyses/LifetimeSafety/LiveOrigins.h | 2 +-
clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp | 7 ++++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/clang/include/clang/Analysis/Analyses/LifetimeSafety/LiveOrigins.h b/clang/include/clang/Analysis/Analyses/LifetimeSafety/LiveOrigins.h
index 8ad17db83499d..35b4224883cce 100644
--- a/clang/include/clang/Analysis/Analyses/LifetimeSafety/LiveOrigins.h
+++ b/clang/include/clang/Analysis/Analyses/LifetimeSafety/LiveOrigins.h
@@ -87,7 +87,7 @@ class LiveOriginsAnalysis {
// Dump liveness values on all test points in the program.
void dump(llvm::raw_ostream &OS,
- llvm::StringMap<ProgramPoint> TestPoints) const;
+ const llvm::StringMap<ProgramPoint> &TestPoints) const;
private:
class Impl;
diff --git a/clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp b/clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp
index f567cdc548ba7..862dca256280f 100644
--- a/clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp
@@ -165,7 +165,7 @@ class AnalysisImpl
// Dump liveness values on all test points in the program.
void dump(llvm::raw_ostream &OS,
- llvm::StringMap<ProgramPoint> TestPoints) const {
+ const llvm::StringMap<ProgramPoint> &TestPoints) const {
llvm::dbgs() << "==========================================\n";
llvm::dbgs() << getAnalysisName() << " results:\n";
llvm::dbgs() << "==========================================\n";
@@ -199,8 +199,9 @@ LivenessMap LiveOriginsAnalysis::getLiveOriginsAt(ProgramPoint P) const {
return PImpl->getLiveOriginsAt(P);
}
-void LiveOriginsAnalysis::dump(llvm::raw_ostream &OS,
- llvm::StringMap<ProgramPoint> TestPoints) const {
+void LiveOriginsAnalysis::dump(
+ llvm::raw_ostream &OS,
+ const llvm::StringMap<ProgramPoint> &TestPoints) const {
PImpl->dump(OS, TestPoints);
}
} // namespace clang::lifetimes::internal
>From a121519d8dd5d47ef0b1635d442ae49416d34bf2 Mon Sep 17 00:00:00 2001
From: sfu <afwbu8tp6 at mozmail.com>
Date: Wed, 7 Jan 2026 03:25:33 +0000
Subject: [PATCH 2/9] [BlockExtract] Avoid copy semantic for ctor (NFC)
---
llvm/lib/Transforms/IPO/BlockExtractor.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/IPO/BlockExtractor.cpp b/llvm/lib/Transforms/IPO/BlockExtractor.cpp
index 44913533030e3..23991afc511a0 100644
--- a/llvm/lib/Transforms/IPO/BlockExtractor.cpp
+++ b/llvm/lib/Transforms/IPO/BlockExtractor.cpp
@@ -196,7 +196,8 @@ bool BlockExtractor::runOnModule(Module &M) {
BlockExtractorPass::BlockExtractorPass(
std::vector<std::vector<BasicBlock *>> &&GroupsOfBlocks,
bool EraseFunctions)
- : GroupsOfBlocks(GroupsOfBlocks), EraseFunctions(EraseFunctions) {}
+ : GroupsOfBlocks(std::move(GroupsOfBlocks)),
+ EraseFunctions(EraseFunctions) {}
PreservedAnalyses BlockExtractorPass::run(Module &M,
ModuleAnalysisManager &AM) {
>From 6b22bcf5627cfe9d5e4da8a2ae80f3c73a6f3f55 Mon Sep 17 00:00:00 2001
From: sfu <afwbu8tp6 at mozmail.com>
Date: Wed, 7 Jan 2026 03:28:52 +0000
Subject: [PATCH 3/9] [TextAPI] Replace map copy with const reference (NFC)
---
llvm/lib/TextAPI/TextStubV5.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/TextAPI/TextStubV5.cpp b/llvm/lib/TextAPI/TextStubV5.cpp
index f2687513bb854..de40d84f5e7a6 100644
--- a/llvm/lib/TextAPI/TextStubV5.cpp
+++ b/llvm/lib/TextAPI/TextStubV5.cpp
@@ -642,13 +642,13 @@ Expected<IFPtr> parseToInterfaceFile(const Object *File) {
auto UmbrellasOrErr = getUmbrellaSection(File, Targets);
if (!UmbrellasOrErr)
return UmbrellasOrErr.takeError();
- AttrToTargets Umbrellas = *UmbrellasOrErr;
+ const AttrToTargets &Umbrellas = *UmbrellasOrErr;
auto ClientsOrErr =
getLibSection(File, TBDKey::AllowableClients, TBDKey::Clients, Targets);
if (!ClientsOrErr)
return ClientsOrErr.takeError();
- AttrToTargets Clients = *ClientsOrErr;
+ const AttrToTargets &Clients = *ClientsOrErr;
auto RLOrErr =
getLibSection(File, TBDKey::ReexportLibs, TBDKey::Names, Targets);
>From b89526f909b36fa580e3019b4ce15b8db36905a0 Mon Sep 17 00:00:00 2001
From: sfu <afwbu8tp6 at mozmail.com>
Date: Wed, 7 Jan 2026 03:32:46 +0000
Subject: [PATCH 4/9] [LoongArch] Remove unnecessary vector copy (NFC)
---
llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
index 2ab2a98c9434c..4b5cba716c638 100644
--- a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
@@ -276,7 +276,7 @@ void LoongArchAsmPrinter::emitJumpTableInfo() {
return;
unsigned Size = getDataLayout().getPointerSize();
- auto JT = JTI->getJumpTables();
+ const auto &JT = JTI->getJumpTables();
// Emit an additional section to store the correlation info as pairs of
// addresses, each pair contains the address of a jump instruction (jr) and
>From 749bb21de1c0be5d461fe9243b69d52848ba369d Mon Sep 17 00:00:00 2001
From: sfu <afwbu8tp6 at mozmail.com>
Date: Wed, 7 Jan 2026 03:34:48 +0000
Subject: [PATCH 5/9] [CommandLine] Avoid vector copy for const argument (NFC)
---
llvm/lib/Support/CommandLine.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 5095b298fd42d..d7a28745a4669 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -2557,7 +2557,7 @@ class HelpPrinterWrapper {
namespace {
class VersionPrinter {
public:
- void print(std::vector<VersionPrinterTy> ExtraPrinters = {}) {
+ void print(const std::vector<VersionPrinterTy> &ExtraPrinters) {
raw_ostream &OS = outs();
#ifdef PACKAGE_VENDOR
OS << PACKAGE_VENDOR << " ";
>From 8261250d70832c2ebd48507fbf0f3f66f0fa1904 Mon Sep 17 00:00:00 2001
From: sfu <afwbu8tp6 at mozmail.com>
Date: Wed, 7 Jan 2026 03:37:18 +0000
Subject: [PATCH 6/9] [InstCombine] Replace vector copy with move semantic
(NFC)
---
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 8c64105b63fe4..f2e827221e8cf 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -4831,7 +4831,7 @@ Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) {
GCR.setOperand(2, ConstantInt::get(OpIntTy2, Val2Idx[DerivedPtr]));
}
// Create new statepoint instruction.
- OperandBundleDef NewBundle("gc-live", NewLiveGc);
+ OperandBundleDef NewBundle("gc-live", std::move(NewLiveGc));
return CallBase::Create(&Call, NewBundle);
}
default: { break; }
>From e1f5254e05d0f1a9096fa04178e0dca1af3235b4 Mon Sep 17 00:00:00 2001
From: sfu <afwbu8tp6 at mozmail.com>
Date: Wed, 7 Jan 2026 03:40:17 +0000
Subject: [PATCH 7/9] [AMDGPU] Replace copy with move semantics (NFC)
SplitProposal with vector field may be copid multiple times in
RecursiveSearchSplitting
---
llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
index b7078825928be..581a3df70b994 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp
@@ -991,7 +991,7 @@ void RecursiveSearchSplitting::run() {
{
SplitModuleTimer SMT("recursive_search_pick", "partitioning");
SplitProposal SP(SG, NumParts);
- pickPartition(/*BranchDepth=*/0, /*Idx=*/0, SP);
+ pickPartition(/*BranchDepth=*/0, /*Idx=*/0, std::move(SP));
}
}
@@ -1161,7 +1161,7 @@ void RecursiveSearchSplitting::pickPartition(unsigned Depth, unsigned Idx,
SP.setName("recursive_search (depth=" + std::to_string(Depth) + ") #" +
std::to_string(NumProposalsSubmitted++));
LLVM_DEBUG(dbgs() << '\n');
- SubmitProposal(SP);
+ SubmitProposal(std::move(SP));
}
std::pair<unsigned, CostType>
>From 25ceecee8093419ff75d32020f3508c358363ff7 Mon Sep 17 00:00:00 2001
From: sfu <afwbu8tp6 at mozmail.com>
Date: Wed, 7 Jan 2026 03:44:41 +0000
Subject: [PATCH 8/9] [-Wunsafe-buffer-usage] Replace vector copy with
reference (NFC)
VariableGroupsManagerImpl copies a vector in ctor. At its single use
site in applyGadgets, the object VarGrpMgr always holds a valid to
`Groups`. Thus such replacement is safe from dangling reference.
---
clang/lib/Analysis/UnsafeBufferUsage.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index da19b9d3902f1..4c7ff12af8a0d 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -4241,7 +4241,7 @@ getNaiveStrategy(llvm::iterator_range<VarDeclIterTy> UnsafeVars) {
// Manages variable groups:
class VariableGroupsManagerImpl : public VariableGroupsManager {
- const std::vector<VarGrpTy> Groups;
+ const std::vector<VarGrpTy> &Groups;
const std::map<const VarDecl *, unsigned> &VarGrpMap;
const llvm::SetVector<const VarDecl *> &GrpsUnionForParms;
>From e8996cb247bab0218d3cfb5f570dc824b9f7d76f Mon Sep 17 00:00:00 2001
From: sfu <afwbu8tp6 at mozmail.com>
Date: Wed, 7 Jan 2026 03:51:28 +0000
Subject: [PATCH 9/9] [AMDGPU] replace copy with const reference (NFC)
V2SCopyInfo, containing a SetVector, gets copid in iteration. By
reordering the erase logic, such replacement is safe from dangling
reference.
---
llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
index 39a6a7762eea5..5ae02d025989b 100644
--- a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
@@ -111,7 +111,7 @@ class V2SCopyInfo {
V2SCopyInfo(unsigned Id, MachineInstr *C, unsigned Width)
: Copy(C), NumReadfirstlanes(Width / 32), ID(Id){};
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
- void dump() {
+ void dump() const {
dbgs() << ID << " : " << *Copy << "\n\tS:" << SChain.size()
<< "\n\tSV:" << NumSVCopies << "\n\tSP: " << SiblingPenalty
<< "\nScore: " << Score << "\n";
@@ -1072,7 +1072,7 @@ void SIFixSGPRCopies::lowerVGPR2SGPRCopies(MachineFunction &MF) {
unsigned CurID = LoweringWorklist.pop_back_val();
auto *CurInfoIt = V2SCopies.find(CurID);
if (CurInfoIt != V2SCopies.end()) {
- V2SCopyInfo C = CurInfoIt->second;
+ const V2SCopyInfo &C = CurInfoIt->second;
LLVM_DEBUG(dbgs() << "Processing ...\n"; C.dump());
for (auto S : C.Siblings) {
auto *SibInfoIt = V2SCopies.find(S);
@@ -1089,10 +1089,10 @@ void SIFixSGPRCopies::lowerVGPR2SGPRCopies(MachineFunction &MF) {
}
LLVM_DEBUG(dbgs() << "V2S copy " << *C.Copy
<< " is being turned to VALU\n");
+ Copies.insert(C.Copy);
// TODO: MapVector::erase is inefficient. Do bulk removal with remove_if
// instead.
V2SCopies.erase(C.ID);
- Copies.insert(C.Copy);
}
}
More information about the llvm-commits
mailing list