[flang-commits] [flang] 1f31795 - [NFC] Cleanup code to get back in synch for upstreaming.
Eric Schweitz via flang-commits
flang-commits at lists.llvm.org
Mon Apr 25 15:57:15 PDT 2022
Author: Eric Schweitz
Date: 2022-04-25T15:57:04-07:00
New Revision: 1f31795cb38949bec45786dc7e125ddac6d54564
URL: https://github.com/llvm/llvm-project/commit/1f31795cb38949bec45786dc7e125ddac6d54564
DIFF: https://github.com/llvm/llvm-project/commit/1f31795cb38949bec45786dc7e125ddac6d54564.diff
LOG: [NFC] Cleanup code to get back in synch for upstreaming.
Differential Revision: https://reviews.llvm.org/D124410
Added:
Modified:
flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
index e1db692868829..989caab35a294 100644
--- a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
+++ b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
@@ -25,29 +25,26 @@
// Codegen rewrite: rewriting of subgraphs of ops
//===----------------------------------------------------------------------===//
-using namespace fir;
-using namespace mlir;
-
#define DEBUG_TYPE "flang-codegen-rewrite"
static void populateShape(llvm::SmallVectorImpl<mlir::Value> &vec,
- ShapeOp shape) {
+ fir::ShapeOp shape) {
vec.append(shape.getExtents().begin(), shape.getExtents().end());
}
// Operands of fir.shape_shift split into two vectors.
static void populateShapeAndShift(llvm::SmallVectorImpl<mlir::Value> &shapeVec,
llvm::SmallVectorImpl<mlir::Value> &shiftVec,
- ShapeShiftOp shift) {
- auto endIter = shift.getPairs().end();
- for (auto i = shift.getPairs().begin(); i != endIter;) {
+ fir::ShapeShiftOp shift) {
+ for (auto i = shift.getPairs().begin(), endIter = shift.getPairs().end();
+ i != endIter;) {
shiftVec.push_back(*i++);
shapeVec.push_back(*i++);
}
}
static void populateShift(llvm::SmallVectorImpl<mlir::Value> &vec,
- ShiftOp shift) {
+ fir::ShiftOp shift) {
vec.append(shift.getOrigins().begin(), shift.getOrigins().end());
}
@@ -72,27 +69,26 @@ namespace {
/// (!fir.ref<!fir.array<?xi32>>, index, index, index, index, index) ->
/// !fir.box<!fir.array<?xi32>>
/// ```
-class EmboxConversion : public mlir::OpRewritePattern<EmboxOp> {
+class EmboxConversion : public mlir::OpRewritePattern<fir::EmboxOp> {
public:
using OpRewritePattern::OpRewritePattern;
mlir::LogicalResult
- matchAndRewrite(EmboxOp embox,
+ matchAndRewrite(fir::EmboxOp embox,
mlir::PatternRewriter &rewriter) const override {
- auto shapeVal = embox.getShape();
// If the embox does not include a shape, then do not convert it
- if (shapeVal)
+ if (auto shapeVal = embox.getShape())
return rewriteDynamicShape(embox, rewriter, shapeVal);
- if (auto boxTy = embox.getType().dyn_cast<BoxType>())
- if (auto seqTy = boxTy.getEleTy().dyn_cast<SequenceType>())
+ if (auto boxTy = embox.getType().dyn_cast<fir::BoxType>())
+ if (auto seqTy = boxTy.getEleTy().dyn_cast<fir::SequenceType>())
if (seqTy.hasConstantShape())
return rewriteStaticShape(embox, rewriter, seqTy);
return mlir::failure();
}
- mlir::LogicalResult rewriteStaticShape(EmboxOp embox,
+ mlir::LogicalResult rewriteStaticShape(fir::EmboxOp embox,
mlir::PatternRewriter &rewriter,
- SequenceType seqTy) const {
+ fir::SequenceType seqTy) const {
auto loc = embox.getLoc();
llvm::SmallVector<mlir::Value> shapeOpers;
auto idxTy = rewriter.getIndexType();
@@ -101,7 +97,7 @@ class EmboxConversion : public mlir::OpRewritePattern<EmboxOp> {
auto extVal = rewriter.create<mlir::arith::ConstantOp>(loc, idxTy, iAttr);
shapeOpers.push_back(extVal);
}
- auto xbox = rewriter.create<cg::XEmboxOp>(
+ auto xbox = rewriter.create<fir::cg::XEmboxOp>(
loc, embox.getType(), embox.getMemref(), shapeOpers, llvm::None,
llvm::None, llvm::None, llvm::None, embox.getTypeparams());
LLVM_DEBUG(llvm::dbgs() << "rewriting " << embox << " to " << xbox << '\n');
@@ -109,17 +105,17 @@ class EmboxConversion : public mlir::OpRewritePattern<EmboxOp> {
return mlir::success();
}
- mlir::LogicalResult rewriteDynamicShape(EmboxOp embox,
+ mlir::LogicalResult rewriteDynamicShape(fir::EmboxOp embox,
mlir::PatternRewriter &rewriter,
mlir::Value shapeVal) const {
auto loc = embox.getLoc();
- auto shapeOp = dyn_cast<ShapeOp>(shapeVal.getDefiningOp());
llvm::SmallVector<mlir::Value> shapeOpers;
llvm::SmallVector<mlir::Value> shiftOpers;
- if (shapeOp) {
+ if (auto shapeOp = mlir::dyn_cast<fir::ShapeOp>(shapeVal.getDefiningOp())) {
populateShape(shapeOpers, shapeOp);
} else {
- auto shiftOp = dyn_cast<ShapeShiftOp>(shapeVal.getDefiningOp());
+ auto shiftOp =
+ mlir::dyn_cast<fir::ShapeShiftOp>(shapeVal.getDefiningOp());
assert(shiftOp && "shape is neither fir.shape nor fir.shape_shift");
populateShapeAndShift(shapeOpers, shiftOpers, shiftOp);
}
@@ -127,7 +123,8 @@ class EmboxConversion : public mlir::OpRewritePattern<EmboxOp> {
llvm::SmallVector<mlir::Value> subcompOpers;
llvm::SmallVector<mlir::Value> substrOpers;
if (auto s = embox.getSlice())
- if (auto sliceOp = dyn_cast_or_null<SliceOp>(s.getDefiningOp())) {
+ if (auto sliceOp =
+ mlir::dyn_cast_or_null<fir::SliceOp>(s.getDefiningOp())) {
sliceOpers.assign(sliceOp.getTriples().begin(),
sliceOp.getTriples().end());
subcompOpers.assign(sliceOp.getFields().begin(),
@@ -135,7 +132,7 @@ class EmboxConversion : public mlir::OpRewritePattern<EmboxOp> {
substrOpers.assign(sliceOp.getSubstr().begin(),
sliceOp.getSubstr().end());
}
- auto xbox = rewriter.create<cg::XEmboxOp>(
+ auto xbox = rewriter.create<fir::cg::XEmboxOp>(
loc, embox.getType(), embox.getMemref(), shapeOpers, shiftOpers,
sliceOpers, subcompOpers, substrOpers, embox.getTypeparams());
LLVM_DEBUG(llvm::dbgs() << "rewriting " << embox << " to " << xbox << '\n');
@@ -156,22 +153,24 @@ class EmboxConversion : public mlir::OpRewritePattern<EmboxOp> {
/// %5 = fircg.ext_rebox %3(%13) origin %12 : (!fir.box<!fir.array<?xi32>>,
/// index, index) -> !fir.box<!fir.array<?xi32>>
/// ```
-class ReboxConversion : public mlir::OpRewritePattern<ReboxOp> {
+class ReboxConversion : public mlir::OpRewritePattern<fir::ReboxOp> {
public:
using OpRewritePattern::OpRewritePattern;
mlir::LogicalResult
- matchAndRewrite(ReboxOp rebox,
+ matchAndRewrite(fir::ReboxOp rebox,
mlir::PatternRewriter &rewriter) const override {
auto loc = rebox.getLoc();
llvm::SmallVector<mlir::Value> shapeOpers;
llvm::SmallVector<mlir::Value> shiftOpers;
if (auto shapeVal = rebox.getShape()) {
- if (auto shapeOp = dyn_cast<ShapeOp>(shapeVal.getDefiningOp()))
+ if (auto shapeOp = mlir::dyn_cast<fir::ShapeOp>(shapeVal.getDefiningOp()))
populateShape(shapeOpers, shapeOp);
- else if (auto shiftOp = dyn_cast<ShapeShiftOp>(shapeVal.getDefiningOp()))
+ else if (auto shiftOp =
+ mlir::dyn_cast<fir::ShapeShiftOp>(shapeVal.getDefiningOp()))
populateShapeAndShift(shapeOpers, shiftOpers, shiftOp);
- else if (auto shiftOp = dyn_cast<ShiftOp>(shapeVal.getDefiningOp()))
+ else if (auto shiftOp =
+ mlir::dyn_cast<fir::ShiftOp>(shapeVal.getDefiningOp()))
populateShift(shiftOpers, shiftOp);
else
return mlir::failure();
@@ -180,7 +179,8 @@ class ReboxConversion : public mlir::OpRewritePattern<ReboxOp> {
llvm::SmallVector<mlir::Value> subcompOpers;
llvm::SmallVector<mlir::Value> substrOpers;
if (auto s = rebox.getSlice())
- if (auto sliceOp = dyn_cast_or_null<SliceOp>(s.getDefiningOp())) {
+ if (auto sliceOp =
+ mlir::dyn_cast_or_null<fir::SliceOp>(s.getDefiningOp())) {
sliceOpers.append(sliceOp.getTriples().begin(),
sliceOp.getTriples().end());
subcompOpers.append(sliceOp.getFields().begin(),
@@ -189,7 +189,7 @@ class ReboxConversion : public mlir::OpRewritePattern<ReboxOp> {
sliceOp.getSubstr().end());
}
- auto xRebox = rewriter.create<cg::XReboxOp>(
+ auto xRebox = rewriter.create<fir::cg::XReboxOp>(
loc, rebox.getType(), rebox.getBox(), shapeOpers, shiftOpers,
sliceOpers, subcompOpers, substrOpers);
LLVM_DEBUG(llvm::dbgs()
@@ -212,22 +212,24 @@ class ReboxConversion : public mlir::OpRewritePattern<ReboxOp> {
/// (!fir.ref<!fir.array<?xi32>>, index, index, index, index, index, index) ->
/// !fir.ref<i32>
/// ```
-class ArrayCoorConversion : public mlir::OpRewritePattern<ArrayCoorOp> {
+class ArrayCoorConversion : public mlir::OpRewritePattern<fir::ArrayCoorOp> {
public:
using OpRewritePattern::OpRewritePattern;
mlir::LogicalResult
- matchAndRewrite(ArrayCoorOp arrCoor,
+ matchAndRewrite(fir::ArrayCoorOp arrCoor,
mlir::PatternRewriter &rewriter) const override {
auto loc = arrCoor.getLoc();
llvm::SmallVector<mlir::Value> shapeOpers;
llvm::SmallVector<mlir::Value> shiftOpers;
if (auto shapeVal = arrCoor.getShape()) {
- if (auto shapeOp = dyn_cast<ShapeOp>(shapeVal.getDefiningOp()))
+ if (auto shapeOp = mlir::dyn_cast<fir::ShapeOp>(shapeVal.getDefiningOp()))
populateShape(shapeOpers, shapeOp);
- else if (auto shiftOp = dyn_cast<ShapeShiftOp>(shapeVal.getDefiningOp()))
+ else if (auto shiftOp =
+ mlir::dyn_cast<fir::ShapeShiftOp>(shapeVal.getDefiningOp()))
populateShapeAndShift(shapeOpers, shiftOpers, shiftOp);
- else if (auto shiftOp = dyn_cast<ShiftOp>(shapeVal.getDefiningOp()))
+ else if (auto shiftOp =
+ mlir::dyn_cast<fir::ShiftOp>(shapeVal.getDefiningOp()))
populateShift(shiftOpers, shiftOp);
else
return mlir::failure();
@@ -235,7 +237,8 @@ class ArrayCoorConversion : public mlir::OpRewritePattern<ArrayCoorOp> {
llvm::SmallVector<mlir::Value> sliceOpers;
llvm::SmallVector<mlir::Value> subcompOpers;
if (auto s = arrCoor.getSlice())
- if (auto sliceOp = dyn_cast_or_null<SliceOp>(s.getDefiningOp())) {
+ if (auto sliceOp =
+ mlir::dyn_cast_or_null<fir::SliceOp>(s.getDefiningOp())) {
sliceOpers.append(sliceOp.getTriples().begin(),
sliceOp.getTriples().end());
subcompOpers.append(sliceOp.getFields().begin(),
@@ -244,7 +247,7 @@ class ArrayCoorConversion : public mlir::OpRewritePattern<ArrayCoorOp> {
"Don't allow substring operations on array_coor. This "
"restriction may be lifted in the future.");
}
- auto xArrCoor = rewriter.create<cg::XArrayCoorOp>(
+ auto xArrCoor = rewriter.create<fir::cg::XArrayCoorOp>(
loc, arrCoor.getType(), arrCoor.getMemref(), shapeOpers, shiftOpers,
sliceOpers, subcompOpers, arrCoor.getIndices(),
arrCoor.getTypeparams());
@@ -255,20 +258,22 @@ class ArrayCoorConversion : public mlir::OpRewritePattern<ArrayCoorOp> {
}
};
-class CodeGenRewrite : public CodeGenRewriteBase<CodeGenRewrite> {
+class CodeGenRewrite : public fir::CodeGenRewriteBase<CodeGenRewrite> {
public:
void runOnOperation() override final {
auto op = getOperation();
auto &context = getContext();
mlir::OpBuilder rewriter(&context);
mlir::ConversionTarget target(context);
- target.addLegalDialect<mlir::arith::ArithmeticDialect, FIROpsDialect,
- FIRCodeGenDialect, mlir::func::FuncDialect>();
- target.addIllegalOp<ArrayCoorOp>();
- target.addIllegalOp<ReboxOp>();
- target.addDynamicallyLegalOp<EmboxOp>([](EmboxOp embox) {
- return !(embox.getShape() ||
- embox.getType().cast<BoxType>().getEleTy().isa<SequenceType>());
+ target.addLegalDialect<mlir::arith::ArithmeticDialect, fir::FIROpsDialect,
+ fir::FIRCodeGenDialect, mlir::func::FuncDialect>();
+ target.addIllegalOp<fir::ArrayCoorOp>();
+ target.addIllegalOp<fir::ReboxOp>();
+ target.addDynamicallyLegalOp<fir::EmboxOp>([](fir::EmboxOp embox) {
+ return !(embox.getShape() || embox.getType()
+ .cast<fir::BoxType>()
+ .getEleTy()
+ .isa<fir::SequenceType>());
});
mlir::RewritePatternSet patterns(&context);
patterns.insert<EmboxConversion, ArrayCoorConversion, ReboxConversion>(
More information about the flang-commits
mailing list