aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Eccles <tom.eccles@arm.com>2023-02-01 11:54:36 +0000
committerTom Eccles <tom.eccles@arm.com>2023-02-06 10:33:20 +0000
commitcf23f08c5c050c9de2cc63815a7f46026e13aa71 (patch)
treed01c65fadaa5de8aec7bc7c86aa57953434be443
parentf7b10467b63f09ab74e67d4002b3e11601091882 (diff)
downloadllvm-cf23f08c5c050c9de2cc63815a7f46026e13aa71.zip
llvm-cf23f08c5c050c9de2cc63815a7f46026e13aa71.tar.gz
llvm-cf23f08c5c050c9de2cc63815a7f46026e13aa71.tar.bz2
[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
-rw-r--r--flang/include/flang/Lower/CustomIntrinsicCall.h12
-rw-r--r--flang/include/flang/Lower/IntrinsicCall.h9
-rw-r--r--flang/lib/Lower/CustomIntrinsicCall.cpp39
-rw-r--r--flang/lib/Lower/IntrinsicCall.cpp19
4 files changed, 42 insertions, 37 deletions
diff --git a/flang/include/flang/Lower/CustomIntrinsicCall.h b/flang/include/flang/Lower/CustomIntrinsicCall.h
index 391aabd..dae94fc1 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 f6c62fd..46ccc5c 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 9b35625..fd2ce92 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 92c4f87..02c2fbf 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,