[PATCH] D150024: use ref to avoid copy in range for-loop
Wang, Xin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun May 28 18:45:04 PDT 2023
XinWang10 added inline comments.
================
Comment at: llvm/include/llvm/MC/MCParser/MCAsmParser.h:239
bool rv = !PendingErrors.empty();
- for (auto Err : PendingErrors) {
+ for (auto &Err : PendingErrors) {
printError(Err.Loc, Twine(Err.Msg), Err.Range);
----------------
Every element here is type MCPendingError defined in MCAsmPaser.h, It contains 1 SMLoc(has 1 internal pointer as member), 1 SmallString, 1 SMRange(composed of 2 SMLoc).
```
struct MCPendingError {
SMLoc Loc;
SmallString<64> Msg;
SMRange Range;
};
```
```
SmallVector<MCPendingError, 0> PendingErrors;
```
This enumerated element has 4 pointers which is bigger than 64bit, I think it's better here to use ref.
================
Comment at: llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp:1315
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];
----------------
The enumerated type is InstToEntryLocMap, every element is a pair of MachineInstr * and LocIndex(composed of 2 uint32_t.
```
using InstToEntryLocMap = std::multimap<const MachineInstr *, LocIndex>;
```
================
Comment at: llvm/lib/CodeGen/MIRParser/MIRParser.cpp:395
const LLVMTargetMachine &TM = MF.getTarget();
- for (auto YamlCSInfo : YamlMF.CallSitesInfo) {
+ for (auto &YamlCSInfo : YamlMF.CallSitesInfo) {
yaml::CallSiteInfo::MachineInstrLoc MILoc = YamlCSInfo.CallLocation;
----------------
YamlMF.CallSitesInfo is type CallSiteInfoMap, defined in MachineFunction.h line 452.
```
struct ArgRegPair {
Register Reg;
uint16_t ArgNo;
ArgRegPair(Register R, unsigned Arg) : Reg(R), ArgNo(Arg) {
assert(Arg < (1 << 16) && "Arg out of range");
}
};
using CallSiteInfo = SmallVector<ArgRegPair, 1>;
...
using CallSiteInfoMap = DenseMap<const MachineInstr *, CallSiteInfo>;
```
Every element here is of type CallSiteInfo which contains a vector.
================
Comment at: llvm/lib/ObjectYAML/MachOEmitter.cpp:429
- for (auto Opcode : BindOpcodes) {
+ for (auto &Opcode : BindOpcodes) {
uint8_t OpByte = Opcode.Opcode | Opcode.Imm;
----------------
The Opcode here is type MachOYAML::BindOpcode, defined in MachOYAML.h line 98.
```
struct BindOpcode {
MachO::BindOpcode Opcode;
uint8_t Imm;
std::vector<yaml::Hex64> ULEBExtraData;
std::vector<int64_t> SLEBExtraData;
StringRef Symbol;
};
```
================
Comment at: llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp:736
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);
----------------
It enumerated NewLeaves which is type GIMatchTreeBuilder::LeafVec and TraversedEdgesByNewLeaves.
In GIMatchTree.h
```
using LeafVec = std::vector<GIMatchTreeBuilderLeafInfo>;
```
and contains to many elements.
```
class GIMatchTreeBuilderLeafInfo {
protected:
GIMatchTreeBuilder &Builder;
GIMatchTreeLeafInfo Info;
const GIMatchDag &MatchDag;
/// The association between GIMatchDagInstr* and GIMatchTreeInstrInfo.
/// The primary reason for this members existence is to allow the use of
/// InstrIDToInfo.lookup() since that requires that the value is
/// default-constructible.
DenseMap<const GIMatchDagInstr *, GIMatchTreeInstrInfo> InstrNodeToInfo;
/// The instruction information for a given ID in the context of this
/// particular leaf.
DenseMap<unsigned, GIMatchTreeInstrInfo *> InstrIDToInfo;
......
```
here I is a tuple composed of GIMatchTreeBuilderLeafInfo and BitVector, must be a big obj.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150024/new/
https://reviews.llvm.org/D150024
More information about the llvm-commits
mailing list