Chris Lattner | ee6b5f6 | 2003-07-29 23:07:13 +0000 | [diff] [blame] | 1 | //===- Target.td - Target Independent TableGen interface --------*- C++ -*-===// |
| 2 | // |
| 3 | // This file defines the target-independent interfaces which should be |
| 4 | // implemented by each target which is using a TableGen based code generator. |
| 5 | // |
Misha Brukman | 01c1638 | 2003-05-29 18:48:17 +0000 | [diff] [blame] | 6 | //===----------------------------------------------------------------------===// |
| 7 | |
Chris Lattner | 7c28952 | 2003-07-30 05:50:12 +0000 | [diff] [blame] | 8 | |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | // |
Chris Lattner | b3aa319 | 2003-07-28 04:24:59 +0000 | [diff] [blame] | 11 | // Value types - These values correspond to the register types defined in the |
Chris Lattner | 84c40c1 | 2003-07-29 23:02:49 +0000 | [diff] [blame] | 12 | // ValueTypes.h file. |
Chris Lattner | 0ad1361 | 2003-07-30 22:16:41 +0000 | [diff] [blame] | 13 | // |
Chris Lattner | de04dd7 | 2003-08-01 05:18:03 +0000 | [diff] [blame] | 14 | class ValueType<int size> { string Namespace = "MVT"; int Size = size; } |
Chris Lattner | 7c28952 | 2003-07-30 05:50:12 +0000 | [diff] [blame] | 15 | |
Chris Lattner | de04dd7 | 2003-08-01 05:18:03 +0000 | [diff] [blame] | 16 | def i1 : ValueType<1>; // One bit boolean value |
| 17 | def i8 : ValueType<8>; // 8-bit integer value |
| 18 | def i16 : ValueType<16>; // 16-bit integer value |
| 19 | def i32 : ValueType<32>; // 32-bit integer value |
| 20 | def i64 : ValueType<64>; // 64-bit integer value |
Chris Lattner | de04dd7 | 2003-08-01 05:18:03 +0000 | [diff] [blame] | 21 | def f32 : ValueType<32>; // 32-bit floating point value |
| 22 | def f64 : ValueType<64>; // 64-bit floating point value |
| 23 | def f80 : ValueType<80>; // 80-bit floating point value |
Chris Lattner | 7c28952 | 2003-07-30 05:50:12 +0000 | [diff] [blame] | 24 | |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | // Register file description - These classes are used to fill in the target |
| 27 | // description classes in llvm/Target/MRegisterInfo.h |
| 28 | |
| 29 | |
| 30 | // Register - You should define one instance of this class for each register in |
| 31 | // the target machine. |
| 32 | // |
Misha Brukman | 01c1638 | 2003-05-29 18:48:17 +0000 | [diff] [blame] | 33 | class Register { |
| 34 | string Namespace = ""; |
Chris Lattner | 76bf868 | 2003-08-03 22:12:37 +0000 | [diff] [blame] | 35 | string Name = ""; |
| 36 | } |
| 37 | |
| 38 | // NamedReg - If the name for the 'def' of the register should not become the |
| 39 | // "name" of the register, you can use this to specify a custom name instead. |
| 40 | // |
| 41 | class NamedReg<string n> : Register { |
Chris Lattner | 60e81db | 2003-08-04 04:58:12 +0000 | [diff] [blame] | 42 | let Name = n; |
Misha Brukman | 01c1638 | 2003-05-29 18:48:17 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Chris Lattner | 7c28952 | 2003-07-30 05:50:12 +0000 | [diff] [blame] | 45 | // RegisterAliases - You should define instances of this class to indicate which |
| 46 | // registers in the register file are aliased together. This allows the code |
| 47 | // generator to be careful not to put two values with overlapping live ranges |
| 48 | // into registers which alias. |
| 49 | // |
| 50 | class RegisterAliases<Register reg, list<Register> aliases> { |
| 51 | Register Reg = reg; |
| 52 | list<Register> Aliases = aliases; |
| 53 | } |
| 54 | |
| 55 | // RegisterClass - Now that all of the registers are defined, and aliases |
| 56 | // between registers are defined, specify which registers belong to which |
| 57 | // register classes. This also defines the default allocation order of |
| 58 | // registers by register allocators. |
| 59 | // |
| 60 | class RegisterClass<ValueType regType, int alignment, list<Register> regList> { |
Chris Lattner | 0ad1361 | 2003-07-30 22:16:41 +0000 | [diff] [blame] | 61 | // RegType - Specify the ValueType of the registers in this register class. |
| 62 | // Note that all registers in a register class must have the same ValueType. |
| 63 | // |
Chris Lattner | 7c28952 | 2003-07-30 05:50:12 +0000 | [diff] [blame] | 64 | ValueType RegType = regType; |
Chris Lattner | 0ad1361 | 2003-07-30 22:16:41 +0000 | [diff] [blame] | 65 | |
| 66 | // Alignment - Specify the alignment required of the registers when they are |
| 67 | // stored or loaded to memory. |
| 68 | // |
Chris Lattner | de04dd7 | 2003-08-01 05:18:03 +0000 | [diff] [blame] | 69 | int Size = RegType.Size; |
Chris Lattner | 7c28952 | 2003-07-30 05:50:12 +0000 | [diff] [blame] | 70 | int Alignment = alignment; |
Chris Lattner | 0ad1361 | 2003-07-30 22:16:41 +0000 | [diff] [blame] | 71 | |
| 72 | // MemberList - Specify which registers are in this class. If the |
| 73 | // allocation_order_* method are not specified, this also defines the order of |
| 74 | // allocation used by the register allocator. |
| 75 | // |
Chris Lattner | 7c28952 | 2003-07-30 05:50:12 +0000 | [diff] [blame] | 76 | list<Register> MemberList = regList; |
Chris Lattner | 0ad1361 | 2003-07-30 22:16:41 +0000 | [diff] [blame] | 77 | |
Chris Lattner | be84e3c | 2003-08-01 22:21:49 +0000 | [diff] [blame] | 78 | // Methods - This member can be used to insert arbitrary code into a generated |
| 79 | // register class. The normal usage of this is to overload virtual methods. |
| 80 | code Methods = [{}]; |
Chris Lattner | 7c28952 | 2003-07-30 05:50:12 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | |
| 84 | //===----------------------------------------------------------------------===// |
Chris Lattner | a5100d9 | 2003-08-03 18:18:31 +0000 | [diff] [blame] | 85 | // Instruction set description - These classes correspond to the C++ classes in |
| 86 | // the Target/TargetInstrInfo.h file. |
Chris Lattner | 7c28952 | 2003-07-30 05:50:12 +0000 | [diff] [blame] | 87 | // |
| 88 | |
Misha Brukman | 01c1638 | 2003-05-29 18:48:17 +0000 | [diff] [blame] | 89 | class Instruction { |
| 90 | string Name; // The opcode string for this instruction |
| 91 | string Namespace = ""; |
| 92 | |
| 93 | list<Register> Uses = []; // Default to using no non-operand registers |
| 94 | list<Register> Defs = []; // Default to modifying no non-operand registers |
| 95 | |
| 96 | // These bits capture information about the high-level semantics of the |
| 97 | // instruction. |
Chris Lattner | 84c40c1 | 2003-07-29 23:02:49 +0000 | [diff] [blame] | 98 | bit isReturn = 0; // Is this instruction a return instruction? |
| 99 | bit isBranch = 0; // Is this instruction a branch instruction? |
| 100 | bit isCall = 0; // Is this instruction a call instruction? |
| 101 | bit isTwoAddress = 0; // Is this a two address instruction? |
| 102 | bit isTerminator = 0; // Is this part of the terminator for a basic block? |
Chris Lattner | 244883e | 2003-08-04 21:07:37 +0000 | [diff] [blame] | 103 | |
| 104 | // Pattern - Set to the DAG pattern for this instruction, if we know of one, |
| 105 | // otherwise, uninitialized. |
| 106 | dag Pattern; |
Chris Lattner | a5100d9 | 2003-08-03 18:18:31 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Chris Lattner | 3e77d6e | 2003-08-06 15:31:02 +0000 | [diff] [blame] | 109 | class Expander<dag pattern, list<dag> result> { |
| 110 | dag Pattern = pattern; |
| 111 | list<dag> Result = result; |
| 112 | } |
| 113 | |
| 114 | |
Chris Lattner | a5100d9 | 2003-08-03 18:18:31 +0000 | [diff] [blame] | 115 | // InstrInfo - This class should only be instantiated once to provide parameters |
| 116 | // which are global to the the target machine. |
| 117 | // |
| 118 | class InstrInfo { |
| 119 | Instruction PHIInst; |
Chris Lattner | 34a2068 | 2003-08-03 21:52:28 +0000 | [diff] [blame] | 120 | |
| 121 | // If the target wants to associate some target-specific information with each |
| 122 | // instruction, it should provide these two lists to indicate how to assemble |
| 123 | // the target specific information into the 32 bits available. |
| 124 | // |
| 125 | list<string> TSFlagsFields = []; |
| 126 | list<int> TSFlagsShifts = []; |
Chris Lattner | a5100d9 | 2003-08-03 18:18:31 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | |
| 130 | //===----------------------------------------------------------------------===// |
| 131 | // Target - This class contains the "global" target information |
| 132 | // |
| 133 | class Target { |
| 134 | // CalleeSavedRegisters - As you might guess, this is a list of the callee |
| 135 | // saved registers for a target. |
| 136 | list<Register> CalleeSavedRegisters = []; |
| 137 | |
| 138 | // PointerType - Specify the value type to be used to represent pointers in |
| 139 | // this target. Typically this is an i32 or i64 type. |
| 140 | ValueType PointerType; |
| 141 | |
| 142 | // InstructionSet - Instruction set description for this target |
| 143 | InstrInfo InstructionSet; |
Misha Brukman | 01c1638 | 2003-05-29 18:48:17 +0000 | [diff] [blame] | 144 | } |
Chris Lattner | 244883e | 2003-08-04 21:07:37 +0000 | [diff] [blame] | 145 | |
| 146 | |
| 147 | //===----------------------------------------------------------------------===// |
| 148 | // DAG node definitions used by the instruction selector... |
| 149 | // |
Chris Lattner | 3e77d6e | 2003-08-06 15:31:02 +0000 | [diff] [blame] | 150 | class DagNodeResultType; |
| 151 | def DNRT_void : DagNodeResultType; // Tree node always returns void |
| 152 | def DNRT_val : DagNodeResultType; // A non-void type |
| 153 | def DNRT_arg0 : DagNodeResultType; // Tree node returns same type as Arg0 |
| 154 | |
| 155 | class DagNodeArgType; |
| 156 | def DNAT_val : DagNodeArgType; // Any value |
| 157 | def DNAT_arg0 : DagNodeArgType; // Same as for arg #0 |
| 158 | def DNAT_ptr : DagNodeArgType; // Returns the target pointer type |
| 159 | |
| 160 | class DagNode<DagNodeResultType ret, list<DagNodeArgType> args> { |
| 161 | DagNodeResultType RetType = ret; |
| 162 | list<DagNodeArgType> ArgTypes = args; |
| 163 | string EnumName = ?; |
| 164 | } |
| 165 | |
| 166 | // BuiltinDagNodes are built into the instruction selector and correspond to |
| 167 | // enum values. |
| 168 | class BuiltinDagNode<DagNodeResultType Ret, list<DagNodeArgType> Args, |
| 169 | string Ename> : DagNode<Ret, Args> { |
| 170 | let EnumName = Ename; |
| 171 | } |
| 172 | |
| 173 | // Magic nodes... |
| 174 | def set : DagNode<DNRT_void, [DNAT_val, DNAT_arg0]>; |
| 175 | |
| 176 | // Terminals... |
| 177 | def imm : DagNode<DNRT_val, []>; |
| 178 | |
| 179 | // Arithmetic... |
| 180 | def plus : BuiltinDagNode<DNRT_arg0, [DNAT_val, DNAT_arg0], "Plus">; |
| 181 | def minus : BuiltinDagNode<DNRT_arg0, [DNAT_val, DNAT_arg0], "Minus">; |
| 182 | //def mult : DagNode<2, DNRT_arg0>; |
| 183 | //def div : DagNode<2, DNRT_arg0>; |
| 184 | //def udiv : DagNode<2, DNRT_arg0>; |
| 185 | //def mod : DagNode<2, DNRT_arg0>; |
| 186 | //def umod : DagNode<2, DNRT_arg0>; |
| 187 | |
| 188 | //def load : DagNode<1, DNRT_val>; |
| 189 | //def store : DagNode<2, DNRT_Void>; |
| 190 | |
| 191 | // Other... |
| 192 | def ret : BuiltinDagNode<DNRT_void, [DNAT_val], "Ret">; |
| 193 | def retvoid : BuiltinDagNode<DNRT_void, [], "RetVoid">; |
| 194 | |