[llvm-dev] Finding Size of X86 instruction in MachineFunctionPass

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

[llvm-dev] Finding Size of X86 instruction in MachineFunctionPass

Robin Eklind via llvm-dev
Dear All,

Is there a way in newer versions of LLVM (4.0 and higher) to find the
size of an x86 instruction within a MachineFunctionPass?  If not, is
there something I can do in the MC layer to do this?

I'm trying to modify LLVM to implement something like Native Client in
which groups of instructions are aligned at a specific alignment and
have the same length.  My current approach is to split each
MachineBasicBlock so that it is less than or equal to the desired size
and then align each MachineBasicBlock at the proper alignment.  However,
I've been poking around doxygen and can't find anything that will give
me the size of an x86 instruction.

Thanks in advance,

John Criswell

--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
http://www.cs.rochester.edu/u/criswell

_______________________________________________
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] Finding Size of X86 instruction in MachineFunctionPass

Robin Eklind via llvm-dev
I don't think this API exists for machine function passes. It also wouldn't be too useful because the size of the instruction depends on details like which register is assigned  which could be changed by later machine passes. Of course during emission the MC layer should have an idea of how big instructions become, so your best bet is probably to modify the compiler at this point (I cannot give tips to that though as I'm not that familiar with these parts).

- Matthias

> On Jul 10, 2018, at 7:29 AM, John Criswell via llvm-dev <[hidden email]> wrote:
>
> Dear All,
>
> Is there a way in newer versions of LLVM (4.0 and higher) to find the size of an x86 instruction within a MachineFunctionPass?  If not, is there something I can do in the MC layer to do this?
>
> I'm trying to modify LLVM to implement something like Native Client in which groups of instructions are aligned at a specific alignment and have the same length.  My current approach is to split each MachineBasicBlock so that it is less than or equal to the desired size and then align each MachineBasicBlock at the proper alignment.  However, I've been poking around doxygen and can't find anything that will give me the size of an x86 instruction.
>
> Thanks in advance,
>
> John Criswell
>
> --
> John Criswell
> Assistant Professor
> Department of Computer Science, University of Rochester
> http://www.cs.rochester.edu/u/criswell
>
> _______________________________________________
> 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] Finding Size of X86 instruction in MachineFunctionPass

Robin Eklind via llvm-dev
Well the API actually does exist as TargetInstrInfo::getInstSizeInBytes() but is optional and not implemented for X86.

> On Jul 10, 2018, at 10:20 AM, Matthias Braun <[hidden email]> wrote:
>
> I don't think this API exists for machine function passes. It also wouldn't be too useful because the size of the instruction depends on details like which register is assigned  which could be changed by later machine passes. Of course during emission the MC layer should have an idea of how big instructions become, so your best bet is probably to modify the compiler at this point (I cannot give tips to that though as I'm not that familiar with these parts).
>
> - Matthias
>
>> On Jul 10, 2018, at 7:29 AM, John Criswell via llvm-dev <[hidden email]> wrote:
>>
>> Dear All,
>>
>> Is there a way in newer versions of LLVM (4.0 and higher) to find the size of an x86 instruction within a MachineFunctionPass?  If not, is there something I can do in the MC layer to do this?
>>
>> I'm trying to modify LLVM to implement something like Native Client in which groups of instructions are aligned at a specific alignment and have the same length.  My current approach is to split each MachineBasicBlock so that it is less than or equal to the desired size and then align each MachineBasicBlock at the proper alignment.  However, I've been poking around doxygen and can't find anything that will give me the size of an x86 instruction.
>>
>> Thanks in advance,
>>
>> John Criswell
>>
>> --
>> John Criswell
>> Assistant Professor
>> Department of Computer Science, University of Rochester
>> http://www.cs.rochester.edu/u/criswell
>>
>> _______________________________________________
>> 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] Finding Size of X86 instruction in MachineFunctionPass

Robin Eklind via llvm-dev
In reply to this post by Robin Eklind via llvm-dev
The actual size of even a MC instruction will change during relaxation--we don't choose between 8-bit jumps and wider jumps until relaxation. You can get the actual encoding of an MCInst via MCCodeEmitter, but if you expect relaxation to occur, or particularly if you're testing before register allocation, the size could only be an estimate and shouldn't be trusted for exact size.

-----Original Message-----
From: llvm-dev [mailto:[hidden email]] On Behalf Of Matthias Braun via llvm-dev
Sent: Tuesday, July 10, 2018 13:21
To: John Criswell <[hidden email]>
Cc: [hidden email]
Subject: Re: [llvm-dev] Finding Size of X86 instruction in MachineFunctionPass

I don't think this API exists for machine function passes. It also wouldn't be too useful because the size of the instruction depends on details like which register is assigned  which could be changed by later machine passes. Of course during emission the MC layer should have an idea of how big instructions become, so your best bet is probably to modify the compiler at this point (I cannot give tips to that though as I'm not that familiar with these parts).

- Matthias

> On Jul 10, 2018, at 7:29 AM, John Criswell via llvm-dev <[hidden email]> wrote:
>
> Dear All,
>
> Is there a way in newer versions of LLVM (4.0 and higher) to find the size of an x86 instruction within a MachineFunctionPass?  If not, is there something I can do in the MC layer to do this?
>
> I'm trying to modify LLVM to implement something like Native Client in which groups of instructions are aligned at a specific alignment and have the same length.  My current approach is to split each MachineBasicBlock so that it is less than or equal to the desired size and then align each MachineBasicBlock at the proper alignment.  However, I've been poking around doxygen and can't find anything that will give me the size of an x86 instruction.
>
> Thanks in advance,
>
> John Criswell
>
> --
> John Criswell
> Assistant Professor
> Department of Computer Science, University of Rochester
> http://www.cs.rochester.edu/u/criswell
>
> _______________________________________________
> 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] Finding Size of X86 instruction in MachineFunctionPass

Robin Eklind via llvm-dev
On 7/10/18 1:48 PM, Cranmer, Joshua via llvm-dev wrote:
> The actual size of even a MC instruction will change during relaxation--we don't choose between 8-bit jumps and wider jumps until relaxation. You can get the actual encoding of an MCInst via MCCodeEmitter, but if you expect relaxation to occur, or particularly if you're testing before register allocation, the size could only be an estimate and shouldn't be trusted for exact size.

Thanks.  I should be doing this as the last pass before emission to the
object file, so it is post register allocation.

Will relaxation cause an instruction to become larger or only smaller? 
If the instruction ends up being smaller, that is fine. If it can get
larger, that could be a problem.

I'll take a look at MCCodeEmitter.

Thanks,

John Criswell

>
> -----Original Message-----
> From: llvm-dev [mailto:[hidden email]] On Behalf Of Matthias Braun via llvm-dev
> Sent: Tuesday, July 10, 2018 13:21
> To: John Criswell <[hidden email]>
> Cc: [hidden email]
> Subject: Re: [llvm-dev] Finding Size of X86 instruction in MachineFunctionPass
>
> I don't think this API exists for machine function passes. It also wouldn't be too useful because the size of the instruction depends on details like which register is assigned  which could be changed by later machine passes. Of course during emission the MC layer should have an idea of how big instructions become, so your best bet is probably to modify the compiler at this point (I cannot give tips to that though as I'm not that familiar with these parts).
>
> - Matthias
>
>> On Jul 10, 2018, at 7:29 AM, John Criswell via llvm-dev <[hidden email]> wrote:
>>
>> Dear All,
>>
>> Is there a way in newer versions of LLVM (4.0 and higher) to find the size of an x86 instruction within a MachineFunctionPass?  If not, is there something I can do in the MC layer to do this?
>>
>> I'm trying to modify LLVM to implement something like Native Client in which groups of instructions are aligned at a specific alignment and have the same length.  My current approach is to split each MachineBasicBlock so that it is less than or equal to the desired size and then align each MachineBasicBlock at the proper alignment.  However, I've been poking around doxygen and can't find anything that will give me the size of an x86 instruction.
>>
>> Thanks in advance,
>>
>> John Criswell
>>
>> --
>> John Criswell
>> Assistant Professor
>> Department of Computer Science, University of Rochester
>> http://www.cs.rochester.edu/u/criswell
>>
>> _______________________________________________
>> 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


--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
http://www.cs.rochester.edu/u/criswell

_______________________________________________
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] Finding Size of X86 instruction in MachineFunctionPass

Robin Eklind via llvm-dev
Relaxation causes instructions to get larger. We optimistically assume that we can encode a relative jump using a 1 byte immediate until we prove that we can't. We will then switch to a 4 byte immediate.

~Craig


On Tue, Jul 10, 2018 at 2:06 PM John Criswell via llvm-dev <[hidden email]> wrote:
On 7/10/18 1:48 PM, Cranmer, Joshua via llvm-dev wrote:
> The actual size of even a MC instruction will change during relaxation--we don't choose between 8-bit jumps and wider jumps until relaxation. You can get the actual encoding of an MCInst via MCCodeEmitter, but if you expect relaxation to occur, or particularly if you're testing before register allocation, the size could only be an estimate and shouldn't be trusted for exact size.

Thanks.  I should be doing this as the last pass before emission to the
object file, so it is post register allocation.

Will relaxation cause an instruction to become larger or only smaller? 
If the instruction ends up being smaller, that is fine. If it can get
larger, that could be a problem.

I'll take a look at MCCodeEmitter.

Thanks,

John Criswell

>
> -----Original Message-----
> From: llvm-dev [mailto:[hidden email]] On Behalf Of Matthias Braun via llvm-dev
> Sent: Tuesday, July 10, 2018 13:21
> To: John Criswell <[hidden email]>
> Cc: [hidden email]
> Subject: Re: [llvm-dev] Finding Size of X86 instruction in MachineFunctionPass
>
> I don't think this API exists for machine function passes. It also wouldn't be too useful because the size of the instruction depends on details like which register is assigned  which could be changed by later machine passes. Of course during emission the MC layer should have an idea of how big instructions become, so your best bet is probably to modify the compiler at this point (I cannot give tips to that though as I'm not that familiar with these parts).
>
> - Matthias
>
>> On Jul 10, 2018, at 7:29 AM, John Criswell via llvm-dev <[hidden email]> wrote:
>>
>> Dear All,
>>
>> Is there a way in newer versions of LLVM (4.0 and higher) to find the size of an x86 instruction within a MachineFunctionPass?  If not, is there something I can do in the MC layer to do this?
>>
>> I'm trying to modify LLVM to implement something like Native Client in which groups of instructions are aligned at a specific alignment and have the same length.  My current approach is to split each MachineBasicBlock so that it is less than or equal to the desired size and then align each MachineBasicBlock at the proper alignment.  However, I've been poking around doxygen and can't find anything that will give me the size of an x86 instruction.
>>
>> Thanks in advance,
>>
>> John Criswell
>>
>> --
>> John Criswell
>> Assistant Professor
>> Department of Computer Science, University of Rochester
>> http://www.cs.rochester.edu/u/criswell
>>
>> _______________________________________________
>> 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


--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
http://www.cs.rochester.edu/u/criswell

_______________________________________________
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