[flang-commits] [flang] [flang] Show types in DumpEvExpr (PR #143743)
Krzysztof Parzyszek via flang-commits
flang-commits at lists.llvm.org
Mon Jun 16 09:17:55 PDT 2025
https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/143743
>From 98f8ca78e14f146e40c044892065747e56b790f8 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Mon, 24 Mar 2025 15:38:58 -0500
Subject: [PATCH 1/6] [flang] Show types in DumpEvExpr
When dumping evaluate::Expr, show type information which contains a lot
of useful information.
For example show
```
expr <Fortran::evaluate::SomeType> {
expr <Fortran::evaluate::SomeKind<Fortran::common::TypeCategory::Integer>> {
expr <Fortran::evaluate::Type<Fortran::common::TypeCategory::Integer, 4>> {
...
```
instead of
```
expr {
expr {
expr {
...
```
---
flang/include/flang/Semantics/dump-expr.h | 42 ++++++++++++++++++-----
flang/lib/Semantics/dump-expr.cpp | 2 +-
2 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/flang/include/flang/Semantics/dump-expr.h b/flang/include/flang/Semantics/dump-expr.h
index 2f445429a10b5..3a6a313546bb5 100644
--- a/flang/include/flang/Semantics/dump-expr.h
+++ b/flang/include/flang/Semantics/dump-expr.h
@@ -16,6 +16,7 @@
#include <memory>
#include <optional>
+#include <string>
#include <variant>
#include <vector>
@@ -38,6 +39,29 @@ class DumpEvaluateExpr {
}
private:
+ template <typename T>
+ struct TypeOf {
+ static constexpr std::string_view name{TypeOf<T>::get()};
+ static constexpr std::string_view get() {
+ std::string_view v(__PRETTY_FUNCTION__);
+ // Extract the "xyz" from the "pretty function" string:
+ // "... [with T = xyz; std::string_view = ...]"
+ std::string_view front("with T = ");
+ std::string_view back("; std::string_view =");
+
+ if (auto fpos{v.find(front)}; fpos != v.npos) {
+ // Strip the part "... [with T = "
+ v.remove_prefix(fpos + front.size());
+ if (auto bpos{v.find(back)}; bpos != v.npos) {
+ // Strip the ending "; std::string_view = ...]"
+ v.remove_suffix(v.size() - bpos);
+ return v;
+ }
+ }
+ return "";
+ }
+ };
+
template <typename A, bool C> void Show(const common::Indirection<A, C> &x) {
Show(x.value());
}
@@ -76,7 +100,7 @@ class DumpEvaluateExpr {
void Show(const evaluate::NullPointer &);
template <typename T> void Show(const evaluate::Constant<T> &x) {
if constexpr (T::category == common::TypeCategory::Derived) {
- Indent("derived constant");
+ Indent("derived constant "s + std::string(TypeOf<T>::name));
for (const auto &map : x.values()) {
for (const auto &pair : map) {
Show(pair.second.value());
@@ -84,7 +108,7 @@ class DumpEvaluateExpr {
}
Outdent();
} else {
- Print("constant");
+ Print("constant "s + std::string(TypeOf<T>::name));
}
}
void Show(const Symbol &symbol);
@@ -102,7 +126,7 @@ class DumpEvaluateExpr {
void Show(const evaluate::Substring &x);
void Show(const evaluate::ComplexPart &x);
template <typename T> void Show(const evaluate::Designator<T> &x) {
- Indent("designator");
+ Indent("designator "s + std::string(TypeOf<T>::name));
Show(x.u);
Outdent();
}
@@ -117,7 +141,7 @@ class DumpEvaluateExpr {
Outdent();
}
template <typename T> void Show(const evaluate::FunctionRef<T> &x) {
- Indent("function ref");
+ Indent("function ref "s + std::string(TypeOf<T>::name));
Show(x.proc());
Show(x.arguments());
Outdent();
@@ -127,14 +151,14 @@ class DumpEvaluateExpr {
}
template <typename T>
void Show(const evaluate::ArrayConstructorValues<T> &x) {
- Indent("array constructor value");
+ Indent("array constructor value "s + std::string(TypeOf<T>::name));
for (auto &v : x) {
Show(v);
}
Outdent();
}
template <typename T> void Show(const evaluate::ImpliedDo<T> &x) {
- Indent("implied do");
+ Indent("implied do "s + std::string(TypeOf<T>::name));
Show(x.lower());
Show(x.upper());
Show(x.stride());
@@ -148,20 +172,20 @@ class DumpEvaluateExpr {
void Show(const evaluate::StructureConstructor &x);
template <typename D, typename R, typename O>
void Show(const evaluate::Operation<D, R, O> &op) {
- Indent("unary op");
+ Indent("unary op "s + std::string(TypeOf<D>::name));
Show(op.left());
Outdent();
}
template <typename D, typename R, typename LO, typename RO>
void Show(const evaluate::Operation<D, R, LO, RO> &op) {
- Indent("binary op");
+ Indent("binary op "s + std::string(TypeOf<D>::name));
Show(op.left());
Show(op.right());
Outdent();
}
void Show(const evaluate::Relational<evaluate::SomeType> &x);
template <typename T> void Show(const evaluate::Expr<T> &x) {
- Indent("expr T");
+ Indent("expr <" + std::string(TypeOf<T>::name) + ">");
Show(x.u);
Outdent();
}
diff --git a/flang/lib/Semantics/dump-expr.cpp b/flang/lib/Semantics/dump-expr.cpp
index aa0b4e0f03398..66cedab94bfb4 100644
--- a/flang/lib/Semantics/dump-expr.cpp
+++ b/flang/lib/Semantics/dump-expr.cpp
@@ -151,7 +151,7 @@ void DumpEvaluateExpr::Show(const evaluate::StructureConstructor &x) {
}
void DumpEvaluateExpr::Show(const evaluate::Relational<evaluate::SomeType> &x) {
- Indent("expr some type");
+ Indent("relational some type");
Show(x.u);
Outdent();
}
>From d4d8095daed661d1b900ee8c81fec5a748c48ef2 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Wed, 11 Jun 2025 11:35:16 -0500
Subject: [PATCH 2/6] format
---
flang/include/flang/Semantics/dump-expr.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/flang/include/flang/Semantics/dump-expr.h b/flang/include/flang/Semantics/dump-expr.h
index 3a6a313546bb5..b7fbd0a1aa278 100644
--- a/flang/include/flang/Semantics/dump-expr.h
+++ b/flang/include/flang/Semantics/dump-expr.h
@@ -39,8 +39,7 @@ class DumpEvaluateExpr {
}
private:
- template <typename T>
- struct TypeOf {
+ template <typename T> struct TypeOf {
static constexpr std::string_view name{TypeOf<T>::get()};
static constexpr std::string_view get() {
std::string_view v(__PRETTY_FUNCTION__);
>From 8babecf533e675a54daee979204f095dd4542927 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Wed, 11 Jun 2025 12:19:49 -0500
Subject: [PATCH 3/6] Reorder declarations
---
flang/include/flang/Semantics/dump-expr.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/flang/include/flang/Semantics/dump-expr.h b/flang/include/flang/Semantics/dump-expr.h
index b7fbd0a1aa278..1adb5904a1699 100644
--- a/flang/include/flang/Semantics/dump-expr.h
+++ b/flang/include/flang/Semantics/dump-expr.h
@@ -40,7 +40,6 @@ class DumpEvaluateExpr {
private:
template <typename T> struct TypeOf {
- static constexpr std::string_view name{TypeOf<T>::get()};
static constexpr std::string_view get() {
std::string_view v(__PRETTY_FUNCTION__);
// Extract the "xyz" from the "pretty function" string:
@@ -59,6 +58,8 @@ class DumpEvaluateExpr {
}
return "";
}
+
+ static constexpr std::string_view name{TypeOf<T>::get()};
};
template <typename A, bool C> void Show(const common::Indirection<A, C> &x) {
>From f29be61b035952422ab7bfabdb1f2668b722ce41 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Wed, 11 Jun 2025 14:11:11 -0500
Subject: [PATCH 4/6] Fix for MSVC
---
flang/include/flang/Semantics/dump-expr.h | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/flang/include/flang/Semantics/dump-expr.h b/flang/include/flang/Semantics/dump-expr.h
index 1adb5904a1699..3a76390234717 100644
--- a/flang/include/flang/Semantics/dump-expr.h
+++ b/flang/include/flang/Semantics/dump-expr.h
@@ -41,17 +41,27 @@ class DumpEvaluateExpr {
private:
template <typename T> struct TypeOf {
static constexpr std::string_view get() {
+#if defined(__GNUC__)
std::string_view v(__PRETTY_FUNCTION__);
// Extract the "xyz" from the "pretty function" string:
// "... [with T = xyz; std::string_view = ...]"
std::string_view front("with T = ");
std::string_view back("; std::string_view =");
+#elif defined(_MSC_VER)
+ std::string_view v(__FUNCSIG__);
+ // Extract the "xyz" from the "pretty function" string:
+ // "... TypeOf<xyz>::get(void)"
+ std::string_view front(" TypeOf<");
+ std::string_view back(">::get(void)");
+
+#else
+ return "";
+#endif
+
if (auto fpos{v.find(front)}; fpos != v.npos) {
- // Strip the part "... [with T = "
v.remove_prefix(fpos + front.size());
if (auto bpos{v.find(back)}; bpos != v.npos) {
- // Strip the ending "; std::string_view = ...]"
v.remove_suffix(v.size() - bpos);
return v;
}
>From f7a2234f720027c40ec23dbf016ca3e162ef4cc4 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Mon, 16 Jun 2025 11:07:04 -0500
Subject: [PATCH 5/6] Fix for MSVC
---
flang/include/flang/Semantics/dump-expr.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/flang/include/flang/Semantics/dump-expr.h b/flang/include/flang/Semantics/dump-expr.h
index 3a76390234717..f0d9b4c0eed93 100644
--- a/flang/include/flang/Semantics/dump-expr.h
+++ b/flang/include/flang/Semantics/dump-expr.h
@@ -51,8 +51,8 @@ class DumpEvaluateExpr {
#elif defined(_MSC_VER)
std::string_view v(__FUNCSIG__);
// Extract the "xyz" from the "pretty function" string:
- // "... TypeOf<xyz>::get(void)"
- std::string_view front(" TypeOf<");
+ // "...TypeOf<xyz>::get(void)"
+ std::string_view front("TypeOf<");
std::string_view back(">::get(void)");
#else
>From 375b7d01d236a942be8f93dd65feb69493491ebf Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Mon, 16 Jun 2025 11:11:27 -0500
Subject: [PATCH 6/6] Guard more code
---
flang/include/flang/Semantics/dump-expr.h | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/flang/include/flang/Semantics/dump-expr.h b/flang/include/flang/Semantics/dump-expr.h
index f0d9b4c0eed93..9cc52b4da487d 100644
--- a/flang/include/flang/Semantics/dump-expr.h
+++ b/flang/include/flang/Semantics/dump-expr.h
@@ -42,6 +42,7 @@ class DumpEvaluateExpr {
template <typename T> struct TypeOf {
static constexpr std::string_view get() {
#if defined(__GNUC__)
+#define DUMP_EXPR_SHOW_TYPE
std::string_view v(__PRETTY_FUNCTION__);
// Extract the "xyz" from the "pretty function" string:
// "... [with T = xyz; std::string_view = ...]"
@@ -49,16 +50,17 @@ class DumpEvaluateExpr {
std::string_view back("; std::string_view =");
#elif defined(_MSC_VER)
+#define DUMP_EXPR_SHOW_TYPE
std::string_view v(__FUNCSIG__);
// Extract the "xyz" from the "pretty function" string:
// "...TypeOf<xyz>::get(void)"
std::string_view front("TypeOf<");
std::string_view back(">::get(void)");
-#else
- return "";
#endif
+#if defined(DUMP_EXPR_SHOW_TYPE)
+#undef DUMP_EXPR_SHOW_TYPE
if (auto fpos{v.find(front)}; fpos != v.npos) {
v.remove_prefix(fpos + front.size());
if (auto bpos{v.find(back)}; bpos != v.npos) {
@@ -66,6 +68,8 @@ class DumpEvaluateExpr {
return v;
}
}
+#endif
+
return "";
}
More information about the flang-commits
mailing list