Re: How to get attribute of callee

2010-10-04 Thread Georg Lay
Phung Nguyen schrieb:
 Dear Georg,
 
 Thank you for your help.
 
 I have a problem after I follow your way. When I compile newlib with
 the modified (in the way you did in blackfin) way, I got the error
 message:
 In function fopencookie:newlib/libc/stdio/fopencookie.c: 261: error,
 insn does not satisfy its constraints:
 (set (reg:HI 5 r5) (reg:HI 19 virtual-outgoing-args) 5 {*movhi_large}
 (nil) (nil))
 
 internal compiler error: in reload_cse_simplify_operands, at postreload.c:391

Please open new questions in the gcc resp. gcc-help mailing lists for new 
issues.

Please write to the gcc's lists. Other guy might learn from the lists, there is
no reason for private communication.

 Did you get the similar problem? Or do you have any idea???

The problem arises from your movhi-insn implementation. Obviously, you try to
split several cases of move by means of predicates/conditions. Don't do that.
You will have to handle every alternative in the constraints, anyway, so this
leads mainly to duplications of insns (and much of trouble until you got there,
especially by register allocator freaking in corner cases).

Supply ONE move insn per mode an fix architecture's oddities and
non-orthogonalities in its constraints.

 Best regards,
 Phung

Georg


Re: How to get attribute of callee

2010-09-03 Thread Georg Lay
Phung Nguyen schrieb:
 Thank you for your reply,
 
 As I know, operand 0 of call is the address of called function;
 operand 1 is the number of arguments; operand 2 is the number of args
 as registers. Therefore, where is the info passed to call ??? As I
 would like to change the target instruction of call based on the
 attribute of the called function, I need the info passed to call
 pattern name.
 
 Could you please explain more about your idea.

Just have a look at the blachfin backend in bfin.c and search for 'cookie'.
I use a similar machanism and it works (as far as I can tell) in all situations,
even if the source messes around with pointers like casting a void pointer to an
attributed function pointer.

Greets

 Phung



Re: How to get attribute of callee

2010-09-02 Thread Georg Lay
Phung Nguyen schrieb:
 Dear all,
 
 I am porting GCC to a new target. I don't know how to get attribute of
 callee of a call.
 
 I defined a new attribute to assign to a function but when writing for
 pattern name call or call_value, I don't know how to know if the
 callee is assigned the attribute.  As the code for the call depends on
 the attribute of the callee, I need to get the corresponding function
 decl tree. As the operand of call or call_value might be
 SYMBOL_REF (direct call) or REG (indirect call), I don't know how to
 get the function declaration (fndecl).
 
 Could you please advise me a solution for it? I highly appreciate your help.

Try this:

-- Store that info in the CUMULATIVE_ARGS object
-- Pass the info in a call cookie as last argument of
   the function like this: FUNCTION_ARG resp. FUNCTION_ARG_ADVANCE
   get called with mode=VOIDmode. Return a CONST_INT and evaluate
   the respective operand of call insn resp. call_calue insn.







Re: How to get attribute of callee

2010-09-02 Thread Jakub Jelinek
On Thu, Sep 02, 2010 at 07:18:29PM +0700, Phung Nguyen wrote:
 I am porting GCC to a new target. I don't know how to get attribute of
 callee of a call.
 
 I defined a new attribute to assign to a function but when writing for
 pattern name call or call_value, I don't know how to know if the
 callee is assigned the attribute.  As the code for the call depends on
 the attribute of the callee, I need to get the corresponding function
 decl tree. As the operand of call or call_value might be
 SYMBOL_REF (direct call) or REG (indirect call), I don't know how to
 get the function declaration (fndecl).

From SYMBOL_REF you just look at SYMBOL_REF_DECL, which will most often be a
FUNCTION_DECL of the called function.
For indirect call, most often (unless the optimizers have done a bad job)
you don't know what function will be called.  So, if your attribute is
supposed to change behavior of a call, including indirect calls, you'd
better make it a type attribute and arrange during expand to use a different
call pattern if the called function's type has that attribute.  At final
time for indirect calls the called fn FUNCTION_TYPE is no longer available.

Jakub


Re: How to get attribute of callee

2010-09-02 Thread Phung Nguyen
Hi Jakub,

Thank you for your help.

For direct call, I solved the problem based on your suggestion.
For indirect call, I don't understand much your idea. Could you please
clarify it?

Phung

On Thu, Sep 2, 2010 at 7:59 PM, Jakub Jelinek ja...@redhat.com wrote:
 On Thu, Sep 02, 2010 at 07:18:29PM +0700, Phung Nguyen wrote:
 I am porting GCC to a new target. I don't know how to get attribute of
 callee of a call.

 I defined a new attribute to assign to a function but when writing for
 pattern name call or call_value, I don't know how to know if the
 callee is assigned the attribute.  As the code for the call depends on
 the attribute of the callee, I need to get the corresponding function
 decl tree. As the operand of call or call_value might be
 SYMBOL_REF (direct call) or REG (indirect call), I don't know how to
 get the function declaration (fndecl).

 From SYMBOL_REF you just look at SYMBOL_REF_DECL, which will most often be a
 FUNCTION_DECL of the called function.
 For indirect call, most often (unless the optimizers have done a bad job)
 you don't know what function will be called.  So, if your attribute is
 supposed to change behavior of a call, including indirect calls, you'd
 better make it a type attribute and arrange during expand to use a different
 call pattern if the called function's type has that attribute.  At final
 time for indirect calls the called fn FUNCTION_TYPE is no longer available.

        Jakub



Re: How to get attribute of callee

2010-09-02 Thread Phung Nguyen
Thank you for your reply,

As I know, operand 0 of call is the address of called function;
operand 1 is the number of arguments; operand 2 is the number of args
as registers. Therefore, where is the info passed to call ??? As I
would like to change the target instruction of call based on the
attribute of the called function, I need the info passed to call
pattern name.

Could you please explain more about your idea.

Phung

On Thu, Sep 2, 2010 at 7:49 PM, Georg Lay a...@gjlay.de wrote:
 Phung Nguyen schrieb:
 Dear all,

 I am porting GCC to a new target. I don't know how to get attribute of
 callee of a call.

 I defined a new attribute to assign to a function but when writing for
 pattern name call or call_value, I don't know how to know if the
 callee is assigned the attribute.  As the code for the call depends on
 the attribute of the callee, I need to get the corresponding function
 decl tree. As the operand of call or call_value might be
 SYMBOL_REF (direct call) or REG (indirect call), I don't know how to
 get the function declaration (fndecl).

 Could you please advise me a solution for it? I highly appreciate your help.

 Try this:

 -- Store that info in the CUMULATIVE_ARGS object
 -- Pass the info in a call cookie as last argument of
   the function like this: FUNCTION_ARG resp. FUNCTION_ARG_ADVANCE
   get called with mode=VOIDmode. Return a CONST_INT and evaluate
   the respective operand of call insn resp. call_calue insn.