Created
July 21, 2024 18:58
-
-
Save makslevental/e70c12676b584f717155b63f4157ee81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace mlir { | |
namespace iree_compiler { | |
namespace AMDAIE { | |
// "); static_assert(always_false<ParserT>, "this FieldParser should never be instantiated"); // | |
enum class FooDir : uint32_t { | |
S2MM = 0, | |
MM2S = 1, | |
}; | |
::std::optional<FooDir> symbolizeFooDir(uint32_t); | |
::llvm::StringRef stringifyFooDir(FooDir); | |
::std::optional<FooDir> symbolizeFooDir(::llvm::StringRef); | |
inline constexpr unsigned getMaxEnumValForFooDir() { | |
return 1; | |
} | |
inline ::llvm::StringRef stringifyEnum(FooDir enumValue) { | |
return stringifyFooDir(enumValue); | |
} | |
template <typename EnumType> | |
::std::optional<EnumType> symbolizeEnum(::llvm::StringRef); | |
template <> | |
inline ::std::optional<FooDir> symbolizeEnum<FooDir>(::llvm::StringRef str) { | |
return symbolizeFooDir(str); | |
} | |
} // namespace AMDAIE | |
} // namespace iree_compiler | |
} // namespace mlir | |
namespace mlir { | |
template <typename T, typename> | |
struct FieldParser; | |
template<> | |
struct FieldParser<mlir::iree_compiler::AMDAIE::FooDir, mlir::iree_compiler::AMDAIE::FooDir> { | |
template <typename ParserT> | |
static FailureOr<mlir::iree_compiler::AMDAIE::FooDir> parse(ParserT &parser) { | |
// Parse the keyword/string containing the enum. | |
std::string enumKeyword; | |
auto loc = parser.getCurrentLocation(); | |
if (failed(parser.parseOptionalKeywordOrString(&enumKeyword))) | |
return parser.emitError(loc, "expected keyword for "); static_assert(always_false<ParserT>, "this FieldParser should never be instantiated"); //"); | |
// Symbolize the keyword. | |
if (::std::optional<mlir::iree_compiler::AMDAIE::FooDir> attr = mlir::iree_compiler::AMDAIE::symbolizeEnum<mlir::iree_compiler::AMDAIE::FooDir>(enumKeyword)) | |
return *attr; | |
return parser.emitError(loc, "invalid "); static_assert(always_false<ParserT>, "this FieldParser should never be instantiated"); // specification: ") << enumKeyword; | |
} | |
}; | |
} // namespace mlir | |
namespace llvm { | |
inline ::llvm::raw_ostream &operator<<(::llvm::raw_ostream &p, mlir::iree_compiler::AMDAIE::FooDir value) { | |
auto valueStr = stringifyEnum(value); | |
return p << valueStr; | |
} | |
} // namespace llvm | |
namespace llvm { | |
template<> struct DenseMapInfo<mlir::iree_compiler::AMDAIE::FooDir> { | |
using StorageInfo = ::llvm::DenseMapInfo<uint32_t>; | |
static inline mlir::iree_compiler::AMDAIE::FooDir getEmptyKey() { | |
return static_cast<mlir::iree_compiler::AMDAIE::FooDir>(StorageInfo::getEmptyKey()); | |
} | |
static inline mlir::iree_compiler::AMDAIE::FooDir getTombstoneKey() { | |
return static_cast<mlir::iree_compiler::AMDAIE::FooDir>(StorageInfo::getTombstoneKey()); | |
} | |
static unsigned getHashValue(const mlir::iree_compiler::AMDAIE::FooDir &val) { | |
return StorageInfo::getHashValue(static_cast<uint32_t>(val)); | |
} | |
static bool isEqual(const mlir::iree_compiler::AMDAIE::FooDir &lhs, const mlir::iree_compiler::AMDAIE::FooDir &rhs) { | |
return lhs == rhs; | |
} | |
}; | |
} | |
namespace mlir { | |
namespace iree_compiler { | |
namespace AMDAIE { | |
::llvm::StringRef stringifyFooDir(FooDir val) { | |
switch (val) { | |
case FooDir::S2MM: return "S2MM"; | |
case FooDir::MM2S: return "MM2S"; | |
} | |
return ""; | |
} | |
::std::optional<FooDir> symbolizeFooDir(::llvm::StringRef str) { | |
return ::llvm::StringSwitch<::std::optional<FooDir>>(str) | |
.Case("S2MM", FooDir::S2MM) | |
.Case("MM2S", FooDir::MM2S) | |
.Default(::std::nullopt); | |
} | |
::std::optional<FooDir> symbolizeFooDir(uint32_t value) { | |
switch (value) { | |
case 0: return FooDir::S2MM; | |
case 1: return FooDir::MM2S; | |
default: return ::std::nullopt; | |
} | |
} | |
} // namespace AMDAIE | |
} // namespace iree_compiler | |
} // namespace mlir | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment