[Mlir-commits] [mlir] 3e13900 - [mlir][Parser] Small optimization to parsing
River Riddle
llvmlistbot at llvm.org
Tue Nov 3 13:10:36 PST 2020
Author: River Riddle
Date: 2020-11-03T13:10:26-08:00
New Revision: 3e1390090fe31702488d26b72aa2aa018f557f0e
URL: https://github.com/llvm/llvm-project/commit/3e1390090fe31702488d26b72aa2aa018f557f0e
DIFF: https://github.com/llvm/llvm-project/commit/3e1390090fe31702488d26b72aa2aa018f557f0e.diff
LOG: [mlir][Parser] Small optimization to parsing
* Use function_ref instead of std::function in several methods
* Use ::get instead of ::getChecked for IntegerType.
- It is already fully verified and constructing a mlir::Location can be extremely costly during parsing.
Added:
Modified:
mlir/lib/Parser/Parser.cpp
mlir/lib/Parser/Parser.h
mlir/lib/Parser/TypeParser.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp
index 6d04f97f4576..e89972007156 100644
--- a/mlir/lib/Parser/Parser.cpp
+++ b/mlir/lib/Parser/Parser.cpp
@@ -35,8 +35,8 @@ using llvm::SourceMgr;
/// Parse a comma separated list of elements that must have at least one entry
/// in it.
-ParseResult Parser::parseCommaSeparatedList(
- const std::function<ParseResult()> &parseElement) {
+ParseResult
+Parser::parseCommaSeparatedList(function_ref<ParseResult()> parseElement) {
// Non-empty case starts with an element.
if (parseElement())
return failure();
@@ -55,9 +55,10 @@ ParseResult Parser::parseCommaSeparatedList(
/// abstract-list ::= rightToken // if allowEmptyList == true
/// abstract-list ::= element (',' element)* rightToken
///
-ParseResult Parser::parseCommaSeparatedListUntil(
- Token::Kind rightToken, const std::function<ParseResult()> &parseElement,
- bool allowEmptyList) {
+ParseResult
+Parser::parseCommaSeparatedListUntil(Token::Kind rightToken,
+ function_ref<ParseResult()> parseElement,
+ bool allowEmptyList) {
// Handle the empty case.
if (getToken().is(rightToken)) {
if (!allowEmptyList)
@@ -145,8 +146,8 @@ class OperationParser : public Parser {
/// returns null on failure.
Value resolveSSAUse(SSAUseInfo useInfo, Type type);
- ParseResult parseSSADefOrUseAndType(
- const std::function<ParseResult(SSAUseInfo, Type)> &action);
+ ParseResult
+ parseSSADefOrUseAndType(function_ref<ParseResult(SSAUseInfo, Type)> action);
ParseResult parseOptionalSSAUseAndTypeList(SmallVectorImpl<Value> &results);
@@ -506,7 +507,7 @@ Value OperationParser::resolveSSAUse(SSAUseInfo useInfo, Type type) {
///
/// ssa-use-and-type ::= ssa-use `:` type
ParseResult OperationParser::parseSSADefOrUseAndType(
- const std::function<ParseResult(SSAUseInfo, Type)> &action) {
+ function_ref<ParseResult(SSAUseInfo, Type)> action) {
SSAUseInfo useInfo;
if (parseSSAUse(useInfo) ||
parseToken(Token::colon, "expected ':' and type for SSA operand"))
diff --git a/mlir/lib/Parser/Parser.h b/mlir/lib/Parser/Parser.h
index 9ffaea051f66..63a9d0df040c 100644
--- a/mlir/lib/Parser/Parser.h
+++ b/mlir/lib/Parser/Parser.h
@@ -36,13 +36,12 @@ class Parser {
/// Parse a comma-separated list of elements up until the specified end token.
ParseResult
parseCommaSeparatedListUntil(Token::Kind rightToken,
- const std::function<ParseResult()> &parseElement,
+ function_ref<ParseResult()> parseElement,
bool allowEmptyList = true);
/// Parse a comma separated list of elements that must have at least one entry
/// in it.
- ParseResult
- parseCommaSeparatedList(const std::function<ParseResult()> &parseElement);
+ ParseResult parseCommaSeparatedList(function_ref<ParseResult()> parseElement);
ParseResult parsePrettyDialectSymbolName(StringRef &prettyName);
diff --git a/mlir/lib/Parser/TypeParser.cpp b/mlir/lib/Parser/TypeParser.cpp
index f5c98f3c6f9d..c3087c15b0c5 100644
--- a/mlir/lib/Parser/TypeParser.cpp
+++ b/mlir/lib/Parser/TypeParser.cpp
@@ -337,9 +337,8 @@ Type Parser::parseNonFunctionType() {
if (Optional<bool> signedness = getToken().getIntTypeSignedness())
signSemantics = *signedness ? IntegerType::Signed : IntegerType::Unsigned;
- auto loc = getEncodedSourceLocation(getToken().getLoc());
consumeToken(Token::inttype);
- return IntegerType::getChecked(width.getValue(), signSemantics, loc);
+ return IntegerType::get(width.getValue(), signSemantics, getContext());
}
// float-type
More information about the Mlir-commits
mailing list