This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: how to get instruction codes in gcc passes?

On Sun, Jun 13, 2010 at 6:38 PM, Richard Guenther
<> wrote:
> On Sun, Jun 13, 2010 at 4:29 PM, Ilya K <> 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.

OK. No low-level instruction codes in gcc.
I found the definitions of instructions in (thanks for this advice):

(define_insn "nop"
  [(const_int 0)]
  [(set_attr "length" "1")
   (set_attr "length_immediate" "0")
   (set_attr "modrm" "0")])

So, the gcc only knows that some specific internal representation
should be generated as "nop" string, right?

And who is generating the binary file from the asm file? Does gcc call
the external program? What the name of this program? Or the sources I
need can be found inside the gcc directory?

I think that if there are no such instruction-code table inside gcc, I
can build my own version of it inside my pass. But I need the sources
of some utility which knows how to convert "nop" string into the
binary number. Where can I get it?

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]