Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions mlir/include/mlir/AsmParser/AsmParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ parseAsmSourceFile(const llvm::SourceMgr &sourceMgr, Block *block,
/// null terminated.
Attribute parseAttribute(llvm::StringRef attrStr, MLIRContext *context,
Type type = {}, size_t *numRead = nullptr,
bool isKnownNullTerminated = false,
llvm::StringMap<Attribute> *attributesCache = nullptr);
bool isKnownNullTerminated = false);

/// This parses a single MLIR type to an MLIR context if it was valid. If not,
/// an error diagnostic is emitted to the context.
Expand Down
24 changes: 2 additions & 22 deletions mlir/lib/AsmParser/DialectSymbolParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,6 @@ static Symbol parseExtendedSymbol(Parser &p, AsmParserState *asmState,
return nullptr;
}

if constexpr (std::is_same_v<Symbol, Attribute>) {
auto &cache = p.getState().symbols.attributesCache;
auto cacheIt = cache.find(symbolData);
// Skip cached attribute if it has type.
if (cacheIt != cache.end() && !p.getToken().is(Token::colon))
return cacheIt->second;

return cache[symbolData] = createSymbol(dialectName, symbolData, loc);
}
return createSymbol(dialectName, symbolData, loc);
}

Expand Down Expand Up @@ -346,7 +337,6 @@ Type Parser::parseExtendedType() {
template <typename T, typename ParserFn>
static T parseSymbol(StringRef inputStr, MLIRContext *context,
size_t *numReadOut, bool isKnownNullTerminated,
llvm::StringMap<Attribute> *attributesCache,
ParserFn &&parserFn) {
// Set the buffer name to the string being parsed, so that it appears in error
// diagnostics.
Expand All @@ -358,9 +348,6 @@ static T parseSymbol(StringRef inputStr, MLIRContext *context,
SourceMgr sourceMgr;
sourceMgr.AddNewSourceBuffer(std::move(memBuffer), SMLoc());
SymbolState aliasState;
if (attributesCache)
aliasState.attributesCache = *attributesCache;

ParserConfig config(context);
ParserState state(sourceMgr, config, aliasState, /*asmState=*/nullptr,
/*codeCompleteContext=*/nullptr);
Expand All @@ -371,11 +358,6 @@ static T parseSymbol(StringRef inputStr, MLIRContext *context,
if (!symbol)
return T();

if constexpr (std::is_same_v<T, Attribute>) {
if (attributesCache)
*attributesCache = state.symbols.attributesCache;
}

// Provide the number of bytes that were read.
Token endTok = parser.getToken();
size_t numRead =
Expand All @@ -392,15 +374,13 @@ static T parseSymbol(StringRef inputStr, MLIRContext *context,

Attribute mlir::parseAttribute(StringRef attrStr, MLIRContext *context,
Type type, size_t *numRead,
bool isKnownNullTerminated,
llvm::StringMap<Attribute> *attributesCache) {
bool isKnownNullTerminated) {
return parseSymbol<Attribute>(
attrStr, context, numRead, isKnownNullTerminated, attributesCache,
attrStr, context, numRead, isKnownNullTerminated,
[type](Parser &parser) { return parser.parseAttribute(type); });
}
Type mlir::parseType(StringRef typeStr, MLIRContext *context, size_t *numRead,
bool isKnownNullTerminated) {
return parseSymbol<Type>(typeStr, context, numRead, isKnownNullTerminated,
/*attributesCache=*/nullptr,
[](Parser &parser) { return parser.parseType(); });
}
3 changes: 0 additions & 3 deletions mlir/lib/AsmParser/ParserState.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ struct SymbolState {

/// A map from unique integer identifier to DistinctAttr.
DenseMap<uint64_t, DistinctAttr> distinctAttributes;

/// A map from unique string identifier to Attribute.
llvm::StringMap<Attribute> attributesCache;
};

//===----------------------------------------------------------------------===//
Expand Down
6 changes: 1 addition & 5 deletions mlir/lib/Bytecode/Reader/BytecodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,10 +895,6 @@ class AttrTypeReader {
SmallVector<AttrEntry> attributes;
SmallVector<TypeEntry> types;

/// The map of cached attributes, used to avoid re-parsing the same
/// attribute multiple times.
llvm::StringMap<Attribute> attributesCache;

/// A location used for error emission.
Location fileLoc;

Expand Down Expand Up @@ -1239,7 +1235,7 @@ LogicalResult AttrTypeReader::parseAsmEntry(T &result, EncodingReader &reader,
::parseType(asmStr, context, &numRead, /*isKnownNullTerminated=*/true);
else
result = ::parseAttribute(asmStr, context, Type(), &numRead,
/*isKnownNullTerminated=*/true, &attributesCache);
/*isKnownNullTerminated=*/true);
if (!result)
return failure();

Expand Down
13 changes: 0 additions & 13 deletions mlir/test/IR/recursive-distinct-attr.mlir

This file was deleted.