This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC][PATCH] Introduce -fdump*-folding


On 05/03/2017 12:12 PM, Richard Biener wrote:
On Wed, May 3, 2017 at 10:10 AM, Martin Liška <mliska@suse.cz> wrote:
Hello

Last release cycle I spent quite some time with reading of IVOPTS pass
dump file. Using -fdump*-details causes to generate a lot of 'Applying pattern'
lines, which can make reading of a dump file more complicated.

There are stats for tramp3d with -O2 and -fdump-tree-all-details. Percentage number
shows how many lines are of the aforementioned pattern:

                        tramp3d-v4.cpp.164t.ivopts: 6.34%
                          tramp3d-v4.cpp.091t.ccp2: 5.04%
                      tramp3d-v4.cpp.093t.cunrolli: 4.41%
                      tramp3d-v4.cpp.129t.laddress: 3.70%
                          tramp3d-v4.cpp.032t.ccp1: 2.31%
                          tramp3d-v4.cpp.038t.evrp: 1.90%
                     tramp3d-v4.cpp.033t.forwprop1: 1.74%
                          tramp3d-v4.cpp.103t.vrp1: 1.52%
                     tramp3d-v4.cpp.124t.forwprop3: 1.31%
                          tramp3d-v4.cpp.181t.vrp2: 1.30%
                       tramp3d-v4.cpp.161t.cunroll: 1.22%
                    tramp3d-v4.cpp.027t.fixup_cfg3: 1.11%
                       tramp3d-v4.cpp.153t.ivcanon: 1.07%
                          tramp3d-v4.cpp.126t.ccp3: 0.96%
                          tramp3d-v4.cpp.143t.sccp: 0.91%
                     tramp3d-v4.cpp.185t.forwprop4: 0.82%
                           tramp3d-v4.cpp.011t.cfg: 0.74%
                     tramp3d-v4.cpp.096t.forwprop2: 0.50%
                    tramp3d-v4.cpp.019t.fixup_cfg1: 0.37%
                     tramp3d-v4.cpp.120t.phicprop1: 0.33%
                           tramp3d-v4.cpp.133t.pre: 0.32%
                     tramp3d-v4.cpp.182t.phicprop2: 0.27%
                    tramp3d-v4.cpp.170t.veclower21: 0.25%
                       tramp3d-v4.cpp.029t.einline: 0.24%

I'm suggesting to add new TDF that will be allocated for that.
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Thoughts?

Ok.  Soon we'll want to change dump_flags to uint64_t ...  (we have 1 bit left
if you allow negative dump_flags).  It'll tickle down on a lot of interfaces
so introducing dump_flags_t at the same time might be a good idea.

Hello.

I've prepared patch that migrates all interfaces and introduces dump_flags_t. I've been
currently testing that. Apart from that Richi requested to come up with more generic approach
of hierarchical structure of options.

Can you please take a look at self-contained source file that shows way I've decided to go?
Another question is whether we want to implement also "aliases", where for instance
current 'all' is equal to union of couple of suboptions?

Thanks for feedback,
Martin


Thanks,
Richard.

Martin

#include <cstdint>
#include <vector>
#include "stdio.h"
#include "string.h"

using namespace std;

enum dump_option_enum
{
  FOLDING,
  FOLDING_GIMPLE,
  FOLDING_GIMPLE_CTOR,
  FOLDING_GIMPLE_MATCH,
  FOLDING_GENERIC,
  FOLDING_GENERIC_C,
  FOLDING_GENERIC_CPP,
  DUMP_OPTION_COUNT
};

struct dump_option_node
{
  inline dump_option_node (const char *_name, dump_option_enum _enum_value);
  inline void initialize (uint64_t *mask_translation);
  inline uint64_t initialize_masks (unsigned *current, uint64_t *mask_translation);
  inline uint64_t parse(char *token);

  const char *name;
  dump_option_enum enum_value;
  vector<dump_option_node *> children;
  uint64_t mask;
};

dump_option_node::dump_option_node (const char *_name,
				    dump_option_enum _enum_value):
  name (_name), enum_value (_enum_value), mask (0)
{}

void
dump_option_node::initialize (uint64_t *mask_translation)
{
  unsigned current = 0;
  initialize_masks (&current, mask_translation);
}

uint64_t
dump_option_node::initialize_masks (unsigned *current, uint64_t *mask_translation)
{
  if (children.empty ())
    mask = (1 << ((*current)++));
  // TODO: add assert
  else
    {
      uint64_t combined = 0;
      for (unsigned i = 0; i < children.size (); i++)
	combined |= children[i]->initialize_masks (current, mask_translation);

      mask = combined;
    }

  mask_translation[enum_value] = mask;
  return mask;
}

uint64_t
dump_option_node::parse(char *token)
{
  if (token == NULL)
    return mask;

  for (unsigned i = 0; i < children.size (); i++)
    if (strcmp (children[i]->name, token) == 0)
    {
      token = strtok (NULL, "-");
      return children[i]->parse (token); 
    }

  return 0;
}

struct dump_flags_t
{
  dump_flags_t ();
  dump_flags_t (uint64_t mask);
  dump_flags_t (dump_option_enum enum_value);

  inline void operator|= (dump_flags_t other)
  {
    m_mask |= other.m_mask;
  }

  inline void operator&= (dump_flags_t other)
  {
    m_mask &= other.m_mask;
  }

  inline bool operator& (dump_flags_t other)
  {
    return m_mask & other.m_mask;
  }

  static inline void init ();
  static dump_flags_t parse (char *option);

  uint64_t m_mask;

  static dump_option_node *root;
  static uint64_t mask_translation[DUMP_OPTION_COUNT];
};

dump_flags_t::dump_flags_t (): m_mask (0)
{}

dump_flags_t::dump_flags_t (uint64_t mask): m_mask (mask)
{}

dump_flags_t::dump_flags_t (dump_option_enum enum_value)
{
  // TODO: add checking assert
  m_mask = mask_translation[enum_value];
}

dump_option_node *dump_flags_t::root = nullptr;
uint64_t dump_flags_t::mask_translation[DUMP_OPTION_COUNT];

void
dump_flags_t::init ()
{
  dump_option_node *n;

  n = new dump_option_node ("gimple", FOLDING_GIMPLE);
  n->children.push_back (new dump_option_node ("ctor", FOLDING_GIMPLE_CTOR));
  n->children.push_back (new dump_option_node ("match", FOLDING_GIMPLE_MATCH));

  root = new dump_option_node ("folding", FOLDING);
  root->children.push_back (n);

  n = new dump_option_node ("generic", FOLDING_GENERIC);
  n->children.push_back (new dump_option_node ("c", FOLDING_GENERIC_C));
  n->children.push_back (new dump_option_node ("cpp", FOLDING_GENERIC_CPP));

  root->children.push_back (n);

  root->initialize (mask_translation);
}

dump_flags_t
dump_flags_t::parse (char *option)
{
  char *token = strtok (option, "-");
  if (token == NULL)
    return dump_flags_t ();
  return dump_flags_t (root->parse (token));
}


int main()
{
  dump_flags_t::init ();

  dump_flags_t flags;
  flags |= FOLDING_GIMPLE;
  flags &= FOLDING_GENERIC;

  if (flags & FOLDING_GENERIC)
    __builtin_abort ();

  dump_flags_t flags2 = dump_flags_t::parse (strdup("gimple-match2"));
  if (!flags2.m_mask)
    fprintf (stderr, "invalid option!!\n");

  flags2 = dump_flags_t::parse (strdup("gimple-match"));
  fprintf (stderr, "flags2 mask: 0x%.8x\n", flags2);
//  for (unsigned i = 0; i < dump_flags_t::root->children.size (); i++)
//    fprintf (stderr, "%s: mask: 0x%.8x\n", root->children[i]->name, root->children[i]->mask);
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]