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]

Re: Okay, who made scalar replacement of aggregates work?


reza@apple.com writes:

> I compiled your suggested program and I found no structure field is
> assigned to
> a registers.  What options did you use ? 
-O3.

> If it is not too hard for
> you, cold you send me
> the .s file that your compiler generates which assigns structure
> fields to registers.

Sure. I'll send it in a moment.

> 
> Thanks
> Reza Yazdani
> 
> 
> From: Daniel Berlin <dan@cgsoftware.com>
> Date: Thu Jun 07, 2001 09:25:30 AM US/Pacific
> To: gcc@gcc.gnu.org
> Subject: Okay, who made scalar replacement of aggregates work?
> 
> 
> I was told we only do it if the entire class fits in a register.
> 
> This is no longer true.
> 
> 
> We'll do it to single members of classes/structs now to.
> 
> In other words, we do full scalar replacement of aggregates.
> 
> 
> Try the following (for C):
> 
> 
> typedef enum { APPLE, BANANA, ORANGE } VARIETY;
> typedef enum { LONG, ROUND } SHAPE;
> typedef struct fruit {
> VARIETY variety;
> SHAPE shape;
> int fred;
> int george;
> int a;
> int b;
> int c;
> int d;
>}
> FRUIT;
> char * Red="red";
> char * Yellow = "yellow";
> char *Orange = "orange";
> 
> int george (CurrentFruit)
> 	FRUIT *CurrentFruit;
> {
> 	return CurrentFruit->george;
>}
> char *color (CurrentFruit)
> FRUIT *CurrentFruit;
> {
> 
> switch (CurrentFruit->variety) {
> case APPLE: return Red;
> break;
> case BANANA: return Yellow;
> break;
> case ORANGE: return Orange;
>}
>}
> main( )
> {
> FRUIT snack;
> snack.variety = APPLE;
> snack.shape = ROUND;
> snack.fred = 30;
> snack.george = 3;
> printf("%s\n", color (&snack));
> printf("%d\n", george (&snack));
>}
> 
> 
> Even though snack can't fit in a register, some of it's components
> will, and we sure as hell put them there.
> 
> Make snack as big as you like. We'll still do the repacements we can.
> 
> 
> Same with the C++ version.
> 
> 
> extern "C" int printf(const char *, ...);
> enum VARIETY
> { APPLE, BANANA, ORANGE };
> enum SHAPE { LONG, ROUND };
> class FRUIT
> {
> 	public:
> 		enum VARIETY variety;
> 		enum SHAPE shape;
> 		int george;
> 		int fred;
>                 int a;
>                 int b;
>                 int c;
>                 int d;
>};
> 
> char * Red="red";
> char * Yellow = "yellow";
> char *Orange = "orange";
> 
> char *color (FRUIT *CurrentFruit)
> {
> 
> 	switch (CurrentFruit->variety) {
> 		case APPLE: return Red;
> 			    break;
> 		case BANANA: return Yellow;
> 			     break;
> 		case ORANGE: return Orange;
>	}
>}
> int main( )
> {
> 	FRUIT snack;
> 	snack.variety = APPLE;
> 	snack.shape = ROUND;
> 	snack.george = 5;
> 	snack.fred = 30;
> 	printf("%s\n", color (&snack));
> 	printf("%d\n", snack.fred);
>}
> 
> 
> 
> --Dan
> --
> "It's a good thing we have gravity, or else when birds died
> they'd just stay right up there.  Hunters would be all confused.
> "-Steven Wright
> 
> 

-- 
"They say we're 98% water.  We're that close to drowning...
(Picks up his glass of water from the stool...)  I like to live
on the edge...
"-Steven Wright


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