From 2ad4120746f401959637e467112cb768f945463d Mon Sep 17 00:00:00 2001
From: Alexandre Oliva <oliva@adacore.com>
Date: Sun, 11 Oct 2020 20:27:27 -0300
Subject: [PATCH] import elementary functions as intrinsics

Importing them as intrinsics enables GCC to treat them as builtins
whose behavior is known by GCC.

Specifically, if they aren't intrinsics, calls to Sin and Cos won't be
combined into sincos.

We still need to make Sin and Cos wrappers inline in user-exposed
interfaces to get users the benefit of this transformation.
That is forthcoming in a separate patch.


for  gcc/ada/ChangeLog

	* libgnat/a-numaux.ads: Make all imports Intrinsic.
	* libgnat/a-numaux__darwin.ads: Likewise.
	* libgnat/a-numaux__libc-x86.ads: Likewise.
	* libgnat/a-numaux__vxworks.ads: Likewise.
---
 gcc/ada/libgnat/a-numaux.ads           | 26 +++++++++++++-------------
 gcc/ada/libgnat/a-numaux__darwin.ads   | 22 +++++++++++-----------
 gcc/ada/libgnat/a-numaux__libc-x86.ads | 26 +++++++++++++-------------
 gcc/ada/libgnat/a-numaux__vxworks.ads  | 26 +++++++++++++-------------
 4 files changed, 50 insertions(+), 50 deletions(-)

diff --git a/gcc/ada/libgnat/a-numaux.ads b/gcc/ada/libgnat/a-numaux.ads
index 3ad70671629..4154e1ab216 100644
--- a/gcc/ada/libgnat/a-numaux.ads
+++ b/gcc/ada/libgnat/a-numaux.ads
@@ -58,55 +58,55 @@ package Ada.Numerics.Aux is
    --  all as pure functions, because indeed all of them are in fact pure.
 
    function Sin (X : Double) return Double;
-   pragma Import (C, Sin, "sin");
+   pragma Import (Intrinsic, Sin, "sin");
    pragma Pure_Function (Sin);
 
    function Cos (X : Double) return Double;
-   pragma Import (C, Cos, "cos");
+   pragma Import (Intrinsic, Cos, "cos");
    pragma Pure_Function (Cos);
 
    function Tan (X : Double) return Double;
-   pragma Import (C, Tan, "tan");
+   pragma Import (Intrinsic, Tan, "tan");
    pragma Pure_Function (Tan);
 
    function Exp (X : Double) return Double;
-   pragma Import (C, Exp, "exp");
+   pragma Import (Intrinsic, Exp, "exp");
    pragma Pure_Function (Exp);
 
    function Sqrt (X : Double) return Double;
-   pragma Import (C, Sqrt, "sqrt");
+   pragma Import (Intrinsic, Sqrt, "sqrt");
    pragma Pure_Function (Sqrt);
 
    function Log (X : Double) return Double;
-   pragma Import (C, Log, "log");
+   pragma Import (Intrinsic, Log, "log");
    pragma Pure_Function (Log);
 
    function Acos (X : Double) return Double;
-   pragma Import (C, Acos, "acos");
+   pragma Import (Intrinsic, Acos, "acos");
    pragma Pure_Function (Acos);
 
    function Asin (X : Double) return Double;
-   pragma Import (C, Asin, "asin");
+   pragma Import (Intrinsic, Asin, "asin");
    pragma Pure_Function (Asin);
 
    function Atan (X : Double) return Double;
-   pragma Import (C, Atan, "atan");
+   pragma Import (Intrinsic, Atan, "atan");
    pragma Pure_Function (Atan);
 
    function Sinh (X : Double) return Double;
-   pragma Import (C, Sinh, "sinh");
+   pragma Import (Intrinsic, Sinh, "sinh");
    pragma Pure_Function (Sinh);
 
    function Cosh (X : Double) return Double;
-   pragma Import (C, Cosh, "cosh");
+   pragma Import (Intrinsic, Cosh, "cosh");
    pragma Pure_Function (Cosh);
 
    function Tanh (X : Double) return Double;
-   pragma Import (C, Tanh, "tanh");
+   pragma Import (Intrinsic, Tanh, "tanh");
    pragma Pure_Function (Tanh);
 
    function Pow (X, Y : Double) return Double;
-   pragma Import (C, Pow, "pow");
+   pragma Import (Intrinsic, Pow, "pow");
    pragma Pure_Function (Pow);
 
 end Ada.Numerics.Aux;
diff --git a/gcc/ada/libgnat/a-numaux__darwin.ads b/gcc/ada/libgnat/a-numaux__darwin.ads
index f2a442815bb..add87a49193 100644
--- a/gcc/ada/libgnat/a-numaux__darwin.ads
+++ b/gcc/ada/libgnat/a-numaux__darwin.ads
@@ -57,47 +57,47 @@ package Ada.Numerics.Aux is
    --  all as pure functions, because indeed all of them are in fact pure.
 
    function Tan (X : Double) return Double;
-   pragma Import (C, Tan, "tan");
+   pragma Import (Intrinsic, Tan, "tan");
    pragma Pure_Function (Tan);
 
    function Exp (X : Double) return Double;
-   pragma Import (C, Exp, "exp");
+   pragma Import (Intrinsic, Exp, "exp");
    pragma Pure_Function (Exp);
 
    function Sqrt (X : Double) return Double;
-   pragma Import (C, Sqrt, "sqrt");
+   pragma Import (Intrinsic, Sqrt, "sqrt");
    pragma Pure_Function (Sqrt);
 
    function Log (X : Double) return Double;
-   pragma Import (C, Log, "log");
+   pragma Import (Intrinsic, Log, "log");
    pragma Pure_Function (Log);
 
    function Acos (X : Double) return Double;
-   pragma Import (C, Acos, "acos");
+   pragma Import (Intrinsic, Acos, "acos");
    pragma Pure_Function (Acos);
 
    function Asin (X : Double) return Double;
-   pragma Import (C, Asin, "asin");
+   pragma Import (Intrinsic, Asin, "asin");
    pragma Pure_Function (Asin);
 
    function Atan (X : Double) return Double;
-   pragma Import (C, Atan, "atan");
+   pragma Import (Intrinsic, Atan, "atan");
    pragma Pure_Function (Atan);
 
    function Sinh (X : Double) return Double;
-   pragma Import (C, Sinh, "sinh");
+   pragma Import (Intrinsic, Sinh, "sinh");
    pragma Pure_Function (Sinh);
 
    function Cosh (X : Double) return Double;
-   pragma Import (C, Cosh, "cosh");
+   pragma Import (Intrinsic, Cosh, "cosh");
    pragma Pure_Function (Cosh);
 
    function Tanh (X : Double) return Double;
-   pragma Import (C, Tanh, "tanh");
+   pragma Import (Intrinsic, Tanh, "tanh");
    pragma Pure_Function (Tanh);
 
    function Pow (X, Y : Double) return Double;
-   pragma Import (C, Pow, "pow");
+   pragma Import (Intrinsic, Pow, "pow");
    pragma Pure_Function (Pow);
 
 end Ada.Numerics.Aux;
diff --git a/gcc/ada/libgnat/a-numaux__libc-x86.ads b/gcc/ada/libgnat/a-numaux__libc-x86.ads
index c4647fd7005..f6deebecbad 100644
--- a/gcc/ada/libgnat/a-numaux__libc-x86.ads
+++ b/gcc/ada/libgnat/a-numaux__libc-x86.ads
@@ -43,55 +43,55 @@ package Ada.Numerics.Aux is
    --  all as pure functions, because indeed all of them are in fact pure.
 
    function Sin (X : Double) return Double;
-   pragma Import (C, Sin, "sinl");
+   pragma Import (Intrinsic, Sin, "sinl");
    pragma Pure_Function (Sin);
 
    function Cos (X : Double) return Double;
-   pragma Import (C, Cos, "cosl");
+   pragma Import (Intrinsic, Cos, "cosl");
    pragma Pure_Function (Cos);
 
    function Tan (X : Double) return Double;
-   pragma Import (C, Tan, "tanl");
+   pragma Import (Intrinsic, Tan, "tanl");
    pragma Pure_Function (Tan);
 
    function Exp (X : Double) return Double;
-   pragma Import (C, Exp, "expl");
+   pragma Import (Intrinsic, Exp, "expl");
    pragma Pure_Function (Exp);
 
    function Sqrt (X : Double) return Double;
-   pragma Import (C, Sqrt, "sqrtl");
+   pragma Import (Intrinsic, Sqrt, "sqrtl");
    pragma Pure_Function (Sqrt);
 
    function Log (X : Double) return Double;
-   pragma Import (C, Log, "logl");
+   pragma Import (Intrinsic, Log, "logl");
    pragma Pure_Function (Log);
 
    function Acos (X : Double) return Double;
-   pragma Import (C, Acos, "acosl");
+   pragma Import (Intrinsic, Acos, "acosl");
    pragma Pure_Function (Acos);
 
    function Asin (X : Double) return Double;
-   pragma Import (C, Asin, "asinl");
+   pragma Import (Intrinsic, Asin, "asinl");
    pragma Pure_Function (Asin);
 
    function Atan (X : Double) return Double;
-   pragma Import (C, Atan, "atanl");
+   pragma Import (Intrinsic, Atan, "atanl");
    pragma Pure_Function (Atan);
 
    function Sinh (X : Double) return Double;
-   pragma Import (C, Sinh, "sinhl");
+   pragma Import (Intrinsic, Sinh, "sinhl");
    pragma Pure_Function (Sinh);
 
    function Cosh (X : Double) return Double;
-   pragma Import (C, Cosh, "coshl");
+   pragma Import (Intrinsic, Cosh, "coshl");
    pragma Pure_Function (Cosh);
 
    function Tanh (X : Double) return Double;
-   pragma Import (C, Tanh, "tanhl");
+   pragma Import (Intrinsic, Tanh, "tanhl");
    pragma Pure_Function (Tanh);
 
    function Pow (X, Y : Double) return Double;
-   pragma Import (C, Pow, "powl");
+   pragma Import (Intrinsic, Pow, "powl");
    pragma Pure_Function (Pow);
 
 end Ada.Numerics.Aux;
diff --git a/gcc/ada/libgnat/a-numaux__vxworks.ads b/gcc/ada/libgnat/a-numaux__vxworks.ads
index c291334304e..410655de8a6 100644
--- a/gcc/ada/libgnat/a-numaux__vxworks.ads
+++ b/gcc/ada/libgnat/a-numaux__vxworks.ads
@@ -43,55 +43,55 @@ package Ada.Numerics.Aux is
    --  all as pure functions, because indeed all of them are in fact pure.
 
    function Sin (X : Double) return Double;
-   pragma Import (C, Sin, "sin");
+   pragma Import (Intrinsic, Sin, "sin");
    pragma Pure_Function (Sin);
 
    function Cos (X : Double) return Double;
-   pragma Import (C, Cos, "cos");
+   pragma Import (Intrinsic, Cos, "cos");
    pragma Pure_Function (Cos);
 
    function Tan (X : Double) return Double;
-   pragma Import (C, Tan, "tan");
+   pragma Import (Intrinsic, Tan, "tan");
    pragma Pure_Function (Tan);
 
    function Exp (X : Double) return Double;
-   pragma Import (C, Exp, "exp");
+   pragma Import (Intrinsic, Exp, "exp");
    pragma Pure_Function (Exp);
 
    function Sqrt (X : Double) return Double;
-   pragma Import (C, Sqrt, "sqrt");
+   pragma Import (Intrinsic, Sqrt, "sqrt");
    pragma Pure_Function (Sqrt);
 
    function Log (X : Double) return Double;
-   pragma Import (C, Log, "log");
+   pragma Import (Intrinsic, Log, "log");
    pragma Pure_Function (Log);
 
    function Acos (X : Double) return Double;
-   pragma Import (C, Acos, "acos");
+   pragma Import (Intrinsic, Acos, "acos");
    pragma Pure_Function (Acos);
 
    function Asin (X : Double) return Double;
-   pragma Import (C, Asin, "asin");
+   pragma Import (Intrinsic, Asin, "asin");
    pragma Pure_Function (Asin);
 
    function Atan (X : Double) return Double;
-   pragma Import (C, Atan, "atan");
+   pragma Import (Intrinsic, Atan, "atan");
    pragma Pure_Function (Atan);
 
    function Sinh (X : Double) return Double;
-   pragma Import (C, Sinh, "sinh");
+   pragma Import (Intrinsic, Sinh, "sinh");
    pragma Pure_Function (Sinh);
 
    function Cosh (X : Double) return Double;
-   pragma Import (C, Cosh, "cosh");
+   pragma Import (Intrinsic, Cosh, "cosh");
    pragma Pure_Function (Cosh);
 
    function Tanh (X : Double) return Double;
-   pragma Import (C, Tanh, "tanh");
+   pragma Import (Intrinsic, Tanh, "tanh");
    pragma Pure_Function (Tanh);
 
    function Pow (X, Y : Double) return Double;
-   pragma Import (C, Pow, "pow");
+   pragma Import (Intrinsic, Pow, "pow");
    pragma Pure_Function (Pow);
 
 end Ada.Numerics.Aux;
-- 
2.30.2