[llvm-dev] New to LLVM. Need help generating assembly

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[llvm-dev] New to LLVM. Need help generating assembly

Alberto Barbaro via llvm-dev
Hi,
I'm new to LLVM and need some help. I defined an instruction to increment the stack pointer by 'amount' (i.e. sp = sp + amount). During assembly generation, the string that gets emitted is "ADS $SP"  rather than "ADS 10", for example, if I want to increment it by 10.

Can somebody show me what I'm doing wrong?
Thanks.

def ADS: F_J<0b100001,(outs),(ins i32imm:$amount),"ADS $amount",[(set SP, (add SP, i32imm:$amount))] > {

        bits<10> amount;

        let Inst{9-0} = amount;
        let isReMaterializable = 1;
        let mayLoad = 0;
        let mayStore = 0;
        let Defs = [SP];
        let Uses = [SP];
}

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] New to LLVM. Need help generating assembly

Alberto Barbaro via llvm-dev
On 12/05/2018 07:22 PM, m m via llvm-dev wrote:

> Hi,
> I'm new to LLVM and need some help. I defined an instruction to increment the stack pointer by 'amount' (i.e. sp = sp + amount). During assembly generation, the string that gets emitted is "ADS $SP"  rather than "ADS 10", for example, if I want to increment it by 10.
>
> Can somebody show me what I'm doing wrong?
> Thanks.
>
> def ADS: F_J<0b100001,(outs),(ins i32imm:$amount),"ADS $amount",[(set SP, (add SP, i32imm:$amount))] > {
>
>         bits<10> amount;
>
>         let Inst{9-0} = amount;
>         let isReMaterializable = 1;
>         let mayLoad = 0;
>         let mayStore = 0;
>         let Defs = [SP];
>         let Uses = [SP];
> }

What does the MCInst dump of this instruction look like?  Have you looked
at YourTargetGenAsmWriter.inc to see which print methods are being called
for this instruction?

-Tom
>
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] New to LLVM. Need help generating assembly

Alberto Barbaro via llvm-dev


On Dec 5, 2018, at 22:15, Tom Stellard via llvm-dev <[hidden email]> wrote:

On 12/05/2018 07:22 PM, m m via llvm-dev wrote:
Hi,
I'm new to LLVM and need some help. I defined an instruction to increment the stack pointer by 'amount' (i.e. sp = sp + amount). During assembly generation, the string that gets emitted is "ADS $SP"  rather than "ADS 10", for example, if I want to increment it by 10.

Can somebody show me what I'm doing wrong?
Thanks.

def ADS: F_J<0b100001,(outs),(ins i32imm:$amount),"ADS $amount",[(set SP, (add SP, i32imm:$amount))] > {

       bits<10> amount;

       let Inst{9-0} = amount;
       let isReMaterializable = 1;
       let mayLoad = 0;
       let mayStore = 0;
       let Defs = [SP];
       let Uses = [SP];
}

What does the MCInst dump of this instruction look like?  Have you looked
at YourTargetGenAsmWriter.inc to see which print methods are being called
for this instruction?

-Tom

It's also worth checking the output of the compiler with the -print-after-all option to see if your instruction is present in the last IR dump. It's possible that another instruction is being selected instead of this one.

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] New to LLVM. Need help generating assembly

Alberto Barbaro via llvm-dev
Swapping the order of SP and $amount in the pattern did not work.
I checked the output of the compiler with the -print-after-all option and the instruction is present in the last IR dump.

I noticed that in GenAsmWriter.inc, there is this line of code in the case of my ADS instruction
printOperand(MI, 0, O);

If I manually change it to printOperand(MI, 1, O);, then it fixes the problem.

How can I make tablegen generate a 1 as the 2nd argument of printOperand for this specific instruction?

From: [hidden email] <[hidden email]> on behalf of Daniel Sanders <[hidden email]>
Sent: Thursday, December 6, 2018 9:31 AM
To: [hidden email]
Cc: m m; [hidden email]
Subject: Re: [llvm-dev] New to LLVM. Need help generating assembly
 


On Dec 5, 2018, at 22:15, Tom Stellard via llvm-dev <[hidden email]> wrote:

On 12/05/2018 07:22 PM, m m via llvm-dev wrote:
Hi,
I'm new to LLVM and need some help. I defined an instruction to increment the stack pointer by 'amount' (i.e. sp = sp + amount). During assembly generation, the string that gets emitted is "ADS $SP"  rather than "ADS 10", for example, if I want to increment it by 10.

Can somebody show me what I'm doing wrong?
Thanks.

def ADS: F_J<0b100001,(outs),(ins i32imm:$amount),"ADS $amount",[(set SP, (add SP, i32imm:$amount))] > {

       bits<10> amount;

       let Inst{9-0} = amount;
       let isReMaterializable = 1;
       let mayLoad = 0;
       let mayStore = 0;
       let Defs = [SP];
       let Uses = [SP];
}

What does the MCInst dump of this instruction look like?  Have you looked
at YourTargetGenAsmWriter.inc to see which print methods are being called
for this instruction?

-Tom

It's also worth checking the output of the compiler with the -print-after-all option to see if your instruction is present in the last IR dump. It's possible that another instruction is being selected instead of this one.

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] New to LLVM. Need help generating assembly

Alberto Barbaro via llvm-dev
On 12/06/2018 10:48 AM, m m wrote:
> Swapping the order of SP and $amount in the pattern did not work.
> I checked the output of the compiler with the -print-after-all option and the instruction is present in the last IR dump.
>
> I noticed that in GenAsmWriter.inc, there is this line of code in the case of my ADS instruction
> printOperand(MI, 0, O);
>
> If I manually change it to printOperand(MI, 1, O);, then it fixes the problem.
>
> How can I make tablegen generate a 1 as the 2nd argument of printOperand for this specific instruction?

SP is supposed to be an implicit argument, so printOperand(MI, 0, 0) is correct.
Can you find out where SP is added as an explicit operand?  Does this happen
after ISEL or some time later?

-Tom

> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> *From:* [hidden email] <[hidden email]> on behalf of Daniel Sanders <[hidden email]>
> *Sent:* Thursday, December 6, 2018 9:31 AM
> *To:* [hidden email]
> *Cc:* m m; [hidden email]
> *Subject:* Re: [llvm-dev] New to LLVM. Need help generating assembly
>  
>
>
>> On Dec 5, 2018, at 22:15, Tom Stellard via llvm-dev <[hidden email] <mailto:[hidden email]>> wrote:
>>
>> On 12/05/2018 07:22 PM, m m via llvm-dev wrote:
>>> Hi,
>>> I'm new to LLVM and need some help. I defined an instruction to increment the stack pointer by 'amount' (i.e. sp = sp + amount). During assembly generation, the string that gets emitted is "ADS $SP"  rather than "ADS 10", for example, if I want to increment it by 10.
>>>
>>> Can somebody show me what I'm doing wrong?
>>> Thanks.
>>>
>>> def ADS: F_J<0b100001,(outs),(ins i32imm:$amount),"ADS $amount",[(set SP, (add SP, i32imm:$amount))] > {
>>>
>>>        bits<10> amount;
>>>
>>>        let Inst{9-0} = amount;
>>>        let isReMaterializable = 1;
>>>        let mayLoad = 0;
>>>        let mayStore = 0;
>>>        let Defs = [SP];
>>>        let Uses = [SP];
>>> }
>>
>> What does the MCInst dump of this instruction look like?  Have you looked
>> at YourTargetGenAsmWriter.inc to see which print methods are being called
>> for this instruction?
>>
>> -Tom
>
> It's also worth checking the output of the compiler with the -print-after-all option to see if your instruction is present in the last IR dump. It's possible that another instruction is being selected instead of this one.
>
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> [hidden email] <mailto:[hidden email]>
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> [hidden email] <mailto:[hidden email]>
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] New to LLVM. Need help generating assembly

Alberto Barbaro via llvm-dev
In reply to this post by Alberto Barbaro via llvm-dev


On Dec 6, 2018, at 10:48, m m <[hidden email]> wrote:

Swapping the order of SP and $amount in the pattern did not work.

The tablegen internals will have generated patterns for both ways around because add is commutative and then removed the one with the immediate on the left to because it knows that DAGISel ensures the immediate is on the right.

I checked the output of the compiler with the -print-after-all option and the instruction is present in the last IR dump.

Ok, in that case it's being selected but isn't printing correctly. Could you copy output line for that instruction here? It's sounding like the operand list in your MCInst doesn't agree with the tablegen definition.

I noticed that in GenAsmWriter.inc, there is this line of code in the case of my ADS instruction
printOperand(MI, 0, O);

If I manually change it to printOperand(MI, 1, O);, then it fixes the problem.

How can I make tablegen generate a 1 as the 2nd argument of printOperand for this specific instruction?

From: [hidden email] <[hidden email]> on behalf of Daniel Sanders <[hidden email]>
Sent: Thursday, December 6, 2018 9:31 AM
To: [hidden email]
Cc: m m; [hidden email]
Subject: Re: [llvm-dev] New to LLVM. Need help generating assembly
 


On Dec 5, 2018, at 22:15, Tom Stellard via llvm-dev <[hidden email]> wrote:

On 12/05/2018 07:22 PM, m m via llvm-dev wrote:
Hi,
I'm new to LLVM and need some help. I defined an instruction to increment the stack pointer by 'amount' (i.e. sp = sp + amount). During assembly generation, the string that gets emitted is "ADS $SP"  rather than "ADS 10", for example, if I want to increment it by 10.

Can somebody show me what I'm doing wrong?
Thanks.

def ADS: F_J<0b100001,(outs),(ins i32imm:$amount),"ADS $amount",[(set SP, (add SP, i32imm:$amount))] > {

       bits<10> amount;

       let Inst{9-0} = amount;
       let isReMaterializable = 1;
       let mayLoad = 0;
       let mayStore = 0;
       let Defs = [SP];
       let Uses = [SP];
}

What does the MCInst dump of this instruction look like?  Have you looked
at YourTargetGenAsmWriter.inc to see which print methods are being called
for this instruction?

-Tom

It's also worth checking the output of the compiler with the -print-after-all option to see if your instruction is present in the last IR dump. It's possible that another instruction is being selected instead of this one.

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev