blob: d7f7d7c41babf51d6bfd0c72933ed69a30a45798 [file] [log] [blame]
Chris Lattneree6b5f62003-07-29 23:07:13 +00001//===- 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 Brukman01c16382003-05-29 18:48:17 +00006//===----------------------------------------------------------------------===//
7
Chris Lattner7c289522003-07-30 05:50:12 +00008
9//===----------------------------------------------------------------------===//
10//
Chris Lattnerb3aa3192003-07-28 04:24:59 +000011// Value types - These values correspond to the register types defined in the
Chris Lattner84c40c12003-07-29 23:02:49 +000012// ValueTypes.h file.
Chris Lattner0ad13612003-07-30 22:16:41 +000013//
Chris Lattnerde04dd72003-08-01 05:18:03 +000014class ValueType<int size> { string Namespace = "MVT"; int Size = size; }
Chris Lattner7c289522003-07-30 05:50:12 +000015
Chris Lattnerde04dd72003-08-01 05:18:03 +000016def i1 : ValueType<1>; // One bit boolean value
17def i8 : ValueType<8>; // 8-bit integer value
18def i16 : ValueType<16>; // 16-bit integer value
19def i32 : ValueType<32>; // 32-bit integer value
20def i64 : ValueType<64>; // 64-bit integer value
Chris Lattnerde04dd72003-08-01 05:18:03 +000021def f32 : ValueType<32>; // 32-bit floating point value
22def f64 : ValueType<64>; // 64-bit floating point value
23def f80 : ValueType<80>; // 80-bit floating point value
Chris Lattner7c289522003-07-30 05:50:12 +000024
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 Brukman01c16382003-05-29 18:48:17 +000033class Register {
34 string Namespace = "";
Chris Lattner76bf8682003-08-03 22:12:37 +000035 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//
41class NamedReg<string n> : Register {
Chris Lattner60e81db2003-08-04 04:58:12 +000042 let Name = n;
Misha Brukman01c16382003-05-29 18:48:17 +000043}
44
Chris Lattner7c289522003-07-30 05:50:12 +000045// 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//
50class 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//
60class RegisterClass<ValueType regType, int alignment, list<Register> regList> {
Chris Lattner0ad13612003-07-30 22:16:41 +000061 // 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 Lattner7c289522003-07-30 05:50:12 +000064 ValueType RegType = regType;
Chris Lattner0ad13612003-07-30 22:16:41 +000065
66 // Alignment - Specify the alignment required of the registers when they are
67 // stored or loaded to memory.
68 //
Chris Lattnerde04dd72003-08-01 05:18:03 +000069 int Size = RegType.Size;
Chris Lattner7c289522003-07-30 05:50:12 +000070 int Alignment = alignment;
Chris Lattner0ad13612003-07-30 22:16:41 +000071
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 Lattner7c289522003-07-30 05:50:12 +000076 list<Register> MemberList = regList;
Chris Lattner0ad13612003-07-30 22:16:41 +000077
Chris Lattnerbe84e3c2003-08-01 22:21:49 +000078 // 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 Lattner7c289522003-07-30 05:50:12 +000081}
82
83
84//===----------------------------------------------------------------------===//
Chris Lattnera5100d92003-08-03 18:18:31 +000085// Instruction set description - These classes correspond to the C++ classes in
86// the Target/TargetInstrInfo.h file.
Chris Lattner7c289522003-07-30 05:50:12 +000087//
88
Misha Brukman01c16382003-05-29 18:48:17 +000089class 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 Lattner84c40c12003-07-29 23:02:49 +000098 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 Lattner244883e2003-08-04 21:07:37 +0000103
104 // Pattern - Set to the DAG pattern for this instruction, if we know of one,
105 // otherwise, uninitialized.
106 dag Pattern;
Chris Lattnera5100d92003-08-03 18:18:31 +0000107}
108
Chris Lattner3e77d6e2003-08-06 15:31:02 +0000109class Expander<dag pattern, list<dag> result> {
110 dag Pattern = pattern;
111 list<dag> Result = result;
112}
113
114
Chris Lattnera5100d92003-08-03 18:18:31 +0000115// InstrInfo - This class should only be instantiated once to provide parameters
116// which are global to the the target machine.
117//
118class InstrInfo {
119 Instruction PHIInst;
Chris Lattner34a20682003-08-03 21:52:28 +0000120
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 Lattnera5100d92003-08-03 18:18:31 +0000127}
128
129
130//===----------------------------------------------------------------------===//
131// Target - This class contains the "global" target information
132//
133class 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 Brukman01c16382003-05-29 18:48:17 +0000144}
Chris Lattner244883e2003-08-04 21:07:37 +0000145
146
147//===----------------------------------------------------------------------===//
148// DAG node definitions used by the instruction selector...
149//
Chris Lattner3e77d6e2003-08-06 15:31:02 +0000150class DagNodeResultType;
151def DNRT_void : DagNodeResultType; // Tree node always returns void
152def DNRT_val : DagNodeResultType; // A non-void type
153def DNRT_arg0 : DagNodeResultType; // Tree node returns same type as Arg0
154
155class DagNodeArgType;
156def DNAT_val : DagNodeArgType; // Any value
157def DNAT_arg0 : DagNodeArgType; // Same as for arg #0
158def DNAT_ptr : DagNodeArgType; // Returns the target pointer type
159
160class 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.
168class BuiltinDagNode<DagNodeResultType Ret, list<DagNodeArgType> Args,
169 string Ename> : DagNode<Ret, Args> {
170 let EnumName = Ename;
171}
172
173// Magic nodes...
174def set : DagNode<DNRT_void, [DNAT_val, DNAT_arg0]>;
175
176// Terminals...
177def imm : DagNode<DNRT_val, []>;
178
179// Arithmetic...
180def plus : BuiltinDagNode<DNRT_arg0, [DNAT_val, DNAT_arg0], "Plus">;
181def 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...
192def ret : BuiltinDagNode<DNRT_void, [DNAT_val], "Ret">;
193def retvoid : BuiltinDagNode<DNRT_void, [], "RetVoid">;
194