summaryrefslogtreecommitdiffstats
path: root/llvm/utils/TableGen
diff options
context:
space:
mode:
authorAndrew Ng <anng.sw@gmail.com>2019-02-26 18:50:49 +0000
committerAndrew Ng <anng.sw@gmail.com>2019-02-26 18:50:49 +0000
commitf38b0053211886f130b5a0c4f1c312a0fff519b6 (patch)
tree36d323da6dbe7a60335ad6b673a5f855fe9c92d2 /llvm/utils/TableGen
parent7557afa000527fa3d8d3da58015b35028b6c370a (diff)
downloadbcm5719-llvm-f38b0053211886f130b5a0c4f1c312a0fff519b6.tar.gz
bcm5719-llvm-f38b0053211886f130b5a0c4f1c312a0fff519b6.zip
[TableGen] Make OpcodeMappings sort comparator deterministic NFCI
The previous sort comparator was not deterministic, i.e. in some situations it would be possible for lhs < rhs && rhs < lhs. This was discovered by an STL assertion in a Windows debug build of llvm-tblgen. Differential Revision: https://reviews.llvm.org/D58687 llvm-svn: 354910
Diffstat (limited to 'llvm/utils/TableGen')
-rw-r--r--llvm/utils/TableGen/CodeGenSchedule.cpp34
1 files changed, 16 insertions, 18 deletions
diff --git a/llvm/utils/TableGen/CodeGenSchedule.cpp b/llvm/utils/TableGen/CodeGenSchedule.cpp
index 4abe1227300..943e7efa760 100644
--- a/llvm/utils/TableGen/CodeGenSchedule.cpp
+++ b/llvm/utils/TableGen/CodeGenSchedule.cpp
@@ -368,24 +368,22 @@ processSTIPredicate(STIPredicateFunction &Fn,
[&](const OpcodeMapPair &Lhs, const OpcodeMapPair &Rhs) {
unsigned LhsIdx = Opcode2Index[Lhs.first];
unsigned RhsIdx = Opcode2Index[Rhs.first];
- std::pair<APInt, APInt> &LhsMasks = OpcodeMasks[LhsIdx];
- std::pair<APInt, APInt> &RhsMasks = OpcodeMasks[RhsIdx];
-
- if (LhsMasks.first != RhsMasks.first) {
- if (LhsMasks.first.countPopulation() <
- RhsMasks.first.countPopulation())
- return true;
- return LhsMasks.first.countLeadingZeros() >
- RhsMasks.first.countLeadingZeros();
- }
-
- if (LhsMasks.second != RhsMasks.second) {
- if (LhsMasks.second.countPopulation() <
- RhsMasks.second.countPopulation())
- return true;
- return LhsMasks.second.countLeadingZeros() >
- RhsMasks.second.countLeadingZeros();
- }
+ const std::pair<APInt, APInt> &LhsMasks = OpcodeMasks[LhsIdx];
+ const std::pair<APInt, APInt> &RhsMasks = OpcodeMasks[RhsIdx];
+
+ auto LessThan = [](const APInt &Lhs, const APInt &Rhs) {
+ unsigned LhsCountPopulation = Lhs.countPopulation();
+ unsigned RhsCountPopulation = Rhs.countPopulation();
+ return ((LhsCountPopulation < RhsCountPopulation) ||
+ ((LhsCountPopulation == RhsCountPopulation) &&
+ (Lhs.countLeadingZeros() > Rhs.countLeadingZeros())));
+ };
+
+ if (LhsMasks.first != RhsMasks.first)
+ return LessThan(LhsMasks.first, RhsMasks.first);
+
+ if (LhsMasks.second != RhsMasks.second)
+ return LessThan(LhsMasks.second, RhsMasks.second);
return LhsIdx < RhsIdx;
});
OpenPOWER on IntegriCloud