Patchwork [Ada] Reduce compilation time at -O0 (2/n)

login
register
mail settings
Submitter Arnaud Charlet
Date Aug. 2, 2011, 10:08 a.m.
Message ID <20110802100808.GA13495@adacore.com>
Download mbox | patch
Permalink /patch/107877/
State New
Headers show

Comments

Arnaud Charlet - Aug. 2, 2011, 10:08 a.m.
This patch slightly reduces compilation time at -O0 in typical conditions by
tuning the implementation of Base_Type to make it more easily optimizable.

No functional changes.

Tested on x86_64-pc-linux-gnu, committed on trunk

2011-08-02  Eric Botcazou  <ebotcazou@adacore.com>

	* einfo.adb (Base_Type): Tune implementation for speed.

Patch

Index: einfo.adb
===================================================================
--- einfo.adb	(revision 177110)
+++ einfo.adb	(working copy)
@@ -5608,7 +5608,13 @@ 
    ---------------
 
    function Base_Type (Id : E) return E is
+      Is_Base_Type : Boolean;
    begin
+      --  Implementation note: this function shows up high in the profile.
+      --  We use a fully static case construct so as to make it easier for
+      --  the compiler to build a static table out of it, instead of using
+      --  a less efficient jump table.
+
       case Ekind (Id) is
          when E_Enumeration_Subtype          |
               E_Incomplete_Type              |
@@ -5628,11 +5634,17 @@ 
               E_Task_Subtype                 |
               E_String_Literal_Subtype       |
               E_Class_Wide_Subtype           =>
-            return Etype (Id);
+            Is_Base_Type := False;
 
          when others =>
-            return Id;
+            Is_Base_Type := True;
       end case;
+
+      if Is_Base_Type then
+         return Id;
+      end if;
+
+      return Etype (Id);
    end Base_Type;
 
    -------------------------