Import llvm::StringSwitch into mlir namespace.
authorChristian Sigg <csigg@google.com>
Wed, 7 Oct 2020 14:17:35 +0000 (16:17 +0200)
committerChristian Sigg <csigg@google.com>
Thu, 8 Oct 2020 09:39:24 +0000 (11:39 +0200)
Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D88971

12 files changed:
mlir/include/mlir/Support/LLVM.h
mlir/lib/Conversion/GPUCommon/IndexIntrinsicsOpLowering.h
mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
mlir/lib/Dialect/PDL/IR/PDL.cpp
mlir/lib/ExecutionEngine/JitRunner.cpp
mlir/lib/IR/SymbolTable.cpp
mlir/lib/Parser/Lexer.cpp
mlir/lib/TableGen/Format.cpp
mlir/lib/TableGen/Predicate.cpp
mlir/test/lib/Dialect/Test/TestDialect.cpp
mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp
mlir/tools/mlir-tblgen/OpFormatGen.cpp

index 17e0204..e8595ae 100644 (file)
@@ -60,6 +60,8 @@ template <typename T>
 class SmallVectorImpl;
 template <typename AllocatorTy>
 class StringSet;
+template <typename T, typename R>
+class StringSwitch;
 template <typename T>
 class TinyPtrVector;
 template <typename T, typename ResultT>
@@ -111,6 +113,8 @@ using llvm::SmallPtrSet;
 using llvm::SmallPtrSetImpl;
 using llvm::SmallVector;
 using llvm::SmallVectorImpl;
+template <typename T, typename R = T>
+using StringSwitch = llvm::StringSwitch<T, R>;
 using llvm::TinyPtrVector;
 template <typename T, typename ResultT = void>
 using TypeSwitch = llvm::TypeSwitch<T, ResultT>;
index 9338105..f4b7ced 100644 (file)
@@ -27,7 +27,7 @@ private:
   unsigned indexBitwidth;
 
   static dimension dimensionToIndex(Op op) {
-    return llvm::StringSwitch<dimension>(op.dimension())
+    return StringSwitch<dimension>(op.dimension())
         .Case("x", X)
         .Case("y", Y)
         .Case("z", Z)
index aa611d7..574d0aa 100644 (file)
@@ -440,7 +440,7 @@ static LLVMType parseTypeImpl(DialectAsmParser &parser,
   if (failed(parser.parseKeyword(&key)))
     return LLVMType();
 
-  return llvm::StringSwitch<function_ref<LLVMType()>>(key)
+  return StringSwitch<function_ref<LLVMType()>>(key)
       .Case("void", [&] { return LLVMVoidType::get(ctx); })
       .Case("half", [&] { return LLVMHalfType::get(ctx); })
       .Case("bfloat", [&] { return LLVMBFloatType::get(ctx); })
index a0b9c96..ba1eb7b 100644 (file)
@@ -34,7 +34,7 @@ Type PDLDialect::parseType(DialectAsmParser &parser) const {
     return Type();
 
   Builder &builder = parser.getBuilder();
-  Type result = llvm::StringSwitch<Type>(keyword)
+  Type result = StringSwitch<Type>(keyword)
                     .Case("attribute", builder.getType<AttributeType>())
                     .Case("operation", builder.getType<OperationType>())
                     .Case("type", builder.getType<TypeType>())
index 2b18adb..7d141e9 100644 (file)
@@ -291,7 +291,7 @@ int mlir::JitRunnerMain(
       Error (*)(Options &, ModuleOp, StringRef,
                 std::function<llvm::Error(llvm::Module *)>);
   auto compileAndExecuteFn =
-      llvm::StringSwitch<CompileAndExecuteFnT>(options.mainFuncType.getValue())
+      StringSwitch<CompileAndExecuteFnT>(options.mainFuncType.getValue())
           .Case("i32", compileAndExecuteSingleReturnFunction<int32_t>)
           .Case("i64", compileAndExecuteSingleReturnFunction<int64_t>)
           .Case("f32", compileAndExecuteSingleReturnFunction<float>)
index b064d83..e18e691 100644 (file)
@@ -166,7 +166,7 @@ SymbolTable::Visibility SymbolTable::getSymbolVisibility(Operation *symbol) {
     return Visibility::Public;
 
   // Otherwise, switch on the string value.
-  return llvm::StringSwitch<Visibility>(vis.getValue())
+  return StringSwitch<Visibility>(vis.getValue())
       .Case("private", Visibility::Private)
       .Case("nested", Visibility::Nested)
       .Case("public", Visibility::Public);
index 9a3418e..ee31ff0 100644 (file)
@@ -212,7 +212,7 @@ Token Lexer::lexBareIdentifierOrKeyword(const char *tokStart) {
        isAllDigit(spelling.drop_front(2))))
     return Token(Token::inttype, spelling);
 
-  Token::Kind kind = llvm::StringSwitch<Token::Kind>(spelling)
+  Token::Kind kind = StringSwitch<Token::Kind>(spelling)
 #define TOK_KEYWORD(SPELLING) .Case(#SPELLING, Token::kw_##SPELLING)
 #include "TokenKinds.def"
                          .Default(Token::bare_identifier);
index 1273587..7d17a0a 100644 (file)
@@ -60,7 +60,7 @@ Optional<StringRef> FmtContext::getSubstFor(StringRef placeholder) const {
 }
 
 FmtContext::PHKind FmtContext::getPlaceHolderKind(StringRef str) {
-  return llvm::StringSwitch<FmtContext::PHKind>(str)
+  return StringSwitch<FmtContext::PHKind>(str)
       .Case("_builder", FmtContext::PHKind::Builder)
       .Case("_op", FmtContext::PHKind::Op)
       .Case("_self", FmtContext::PHKind::Self)
index 8927296..a37847f 100644 (file)
@@ -119,7 +119,7 @@ static PredCombinerKind getPredCombinerKind(const Pred &pred) {
     return PredCombinerKind::Leaf;
 
   const auto &combinedPred = static_cast<const CombinedPred &>(pred);
-  return llvm::StringSwitch<PredCombinerKind>(
+  return StringSwitch<PredCombinerKind>(
              combinedPred.getCombinerDef()->getName())
       .Case("PredCombinerAnd", PredCombinerKind::And)
       .Case("PredCombinerOr", PredCombinerKind::Or)
index c84a771..4ca89bc 100644 (file)
@@ -685,7 +685,7 @@ void SideEffectOp::getEffects(
 
     // Get the specific memory effect.
     MemoryEffects::Effect *effect =
-        llvm::StringSwitch<MemoryEffects::Effect *>(
+        StringSwitch<MemoryEffects::Effect *>(
             effectElement.get("effect").cast<StringAttr>().getValue())
             .Case("allocate", MemoryEffects::Allocate::get())
             .Case("free", MemoryEffects::Free::get())
index 4fe3cd1..64424b4 100644 (file)
@@ -288,7 +288,7 @@ Token Lexer::lexIdentifier(const char *tokStart) {
 
   // Check to see if this identifier is a keyword.
   StringRef str(tokStart, curPtr - tokStart);
-  Token::Kind kind = llvm::StringSwitch<Token::Kind>(str)
+  Token::Kind kind = StringSwitch<Token::Kind>(str)
                          .Case("def", Token::Kind::kw_def)
                          .Case("ods_def", Token::Kind::kw_ods_def)
                          .Case("floordiv", Token::Kind::kw_floordiv)
index 336c911..9b8f249 100644 (file)
@@ -719,7 +719,7 @@ static void genLiteralParser(StringRef value, OpMethodBody &body) {
     body << "Keyword(\"" << value << "\")";
     return;
   }
-  body << (StringRef)llvm::StringSwitch<StringRef>(value)
+  body << (StringRef)StringSwitch<StringRef>(value)
               .Case("->", "Arrow()")
               .Case(":", "Colon()")
               .Case(",", "Comma()")
@@ -1936,7 +1936,7 @@ Token FormatLexer::lexIdentifier(const char *tokStart) {
   // Check to see if this identifier is a keyword.
   StringRef str(tokStart, curPtr - tokStart);
   Token::Kind kind =
-      llvm::StringSwitch<Token::Kind>(str)
+      StringSwitch<Token::Kind>(str)
           .Case("attr-dict", Token::kw_attr_dict)
           .Case("attr-dict-with-keyword", Token::kw_attr_dict_w_keyword)
           .Case("custom", Token::kw_custom)