-
In general, you want to follow the format of X86 or PowerPC (in
-lib/Target).
+
In general, you want to follow the format of SPARC, X86 or PowerPC (in
+lib/Target). SPARC is the simplest backend, and is RISC, so if
+you're working on a RISC target, it is a good one to start with.
To create a static compiler (one that emits text assembly), you need to
implement the following:
-- Describe the register set
+
- Describe the register set.
- Create a TableGen description of
the register set and register classes
- Implement a subclass of MRegisterInfo
+ href="CodeGenerator.html#targetregisterinfo">TargetRegisterInfo
-
Describe the instruction set
+Describe the instruction set.
-
Describe the target machine
+Describe the target machine.
- Create a TableGen description of
the target that describes the pointer size and references the instruction
@@ -92,38 +92,50 @@ implement the following:
href="CodeGenerator.html#targetmachine">TargetMachine, which
configures TargetData
correctly
+ - Register your new target using the RegisterTarget
+ template:
+
+RegisterTarget<MyTargetMachine> M("short_name", " Target name");
+
+
Here, MyTargetMachine is the name of your implemented
+ subclass of TargetMachine,
+ short_name is the option that will be active following
+ -march= to select a target in llc and lli, and the last string
+ is the description of your target to appear in -help
+ listing.
-
Implement the assembly printer for the architecture. Usually, if you have
-described the instruction set with the assembly printer generator in mind, that
-step can be almost automated.
-
-
-
Now, for static code generation you also need to write an instruction
-selector for your platform: see lib/Target/*/*ISelSimple.cpp which
-is no longer "simple" but it gives you the idea: you have to be able to create
-MachineInstrs for any given LLVM instruction using the InstVisitor
-pattern, and produce a MachineFunction with
-MachineBasicBlocks full of MachineInstrs for a
-corresponding LLVM Function. Creating an instruction selector is perhaps the
-most time-consuming part of creating a back-end.
-
-
To create a JIT for your platform:
-
+
Implement the assembly printer for the architecture.
+
+ - Define all of the assembly strings for your target, adding them to the
+ instructions in your *InstrInfo.td file.
+ - Implement the llvm::AsmPrinter interface.
+
+
+
Implement an instruction selector for the architecture.
+
+ - The recommended method is the
+ pattern-matching DAG-to-DAG instruction selector (for example, see
+ the PowerPC backend in PPCISelDAGtoDAG.cpp). Parts of instruction
+ selector creation can be performed by adding patterns to the instructions
+ in your .td file.
+
+
+
Optionally, add subtarget support.
-- Create a subclass of TargetJITInfo
-- Create a machine code emitter that will be used to emit binary code
- directly into memory, given MachineInstrs
+ - If your target has multiple subtargets (e.g. variants with different
+ capabilities), implement the llvm::TargetSubtarget interface
+ for your architecture. This allows you to add -mcpu= and
+ -mattr= options.
+
+Optionally, add JIT support.
+
+ - Create a subclass of TargetJITInfo
+ - Create a machine code emitter that will be used to emit binary code
+ directly into memory, given MachineInstrs
+
-
-Note that lib/target/Skeleton is a clean skeleton for a new target,
-so you might want to start with that and adapt it for your target, and if you
-are wondering how things are done, peek in the X86 or PowerPC target.
-
-The Skeleton target is non-functional but provides the basic building blocks
-you will need for your endeavor.
-
@@ -148,15 +160,15 @@ architected registers.
// class Register is defined in Target.td
-class TargetReg : Register {
+class TargetReg<string name> : Register<name> {
let Namespace = "Target";
}
-class IntReg<bits<5> num> : TargetReg {
+class IntReg<bits<5> num, string name> : TargetReg<name> {
field bits<5> Num = num;
}
-def R0 : IntReg<0>;
+def R0 : IntReg<0, "%R0">;
...
// class RegisterClass is defined in Target.td
@@ -218,10 +230,13 @@ how the C backend is written.
- Code generator -
describes some of the classes in code generation at a high level, but
- it is not (yet) complete.
+ it is not (yet) complete
- TableGen fundamentals -
- describes how to use TableGen to describe your target information succinctly
-
+ describes how to use TableGen to describe your target information
+ succinctly
+- Debugging code generation with
+ bugpoint - shows bugpoint usage scenarios to simplify backend
+ development
@@ -236,7 +251,7 @@ how the C backend is written.
src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" />