aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Lower
diff options
context:
space:
mode:
Diffstat (limited to 'flang/lib/Lower')
-rw-r--r--flang/lib/Lower/Bridge.cpp20
-rw-r--r--flang/lib/Lower/ConvertVariable.cpp2
-rw-r--r--flang/lib/Lower/OpenACC.cpp60
-rw-r--r--flang/lib/Lower/OpenMP/OpenMP.cpp55
4 files changed, 94 insertions, 43 deletions
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 3b711cc..a516a44 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -1766,7 +1766,7 @@ private:
// to a crash due to a block with no terminator. See issue #126452.
mlir::FunctionType funcType = builder->getFunction().getFunctionType();
mlir::Type resultType = funcType.getResult(0);
- mlir::Value undefResult = builder->create<fir::UndefOp>(loc, resultType);
+ mlir::Value undefResult = fir::UndefOp::create(*builder, loc, resultType);
genExitRoutine(false, undefResult);
return;
}
@@ -4010,8 +4010,8 @@ private:
// parameters and dynamic type. The selector cannot be a
// POINTER/ALLOCATBLE as per F'2023 C1160.
fir::ExtendedValue newExv;
- llvm::SmallVector assumeSizeExtents{
- builder->createMinusOneInteger(loc, builder->getIndexType())};
+ llvm::SmallVector<mlir::Value> assumeSizeExtents{
+ fir::AssumedSizeExtentOp::create(*builder, loc)};
mlir::Value baseAddr =
hlfir::genVariableRawAddress(loc, *builder, selector);
const bool isVolatile = fir::isa_volatile_type(selector.getType());
@@ -4733,11 +4733,21 @@ private:
return fir::factory::createUnallocatedBox(*builder, loc, lhsBoxType, {});
hlfir::Entity rhs = Fortran::lower::convertExprToHLFIR(
loc, *this, assign.rhs, localSymbols, rhsContext);
+ auto rhsBoxType = rhs.getBoxType();
// Create pointer descriptor value from the RHS.
if (rhs.isMutableBox())
rhs = hlfir::Entity{fir::LoadOp::create(*builder, loc, rhs)};
- mlir::Value rhsBox = hlfir::genVariableBox(
- loc, *builder, rhs, lhsBoxType.getBoxTypeWithNewShape(rhs.getRank()));
+
+ // Use LHS type if LHS is not polymorphic.
+ fir::BaseBoxType targetBoxType;
+ if (assign.lhs.GetType()->IsPolymorphic())
+ targetBoxType = rhsBoxType.getBoxTypeWithNewAttr(
+ fir::BaseBoxType::Attribute::Pointer);
+ else
+ targetBoxType = lhsBoxType.getBoxTypeWithNewShape(rhs.getRank());
+ mlir::Value rhsBox =
+ hlfir::genVariableBox(loc, *builder, rhs, targetBoxType);
+
// Apply lower bounds or reshaping if any.
if (const auto *lbExprs =
std::get_if<Fortran::evaluate::Assignment::BoundsSpec>(&assign.u);
diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp
index 00ec1b5..2517ab3 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -1711,7 +1711,7 @@ static void lowerExplicitLowerBounds(
/// CFI_desc_t requirements in 18.5.3 point 5.).
static mlir::Value getAssumedSizeExtent(mlir::Location loc,
fir::FirOpBuilder &builder) {
- return builder.createMinusOneInteger(loc, builder.getIndexType());
+ return fir::AssumedSizeExtentOp::create(builder, loc);
}
/// Lower explicit extents into \p result if this is an explicit-shape or
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index af4f420..d7861ac 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -816,8 +816,9 @@ static void genDeclareDataOperandOperations(
Fortran::semantics::FindCommonBlockContaining(symbol)) {
emitCommonGlobal(
converter, builder, accObject, dataClause,
- [&](mlir::OpBuilder &modBuilder, mlir::Location loc,
- fir::GlobalOp globalOp, mlir::acc::DataClause clause,
+ [&](mlir::OpBuilder &modBuilder, [[maybe_unused]] mlir::Location loc,
+ [[maybe_unused]] fir::GlobalOp globalOp,
+ [[maybe_unused]] mlir::acc::DataClause clause,
std::stringstream &asFortranStr, const std::string &ctorName) {
if constexpr (std::is_same_v<EntryOp, mlir::acc::DeclareLinkOp>) {
createDeclareGlobalOp<
@@ -2366,6 +2367,23 @@ static void processDoLoopBounds(
}
}
+static void remapCommonBlockMember(
+ Fortran::lower::AbstractConverter &converter, mlir::Location loc,
+ const Fortran::semantics::Symbol &member,
+ mlir::Value newCommonBlockBaseAddress,
+ const Fortran::semantics::Symbol &commonBlockSymbol,
+ llvm::SmallPtrSetImpl<const Fortran::semantics::Symbol *> &seenSymbols) {
+ if (seenSymbols.contains(&member))
+ return;
+ mlir::Value accMemberValue = Fortran::lower::genCommonBlockMember(
+ converter, loc, member, newCommonBlockBaseAddress,
+ commonBlockSymbol.size());
+ fir::ExtendedValue hostExv = converter.getSymbolExtendedValue(member);
+ fir::ExtendedValue accExv = fir::substBase(hostExv, accMemberValue);
+ converter.bindSymbol(member, accExv);
+ seenSymbols.insert(&member);
+}
+
/// Remap symbols that appeared in OpenACC data clauses to use the results of
/// the corresponding data operations. This allows isolating symbol accesses
/// inside the OpenACC region from accesses in the host and other regions while
@@ -2391,14 +2409,39 @@ static void remapDataOperandSymbols(
builder.setInsertionPointToStart(&regionOp.getRegion().front());
llvm::SmallPtrSet<const Fortran::semantics::Symbol *, 8> seenSymbols;
mlir::IRMapping mapper;
+ mlir::Location loc = regionOp.getLoc();
for (auto [value, symbol] : dataOperandSymbolPairs) {
-
- // If A symbol appears on several data clause, just map it to the first
+ // If a symbol appears on several data clause, just map it to the first
// result (all data operations results for a symbol are pointing same
// memory, so it does not matter which one is used).
if (seenSymbols.contains(&symbol.get()))
continue;
seenSymbols.insert(&symbol.get());
+ // When a common block appears in a directive, remap its members.
+ // Note: this will instantiate all common block members even if they are not
+ // used inside the region. If hlfir.declare DCE is not made possible, this
+ // could be improved to reduce IR noise.
+ if (const auto *commonBlock = symbol->template detailsIf<
+ Fortran::semantics::CommonBlockDetails>()) {
+ const Fortran::semantics::Scope &commonScope = symbol->owner();
+ if (commonScope.equivalenceSets().empty()) {
+ for (auto member : commonBlock->objects())
+ remapCommonBlockMember(converter, loc, *member, value, *symbol,
+ seenSymbols);
+ } else {
+ // Objects equivalenced with common block members still belong to the
+ // common block storage even if they are not part of the common block
+ // declaration. The easiest and most robust way to find all symbols
+ // belonging to the common block is to loop through the scope symbols
+ // and check if they belong to the common.
+ for (const auto &scopeSymbol : commonScope)
+ if (Fortran::semantics::FindCommonBlockContaining(
+ *scopeSymbol.second) == &symbol.get())
+ remapCommonBlockMember(converter, loc, *scopeSymbol.second, value,
+ *symbol, seenSymbols);
+ }
+ continue;
+ }
std::optional<fir::FortranVariableOpInterface> hostDef =
symbolMap.lookupVariableDefinition(symbol);
assert(hostDef.has_value() && llvm::isa<hlfir::DeclareOp>(*hostDef) &&
@@ -2415,10 +2458,8 @@ static void remapDataOperandSymbols(
"box type mismatch between compute region variable and "
"hlfir.declare input unexpected");
if (Fortran::semantics::IsOptional(symbol))
- TODO(regionOp.getLoc(),
- "remapping OPTIONAL symbol in OpenACC compute region");
- auto rawValue =
- fir::BoxAddrOp::create(builder, regionOp.getLoc(), hostType, value);
+ TODO(loc, "remapping OPTIONAL symbol in OpenACC compute region");
+ auto rawValue = fir::BoxAddrOp::create(builder, loc, hostType, value);
mapper.map(hostInput, rawValue);
} else {
assert(!llvm::isa<fir::BaseBoxType>(hostType) &&
@@ -2430,8 +2471,7 @@ static void remapDataOperandSymbols(
assert(fir::isa_ref_type(hostType) && fir::isa_ref_type(computeType) &&
"compute region variable and host variable should both be raw "
"addresses");
- mlir::Value cast =
- builder.createConvert(regionOp.getLoc(), hostType, value);
+ mlir::Value cast = builder.createConvert(loc, hostType, value);
mapper.map(hostInput, cast);
}
if (mlir::Value dummyScope = hostDeclare.getDummyScope()) {
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index a49961c..7106728 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -2059,37 +2059,38 @@ static void genCanonicalLoopNest(
// Start lowering
mlir::Value zero = firOpBuilder.createIntegerConstant(loc, loopVarType, 0);
mlir::Value one = firOpBuilder.createIntegerConstant(loc, loopVarType, 1);
- mlir::Value isDownwards = firOpBuilder.create<mlir::arith::CmpIOp>(
- loc, mlir::arith::CmpIPredicate::slt, loopStepVar, zero);
+ mlir::Value isDownwards = mlir::arith::CmpIOp::create(
+ firOpBuilder, loc, mlir::arith::CmpIPredicate::slt, loopStepVar, zero);
// Ensure we are counting upwards. If not, negate step and swap lb and ub.
mlir::Value negStep =
- firOpBuilder.create<mlir::arith::SubIOp>(loc, zero, loopStepVar);
- mlir::Value incr = firOpBuilder.create<mlir::arith::SelectOp>(
- loc, isDownwards, negStep, loopStepVar);
- mlir::Value lb = firOpBuilder.create<mlir::arith::SelectOp>(
- loc, isDownwards, loopUBVar, loopLBVar);
- mlir::Value ub = firOpBuilder.create<mlir::arith::SelectOp>(
- loc, isDownwards, loopLBVar, loopUBVar);
+ mlir::arith::SubIOp::create(firOpBuilder, loc, zero, loopStepVar);
+ mlir::Value incr = mlir::arith::SelectOp::create(
+ firOpBuilder, loc, isDownwards, negStep, loopStepVar);
+ mlir::Value lb = mlir::arith::SelectOp::create(
+ firOpBuilder, loc, isDownwards, loopUBVar, loopLBVar);
+ mlir::Value ub = mlir::arith::SelectOp::create(
+ firOpBuilder, loc, isDownwards, loopLBVar, loopUBVar);
// Compute the trip count assuming lb <= ub. This guarantees that the result
// is non-negative and we can use unsigned arithmetic.
- mlir::Value span = firOpBuilder.create<mlir::arith::SubIOp>(
- loc, ub, lb, ::mlir::arith::IntegerOverflowFlags::nuw);
+ mlir::Value span = mlir::arith::SubIOp::create(
+ firOpBuilder, loc, ub, lb, ::mlir::arith::IntegerOverflowFlags::nuw);
mlir::Value tcMinusOne =
- firOpBuilder.create<mlir::arith::DivUIOp>(loc, span, incr);
- mlir::Value tcIfLooping = firOpBuilder.create<mlir::arith::AddIOp>(
- loc, tcMinusOne, one, ::mlir::arith::IntegerOverflowFlags::nuw);
+ mlir::arith::DivUIOp::create(firOpBuilder, loc, span, incr);
+ mlir::Value tcIfLooping =
+ mlir::arith::AddIOp::create(firOpBuilder, loc, tcMinusOne, one,
+ ::mlir::arith::IntegerOverflowFlags::nuw);
// Fall back to 0 if lb > ub
- mlir::Value isZeroTC = firOpBuilder.create<mlir::arith::CmpIOp>(
- loc, mlir::arith::CmpIPredicate::slt, ub, lb);
- mlir::Value tripcount = firOpBuilder.create<mlir::arith::SelectOp>(
- loc, isZeroTC, zero, tcIfLooping);
+ mlir::Value isZeroTC = mlir::arith::CmpIOp::create(
+ firOpBuilder, loc, mlir::arith::CmpIPredicate::slt, ub, lb);
+ mlir::Value tripcount = mlir::arith::SelectOp::create(
+ firOpBuilder, loc, isZeroTC, zero, tcIfLooping);
tripcounts.push_back(tripcount);
// Create the CLI handle.
- auto newcli = firOpBuilder.create<mlir::omp::NewCliOp>(loc);
+ auto newcli = mlir::omp::NewCliOp::create(firOpBuilder, loc);
mlir::Value cli = newcli.getResult();
clis.push_back(cli);
@@ -2122,10 +2123,10 @@ static void genCanonicalLoopNest(
"Expecting all block args to have been collected by now");
for (auto j : llvm::seq<size_t>(numLoops)) {
mlir::Value natIterNum = fir::getBase(blockArgs[j]);
- mlir::Value scaled = firOpBuilder.create<mlir::arith::MulIOp>(
- loc, natIterNum, loopStepVars[j]);
- mlir::Value userVal = firOpBuilder.create<mlir::arith::AddIOp>(
- loc, loopLBVars[j], scaled);
+ mlir::Value scaled = mlir::arith::MulIOp::create(
+ firOpBuilder, loc, natIterNum, loopStepVars[j]);
+ mlir::Value userVal = mlir::arith::AddIOp::create(
+ firOpBuilder, loc, loopLBVars[j], scaled);
mlir::OpBuilder::InsertPoint insPt =
firOpBuilder.saveInsertionPoint();
@@ -2198,9 +2199,9 @@ static void genTileOp(Fortran::lower::AbstractConverter &converter,
gridGeneratees.reserve(numLoops);
intratileGeneratees.reserve(numLoops);
for ([[maybe_unused]] auto i : llvm::seq<int>(0, sizesClause.sizes.size())) {
- auto gridCLI = firOpBuilder.create<mlir::omp::NewCliOp>(loc);
+ auto gridCLI = mlir::omp::NewCliOp::create(firOpBuilder, loc);
gridGeneratees.push_back(gridCLI.getResult());
- auto intratileCLI = firOpBuilder.create<mlir::omp::NewCliOp>(loc);
+ auto intratileCLI = mlir::omp::NewCliOp::create(firOpBuilder, loc);
intratileGeneratees.push_back(intratileCLI.getResult());
}
@@ -2209,8 +2210,8 @@ static void genTileOp(Fortran::lower::AbstractConverter &converter,
generatees.append(gridGeneratees);
generatees.append(intratileGeneratees);
- firOpBuilder.create<mlir::omp::TileOp>(loc, generatees, applyees,
- sizesClause.sizes);
+ mlir::omp::TileOp::create(firOpBuilder, loc, generatees, applyees,
+ sizesClause.sizes);
}
static void genUnrollOp(Fortran::lower::AbstractConverter &converter,