[patch i386]: Implementation for call abi switching via attribute.

Kai Tietz ktietz70@googlemail.com
Sat May 24 10:46:00 GMT 2008


Hi Honza,

2008/5/23 Jan Hubicka <jh@suse.cz>:
>> +  if (TARGET_64BIT)
>> +    {
>> +      if (cum->call_abi != DEFAULT_ABI)
>> +        cum->nregs = DEFAULT_ABI != SYSV_ABI ? 6 : 4;
>> +    }
>>    if (TARGET_SSE)
>> -    cum->sse_nregs = SSE_REGPARM_MAX;
>> +    {
>> +      cum->sse_nregs = SSE_REGPARM_MAX;
>> +      if (TARGET_64BIT)
>> +        {
>> +          if (cum->call_abi != DEFAULT_ABI)
>> +            cum->sse_nregs = DEFAULT_ABI != SYSV_ABI ? 8 : 4; /* $$$$ */
>> +        }
>> +    }
>
> Probably adding ABI argument to REGPARM_MAX/SSE_REGPARM_MAX would
> help... Magic constants around the code are quite ugly..
I agree, but what should we do with i386.md and co, where those macros
are used everywhere?

>> @@ -4325,7 +4401,7 @@ function_arg_advance (CUMULATIVE_ARGS *c
>>    if (type)
>>      mode = type_natural_mode (type);
>>
>> -  if (TARGET_64BIT_MS_ABI)
>> +  if (TARGET_64BIT && (cum ? cum->call_abi : DEFAULT_ABI) == MS_ABI)
>
> Testing cum for non-zero should not be needed here.
>> +/* regclass.c  */
>> +extern void init_regs (void);
>> +
>> +#define OVERRIDE_ABI_FORMAT(FNDECL) \
>
> Please move this offline.  Also the new hook and documentation needs
> approval from RTL maintainer, so breaking it to separate patch would
> help.
As I told, Mark meant, that this part should be better part of the
target implementation and he would take a look on it for approval. The
documentation is added to tm.texi for the new hook.

> init_regs is expensive function, we definitly don't want to call it for
> every function being compiled.  We should not need it in full power,
> perhaps breaking out init_call_used_regs () and doing this all only when
> ABI changes would help?
>> +do {                                                                 \
>> +    if (FNDECL == NULL)                                                      \
>> +      cfun->machine->call_abi = DEFAULT_ABI;                 \
>> +    else                                                             \
>> +      cfun->machine->call_abi = ix86_function_type_abi (TREE_TYPE (FNDECL)); \
>> +    if (cfun->machine->call_abi == MS_ABI && call_used_regs)                 \
>> +      {                                                                              \
>> +        if (call_used_regs[4 /*RSI*/] != 0 || call_used_regs[5 /*RDI*/] != 0) \
>> +          {                                                          \
>> +         call_used_regs[4 /*RSI*/] = 0;                              \
>> +         call_used_regs[5 /*RDI*/] = 0;                              \
>> +            init_regs ();                                            \
>> +       }                                                             \
>> +      }                                                                      \
>> +    else if (TARGET_64BIT && call_used_regs)                                 \
>> +      {                                                                      \
>> +        if (call_used_regs[4 /*RSI*/] != 1 || call_used_regs[5 /*RDI*/] != 1)        \
>> +          {                                                          \
>> +         call_used_regs[4 /*RSI*/] = 1;                              \
>> +         call_used_regs[5 /*RDI*/] = 1;                              \
>> +            init_regs ();                                            \
>> +       }                                                             \
>> +      }                                                                      \
>> +   } while (0)
>> +
>
> I also believe there is still problem with call used regs.
> If you call from MSABI to SYSV ABI, RSI/RDI are not call used in caller
> but they are call used in callee.  This will lead to miscompilation.
> We need to handle this by extra clobbers in call instruction.  I hope
> something like this:
>
> (define_insn "*call_1_rex64"
>  [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rsm"))
>         (match_operand 1 "" ""))]
>  "!SIBLING_CALL_P (insn) && TARGET_64BIT
>   && ix86_cmodel != CM_LARGE && ix86_cmodel != CM_LARGE_PIC"
>
> (define_insn "*call_1_msabi_sysvabi"
>  [(call (mem:QI (match_operand:DI 0 "call_insn_operand" "rsm"))
>         (match_operand 1 "" ""))
>   (unspec_volatile:HI [(const_int 0)] UNSPECV_MSABI)
>   (clobber:SI DI_REG)
>   (clobber:SI SI_REG)]
>
> should work after arranging call expanders to use the second variant for
> MSABI->SYSV.    The unspec or something like this will be needed to
> avoid combine and recog machinery from stripping away the clobbers.
Ok, I will try to alter the call expanders.

> I would be happy with first version of patch simply sorrying out on the
> MS->SYSV calls and we can handle it incrementally.
Ok, I will do this in attribute check, is that ok?

Cheers,
  Kai


-- 
| (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination



More information about the Gcc-patches mailing list