This is the mail archive of the gcc@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]

RFD - cleaning up C identifier lookup


I spent some time this weekend looking into how the C front end
handles identifier lookup.  I believe we can clean it up considerably,
saving memory and improving performance.  I'd like to outline a plan
for this, and get reactions, before I spend much time wrestling with
pushdecl and other monstrosities.

After the change I just checked in, C's lang_identifier looks like
this:

struct lang_identifier GTY(())
{
  struct c_common_identifier common_id;
  tree global_value;
  tree local_value;
  tree label_value;
  tree implicit_decl;
  tree limbo_value;
};

First, the implicit_decl and limbo_value fields are used only under
circumstances which do not occur in modern programs.  limbo_value is
only for issuing warnings on

int foo() 
{
    { extern int bar(void); }
    { extern double bar(void); }
}

Oddly, warnings do not occur if the two decls are in separate
functions.  implicit_decl is the same thing, but for implicit decls
caused by calling a function with no declaration in scope.  My
suspicion is that block scope external declarations, implicit or
explicit, are simply not used in modern C.  Thus, we can save two more
pointers per identifier by removing both fields and maintaining a
global list of such declarations instead; under normal circumstances
this list will be empty.

Second, the distinction between global_value and local_value is
artificial.  I propose to remove it and use the existing mechanism for
block-scope shadows to handle shadowing of globals.  That would free
up another slot, but instead of removing it altogether I plan to
recycle it for the type-tag namespace:

struct lang_identifier GTY(())
{
  struct c_common_identifier common_id;
  tree symbol_value;
  tree tag_value;
  tree label_value;
}

That allows elimination of the disgusting linear-or-worse search
algorithm used by lookup_tag, and I hope it will allow removal of
lookup_tag_reverse entirely.

Much of this stuff could also be applied to the C++ front end also,
but templates produce complications, so I'd prefer to get it all done
for C first.

zw


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