Pattern class

Has anybody used the Pattern class. We all use Pat and ComplexPattern but I can’t find any examples of Pattern.

I have some instructions that I’m currently treating as pseudos but I’d like to treat them as patterns with several instructions but this does not seem to work, at least I can’t get it to work so far.

I get an error:

Cannot handle instructions with temporaries yet!

When I try and use it.

You might want to refer to lib/Target/Sparc/SparcInstrInfo.td for
examples of both Pat and ComplexPattern.

Regards.

I'm interested in class Pattern.

Classes Pat and ComplexPattern are used everywhere.

I have several places where I want to emit several instructions but they are not connected as would be required by Pat.

Right now I do them as sort of pseudo instructions where several machine instructions are put in the assembly string.

This has several problems for direct object emitting and also it's not the cleanest solution.

I really want to match the pattern and emit my instruction sequence using a set of single instructions.

This is what is supposedly allowed in class Pattern but I can't seem to get it to be accepted by tablegen and can't find any examples of people using it.

An example of a place where I need it is for certain conditional expressions.

For example, register T8 is not directly accessible when in mips 16 mode and is more or less a condition code register in that mode.

So I want to do a compare and then a branch based on the contents of T8 (which the branch instructions can implicity see).

I have other cases that are more involved where I am simulating conditional move instructions.

I can do it all with my current method but it's not preferred and would be cleaner with this multiple instruction sequence of the Pattern class.

This has several problems for direct object emitting

Why? Just expand these pseudos before asm printing and you're done.
This is the approach used by other targets. Check e.g. ARM backend for
handling movw + movt pair of instructions.

> This has several problems for direct object emitting
Why? Just expand these pseudos before asm printing and you're done.
This is the approach used by other targets. Check e.g. ARM backend for
handling movw + movt pair of instructions.

I think that *if* it were possible to do this with patterns, then that
would be the preferred mechanism.

-Hal

This Pattern class says it's possible but seems just to not work or maybe I'm using it incorrectly.

Probably I will go and fix it when I'm done with mips16.

What have you tried?

Here is a simple place I wanted to use it.

...

On multiply, the result implicit is placed in a 64 bit hi/lo register.

//
// Format: MFLO rx MIPS16e
// Purpose: Move From LO Register
// To copy the special purpose LO register to a GPR.
//
def Mflo16: FRR16_M_ins<0b10010, "mflo", IIAlu> {
  let Uses = [LO];
  let neverHasSideEffects = 1;
}

//
// Pseudo Instruction for mult
//
def MultRxRy16: FMULT16_ins<"mult", IIAlu> {
  let isCommutable = 1;
  let neverHasSideEffects = 1;
  let Defs = [HI, LO];
}

def: Mips16Pattern<(mul CPU16Regs:$l, CPU16Regs:$r),
              [(MultRxRyRz16 CPU16Regs:$l, CPU16Regs:$r), (Mflo16) ]>;

Without the list of instructions feature in the Pattern class, I am forced to make a pseudo that has both the mul and mflo instruction in it.

This is a very simple example and some, like for example the conditional move have 3 instructions with sequences like:

cmp x,y
bnez .+4
move a, b

I am able to do all of this just fine with pseudo's but it's not as clean a solution.

If I can't solve this more elegantly, I will be putting back the current code to the Mips16 port tomorrow.

I have quite a few of these multi instruction pseudos for condtional branch, select and setcc matching