ipa-cp.c (ipcp_cloning_candidate_p): Use opt_for_fn.
[gcc.git] / gcc / plugin.c
index 2179b8192885d47dbf42c16fd8a88653ea39b926..8debc09cada18a08f961f633851a8c394f163807 100644 (file)
@@ -1,5 +1,5 @@
 /* Support for GCC plugin mechanism.
-   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2009-2014 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -22,22 +22,13 @@ along with GCC; see the file COPYING3.  If not see
 
 #include "config.h"
 #include "system.h"
-
-/* If plugin support is not enabled, do not try to execute any code
-   that may reference libdl.  The generic code is still compiled in to
-   avoid including too many conditional compilation paths in the rest
-   of the compiler.  */
-#ifdef ENABLE_PLUGIN
-#include <dlfcn.h>
-#endif
-
 #include "coretypes.h"
+#include "hash-table.h"
 #include "diagnostic-core.h"
 #include "tree.h"
 #include "tree-pass.h"
 #include "intl.h"
 #include "plugin.h"
-#include "timevar.h"
 #include "ggc.h"
 
 #ifdef ENABLE_PLUGIN
@@ -60,9 +51,36 @@ static const char *plugin_event_name_init[] =
 
 const char **plugin_event_name = plugin_event_name_init;
 
+/* Event hashtable helpers.  */
+
+struct event_hasher : typed_noop_remove <const char *>
+{
+  typedef const char *value_type;
+  typedef const char *compare_type;
+  static inline hashval_t hash (const value_type *);
+  static inline bool equal (const value_type *, const compare_type *);
+};
+
+/* Helper function for the event hash table that hashes the entry V.  */
+
+inline hashval_t
+event_hasher::hash (const value_type *v)
+{
+  return htab_hash_string (*v);
+}
+
+/* Helper function for the event hash table that compares the name of an
+   existing entry (S1) with the given string (S2).  */
+
+inline bool
+event_hasher::equal (const value_type *s1, const compare_type *s2)
+{
+  return !strcmp (*s1, *s2);
+}
+
 /* A hash table to map event names to the position of the names in the
    plugin_event_name table.  */
-static htab_t event_tab;
+static hash_table<event_hasher> *event_tab;
 
 /* Keep track of the limit of allocated events and space ready for
    allocating events.  */
@@ -158,7 +176,7 @@ add_new_plugin (const char* plugin_name)
                            plugin_name, ".so", NULL);
       if (access (plugin_name, R_OK))
        fatal_error
-         ("inacessible plugin file %s expanded from short plugin name %s: %m",
+         ("inaccessible plugin file %s expanded from short plugin name %s: %m",
           plugin_name, base_name);
     }
   else
@@ -223,16 +241,13 @@ parse_plugin_arg_opt (const char *arg)
         }
       else if (*ptr == '=')
         {
-          if (key_parsed)
-            {
-              error ("malformed option -fplugin-arg-%s (multiple '=' signs)",
-                    arg);
-              return;
-            }
-          key_len = len;
-          len = 0;
-          value_start = ptr + 1;
-          key_parsed = true;
+         if (!key_parsed) 
+           {
+             key_len = len;
+             len = 0;
+             value_start = ptr + 1;
+             key_parsed = true;
+           }
           continue;
         }
       else
@@ -322,41 +337,31 @@ register_plugin_info (const char* name, struct plugin_info *info)
   plugin->help = info->help;
 }
 
-/* Helper function for the event hash table that compares the name of an
-   existing entry (E1) with the given string (S2).  */
-
-static int
-htab_event_eq (const void *e1, const void *s2)
-{
-  const char *s1= *(const char * const *) e1;
-  return !strcmp (s1, (const char *) s2);
-}
-
 /* Look up the event id for NAME.  If the name is not found, return -1
    if INSERT is NO_INSERT.  */
 
 int
 get_named_event_id (const char *name, enum insert_option insert)
 {
-  void **slot;
+  const char ***slot;
 
   if (!event_tab)
     {
       int i;
 
-      event_tab = htab_create (150, htab_hash_string, htab_event_eq, NULL);
+      event_tab = new hash_table<event_hasher> (150);
       for (i = 0; i < event_last; i++)
        {
-         slot = htab_find_slot (event_tab, plugin_event_name[i], INSERT);
+         slot = event_tab->find_slot (&plugin_event_name[i], INSERT);
          gcc_assert (*slot == HTAB_EMPTY_ENTRY);
          *slot = &plugin_event_name[i];
        }
     }
-  slot = htab_find_slot (event_tab, name, insert);
+  slot = event_tab->find_slot (&name, insert);
   if (slot == NULL)
     return -1;
   if (*slot != HTAB_EMPTY_ENTRY)
-    return (const char **) *slot - &plugin_event_name[0];
+    return *slot - &plugin_event_name[0];
 
   if (event_last >= event_horizon)
     {
@@ -378,7 +383,7 @@ get_named_event_id (const char *name, enum insert_option insert)
                                         plugin_callbacks, event_horizon);
        }
       /* All the pointers in the hash table will need to be updated.  */
-      htab_delete (event_tab);
+      delete event_tab;
       event_tab = NULL;
     }
   else
@@ -429,6 +434,7 @@ register_callback (const char *plugin_name,
          }
       /* Fall through.  */
       case PLUGIN_FINISH_TYPE:
+      case PLUGIN_FINISH_DECL:
       case PLUGIN_START_UNIT:
       case PLUGIN_FINISH_UNIT:
       case PLUGIN_PRE_GENERICIZE:
@@ -447,6 +453,7 @@ register_callback (const char *plugin_name,
       case PLUGIN_EARLY_GIMPLE_PASSES_START:
       case PLUGIN_EARLY_GIMPLE_PASSES_END:
       case PLUGIN_NEW_PASS:
+      case PLUGIN_INCLUDE_FILE:
         {
           struct callback_info *new_callback;
           if (!callback)
@@ -505,6 +512,7 @@ invoke_plugin_callbacks_full (int event, void *gcc_data)
        gcc_assert (event < event_last);
       /* Fall through.  */
       case PLUGIN_FINISH_TYPE:
+      case PLUGIN_FINISH_DECL:
       case PLUGIN_START_UNIT:
       case PLUGIN_FINISH_UNIT:
       case PLUGIN_PRE_GENERICIZE:
@@ -523,6 +531,7 @@ invoke_plugin_callbacks_full (int event, void *gcc_data)
       case PLUGIN_EARLY_GIMPLE_PASSES_START:
       case PLUGIN_EARLY_GIMPLE_PASSES_END:
       case PLUGIN_NEW_PASS:
+      case PLUGIN_INCLUDE_FILE:
         {
           /* Iterate over every callback registered with this event and
              call it.  */
@@ -797,7 +806,7 @@ dump_active_plugins (FILE *file)
        for (ci = plugin_callbacks[event]; ci; ci = ci->next)
          fprintf (file, " %s", ci->plugin_name);
 
-       putc('\n', file);
+       putc ('\n', file);
       }
 }
 
@@ -872,7 +881,7 @@ get_event_last (void)
 
 
 /* Retrieve the default plugin directory.  The gcc driver should have passed
-   it as -iplugindir <dir> to the cc1 program, and it is queriable thru the
+   it as -iplugindir <dir> to the cc1 program, and it is queriable through the
    -print-file-name=plugin option to gcc.  */
 const char*
 default_plugin_dir_name (void)