llvm.org GIT mirror llvm / 6aa8127
Add some hands-on documentation about which files to create and edit when adding a backend. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56783 91177308-0d34-0410-b5e6-96231b3b80d8 Matthijs Kooijman 12 years ago
1 changed file(s) with 50 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
217217 how the C backend is written.

218218
219219
220
221
222 Files to create/modify
223
224
225
226
227

To actually create your backend, you need to create and modify a few files.

228 Here, the absolute minimum will be discussed. To actually use LLVM's target
229 independent codegenerator, you must implement extra
230 things.

231
232

First of all, you should create a subdirectory under lib/Target,

233 which will hold all the files related to your target. Let's assume that our
234 target is called, "Dummy", we would create the directory
235 lib/Target/Dummy.

236
237

In this new directory, you should put a Makefile. You can probably

238 copy one from another target and modify it. It should at least contain the
239 LEVEL, LIBRARYNAME and TARGET variables, and then
240 include $(LEVEL)/Makefile.common. Be careful to give the library the
241 correct name, it must be named LLVMDummy (see the MIPS target, for
242 example). Alternatively, you can split the library into
243 LLVMDummyCodeGen and LLVMDummyAsmPrinter, the latter of which
244 should be implemented in a subdirectory below lib/Target/Dummy (see the
245 PowerPC target, for example).

246
247

Note that these two naming schemes are hardcoded into llvm-config. Using any

248 other naming scheme will confuse llvm-config and produce lots of (seemingly
249 unrelated) linker errors when linking llc.

250
251

To make your target actually do something, you need to implement a subclass

252 of TargetMachine. This implementation should typically be in the file
253 lib/Target/DummyTargetMachine.cpp, but any file in the
254 lib/Target directory will be built and should work. To use LLVM's
255 href="CodeGenerator.html">target independent code generator, you should
256 create a subclass of LLVMTargetMachine. This is what all current
257 machine backends do. To create a target from scratch, create a subclass of
258 TargetMachine. This is what the current language backends do.

259
260

To get LLVM to actually build and link your target, you also need to add it

261 to the TARGETS_TO_BUILD variable. To do this, you need to modify the
262 configure script to know about your target when parsing the
263 --enable-targets option. Search the configure script for
264 TARGETS_TO_BUILD, add your target to the lists there (some creativity
265 required) and then reconfigure. Alternatively, you can change
266 autotools/configure.ac and regenerate configure by running
267 ./autoconf/AutoRegen.sh.
268
269
220270
221271
222272