OpAsmParser &parser, bool allowAttributes, bool allowVariadic,
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &argNames,
SmallVectorImpl<Type> &argTypes, SmallVectorImpl<NamedAttrList> &argAttrs,
- SmallVectorImpl<Location> &argLocations, bool &isVariadic);
+ bool &isVariadic);
/// Parses a function signature using `parser`. The `allowVariadic` argument
/// indicates whether functions with variadic arguments are supported. The
OpAsmParser &parser, bool allowVariadic,
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &argNames,
SmallVectorImpl<Type> &argTypes, SmallVectorImpl<NamedAttrList> &argAttrs,
- SmallVectorImpl<Location> &argLocations, bool &isVariadic,
- SmallVectorImpl<Type> &resultTypes,
+ bool &isVariadic, SmallVectorImpl<Type> &resultTypes,
SmallVectorImpl<NamedAttrList> &resultAttrs);
/// Parser implementation for function-like operations. Uses
SMLoc location; // Location of the token.
StringRef name; // Value name, e.g. %42 or %abc
unsigned number; // Number, e.g. 12 for an operand like %xyz#12
+ Optional<Location> sourceLoc; // Source location specifier if present.
};
/// Parse different components, viz., use-info of operand(s), successor(s),
/// Parses a region. Any parsed blocks are appended to 'region' and must be
/// moved to the op regions after the op is created. The first block of the
- /// region takes 'arguments' of types 'argTypes'. If `argLocations` is
- /// non-empty it contains a location to be attached to each argument. If
- /// 'enableNameShadowing' is set to true, the argument names are allowed to
- /// shadow the names of other existing SSA values defined above the region
- /// scope. 'enableNameShadowing' can only be set to true for regions attached
- /// to operations that are 'IsolatedFromAbove'.
+ /// region takes 'arguments' of types 'argTypes'. If 'enableNameShadowing' is
+ /// set to true, the argument names are allowed to shadow the names of other
+ /// existing SSA values defined above the region scope. 'enableNameShadowing'
+ /// can only be set to true for regions attached to operations that are
+ /// 'IsolatedFromAbove'.
virtual ParseResult parseRegion(Region ®ion,
ArrayRef<UnresolvedOperand> arguments = {},
ArrayRef<Type> argTypes = {},
- ArrayRef<Location> argLocations = {},
bool enableNameShadowing = false) = 0;
/// Parses a region if present.
virtual OptionalParseResult parseOptionalRegion(
Region ®ion, ArrayRef<UnresolvedOperand> arguments = {},
- ArrayRef<Type> argTypes = {}, ArrayRef<Location> argLocations = {},
- bool enableNameShadowing = false) = 0;
+ ArrayRef<Type> argTypes = {}, bool enableNameShadowing = false) = 0;
/// Parses a region if present. If the region is present, a new region is
/// allocated and placed in `region`. If no region is present or on failure,
Region *body = result.addRegion();
if (parser.parseRegion(*body, /*arguments=*/{unwrappedArgs},
/*argTypes=*/{unwrappedTypes},
- /*argLocations=*/{},
/*enableNameShadowing=*/false))
return failure();
if (parser.parseOptionalKeyword("args"))
return success();
SmallVector<NamedAttrList> argAttrs;
- SmallVector<Location> argLocations;
bool isVariadic = false;
return function_interface_impl::parseFunctionArgumentList(
parser, /*allowAttributes=*/false,
- /*allowVariadic=*/false, argNames, argTypes, argAttrs, argLocations,
- isVariadic);
+ /*allowVariadic=*/false, argNames, argTypes, argAttrs, isVariadic);
}
static void printLaunchFuncOperands(OpAsmPrinter &printer, Operation *,
SmallVector<NamedAttrList> resultAttrs;
SmallVector<Type> argTypes;
SmallVector<Type> resultTypes;
- SmallVector<Location> argLocations;
bool isVariadic;
// Parse the function name.
auto signatureLocation = parser.getCurrentLocation();
if (failed(function_interface_impl::parseFunctionSignature(
parser, /*allowVariadic=*/false, entryArgs, argTypes, argAttrs,
- argLocations, isVariadic, resultTypes, resultAttrs)))
+ isVariadic, resultTypes, resultAttrs)))
return failure();
if (entryArgs.empty() && !argTypes.empty())
SmallVector<NamedAttrList> resultAttrs;
SmallVector<Type> argTypes;
SmallVector<Type> resultTypes;
- SmallVector<Location> argLocations;
bool isVariadic;
auto signatureLocation = parser.getCurrentLocation();
result.attributes) ||
function_interface_impl::parseFunctionSignature(
parser, /*allowVariadic=*/true, entryArgs, argTypes, argAttrs,
- argLocations, isVariadic, resultTypes, resultAttrs))
+ isVariadic, resultTypes, resultAttrs))
return failure();
auto type =
SmallVector<NamedAttrList> resultAttrs;
SmallVector<Type> argTypes;
SmallVector<Type> resultTypes;
- SmallVector<Location> argLocations;
auto &builder = parser.getBuilder();
// Parse the name as a symbol.
bool isVariadic = false;
if (function_interface_impl::parseFunctionSignature(
parser, /*allowVariadic=*/false, entryArgs, argTypes, argAttrs,
- argLocations, isVariadic, resultTypes, resultAttrs))
+ isVariadic, resultTypes, resultAttrs))
return failure();
auto fnType = builder.getFunctionType(argTypes, resultTypes);
OpAsmParser &parser, bool allowAttributes, bool allowVariadic,
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &argNames,
SmallVectorImpl<Type> &argTypes, SmallVectorImpl<NamedAttrList> &argAttrs,
- SmallVectorImpl<Location> &argLocations, bool &isVariadic) {
+ bool &isVariadic) {
if (parser.parseLParen())
return failure();
// Reject this if the preceding argument was missing a name.
if (argNames.empty() && !argTypes.empty())
return parser.emitError(loc, "expected type instead of SSA identifier");
- argNames.push_back(argument);
+ // Parse required type.
if (parser.parseColonType(argumentType))
return failure();
} else if (allowVariadic && succeeded(parser.parseOptionalEllipsis())) {
// Add the argument type.
argTypes.push_back(argumentType);
- // Parse any argument attributes.
+ // Parse any argument attributes and source location information.
NamedAttrList attrs;
- if (parser.parseOptionalAttrDict(attrs))
+ if (parser.parseOptionalAttrDict(attrs) ||
+ parser.parseOptionalLocationSpecifier(argument.sourceLoc))
return failure();
+
if (!allowAttributes && !attrs.empty())
return parser.emitError(loc, "expected arguments without attributes");
argAttrs.push_back(attrs);
- // Parse a location if specified.
- Optional<Location> explicitLoc;
- if (!argument.name.empty() &&
- parser.parseOptionalLocationSpecifier(explicitLoc))
- return failure();
- if (!explicitLoc)
- explicitLoc = parser.getEncodedSourceLoc(loc);
- argLocations.push_back(*explicitLoc);
-
+ // If we had an argument name, then remember the parsed argument.
+ if (!argument.name.empty())
+ argNames.push_back(argument);
return success();
};
OpAsmParser &parser, bool allowVariadic,
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &argNames,
SmallVectorImpl<Type> &argTypes, SmallVectorImpl<NamedAttrList> &argAttrs,
- SmallVectorImpl<Location> &argLocations, bool &isVariadic,
- SmallVectorImpl<Type> &resultTypes,
+ bool &isVariadic, SmallVectorImpl<Type> &resultTypes,
SmallVectorImpl<NamedAttrList> &resultAttrs) {
bool allowArgAttrs = true;
if (parseFunctionArgumentList(parser, allowArgAttrs, allowVariadic, argNames,
- argTypes, argAttrs, argLocations, isVariadic))
+ argTypes, argAttrs, isVariadic))
return failure();
if (succeeded(parser.parseOptionalArrow()))
return parseFunctionResultList(parser, resultTypes, resultAttrs);
SmallVector<NamedAttrList> resultAttrs;
SmallVector<Type> argTypes;
SmallVector<Type> resultTypes;
- SmallVector<Location> argLocations;
auto &builder = parser.getBuilder();
// Parse visibility.
SMLoc signatureLocation = parser.getCurrentLocation();
bool isVariadic = false;
if (parseFunctionSignature(parser, allowVariadic, entryArgs, argTypes,
- argAttrs, argLocations, isVariadic, resultTypes,
- resultAttrs))
+ argAttrs, isVariadic, resultTypes, resultAttrs))
return failure();
std::string errorMessage;
SMLoc loc = parser.getCurrentLocation();
OptionalParseResult parseResult = parser.parseOptionalRegion(
*body, entryArgs, entryArgs.empty() ? ArrayRef<Type>() : argTypes,
- entryArgs.empty() ? ArrayRef<Location>() : argLocations,
/*enableNameShadowing=*/false);
if (parseResult.hasValue()) {
if (failed(*parseResult))
//===--------------------------------------------------------------------===//
/// Parse a region into 'region' with the provided entry block arguments.
- /// If non-empty, 'argLocations' contains an optional locations for each
- /// argument. 'isIsolatedNameScope' indicates if the naming scope of this
- /// region is isolated from those above.
+ /// 'isIsolatedNameScope' indicates if the naming scope of this region is
+ /// isolated from those above.
ParseResult
parseRegion(Region ®ion,
ArrayRef<std::pair<UnresolvedOperand, Type>> entryArguments,
- ArrayRef<Location> argLocations,
bool isIsolatedNameScope = false);
/// Parse a region body into 'region'.
ParseResult
parseRegionBody(Region ®ion, SMLoc startLoc,
ArrayRef<std::pair<UnresolvedOperand, Type>> entryArguments,
- ArrayRef<Location> argLocations, bool isIsolatedNameScope);
+ bool isIsolatedNameScope);
//===--------------------------------------------------------------------===//
// Block Parsing
unsigned opResI = 0;
for (ResultRecord &resIt : resultIDs) {
for (unsigned subRes : llvm::seq<unsigned>(0, std::get<1>(resIt))) {
- if (addDefinition({std::get<2>(resIt), std::get<0>(resIt), subRes},
+ if (addDefinition({std::get<2>(resIt), std::get<0>(resIt), subRes, {}},
op->getResult(opResI++)))
return failure();
}
do {
// Create temporary regions with the top level region as parent.
result.regions.emplace_back(new Region(topLevelOp));
- if (parseRegion(*result.regions.back(), /*entryArguments=*/{},
- /*argLocations=*/{}))
+ if (parseRegion(*result.regions.back(), /*entryArguments=*/{}))
return failure();
} while (consumeIf(Token::comma));
if (parseToken(Token::r_paren, "expected ')' to end region list"))
if (parser.parseSSAUse(useInfo))
return failure();
- result = {useInfo.location, useInfo.name, useInfo.number};
- return success();
+ result = {useInfo.location, useInfo.name, useInfo.number, {}};
+
+ // Parse a source locator on the operand if present.
+ return parseOptionalLocationSpecifier(result.sourceLoc);
}
/// Parse a single operand if present.
/// effectively defines the SSA values of `arguments` and assigns their type.
ParseResult parseRegion(Region ®ion, ArrayRef<UnresolvedOperand> arguments,
ArrayRef<Type> argTypes,
- ArrayRef<Location> argLocations,
bool enableNameShadowing) override {
assert(arguments.size() == argTypes.size() &&
"mismatching number of arguments and types");
(void)isIsolatedFromAbove;
assert((!enableNameShadowing || isIsolatedFromAbove) &&
"name shadowing is only allowed on isolated regions");
- if (parser.parseRegion(region, regionArguments, argLocations,
- enableNameShadowing))
+ if (parser.parseRegion(region, regionArguments, enableNameShadowing))
return failure();
return success();
}
OptionalParseResult parseOptionalRegion(Region ®ion,
ArrayRef<UnresolvedOperand> arguments,
ArrayRef<Type> argTypes,
- ArrayRef<Location> argLocations,
bool enableNameShadowing) override {
if (parser.getToken().isNot(Token::l_brace))
return llvm::None;
- return parseRegion(region, arguments, argTypes, argLocations,
- enableNameShadowing);
+ return parseRegion(region, arguments, argTypes, enableNameShadowing);
}
/// Parses a region if present. If the region is present, a new region is
if (parser.getToken().isNot(Token::l_brace))
return llvm::None;
std::unique_ptr<Region> newRegion = std::make_unique<Region>();
- if (parseRegion(*newRegion, arguments, argTypes, /*argLocations=*/{},
- enableNameShadowing))
+ if (parseRegion(*newRegion, arguments, argTypes, enableNameShadowing))
return failure();
region = std::move(newRegion);
Region ®ion,
ArrayRef<std::pair<OperationParser::UnresolvedOperand, Type>>
entryArguments,
- ArrayRef<Location> argLocations, bool isIsolatedNameScope) {
+ bool isIsolatedNameScope) {
// Parse the '{'.
Token lBraceTok = getToken();
if (parseToken(Token::l_brace, "expected '{' to begin a region"))
// Parse the region body.
if ((!entryArguments.empty() || getToken().isNot(Token::r_brace)) &&
- parseRegionBody(region, lBraceTok.getLoc(), entryArguments, argLocations,
+ parseRegionBody(region, lBraceTok.getLoc(), entryArguments,
isIsolatedNameScope)) {
return failure();
}
Region ®ion, SMLoc startLoc,
ArrayRef<std::pair<OperationParser::UnresolvedOperand, Type>>
entryArguments,
- ArrayRef<Location> argLocations, bool isIsolatedNameScope) {
- assert(argLocations.empty() || argLocations.size() == entryArguments.size());
+ bool isIsolatedNameScope) {
auto currentPt = opBuilder.saveInsertionPoint();
// Push a new named value scope.
if (getToken().is(Token::caret_identifier))
return emitError("invalid block name in region with named arguments");
- for (const auto &it : llvm::enumerate(entryArguments)) {
- size_t argIndex = it.index();
- auto &placeholderArgPair = it.value();
+ for (auto &placeholderArgPair : entryArguments) {
auto &argInfo = placeholderArgPair.first;
// Ensure that the argument was not already defined.
.attachNote(getEncodedSourceLocation(*defLoc))
<< "previously referenced here";
}
- BlockArgument arg = block->addArgument(
- placeholderArgPair.second,
- argLocations.empty()
- ? getEncodedSourceLocation(placeholderArgPair.first.location)
- : argLocations[argIndex]);
+ Location loc = argInfo.sourceLoc.hasValue()
+ ? argInfo.sourceLoc.getValue()
+ : getEncodedSourceLocation(argInfo.location);
+ BlockArgument arg = block->addArgument(placeholderArgPair.second, loc);
// Add a definition of this arg to the assembly state if provided.
if (state.asmState)
// RUN: mlir-opt -split-input-file -verify-diagnostics %s | mlir-opt | FileCheck %s
// RUN: mlir-opt -split-input-file -verify-diagnostics -mlir-print-op-generic %s | FileCheck %s --check-prefix=GENERIC
+// RUN: mlir-opt -split-input-file -verify-diagnostics %s -mlir-print-debuginfo | mlir-opt -mlir-print-debuginfo | FileCheck %s --check-prefix=LOCINFO
module {
// GENERIC: "llvm.func"
}
// CHECK: llvm.func @sretattr(%{{.*}}: !llvm.ptr<i32> {llvm.sret})
- llvm.func @sretattr(%arg0: !llvm.ptr<i32> {llvm.sret}) {
+ // LOCINFO: llvm.func @sretattr(%{{.*}}: !llvm.ptr<i32> {llvm.sret} loc("some_source_loc"))
+ llvm.func @sretattr(%arg0: !llvm.ptr<i32> {llvm.sret} loc("some_source_loc")) {
llvm.return
}
// Parse the body region, and reuse the operand info as the argument info.
Region *body = result.addRegion();
- return parser.parseRegion(*body, argInfo, argType, /*argLocations=*/{},
+ return parser.parseRegion(*body, argInfo, argType,
/*enableNameShadowing=*/true);
}