Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame^] | 1 | // This test describes how we eventually want to describe instructions in |
| 2 | // the target independent code generators. |
| 3 | // RUN: tblgen %s |
| 4 | |
| 5 | // Target indep stuff. |
| 6 | class Instruction { // Would have other stuff eventually |
| 7 | bit isTwoAddress = 0; |
| 8 | string AssemblyString; |
| 9 | } |
| 10 | class RegisterClass; |
| 11 | |
| 12 | class RTLNode; |
| 13 | |
| 14 | def ops; // Marker for operand list. |
| 15 | |
| 16 | // Various expressions used in RTL descriptions. |
| 17 | def imm8 : RTLNode; |
| 18 | def imm32 : RTLNode; |
| 19 | def addr : RTLNode; |
| 20 | |
| 21 | def set : RTLNode; |
| 22 | def signext : RTLNode; |
| 23 | def zeroext : RTLNode; |
| 24 | def plus : RTLNode; |
| 25 | def and : RTLNode; |
| 26 | def xor : RTLNode; |
| 27 | def shl : RTLNode; |
| 28 | def load : RTLNode; |
| 29 | def store : RTLNode; |
| 30 | def unspec : RTLNode; |
| 31 | |
| 32 | // Start of X86 specific stuff. |
| 33 | |
| 34 | def R8 : RegisterClass; |
| 35 | def R16 : RegisterClass; |
| 36 | def R32 : RegisterClass; |
| 37 | |
| 38 | def CL; // As are currently defined |
| 39 | def AL; |
| 40 | def AX; |
| 41 | def EDX; |
| 42 | |
| 43 | class Format<bits<5> val> { |
| 44 | bits<5> Value = val; |
| 45 | } |
| 46 | |
| 47 | def Pseudo : Format<0>; def RawFrm : Format<1>; |
| 48 | def AddRegFrm : Format<2>; def MRMDestReg : Format<3>; |
| 49 | def MRMDestMem : Format<4>; def MRMSrcReg : Format<5>; |
| 50 | def MRMSrcMem : Format<6>; |
| 51 | def MRM0r : Format<16>; def MRM1r : Format<17>; def MRM2r : Format<18>; |
| 52 | def MRM3r : Format<19>; def MRM4r : Format<20>; def MRM5r : Format<21>; |
| 53 | def MRM6r : Format<22>; def MRM7r : Format<23>; |
| 54 | def MRM0m : Format<24>; def MRM1m : Format<25>; def MRM2m : Format<26>; |
| 55 | def MRM3m : Format<27>; def MRM4m : Format<28>; def MRM5m : Format<29>; |
| 56 | def MRM6m : Format<30>; def MRM7m : Format<31>; |
| 57 | |
| 58 | |
| 59 | class Inst<dag opnds, string asmstr, bits<8> opcode, |
| 60 | Format f, list<dag> rtl> : Instruction { |
| 61 | dag Operands = opnds; |
| 62 | string AssemblyString = asmstr; |
| 63 | bits<8> Opcode = opcode; |
| 64 | Format Format = f; |
| 65 | list<dag> RTL = rtl; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | // Start of instruction definitions, the real point of this file. |
| 70 | // |
| 71 | // Note that these patterns show a couple of important things: |
| 72 | // 1. The order and contents of the operands of the MachineInstr are |
| 73 | // described here. Eventually we can do away with this when everything |
| 74 | // is generated from the description. |
| 75 | // 2. The asm string is captured here, which makes it possible to get rid of |
| 76 | // a ton of hacks in the various printers and a bunch of flags. |
| 77 | // 3. Target specific properties (e.g. Format) can still be captured as |
| 78 | // needed. |
| 79 | // 4. We capture the behavior of the instruction with a simplified RTL-like |
| 80 | // expression. |
| 81 | // 5. The use/def properties for each operand are automatically inferred from |
| 82 | // the pattern. |
| 83 | // 6. Address expressions should become first-class entities. |
| 84 | |
| 85 | // Simple copy instruction. isMoveInstr could easily be inferred from this, |
| 86 | // as could MRegisterInfo::copyRegToReg. |
| 87 | def MOV8rr : Inst<(ops R8:$dst, R8:$src), |
| 88 | "mov $dst, $src", 0x88, MRMDestReg, |
| 89 | [(set R8:$dst, R8:$src)]>; |
| 90 | |
| 91 | // Simple immediate initialization. |
| 92 | def MOV8ri : Inst<(ops R8:$dst, imm8:$src), |
| 93 | "mov $dst, $src", 0xB0, AddRegFrm, |
| 94 | [(set R8:$dst, imm8:$src)]>; |
| 95 | |
| 96 | // Two address instructions are described as three-addr instructions, with |
| 97 | // the special target-independent isTwoAddress flag set. The asm pattern |
| 98 | // should not refer to the $src1, this would be enforced by the |
| 99 | // TargetInstrInfo tablegen backend. |
| 100 | let isTwoAddress = 1 in |
| 101 | def AND8rr : Inst<(ops R8:$dst, R8:$src1, R8:$src2), |
| 102 | "and $dst, $src2", 0x20, MRMDestReg, |
| 103 | [(set R8:$dst, (and R8:$src1, R8:$src2))]>; |
| 104 | |
| 105 | // Instructions that have explicit uses/defs make them explicit in the RTL. |
| 106 | // Instructions that need extra stuff emitted in the assembly can, trivially. |
| 107 | let isTwoAddress = 1 in |
| 108 | def SHL32rCL : Inst<(ops R32:$dst, R32:$src), |
| 109 | "shl $dst, CL", 0xD2, MRM4r, |
| 110 | [(set R32:$dst, (shl R32:$src, CL))]>; |
| 111 | |
| 112 | // The RTL list is a list, allowing complex instructions to be defined easily. |
| 113 | // Temporary 'internal' registers can be used to break instructions appart. |
| 114 | let isTwoAddress = 1 in |
| 115 | def XOR32mi : Inst<(ops addr:$addr, imm32:$imm), |
| 116 | "xor $dst, $src2", 0x81, MRM6m, |
| 117 | [(set R32:$tmp1, (load addr:$addr)), |
| 118 | (set R32:$tmp2, (xor R32:$tmp1, imm32:$imm)), |
| 119 | (store addr:$addr, R32:$tmp2)]>; |
| 120 | |
| 121 | // Alternatively, if each tmporary register is only used once, the instruction |
| 122 | // can just be described in nested form. This would be the canonical |
| 123 | // representation the target generator would convert the above into. Pick your |
| 124 | // favorite indentation scheme. |
| 125 | let isTwoAddress = 1 in |
| 126 | def AND32mr : Inst<(ops addr:$addr, R32:$src), |
| 127 | "xor $dst, $src2", 0x81, MRM6m, |
| 128 | [(store addr:$addr, |
| 129 | (and |
| 130 | (load addr:$addr), |
| 131 | R32:$src) |
| 132 | ) |
| 133 | ]>; |
| 134 | |
| 135 | // Describing complex instructions is not too hard! Note how implicit uses/defs |
| 136 | // become explicit here. |
| 137 | def CBW : Inst<(ops), |
| 138 | "cbw", 0x98, RawFrm, |
| 139 | [(set AX, (signext AL))]>; |
| 140 | |
| 141 | // Noop, does nothing. |
| 142 | def NOOP : Inst<(ops), "nop", 0x90, RawFrm, []>; |
| 143 | |
| 144 | |
| 145 | // Instructions that don't expect optimization can use unspec. |
| 146 | def IN8rr : Inst<(ops), "in AL, EDX", 0xEC, RawFrm, |
| 147 | [(set AL, (unspec EDX))]>; |
| 148 | |