[LLVMdev] Using patterns inside patterns

Chris Lattner clattner at apple.com
Thu Oct 30 10:28:43 PDT 2008


On Oct 30, 2008, at 9:18 AM, Villmow, Micah wrote:

> I do not have access to a subtraction routine, as it is considered  
> add with negation on the second parameter, so I have this pattern:
> // integer subtraction
> // a - b ==> a + (-b)
> def ISUB : Pat<(sub GPRI32:$src0, GPRI32:$src1),
>                (IADD GPRI32:$src0, (INEGATE GPRI32:$src1))>;

Micah,

The best way to find answers to these types of questions is to look  
for examples in other targets.  For example, PPC has this Pat pattern  
which synthesizes an immediate with two instructions:

// Arbitrary immediate support.  Implement in terms of LIS/ORI.
def : Pat<(i32 imm:$imm),
           (ORI (LIS (HI16 imm:$imm)), (LO16 imm:$imm))>;


It also has stuff like this:

// Implement the 'not' operation with the NOR instruction.
def NOT : Pat<(not GPRC:$in),
               (NOR GPRC:$in, GPRC:$in)>;

For more information, please see the powerpc .td files.  In answer to  
your question, you can't map target-independent nodes to target- 
independent nodes, you have to map them to target specific  
instructions: ORI/LIS/NOR in these examples.

-Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20081030/0563ed89/attachment.html>


More information about the llvm-dev mailing list