Codegen document question

Hi,

In The LLVM Target-Independent Code Generator — LLVM 16.0.0git documentation, I see the following.

In def FMADDS : AForm_1<59, 29,
(ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRC, F4RC:$FRB),
“fmadds $FRT, $FRA, $FRC, $FRB”,
[(set F4RC:$FRT, (fadd (fmul F4RC:$FRA, F4RC:$FRC),
F4RC:$FRB))]>;
def FADDS : AForm_2<59, 21,
(ops F4RC:$FRT, F4RC:$FRA, F4RC:$FRB),
“fadds $FRT, $FRA, $FRB”,
[(set F4RC:$FRT, (fadd F4RC:$FRA, F4RC:$FRB))]>;

In PPCInstrFormat.td, I see that AForm_1’s signature is as follows.

class AForm_1<bits<6> opcode, bits<5> xo, dag OOL, dag IOL, string asmstr,
InstrItinClass itin, list pattern>

For a beginner to write records like FMADDS is not straightforward. Can someone simplify this FMADDS? For example, I didn’t understand why InstrItinClass is used in AForm_1 as a parameter. Is there any document explaining how to write Instruction records from scratch?

Thanks in advance!

For a beginner to write records like FMADDS is not straightforward.

I would say that nothing related to LLVM backend development is straightforward. You should expect to hit a lot of walls.

Can someone simplify this FMADDS?

Not really - every field matters for the architecture you are looking at. But you could omit some of those fields in your own record definitions depending on what you need exactly. For example, if you only plan on supporting C to assembly compiler you do not need the bits<6> opcode part (assembling can be delegated to the system assembly, if you have one).

InstrItinClass denotes the itinerary class. Itinerary classes are used to describe the scheduling model of the instruction: which resources it uses, at which stages the operands are read/written, whether there are bypasses… This is all described in “itineraries”. An itinerary class maps a certain set of instructions to an itinerary.

Is there any document explaining how to write Instruction records from scratch?

I am not aware of any, but maybe there is one. So far, my own method of learning has been to look at what other backends do, look at the .td files for the few documentation there is (mainly TargetSchedule.td and Target.td), and TableGen reference for what you can do with TableGen exactly.

Perhaps your best bet would be to find and look at simpler backends to get started?

1 Like

BPF might be an easier backend to start with IMHO.

1 Like