[flang-commits] [flang] 69a337e - [flang][openacc][NFC] Rename createRegisterFunc and refactor
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu Aug 10 11:07:59 PDT 2023
Author: Valentin Clement
Date: 2023-08-10T10:57:25-07:00
New Revision: 69a337e2c75acac0ac12190720324560a3becdd3
URL: https://github.com/llvm/llvm-project/commit/69a337e2c75acac0ac12190720324560a3becdd3
DIFF: https://github.com/llvm/llvm-project/commit/69a337e2c75acac0ac12190720324560a3becdd3.diff
LOG: [flang][openacc][NFC] Rename createRegisterFunc and refactor
Depends on D157530
Reviewed By: razvanlupusoru
Differential Revision: https://reviews.llvm.org/D157555
Added:
Modified:
flang/include/flang/Lower/OpenACC.h
flang/lib/Lower/OpenACC.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Lower/OpenACC.h b/flang/include/flang/Lower/OpenACC.h
index c551b69f2b2754..8d072aa34acf09 100644
--- a/flang/include/flang/Lower/OpenACC.h
+++ b/flang/include/flang/Lower/OpenACC.h
@@ -51,6 +51,8 @@ namespace pft {
struct Evaluation;
} // namespace pft
+static constexpr llvm::StringRef declarePostAllocSuffix =
+ "_acc_declare_update_desc_post_alloc";
static constexpr llvm::StringRef declarePreDeallocSuffix =
"_acc_declare_update_desc_pre_dealloc";
static constexpr llvm::StringRef declarePostDeallocSuffix =
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 073cb9bc46a97b..33dc37e8b43f50 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -2346,22 +2346,30 @@ static void createDeclareGlobalOp(mlir::OpBuilder &modBuilder,
modBuilder.setInsertionPointAfter(declareGlobalOp);
}
+static mlir::func::FuncOp createDeclareFunc(mlir::OpBuilder &modBuilder,
+ fir::FirOpBuilder &builder,
+ mlir::Location loc,
+ llvm::StringRef funcName) {
+ auto funcTy = mlir::FunctionType::get(modBuilder.getContext(), {}, {});
+ auto funcOp = modBuilder.create<mlir::func::FuncOp>(loc, funcName, funcTy);
+ funcOp.setVisibility(mlir::SymbolTable::Visibility::Private);
+ builder.createBlock(&funcOp.getRegion(), funcOp.getRegion().end(), {}, {});
+ builder.setInsertionPointToEnd(&funcOp.getRegion().back());
+ builder.create<mlir::func::ReturnOp>(loc);
+ builder.setInsertionPointToStart(&funcOp.getRegion().back());
+ return funcOp;
+}
+
template <typename EntryOp>
-static void createRegisterFunc(mlir::OpBuilder &modBuilder,
- fir::FirOpBuilder &builder, mlir::Location loc,
- fir::GlobalOp &globalOp,
- mlir::acc::DataClause clause) {
+static void createDeclareAllocFunc(mlir::OpBuilder &modBuilder,
+ fir::FirOpBuilder &builder,
+ mlir::Location loc, fir::GlobalOp &globalOp,
+ mlir::acc::DataClause clause) {
std::stringstream registerFuncName;
registerFuncName << globalOp.getSymName().str()
- << "_acc_declare_update_desc_post_alloc";
- auto funcTy = mlir::FunctionType::get(modBuilder.getContext(), {}, {});
- mlir::func::FuncOp registerFuncOp = modBuilder.create<mlir::func::FuncOp>(
- loc, registerFuncName.str(), funcTy);
- registerFuncOp.setVisibility(mlir::SymbolTable::Visibility::Private);
-
- builder.createBlock(®isterFuncOp.getRegion(),
- registerFuncOp.getRegion().end(), {}, {});
- builder.setInsertionPointToEnd(®isterFuncOp.getRegion().back());
+ << Fortran::lower::declarePostAllocSuffix.str();
+ auto registerFuncOp =
+ createDeclareFunc(modBuilder, builder, loc, registerFuncName.str());
fir::AddrOfOp addrOp = builder.create<fir::AddrOfOp>(
loc, fir::ReferenceType::get(globalOp.getType()), globalOp.getSymbol());
@@ -2387,25 +2395,9 @@ static void createRegisterFunc(mlir::OpBuilder &modBuilder,
llvm::SmallVector<int32_t> operandSegments{0, 0, 0, 0, 0, 1};
llvm::SmallVector<mlir::Value> operands{updateDeviceOp.getResult()};
createSimpleOp<mlir::acc::UpdateOp>(builder, loc, operands, operandSegments);
-
- builder.create<mlir::func::ReturnOp>(loc);
modBuilder.setInsertionPointAfter(registerFuncOp);
}
-static mlir::func::FuncOp createDeclareFunc(mlir::OpBuilder &modBuilder,
- fir::FirOpBuilder &builder,
- mlir::Location loc,
- llvm::StringRef funcName) {
- auto funcTy = mlir::FunctionType::get(modBuilder.getContext(), {}, {});
- auto funcOp = modBuilder.create<mlir::func::FuncOp>(loc, funcName, funcTy);
- funcOp.setVisibility(mlir::SymbolTable::Visibility::Private);
- builder.createBlock(&funcOp.getRegion(), funcOp.getRegion().end(), {}, {});
- builder.setInsertionPointToEnd(&funcOp.getRegion().back());
- builder.create<mlir::func::ReturnOp>(loc);
- builder.setInsertionPointToStart(&funcOp.getRegion().back());
- return funcOp;
-}
-
/// Action to be performed on deallocation are split in two distinct functions.
/// - Pre deallocation function includes all the action to be performed before
/// the actual deallocation is done on the host side.
@@ -2500,7 +2492,7 @@ static void genGlobalCtors(Fortran::lower::AbstractConverter &converter,
mlir::acc::DeclareEnterOp, ExitOp>(
modBuilder, builder, operandLocation, globalOp, clause,
/*implicit=*/true);
- createRegisterFunc<EntryOp>(
+ createDeclareAllocFunc<EntryOp>(
modBuilder, builder, operandLocation, globalOp, clause);
if constexpr (!std::is_same_v<EntryOp, ExitOp>)
createDeclareDeallocFunc<ExitOp>(
More information about the flang-commits
mailing list