[mlir] Flip Async/GPU/MemRef/OpenACC/OpenMP/PDL dialects to prefixed

This flips all of the remaining dialects to prefixed except for linalg, which
will be done in a followup.

Differential Revision: https://reviews.llvm.org/D134995
This commit is contained in:
River Riddle 2022-09-30 16:06:29 -07:00
parent 0d7f3464ce
commit c692a11e69
11 changed files with 41 additions and 56 deletions

View File

@ -820,9 +820,9 @@ genACCEnterDataOp(Fortran::lower::AbstractConverter &converter,
firOpBuilder, currentLocation, operands, operandSegments); firOpBuilder, currentLocation, operands, operandSegments);
if (addAsyncAttr) if (addAsyncAttr)
enterDataOp.asyncAttr(firOpBuilder.getUnitAttr()); enterDataOp.setAsyncAttr(firOpBuilder.getUnitAttr());
if (addWaitAttr) if (addWaitAttr)
enterDataOp.waitAttr(firOpBuilder.getUnitAttr()); enterDataOp.setWaitAttr(firOpBuilder.getUnitAttr());
} }
static void static void
@ -896,11 +896,11 @@ genACCExitDataOp(Fortran::lower::AbstractConverter &converter,
firOpBuilder, currentLocation, operands, operandSegments); firOpBuilder, currentLocation, operands, operandSegments);
if (addAsyncAttr) if (addAsyncAttr)
exitDataOp.asyncAttr(firOpBuilder.getUnitAttr()); exitDataOp.setAsyncAttr(firOpBuilder.getUnitAttr());
if (addWaitAttr) if (addWaitAttr)
exitDataOp.waitAttr(firOpBuilder.getUnitAttr()); exitDataOp.setWaitAttr(firOpBuilder.getUnitAttr());
if (addFinalizeAttr) if (addFinalizeAttr)
exitDataOp.finalizeAttr(firOpBuilder.getUnitAttr()); exitDataOp.setFinalizeAttr(firOpBuilder.getUnitAttr());
} }
template <typename Op> template <typename Op>
@ -1010,11 +1010,11 @@ genACCUpdateOp(Fortran::lower::AbstractConverter &converter,
firOpBuilder, currentLocation, operands, operandSegments); firOpBuilder, currentLocation, operands, operandSegments);
if (addAsyncAttr) if (addAsyncAttr)
updateOp.asyncAttr(firOpBuilder.getUnitAttr()); updateOp.setAsyncAttr(firOpBuilder.getUnitAttr());
if (addWaitAttr) if (addWaitAttr)
updateOp.waitAttr(firOpBuilder.getUnitAttr()); updateOp.setWaitAttr(firOpBuilder.getUnitAttr());
if (addIfPresentAttr) if (addIfPresentAttr)
updateOp.ifPresentAttr(firOpBuilder.getUnitAttr()); updateOp.setIfPresentAttr(firOpBuilder.getUnitAttr());
} }
static void static void
@ -1116,7 +1116,7 @@ static void genACC(Fortran::lower::AbstractConverter &converter,
firOpBuilder, currentLocation, operands, operandSegments); firOpBuilder, currentLocation, operands, operandSegments);
if (addAsyncAttr) if (addAsyncAttr)
waitOp.asyncAttr(firOpBuilder.getUnitAttr()); waitOp.setAsyncAttr(firOpBuilder.getUnitAttr());
} }
void Fortran::lower::genOpenACCConstruct( void Fortran::lower::genOpenACCConstruct(

View File

@ -112,7 +112,8 @@ static bool privatizeVars(Op &op, Fortran::lower::AbstractConverter &converter,
// TODO: Add lastprivate support for sections construct, simd construct // TODO: Add lastprivate support for sections construct, simd construct
if (std::is_same_v<Op, omp::WsLoopOp>) { if (std::is_same_v<Op, omp::WsLoopOp>) {
omp::WsLoopOp *wsLoopOp = dyn_cast<omp::WsLoopOp>(&op); omp::WsLoopOp *wsLoopOp = dyn_cast<omp::WsLoopOp>(&op);
mlir::Operation *lastOper = wsLoopOp->region().back().getTerminator(); mlir::Operation *lastOper =
wsLoopOp->getRegion().back().getTerminator();
firOpBuilder.setInsertionPoint(lastOper); firOpBuilder.setInsertionPoint(lastOper);
// Our goal here is to introduce the following control flow // Our goal here is to introduce the following control flow
@ -150,7 +151,7 @@ static bool privatizeVars(Op &op, Fortran::lower::AbstractConverter &converter,
cmpOp = firOpBuilder.create<mlir::arith::CmpIOp>( cmpOp = firOpBuilder.create<mlir::arith::CmpIOp>(
wsLoopOp->getLoc(), mlir::arith::CmpIPredicate::eq, wsLoopOp->getLoc(), mlir::arith::CmpIPredicate::eq,
wsLoopOp->getRegion().front().getArguments()[0], wsLoopOp->getRegion().front().getArguments()[0],
wsLoopOp->upperBound()[0]); wsLoopOp->getUpperBound()[0]);
} }
mlir::scf::IfOp ifOp = firOpBuilder.create<mlir::scf::IfOp>( mlir::scf::IfOp ifOp = firOpBuilder.create<mlir::scf::IfOp>(
wsLoopOp->getLoc(), cmpOp, /*else*/ false); wsLoopOp->getLoc(), cmpOp, /*else*/ false);
@ -286,7 +287,7 @@ static void threadPrivatizeVars(Fortran::lower::AbstractConverter &converter,
assert(mlir::isa<mlir::omp::ThreadprivateOp>(op) && assert(mlir::isa<mlir::omp::ThreadprivateOp>(op) &&
"The threadprivate operation not created"); "The threadprivate operation not created");
mlir::Value symValue = mlir::Value symValue =
mlir::dyn_cast<mlir::omp::ThreadprivateOp>(op).sym_addr(); mlir::dyn_cast<mlir::omp::ThreadprivateOp>(op).getSymAddr();
return firOpBuilder.create<mlir::omp::ThreadprivateOp>( return firOpBuilder.create<mlir::omp::ThreadprivateOp>(
currentLocation, symValue.getType(), symValue); currentLocation, symValue.getType(), symValue);
}; };
@ -908,17 +909,18 @@ static omp::ReductionDeclareOp createReductionDecl(
modBuilder.create<omp::ReductionDeclareOp>(loc, reductionOpName, type); modBuilder.create<omp::ReductionDeclareOp>(loc, reductionOpName, type);
else else
return decl; return decl;
builder.createBlock(&decl.initializerRegion(), decl.initializerRegion().end(), builder.createBlock(&decl.getInitializerRegion(),
{type}, {loc}); decl.getInitializerRegion().end(), {type}, {loc});
builder.setInsertionPointToEnd(&decl.initializerRegion().back()); builder.setInsertionPointToEnd(&decl.getInitializerRegion().back());
Value init = getReductionInitValue(loc, type, reductionOpName, builder); Value init = getReductionInitValue(loc, type, reductionOpName, builder);
builder.create<omp::YieldOp>(loc, init); builder.create<omp::YieldOp>(loc, init);
builder.createBlock(&decl.reductionRegion(), decl.reductionRegion().end(), builder.createBlock(&decl.getReductionRegion(),
{type, type}, {loc, loc}); decl.getReductionRegion().end(), {type, type},
builder.setInsertionPointToEnd(&decl.reductionRegion().back()); {loc, loc});
mlir::Value op1 = decl.reductionRegion().front().getArgument(0); builder.setInsertionPointToEnd(&decl.getReductionRegion().back());
mlir::Value op2 = decl.reductionRegion().front().getArgument(1); mlir::Value op1 = decl.getReductionRegion().front().getArgument(0);
mlir::Value op2 = decl.getReductionRegion().front().getArgument(1);
Value reductionOp; Value reductionOp;
switch (intrinsicOp) { switch (intrinsicOp) {
@ -1156,7 +1158,7 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
"Reduction of some types is not supported"); "Reduction of some types is not supported");
} }
reductionDeclSymbols.push_back(SymbolRefAttr::get( reductionDeclSymbols.push_back(SymbolRefAttr::get(
firOpBuilder.getContext(), decl.sym_name())); firOpBuilder.getContext(), decl.getSymName()));
} }
} }
} }
@ -1232,10 +1234,10 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
const auto *expr = Fortran::semantics::GetExpr(orderedClause->v); const auto *expr = Fortran::semantics::GetExpr(orderedClause->v);
const std::optional<std::int64_t> orderedClauseValue = const std::optional<std::int64_t> orderedClauseValue =
Fortran::evaluate::ToInt64(*expr); Fortran::evaluate::ToInt64(*expr);
wsLoopOp.ordered_valAttr( wsLoopOp.setOrderedValAttr(
firOpBuilder.getI64IntegerAttr(*orderedClauseValue)); firOpBuilder.getI64IntegerAttr(*orderedClauseValue));
} else { } else {
wsLoopOp.ordered_valAttr(firOpBuilder.getI64IntegerAttr(0)); wsLoopOp.setOrderedValAttr(firOpBuilder.getI64IntegerAttr(0));
} }
} else if (const auto &scheduleClause = } else if (const auto &scheduleClause =
std::get_if<Fortran::parser::OmpClause::Schedule>( std::get_if<Fortran::parser::OmpClause::Schedule>(
@ -1247,34 +1249,34 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
scheduleType.t); scheduleType.t);
switch (scheduleKind) { switch (scheduleKind) {
case Fortran::parser::OmpScheduleClause::ScheduleType::Static: case Fortran::parser::OmpScheduleClause::ScheduleType::Static:
wsLoopOp.schedule_valAttr(omp::ClauseScheduleKindAttr::get( wsLoopOp.setScheduleValAttr(omp::ClauseScheduleKindAttr::get(
context, omp::ClauseScheduleKind::Static)); context, omp::ClauseScheduleKind::Static));
break; break;
case Fortran::parser::OmpScheduleClause::ScheduleType::Dynamic: case Fortran::parser::OmpScheduleClause::ScheduleType::Dynamic:
wsLoopOp.schedule_valAttr(omp::ClauseScheduleKindAttr::get( wsLoopOp.setScheduleValAttr(omp::ClauseScheduleKindAttr::get(
context, omp::ClauseScheduleKind::Dynamic)); context, omp::ClauseScheduleKind::Dynamic));
break; break;
case Fortran::parser::OmpScheduleClause::ScheduleType::Guided: case Fortran::parser::OmpScheduleClause::ScheduleType::Guided:
wsLoopOp.schedule_valAttr(omp::ClauseScheduleKindAttr::get( wsLoopOp.setScheduleValAttr(omp::ClauseScheduleKindAttr::get(
context, omp::ClauseScheduleKind::Guided)); context, omp::ClauseScheduleKind::Guided));
break; break;
case Fortran::parser::OmpScheduleClause::ScheduleType::Auto: case Fortran::parser::OmpScheduleClause::ScheduleType::Auto:
wsLoopOp.schedule_valAttr(omp::ClauseScheduleKindAttr::get( wsLoopOp.setScheduleValAttr(omp::ClauseScheduleKindAttr::get(
context, omp::ClauseScheduleKind::Auto)); context, omp::ClauseScheduleKind::Auto));
break; break;
case Fortran::parser::OmpScheduleClause::ScheduleType::Runtime: case Fortran::parser::OmpScheduleClause::ScheduleType::Runtime:
wsLoopOp.schedule_valAttr(omp::ClauseScheduleKindAttr::get( wsLoopOp.setScheduleValAttr(omp::ClauseScheduleKindAttr::get(
context, omp::ClauseScheduleKind::Runtime)); context, omp::ClauseScheduleKind::Runtime));
break; break;
} }
mlir::omp::ScheduleModifier scheduleModifier = mlir::omp::ScheduleModifier scheduleModifier =
getScheduleModifier(scheduleClause->v); getScheduleModifier(scheduleClause->v);
if (scheduleModifier != mlir::omp::ScheduleModifier::none) if (scheduleModifier != mlir::omp::ScheduleModifier::none)
wsLoopOp.schedule_modifierAttr( wsLoopOp.setScheduleModifierAttr(
omp::ScheduleModifierAttr::get(context, scheduleModifier)); omp::ScheduleModifierAttr::get(context, scheduleModifier));
if (getSIMDModifier(scheduleClause->v) != if (getSIMDModifier(scheduleClause->v) !=
mlir::omp::ScheduleModifier::none) mlir::omp::ScheduleModifier::none)
wsLoopOp.simd_modifierAttr(firOpBuilder.getUnitAttr()); wsLoopOp.setSimdModifierAttr(firOpBuilder.getUnitAttr());
} }
} }
// In FORTRAN `nowait` clause occur at the end of `omp do` directive. // In FORTRAN `nowait` clause occur at the end of `omp do` directive.
@ -1289,7 +1291,7 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
std::get<Fortran::parser::OmpClauseList>((*endClauseList).t); std::get<Fortran::parser::OmpClauseList>((*endClauseList).t);
for (const Fortran::parser::OmpClause &clause : clauseList.v) for (const Fortran::parser::OmpClause &clause : clauseList.v)
if (std::get_if<Fortran::parser::OmpClause::Nowait>(&clause.u)) if (std::get_if<Fortran::parser::OmpClause::Nowait>(&clause.u))
wsLoopOp.nowaitAttr(firOpBuilder.getUnitAttr()); wsLoopOp.setNowaitAttr(firOpBuilder.getUnitAttr());
} }
createBodyOfOp<omp::WsLoopOp>(wsLoopOp, converter, currentLocation, eval, createBodyOfOp<omp::WsLoopOp>(wsLoopOp, converter, currentLocation, eval,
@ -1333,7 +1335,7 @@ genOMP(Fortran::lower::AbstractConverter &converter,
currentLocation, name, hint); currentLocation, name, hint);
return firOpBuilder.create<mlir::omp::CriticalOp>( return firOpBuilder.create<mlir::omp::CriticalOp>(
currentLocation, mlir::FlatSymbolRefAttr::get( currentLocation, mlir::FlatSymbolRefAttr::get(
firOpBuilder.getContext(), global.sym_name())); firOpBuilder.getContext(), global.getSymName()));
} }
}(); }();
createBodyOfOp<omp::CriticalOp>(criticalOp, converter, currentLocation, eval); createBodyOfOp<omp::CriticalOp>(criticalOp, converter, currentLocation, eval);

View File

@ -135,7 +135,7 @@ public:
matchAndRewrite(memref::AllocOp op, matchAndRewrite(memref::AllocOp op,
mlir::PatternRewriter &rewriter) const override { mlir::PatternRewriter &rewriter) const override {
rewriter.replaceOpWithNewOp<fir::AllocaOp>(op, convertMemRef(op.getType()), rewriter.replaceOpWithNewOp<fir::AllocaOp>(op, convertMemRef(op.getType()),
op.memref()); op.getMemref());
return success(); return success();
} }
}; };

View File

@ -38,9 +38,6 @@ def AsyncDialect : Dialect {
static constexpr StringRef kAllowedToBlockAttrName = static constexpr StringRef kAllowedToBlockAttrName =
"async.allowed_to_block"; "async.allowed_to_block";
}]; }];
// TODO: Prefixed form overlaps with generated names, update before flipping.
let emitAccessorPrefix = kEmitAccessorPrefix_Both;
} }
#endif // ASYNC_DIALECT_TD #endif // ASYNC_DIALECT_TD

View File

@ -56,9 +56,6 @@ def GPU_Dialect : Dialect {
let dependentDialects = ["arith::ArithDialect"]; let dependentDialects = ["arith::ArithDialect"];
let useDefaultAttributePrinterParser = 1; let useDefaultAttributePrinterParser = 1;
let useDefaultTypePrinterParser = 1; let useDefaultTypePrinterParser = 1;
// TODO: Update this to _Prefixed.
let emitAccessorPrefix = kEmitAccessorPrefix_Both;
} }
def GPU_AsyncToken : DialectType< def GPU_AsyncToken : DialectType<

View File

@ -21,8 +21,6 @@ def MemRef_Dialect : Dialect {
}]; }];
let dependentDialects = ["arith::ArithDialect"]; let dependentDialects = ["arith::ArithDialect"];
let hasConstantMaterializer = 1; let hasConstantMaterializer = 1;
let emitAccessorPrefix = kEmitAccessorPrefix_Both;
} }
#endif // MEMREF_BASE #endif // MEMREF_BASE

View File

@ -27,9 +27,6 @@ def OpenACC_Dialect : Dialect {
let useDefaultAttributePrinterParser = 1; let useDefaultAttributePrinterParser = 1;
let cppNamespace = "::mlir::acc"; let cppNamespace = "::mlir::acc";
// TODO: Flip to _Prefixed.
let emitAccessorPrefix = kEmitAccessorPrefix_Both;
} }
// AccCommon requires definition of OpenACC_Dialect. // AccCommon requires definition of OpenACC_Dialect.

View File

@ -28,9 +28,6 @@ def OpenMP_Dialect : Dialect {
let cppNamespace = "::mlir::omp"; let cppNamespace = "::mlir::omp";
let dependentDialects = ["::mlir::LLVM::LLVMDialect"]; let dependentDialects = ["::mlir::LLVM::LLVMDialect"];
let useDefaultAttributePrinterParser = 1; let useDefaultAttributePrinterParser = 1;
// TODO: Flip to _Prefixed.
let emitAccessorPrefix = kEmitAccessorPrefix_Both;
} }
// OmpCommon requires definition of OpenACC_Dialect. // OmpCommon requires definition of OpenACC_Dialect.

View File

@ -69,9 +69,6 @@ def PDL_Dialect : Dialect {
let extraClassDeclaration = [{ let extraClassDeclaration = [{
void registerTypes(); void registerTypes();
}]; }];
// FIXME: Flip to prefixed.
let emitAccessorPrefix = kEmitAccessorPrefix_Both;
} }
#endif // MLIR_DIALECT_PDL_IR_PDLDIALECT #endif // MLIR_DIALECT_PDL_IR_PDLDIALECT

View File

@ -333,13 +333,13 @@ LogicalResult LoadOpOfSubViewOpFolder<OpTy>::matchAndRewrite(
llvm::TypeSwitch<Operation *, void>(loadOp) llvm::TypeSwitch<Operation *, void>(loadOp)
.Case<AffineLoadOp, memref::LoadOp>([&](auto op) { .Case<AffineLoadOp, memref::LoadOp>([&](auto op) {
rewriter.replaceOpWithNewOp<decltype(op)>(loadOp, subViewOp.source(), rewriter.replaceOpWithNewOp<decltype(op)>(loadOp, subViewOp.getSource(),
sourceIndices); sourceIndices);
}) })
.Case([&](vector::TransferReadOp transferReadOp) { .Case([&](vector::TransferReadOp transferReadOp) {
rewriter.replaceOpWithNewOp<vector::TransferReadOp>( rewriter.replaceOpWithNewOp<vector::TransferReadOp>(
transferReadOp, transferReadOp.getVectorType(), subViewOp.source(), transferReadOp, transferReadOp.getVectorType(),
sourceIndices, subViewOp.getSource(), sourceIndices,
getPermutationMapAttr(rewriter.getContext(), subViewOp, getPermutationMapAttr(rewriter.getContext(), subViewOp,
transferReadOp.getPermutationMap()), transferReadOp.getPermutationMap()),
transferReadOp.getPadding(), transferReadOp.getPadding(),
@ -440,11 +440,11 @@ LogicalResult StoreOpOfSubViewOpFolder<OpTy>::matchAndRewrite(
llvm::TypeSwitch<Operation *, void>(storeOp) llvm::TypeSwitch<Operation *, void>(storeOp)
.Case<AffineStoreOp, memref::StoreOp>([&](auto op) { .Case<AffineStoreOp, memref::StoreOp>([&](auto op) {
rewriter.replaceOpWithNewOp<decltype(op)>( rewriter.replaceOpWithNewOp<decltype(op)>(
storeOp, storeOp.getValue(), subViewOp.source(), sourceIndices); storeOp, storeOp.getValue(), subViewOp.getSource(), sourceIndices);
}) })
.Case([&](vector::TransferWriteOp op) { .Case([&](vector::TransferWriteOp op) {
rewriter.replaceOpWithNewOp<vector::TransferWriteOp>( rewriter.replaceOpWithNewOp<vector::TransferWriteOp>(
op, op.getValue(), subViewOp.source(), sourceIndices, op, op.getValue(), subViewOp.getSource(), sourceIndices,
getPermutationMapAttr(rewriter.getContext(), subViewOp, getPermutationMapAttr(rewriter.getContext(), subViewOp,
op.getPermutationMap()), op.getPermutationMap()),
op.getInBoundsAttr()); op.getInBoundsAttr());

View File

@ -721,7 +721,7 @@ class RewriteExtractAlignedPointerAsIndexOfViewLikeOp
if (!viewLikeOp) if (!viewLikeOp)
return rewriter.notifyMatchFailure(extractOp, "not a ViewLike source"); return rewriter.notifyMatchFailure(extractOp, "not a ViewLike source");
rewriter.updateRootInPlace(extractOp, [&]() { rewriter.updateRootInPlace(extractOp, [&]() {
extractOp.sourceMutable().assign(viewLikeOp.getViewSource()); extractOp.getSourceMutable().assign(viewLikeOp.getViewSource());
}); });
return success(); return success();
} }