@@ -1856,6 +1856,44 @@ void ConversionPatternRewriterImpl::replaceOp(
18561856 Operation *op, SmallVector<SmallVector<Value>> &&newValues) {
18571857 assert (newValues.size () == op->getNumResults () &&
18581858 " incorrect number of replacement values" );
1859+ LLVM_DEBUG ({
1860+ logger.startLine () << " ** Replace : '" << op->getName () << " '(" << op
1861+ << " )\n " ;
1862+ if (currentTypeConverter) {
1863+ // If the user-provided replacement types are different from the
1864+ // legalized types, as per the current type converter, print a note.
1865+ // In most cases, the replacement types are expected to match the types
1866+ // produced by the type converter, so this could indicate a bug in the
1867+ // user code.
1868+ for (auto [result, repls] :
1869+ llvm::zip_equal (op->getResults (), newValues)) {
1870+ Type resultType = result.getType ();
1871+ auto logProlog = [&, repls = repls]() {
1872+ logger.startLine () << " Note: Replacing op result of type "
1873+ << resultType << " with value(s) of type (" ;
1874+ llvm::interleaveComma (repls, logger.getOStream (), [&](Value v) {
1875+ logger.getOStream () << v.getType ();
1876+ });
1877+ logger.getOStream () << " )" ;
1878+ };
1879+ SmallVector<Type> convertedTypes;
1880+ if (failed (currentTypeConverter->convertTypes (resultType,
1881+ convertedTypes))) {
1882+ logProlog ();
1883+ logger.getOStream () << " , but the type converter failed to legalize "
1884+ " the original type.\n " ;
1885+ continue ;
1886+ }
1887+ if (TypeRange (convertedTypes) != TypeRange (ValueRange (repls))) {
1888+ logProlog ();
1889+ logger.getOStream () << " , but the legalized type(s) is/are (" ;
1890+ llvm::interleaveComma (convertedTypes, logger.getOStream (),
1891+ [&](Type t) { logger.getOStream () << t; });
1892+ logger.getOStream () << " )\n " ;
1893+ }
1894+ }
1895+ }
1896+ });
18591897
18601898 if (!config.allowPatternRollback ) {
18611899 // Pattern rollback is not allowed: materialize all IR changes immediately.
@@ -2072,10 +2110,6 @@ void ConversionPatternRewriter::replaceOp(Operation *op, Operation *newOp) {
20722110void ConversionPatternRewriter::replaceOp (Operation *op, ValueRange newValues) {
20732111 assert (op->getNumResults () == newValues.size () &&
20742112 " incorrect # of replacement values" );
2075- LLVM_DEBUG ({
2076- impl->logger .startLine ()
2077- << " ** Replace : '" << op->getName () << " '(" << op << " )\n " ;
2078- });
20792113
20802114 // If the current insertion point is before the erased operation, we adjust
20812115 // the insertion point to be after the operation.
@@ -2093,10 +2127,6 @@ void ConversionPatternRewriter::replaceOpWithMultiple(
20932127 Operation *op, SmallVector<SmallVector<Value>> &&newValues) {
20942128 assert (op->getNumResults () == newValues.size () &&
20952129 " incorrect # of replacement values" );
2096- LLVM_DEBUG ({
2097- impl->logger .startLine ()
2098- << " ** Replace : '" << op->getName () << " '(" << op << " )\n " ;
2099- });
21002130
21012131 // If the current insertion point is before the erased operation, we adjust
21022132 // the insertion point to be after the operation.
0 commit comments