5

Starting from an LLVM module *Mod containing some IR: How do I use a specific back-end to generate target-specific assembler from it? Unfortunately the Kaleidoscope tutorial does not detail on this. It only uses the execution engine to JIT compile the program (on the build, target architecture), but does not actually select a specific back-end to generate target-specific assembler. Neither does any LLVM tutorials, as they are not detailing on building a static compiler, I assume. Thus, this question can provide this missing piece of information.

Since we want to build a static compiler, we don't want to use the command line tools like llc, etc. to accomplish the job. We want to use the LLVM API.

To make this more concrete, let's start with this code:

LLVMContext &Context = getGlobalContext();
SMDiagnostic Err;
Module *Mod = ParseIRFile(argv[1], Err, Context);

The filename (given by the 1st argument) was successfully parsed to IR. Now let's skip the optimization passes and create some assembler with a specific back-end, e.g. the PTX backend (available since version 3.2).

4

1 回答 1

8

只需查看tools/llc/llc.cpp. 它完成了所有这些,而且非常简短且不难理解。如果您对某些您不理解的事情有具体问题,请随时提问。

于 2013-05-09T14:57:53.567 回答