From 35b5598e5d21f979fcc038c7b5bb457c25d5d889 Mon Sep 17 00:00:00 2001
From: Erick Ochoa <eochoa@gcc.gnu.org>
Date: Wed, 8 Sep 2021 21:26:31 +0200
Subject: [PATCH 2/4] Printing

---
 gcc/ipa-hash.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 105 insertions(+), 1 deletion(-)

diff --git a/gcc/ipa-hash.c b/gcc/ipa-hash.c
index 84abe1da0d9..58d9157a124 100644
--- a/gcc/ipa-hash.c
+++ b/gcc/ipa-hash.c
@@ -26,16 +26,120 @@
 #include "lto-streamer.h"
 #include "ipa-hash.h"
 
+class symtab_wrapper_traits;
+class symtab_wrapper
+{
+private:
+  symtab_node *_symtab_node;
+public:
+  friend symtab_wrapper_traits;
+  symtab_wrapper ()
+    : _symtab_node (NULL)
+  {}
+  symtab_wrapper (symtab_node *s)
+    : _symtab_node (s)
+  { gcc_assert (s); }
+
+  void print (void)
+  {
+    if (!dump_file) return;
+    gcc_assert (_symtab_node);
+    fprintf (dump_file, "%s\n", _symtab_node->name ());
+  }
+};
+
+template <typename KeyId, bool Lazy = false, typename Traits = default_hash_traits <KeyId> >
+class my_set_t
+{
+private:
+  hash_set <KeyId, Lazy, Traits> _impl;
+public:
+  my_set_t () {}
+
+  void insert (const KeyId &k)
+  {
+    _impl.add (k);
+  }
+
+  bool contains (const KeyId &k)
+  {
+    return _impl.contains (k);
+  }
+
+  void print (void)
+  {
+    if (!dump_file) return;
+    for (auto i = _impl.begin (), e = _impl.end (); i != e; ++i)
+    {
+      (*i).print ();
+    }
+  }
+};
+
+class symtab_wrapper_traits 
+{
+public:
+  typedef symtab_wrapper value_type;
+  typedef symtab_wrapper compare_type;
+  static const bool empty_zero_p = true;
+
+  static inline hashval_t hash (const value_type &v)
+  {
+    return pointer_hash <void>::hash (v._symtab_node);
+  }
+
+  static bool equal (const value_type &l, const value_type &r)
+  {
+    return l._symtab_node == r._symtab_node;
+  }
+
+  static void mark_deleted (value_type &v)
+  {
+    v._symtab_node = NULL;
+  }
+
+  static void mark_empty (value_type &v)
+  {
+    v._symtab_node = NULL;
+  }
+
+  static void remove (value_type &v)
+  {
+    v._symtab_node = NULL;
+  }
+
+  static bool is_deleted (const value_type &v)
+  {
+     return !v._symtab_node;
+  }
+
+  static bool is_empty (const value_type &v)
+  {
+     return !v._symtab_node;
+  }
+
+};
+
+my_set_t <symtab_wrapper, false, symtab_wrapper_traits> my_set;
+
 static void
 ipa_hash_generate_summary (void)
 {
+  cgraph_node *cnode = NULL;
+  FOR_EACH_FUNCTION (cnode)
+  {
+    symtab_wrapper w (cnode);
+    my_set.insert (w);
+  }
+
+  my_set.print ();
+
   return;
 }
 
 static unsigned
 ipa_pta_execute (void)
 {
-  if (dump_file) fprintf (dump_file, "hello from wpa\n");
   return 0;
 }
 
-- 
2.25.1

