[flang-commits] [flang] [flang][Evaluate] Add `AsGenericExpr` that takes std::optional (PR #81264)
Krzysztof Parzyszek via flang-commits
flang-commits at lists.llvm.org
Fri Feb 9 08:19:52 PST 2024
https://github.com/kparzysz created https://github.com/llvm/llvm-project/pull/81264
`AsGenericExpr` already returns optional Expr. Making it accept an optional Expr as input would reduce the number of necessary checks when handling frequent optional values in evaluator.
>From 37ac5b42e0e4693bc0483db82721f9cbde66959c Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Thu, 8 Feb 2024 08:32:41 -0600
Subject: [PATCH] [flang][Evaluate] Add `AsGenericExpt` that takes
std::optional
`AsGenericExpr` already returns optional Expr. Making it accept an
optional Expr as input would reduce the number of necessary checks
when handling frequent optional values in evaluator.
---
flang/include/flang/Evaluate/tools.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index d257da1a709642..f7f155a5da9e13 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -148,6 +148,14 @@ inline Expr<SomeType> AsGenericExpr(Expr<SomeType> &&x) { return std::move(x); }
std::optional<Expr<SomeType>> AsGenericExpr(DataRef &&);
std::optional<Expr<SomeType>> AsGenericExpr(const Symbol &);
+// Propagate std::optional from input to output.
+template <typename A>
+std::optional<Expr<SomeType>> AsGenericExpr(std::optional<A> &&x) {
+ if (!x)
+ return std::nullopt;
+ return AsGenericExpr(std::move(*x));
+}
+
template <typename A>
common::IfNoLvalue<Expr<SomeKind<ResultType<A>::category>>, A> AsCategoryExpr(
A &&x) {
More information about the flang-commits
mailing list