[PATCH] D150024: use ref to avoid copy in range for-loop
Wang, Xin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat May 6 01:40:20 PDT 2023
XinWang10 created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
XinWang10 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Use big obj copy in range for-loop will call copy constructor every time,
which can be avoided by use ref instead.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D150024
Files:
llvm/include/llvm/MC/MCParser/MCAsmParser.h
llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp
llvm/lib/CodeGen/MIRParser/MIRParser.cpp
llvm/lib/ObjectYAML/MachOEmitter.cpp
llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
Index: llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
===================================================================
--- llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
+++ llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
@@ -733,7 +733,7 @@
NewInstrID = SubBuilder.allocInstrID();
GIMatchTreeBuilder::LeafVec &NewLeaves = SubBuilder.getPossibleLeaves();
- for (const auto I : zip(NewLeaves, TraversedEdgesByNewLeaves)) {
+ for (const auto &I : zip(NewLeaves, TraversedEdgesByNewLeaves)) {
auto &Leaf = std::get<0>(I);
auto &TraversedEdgesForLeaf = std::get<1>(I);
GIMatchTreeInstrInfo *InstrInfo = Leaf.getInstrInfo(InstrID);
Index: llvm/lib/ObjectYAML/MachOEmitter.cpp
===================================================================
--- llvm/lib/ObjectYAML/MachOEmitter.cpp
+++ llvm/lib/ObjectYAML/MachOEmitter.cpp
@@ -426,7 +426,7 @@
void MachOWriter::writeBindOpcodes(
raw_ostream &OS, std::vector<MachOYAML::BindOpcode> &BindOpcodes) {
- for (auto Opcode : BindOpcodes) {
+ for (auto &Opcode : BindOpcodes) {
uint8_t OpByte = Opcode.Opcode | Opcode.Imm;
OS.write(reinterpret_cast<char *>(&OpByte), 1);
for (auto Data : Opcode.ULEBExtraData) {
Index: llvm/lib/CodeGen/MIRParser/MIRParser.cpp
===================================================================
--- llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+++ llvm/lib/CodeGen/MIRParser/MIRParser.cpp
@@ -392,7 +392,7 @@
MachineFunction &MF = PFS.MF;
SMDiagnostic Error;
const LLVMTargetMachine &TM = MF.getTarget();
- for (auto YamlCSInfo : YamlMF.CallSitesInfo) {
+ for (auto &YamlCSInfo : YamlMF.CallSitesInfo) {
yaml::CallSiteInfo::MachineInstrLoc MILoc = YamlCSInfo.CallLocation;
if (MILoc.BlockNum >= MF.size())
return error(Twine(MF.getName()) +
Index: llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp
===================================================================
--- llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp
+++ llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp
@@ -1312,7 +1312,7 @@
return;
auto TransRange = EntryValTransfers.equal_range(TRInst);
- for (auto TDPair : llvm::make_range(TransRange.first, TransRange.second)) {
+ for (auto &TDPair : llvm::make_range(TransRange.first, TransRange.second)) {
const VarLoc &EmittedEV = VarLocIDs[TDPair.second];
if (std::tie(EntryVL.Var, EntryVL.Locs[0].Value.RegNo, EntryVL.Expr) ==
std::tie(EmittedEV.Var, EmittedEV.Locs[0].Value.RegNo,
Index: llvm/include/llvm/MC/MCParser/MCAsmParser.h
===================================================================
--- llvm/include/llvm/MC/MCParser/MCAsmParser.h
+++ llvm/include/llvm/MC/MCParser/MCAsmParser.h
@@ -236,7 +236,7 @@
bool printPendingErrors() {
bool rv = !PendingErrors.empty();
- for (auto Err : PendingErrors) {
+ for (auto &Err : PendingErrors) {
printError(Err.Loc, Twine(Err.Msg), Err.Range);
}
PendingErrors.clear();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150024.520044.patch
Type: text/x-patch
Size: 2960 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230506/6f8ec251/attachment.bin>
More information about the llvm-commits
mailing list