Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1900,8 +1900,7 @@ hlfir::ShapeOfOp::canonicalize(ShapeOfOp shapeOf,
// shape information is not available at compile time
return llvm::LogicalResult::failure();

rewriter.replaceAllUsesWith(shapeOf.getResult(), shape);
rewriter.eraseOp(shapeOf);
rewriter.replaceOp(shapeOf, shape);
return llvm::LogicalResult::success();
}

Expand Down
6 changes: 1 addition & 5 deletions flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,8 @@ struct AssociateOpConversion

mlir::Type associateHlfirVarType = associate.getResultTypes()[0];
hlfirVar = adjustVar(hlfirVar, associateHlfirVarType);
associate.getResult(0).replaceAllUsesWith(hlfirVar);

mlir::Type associateFirVarType = associate.getResultTypes()[1];
firVar = adjustVar(firVar, associateFirVarType);
associate.getResult(1).replaceAllUsesWith(firVar);
associate.getResult(2).replaceAllUsesWith(flag);
// FIXME: note that the AssociateOp that is being erased
// here will continue to be a user of the original Source
// operand (e.g. a result of hlfir.elemental), because
Expand All @@ -472,7 +468,7 @@ struct AssociateOpConversion
// the conversions, so that we can analyze HLFIR in its
// original form and decide which of the AssociateOp
// users of hlfir.expr can reuse the buffer (if it can).
rewriter.eraseOp(associate);
rewriter.replaceOp(associate, {hlfirVar, firVar, flag});
};

// If this is the last use of the expression value and this is an hlfir.expr
Expand Down
3 changes: 1 addition & 2 deletions flang/lib/Optimizer/HLFIR/Transforms/InlineElementals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ class InlineElementalConversion
elemental.getLoc(), builder, elemental, apply.getIndices());

// remove the old elemental and all of the bookkeeping
rewriter.replaceAllUsesWith(apply.getResult(), yield.getElementValue());
rewriter.replaceOp(apply, {yield.getElementValue()});
rewriter.eraseOp(yield);
rewriter.eraseOp(apply);
rewriter.eraseOp(destroy);
rewriter.eraseOp(elemental);

Expand Down
7 changes: 2 additions & 5 deletions flang/lib/Optimizer/OpenMP/SimdOnly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,13 @@ class SimdOnlyConversionPattern : public mlir::RewritePattern {
return mlir::success();
}
if (auto mapInfoOp = mlir::dyn_cast<mlir::omp::MapInfoOp>(op)) {
mapInfoOp.getResult().replaceAllUsesWith(mapInfoOp.getVarPtr());
rewriter.eraseOp(mapInfoOp);
rewriter.replaceOp(mapInfoOp, {mapInfoOp.getVarPtr()});
return mlir::success();
}

// Might be leftover after parse tree rewriting
if (auto threadPrivateOp = mlir::dyn_cast<mlir::omp::ThreadprivateOp>(op)) {
threadPrivateOp.getTlsAddr().replaceAllUsesWith(
threadPrivateOp.getSymAddr());
rewriter.eraseOp(threadPrivateOp);
rewriter.replaceOp(threadPrivateOp, {threadPrivateOp.getSymAddr()});
return mlir::success();
}

Expand Down
5 changes: 1 addition & 4 deletions flang/lib/Optimizer/Transforms/AffineDemotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ class ConvertConversion : public mlir::OpRewritePattern<fir::ConvertOp> {
op.getValue());
return success();
}
rewriter.startOpModification(op->getParentOp());
op.getResult().replaceAllUsesWith(op.getValue());
rewriter.finalizeOpModification(op->getParentOp());
rewriter.eraseOp(op);
rewriter.replaceOp(op, op.getValue());
}
return success();
}
Expand Down
3 changes: 0 additions & 3 deletions flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,6 @@ class ArrayUpdateConversion : public ArrayUpdateConversionBase<ArrayUpdateOp> {
auto lhsEltRefType = toRefType(update.getMerge().getType());
auto [_, lhsLoadResult] = materializeAssignment(
loc, rewriter, update, assignElement, lhsEltRefType);
update.replaceAllUsesWith(lhsLoadResult);
rewriter.replaceOp(update, lhsLoadResult);
return mlir::success();
}
Expand All @@ -1287,7 +1286,6 @@ class ArrayModifyConversion : public ArrayUpdateConversionBase<ArrayModifyOp> {
auto lhsEltRefType = modify.getResult(0).getType();
auto [lhsEltCoor, lhsLoadResult] = materializeAssignment(
loc, rewriter, modify, assignElement, lhsEltRefType);
modify.replaceAllUsesWith(mlir::ValueRange{lhsEltCoor, lhsLoadResult});
rewriter.replaceOp(modify, mlir::ValueRange{lhsEltCoor, lhsLoadResult});
return mlir::success();
}
Expand Down Expand Up @@ -1339,7 +1337,6 @@ class ArrayAccessConversion : public ArrayUpdateConversionBase<ArrayAccessOp> {
// This array_access is associated with an array_amend and there is a
// conflict. Make a copy to store into.
auto result = referenceToClone(loc, rewriter, access);
access.replaceAllUsesWith(result);
rewriter.replaceOp(access, result);
return mlir::success();
}
Expand Down
9 changes: 2 additions & 7 deletions flang/lib/Optimizer/Transforms/FIRToSCF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "flang/Optimizer/Dialect/FIRDialect.h"
#include "flang/Optimizer/Transforms/Passes.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Transforms/DialectConversion.h"
#include "mlir/Transforms/WalkPatternRewriteDriver.h"

namespace fir {
#define GEN_PASS_DEF_FIRTOSCFPASS
Expand Down Expand Up @@ -201,12 +201,7 @@ void FIRToSCFPass::runOnOperation() {
mlir::RewritePatternSet patterns(&getContext());
patterns.add<DoLoopConversion, IterWhileConversion, IfConversion>(
patterns.getContext());
mlir::ConversionTarget target(getContext());
target.addIllegalOp<fir::DoLoopOp, fir::IterWhileOp, fir::IfOp>();
target.markUnknownOpDynamicallyLegal([](mlir::Operation *) { return true; });
if (failed(
applyPartialConversion(getOperation(), target, std::move(patterns))))
signalPassFailure();
walkAndApplyPatterns(getOperation(), std::move(patterns));
}

std::unique_ptr<mlir::Pass> fir::createFIRToSCFPass() {
Expand Down
3 changes: 1 addition & 2 deletions flang/lib/Optimizer/Transforms/OptimizeArrayRepacking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ PackingOfContiguous::matchAndRewrite(fir::PackArrayOp op,
mlir::PatternRewriter &rewriter) const {
mlir::Value box = op.getArray();
if (hlfir::isSimplyContiguous(box, !op.getInnermost())) {
rewriter.replaceAllUsesWith(op, box);
rewriter.eraseOp(op);
rewriter.replaceOp(op, box);
return mlir::success();
}
return mlir::failure();
Expand Down
5 changes: 1 addition & 4 deletions flang/lib/Optimizer/Transforms/StackArrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,7 @@ AllocMemConversion::matchAndRewrite(fir::AllocMemOp allocmem,
// replace references to heap allocation with references to stack allocation
mlir::Value newValue = convertAllocationType(
rewriter, allocmem.getLoc(), allocmem.getResult(), alloca->getResult());
rewriter.replaceAllUsesWith(allocmem.getResult(), newValue);

// remove allocmem operation
rewriter.eraseOp(allocmem.getOperation());
rewriter.replaceOp(allocmem, newValue);

return mlir::success();
}
Expand Down