Skip to content

Commit cc83dc1

Browse files
committed
Import llvm::StringSwitch into mlir namespace.
Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D88971
1 parent 3578945 commit cc83dc1

File tree

12 files changed

+16
-12
lines changed

12 files changed

+16
-12
lines changed

mlir/include/mlir/Support/LLVM.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ template <typename T>
6060
class SmallVectorImpl;
6161
template <typename AllocatorTy>
6262
class StringSet;
63+
template <typename T, typename R>
64+
class StringSwitch;
6365
template <typename T>
6466
class TinyPtrVector;
6567
template <typename T, typename ResultT>
@@ -111,6 +113,8 @@ using llvm::SmallPtrSet;
111113
using llvm::SmallPtrSetImpl;
112114
using llvm::SmallVector;
113115
using llvm::SmallVectorImpl;
116+
template <typename T, typename R = T>
117+
using StringSwitch = llvm::StringSwitch<T, R>;
114118
using llvm::TinyPtrVector;
115119
template <typename T, typename ResultT = void>
116120
using TypeSwitch = llvm::TypeSwitch<T, ResultT>;

mlir/lib/Conversion/GPUCommon/IndexIntrinsicsOpLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct GPUIndexIntrinsicOpLowering : public ConvertToLLVMPattern {
2727
unsigned indexBitwidth;
2828

2929
static dimension dimensionToIndex(Op op) {
30-
return llvm::StringSwitch<dimension>(op.dimension())
30+
return StringSwitch<dimension>(op.dimension())
3131
.Case("x", X)
3232
.Case("y", Y)
3333
.Case("z", Z)

mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ static LLVMType parseTypeImpl(DialectAsmParser &parser,
440440
if (failed(parser.parseKeyword(&key)))
441441
return LLVMType();
442442

443-
return llvm::StringSwitch<function_ref<LLVMType()>>(key)
443+
return StringSwitch<function_ref<LLVMType()>>(key)
444444
.Case("void", [&] { return LLVMVoidType::get(ctx); })
445445
.Case("half", [&] { return LLVMHalfType::get(ctx); })
446446
.Case("bfloat", [&] { return LLVMBFloatType::get(ctx); })

mlir/lib/Dialect/PDL/IR/PDL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Type PDLDialect::parseType(DialectAsmParser &parser) const {
3434
return Type();
3535

3636
Builder &builder = parser.getBuilder();
37-
Type result = llvm::StringSwitch<Type>(keyword)
37+
Type result = StringSwitch<Type>(keyword)
3838
.Case("attribute", builder.getType<AttributeType>())
3939
.Case("operation", builder.getType<OperationType>())
4040
.Case("type", builder.getType<TypeType>())

mlir/lib/ExecutionEngine/JitRunner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ int mlir::JitRunnerMain(
291291
Error (*)(Options &, ModuleOp, StringRef,
292292
std::function<llvm::Error(llvm::Module *)>);
293293
auto compileAndExecuteFn =
294-
llvm::StringSwitch<CompileAndExecuteFnT>(options.mainFuncType.getValue())
294+
StringSwitch<CompileAndExecuteFnT>(options.mainFuncType.getValue())
295295
.Case("i32", compileAndExecuteSingleReturnFunction<int32_t>)
296296
.Case("i64", compileAndExecuteSingleReturnFunction<int64_t>)
297297
.Case("f32", compileAndExecuteSingleReturnFunction<float>)

mlir/lib/IR/SymbolTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ SymbolTable::Visibility SymbolTable::getSymbolVisibility(Operation *symbol) {
166166
return Visibility::Public;
167167

168168
// Otherwise, switch on the string value.
169-
return llvm::StringSwitch<Visibility>(vis.getValue())
169+
return StringSwitch<Visibility>(vis.getValue())
170170
.Case("private", Visibility::Private)
171171
.Case("nested", Visibility::Nested)
172172
.Case("public", Visibility::Public);

mlir/lib/Parser/Lexer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Token Lexer::lexBareIdentifierOrKeyword(const char *tokStart) {
212212
isAllDigit(spelling.drop_front(2))))
213213
return Token(Token::inttype, spelling);
214214

215-
Token::Kind kind = llvm::StringSwitch<Token::Kind>(spelling)
215+
Token::Kind kind = StringSwitch<Token::Kind>(spelling)
216216
#define TOK_KEYWORD(SPELLING) .Case(#SPELLING, Token::kw_##SPELLING)
217217
#include "TokenKinds.def"
218218
.Default(Token::bare_identifier);

mlir/lib/TableGen/Format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Optional<StringRef> FmtContext::getSubstFor(StringRef placeholder) const {
6060
}
6161

6262
FmtContext::PHKind FmtContext::getPlaceHolderKind(StringRef str) {
63-
return llvm::StringSwitch<FmtContext::PHKind>(str)
63+
return StringSwitch<FmtContext::PHKind>(str)
6464
.Case("_builder", FmtContext::PHKind::Builder)
6565
.Case("_op", FmtContext::PHKind::Op)
6666
.Case("_self", FmtContext::PHKind::Self)

mlir/lib/TableGen/Predicate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static PredCombinerKind getPredCombinerKind(const Pred &pred) {
119119
return PredCombinerKind::Leaf;
120120

121121
const auto &combinedPred = static_cast<const CombinedPred &>(pred);
122-
return llvm::StringSwitch<PredCombinerKind>(
122+
return StringSwitch<PredCombinerKind>(
123123
combinedPred.getCombinerDef()->getName())
124124
.Case("PredCombinerAnd", PredCombinerKind::And)
125125
.Case("PredCombinerOr", PredCombinerKind::Or)

mlir/test/lib/Dialect/Test/TestDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ void SideEffectOp::getEffects(
685685

686686
// Get the specific memory effect.
687687
MemoryEffects::Effect *effect =
688-
llvm::StringSwitch<MemoryEffects::Effect *>(
688+
StringSwitch<MemoryEffects::Effect *>(
689689
effectElement.get("effect").cast<StringAttr>().getValue())
690690
.Case("allocate", MemoryEffects::Allocate::get())
691691
.Case("free", MemoryEffects::Free::get())

mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ Token Lexer::lexIdentifier(const char *tokStart) {
288288

289289
// Check to see if this identifier is a keyword.
290290
StringRef str(tokStart, curPtr - tokStart);
291-
Token::Kind kind = llvm::StringSwitch<Token::Kind>(str)
291+
Token::Kind kind = StringSwitch<Token::Kind>(str)
292292
.Case("def", Token::Kind::kw_def)
293293
.Case("ods_def", Token::Kind::kw_ods_def)
294294
.Case("floordiv", Token::Kind::kw_floordiv)

mlir/tools/mlir-tblgen/OpFormatGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ static void genLiteralParser(StringRef value, OpMethodBody &body) {
719719
body << "Keyword(\"" << value << "\")";
720720
return;
721721
}
722-
body << (StringRef)llvm::StringSwitch<StringRef>(value)
722+
body << (StringRef)StringSwitch<StringRef>(value)
723723
.Case("->", "Arrow()")
724724
.Case(":", "Colon()")
725725
.Case(",", "Comma()")
@@ -1936,7 +1936,7 @@ Token FormatLexer::lexIdentifier(const char *tokStart) {
19361936
// Check to see if this identifier is a keyword.
19371937
StringRef str(tokStart, curPtr - tokStart);
19381938
Token::Kind kind =
1939-
llvm::StringSwitch<Token::Kind>(str)
1939+
StringSwitch<Token::Kind>(str)
19401940
.Case("attr-dict", Token::kw_attr_dict)
19411941
.Case("attr-dict-with-keyword", Token::kw_attr_dict_w_keyword)
19421942
.Case("custom", Token::kw_custom)

0 commit comments

Comments
 (0)