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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- Lower/CUDA.h -- CUDA Fortran utilities ------------------*- C++ -*-===//
//===-- Lower/Cuda.h -- Cuda Fortran utilities ------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -15,7 +15,6 @@

#include "flang/Optimizer/Builder/FIRBuilder.h"
#include "flang/Optimizer/Dialect/CUF/CUFOps.h"
#include "flang/Runtime/allocator-registry-consts.h"
#include "flang/Semantics/tools.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/OpenACC/OpenACC.h"
Expand All @@ -38,15 +37,6 @@ static inline unsigned getAllocatorIdx(const Fortran::semantics::Symbol &sym) {
return kDefaultAllocator;
}

void initializeDeviceComponentAllocator(
Fortran::lower::AbstractConverter &converter,
const Fortran::semantics::Symbol &sym, const fir::MutableBoxValue &box);

mlir::Type gatherDeviceComponentCoordinatesAndType(
fir::FirOpBuilder &builder, mlir::Location loc,
const Fortran::semantics::Symbol &sym, fir::RecordType recTy,
llvm::SmallVector<mlir::Value> &coordinates);

} // end namespace Fortran::lower

#endif // FORTRAN_LOWER_CUDA_H
14 changes: 5 additions & 9 deletions flang/lib/Lower/Allocatable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#include "flang/Lower/Allocatable.h"
#include "flang/Evaluate/tools.h"
#include "flang/Lower/AbstractConverter.h"
#include "flang/Lower/CUDA.h"
#include "flang/Lower/ConvertType.h"
#include "flang/Lower/ConvertVariable.h"
#include "flang/Lower/Cuda.h"
#include "flang/Lower/IterationSpace.h"
#include "flang/Lower/Mangler.h"
#include "flang/Lower/OpenACC.h"
Expand Down Expand Up @@ -445,14 +445,10 @@ class AllocateStmtHelper {
/*mustBeHeap=*/true);
}

void postAllocationAction(const Allocation &alloc,
const fir::MutableBoxValue &box) {
void postAllocationAction(const Allocation &alloc) {
if (alloc.getSymbol().test(Fortran::semantics::Symbol::Flag::AccDeclare))
Fortran::lower::attachDeclarePostAllocAction(converter, builder,
alloc.getSymbol());
if (Fortran::semantics::HasCUDAComponent(alloc.getSymbol()))
Fortran::lower::initializeDeviceComponentAllocator(
converter, alloc.getSymbol(), box);
}

void setPinnedToFalse() {
Expand Down Expand Up @@ -485,7 +481,7 @@ class AllocateStmtHelper {
// Pointers must use PointerAllocate so that their deallocations
// can be validated.
genInlinedAllocation(alloc, box);
postAllocationAction(alloc, box);
postAllocationAction(alloc);
setPinnedToFalse();
return;
}
Expand All @@ -508,7 +504,7 @@ class AllocateStmtHelper {
genCudaAllocate(builder, loc, box, errorManager, alloc.getSymbol());
}
fir::factory::syncMutableBoxFromIRBox(builder, loc, box);
postAllocationAction(alloc, box);
postAllocationAction(alloc);
errorManager.assignStat(builder, loc, stat);
}

Expand Down Expand Up @@ -651,7 +647,7 @@ class AllocateStmtHelper {
setPinnedToFalse();
}
fir::factory::syncMutableBoxFromIRBox(builder, loc, box);
postAllocationAction(alloc, box);
postAllocationAction(alloc);
errorManager.assignStat(builder, loc, stat);
}

Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#include "flang/Lower/Bridge.h"

#include "flang/Lower/Allocatable.h"
#include "flang/Lower/CUDA.h"
#include "flang/Lower/CallInterface.h"
#include "flang/Lower/Coarray.h"
#include "flang/Lower/ConvertCall.h"
#include "flang/Lower/ConvertExpr.h"
#include "flang/Lower/ConvertExprToHLFIR.h"
#include "flang/Lower/ConvertType.h"
#include "flang/Lower/ConvertVariable.h"
#include "flang/Lower/Cuda.h"
#include "flang/Lower/DirectivesCommon.h"
#include "flang/Lower/HostAssociations.h"
#include "flang/Lower/IO.h"
Expand Down
1 change: 0 additions & 1 deletion flang/lib/Lower/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ add_flang_library(FortranLower
ConvertProcedureDesignator.cpp
ConvertType.cpp
ConvertVariable.cpp
CUDA.cpp
CustomIntrinsicCall.cpp
HlfirIntrinsics.cpp
HostAssociations.cpp
Expand Down
148 changes: 0 additions & 148 deletions flang/lib/Lower/CUDA.cpp

This file was deleted.

75 changes: 66 additions & 9 deletions flang/lib/Lower/ConvertVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
#include "flang/Lower/AbstractConverter.h"
#include "flang/Lower/Allocatable.h"
#include "flang/Lower/BoxAnalyzer.h"
#include "flang/Lower/CUDA.h"
#include "flang/Lower/CallInterface.h"
#include "flang/Lower/ConvertConstant.h"
#include "flang/Lower/ConvertExpr.h"
#include "flang/Lower/ConvertExprToHLFIR.h"
#include "flang/Lower/ConvertProcedureDesignator.h"
#include "flang/Lower/Cuda.h"
#include "flang/Lower/Mangler.h"
#include "flang/Lower/PFTBuilder.h"
#include "flang/Lower/StatementContext.h"
Expand Down Expand Up @@ -814,24 +814,81 @@ initializeDeviceComponentAllocator(Fortran::lower::AbstractConverter &converter,
baseTy = boxTy.getEleTy();
baseTy = fir::unwrapRefType(baseTy);

if (fir::isAllocatableType(fir::getBase(exv).getType()) ||
fir::isPointerType(fir::getBase(exv).getType()))
if (mlir::isa<fir::SequenceType>(baseTy) &&
(fir::isAllocatableType(fir::getBase(exv).getType()) ||
fir::isPointerType(fir::getBase(exv).getType())))
return; // Allocator index need to be set after allocation.

auto recTy =
mlir::dyn_cast<fir::RecordType>(fir::unwrapSequenceType(baseTy));
assert(recTy && "expected fir::RecordType");

llvm::SmallVector<mlir::Value> coordinates;
Fortran::semantics::UltimateComponentIterator components{*derived};
for (const auto &sym : components) {
if (Fortran::semantics::IsDeviceAllocatable(sym)) {
llvm::SmallVector<mlir::Value> coord;
mlir::Type fieldTy =
Fortran::lower::gatherDeviceComponentCoordinatesAndType(
builder, loc, sym, recTy, coord);
unsigned fieldIdx = recTy.getFieldIndex(sym.name().ToString());
mlir::Type fieldTy;
llvm::SmallVector<mlir::Value> coordinates;

if (fieldIdx != std::numeric_limits<unsigned>::max()) {
// Field found in the base record type.
auto fieldName = recTy.getTypeList()[fieldIdx].first;
fieldTy = recTy.getTypeList()[fieldIdx].second;
mlir::Value fieldIndex = fir::FieldIndexOp::create(
builder, loc, fir::FieldType::get(fieldTy.getContext()),
fieldName, recTy,
/*typeParams=*/mlir::ValueRange{});
coordinates.push_back(fieldIndex);
} else {
// Field not found in base record type, search in potential
// record type components.
for (auto component : recTy.getTypeList()) {
if (auto childRecTy =
mlir::dyn_cast<fir::RecordType>(component.second)) {
fieldIdx = childRecTy.getFieldIndex(sym.name().ToString());
if (fieldIdx != std::numeric_limits<unsigned>::max()) {
mlir::Value parentFieldIndex = fir::FieldIndexOp::create(
builder, loc,
fir::FieldType::get(childRecTy.getContext()),
component.first, recTy,
/*typeParams=*/mlir::ValueRange{});
coordinates.push_back(parentFieldIndex);
auto fieldName = childRecTy.getTypeList()[fieldIdx].first;
fieldTy = childRecTy.getTypeList()[fieldIdx].second;
mlir::Value childFieldIndex = fir::FieldIndexOp::create(
builder, loc, fir::FieldType::get(fieldTy.getContext()),
fieldName, childRecTy,
/*typeParams=*/mlir::ValueRange{});
coordinates.push_back(childFieldIndex);
break;
}
}
}
}

if (coordinates.empty())
TODO(loc, "device resident component in complex derived-type "
"hierarchy");

mlir::Value base = fir::getBase(exv);
mlir::Value comp = fir::CoordinateOp::create(
builder, loc, builder.getRefType(fieldTy), base, coord);
mlir::Value comp;
if (mlir::isa<fir::BaseBoxType>(fir::unwrapRefType(base.getType()))) {
mlir::Value box = fir::LoadOp::create(builder, loc, base);
mlir::Value addr = fir::BoxAddrOp::create(builder, loc, box);
llvm::SmallVector<mlir::Value> lenParams;
assert(coordinates.size() == 1 && "expect one coordinate");
auto field = mlir::dyn_cast<fir::FieldIndexOp>(
coordinates[0].getDefiningOp());
comp = hlfir::DesignateOp::create(
builder, loc, builder.getRefType(fieldTy), addr,
/*component=*/field.getFieldName(),
/*componentShape=*/mlir::Value{},
hlfir::DesignateOp::Subscripts{});
} else {
comp = fir::CoordinateOp::create(
builder, loc, builder.getRefType(fieldTy), base, coordinates);
}
cuf::DataAttributeAttr dataAttr =
Fortran::lower::translateSymbolCUFDataAttribute(
builder.getContext(), sym);
Expand Down
Loading
Loading