Add support for local dynamic TLS model in LowerGlobalTLSAddress. Direct object
[oota-llvm.git] / lib / Target / Mips / MCTargetDesc / MipsBaseInfo.h
1 //===-- MipsBaseInfo.h - Top level definitions for ARM ------- --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains small standalone helper functions and enum definitions for
11 // the Mips target useful for the compiler back-end and the MC libraries.
12 //
13 //===----------------------------------------------------------------------===//
14 #ifndef MIPSBASEINFO_H
15 #define MIPSBASEINFO_H
16
17 #include "MipsMCTargetDesc.h"
18 #include "llvm/Support/DataTypes.h"
19 #include "llvm/Support/ErrorHandling.h"
20
21 namespace llvm {
22
23 /// MipsII - This namespace holds all of the target specific flags that
24 /// instruction info tracks.
25 ///
26 namespace MipsII {
27   /// Target Operand Flag enum.
28   enum TOF {
29     //===------------------------------------------------------------------===//
30     // Mips Specific MachineOperand flags.
31
32     MO_NO_FLAG,
33
34     /// MO_GOT16 - Represents the offset into the global offset table at which
35     /// the address the relocation entry symbol resides during execution.
36     MO_GOT16,
37     MO_GOT,
38
39     /// MO_GOT_CALL - Represents the offset into the global offset table at
40     /// which the address of a call site relocation entry symbol resides
41     /// during execution. This is different from the above since this flag
42     /// can only be present in call instructions.
43     MO_GOT_CALL,
44
45     /// MO_GPREL - Represents the offset from the current gp value to be used
46     /// for the relocatable object file being produced.
47     MO_GPREL,
48
49     /// MO_ABS_HI/LO - Represents the hi or low part of an absolute symbol
50     /// address.
51     MO_ABS_HI,
52     MO_ABS_LO,
53
54     /// MO_TLSGD - Represents the offset into the global offset table at which
55     // the module ID and TSL block offset reside during execution (General
56     // Dynamic TLS).
57     MO_TLSGD,
58
59     /// MO_TLSLDM - Represents the offset into the global offset table at which
60     // the module ID and TSL block offset reside during execution (Local
61     // Dynamic TLS).
62     MO_TLSLDM,
63     MO_DTPREL_HI,
64     MO_DTPREL_LO,
65
66     /// MO_GOTTPREL - Represents the offset from the thread pointer (Initial
67     // Exec TLS).
68     MO_GOTTPREL,
69
70     /// MO_TPREL_HI/LO - Represents the hi and low part of the offset from
71     // the thread pointer (Local Exec TLS).
72     MO_TPREL_HI,
73     MO_TPREL_LO,
74
75     // N32/64 Flags.
76     MO_GPOFF_HI,
77     MO_GPOFF_LO,
78     MO_GOT_DISP,
79     MO_GOT_PAGE,
80     MO_GOT_OFST
81   };
82
83   enum {
84     //===------------------------------------------------------------------===//
85     // Instruction encodings.  These are the standard/most common forms for
86     // Mips instructions.
87     //
88
89     // Pseudo - This represents an instruction that is a pseudo instruction
90     // or one that has not been implemented yet.  It is illegal to code generate
91     // it, but tolerated for intermediate implementation stages.
92     Pseudo   = 0,
93
94     /// FrmR - This form is for instructions of the format R.
95     FrmR  = 1,
96     /// FrmI - This form is for instructions of the format I.
97     FrmI  = 2,
98     /// FrmJ - This form is for instructions of the format J.
99     FrmJ  = 3,
100     /// FrmFR - This form is for instructions of the format FR.
101     FrmFR = 4,
102     /// FrmFI - This form is for instructions of the format FI.
103     FrmFI = 5,
104     /// FrmOther - This form is for instructions that have no specific format.
105     FrmOther = 6,
106
107     FormMask = 15
108   };
109 }
110
111
112 /// getMipsRegisterNumbering - Given the enum value for some register,
113 /// return the number that it corresponds to.
114 inline static unsigned getMipsRegisterNumbering(unsigned RegEnum)
115 {
116   switch (RegEnum) {
117   case Mips::ZERO: case Mips::ZERO_64: case Mips::F0: case Mips::D0_64:
118   case Mips::D0:
119     return 0;
120   case Mips::AT: case Mips::AT_64: case Mips::F1: case Mips::D1_64:
121     return 1;
122   case Mips::V0: case Mips::V0_64: case Mips::F2: case Mips::D2_64:
123   case Mips::D1:
124     return 2;
125   case Mips::V1: case Mips::V1_64: case Mips::F3: case Mips::D3_64:
126     return 3;
127   case Mips::A0: case Mips::A0_64: case Mips::F4: case Mips::D4_64:
128   case Mips::D2:
129     return 4;
130   case Mips::A1: case Mips::A1_64: case Mips::F5: case Mips::D5_64:
131     return 5;
132   case Mips::A2: case Mips::A2_64: case Mips::F6: case Mips::D6_64:
133   case Mips::D3:
134     return 6;
135   case Mips::A3: case Mips::A3_64: case Mips::F7: case Mips::D7_64:
136     return 7;
137   case Mips::T0: case Mips::T0_64: case Mips::F8: case Mips::D8_64:
138   case Mips::D4:
139     return 8;
140   case Mips::T1: case Mips::T1_64: case Mips::F9: case Mips::D9_64:
141     return 9;
142   case Mips::T2: case Mips::T2_64: case Mips::F10: case Mips::D10_64:
143   case Mips::D5:
144     return 10;
145   case Mips::T3: case Mips::T3_64: case Mips::F11: case Mips::D11_64:
146     return 11;
147   case Mips::T4: case Mips::T4_64: case Mips::F12: case Mips::D12_64:
148   case Mips::D6:
149     return 12;
150   case Mips::T5: case Mips::T5_64: case Mips::F13: case Mips::D13_64:
151     return 13;
152   case Mips::T6: case Mips::T6_64: case Mips::F14: case Mips::D14_64:
153   case Mips::D7:
154     return 14;
155   case Mips::T7: case Mips::T7_64: case Mips::F15: case Mips::D15_64:
156     return 15;
157   case Mips::S0: case Mips::S0_64: case Mips::F16: case Mips::D16_64:
158   case Mips::D8:
159     return 16;
160   case Mips::S1: case Mips::S1_64: case Mips::F17: case Mips::D17_64:
161     return 17;
162   case Mips::S2: case Mips::S2_64: case Mips::F18: case Mips::D18_64:
163   case Mips::D9:
164     return 18;
165   case Mips::S3: case Mips::S3_64: case Mips::F19: case Mips::D19_64:
166     return 19;
167   case Mips::S4: case Mips::S4_64: case Mips::F20: case Mips::D20_64:
168   case Mips::D10:
169     return 20;
170   case Mips::S5: case Mips::S5_64: case Mips::F21: case Mips::D21_64:
171     return 21;
172   case Mips::S6: case Mips::S6_64: case Mips::F22: case Mips::D22_64:
173   case Mips::D11:
174     return 22;
175   case Mips::S7: case Mips::S7_64: case Mips::F23: case Mips::D23_64:
176     return 23;
177   case Mips::T8: case Mips::T8_64: case Mips::F24: case Mips::D24_64:
178   case Mips::D12:
179     return 24;
180   case Mips::T9: case Mips::T9_64: case Mips::F25: case Mips::D25_64:
181     return 25;
182   case Mips::K0: case Mips::K0_64: case Mips::F26: case Mips::D26_64:
183   case Mips::D13:
184     return 26;
185   case Mips::K1: case Mips::K1_64: case Mips::F27: case Mips::D27_64:
186     return 27;
187   case Mips::GP: case Mips::GP_64: case Mips::F28: case Mips::D28_64:
188   case Mips::D14:
189     return 28;
190   case Mips::SP: case Mips::SP_64: case Mips::F29: case Mips::D29_64:
191   case Mips::HWR29:
192     return 29;
193   case Mips::FP: case Mips::FP_64: case Mips::F30: case Mips::D30_64:
194   case Mips::D15: 
195     return 30;
196   case Mips::RA: case Mips::RA_64: case Mips::F31: case Mips::D31_64:
197     return 31;
198   default: llvm_unreachable("Unknown register number!");
199   }
200   return 0; // Not reached
201 }
202 }
203
204 #endif