LogicalResult convertFunction(Function *f);
/// Converts the given region starting from the entry block and following the
- /// block successors. Returns failure on error, success otherwise.
- template <typename RegionParent>
+ /// block successors. Returns failure on error, success otherwise. Prints
+ /// error messages at `loc`.
LogicalResult convertRegion(DialectConversionRewriter &rewriter,
- Region ®ion, RegionParent *parent);
+ Region ®ion, Location loc);
/// Converts a block by traversing its operations sequentially, attempting to
/// match a pattern. If there is no match, recurses the operations regions if
// Traverse any held regions.
for (auto ®ion : op.getRegions())
- if (!region.empty() && failed(convertRegion(rewriter, region, &op)))
+ if (!region.empty() &&
+ failed(convertRegion(rewriter, region, op.getLoc())))
return failure();
}
return success();
}
-template <typename RegionParent>
LogicalResult
FunctionConverter::convertRegion(DialectConversionRewriter &rewriter,
- Region ®ion, RegionParent *parent) {
+ Region ®ion, Location loc) {
assert(!region.empty() && "expected non-empty region");
// Create the arguments of each of the blocks in the region. If a type
if (dialectConversion) {
for (Block &block : region)
for (auto *arg : block.getArguments())
- if (failed(convertArgument(rewriter, arg, parent->getLoc())))
+ if (failed(convertArgument(rewriter, arg, loc)))
return failure();
}
// If some blocks are not reachable through successor chains, they should have
// been removed by the DCE before this.
if (visitedBlocks.size() != std::distance(region.begin(), region.end()))
- return parent->emitError("unreachable blocks were not converted");
+ return rewriter.getContext()->emitError(loc)
+ << "unreachable blocks were not converted";
return success();
}
// Rewrite the function body.
DialectConversionRewriter rewriter(f);
- if (failed(convertRegion(rewriter, f->getBody(), f))) {
+ if (failed(convertRegion(rewriter, f->getBody(), f->getLoc()))) {
// Reset any of the generated rewrites.
rewriter.discardRewrites();
return failure();