Make PPC JIT support inline assembly?

Hi, all

  It seems PPC JIT does not recognize inline assembly.
For example, when I give LLVM IR belows to PPC JIT,

%0 = tail call i32* asm "", "={r10}"() nounwind ; <i32*> [#uses=1]

  it complaints that inline assembly is not a supported
instruction. x86 JIT works fine, however.

  Is there a reason that makes PPC JIT not support inline
assembly?

  Currently, we modify PPCGenCodeEmitter.inc, then rebuild
LLVM to let ppc recognize inline assembly (see attachment).
Is there a better way to make PPC JIT support inline assembly?

  Any suggestion appreciated.

Regards,
chenwj

PPCGenCodeEmitter.inc.patch (348 Bytes)

Hi 陳韋任,

   It seems PPC JIT does not recognize inline assembly.
For example, when I give LLVM IR belows to PPC JIT,

%0 = tail call i32* asm "", "={r10}"() nounwind ;<i32*> [#uses=1]

   it complaints that inline assembly is not a supported
instruction. x86 JIT works fine, however.

I'm surprised this worked with the x86 JIT - I thought the JIT didn't
support any inline assembler on any platform, and that the plan was to
solve this with the new MC-JIT, see
   http://blog.llvm.org/2010/04/intro-to-llvm-mc-project.html

Ciao, Duncan.

Hi,

Very few inline assembly are supported for the X86 backend. As I see from
X86ISelLowering.cpp, only bswap, rorw, xchgl and simple register selections
(e.g. {=r10}) LLVM JIT can recoginze. But for PPC backend, I am not
sure why PPC JIT see all inline assembly IRs as an error.

Ding-Yong

Hi, Duncan

support any inline assembler on any platform, and that the plan was to
solve this with the new MC-JIT, see
   http://blog.llvm.org/2010/04/intro-to-llvm-mc-project.html

  At the first glance, I think what llvm-mc does is, given an input,
llvm-mc will disassemble the input into assembly. I don't know the
MC-JIT you mentioned can be used as a JIT. Currently, a JIT is
created by ExecutionEngine::createJIT.

  Can you give more information about the MC-JIT? Is it already
included in llvm-2.8?

  Thank!

Regards,
chenwj

Hi chenwj,

support any inline assembler on any platform, and that the plan was to
solve this with the new MC-JIT, see
    http://blog.llvm.org/2010/04/intro-to-llvm-mc-project.html

   At the first glance, I think what llvm-mc does is, given an input,
llvm-mc will disassemble the input into assembly. I don't know the
MC-JIT you mentioned can be used as a JIT. Currently, a JIT is
created by ExecutionEngine::createJIT.

   Can you give more information about the MC-JIT? Is it already
included in llvm-2.8?

it is not in llvm-2.8, it will not even be in llvm-2.9. This is why you
couldn't find it :slight_smile: Some patches went into the subversion repository
lately if you are interested.

Ciao, Duncan.

Hi Ding-Yong,

Very few inline assembly are supported for the X86 backend. As I see from
X86ISelLowering.cpp, only bswap, rorw, xchgl and simple register selections
(e.g. {=r10}) LLVM JIT can recoginze. But for PPC backend, I am not
sure why PPC JIT see all inline assembly IRs as an error.

probably because no-one was interested enough to add the analogous logic to the
PPC backend (the PowerPC target does not implement ExpandInlineAsm).

Ciao, Duncan.

Hi, Duncan

it is not in llvm-2.8, it will not even be in llvm-2.9. This is why you
couldn't find it :slight_smile: Some patches went into the subversion repository
lately if you are interested.

  You mentioned "the plan was to solve this with the new MC-JIT". You
mean that MC-JIT can handle inline assembly as an input, and generate
target binary code?

Regards,
chenwj

Hi chenwj,

it is not in llvm-2.8, it will not even be in llvm-2.9. This is why you
couldn't find it :slight_smile: Some patches went into the subversion repository
lately if you are interested.

   You mentioned "the plan was to solve this with the new MC-JIT". You
mean that MC-JIT can handle inline assembly as an input, and generate
target binary code?

MC allows you to turn LLVM IR into object code or assembler. It also enables
you to turn assembler into object code. Consider now how a JIT works. When a
function is to be run, the LLVM IR for it needs to be turned into object code
in memory; the object code will then be executed by the processor. I hope it
is clear that MC could be used to generate the object code in memory, rather
than the hand-crafted assembly snippets currently used. Now consider what is
required to have the JIT execute inline assembler. Essentially an inline asm
is a string containing assembly code. In order for the JIT to execute it it
needs to convert that assembly code into object code in memory. Thus the JIT
needs to have a built in assembler. Currently the JIT does not have a built
in assembler (though in the X86 case it does have an assembler that can only
handle a few special cases). Since MC can also act as an assembler, it could
be used to turn inline asm into object code.

Ciao, Duncan.

Hi,

  I see. Thanks. :slight_smile:

  One more question, how mature MC-JIT is? Can it be used on
x86 or other architecture?

Regards,
chenwj

Hi chenwj,

   One more question, how mature MC-JIT is? Can it be used on
x86 or other architecture?

my understanding is that it is not yet usable.

Ciao, Duncan.

Correct. It's in its very early stages. It can run some trivial things, but nothing really interesting yet.