blob: f7aedd02068fda09313e587893de17597c346822 [file] [log] [blame]
Jia Liu9d2d2ad2012-02-24 02:05:28 +00001//===-- MipsBaseInfo.h - Top level definitions for MIPS MC ------*- C++ -*-===//
Akira Hatanakad9ea7c82011-10-14 03:04:24 +00002//
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
Akira Hatanakaa06bc1c2012-03-27 02:04:18 +000017#include "MipsFixupKinds.h"
Akira Hatanakad9ea7c82011-10-14 03:04:24 +000018#include "MipsMCTargetDesc.h"
Akira Hatanakaa06bc1c2012-03-27 02:04:18 +000019#include "llvm/MC/MCExpr.h"
Akira Hatanakad9ea7c82011-10-14 03:04:24 +000020#include "llvm/Support/DataTypes.h"
21#include "llvm/Support/ErrorHandling.h"
22
23namespace llvm {
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +000024
25/// MipsII - This namespace holds all of the target specific flags that
26/// instruction info tracks.
27///
28namespace MipsII {
29 /// Target Operand Flag enum.
30 enum TOF {
31 //===------------------------------------------------------------------===//
32 // Mips Specific MachineOperand flags.
33
34 MO_NO_FLAG,
35
Bruno Cardoso Lopes61e6d982011-12-07 00:28:57 +000036 /// MO_GOT16 - Represents the offset into the global offset table at which
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +000037 /// the address the relocation entry symbol resides during execution.
Bruno Cardoso Lopes61e6d982011-12-07 00:28:57 +000038 MO_GOT16,
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +000039 MO_GOT,
40
41 /// MO_GOT_CALL - Represents the offset into the global offset table at
42 /// which the address of a call site relocation entry symbol resides
43 /// during execution. This is different from the above since this flag
44 /// can only be present in call instructions.
45 MO_GOT_CALL,
46
47 /// MO_GPREL - Represents the offset from the current gp value to be used
48 /// for the relocatable object file being produced.
49 MO_GPREL,
50
51 /// MO_ABS_HI/LO - Represents the hi or low part of an absolute symbol
52 /// address.
53 MO_ABS_HI,
54 MO_ABS_LO,
55
56 /// MO_TLSGD - Represents the offset into the global offset table at which
57 // the module ID and TSL block offset reside during execution (General
58 // Dynamic TLS).
59 MO_TLSGD,
60
Akira Hatanakabff84e12011-12-14 18:26:41 +000061 /// MO_TLSLDM - Represents the offset into the global offset table at which
62 // the module ID and TSL block offset reside during execution (Local
63 // Dynamic TLS).
64 MO_TLSLDM,
65 MO_DTPREL_HI,
66 MO_DTPREL_LO,
67
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +000068 /// MO_GOTTPREL - Represents the offset from the thread pointer (Initial
69 // Exec TLS).
70 MO_GOTTPREL,
71
72 /// MO_TPREL_HI/LO - Represents the hi and low part of the offset from
73 // the thread pointer (Local Exec TLS).
74 MO_TPREL_HI,
75 MO_TPREL_LO,
76
77 // N32/64 Flags.
78 MO_GPOFF_HI,
79 MO_GPOFF_LO,
80 MO_GOT_DISP,
81 MO_GOT_PAGE,
Akira Hatanaka6035fe72012-07-21 03:09:04 +000082 MO_GOT_OFST,
83
84 MO_HIGHER,
85 MO_HIGHEST
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +000086 };
87
88 enum {
89 //===------------------------------------------------------------------===//
90 // Instruction encodings. These are the standard/most common forms for
91 // Mips instructions.
92 //
93
94 // Pseudo - This represents an instruction that is a pseudo instruction
95 // or one that has not been implemented yet. It is illegal to code generate
96 // it, but tolerated for intermediate implementation stages.
97 Pseudo = 0,
98
99 /// FrmR - This form is for instructions of the format R.
100 FrmR = 1,
101 /// FrmI - This form is for instructions of the format I.
102 FrmI = 2,
103 /// FrmJ - This form is for instructions of the format J.
104 FrmJ = 3,
105 /// FrmFR - This form is for instructions of the format FR.
106 FrmFR = 4,
107 /// FrmFI - This form is for instructions of the format FI.
108 FrmFI = 5,
109 /// FrmOther - This form is for instructions that have no specific format.
110 FrmOther = 6,
111
112 FormMask = 15
113 };
114}
115
116
Akira Hatanakad9ea7c82011-10-14 03:04:24 +0000117/// getMipsRegisterNumbering - Given the enum value for some register,
118/// return the number that it corresponds to.
119inline static unsigned getMipsRegisterNumbering(unsigned RegEnum)
120{
121 switch (RegEnum) {
122 case Mips::ZERO: case Mips::ZERO_64: case Mips::F0: case Mips::D0_64:
123 case Mips::D0:
124 return 0;
125 case Mips::AT: case Mips::AT_64: case Mips::F1: case Mips::D1_64:
126 return 1;
127 case Mips::V0: case Mips::V0_64: case Mips::F2: case Mips::D2_64:
128 case Mips::D1:
129 return 2;
130 case Mips::V1: case Mips::V1_64: case Mips::F3: case Mips::D3_64:
131 return 3;
132 case Mips::A0: case Mips::A0_64: case Mips::F4: case Mips::D4_64:
133 case Mips::D2:
134 return 4;
135 case Mips::A1: case Mips::A1_64: case Mips::F5: case Mips::D5_64:
136 return 5;
137 case Mips::A2: case Mips::A2_64: case Mips::F6: case Mips::D6_64:
138 case Mips::D3:
139 return 6;
140 case Mips::A3: case Mips::A3_64: case Mips::F7: case Mips::D7_64:
141 return 7;
142 case Mips::T0: case Mips::T0_64: case Mips::F8: case Mips::D8_64:
143 case Mips::D4:
144 return 8;
145 case Mips::T1: case Mips::T1_64: case Mips::F9: case Mips::D9_64:
146 return 9;
147 case Mips::T2: case Mips::T2_64: case Mips::F10: case Mips::D10_64:
148 case Mips::D5:
149 return 10;
150 case Mips::T3: case Mips::T3_64: case Mips::F11: case Mips::D11_64:
151 return 11;
152 case Mips::T4: case Mips::T4_64: case Mips::F12: case Mips::D12_64:
153 case Mips::D6:
154 return 12;
155 case Mips::T5: case Mips::T5_64: case Mips::F13: case Mips::D13_64:
156 return 13;
157 case Mips::T6: case Mips::T6_64: case Mips::F14: case Mips::D14_64:
158 case Mips::D7:
159 return 14;
160 case Mips::T7: case Mips::T7_64: case Mips::F15: case Mips::D15_64:
161 return 15;
162 case Mips::S0: case Mips::S0_64: case Mips::F16: case Mips::D16_64:
163 case Mips::D8:
164 return 16;
165 case Mips::S1: case Mips::S1_64: case Mips::F17: case Mips::D17_64:
166 return 17;
167 case Mips::S2: case Mips::S2_64: case Mips::F18: case Mips::D18_64:
168 case Mips::D9:
169 return 18;
170 case Mips::S3: case Mips::S3_64: case Mips::F19: case Mips::D19_64:
171 return 19;
172 case Mips::S4: case Mips::S4_64: case Mips::F20: case Mips::D20_64:
173 case Mips::D10:
174 return 20;
175 case Mips::S5: case Mips::S5_64: case Mips::F21: case Mips::D21_64:
176 return 21;
177 case Mips::S6: case Mips::S6_64: case Mips::F22: case Mips::D22_64:
178 case Mips::D11:
179 return 22;
180 case Mips::S7: case Mips::S7_64: case Mips::F23: case Mips::D23_64:
181 return 23;
182 case Mips::T8: case Mips::T8_64: case Mips::F24: case Mips::D24_64:
183 case Mips::D12:
184 return 24;
185 case Mips::T9: case Mips::T9_64: case Mips::F25: case Mips::D25_64:
186 return 25;
187 case Mips::K0: case Mips::K0_64: case Mips::F26: case Mips::D26_64:
188 case Mips::D13:
189 return 26;
190 case Mips::K1: case Mips::K1_64: case Mips::F27: case Mips::D27_64:
191 return 27;
192 case Mips::GP: case Mips::GP_64: case Mips::F28: case Mips::D28_64:
193 case Mips::D14:
194 return 28;
195 case Mips::SP: case Mips::SP_64: case Mips::F29: case Mips::D29_64:
Bruno Cardoso Lopes1b1a1222011-12-06 03:34:36 +0000196 case Mips::HWR29:
Akira Hatanakad9ea7c82011-10-14 03:04:24 +0000197 return 29;
198 case Mips::FP: case Mips::FP_64: case Mips::F30: case Mips::D30_64:
Jia Liuf54f60f2012-02-28 07:46:26 +0000199 case Mips::D15:
Akira Hatanakad9ea7c82011-10-14 03:04:24 +0000200 return 30;
201 case Mips::RA: case Mips::RA_64: case Mips::F31: case Mips::D31_64:
202 return 31;
203 default: llvm_unreachable("Unknown register number!");
204 }
Akira Hatanakad9ea7c82011-10-14 03:04:24 +0000205}
Akira Hatanakaa06bc1c2012-03-27 02:04:18 +0000206
207inline static std::pair<const MCSymbolRefExpr*, int64_t>
208MipsGetSymAndOffset(const MCFixup &Fixup) {
209 MCFixupKind FixupKind = Fixup.getKind();
210
211 if ((FixupKind < FirstTargetFixupKind) ||
212 (FixupKind >= MCFixupKind(Mips::LastTargetFixupKind)))
213 return std::make_pair((const MCSymbolRefExpr*)0, (int64_t)0);
214
215 const MCExpr *Expr = Fixup.getValue();
216 MCExpr::ExprKind Kind = Expr->getKind();
217
218 if (Kind == MCExpr::Binary) {
219 const MCBinaryExpr *BE = static_cast<const MCBinaryExpr*>(Expr);
220 const MCExpr *LHS = BE->getLHS();
221 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(BE->getRHS());
222
223 if ((LHS->getKind() != MCExpr::SymbolRef) || !CE)
224 return std::make_pair((const MCSymbolRefExpr*)0, (int64_t)0);
225
226 return std::make_pair(cast<MCSymbolRefExpr>(LHS), CE->getValue());
227 }
228
229 if (Kind != MCExpr::SymbolRef)
230 return std::make_pair((const MCSymbolRefExpr*)0, (int64_t)0);
231
232 return std::make_pair(cast<MCSymbolRefExpr>(Expr), 0);
233}
Akira Hatanakad9ea7c82011-10-14 03:04:24 +0000234}
235
236#endif