Skip to content

Commit 65099e8

Browse files
committed
Revert "[mlir][Func] Delete DecomposeCallGraphTypes.cpp (llvm#117424)"
This reverts commit 7267c85. Signed-off-by: nithinsubbiah <[email protected]>
1 parent 967e3a9 commit 65099e8

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===- DecomposeCallGraphTypes.h - CG type decompositions -------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// Conversion patterns for decomposing types along call graph edges. That is,
10+
// decomposing types for calls, returns, and function args.
11+
//
12+
// TODO: Make this handle dialect-defined functions, calls, and returns.
13+
// Currently, the generic interfaces aren't sophisticated enough for the
14+
// types of mutations that we are doing here.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef MLIR_DIALECT_FUNC_TRANSFORMS_DECOMPOSECALLGRAPHTYPES_H
19+
#define MLIR_DIALECT_FUNC_TRANSFORMS_DECOMPOSECALLGRAPHTYPES_H
20+
21+
#include "mlir/Transforms/DialectConversion.h"
22+
#include <optional>
23+
24+
namespace mlir {
25+
26+
/// Populates the patterns needed to drive the conversion process for
27+
/// decomposing call graph types with the given `TypeConverter`.
28+
void populateDecomposeCallGraphTypesPatterns(MLIRContext *context,
29+
const TypeConverter &typeConverter,
30+
RewritePatternSet &patterns);
31+
32+
} // namespace mlir
33+
34+
#endif // MLIR_DIALECT_FUNC_TRANSFORMS_DECOMPOSECALLGRAPHTYPES_H

mlir/lib/Dialect/Func/Transforms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_mlir_dialect_library(MLIRFuncTransforms
2+
DecomposeCallGraphTypes.cpp
23
DuplicateFunctionElimination.cpp
34
FuncConversions.cpp
45
OneToNFuncConversions.cpp

mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ class ReturnOpTypeConversion : public OpConversionPattern<ReturnOp> {
116116
using OpConversionPattern<ReturnOp>::OpConversionPattern;
117117

118118
LogicalResult
119-
matchAndRewrite(ReturnOp op, OneToNOpAdaptor adaptor,
119+
matchAndRewrite(ReturnOp op, OpAdaptor adaptor,
120120
ConversionPatternRewriter &rewriter) const final {
121-
rewriter.replaceOpWithNewOp<ReturnOp>(op,
122-
flattenValues(adaptor.getOperands()));
121+
// For a return, all operands go to the results of the parent, so
122+
// rewrite them all.
123+
rewriter.modifyOpInPlace(op,
124+
[&] { op->setOperands(adaptor.getOperands()); });
123125
return success();
124126
}
125127
};

mlir/lib/Transforms/Utils/DialectConversion.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2565,7 +2565,6 @@ legalizeUnresolvedMaterialization(RewriterBase &rewriter,
25652565
if (newMaterialization) {
25662566
assert(newMaterialization.getType() == outputType &&
25672567
"materialization callback produced value of incorrect type");
2568-
#endif // NDEBUG
25692568
rewriter.replaceOp(op, newMaterialization);
25702569
return success();
25712570
}

mlir/test/lib/Dialect/Func/TestDecomposeCallGraphTypes.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "TestDialect.h"
1010
#include "TestOps.h"
1111
#include "mlir/Dialect/Func/IR/FuncOps.h"
12-
#include "mlir/Dialect/Func/Transforms/FuncConversions.h"
12+
#include "mlir/Dialect/Func/Transforms/DecomposeCallGraphTypes.h"
1313
#include "mlir/IR/Builders.h"
1414
#include "mlir/Pass/Pass.h"
1515
#include "mlir/Transforms/DialectConversion.h"
@@ -142,10 +142,7 @@ struct TestDecomposeCallGraphTypes
142142
typeConverter.addArgumentMaterialization(buildMakeTupleOp);
143143
typeConverter.addTargetMaterialization(buildDecomposeTuple);
144144

145-
populateFunctionOpInterfaceTypeConversionPattern<func::FuncOp>(
146-
patterns, typeConverter);
147-
populateReturnOpTypeConversionPattern(patterns, typeConverter);
148-
populateCallOpTypeConversionPattern(patterns, typeConverter);
145+
populateDecomposeCallGraphTypesPatterns(context, typeConverter, patterns);
149146

150147
if (failed(applyPartialConversion(module, target, std::move(patterns))))
151148
return signalPassFailure();

0 commit comments

Comments
 (0)