[flang-commits] [flang] cf23f08 - [flang][NFC] remove stmtCtx genIntrinsicCall 1/6
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Mon Feb 6 02:35:20 PST 2023
Author: Tom Eccles
Date: 2023-02-06T10:33:20Z
New Revision: cf23f08c5c050c9de2cc63815a7f46026e13aa71
URL: https://github.com/llvm/llvm-project/commit/cf23f08c5c050c9de2cc63815a7f46026e13aa71
DIFF: https://github.com/llvm/llvm-project/commit/cf23f08c5c050c9de2cc63815a7f46026e13aa71.diff
LOG: [flang][NFC] remove stmtCtx genIntrinsicCall 1/6
This removes IntrinsicCall's dependency upon StatementContext, which
will make it easier to move IntrinsicCall into flang/lib/Optimizer, for
use in passes.
Differential Revision: https://reviews.llvm.org/D143079
Added:
Modified:
flang/include/flang/Lower/CustomIntrinsicCall.h
flang/include/flang/Lower/IntrinsicCall.h
flang/lib/Lower/CustomIntrinsicCall.cpp
flang/lib/Lower/IntrinsicCall.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Lower/CustomIntrinsicCall.h b/flang/include/flang/Lower/CustomIntrinsicCall.h
index 391aabd01721a..dae94fc18e3bf 100644
--- a/flang/include/flang/Lower/CustomIntrinsicCall.h
+++ b/flang/include/flang/Lower/CustomIntrinsicCall.h
@@ -93,6 +93,18 @@ lowerCustomIntrinsic(fir::FirOpBuilder &builder, mlir::Location loc,
const OperandPresent &isPresentCheck,
const OperandGetter &getOperand, std::size_t numOperands,
Fortran::lower::StatementContext &stmtCtx);
+
+/// DEPRICATED: NEW CODE SHOULD USE THE VERSION OF genIntrinsicCall WITHOUT A
+/// StatementContext, DECLARED IN IntrinsicCall.h
+/// Generate the FIR+MLIR operations for the generic intrinsic \p name
+/// with argument \p args and expected result type \p resultType.
+/// Returned fir::ExtendedValue is the returned Fortran intrinsic value.
+fir::ExtendedValue genIntrinsicCall(fir::FirOpBuilder &builder,
+ mlir::Location loc, llvm::StringRef name,
+ std::optional<mlir::Type> resultType,
+ llvm::ArrayRef<fir::ExtendedValue> args,
+ StatementContext &stmtCtx);
+
} // namespace lower
} // namespace Fortran
diff --git a/flang/include/flang/Lower/IntrinsicCall.h b/flang/include/flang/Lower/IntrinsicCall.h
index f6c62fd65110c..46ccc5cab7527 100644
--- a/flang/include/flang/Lower/IntrinsicCall.h
+++ b/flang/include/flang/Lower/IntrinsicCall.h
@@ -19,15 +19,6 @@ class StatementContext;
// TODO: Error handling interface ?
// TODO: Implementation is incomplete. Many intrinsics to tbd.
-/// Generate the FIR+MLIR operations for the generic intrinsic \p name
-/// with arguments \p args and expected result type \p resultType.
-/// Returned mlir::Value is the returned Fortran intrinsic value.
-fir::ExtendedValue genIntrinsicCall(fir::FirOpBuilder &, mlir::Location,
- llvm::StringRef name,
- std::optional<mlir::Type> resultType,
- llvm::ArrayRef<fir::ExtendedValue> args,
- StatementContext &);
-
/// Same as the other genIntrinsicCall version above, except that the result
/// deallocation, if required, is not added to a StatementContext. Instead, an
/// extra boolean result indicates if the result must be freed after use.
diff --git a/flang/lib/Lower/CustomIntrinsicCall.cpp b/flang/lib/Lower/CustomIntrinsicCall.cpp
index 9b35625125aaa..fd2ce925f082f 100644
--- a/flang/lib/Lower/CustomIntrinsicCall.cpp
+++ b/flang/lib/Lower/CustomIntrinsicCall.cpp
@@ -15,6 +15,7 @@
#include "flang/Evaluate/fold.h"
#include "flang/Evaluate/tools.h"
#include "flang/Lower/IntrinsicCall.h"
+#include "flang/Lower/StatementContext.h"
#include "flang/Optimizer/Builder/Todo.h"
#include <optional>
@@ -63,6 +64,28 @@ bool Fortran::lower::intrinsicRequiresCustomOptionalHandling(
isIshftcWithDynamicallyOptionalArg(name, procRef, fldCtx);
}
+/// Generate the FIR+MLIR operations for the generic intrinsic \p name
+/// with arguments \p args and the expected result type \p resultType.
+/// Returned fir::ExtendedValue is the returned Fortran intrinsic value.
+fir::ExtendedValue
+Fortran::lower::genIntrinsicCall(fir::FirOpBuilder &builder, mlir::Location loc,
+ llvm::StringRef name,
+ std::optional<mlir::Type> resultType,
+ llvm::ArrayRef<fir::ExtendedValue> args,
+ Fortran::lower::StatementContext &stmtCtx) {
+ auto [result, mustBeFreed] =
+ Fortran::lower::genIntrinsicCall(builder, loc, name, resultType, args);
+ if (mustBeFreed) {
+ mlir::Value addr = fir::getBase(result);
+ if (auto *box = result.getBoxOf<fir::BoxValue>())
+ addr =
+ builder.create<fir::BoxAddrOp>(loc, box->getMemTy(), box->getAddr());
+ fir::FirOpBuilder *bldr = &builder;
+ stmtCtx.attachCleanup([=]() { bldr->create<fir::FreeMemOp>(loc, addr); });
+ }
+ return result;
+}
+
static void prepareMinOrMaxArguments(
const Fortran::evaluate::ProcedureRef &procRef,
const Fortran::evaluate::SpecificIntrinsic &intrinsic,
@@ -108,8 +131,8 @@ lowerMinOrMax(fir::FirOpBuilder &builder, mlir::Location loc,
llvm::SmallVector<fir::ExtendedValue> args;
args.push_back(getOperand(0));
args.push_back(getOperand(1));
- mlir::Value extremum = fir::getBase(Fortran::lower::genIntrinsicCall(
- builder, loc, name, resultType, args, stmtCtx));
+ mlir::Value extremum = fir::getBase(
+ genIntrinsicCall(builder, loc, name, resultType, args, stmtCtx));
for (std::size_t opIndex = 2; opIndex < numOperands; ++opIndex) {
if (std::optional<mlir::Value> isPresentRuntimeCheck =
@@ -123,9 +146,8 @@ lowerMinOrMax(fir::FirOpBuilder &builder, mlir::Location loc,
llvm::SmallVector<fir::ExtendedValue> args;
args.emplace_back(extremum);
args.emplace_back(getOperand(opIndex));
- fir::ExtendedValue newExtremum =
- Fortran::lower::genIntrinsicCall(builder, loc, name,
- resultType, args, stmtCtx);
+ fir::ExtendedValue newExtremum = genIntrinsicCall(
+ builder, loc, name, resultType, args, stmtCtx);
builder.create<fir::ResultOp>(loc, fir::getBase(newExtremum));
})
.genElse([&]() { builder.create<fir::ResultOp>(loc, extremum); })
@@ -135,8 +157,8 @@ lowerMinOrMax(fir::FirOpBuilder &builder, mlir::Location loc,
llvm::SmallVector<fir::ExtendedValue> args;
args.emplace_back(extremum);
args.emplace_back(getOperand(opIndex));
- extremum = fir::getBase(Fortran::lower::genIntrinsicCall(
- builder, loc, name, resultType, args, stmtCtx));
+ extremum = fir::getBase(
+ genIntrinsicCall(builder, loc, name, resultType, args, stmtCtx));
}
}
return extremum;
@@ -198,8 +220,7 @@ lowerIshftc(fir::FirOpBuilder &builder, mlir::Location loc,
builder.create<fir::ResultOp>(loc, bitSize);
})
.getResults()[0]);
- return Fortran::lower::genIntrinsicCall(builder, loc, name, resultType, args,
- stmtCtx);
+ return genIntrinsicCall(builder, loc, name, resultType, args, stmtCtx);
}
void Fortran::lower::prepareCustomIntrinsicArgument(
diff --git a/flang/lib/Lower/IntrinsicCall.cpp b/flang/lib/Lower/IntrinsicCall.cpp
index 92c4f87ae03cc..02c2fbfa999ef 100644
--- a/flang/lib/Lower/IntrinsicCall.cpp
+++ b/flang/lib/Lower/IntrinsicCall.cpp
@@ -17,7 +17,6 @@
#include "flang/Common/static-multimap-view.h"
#include "flang/Lower/Mangler.h"
#include "flang/Lower/Runtime.h"
-#include "flang/Lower/StatementContext.h"
#include "flang/Lower/Support/Utils.h"
#include "flang/Lower/SymbolMap.h"
#include "flang/Optimizer/Builder/BoxValue.h"
@@ -5307,24 +5306,6 @@ Fortran::lower::ArgLoweringRule Fortran::lower::lowerIntrinsicArgumentAs(
// Public intrinsic call helpers
//===----------------------------------------------------------------------===//
-fir::ExtendedValue
-Fortran::lower::genIntrinsicCall(fir::FirOpBuilder &builder, mlir::Location loc,
- llvm::StringRef name,
- std::optional<mlir::Type> resultType,
- llvm::ArrayRef<fir::ExtendedValue> args,
- Fortran::lower::StatementContext &stmtCtx) {
- auto [result, mustBeFreed] =
- IntrinsicLibrary{builder, loc}.genIntrinsicCall(name, resultType, args);
- if (mustBeFreed) {
- mlir::Value addr = fir::getBase(result);
- if (auto *box = result.getBoxOf<fir::BoxValue>())
- addr =
- builder.create<fir::BoxAddrOp>(loc, box->getMemTy(), box->getAddr());
- fir::FirOpBuilder *bldr = &builder;
- stmtCtx.attachCleanup([=]() { bldr->create<fir::FreeMemOp>(loc, addr); });
- }
- return result;
-}
std::pair<fir::ExtendedValue, bool>
Fortran::lower::genIntrinsicCall(fir::FirOpBuilder &builder, mlir::Location loc,
llvm::StringRef name,
More information about the flang-commits
mailing list