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]

Re: [tree-ssa] Switch stmts and inserting on edges


On Fri, 2003-05-30 at 14:08, Frank Ch. Eigler wrote:
> 
> amacleod wrote:
> 
> > [...]
> > I have an edge from the switch stmt to the default case that I need to
> > insert a copy on.
> > [...]
> > case blah:
> >   <...>
> >   goto new_label;
> > 
> > default:
> >   <inserted_stmt>
> > new_label:
> >   default code.
> > [...]
> 
> That's not bad - it's only needed if the previous case falls through.
> 
> 
Its my worst case scenario.

> > Any other suggestions? I havent thought of anything I actually like....
> 
> How about forking the switch() into two, with the first one containing
> the inserted statement?
> 
> switch (expr)
> {
>   case <1...N>: break;
>   default: <inserted_stmt>
> }
> switch (expr)
> {
>   <unmodified>  
> }
> 

I think thats a bit heavyweight :-). Before doing that Id go in and muck
around with the existing case and change where the default target goes.
ie

switch (expr)
  <..>
  case 48:
     /*fallthru */
  default:
    code

into

switch (expr)
  <..>
  case 48:
     /*fallthru */
  new_label:
    code
    break;
  default
    copy
    goto new_label;

of somesuch thing.  I was just hoping I wouldnt have to have to teach
the insert routine lots of gunk about switch stmts.

  
> ... or using a temporary variable as a flag?
> 
> switch (expr)
> {
>   int default_fallthrough = 0;
> 
>   case <1..M>: break;
>   case <N>: stmt; stmt;  /* fallthrough */
>        default_fallthrough = 1;
>   default:
>      if (! default_fallthrough) { <inserted_stmt> }
>      <old default code>
> } 
> 

Again, I think I'd go to the actual effort of rearranging flow before
doing this. This is every bit as much work, and if Im going to go to the
effort, I might as well do it right.

Andrew


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