Hi,
I have some questions with regard to instruction definition.
Preamble:
- My target allows immediate values for common arithmetic instructions, fma, fadd, … etc.
- I don’t need llvm’s assembler and disassembler components
=> I don’t need encode info in my InstrFormat.td and InstrInfo.td.
My first question is should I define an instruction which allows Register/Immediate operands, or should I define many instructions and each maps to an “operands-combination”.
For example:
Single instruction pattern
// Instruction definition
def f32Op : Operand<f32>;
def FMA : Inst<"fma",
(outs Dst32:$rd),
(ins f32Op:$rn, f32Op:$rm, f32Op:$ra)>;
// Pattern definition
def F32ImmOp : Operand<f32>, FPImmLeaf<f32, [{ return true; }]>;
// rii
def : Pat<(any_fma Src32:$rn, F32ImmOp:$imm0, F32ImmOp:$imm1),
(FMA Src32:$rn, F32ImmOp:$imm0, F32ImmOp:$imm1)>;
// rri
def : Pat<(any_fma Src32:$rn, Src32:$rm, F32ImmOp:$imm0),
(FMA Src32:$rn, Src32:$rm, F32ImmOp:$imm0)>;
// rir, irr, iir, iri, iir, rrr. etc.
Many instructions pattern
def FMArii : Inst<"fma_rii", (outs Dst32:$rd), (ins Src32:$rn, F32ImmOp:$imm0, F32ImmOp:$imm1)>;
def FMArri : Inst<"fma_rri", (outs Dst32:$rd), (ins Src32:$rn, Src32:$rm, F32ImmOp:$imm0)>;
... rir, irr, iir, iri, iir, rrr. etc.
// rii
def : Pat<(any_fma Src32:$rn, F32ImmOp:$imm0, F32ImmOp:$imm1),
(FMArii Src32:$rn, F32ImmOp:$imm0, F32ImmOp:$imm1)>;
// rri
....
Currently I prefer Single instruction pattern. Because I don’t want to create too many instruction variants, i.e. FMArii, FMArri, FMArir, …
Any comments on this?
My second question is, when defining outs and ins dags, it looks like the operand type doesn’t really matter, for example:
def f32Op : Operand<f32>;
def FMA : Inst<"fma",
(outs Dst32:$rd),
(ins f32Op:$rn, f32Op:$rm, f32Op:$ra)>;
// or:
def FMA : Inst<"fma",
(outs Dst32:$rd),
(ins Src32:$rn, Src32:$rm, Src32:$ra)>;
// Src32 is a specific register class.
I found Operand Type (DAGOperand or SDPatternOperator) is only matter in pattern definition (I am using GISel), i.e. I can use any operand in instruction definition and it has no any effect on pattern match. Is it because I don’t use llvm’s assembler/disassembler so I don’t really need to pay attention on operands when defining an instruction?
Thanks!
CY