[LLVMdev] [PATCH][RFC] Add llvm.codegen Intrinsic To Support Embedded LLVM IR Code Generation

dag at cray.com dag at cray.com
Tue May 8 09:29:25 PDT 2012


Tobias Grosser <tobias at grosser.es> writes:

> So why the intrinsic? I want to create the PTX string from an LLVM-IR
> optimizer pass, that should be loaded into clang, dragonegg, opt, ..

You want to codegen in the optimizer?  I'm confused.

> An LLVM-IR optimizer pass does not have access to the file system and
> it can not link to the LLVM back ends to directly create PTX. Creating
> PTX in an optimizer pass would be an ugly hack.

So you _don't_ want to codegen in the optimizer.  Now I'm really
confused.

> The cleaner solution is to store an LLVM-IR string in the host module
> and to mark it with the llvm.codegen() intrinsic. When the module is
> processed by the backend, the string is automatically translated to
> PTX. This requires no additional file writing, introduces no layering
> violations and seems to be very simple.

Why do you need to store IR in a string?  It's already in the IR file or
you can put it into another file.  All you need is an _external_ tool to
drive llc to process and codegen these multiple files (to multiple
targets) and then another tool to suck up the accelerator code into a
string in the host assembly file.  Then you assemble into an object.

No IR changes and you end up with one object file.  No changes to build
systems at all, it's all handled by a driver.

llvm.codegen is completely unnecessary.

                                 -Dave



More information about the llvm-dev mailing list