[flang-commits] [flang] 67e41df - [flang] Expose specific to generic intrinsic name mapping

Jean Perier via flang-commits flang-commits at lists.llvm.org
Thu Jul 30 05:31:02 PDT 2020


Author: Jean Perier
Date: 2020-07-30T14:30:12+02:00
New Revision: 67e41df4e03e934b2990cd7f0b7f5d4e0a58e14f

URL: https://github.com/llvm/llvm-project/commit/67e41df4e03e934b2990cd7f0b7f5d4e0a58e14f
DIFF: https://github.com/llvm/llvm-project/commit/67e41df4e03e934b2990cd7f0b7f5d4e0a58e14f.diff

LOG: [flang] Expose specific to generic intrinsic name mapping

The intrinsic lowering facility is based on the generic intrinsic names to avoid
duplicating implementations. Specific intrinsics call are re-written to call to
the generic versions by the front-end but this cannot be done when specific intrinsics
are passed as arguments (the rewrite would give illegal/ambiguous unparsed Fortran).
Solve the issue by making the specific to generic name mapping accessible to lowering
and can be later used to generate the unrestricted intrinsic functions.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D84842

Added: 
    

Modified: 
    flang/include/flang/Evaluate/intrinsics.h
    flang/lib/Evaluate/intrinsics.cpp
    flang/unittests/Evaluate/intrinsics.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Evaluate/intrinsics.h b/flang/include/flang/Evaluate/intrinsics.h
index 88d6a7af13eb..50212a1434c3 100644
--- a/flang/include/flang/Evaluate/intrinsics.h
+++ b/flang/include/flang/Evaluate/intrinsics.h
@@ -76,6 +76,11 @@ class IntrinsicProcTable {
   // Inquiry intrinsics are defined in section 16.7, table 16.1
   IntrinsicClass GetIntrinsicClass(const std::string &) const;
 
+  // Return the generic name of a specific intrinsic name.
+  // The name provided is returned if it is a generic intrinsic name or is
+  // not known to be an intrinsic.
+  std::string GetGenericIntrinsicName(const std::string &) const;
+
   // Probe the intrinsics for a match against a specific call.
   // On success, the actual arguments are transferred to the result
   // in dummy argument order; on failure, the actual arguments remain

diff  --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index 6237499d12ef..0ad5c195ae86 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -1568,6 +1568,7 @@ class IntrinsicProcTable::Implementation {
   bool IsIntrinsic(const std::string &) const;
 
   IntrinsicClass GetIntrinsicClass(const std::string &) const;
+  std::string GetGenericIntrinsicName(const std::string &) const;
 
   std::optional<SpecificCall> Probe(const CallCharacteristics &,
       ActualArguments &, FoldingContext &, const IntrinsicProcTable &) const;
@@ -1625,6 +1626,17 @@ IntrinsicClass IntrinsicProcTable::Implementation::GetIntrinsicClass(
   return IntrinsicClass::noClass;
 }
 
+std::string IntrinsicProcTable::Implementation::GetGenericIntrinsicName(
+    const std::string &name) const {
+  auto specificIntrinsic{specificFuncs_.find(name)};
+  if (specificIntrinsic != specificFuncs_.end()) {
+    if (const char *genericName{specificIntrinsic->second->generic}) {
+      return {genericName};
+    }
+  }
+  return name;
+}
+
 bool CheckAndRearrangeArguments(ActualArguments &arguments,
     parser::ContextualMessages &messages, const char *const dummyKeywords[],
     std::size_t trailingOptionals) {
@@ -2075,6 +2087,11 @@ IntrinsicClass IntrinsicProcTable::GetIntrinsicClass(
   return DEREF(impl_).GetIntrinsicClass(name);
 }
 
+std::string IntrinsicProcTable::GetGenericIntrinsicName(
+    const std::string &name) const {
+  return DEREF(impl_).GetGenericIntrinsicName(name);
+}
+
 std::optional<SpecificCall> IntrinsicProcTable::Probe(
     const CallCharacteristics &call, ActualArguments &arguments,
     FoldingContext &context) const {

diff  --git a/flang/unittests/Evaluate/intrinsics.cpp b/flang/unittests/Evaluate/intrinsics.cpp
index 57f71965f8d9..7b8895b8da4c 100644
--- a/flang/unittests/Evaluate/intrinsics.cpp
+++ b/flang/unittests/Evaluate/intrinsics.cpp
@@ -292,6 +292,43 @@ void TestIntrinsics() {
       .DoCall(); // bad type
 
   // TODO: test other intrinsics
+
+  // Test unrestricted specific to generic name mapping (table 16.2).
+  TEST(table.GetGenericIntrinsicName("alog") == "log");
+  TEST(table.GetGenericIntrinsicName("alog10") == "log10");
+  TEST(table.GetGenericIntrinsicName("amod") == "mod");
+  TEST(table.GetGenericIntrinsicName("cabs") == "abs");
+  TEST(table.GetGenericIntrinsicName("ccos") == "cos");
+  TEST(table.GetGenericIntrinsicName("cexp") == "exp");
+  TEST(table.GetGenericIntrinsicName("clog") == "log");
+  TEST(table.GetGenericIntrinsicName("csin") == "sin");
+  TEST(table.GetGenericIntrinsicName("csqrt") == "sqrt");
+  TEST(table.GetGenericIntrinsicName("dabs") == "abs");
+  TEST(table.GetGenericIntrinsicName("dacos") == "acos");
+  TEST(table.GetGenericIntrinsicName("dasin") == "asin");
+  TEST(table.GetGenericIntrinsicName("datan") == "atan");
+  TEST(table.GetGenericIntrinsicName("datan2") == "atan2");
+  TEST(table.GetGenericIntrinsicName("dcos") == "cos");
+  TEST(table.GetGenericIntrinsicName("dcosh") == "cosh");
+  TEST(table.GetGenericIntrinsicName("ddim") == "dim");
+  TEST(table.GetGenericIntrinsicName("dexp") == "exp");
+  TEST(table.GetGenericIntrinsicName("dint") == "aint");
+  TEST(table.GetGenericIntrinsicName("dlog") == "log");
+  TEST(table.GetGenericIntrinsicName("dlog10") == "log10");
+  TEST(table.GetGenericIntrinsicName("dmod") == "mod");
+  TEST(table.GetGenericIntrinsicName("dnint") == "anint");
+  TEST(table.GetGenericIntrinsicName("dsign") == "sign");
+  TEST(table.GetGenericIntrinsicName("dsin") == "sin");
+  TEST(table.GetGenericIntrinsicName("dsinh") == "sinh");
+  TEST(table.GetGenericIntrinsicName("dsqrt") == "sqrt");
+  TEST(table.GetGenericIntrinsicName("dtan") == "tan");
+  TEST(table.GetGenericIntrinsicName("dtanh") == "tanh");
+  TEST(table.GetGenericIntrinsicName("iabs") == "abs");
+  TEST(table.GetGenericIntrinsicName("idim") == "dim");
+  TEST(table.GetGenericIntrinsicName("idnint") == "nint");
+  TEST(table.GetGenericIntrinsicName("isign") == "sign");
+  // Test a case where specific and generic name are the same.
+  TEST(table.GetGenericIntrinsicName("acos") == "acos");
 }
 } // namespace Fortran::evaluate
 


        


More information about the flang-commits mailing list