This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: how to get instruction codes in gcc passes?
- From: Richard Guenther <richard dot guenther at gmail dot com>
- To: Ilya K <ilya2do at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Sun, 13 Jun 2010 16:38:32 +0200
- Subject: Re: how to get instruction codes in gcc passes?
- References: <AANLkTinqcHgWdQ36NzT_6J1IwInpNZb4zqvyan1nvW23@mail.gmail.com>
On Sun, Jun 13, 2010 at 4:29 PM, Ilya K <ilya2do@gmail.com> wrote:
> Hi all.
> (I have never used these maillists before. Sorry if something wrong here.)
>
> I am newbie in gcc and I need some help.
>
> I am performing some research work in theme of code optimization.
> Now I have to write my own optimization pass for gcc. And in this pass
> I need to get the instruction codes of the resulting assemble code.
>
> I put my pass just before the "NEXT_PASS (pass_final);" in
> init_optimization_passes function. So I think that asm instructions
> are almost ready when my pass starts its work.
> This pass is already inserted into the gcc code and can be started.
> The gcc is compiled. And I can see my debug stuff in especially
> generated file when the gcc works.
> Actually I have no useful code yet, but I just want to get some
> information for starting the developing.
>
> For the beginning I want to do something like this:
> ? ?for (insn = get_insns() ; insn ; insn = NEXT_INSN(insn))
> ? ?{
> ? ? ? ?int code = ...; ? //I need help in this line!!!
> ? ? ? ?myDebugOutputShowCode(++i, code);
> ? ?}
>
> I.e. I just want to see the whole list of code of instructions. Like
> assembler listing.
>
> Can you help me and give some advices how to do it?
> I had a look at some *.md files in gcc sources, but did not found any
> source of codes of assembler instructions. How does the gcc generates
> the binary file? Where can it get the binary representation of asm
> instruction?
> Where is it described that "nop" is "0F 1F" value for x86 architecture
> and so on?
GCC does not have an integrated assembler and only outputs
assembler source. At the point above you still have RTXen
where you can query INSN_CODE to see what instruction from
the machine description was matched. In the define_insns
there are patterns for generating the assembler source instruction.
Richard.
> Thanks for any help.
>