Import llvm::StringSwitch into mlir namespace.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D88971
This commit is contained in:
Christian Sigg 2020-10-07 16:17:35 +02:00
parent 3578945004
commit cc83dc191c
12 changed files with 16 additions and 12 deletions

View 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>;

View 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)

View 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); })

View 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>())

View 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>)

View 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);

View 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);

View 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)

View 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)

View 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())

View 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)

View 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)