|
22 | 22 | #include "mlir/IR/BuiltinOps.h"
|
23 | 23 | #include "llvm/ADT/SetVector.h"
|
24 | 24 | #include "llvm/ADT/SmallVector.h"
|
| 25 | +#include "llvm/ADT/TypeSwitch.h" |
25 | 26 |
|
26 | 27 | namespace flangomp {
|
27 | 28 | #define GEN_PASS_DEF_FUNCTIONFILTERINGPASS
|
@@ -443,16 +444,38 @@ class FunctionFilteringPass
|
443 | 444 | builder.getI64IntegerAttr(0));
|
444 | 445 |
|
445 | 446 | if (auto shape = declareOp.getShape()) {
|
| 447 | + // The pre-cg rewrite pass requires the shape to be defined by one of |
| 448 | + // fir.shape, fir.shapeshift or fir.shift, so we need to make sure it's |
| 449 | + // still defined by one of these after this pass. |
446 | 450 | Operation *shapeOp = shape.getDefiningOp();
|
447 |
| - unsigned numArgs = shapeOp->getNumOperands(); |
448 |
| - if (isa<fir::ShapeShiftOp>(shapeOp)) |
449 |
| - numArgs /= 2; |
450 |
| - |
451 |
| - // Since the pre-cg rewrite pass requires the shape to be defined by one |
452 |
| - // of fir.shape, fir.shapeshift or fir.shift, we need to create one of |
453 |
| - // these. |
454 |
| - llvm::SmallVector<Value> extents(numArgs, zero); |
455 |
| - auto newShape = builder.create<fir::ShapeOp>(shape.getLoc(), extents); |
| 451 | + llvm::SmallVector<Value> extents(shapeOp->getNumOperands(), zero); |
| 452 | + Value newShape = |
| 453 | + llvm::TypeSwitch<Operation *, Value>(shapeOp) |
| 454 | + .Case([&](fir::ShapeOp op) { |
| 455 | + return builder.create<fir::ShapeOp>(op.getLoc(), extents); |
| 456 | + }) |
| 457 | + .Case([&](fir::ShapeShiftOp op) { |
| 458 | + auto type = fir::ShapeShiftType::get(op.getContext(), |
| 459 | + extents.size() / 2); |
| 460 | + return builder.create<fir::ShapeShiftOp>(op.getLoc(), type, |
| 461 | + extents); |
| 462 | + }) |
| 463 | + .Case([&](fir::ShiftOp op) { |
| 464 | + auto type = |
| 465 | + fir::ShiftType::get(op.getContext(), extents.size()); |
| 466 | + return builder.create<fir::ShiftOp>(op.getLoc(), type, |
| 467 | + extents); |
| 468 | + }) |
| 469 | + .Default([](Operation *op) { |
| 470 | + op->emitOpError() |
| 471 | + << "hlfir.declare shape expected to be one of: " |
| 472 | + "fir.shape, fir.shapeshift or fir.shift"; |
| 473 | + return nullptr; |
| 474 | + }); |
| 475 | + |
| 476 | + if (!newShape) |
| 477 | + return failure(); |
| 478 | + |
456 | 479 | declareOp.getShapeMutable().assign(newShape);
|
457 | 480 | }
|
458 | 481 |
|
|
0 commit comments