Skip to content

Commit 12ad9c4

Browse files
Address comments
1 parent 1cee0ef commit 12ad9c4

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

llvm/utils/TableGen/AsmMatcherEmitter.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -619,14 +619,14 @@ struct MatchableInfo {
619619

620620
/// shouldBeMatchedBefore - Compare two matchables for ordering.
621621
bool shouldBeMatchedBefore(const MatchableInfo &RHS,
622-
const CodeGenTarget &Target) const {
622+
bool PreferSmallerInstructions) const {
623623
// The primary comparator is the instruction mnemonic.
624624
if (int Cmp = Mnemonic.compare_insensitive(RHS.Mnemonic))
625625
return Cmp == -1;
626626

627627
// (Optionally) Order by the resultant instuctions size.
628628
// eg. for ARM thumb instructions smaller encodings should be preferred.
629-
if (getPreferSmallerInstructions(Target) && ResInstSize != RHS.ResInstSize)
629+
if (PreferSmallerInstructions && ResInstSize != RHS.ResInstSize)
630630
return ResInstSize < RHS.ResInstSize;
631631

632632
if (AsmOperands.size() != RHS.AsmOperands.size())
@@ -668,7 +668,7 @@ struct MatchableInfo {
668668
/// ambiguously match the same set of operands as \p RHS (without being a
669669
/// strictly superior match).
670670
bool couldMatchAmbiguouslyWith(const MatchableInfo &RHS,
671-
const CodeGenTarget &Target) const {
671+
bool PreferSmallerInstructions) const {
672672
// The primary comparator is the instruction mnemonic.
673673
if (Mnemonic != RHS.Mnemonic)
674674
return false;
@@ -678,7 +678,7 @@ struct MatchableInfo {
678678
return false;
679679

680680
// The size of instruction is unambiguous.
681-
if (getPreferSmallerInstructions(Target) && ResInstSize != RHS.ResInstSize)
681+
if (PreferSmallerInstructions && ResInstSize != RHS.ResInstSize)
682682
return false;
683683

684684
// The number of operands is unambiguous.
@@ -3241,21 +3241,23 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
32413241
AsmMatcherInfo Info(AsmParser, Target, Records);
32423242
Info.buildInfo();
32433243

3244+
bool PreferSmallerInstructions = getPreferSmallerInstructions(Target);
32443245
// Sort the instruction table using the partial order on classes. We use
32453246
// stable_sort to ensure that ambiguous instructions are still
32463247
// deterministically ordered.
3247-
llvm::stable_sort(Info.Matchables,
3248-
[&Target](const std::unique_ptr<MatchableInfo> &a,
3249-
const std::unique_ptr<MatchableInfo> &b) {
3250-
return a->shouldBeMatchedBefore(*b, Target);
3251-
});
3248+
llvm::stable_sort(
3249+
Info.Matchables,
3250+
[PreferSmallerInstructions](const std::unique_ptr<MatchableInfo> &A,
3251+
const std::unique_ptr<MatchableInfo> &B) {
3252+
return A->shouldBeMatchedBefore(*B, PreferSmallerInstructions);
3253+
});
32523254

32533255
#ifdef EXPENSIVE_CHECKS
32543256
// Verify that the table is sorted and operator < works transitively.
32553257
for (auto I = Info.Matchables.begin(), E = Info.Matchables.end(); I != E;
32563258
++I) {
32573259
for (auto J = I; J != E; ++J) {
3258-
assert(!(*J)->shouldBeMatchedBefore(**I, Target));
3260+
assert(!(*J)->shouldBeMatchedBefore(**I, PreferSmallerInstructions));
32593261
}
32603262
}
32613263
#endif
@@ -3274,7 +3276,7 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
32743276
const MatchableInfo &A = **I;
32753277
const MatchableInfo &B = **J;
32763278

3277-
if (A.couldMatchAmbiguouslyWith(B, Target)) {
3279+
if (A.couldMatchAmbiguouslyWith(B, PreferSmallerInstructions)) {
32783280
errs() << "warning: ambiguous matchables:\n";
32793281
A.dump();
32803282
errs() << "\nis incomparable with:\n";

0 commit comments

Comments
 (0)