[llvm] [NFC] Fix line endings for a OptionStrCmp.h and .td test file (PR #109805)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 24 07:33:19 PDT 2024


https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/109805

Fix line endings to Unix style for a few files.

>From 4da3e213b25d1313d3841ad465b520d0e2438e84 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Mon, 23 Sep 2024 20:42:17 -0700
Subject: [PATCH 1/2] [NFC][TableGen] Adopt scaled indent in PredicateExpander

---
 llvm/include/llvm/Support/raw_ostream.h       |  24 ++++
 llvm/unittests/Support/raw_ostream_test.cpp   |  20 ++++
 .../TableGen/Common/PredicateExpander.cpp     | 107 +++++++-----------
 .../utils/TableGen/Common/PredicateExpander.h |  19 ++--
 llvm/utils/TableGen/InstrInfoEmitter.cpp      |   4 +-
 .../TableGen/MacroFusionPredicatorEmitter.cpp |   4 +-
 llvm/utils/TableGen/SubtargetEmitter.cpp      |  20 ++--
 7 files changed, 106 insertions(+), 92 deletions(-)

diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index c2f2299ed96455..d3b411590e7fd7 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -797,6 +797,30 @@ struct indent {
     assert(NumIndents >= N && "Indentation undeflow");
     return indent(NumIndents - N, Scale);
   }
+  indent &operator++() { // Prefix ++.
+    ++NumIndents;
+    return *this;
+  }
+  indent operator++(int) { // Postfix ++.
+    indent Old = *this;
+    ++NumIndents;
+    return Old;
+  }
+  indent &operator--() { // Prefix --.
+    assert(NumIndents >= 1);
+    --NumIndents;
+    return *this;
+  }
+  indent operator--(int) { // Postfix --.
+    indent Old = *this;
+    assert(NumIndents >= 1);
+    --NumIndents;
+    return Old;
+  }
+  indent &operator=(unsigned N) {
+    NumIndents = N;
+    return *this;
+  }
 };
 
 inline raw_ostream &operator<<(raw_ostream &OS, const indent &Indent) {
diff --git a/llvm/unittests/Support/raw_ostream_test.cpp b/llvm/unittests/Support/raw_ostream_test.cpp
index a35edd61685296..fbeff37d26a354 100644
--- a/llvm/unittests/Support/raw_ostream_test.cpp
+++ b/llvm/unittests/Support/raw_ostream_test.cpp
@@ -198,6 +198,26 @@ TEST(raw_ostreamTest, Indent) {
   EXPECT_EQ(Spaces(10), printToString(Scaled));
   Scaled -= 1;
   EXPECT_EQ(Spaces(8), printToString(Scaled));
+
+  // Operators.
+  Indent = 10;
+  EXPECT_EQ(Spaces(10), printToString(Indent));
+
+  indent Temp = Indent++;
+  EXPECT_EQ(Spaces(11), printToString(Indent));
+  EXPECT_EQ(Spaces(10), printToString(Temp));
+
+  Temp = Indent--;
+  EXPECT_EQ(Spaces(10), printToString(Indent));
+  EXPECT_EQ(Spaces(11), printToString(Temp));
+
+  Temp = ++Indent;
+  EXPECT_EQ(Spaces(11), printToString(Indent));
+  EXPECT_EQ(Spaces(11), printToString(Temp));
+
+  Temp = --Indent;
+  EXPECT_EQ(Spaces(10), printToString(Indent));
+  EXPECT_EQ(Spaces(10), printToString(Temp));
 }
 
 TEST(raw_ostreamTest, FormatHex) {  
diff --git a/llvm/utils/TableGen/Common/PredicateExpander.cpp b/llvm/utils/TableGen/Common/PredicateExpander.cpp
index 2afaa8cc21aa66..314e563ba90bb4 100644
--- a/llvm/utils/TableGen/Common/PredicateExpander.cpp
+++ b/llvm/utils/TableGen/Common/PredicateExpander.cpp
@@ -153,10 +153,9 @@ void PredicateExpander::expandCheckOpcode(raw_ostream &OS,
   }
 
   OS << '(';
-  increaseIndentLevel();
+  ++Indent;
   for (const Record *Rec : Opcodes) {
-    OS << '\n';
-    OS.indent(getIndentLevel() * 2);
+    OS << '\n' << Indent;
     if (!First)
       OS << (shouldNegate() ? "&& " : "|| ");
 
@@ -164,10 +163,8 @@ void PredicateExpander::expandCheckOpcode(raw_ostream &OS,
     First = false;
   }
 
-  OS << '\n';
-  decreaseIndentLevel();
-  OS.indent(getIndentLevel() * 2);
-  OS << ')';
+  --Indent;
+  OS << '\n' << Indent << ')';
 }
 
 void PredicateExpander::expandCheckPseudo(raw_ostream &OS,
@@ -187,22 +184,19 @@ void PredicateExpander::expandPredicateSequence(
   // Okay, there is more than one predicate in the set.
   bool First = true;
   OS << (shouldNegate() ? "!(" : "(");
-  increaseIndentLevel();
+  ++Indent;
 
   bool OldValue = shouldNegate();
   setNegatePredicate(false);
   for (const Record *Rec : Sequence) {
-    OS << '\n';
-    OS.indent(getIndentLevel() * 2);
+    OS << '\n' << Indent;
     if (!First)
       OS << (IsCheckAll ? "&& " : "|| ");
     expandPredicate(OS, Rec);
     First = false;
   }
-  OS << '\n';
-  decreaseIndentLevel();
-  OS.indent(getIndentLevel() * 2);
-  OS << ')';
+  --Indent;
+  OS << '\n' << Indent << ')';
   setNegatePredicate(OldValue);
 }
 
@@ -269,15 +263,14 @@ void PredicateExpander::expandReturnStatement(raw_ostream &OS,
 void PredicateExpander::expandOpcodeSwitchCase(raw_ostream &OS,
                                                const Record *Rec) {
   for (const Record *Opcode : Rec->getValueAsListOfDefs("Opcodes")) {
-    OS.indent(getIndentLevel() * 2);
-    OS << "case " << Opcode->getValueAsString("Namespace")
+    OS << Indent << "case " << Opcode->getValueAsString("Namespace")
        << "::" << Opcode->getName() << ":\n";
   }
 
-  increaseIndentLevel();
-  OS.indent(getIndentLevel() * 2);
+  ++Indent;
+  OS << Indent;
   expandStatement(OS, Rec->getValueAsDef("CaseStmt"));
-  decreaseIndentLevel();
+  --Indent;
 }
 
 void PredicateExpander::expandOpcodeSwitchStatement(
@@ -292,17 +285,12 @@ void PredicateExpander::expandOpcodeSwitchStatement(
   }
 
   // Expand the default case.
-  SS.indent(getIndentLevel() * 2);
-  SS << "default:\n";
+  SS << Indent << "default:\n";
 
-  increaseIndentLevel();
-  SS.indent(getIndentLevel() * 2);
+  ++Indent;
+  SS << Indent;
   expandStatement(SS, Default);
-  decreaseIndentLevel();
-  SS << '\n';
-
-  SS.indent(getIndentLevel() * 2);
-  SS << "} // end of switch-stmt";
+  SS << '\n' << Indent << "} // end of switch-stmt";
   OS << Buffer;
 }
 
@@ -436,8 +424,7 @@ void STIPredicateExpander::expandHeader(raw_ostream &OS,
   const Record *Rec = Fn.getDeclaration();
   StringRef FunctionName = Rec->getValueAsString("Name");
 
-  OS.indent(getIndentLevel() * 2);
-  OS << "bool ";
+  OS << Indent << "bool ";
   if (shouldExpandDefinition())
     OS << getClassPrefix() << "::";
   OS << FunctionName << "(";
@@ -463,26 +450,22 @@ void STIPredicateExpander::expandPrologue(raw_ostream &OS,
   bool UpdatesOpcodeMask =
       Fn.getDeclaration()->getValueAsBit("UpdatesOpcodeMask");
 
-  increaseIndentLevel();
-  unsigned IndentLevel = getIndentLevel();
+  ++Indent;
   for (const Record *Delegate :
        Fn.getDeclaration()->getValueAsListOfDefs("Delegates")) {
-    OS.indent(IndentLevel * 2);
-    OS << "if (" << Delegate->getValueAsString("Name") << "(MI";
+    OS << Indent << "if (" << Delegate->getValueAsString("Name") << "(MI";
     if (UpdatesOpcodeMask)
       OS << ", Mask";
     if (shouldExpandForMC())
       OS << ", ProcessorID";
     OS << "))\n";
-    OS.indent((1 + IndentLevel) * 2);
-    OS << "return true;\n\n";
+    OS << Indent + 1 << "return true;\n\n";
   }
 
   if (shouldExpandForMC())
     return;
 
-  OS.indent(IndentLevel * 2);
-  OS << "unsigned ProcessorID = getSchedModel().getProcessorID();\n";
+  OS << Indent << "unsigned ProcessorID = getSchedModel().getProcessorID();\n";
 }
 
 void STIPredicateExpander::expandOpcodeGroup(raw_ostream &OS,
@@ -497,8 +480,7 @@ void STIPredicateExpander::expandOpcodeGroup(raw_ostream &OS,
         continue;
 
       if (FirstProcID) {
-        OS.indent(getIndentLevel() * 2);
-        OS << "if (ProcessorID == " << I;
+        OS << Indent << "if (ProcessorID == " << I;
       } else {
         OS << " || ProcessorID == " << I;
       }
@@ -507,21 +489,20 @@ void STIPredicateExpander::expandOpcodeGroup(raw_ostream &OS,
 
     OS << ") {\n";
 
-    increaseIndentLevel();
-    OS.indent(getIndentLevel() * 2);
+    ++Indent;
+    OS << Indent;
     if (ShouldUpdateOpcodeMask) {
       if (PI.OperandMask.isZero())
         OS << "Mask.clearAllBits();\n";
       else
         OS << "Mask = " << PI.OperandMask << ";\n";
-      OS.indent(getIndentLevel() * 2);
+      OS << Indent;
     }
     OS << "return ";
     expandPredicate(OS, PI.Predicate);
     OS << ";\n";
-    decreaseIndentLevel();
-    OS.indent(getIndentLevel() * 2);
-    OS << "}\n";
+    --Indent;
+    OS << Indent << "}\n";
   }
 }
 
@@ -530,46 +511,38 @@ void STIPredicateExpander::expandBody(raw_ostream &OS,
   bool UpdatesOpcodeMask =
       Fn.getDeclaration()->getValueAsBit("UpdatesOpcodeMask");
 
-  unsigned IndentLevel = getIndentLevel();
-  OS.indent(IndentLevel * 2);
-  OS << "switch(MI" << (isByRef() ? "." : "->") << "getOpcode()) {\n";
-  OS.indent(IndentLevel * 2);
-  OS << "default:\n";
-  OS.indent(IndentLevel * 2);
-  OS << "  break;";
+  OS << Indent << "switch(MI" << (isByRef() ? "." : "->") << "getOpcode()) {\n";
+  OS << Indent << "default:\n";
+  OS << Indent << "  break;";
 
   for (const OpcodeGroup &Group : Fn.getGroups()) {
     for (const Record *Opcode : Group.getOpcodes()) {
-      OS << '\n';
-      OS.indent(IndentLevel * 2);
-      OS << "case " << getTargetName() << "::" << Opcode->getName() << ":";
+      OS << '\n'
+         << Indent << "case " << getTargetName() << "::" << Opcode->getName()
+         << ":";
     }
 
     OS << '\n';
-    increaseIndentLevel();
+    ++Indent;
     expandOpcodeGroup(OS, Group, UpdatesOpcodeMask);
 
-    OS.indent(getIndentLevel() * 2);
-    OS << "break;\n";
-    decreaseIndentLevel();
+    OS << Indent << "break;\n";
+    --Indent;
   }
 
-  OS.indent(IndentLevel * 2);
-  OS << "}\n";
+  OS << Indent << "}\n";
 }
 
 void STIPredicateExpander::expandEpilogue(raw_ostream &OS,
                                           const STIPredicateFunction &Fn) {
-  OS << '\n';
-  OS.indent(getIndentLevel() * 2);
+  OS << '\n' << Indent;
   OS << "return ";
   expandPredicate(OS, Fn.getDefaultReturnPredicate());
   OS << ";\n";
 
-  decreaseIndentLevel();
-  OS.indent(getIndentLevel() * 2);
+  --Indent;
   StringRef FunctionName = Fn.getDeclaration()->getValueAsString("Name");
-  OS << "} // " << ClassPrefix << "::" << FunctionName << "\n\n";
+  OS << Indent << "} // " << ClassPrefix << "::" << FunctionName << "\n\n";
 }
 
 void STIPredicateExpander::expandSTIPredicate(raw_ostream &OS,
diff --git a/llvm/utils/TableGen/Common/PredicateExpander.h b/llvm/utils/TableGen/Common/PredicateExpander.h
index c0cd69e3cb1f85..0c3a8718a473f1 100644
--- a/llvm/utils/TableGen/Common/PredicateExpander.h
+++ b/llvm/utils/TableGen/Common/PredicateExpander.h
@@ -18,39 +18,38 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
 
 namespace llvm {
 
-class raw_ostream;
 class Record;
 
 class PredicateExpander {
   bool EmitCallsByRef;
   bool NegatePredicate;
   bool ExpandForMC;
-  unsigned IndentLevel;
   StringRef TargetName;
 
   PredicateExpander(const PredicateExpander &) = delete;
   PredicateExpander &operator=(const PredicateExpander &) = delete;
 
+protected:
+  indent Indent;
+
 public:
-  PredicateExpander(StringRef Target)
+  explicit PredicateExpander(StringRef Target, unsigned Indent = 1)
       : EmitCallsByRef(true), NegatePredicate(false), ExpandForMC(false),
-        IndentLevel(1U), TargetName(Target) {}
+        TargetName(Target), Indent(Indent, 2) {}
   bool isByRef() const { return EmitCallsByRef; }
   bool shouldNegate() const { return NegatePredicate; }
   bool shouldExpandForMC() const { return ExpandForMC; }
-  unsigned getIndentLevel() const { return IndentLevel; }
+  indent &getIndent() { return Indent; }
   StringRef getTargetName() const { return TargetName; }
 
   void setByRef(bool Value) { EmitCallsByRef = Value; }
   void flipNegatePredicate() { NegatePredicate = !NegatePredicate; }
   void setNegatePredicate(bool Value) { NegatePredicate = Value; }
   void setExpandForMC(bool Value) { ExpandForMC = Value; }
-  void setIndentLevel(unsigned Level) { IndentLevel = Level; }
-  void increaseIndentLevel() { ++IndentLevel; }
-  void decreaseIndentLevel() { --IndentLevel; }
 
   void expandTrue(raw_ostream &OS);
   void expandFalse(raw_ostream &OS);
@@ -116,8 +115,8 @@ class STIPredicateExpander : public PredicateExpander {
   void expandEpilogue(raw_ostream &OS, const STIPredicateFunction &Fn);
 
 public:
-  STIPredicateExpander(StringRef Target)
-      : PredicateExpander(Target), ExpandDefinition(false) {}
+  explicit STIPredicateExpander(StringRef Target, unsigned Indent = 1)
+      : PredicateExpander(Target, Indent), ExpandDefinition(false) {}
 
   bool shouldExpandDefinition() const { return ExpandDefinition; }
   StringRef getClassPrefix() const { return ClassPrefix; }
diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp
index cc5ef49385bb86..46605095ba85f8 100644
--- a/llvm/utils/TableGen/InstrInfoEmitter.cpp
+++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp
@@ -711,7 +711,7 @@ void InstrInfoEmitter::emitMCIIHelperMethods(raw_ostream &OS,
     OS << "bool " << Rec->getValueAsString("FunctionName");
     OS << "(const MCInst &MI) {\n";
 
-    OS.indent(PE.getIndentLevel() * 2);
+    OS << PE.getIndent();
     PE.expandStatement(OS, Rec->getValueAsDef("Body"));
     OS << "\n}\n\n";
   }
@@ -914,7 +914,7 @@ void InstrInfoEmitter::emitTIIHelperMethods(raw_ostream &OS,
     }
 
     OS << " {\n";
-    OS.indent(PE.getIndentLevel() * 2);
+    OS << PE.getIndent();
     PE.expandStatement(OS, Rec->getValueAsDef("Body"));
     OS << "\n}\n\n";
   }
diff --git a/llvm/utils/TableGen/MacroFusionPredicatorEmitter.cpp b/llvm/utils/TableGen/MacroFusionPredicatorEmitter.cpp
index c4f238b67476a7..6ca2fea41230b8 100644
--- a/llvm/utils/TableGen/MacroFusionPredicatorEmitter.cpp
+++ b/llvm/utils/TableGen/MacroFusionPredicatorEmitter.cpp
@@ -160,7 +160,7 @@ void MacroFusionPredicatorEmitter::emitFirstPredicate(const Record *Predicate,
     OS.indent(4) << "const MachineInstr *MI = FirstMI;\n";
     OS.indent(4) << "if (";
     PE.setNegatePredicate(true);
-    PE.setIndentLevel(3);
+    PE.getIndent() = 3;
     PE.expandPredicate(OS, Predicate->getValueAsDef("Predicate"));
     OS << ")\n";
     OS.indent(4) << "  return false;\n";
@@ -181,7 +181,7 @@ void MacroFusionPredicatorEmitter::emitSecondPredicate(const Record *Predicate,
     OS.indent(4) << "const MachineInstr *MI = &SecondMI;\n";
     OS.indent(4) << "if (";
     PE.setNegatePredicate(true);
-    PE.setIndentLevel(3);
+    PE.getIndent() = 3;
     PE.expandPredicate(OS, Predicate->getValueAsDef("Predicate"));
     OS << ")\n";
     OS.indent(4) << "  return false;\n";
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index 78d80ff82d6a4f..376475403f4e35 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -1576,13 +1576,13 @@ static void emitPredicates(const CodeGenSchedTransition &T,
   unsigned NumNonTruePreds =
       T.PredTerm.size() - count_if(T.PredTerm, isTruePredicate);
 
-  SS.indent(PE.getIndentLevel() * 2);
+  SS << PE.getIndent();
 
   if (NumNonTruePreds) {
     bool FirstNonTruePredicate = true;
     SS << "if (";
 
-    PE.setIndentLevel(PE.getIndentLevel() + 2);
+    PE.getIndent() += 2;
 
     for (const Record *Rec : T.PredTerm) {
       // Skip predicates that evaluate to "true".
@@ -1593,7 +1593,7 @@ static void emitPredicates(const CodeGenSchedTransition &T,
         FirstNonTruePredicate = false;
       } else {
         SS << "\n";
-        SS.indent(PE.getIndentLevel() * 2);
+        SS << PE.getIndent();
         SS << "&& ";
       }
 
@@ -1610,9 +1610,9 @@ static void emitPredicates(const CodeGenSchedTransition &T,
     }
 
     SS << ")\n"; // end of if-stmt
-    PE.decreaseIndentLevel();
-    SS.indent(PE.getIndentLevel() * 2);
-    PE.decreaseIndentLevel();
+    PE.getIndent()--;
+    SS << PE.getIndent();
+    PE.getIndent()--;
   }
 
   SS << "return " << T.ToClassIdx << "; // " << SC.Name << '\n';
@@ -1736,7 +1736,7 @@ void SubtargetEmitter::emitSchedModelHelpersImpl(
           FinalT = &T;
           continue;
         }
-        PE.setIndentLevel(3);
+        PE.getIndent() = 3;
         emitPredicates(T, SchedModels.getSchedClass(T.ToClassIdx), PE, OS);
       }
       if (FinalT)
@@ -1780,11 +1780,10 @@ void SubtargetEmitter::EmitSchedModelHelpers(const std::string &ClassName,
      << "::resolveVariantSchedClassImpl(SchedClass, MI, MCII, CPUID);\n"
      << "} // " << ClassName << "::resolveVariantSchedClass\n\n";
 
-  STIPredicateExpander PE(Target);
+  STIPredicateExpander PE(Target, /*Indent=*/0);
   PE.setClassPrefix(ClassName);
   PE.setExpandDefinition(true);
   PE.setByRef(false);
-  PE.setIndentLevel(0);
 
   for (const STIPredicateFunction &Fn : SchedModels.getSTIPredicates())
     PE.expandSTIPredicate(OS, Fn);
@@ -1962,7 +1961,7 @@ void SubtargetEmitter::EmitMCInstrAnalysisPredicateFunctions(raw_ostream &OS) {
   OS << "\n#ifdef GET_STIPREDICATE_DECLS_FOR_MC_ANALYSIS\n";
   OS << "#undef GET_STIPREDICATE_DECLS_FOR_MC_ANALYSIS\n\n";
 
-  STIPredicateExpander PE(Target);
+  STIPredicateExpander PE(Target, /*Indent=*/0);
   PE.setExpandForMC(true);
   PE.setByRef(true);
   for (const STIPredicateFunction &Fn : SchedModels.getSTIPredicates())
@@ -1976,7 +1975,6 @@ void SubtargetEmitter::EmitMCInstrAnalysisPredicateFunctions(raw_ostream &OS) {
   std::string ClassPrefix = Target + "MCInstrAnalysis";
   PE.setExpandDefinition(true);
   PE.setClassPrefix(ClassPrefix);
-  PE.setIndentLevel(0);
   for (const STIPredicateFunction &Fn : SchedModels.getSTIPredicates())
     PE.expandSTIPredicate(OS, Fn);
 

>From d6fd1d496aa4327e7a5d5ddf9143506feb8aeb6a Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Tue, 24 Sep 2024 07:31:14 -0700
Subject: [PATCH 2/2] [NFC] Fix line endings for a OptionStrCmp.h and .td test
 file

---
 llvm/include/llvm/Support/OptionStrCmp.h | 64 ++++++++++++------------
 llvm/test/TableGen/listflatten-error.td  | 12 ++---
 llvm/test/TableGen/listflatten.td        | 64 ++++++++++++------------
 3 files changed, 70 insertions(+), 70 deletions(-)

diff --git a/llvm/include/llvm/Support/OptionStrCmp.h b/llvm/include/llvm/Support/OptionStrCmp.h
index d417fe675e292d..f3d3c2adb902f3 100644
--- a/llvm/include/llvm/Support/OptionStrCmp.h
+++ b/llvm/include/llvm/Support/OptionStrCmp.h
@@ -1,32 +1,32 @@
-//===- OptionStrCmp.h - Option String Comparison ----------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SUPPORT_OPTIONSTRCMP_H
-#define LLVM_SUPPORT_OPTIONSTRCMP_H
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/StringRef.h"
-
-namespace llvm {
-
-// Comparison function for Option strings (option names & prefixes).
-// The ordering is *almost* case-insensitive lexicographic, with an exception.
-// '\0' comes at the end of the alphabet instead of the beginning (thus options
-// precede any other options which prefix them). Additionally, if two options
-// are identical ignoring case, they are ordered according to case sensitive
-// ordering if `FallbackCaseSensitive` is true.
-int StrCmpOptionName(StringRef A, StringRef B,
-                     bool FallbackCaseSensitive = true);
-
-// Comparison function for Option prefixes.
-int StrCmpOptionPrefixes(ArrayRef<StringRef> APrefixes,
-                         ArrayRef<StringRef> BPrefixes);
-
-} // namespace llvm
-
-#endif // LLVM_SUPPORT_OPTIONSTRCMP_H
+//===- OptionStrCmp.h - Option String Comparison ----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_OPTIONSTRCMP_H
+#define LLVM_SUPPORT_OPTIONSTRCMP_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace llvm {
+
+// Comparison function for Option strings (option names & prefixes).
+// The ordering is *almost* case-insensitive lexicographic, with an exception.
+// '\0' comes at the end of the alphabet instead of the beginning (thus options
+// precede any other options which prefix them). Additionally, if two options
+// are identical ignoring case, they are ordered according to case sensitive
+// ordering if `FallbackCaseSensitive` is true.
+int StrCmpOptionName(StringRef A, StringRef B,
+                     bool FallbackCaseSensitive = true);
+
+// Comparison function for Option prefixes.
+int StrCmpOptionPrefixes(ArrayRef<StringRef> APrefixes,
+                         ArrayRef<StringRef> BPrefixes);
+
+} // namespace llvm
+
+#endif // LLVM_SUPPORT_OPTIONSTRCMP_H
diff --git a/llvm/test/TableGen/listflatten-error.td b/llvm/test/TableGen/listflatten-error.td
index 56062420982a11..2f13356b6792f2 100644
--- a/llvm/test/TableGen/listflatten-error.td
+++ b/llvm/test/TableGen/listflatten-error.td
@@ -1,6 +1,6 @@
-// RUN: not llvm-tblgen %s 2>&1 | FileCheck %s  -DFILE=%s
-
-// CHECK: [[FILE]]:[[@LINE+2]]:33: error: expected list type argument in unary operator
-class Flatten<int A> {
-    list<int> F = !listflatten(A);
-}
+// RUN: not llvm-tblgen %s 2>&1 | FileCheck %s  -DFILE=%s
+
+// CHECK: [[FILE]]:[[@LINE+2]]:33: error: expected list type argument in unary operator
+class Flatten<int A> {
+    list<int> F = !listflatten(A);
+}
diff --git a/llvm/test/TableGen/listflatten.td b/llvm/test/TableGen/listflatten.td
index bc9b1c71ea88d7..a76ac21c4ad84e 100644
--- a/llvm/test/TableGen/listflatten.td
+++ b/llvm/test/TableGen/listflatten.td
@@ -1,32 +1,32 @@
-// RUN: llvm-tblgen %s | FileCheck %s
-
-class Flatten<list<int> A, list<int> B> {
-    list<int> Flat1 = !listflatten([A, B, [6], [7, 8]]);
-
-    list<list<int>> X = [A, B];
-    list<int> Flat2 = !listflatten(!listconcat(X, [[7]]));
-
-    // Generate a nested list of integers.
-    list<int> Y0 = [1, 2, 3, 4];
-    list<list<int>> Y1 = !foreach(elem, Y0, [elem]);
-    list<list<list<int>>> Y2 = !foreach(elem, Y1, [elem]);
-    list<list<list<list<int>>>> Y3 = !foreach(elem, Y2, [elem]);
-
-    // Flatten it completely.
-    list<int> Flat3=!listflatten(!listflatten(!listflatten(Y3)));
-
-    // Flatten it partially.
-    list<list<list<int>>> Flat4 = !listflatten(Y3);
-    list<list<int>> Flat5 = !listflatten(!listflatten(Y3));
-
-    // Test NOP flattening.
-    list<string> Flat6 = !listflatten(["a", "b"]);
-}
-
-// CHECK: list<int> Flat1 = [1, 2, 3, 4, 5, 6, 7, 8];
-// CHECK: list<int> Flat2 = [1, 2, 3, 4, 5, 7];
-// CHECK: list<int> Flat3 = [1, 2, 3, 4];
-// CHECK{LITERAL}: list<list<list<int>>> Flat4 = [[[1]], [[2]], [[3]], [[4]]];
-// CHECK: list<string> Flat6 = ["a", "b"];
-def F : Flatten<[1,2], [3,4,5]>;
-
+// RUN: llvm-tblgen %s | FileCheck %s
+
+class Flatten<list<int> A, list<int> B> {
+    list<int> Flat1 = !listflatten([A, B, [6], [7, 8]]);
+
+    list<list<int>> X = [A, B];
+    list<int> Flat2 = !listflatten(!listconcat(X, [[7]]));
+
+    // Generate a nested list of integers.
+    list<int> Y0 = [1, 2, 3, 4];
+    list<list<int>> Y1 = !foreach(elem, Y0, [elem]);
+    list<list<list<int>>> Y2 = !foreach(elem, Y1, [elem]);
+    list<list<list<list<int>>>> Y3 = !foreach(elem, Y2, [elem]);
+
+    // Flatten it completely.
+    list<int> Flat3=!listflatten(!listflatten(!listflatten(Y3)));
+
+    // Flatten it partially.
+    list<list<list<int>>> Flat4 = !listflatten(Y3);
+    list<list<int>> Flat5 = !listflatten(!listflatten(Y3));
+
+    // Test NOP flattening.
+    list<string> Flat6 = !listflatten(["a", "b"]);
+}
+
+// CHECK: list<int> Flat1 = [1, 2, 3, 4, 5, 6, 7, 8];
+// CHECK: list<int> Flat2 = [1, 2, 3, 4, 5, 7];
+// CHECK: list<int> Flat3 = [1, 2, 3, 4];
+// CHECK{LITERAL}: list<list<list<int>>> Flat4 = [[[1]], [[2]], [[3]], [[4]]];
+// CHECK: list<string> Flat6 = ["a", "b"];
+def F : Flatten<[1,2], [3,4,5]>;
+



More information about the llvm-commits mailing list