[LLVMdev] how to annotate assembler

Benjamin Kramer benny.kra at googlemail.com
Fri Mar 2 04:32:55 PST 2012


On 02.03.2012, at 09:20, Konstantin Vladimirov wrote:

> Hi,
> 
> In GCC there is one useful option -dp (or -dP for more verbose output)
> to annotate assembler with instruction patterns, that was used when
> assembler was generated. For example:

The internal "-mllvm -show-mc-inst" option is probably as close as you can get.

$ clang -S -O0 test.c -mllvm -show-mc-inst -o -
_test:                                  ## @test
	.cfi_startproc
## BB#0:                                ## %entry
	pushq	%rbp                    ## <MCInst #2120 PUSH64r
                                        ##  <MCOperand Reg:106>>
Ltmp2:
	.cfi_def_cfa_offset 16
Ltmp3:
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp              ## <MCInst #1491 MOV64rr
                                        ##  <MCOperand Reg:106>
                                        ##  <MCOperand Reg:114>>
Ltmp4:
	.cfi_def_cfa_register %rbp
	movq	%rdi, -8(%rbp)          ## <MCInst #1482 MOV64mr
                                        ##  <MCOperand Reg:106>
                                        ##  <MCOperand Imm:1>
                                        ##  <MCOperand Reg:0>
                                        ##  <MCOperand Imm:-8>
                                        ##  <MCOperand Reg:0>
                                        ##  <MCOperand Reg:109>>
	cvtsi2sdq	-8(%rbp), %xmm0 ## <MCInst #607 CVTSI2SD64rm
                                        ##  <MCOperand Reg:128>
                                        ##  <MCOperand Reg:106>
                                        ##  <MCOperand Imm:1>
                                        ##  <MCOperand Reg:0>
                                        ##  <MCOperand Imm:-8>
                                        ##  <MCOperand Reg:0>>
	popq	%rbp                    ## <MCInst #2000 POP64r
                                        ##  <MCOperand Reg:106>>
	ret                             ## <MCInst #2227 RET>
	.cfi_endproc

- Ben

> 
> double
> test(long long s)
> {
>  return s;
> }
> 
> gcc -S -dp -O0 test.c
> 
> test:
> .LFB0:
>  .cfi_startproc
>  pushq %rbp  # 18  *pushdi2_rex64/1  [length = 1]
>  .cfi_def_cfa_offset 16
>  movq  %rsp, %rbp  # 19  *movdi_1_rex64/2  [length = 3]
>  .cfi_offset 6, -16
>  .cfi_def_cfa_register 6
>  movq  %rdi, -8(%rbp)  # 2 *movdi_1_rex64/4  [length = 4]
>  cvtsi2sdq -8(%rbp), %xmm0 # 6 *floatdidf2_sse_interunit/2 [length = 6]
>  leave # 24  leave_rex64 [length = 1]
>  .cfi_def_cfa 7, 8
>  ret # 25  return_internal [length = 1]
>  .cfi_endproc
> 
> Now I may look into config/i386/i386.md, and look for mentioned
> *pushdi2_rex64, movdi_1_rex64, floatdidf2_sse_interunit and other
> patterns and study how they work.
> 
> How to make the same annotation for clang output assembler code?
> 
> test:
> .Leh_func_begin1:
>  pushq %rbp          # ??? what insn in X86InstrInfo.td?
> .Llabel1:
>  movq  %rsp, %rbp  # ??? what insn in X86InstrInfo.td?
> .Llabel2:
>  movq  %rdi, -16(%rbp)  # ??? what insn in X86InstrInfo.td?
>  movq  -16(%rbp), %rax  # ??? what insn in X86InstrInfo.td?
>  cvtsi2sdq %rax, %xmm0  # ??? what insn in X86InstrInfo.td?
>  movsd %xmm0, -8(%rbp)  # ??? what insn in X86InstrInfo.td?
>  movsd -8(%rbp), %xmm0  # ??? what insn in X86InstrInfo.td?
>  popq  %rbp  # ??? what insn in X86InstrInfo.td?
>  ret
> 
> 
> ---
> With best regards, Konstantin
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev





More information about the llvm-dev mailing list