Skip to content

Commit 9efaf2f

Browse files
committed
[C++11] Use std::tie to simplify compare operators.
No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202751 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c3835cc commit 9efaf2f

File tree

8 files changed

+22
-54
lines changed

8 files changed

+22
-54
lines changed

include/llvm/CodeGen/LiveInterval.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ namespace llvm {
173173
}
174174

175175
bool operator<(const Segment &Other) const {
176-
return start < Other.start || (start == Other.start && end < Other.end);
176+
return std::tie(start, end) < std::tie(Other.start, Other.end);
177177
}
178178
bool operator==(const Segment &Other) const {
179179
return start == Other.start && end == Other.end;
@@ -552,8 +552,7 @@ namespace llvm {
552552
bool operator<(const LiveInterval& other) const {
553553
const SlotIndex &thisIndex = beginIndex();
554554
const SlotIndex &otherIndex = other.beginIndex();
555-
return thisIndex < otherIndex ||
556-
(thisIndex == otherIndex && reg < other.reg);
555+
return std::tie(thisIndex, reg) < std::tie(otherIndex, other.reg);
557556
}
558557

559558
void print(raw_ostream &OS) const;

include/llvm/CodeGen/SelectionDAGNodes.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class SDValue {
120120
return !operator==(O);
121121
}
122122
bool operator<(const SDValue &O) const {
123-
return Node < O.Node || (Node == O.Node && ResNo < O.ResNo);
123+
return std::tie(Node, ResNo) < std::tie(O.Node, O.ResNo);
124124
}
125125

126126
SDValue getValue(unsigned R) const {

include/llvm/Support/FileSystem.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ class UniqueID {
135135
}
136136
bool operator!=(const UniqueID &Other) const { return !(*this == Other); }
137137
bool operator<(const UniqueID &Other) const {
138-
return Device < Other.Device ||
139-
(Device == Other.Device && File < Other.File);
138+
return std::tie(Device, File) < std::tie(Other.Device, Other.File);
140139
}
141140
uint64_t getDevice() const { return Device; }
142141
uint64_t getFile() const { return File; }

lib/CodeGen/RegAllocGreedy.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,8 @@ class RAGreedy : public MachineFunctionPass,
190190
void setBrokenHints(unsigned NHints) { BrokenHints = NHints; }
191191

192192
bool operator<(const EvictionCost &O) const {
193-
if (BrokenHints != O.BrokenHints)
194-
return BrokenHints < O.BrokenHints;
195-
return MaxWeight < O.MaxWeight;
193+
return std::tie(BrokenHints, MaxWeight) <
194+
std::tie(O.BrokenHints, O.MaxWeight);
196195
}
197196
};
198197

lib/IR/ConstantsContext.h

+8-19
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,10 @@ struct ExprMapKeyType {
334334
this->indices == that.indices;
335335
}
336336
bool operator<(const ExprMapKeyType & that) const {
337-
if (this->opcode != that.opcode) return this->opcode < that.opcode;
338-
if (this->operands != that.operands) return this->operands < that.operands;
339-
if (this->subclassdata != that.subclassdata)
340-
return this->subclassdata < that.subclassdata;
341-
if (this->subclassoptionaldata != that.subclassoptionaldata)
342-
return this->subclassoptionaldata < that.subclassoptionaldata;
343-
if (this->indices != that.indices) return this->indices < that.indices;
344-
return false;
337+
return std::tie(opcode, operands, subclassdata, subclassoptionaldata,
338+
indices) <
339+
std::tie(that.opcode, that.operands, that.subclassdata,
340+
that.subclassoptionaldata, that.indices);
345341
}
346342

347343
bool operator!=(const ExprMapKeyType& that) const {
@@ -369,17 +365,10 @@ struct InlineAsmKeyType {
369365
this->asm_dialect == that.asm_dialect;
370366
}
371367
bool operator<(const InlineAsmKeyType& that) const {
372-
if (this->asm_string != that.asm_string)
373-
return this->asm_string < that.asm_string;
374-
if (this->constraints != that.constraints)
375-
return this->constraints < that.constraints;
376-
if (this->has_side_effects != that.has_side_effects)
377-
return this->has_side_effects < that.has_side_effects;
378-
if (this->is_align_stack != that.is_align_stack)
379-
return this->is_align_stack < that.is_align_stack;
380-
if (this->asm_dialect != that.asm_dialect)
381-
return this->asm_dialect < that.asm_dialect;
382-
return false;
368+
return std::tie(asm_string, constraints, has_side_effects, is_align_stack,
369+
asm_dialect) <
370+
std::tie(that.asm_string, that.constraints, that.has_side_effects,
371+
that.is_align_stack, that.asm_dialect);
383372
}
384373

385374
bool operator!=(const InlineAsmKeyType& that) const {

lib/Transforms/IPO/DeadArgumentElimination.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,7 @@ namespace {
6262

6363
/// Make RetOrArg comparable, so we can put it into a map.
6464
bool operator<(const RetOrArg &O) const {
65-
if (F != O.F)
66-
return F < O.F;
67-
else if (Idx != O.Idx)
68-
return Idx < O.Idx;
69-
else
70-
return IsArg < O.IsArg;
65+
return std::tie(F, Idx, IsArg) < std::tie(O.F, O.Idx, O.IsArg);
7166
}
7267

7368
/// Make RetOrArg comparable, so we can easily iterate the multimap.

lib/Transforms/Scalar/LoopStrengthReduce.cpp

+5-15
Original file line numberDiff line numberDiff line change
@@ -979,21 +979,11 @@ void Cost::Lose() {
979979

980980
/// operator< - Choose the lower cost.
981981
bool Cost::operator<(const Cost &Other) const {
982-
if (NumRegs != Other.NumRegs)
983-
return NumRegs < Other.NumRegs;
984-
if (AddRecCost != Other.AddRecCost)
985-
return AddRecCost < Other.AddRecCost;
986-
if (NumIVMuls != Other.NumIVMuls)
987-
return NumIVMuls < Other.NumIVMuls;
988-
if (NumBaseAdds != Other.NumBaseAdds)
989-
return NumBaseAdds < Other.NumBaseAdds;
990-
if (ScaleCost != Other.ScaleCost)
991-
return ScaleCost < Other.ScaleCost;
992-
if (ImmCost != Other.ImmCost)
993-
return ImmCost < Other.ImmCost;
994-
if (SetupCost != Other.SetupCost)
995-
return SetupCost < Other.SetupCost;
996-
return false;
982+
return std::tie(NumRegs, AddRecCost, NumIVMuls, NumBaseAdds, ScaleCost,
983+
ImmCost, SetupCost) <
984+
std::tie(Other.NumRegs, Other.AddRecCost, Other.NumIVMuls,
985+
Other.NumBaseAdds, Other.ScaleCost, Other.ImmCost,
986+
Other.SetupCost);
997987
}
998988

999989
void Cost::print(raw_ostream &OS) const {

utils/TableGen/CodeGenRegisters.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -782,11 +782,8 @@ namespace llvm {
782782
bool CodeGenRegisterClass::Key::
783783
operator<(const CodeGenRegisterClass::Key &B) const {
784784
assert(Members && B.Members);
785-
if (*Members != *B.Members)
786-
return *Members < *B.Members;
787-
if (SpillSize != B.SpillSize)
788-
return SpillSize < B.SpillSize;
789-
return SpillAlignment < B.SpillAlignment;
785+
return std::tie(*Members, SpillSize, SpillAlignment) <
786+
std::tie(*B.Members, B.SpillSize, B.SpillAlignment);
790787
}
791788

792789
// Returns true if RC is a strict subclass.

0 commit comments

Comments
 (0)