What does this inline assembly within an LLVM-IR CodeGen testcase mean?

时间:2015-09-30 23:13:31

标签: assembly llvm inline-assembly llvm-ir

I'm trying to understand an LLVM CodeGen/Generic testcase so I can get it passing for a backend for a new processor.

This is the testcase (llvm/test/CodeGen/Generic/2007-04-08-MultipleFrameIndices.ll):

; RUN: llc -no-integrated-as < %s
; XFAIL: sparc-sun-solaris2
; PR1308
; PR1557
define i32 @stuff(i32, ...) {
    %foo = alloca i8*
    %bar = alloca i32*
    %A = call i32 asm sideeffect "inline asm $0 $2 $3 $4", "=r,0,i,m,m"( i32 0, i32 1, i8** %foo, i32** %bar )
    ret i32 %A
}

I'm specifically wondering about this part:

    %A = call i32 asm sideeffect "inline asm $0 $2 $3 $4", "=r,0,i,m,m"( i32 0, i32 1, i8** %foo, i32** %bar )

What exactly should that inline asm accomplish?

When I run it through llc as indicated in the comment, I see this on the output (for x86_64):

    .text
    .file   "<stdin>"
    .globl  stuff
    .align  16, 0x90
    .type   stuff,@function
stuff:                                  # @stuff
    .cfi_startproc
# BB#0:
    leaq    -8(%rsp), %rax
    movq    %rax, -24(%rsp)
    leaq    -16(%rsp), %rax
    movq    %rax, -32(%rsp)
    xorl    %eax, %eax
    #APP
    inline asm %eax $1 -24(%rsp) -32(%rsp)
    #NO_APP
    retq
.Ltmp0:
    .size   stuff, .Ltmp0-stuff
    .cfi_endproc


    .section    ".note.GNU-stack","",@progbits

It seems to have resulting in the following line in the output asm code:

   inline asm %eax $1 -24(%rsp) -32(%rsp)

...but I'm not entirely sure how that was generated from the input. Where does the %eax come from, for example? What does this generated line mean/do?

1 个答案:

答案 0 :(得分:1)

I am guessing that it came to be because input operand $1 is the same place as output operand $0, and must be in a register. It's also specified as a constant zero. The compiler picked %eax for $0 and thus $1 too, and zeroed it beforehand by the xorl %eax, %eax.

The generated code is invalid, I assume it is not meant to be assembled, presumably the test engine just checks whether the output assembly is the expected one.