From ce16eb4af5a85c3f07553ca7adc5016c0c575076 Mon Sep 17 00:00:00 2001 From: abhishek-kaushik22 Date: Fri, 29 Nov 2024 14:11:43 +0530 Subject: [PATCH 1/5] [CGData][GlobalIsel][Legalizer][DAG][MC][AsmParser][X86][AMX] Use std::move to avoid copy --- llvm/include/llvm/CGData/StableFunctionMap.h | 4 +- .../lib/CodeGen/GlobalISel/CombinerHelper.cpp | 4 +- .../CodeGen/GlobalISel/LegalityPredicates.cpp | 6 +-- .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 +- llvm/lib/MC/MCParser/AsmParser.cpp | 2 +- llvm/lib/MC/MCStreamer.cpp | 40 +++++++++---------- llvm/lib/Target/X86/X86TileConfig.cpp | 6 +-- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/llvm/include/llvm/CGData/StableFunctionMap.h b/llvm/include/llvm/CGData/StableFunctionMap.h index 8881adf5889d0..954b001c1477d 100644 --- a/llvm/include/llvm/CGData/StableFunctionMap.h +++ b/llvm/include/llvm/CGData/StableFunctionMap.h @@ -42,8 +42,8 @@ struct StableFunction { StableFunction(stable_hash Hash, const std::string FunctionName, const std::string ModuleName, unsigned InstCount, IndexOperandHashVecType &&IndexOperandHashes) - : Hash(Hash), FunctionName(FunctionName), ModuleName(ModuleName), - InstCount(InstCount), + : Hash(Hash), FunctionName(std::move(FunctionName)), + ModuleName(std::move(ModuleName)), InstCount(InstCount), IndexOperandHashes(std::move(IndexOperandHashes)) {} StableFunction() = default; }; diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp index d95fc8cfbcf55..a273799544652 100644 --- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp @@ -7717,9 +7717,9 @@ bool CombinerHelper::matchShuffleUndefRHS(MachineInstr &MI, if (!Changed) return false; - MatchInfo = [&, NewMask](MachineIRBuilder &B) { + MatchInfo = [&, NewMask = std::move(NewMask)](MachineIRBuilder &B) { B.buildShuffleVector(MI.getOperand(0), MI.getOperand(1), MI.getOperand(2), - NewMask); + std::move(NewMask)); }; return true; diff --git a/llvm/lib/CodeGen/GlobalISel/LegalityPredicates.cpp b/llvm/lib/CodeGen/GlobalISel/LegalityPredicates.cpp index 30c2d089c3121..30c34f2e74e61 100644 --- a/llvm/lib/CodeGen/GlobalISel/LegalityPredicates.cpp +++ b/llvm/lib/CodeGen/GlobalISel/LegalityPredicates.cpp @@ -35,7 +35,7 @@ LegalityPredicates::typeInSet(unsigned TypeIdx, std::initializer_list TypesInit) { SmallVector Types = TypesInit; return [=](const LegalityQuery &Query) { - return llvm::is_contained(Types, Query.Types[TypeIdx]); + return llvm::is_contained(std::move(Types), Query.Types[TypeIdx]); }; } @@ -45,7 +45,7 @@ LegalityPredicate LegalityPredicates::typePairInSet( SmallVector, 4> Types = TypesInit; return [=](const LegalityQuery &Query) { std::pair Match = {Query.Types[TypeIdx0], Query.Types[TypeIdx1]}; - return llvm::is_contained(Types, Match); + return llvm::is_contained(std::move(Types), Match); }; } @@ -56,7 +56,7 @@ LegalityPredicate LegalityPredicates::typeTupleInSet( return [=](const LegalityQuery &Query) { std::tuple Match = { Query.Types[TypeIdx0], Query.Types[TypeIdx1], Query.Types[TypeIdx2]}; - return llvm::is_contained(Types, Match); + return llvm::is_contained(std::move(Types), Match); }; } diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 182529123ec6d..0fb5612390ea7 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -6824,7 +6824,7 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, continue; } APInt Val = cast(Op)->getAPIntValue(); - ScalarOps.push_back(SignExtendInReg(Val, OpVT)); + ScalarOps.push_back(SignExtendInReg(std::move(Val), OpVT)); } return getBuildVector(VT, DL, ScalarOps); } diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 3ce45f7d5d67e..d15a9a8a36c5a 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -6287,7 +6287,7 @@ bool AsmParser::parseMSInlineAsm( if (AsmStart != AsmEnd) OS << StringRef(AsmStart, AsmEnd - AsmStart); - AsmString = AsmStringIR; + AsmString = std::move(AsmStringIR); return false; } diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index df1b160f9df28..5703cfd03fceb 100644 --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -463,7 +463,7 @@ void MCStreamer::emitCFIStartProc(bool IsSimple, SMLoc Loc) { } FrameInfoStack.emplace_back(DwarfFrameInfos.size(), getCurrentSectionOnly()); - DwarfFrameInfos.push_back(Frame); + DwarfFrameInfos.push_back(std::move(Frame)); } void MCStreamer::emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) { @@ -510,7 +510,7 @@ void MCStreamer::emitCFIDefCfa(int64_t Register, int64_t Offset, SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); CurFrame->CurrentCfaRegister = static_cast(Register); } @@ -521,7 +521,7 @@ void MCStreamer::emitCFIDefCfaOffset(int64_t Offset, SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } void MCStreamer::emitCFIAdjustCfaOffset(int64_t Adjustment, SMLoc Loc) { @@ -531,7 +531,7 @@ void MCStreamer::emitCFIAdjustCfaOffset(int64_t Adjustment, SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } void MCStreamer::emitCFIDefCfaRegister(int64_t Register, SMLoc Loc) { @@ -541,7 +541,7 @@ void MCStreamer::emitCFIDefCfaRegister(int64_t Register, SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); CurFrame->CurrentCfaRegister = static_cast(Register); } @@ -553,7 +553,7 @@ void MCStreamer::emitCFILLVMDefAspaceCfa(int64_t Register, int64_t Offset, MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); CurFrame->CurrentCfaRegister = static_cast(Register); } @@ -564,7 +564,7 @@ void MCStreamer::emitCFIOffset(int64_t Register, int64_t Offset, SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } void MCStreamer::emitCFIRelOffset(int64_t Register, int64_t Offset, SMLoc Loc) { @@ -574,7 +574,7 @@ void MCStreamer::emitCFIRelOffset(int64_t Register, int64_t Offset, SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } void MCStreamer::emitCFIPersonality(const MCSymbol *Sym, @@ -601,7 +601,7 @@ void MCStreamer::emitCFIRememberState(SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } void MCStreamer::emitCFIRestoreState(SMLoc Loc) { @@ -612,7 +612,7 @@ void MCStreamer::emitCFIRestoreState(SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } void MCStreamer::emitCFISameValue(int64_t Register, SMLoc Loc) { @@ -622,7 +622,7 @@ void MCStreamer::emitCFISameValue(int64_t Register, SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } void MCStreamer::emitCFIRestore(int64_t Register, SMLoc Loc) { @@ -632,7 +632,7 @@ void MCStreamer::emitCFIRestore(int64_t Register, SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } void MCStreamer::emitCFIEscape(StringRef Values, SMLoc Loc) { @@ -642,7 +642,7 @@ void MCStreamer::emitCFIEscape(StringRef Values, SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } void MCStreamer::emitCFIGnuArgsSize(int64_t Size, SMLoc Loc) { @@ -652,7 +652,7 @@ void MCStreamer::emitCFIGnuArgsSize(int64_t Size, SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } void MCStreamer::emitCFISignalFrame() { @@ -669,7 +669,7 @@ void MCStreamer::emitCFIUndefined(int64_t Register, SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } void MCStreamer::emitCFIRegister(int64_t Register1, int64_t Register2, @@ -680,7 +680,7 @@ void MCStreamer::emitCFIRegister(int64_t Register1, int64_t Register2, MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } void MCStreamer::emitCFIWindowSave(SMLoc Loc) { @@ -689,7 +689,7 @@ void MCStreamer::emitCFIWindowSave(SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } void MCStreamer::emitCFINegateRAState(SMLoc Loc) { @@ -699,7 +699,7 @@ void MCStreamer::emitCFINegateRAState(SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } void MCStreamer::emitCFINegateRAStateWithPC(SMLoc Loc) { @@ -709,7 +709,7 @@ void MCStreamer::emitCFINegateRAStateWithPC(SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } void MCStreamer::emitCFIReturnColumn(int64_t Register) { @@ -733,7 +733,7 @@ void MCStreamer::emitCFIValOffset(int64_t Register, int64_t Offset, SMLoc Loc) { MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo(); if (!CurFrame) return; - CurFrame->Instructions.push_back(Instruction); + CurFrame->Instructions.push_back(std::move(Instruction)); } WinEH::FrameInfo *MCStreamer::EnsureValidWinFrameInfo(SMLoc Loc) { diff --git a/llvm/lib/Target/X86/X86TileConfig.cpp b/llvm/lib/Target/X86/X86TileConfig.cpp index 75f002f418ba6..c054b26727855 100644 --- a/llvm/lib/Target/X86/X86TileConfig.cpp +++ b/llvm/lib/Target/X86/X86TileConfig.cpp @@ -103,7 +103,7 @@ static void collectVirtRegShapes(MachineRegisterInfo *MRI, VirtRegMap &VRM, unsigned Index = PhysReg - X86::TMM0; if (!Phys2Shapes[Index].isValid()) { ShapeT Shape = VRM.getShape(VirtReg); - Phys2Shapes[Index] = Shape; + Phys2Shapes[Index] = std::move(Shape); return; } } @@ -118,12 +118,12 @@ static void collectVirtRegShapes(MachineRegisterInfo *MRI, VirtRegMap &VRM, if (!Phys2Shapes[Index0].isValid()) { ShapeT Shape0(Shape.getRow(0), Shape.getCol(0), MRI); - Phys2Shapes[Index0] = Shape0; + Phys2Shapes[Index0] = std::move(Shape0); } if (!Phys2Shapes[Index1].isValid()) { ShapeT Shape1(Shape.getRow(1), Shape.getCol(1), MRI); - Phys2Shapes[Index1] = Shape1; + Phys2Shapes[Index1] = std::move(Shape1); } } } From 64e844acb3d113a951b6de61220b2b426736eadb Mon Sep 17 00:00:00 2001 From: abhishek-kaushik22 Date: Thu, 5 Dec 2024 12:24:31 +0530 Subject: [PATCH 2/5] Update StableFunctionMap.h --- llvm/include/llvm/CGData/StableFunctionMap.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/CGData/StableFunctionMap.h b/llvm/include/llvm/CGData/StableFunctionMap.h index 954b001c1477d..7725929935e3c 100644 --- a/llvm/include/llvm/CGData/StableFunctionMap.h +++ b/llvm/include/llvm/CGData/StableFunctionMap.h @@ -42,8 +42,8 @@ struct StableFunction { StableFunction(stable_hash Hash, const std::string FunctionName, const std::string ModuleName, unsigned InstCount, IndexOperandHashVecType &&IndexOperandHashes) - : Hash(Hash), FunctionName(std::move(FunctionName)), - ModuleName(std::move(ModuleName)), InstCount(InstCount), + : Hash(Hash), FunctionName(FunctionName), ModuleName(ModuleName), + InstCount(InstCount), IndexOperandHashes(std::move(IndexOperandHashes)) {} StableFunction() = default; }; From dbf9c385c6d6598fa0bc85ec59a1c02f860c2a5b Mon Sep 17 00:00:00 2001 From: abhishek-kaushik22 Date: Thu, 5 Dec 2024 12:29:14 +0530 Subject: [PATCH 3/5] Update StableFunctionMap.h --- llvm/include/llvm/CGData/StableFunctionMap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/include/llvm/CGData/StableFunctionMap.h b/llvm/include/llvm/CGData/StableFunctionMap.h index 7725929935e3c..8881adf5889d0 100644 --- a/llvm/include/llvm/CGData/StableFunctionMap.h +++ b/llvm/include/llvm/CGData/StableFunctionMap.h @@ -42,7 +42,7 @@ struct StableFunction { StableFunction(stable_hash Hash, const std::string FunctionName, const std::string ModuleName, unsigned InstCount, IndexOperandHashVecType &&IndexOperandHashes) - : Hash(Hash), FunctionName(FunctionName), ModuleName(ModuleName), + : Hash(Hash), FunctionName(FunctionName), ModuleName(ModuleName), InstCount(InstCount), IndexOperandHashes(std::move(IndexOperandHashes)) {} StableFunction() = default; From 9d4c10f8d9db35219795d428149379c2d6940b85 Mon Sep 17 00:00:00 2001 From: abhishek-kaushik22 Date: Thu, 5 Dec 2024 12:35:13 +0530 Subject: [PATCH 4/5] Update SelectionDAG.cpp --- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 0fb5612390ea7..df3e2a5daa3b3 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -6823,7 +6823,7 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, ScalarOps.push_back(getUNDEF(OpVT)); continue; } - APInt Val = cast(Op)->getAPIntValue(); + const APInt &Val = cast(Op)->getAPIntValue(); ScalarOps.push_back(SignExtendInReg(std::move(Val), OpVT)); } return getBuildVector(VT, DL, ScalarOps); From b39ffba7ea135be6a902429a72177bd41f3b58be Mon Sep 17 00:00:00 2001 From: abhishek-kaushik22 Date: Thu, 5 Dec 2024 12:45:31 +0530 Subject: [PATCH 5/5] Review Changes --- llvm/lib/CodeGen/GlobalISel/LegalityPredicates.cpp | 6 +++--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/lib/CodeGen/GlobalISel/LegalityPredicates.cpp b/llvm/lib/CodeGen/GlobalISel/LegalityPredicates.cpp index 30c34f2e74e61..30c2d089c3121 100644 --- a/llvm/lib/CodeGen/GlobalISel/LegalityPredicates.cpp +++ b/llvm/lib/CodeGen/GlobalISel/LegalityPredicates.cpp @@ -35,7 +35,7 @@ LegalityPredicates::typeInSet(unsigned TypeIdx, std::initializer_list TypesInit) { SmallVector Types = TypesInit; return [=](const LegalityQuery &Query) { - return llvm::is_contained(std::move(Types), Query.Types[TypeIdx]); + return llvm::is_contained(Types, Query.Types[TypeIdx]); }; } @@ -45,7 +45,7 @@ LegalityPredicate LegalityPredicates::typePairInSet( SmallVector, 4> Types = TypesInit; return [=](const LegalityQuery &Query) { std::pair Match = {Query.Types[TypeIdx0], Query.Types[TypeIdx1]}; - return llvm::is_contained(std::move(Types), Match); + return llvm::is_contained(Types, Match); }; } @@ -56,7 +56,7 @@ LegalityPredicate LegalityPredicates::typeTupleInSet( return [=](const LegalityQuery &Query) { std::tuple Match = { Query.Types[TypeIdx0], Query.Types[TypeIdx1], Query.Types[TypeIdx2]}; - return llvm::is_contained(std::move(Types), Match); + return llvm::is_contained(Types, Match); }; } diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index df3e2a5daa3b3..2e355fa895a87 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -6824,7 +6824,7 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, continue; } const APInt &Val = cast(Op)->getAPIntValue(); - ScalarOps.push_back(SignExtendInReg(std::move(Val), OpVT)); + ScalarOps.push_back(SignExtendInReg(Val, OpVT)); } return getBuildVector(VT, DL, ScalarOps); }