Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/Transforms/Utils/DialectConversion.cpp
Show First 20 Lines • Show All 1,288 Lines • ▼ Show 20 Lines | void ConversionPatternRewriterImpl::notifyRegionWasClonedBefore( | ||||||||||||||||||||||
// This original region has already had its conversion set computed, so there | // This original region has already had its conversion set computed, so there | ||||||||||||||||||||||
// shouldn't be any new failures. | // shouldn't be any new failures. | ||||||||||||||||||||||
(void)result; | (void)result; | ||||||||||||||||||||||
assert(succeeded(result) && "expected region to have no unreachable blocks"); | assert(succeeded(result) && "expected region to have no unreachable blocks"); | ||||||||||||||||||||||
} | } | ||||||||||||||||||||||
LogicalResult ConversionPatternRewriterImpl::notifyMatchFailure( | LogicalResult ConversionPatternRewriterImpl::notifyMatchFailure( | ||||||||||||||||||||||
Location loc, function_ref<void(Diagnostic &)> reasonCallback) { | Location loc, function_ref<void(Diagnostic &)> reasonCallback) { | ||||||||||||||||||||||
LLVM_DEBUG({ | LLVM_DEBUG({ | ||||||||||||||||||||||
// If it returns failure, it means there's no debugging handler registered. | |||||||||||||||||||||||
(void)emitDebugging(loc, reasonCallback); | |||||||||||||||||||||||
rriddle: This isn't the same as LLVM_DEBUG. LLVM_DEBUG also handles checking if the current debug mode… | |||||||||||||||||||||||
Reverted back to use LLVM_DEBUG I think that's enough for the initial support Chia-hungDuan: Reverted back to use LLVM_DEBUG I think that's enough for the initial support | |||||||||||||||||||||||
Diagnostic diag(loc, DiagnosticSeverity::Remark); | Diagnostic diag(loc, DiagnosticSeverity::Remark); | ||||||||||||||||||||||
reasonCallback(diag); | reasonCallback(diag); | ||||||||||||||||||||||
logger.startLine() << "** Failure : " << diag.str() << "\n"; | logger.startLine() << "** Failure : " << diag.str() << "\n"; | ||||||||||||||||||||||
}); | }); | ||||||||||||||||||||||
return failure(); | return failure(); | ||||||||||||||||||||||
} | } | ||||||||||||||||||||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||||||||||||||||||||
// ConversionPatternRewriter | // ConversionPatternRewriter | ||||||||||||||||||||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||||||||||||||||||||
ConversionPatternRewriter::ConversionPatternRewriter(MLIRContext *ctx) | ConversionPatternRewriter::ConversionPatternRewriter(MLIRContext *ctx) | ||||||||||||||||||||||
: PatternRewriter(ctx), | : PatternRewriter(ctx), | ||||||||||||||||||||||
impl(new detail::ConversionPatternRewriterImpl(*this)) {} | impl(new detail::ConversionPatternRewriterImpl(*this)) {} | ||||||||||||||||||||||
ConversionPatternRewriter::~ConversionPatternRewriter() {} | ConversionPatternRewriter::~ConversionPatternRewriter() {} | ||||||||||||||||||||||
/// PatternRewriter hook for replacing the results of an operation when the | /// PatternRewriter hook for replacing the results of an operation when the | ||||||||||||||||||||||
/// given functor returns true. | /// given functor returns true. | ||||||||||||||||||||||
void ConversionPatternRewriter::replaceOpWithIf( | void ConversionPatternRewriter::replaceOpWithIf( | ||||||||||||||||||||||
Not Done ReplyInline Actions
nit: I would just inline all of these into the class. rriddle: nit: I would just inline all of these into the class. | |||||||||||||||||||||||
Operation *op, ValueRange newValues, bool *allUsesReplaced, | Operation *op, ValueRange newValues, bool *allUsesReplaced, | ||||||||||||||||||||||
llvm::unique_function<bool(OpOperand &) const> functor) { | llvm::unique_function<bool(OpOperand &) const> functor) { | ||||||||||||||||||||||
// TODO: To support this we will need to rework a bit of how replacements are | // TODO: To support this we will need to rework a bit of how replacements are | ||||||||||||||||||||||
// tracked, given that this isn't guranteed to replace all of the uses of an | // tracked, given that this isn't guranteed to replace all of the uses of an | ||||||||||||||||||||||
// operation. The main change is that now an operation can be replaced | // operation. The main change is that now an operation can be replaced | ||||||||||||||||||||||
// multiple times, in parts. The current "set" based tracking is mainly useful | // multiple times, in parts. The current "set" based tracking is mainly useful | ||||||||||||||||||||||
// for tracking if a replaced operation should be ignored, i.e. if all of the | // for tracking if a replaced operation should be ignored, i.e. if all of the | ||||||||||||||||||||||
// uses will be replaced. | // uses will be replaced. | ||||||||||||||||||||||
▲ Show 20 Lines • Show All 463 Lines • ▼ Show 20 Lines | auto canApply = [&](const Pattern &pattern) { | ||||||||||||||||||||||
return canApplyPattern(op, pattern, rewriter); | return canApplyPattern(op, pattern, rewriter); | ||||||||||||||||||||||
}; | }; | ||||||||||||||||||||||
// Functor that cleans up the rewriter state after a pattern failed to match. | // Functor that cleans up the rewriter state after a pattern failed to match. | ||||||||||||||||||||||
RewriterState curState = rewriterImpl.getCurrentState(); | RewriterState curState = rewriterImpl.getCurrentState(); | ||||||||||||||||||||||
auto onFailure = [&](const Pattern &pattern) { | auto onFailure = [&](const Pattern &pattern) { | ||||||||||||||||||||||
LLVM_DEBUG(logFailure(rewriterImpl.logger, "pattern failed to match")); | LLVM_DEBUG(logFailure(rewriterImpl.logger, "pattern failed to match")); | ||||||||||||||||||||||
rewriterImpl.resetState(curState); | rewriterImpl.resetState(curState); | ||||||||||||||||||||||
appliedPatterns.erase(&pattern); | appliedPatterns.erase(&pattern); | ||||||||||||||||||||||
}; | }; | ||||||||||||||||||||||
// Functor that performs additional legalization when a pattern is | // Functor that performs additional legalization when a pattern is | ||||||||||||||||||||||
// successfully applied. | // successfully applied. | ||||||||||||||||||||||
auto onSuccess = [&](const Pattern &pattern) { | auto onSuccess = [&](const Pattern &pattern) { | ||||||||||||||||||||||
Not Done ReplyInline ActionsWhat does the pattern debug log output look like with this? rriddle: What does the pattern debug log output look like with this? | |||||||||||||||||||||||
As you mentioned, the curly brackets may have little problem. Added a new line for output. Now it looks like Failed to apply pattern "(anonymous namespace)::TestRegionRewriteBlockMovement" on op: "test.region"() ( { ^bb0(%arg0: i64): // no predecessors br ^bb1(%arg0 : i64) ^bb1(%0: i64): // pred: ^bb0 "test.invalid"(%0) : (i64) -> () }) {legalizer.erase_old_blocks, legalizer.should_clone} : () -> () Chia-hungDuan: As you mentioned, the curly brackets may have little problem. Added a new line for output. Now… | |||||||||||||||||||||||
auto result = legalizePatternResult(op, pattern, rewriter, curState); | auto result = legalizePatternResult(op, pattern, rewriter, curState); | ||||||||||||||||||||||
appliedPatterns.erase(&pattern); | appliedPatterns.erase(&pattern); | ||||||||||||||||||||||
if (failed(result)) | if (failed(result)) | ||||||||||||||||||||||
rewriterImpl.resetState(curState); | rewriterImpl.resetState(curState); | ||||||||||||||||||||||
return result; | return result; | ||||||||||||||||||||||
}; | }; | ||||||||||||||||||||||
// Try to match and rewrite a pattern on this operation. | // Try to match and rewrite a pattern on this operation. | ||||||||||||||||||||||
▲ Show 20 Lines • Show All 1,053 Lines • Show Last 20 Lines |
This isn't the same as LLVM_DEBUG. LLVM_DEBUG also handles checking if the current debug mode enabled is dialect conversion. Can we just have a bool that is defaulted to true/false depending on notifyCallback, that gets explicitly set to true inside of an LLVM_DEBUG code block?