blob: 34b4e3d6b3f84593adf32fa37b08d83d147b6ab3 [file] [log] [blame]
Jim Grosbach1287f4f2010-09-17 18:46:17 +00001//===-- ARM/ARMMCCodeEmitter.cpp - Convert ARM code to machine code -------===//
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 implements the ARMMCCodeEmitter class.
11//
12//===----------------------------------------------------------------------===//
13
Chris Lattner63274cb2010-11-15 05:19:05 +000014#define DEBUG_TYPE "mccodeemitter"
Evan Chenga20cde32011-07-20 23:34:39 +000015#include "MCTargetDesc/ARMAddressingModes.h"
Evan Chengad5f4852011-07-23 00:00:19 +000016#include "MCTargetDesc/ARMBaseInfo.h"
17#include "MCTargetDesc/ARMFixupKinds.h"
Evan Chenga20cde32011-07-20 23:34:39 +000018#include "MCTargetDesc/ARMMCExpr.h"
Evan Chengad5f4852011-07-23 00:00:19 +000019#include "MCTargetDesc/ARMMCTargetDesc.h"
Jim Grosbach1287f4f2010-09-17 18:46:17 +000020#include "llvm/MC/MCCodeEmitter.h"
21#include "llvm/MC/MCExpr.h"
22#include "llvm/MC/MCInst.h"
Evan Chengc5e6d2f2011-07-11 03:57:24 +000023#include "llvm/MC/MCInstrInfo.h"
Evan Chengad5f4852011-07-23 00:00:19 +000024#include "llvm/MC/MCRegisterInfo.h"
Evan Chengc5e6d2f2011-07-11 03:57:24 +000025#include "llvm/MC/MCSubtargetInfo.h"
Evan Chenga20cde32011-07-20 23:34:39 +000026#include "llvm/ADT/APFloat.h"
Jim Grosbach91029092010-10-07 22:12:50 +000027#include "llvm/ADT/Statistic.h"
Jim Grosbach1287f4f2010-09-17 18:46:17 +000028#include "llvm/Support/raw_ostream.h"
Evan Chengc5e6d2f2011-07-11 03:57:24 +000029
Jim Grosbach1287f4f2010-09-17 18:46:17 +000030using namespace llvm;
31
Jim Grosbach0fb841f2010-11-04 01:12:30 +000032STATISTIC(MCNumEmitted, "Number of MC instructions emitted.");
33STATISTIC(MCNumCPRelocations, "Number of constant pool relocations created.");
Jim Grosbach91029092010-10-07 22:12:50 +000034
Jim Grosbach1287f4f2010-09-17 18:46:17 +000035namespace {
36class ARMMCCodeEmitter : public MCCodeEmitter {
37 ARMMCCodeEmitter(const ARMMCCodeEmitter &); // DO NOT IMPLEMENT
38 void operator=(const ARMMCCodeEmitter &); // DO NOT IMPLEMENT
Evan Chengc5e6d2f2011-07-11 03:57:24 +000039 const MCInstrInfo &MCII;
40 const MCSubtargetInfo &STI;
Jim Grosbach1287f4f2010-09-17 18:46:17 +000041
42public:
Evan Chengc5e6d2f2011-07-11 03:57:24 +000043 ARMMCCodeEmitter(const MCInstrInfo &mcii, const MCSubtargetInfo &sti,
44 MCContext &ctx)
Evan Cheng58a98142011-07-11 21:24:15 +000045 : MCII(mcii), STI(sti) {
Jim Grosbach1287f4f2010-09-17 18:46:17 +000046 }
47
48 ~ARMMCCodeEmitter() {}
49
Evan Chengc5e6d2f2011-07-11 03:57:24 +000050 bool isThumb() const {
51 // FIXME: Can tablegen auto-generate this?
52 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
53 }
54 bool isThumb2() const {
55 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) != 0;
56 }
57 bool isTargetDarwin() const {
58 Triple TT(STI.getTargetTriple());
59 Triple::OSType OS = TT.getOS();
60 return OS == Triple::Darwin || OS == Triple::MacOSX || OS == Triple::IOS;
61 }
62
Jim Grosbach6fead932010-10-12 17:11:26 +000063 unsigned getMachineSoImmOpValue(unsigned SoImm) const;
64
Jim Grosbach8aed3862010-10-07 21:57:55 +000065 // getBinaryCodeForInstr - TableGen'erated function for getting the
66 // binary encoding for an instruction.
Jim Grosbach2eed7a12010-11-03 23:52:49 +000067 unsigned getBinaryCodeForInstr(const MCInst &MI,
68 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach8aed3862010-10-07 21:57:55 +000069
70 /// getMachineOpValue - Return binary encoding of operand. If the machine
71 /// operand requires relocation, record the relocation and return zero.
Jim Grosbach2eed7a12010-11-03 23:52:49 +000072 unsigned getMachineOpValue(const MCInst &MI,const MCOperand &MO,
73 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach8aed3862010-10-07 21:57:55 +000074
Evan Cheng965b3c72011-01-13 07:58:56 +000075 /// getHiLo16ImmOpValue - Return the encoding for the hi / low 16-bit of
Owen Anderson4ebf4712011-02-08 22:39:40 +000076 /// the specified operand. This is used for operands with :lower16: and
Evan Cheng965b3c72011-01-13 07:58:56 +000077 /// :upper16: prefixes.
78 uint32_t getHiLo16ImmOpValue(const MCInst &MI, unsigned OpIdx,
79 SmallVectorImpl<MCFixup> &Fixups) const;
Jason W Kim5a97bd82010-11-18 23:37:15 +000080
Bill Wendlinge84eb992010-11-03 01:49:29 +000081 bool EncodeAddrModeOpValues(const MCInst &MI, unsigned OpIdx,
Jim Grosbach2eed7a12010-11-03 23:52:49 +000082 unsigned &Reg, unsigned &Imm,
83 SmallVectorImpl<MCFixup> &Fixups) const;
Bill Wendlinge84eb992010-11-03 01:49:29 +000084
Jim Grosbach9e199462010-12-06 23:57:07 +000085 /// getThumbBLTargetOpValue - Return encoding info for Thumb immediate
Bill Wendling3392bfc2010-12-09 00:39:08 +000086 /// BL branch target.
Jim Grosbach9e199462010-12-06 23:57:07 +000087 uint32_t getThumbBLTargetOpValue(const MCInst &MI, unsigned OpIdx,
88 SmallVectorImpl<MCFixup> &Fixups) const;
89
Bill Wendling3392bfc2010-12-09 00:39:08 +000090 /// getThumbBLXTargetOpValue - Return encoding info for Thumb immediate
91 /// BLX branch target.
92 uint32_t getThumbBLXTargetOpValue(const MCInst &MI, unsigned OpIdx,
93 SmallVectorImpl<MCFixup> &Fixups) const;
94
Jim Grosbache119da12010-12-10 18:21:33 +000095 /// getThumbBRTargetOpValue - Return encoding info for Thumb branch target.
96 uint32_t getThumbBRTargetOpValue(const MCInst &MI, unsigned OpIdx,
97 SmallVectorImpl<MCFixup> &Fixups) const;
98
Jim Grosbach78485ad2010-12-10 17:13:40 +000099 /// getThumbBCCTargetOpValue - Return encoding info for Thumb branch target.
100 uint32_t getThumbBCCTargetOpValue(const MCInst &MI, unsigned OpIdx,
101 SmallVectorImpl<MCFixup> &Fixups) const;
102
Jim Grosbach62b68112010-12-09 19:04:53 +0000103 /// getThumbCBTargetOpValue - Return encoding info for Thumb branch target.
104 uint32_t getThumbCBTargetOpValue(const MCInst &MI, unsigned OpIdx,
Bill Wendlinga7d6aa92010-12-08 23:01:43 +0000105 SmallVectorImpl<MCFixup> &Fixups) const;
106
Jim Grosbach9d6d77a2010-11-11 18:04:49 +0000107 /// getBranchTargetOpValue - Return encoding info for 24-bit immediate
108 /// branch target.
109 uint32_t getBranchTargetOpValue(const MCInst &MI, unsigned OpIdx,
110 SmallVectorImpl<MCFixup> &Fixups) const;
111
Owen Anderson578074b2010-12-13 19:31:11 +0000112 /// getUnconditionalBranchTargetOpValue - Return encoding info for 24-bit
113 /// immediate Thumb2 direct branch target.
114 uint32_t getUnconditionalBranchTargetOpValue(const MCInst &MI, unsigned OpIdx,
115 SmallVectorImpl<MCFixup> &Fixups) const;
Owen Anderson1732c2e2011-08-30 21:58:18 +0000116
Jason W Kimd2e2f562011-02-04 19:47:15 +0000117 /// getARMBranchTargetOpValue - Return encoding info for 24-bit immediate
118 /// branch target.
119 uint32_t getARMBranchTargetOpValue(const MCInst &MI, unsigned OpIdx,
120 SmallVectorImpl<MCFixup> &Fixups) const;
Owen Andersonb205c022011-08-26 23:32:08 +0000121 uint32_t getARMBLXTargetOpValue(const MCInst &MI, unsigned OpIdx,
122 SmallVectorImpl<MCFixup> &Fixups) const;
Owen Anderson578074b2010-12-13 19:31:11 +0000123
Jim Grosbachdc35e062010-12-01 19:47:31 +0000124 /// getAdrLabelOpValue - Return encoding info for 12-bit immediate
125 /// ADR label target.
126 uint32_t getAdrLabelOpValue(const MCInst &MI, unsigned OpIdx,
127 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach509dc2a2010-12-14 22:28:03 +0000128 uint32_t getThumbAdrLabelOpValue(const MCInst &MI, unsigned OpIdx,
129 SmallVectorImpl<MCFixup> &Fixups) const;
Owen Anderson6d375e52010-12-14 00:36:49 +0000130 uint32_t getT2AdrLabelOpValue(const MCInst &MI, unsigned OpIdx,
131 SmallVectorImpl<MCFixup> &Fixups) const;
Owen Anderson4ebf4712011-02-08 22:39:40 +0000132
Jim Grosbachdc35e062010-12-01 19:47:31 +0000133
Bill Wendlinge84eb992010-11-03 01:49:29 +0000134 /// getAddrModeImm12OpValue - Return encoding info for 'reg +/- imm12'
135 /// operand.
Jim Grosbach2eed7a12010-11-03 23:52:49 +0000136 uint32_t getAddrModeImm12OpValue(const MCInst &MI, unsigned OpIdx,
137 SmallVectorImpl<MCFixup> &Fixups) const;
Bill Wendlinge84eb992010-11-03 01:49:29 +0000138
Bill Wendling092a7bd2010-12-14 03:36:38 +0000139 /// getThumbAddrModeRegRegOpValue - Return encoding for 'reg + reg' operand.
140 uint32_t getThumbAddrModeRegRegOpValue(const MCInst &MI, unsigned OpIdx,
141 SmallVectorImpl<MCFixup> &Fixups)const;
Owen Andersonb0fa1272010-12-10 22:11:13 +0000142
Owen Anderson943fb602010-12-01 19:18:46 +0000143 /// getT2AddrModeImm8s4OpValue - Return encoding info for 'reg +/- imm8<<2'
144 /// operand.
145 uint32_t getT2AddrModeImm8s4OpValue(const MCInst &MI, unsigned OpIdx,
146 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000147 /// getT2Imm8s4OpValue - Return encoding info for '+/- imm8<<2'
148 /// operand.
149 uint32_t getT2Imm8s4OpValue(const MCInst &MI, unsigned OpIdx,
150 SmallVectorImpl<MCFixup> &Fixups) const;
Owen Anderson943fb602010-12-01 19:18:46 +0000151
152
Jim Grosbachdbfb5ed2010-11-09 17:20:53 +0000153 /// getLdStSORegOpValue - Return encoding info for 'reg +/- reg shop imm'
154 /// operand as needed by load/store instructions.
155 uint32_t getLdStSORegOpValue(const MCInst &MI, unsigned OpIdx,
156 SmallVectorImpl<MCFixup> &Fixups) const;
157
Jim Grosbachcc4a4912010-11-10 23:38:36 +0000158 /// getLdStmModeOpValue - Return encoding for load/store multiple mode.
159 uint32_t getLdStmModeOpValue(const MCInst &MI, unsigned OpIdx,
160 SmallVectorImpl<MCFixup> &Fixups) const {
161 ARM_AM::AMSubMode Mode = (ARM_AM::AMSubMode)MI.getOperand(OpIdx).getImm();
162 switch (Mode) {
Matt Beaumont-Gay3077bb62011-01-12 18:02:55 +0000163 default: assert(0 && "Unknown addressing sub-mode!");
Jim Grosbachcc4a4912010-11-10 23:38:36 +0000164 case ARM_AM::da: return 0;
165 case ARM_AM::ia: return 1;
166 case ARM_AM::db: return 2;
167 case ARM_AM::ib: return 3;
168 }
169 }
Jim Grosbach38b469e2010-11-15 20:47:07 +0000170 /// getShiftOp - Return the shift opcode (bit[6:5]) of the immediate value.
171 ///
172 unsigned getShiftOp(ARM_AM::ShiftOpc ShOpc) const {
173 switch (ShOpc) {
174 default: llvm_unreachable("Unknown shift opc!");
175 case ARM_AM::no_shift:
176 case ARM_AM::lsl: return 0;
177 case ARM_AM::lsr: return 1;
178 case ARM_AM::asr: return 2;
179 case ARM_AM::ror:
180 case ARM_AM::rrx: return 3;
181 }
182 return 0;
183 }
184
185 /// getAddrMode2OpValue - Return encoding for addrmode2 operands.
186 uint32_t getAddrMode2OpValue(const MCInst &MI, unsigned OpIdx,
187 SmallVectorImpl<MCFixup> &Fixups) const;
188
189 /// getAddrMode2OffsetOpValue - Return encoding for am2offset operands.
190 uint32_t getAddrMode2OffsetOpValue(const MCInst &MI, unsigned OpIdx,
191 SmallVectorImpl<MCFixup> &Fixups) const;
192
Jim Grosbachd3595712011-08-03 23:50:40 +0000193 /// getPostIdxRegOpValue - Return encoding for postidx_reg operands.
194 uint32_t getPostIdxRegOpValue(const MCInst &MI, unsigned OpIdx,
195 SmallVectorImpl<MCFixup> &Fixups) const;
196
Jim Grosbach68685e62010-11-11 16:55:29 +0000197 /// getAddrMode3OffsetOpValue - Return encoding for am3offset operands.
198 uint32_t getAddrMode3OffsetOpValue(const MCInst &MI, unsigned OpIdx,
199 SmallVectorImpl<MCFixup> &Fixups) const;
200
Jim Grosbach607efcb2010-11-11 01:09:40 +0000201 /// getAddrMode3OpValue - Return encoding for addrmode3 operands.
202 uint32_t getAddrMode3OpValue(const MCInst &MI, unsigned OpIdx,
203 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbachcc4a4912010-11-10 23:38:36 +0000204
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000205 /// getAddrModeThumbSPOpValue - Return encoding info for 'reg +/- imm12'
206 /// operand.
207 uint32_t getAddrModeThumbSPOpValue(const MCInst &MI, unsigned OpIdx,
208 SmallVectorImpl<MCFixup> &Fixups) const;
209
Bill Wendling092a7bd2010-12-14 03:36:38 +0000210 /// getAddrModeISOpValue - Encode the t_addrmode_is# operands.
211 uint32_t getAddrModeISOpValue(const MCInst &MI, unsigned OpIdx,
Bill Wendling03e75762010-12-15 08:51:02 +0000212 SmallVectorImpl<MCFixup> &Fixups) const;
Bill Wendlinga9e3df72010-11-30 22:57:21 +0000213
Bill Wendling8a6449c2010-12-08 01:57:09 +0000214 /// getAddrModePCOpValue - Return encoding for t_addrmode_pc operands.
215 uint32_t getAddrModePCOpValue(const MCInst &MI, unsigned OpIdx,
216 SmallVectorImpl<MCFixup> &Fixups) const;
217
Bill Wendlinge84eb992010-11-03 01:49:29 +0000218 /// getAddrMode5OpValue - Return encoding info for 'reg +/- imm8' operand.
Jim Grosbach2eed7a12010-11-03 23:52:49 +0000219 uint32_t getAddrMode5OpValue(const MCInst &MI, unsigned OpIdx,
220 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000221
Jim Grosbachd9d31da2010-10-12 23:00:24 +0000222 /// getCCOutOpValue - Return encoding of the 's' bit.
Jim Grosbach2eed7a12010-11-03 23:52:49 +0000223 unsigned getCCOutOpValue(const MCInst &MI, unsigned Op,
224 SmallVectorImpl<MCFixup> &Fixups) const {
Jim Grosbachd9d31da2010-10-12 23:00:24 +0000225 // The operand is either reg0 or CPSR. The 's' bit is encoded as '0' or
226 // '1' respectively.
227 return MI.getOperand(Op).getReg() == ARM::CPSR;
228 }
Jim Grosbachefd53692010-10-12 23:53:58 +0000229
Jim Grosbach12e493a2010-10-12 23:18:08 +0000230 /// getSOImmOpValue - Return an encoded 12-bit shifted-immediate value.
Jim Grosbach2eed7a12010-11-03 23:52:49 +0000231 unsigned getSOImmOpValue(const MCInst &MI, unsigned Op,
232 SmallVectorImpl<MCFixup> &Fixups) const {
Jim Grosbach12e493a2010-10-12 23:18:08 +0000233 unsigned SoImm = MI.getOperand(Op).getImm();
234 int SoImmVal = ARM_AM::getSOImmVal(SoImm);
235 assert(SoImmVal != -1 && "Not a valid so_imm value!");
236
237 // Encode rotate_imm.
238 unsigned Binary = (ARM_AM::getSOImmValRot((unsigned)SoImmVal) >> 1)
239 << ARMII::SoRotImmShift;
240
241 // Encode immed_8.
242 Binary |= ARM_AM::getSOImmValImm((unsigned)SoImmVal);
243 return Binary;
244 }
Jim Grosbachc4a0c292010-12-10 21:57:34 +0000245
Owen Anderson8fdd1722010-11-12 21:12:40 +0000246 /// getT2SOImmOpValue - Return an encoded 12-bit shifted-immediate value.
247 unsigned getT2SOImmOpValue(const MCInst &MI, unsigned Op,
248 SmallVectorImpl<MCFixup> &Fixups) const {
249 unsigned SoImm = MI.getOperand(Op).getImm();
250 unsigned Encoded = ARM_AM::getT2SOImmVal(SoImm);
251 assert(Encoded != ~0U && "Not a Thumb2 so_imm value?");
252 return Encoded;
253 }
Jim Grosbachd9d31da2010-10-12 23:00:24 +0000254
Owen Anderson50d662b2010-11-29 22:44:32 +0000255 unsigned getT2AddrModeSORegOpValue(const MCInst &MI, unsigned OpNum,
256 SmallVectorImpl<MCFixup> &Fixups) const;
257 unsigned getT2AddrModeImm8OpValue(const MCInst &MI, unsigned OpNum,
258 SmallVectorImpl<MCFixup> &Fixups) const;
Owen Andersone22c7322010-11-30 00:14:31 +0000259 unsigned getT2AddrModeImm8OffsetOpValue(const MCInst &MI, unsigned OpNum,
260 SmallVectorImpl<MCFixup> &Fixups) const;
Owen Anderson299382e2010-11-30 19:19:31 +0000261 unsigned getT2AddrModeImm12OffsetOpValue(const MCInst &MI, unsigned OpNum,
262 SmallVectorImpl<MCFixup> &Fixups) const;
Owen Anderson50d662b2010-11-29 22:44:32 +0000263
Jim Grosbachefd53692010-10-12 23:53:58 +0000264 /// getSORegOpValue - Return an encoded so_reg shifted register value.
Owen Anderson04912702011-07-21 23:38:37 +0000265 unsigned getSORegRegOpValue(const MCInst &MI, unsigned Op,
266 SmallVectorImpl<MCFixup> &Fixups) const;
267 unsigned getSORegImmOpValue(const MCInst &MI, unsigned Op,
Jim Grosbach2eed7a12010-11-03 23:52:49 +0000268 SmallVectorImpl<MCFixup> &Fixups) const;
Owen Anderson8fdd1722010-11-12 21:12:40 +0000269 unsigned getT2SORegOpValue(const MCInst &MI, unsigned Op,
270 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbachefd53692010-10-12 23:53:58 +0000271
Jim Grosbach2eed7a12010-11-03 23:52:49 +0000272 unsigned getNEONVcvtImm32OpValue(const MCInst &MI, unsigned Op,
273 SmallVectorImpl<MCFixup> &Fixups) const {
Owen Andersonfadb9512010-10-27 22:49:00 +0000274 return 64 - MI.getOperand(Op).getImm();
275 }
Jim Grosbach68a335e2010-10-15 17:15:16 +0000276
Jim Grosbach2eed7a12010-11-03 23:52:49 +0000277 unsigned getBitfieldInvertedMaskOpValue(const MCInst &MI, unsigned Op,
278 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach5edb03e2010-10-21 22:03:21 +0000279
Bruno Cardoso Lopes7f639c12011-01-18 20:45:56 +0000280 unsigned getMsbOpValue(const MCInst &MI, unsigned Op,
281 SmallVectorImpl<MCFixup> &Fixups) const;
282
Jim Grosbach2eed7a12010-11-03 23:52:49 +0000283 unsigned getRegisterListOpValue(const MCInst &MI, unsigned Op,
284 SmallVectorImpl<MCFixup> &Fixups) const;
285 unsigned getAddrMode6AddressOpValue(const MCInst &MI, unsigned Op,
286 SmallVectorImpl<MCFixup> &Fixups) const;
Mon P Wang92ff16b2011-05-09 17:47:27 +0000287 unsigned getAddrMode6OneLane32AddressOpValue(const MCInst &MI, unsigned Op,
288 SmallVectorImpl<MCFixup> &Fixups) const;
Bob Wilson318ce7c2010-11-30 00:00:42 +0000289 unsigned getAddrMode6DupAddressOpValue(const MCInst &MI, unsigned Op,
290 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach2eed7a12010-11-03 23:52:49 +0000291 unsigned getAddrMode6OffsetOpValue(const MCInst &MI, unsigned Op,
292 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach74ef9e12010-10-30 00:37:59 +0000293
Bill Wendling77ad1dc2011-03-07 23:38:41 +0000294 unsigned getShiftRight8Imm(const MCInst &MI, unsigned Op,
295 SmallVectorImpl<MCFixup> &Fixups) const;
296 unsigned getShiftRight16Imm(const MCInst &MI, unsigned Op,
297 SmallVectorImpl<MCFixup> &Fixups) const;
298 unsigned getShiftRight32Imm(const MCInst &MI, unsigned Op,
299 SmallVectorImpl<MCFixup> &Fixups) const;
300 unsigned getShiftRight64Imm(const MCInst &MI, unsigned Op,
301 SmallVectorImpl<MCFixup> &Fixups) const;
Bill Wendling3b1459b2011-03-01 01:00:59 +0000302
Owen Andersonc4030382011-08-08 20:42:17 +0000303 unsigned getThumbSRImmOpValue(const MCInst &MI, unsigned Op,
304 SmallVectorImpl<MCFixup> &Fixups) const;
305
Owen Anderson7ffe3b32010-11-11 19:07:48 +0000306 unsigned NEONThumb2DataIPostEncoder(const MCInst &MI,
307 unsigned EncodedValue) const;
Owen Anderson99a8cb42010-11-11 21:36:43 +0000308 unsigned NEONThumb2LoadStorePostEncoder(const MCInst &MI,
Bill Wendling87240d42010-12-01 21:54:50 +0000309 unsigned EncodedValue) const;
Owen Andersonce2250f2010-11-11 23:12:55 +0000310 unsigned NEONThumb2DupPostEncoder(const MCInst &MI,
Bill Wendling87240d42010-12-01 21:54:50 +0000311 unsigned EncodedValue) const;
312
313 unsigned VFPThumb2PostEncoder(const MCInst &MI,
314 unsigned EncodedValue) const;
Owen Anderson7ffe3b32010-11-11 19:07:48 +0000315
Jim Grosbach0fb841f2010-11-04 01:12:30 +0000316 void EmitByte(unsigned char C, raw_ostream &OS) const {
Jim Grosbach1287f4f2010-09-17 18:46:17 +0000317 OS << (char)C;
Jim Grosbach1287f4f2010-09-17 18:46:17 +0000318 }
319
Jim Grosbach0fb841f2010-11-04 01:12:30 +0000320 void EmitConstant(uint64_t Val, unsigned Size, raw_ostream &OS) const {
Jim Grosbach1287f4f2010-09-17 18:46:17 +0000321 // Output the constant in little endian byte order.
322 for (unsigned i = 0; i != Size; ++i) {
Jim Grosbach0fb841f2010-11-04 01:12:30 +0000323 EmitByte(Val & 255, OS);
Jim Grosbach1287f4f2010-09-17 18:46:17 +0000324 Val >>= 8;
325 }
326 }
327
Jim Grosbach1287f4f2010-09-17 18:46:17 +0000328 void EncodeInstruction(const MCInst &MI, raw_ostream &OS,
329 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach1287f4f2010-09-17 18:46:17 +0000330};
331
332} // end anonymous namespace
333
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000334MCCodeEmitter *llvm::createARMMCCodeEmitter(const MCInstrInfo &MCII,
335 const MCSubtargetInfo &STI,
Bill Wendlingf9eebb52010-11-02 22:53:11 +0000336 MCContext &Ctx) {
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000337 return new ARMMCCodeEmitter(MCII, STI, Ctx);
Jim Grosbach1287f4f2010-09-17 18:46:17 +0000338}
339
Jim Grosbachc4a0c292010-12-10 21:57:34 +0000340/// NEONThumb2DataIPostEncoder - Post-process encoded NEON data-processing
341/// instructions, and rewrite them to their Thumb2 form if we are currently in
Owen Anderson7ffe3b32010-11-11 19:07:48 +0000342/// Thumb2 mode.
343unsigned ARMMCCodeEmitter::NEONThumb2DataIPostEncoder(const MCInst &MI,
344 unsigned EncodedValue) const {
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000345 if (isThumb2()) {
Jim Grosbachc4a0c292010-12-10 21:57:34 +0000346 // NEON Thumb2 data-processsing encodings are very simple: bit 24 is moved
Owen Anderson7ffe3b32010-11-11 19:07:48 +0000347 // to bit 12 of the high half-word (i.e. bit 28), and bits 27-24 are
348 // set to 1111.
349 unsigned Bit24 = EncodedValue & 0x01000000;
350 unsigned Bit28 = Bit24 << 4;
351 EncodedValue &= 0xEFFFFFFF;
352 EncodedValue |= Bit28;
353 EncodedValue |= 0x0F000000;
354 }
Jim Grosbachc4a0c292010-12-10 21:57:34 +0000355
Owen Anderson7ffe3b32010-11-11 19:07:48 +0000356 return EncodedValue;
357}
358
Owen Anderson99a8cb42010-11-11 21:36:43 +0000359/// NEONThumb2LoadStorePostEncoder - Post-process encoded NEON load/store
Jim Grosbachc4a0c292010-12-10 21:57:34 +0000360/// instructions, and rewrite them to their Thumb2 form if we are currently in
Owen Anderson99a8cb42010-11-11 21:36:43 +0000361/// Thumb2 mode.
362unsigned ARMMCCodeEmitter::NEONThumb2LoadStorePostEncoder(const MCInst &MI,
363 unsigned EncodedValue) const {
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000364 if (isThumb2()) {
Owen Anderson99a8cb42010-11-11 21:36:43 +0000365 EncodedValue &= 0xF0FFFFFF;
366 EncodedValue |= 0x09000000;
367 }
Jim Grosbachc4a0c292010-12-10 21:57:34 +0000368
Owen Anderson99a8cb42010-11-11 21:36:43 +0000369 return EncodedValue;
370}
371
Owen Andersonce2250f2010-11-11 23:12:55 +0000372/// NEONThumb2DupPostEncoder - Post-process encoded NEON vdup
Jim Grosbachc4a0c292010-12-10 21:57:34 +0000373/// instructions, and rewrite them to their Thumb2 form if we are currently in
Owen Andersonce2250f2010-11-11 23:12:55 +0000374/// Thumb2 mode.
375unsigned ARMMCCodeEmitter::NEONThumb2DupPostEncoder(const MCInst &MI,
376 unsigned EncodedValue) const {
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000377 if (isThumb2()) {
Owen Andersonce2250f2010-11-11 23:12:55 +0000378 EncodedValue &= 0x00FFFFFF;
379 EncodedValue |= 0xEE000000;
380 }
Jim Grosbachc4a0c292010-12-10 21:57:34 +0000381
Owen Andersonce2250f2010-11-11 23:12:55 +0000382 return EncodedValue;
383}
384
Bill Wendling87240d42010-12-01 21:54:50 +0000385/// VFPThumb2PostEncoder - Post-process encoded VFP instructions and rewrite
386/// them to their Thumb2 form if we are currently in Thumb2 mode.
387unsigned ARMMCCodeEmitter::
388VFPThumb2PostEncoder(const MCInst &MI, unsigned EncodedValue) const {
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000389 if (isThumb2()) {
Bill Wendling87240d42010-12-01 21:54:50 +0000390 EncodedValue &= 0x0FFFFFFF;
391 EncodedValue |= 0xE0000000;
392 }
393 return EncodedValue;
394}
Owen Anderson99a8cb42010-11-11 21:36:43 +0000395
Jim Grosbachc43c9302010-10-08 21:45:55 +0000396/// getMachineOpValue - Return binary encoding of operand. If the machine
397/// operand requires relocation, record the relocation and return zero.
Jim Grosbach2eed7a12010-11-03 23:52:49 +0000398unsigned ARMMCCodeEmitter::
399getMachineOpValue(const MCInst &MI, const MCOperand &MO,
400 SmallVectorImpl<MCFixup> &Fixups) const {
Bill Wendling6f52f8a2010-10-14 02:33:26 +0000401 if (MO.isReg()) {
Bill Wendlingf9eebb52010-11-02 22:53:11 +0000402 unsigned Reg = MO.getReg();
403 unsigned RegNo = getARMRegisterNumbering(Reg);
Jim Grosbach96d82842010-10-29 23:21:03 +0000404
Jim Grosbachee48d2d2010-11-30 23:51:41 +0000405 // Q registers are encoded as 2x their register number.
Bill Wendlingf9eebb52010-11-02 22:53:11 +0000406 switch (Reg) {
407 default:
408 return RegNo;
409 case ARM::Q0: case ARM::Q1: case ARM::Q2: case ARM::Q3:
410 case ARM::Q4: case ARM::Q5: case ARM::Q6: case ARM::Q7:
411 case ARM::Q8: case ARM::Q9: case ARM::Q10: case ARM::Q11:
412 case ARM::Q12: case ARM::Q13: case ARM::Q14: case ARM::Q15:
413 return 2 * RegNo;
Owen Anderson2bfa8ed2010-10-21 20:49:13 +0000414 }
Bill Wendling6f52f8a2010-10-14 02:33:26 +0000415 } else if (MO.isImm()) {
Jim Grosbachc43c9302010-10-08 21:45:55 +0000416 return static_cast<unsigned>(MO.getImm());
Bill Wendling6f52f8a2010-10-14 02:33:26 +0000417 } else if (MO.isFPImm()) {
418 return static_cast<unsigned>(APFloat(MO.getFPImm())
419 .bitcastToAPInt().getHiBits(32).getLimitedValue());
Jim Grosbachc43c9302010-10-08 21:45:55 +0000420 }
Bill Wendlingf9eebb52010-11-02 22:53:11 +0000421
Jim Grosbach2aeb8b92010-11-19 00:27:09 +0000422 llvm_unreachable("Unable to encode MCOperand!");
Jim Grosbachc43c9302010-10-08 21:45:55 +0000423 return 0;
424}
425
Bill Wendling603bd8f2010-11-02 22:31:46 +0000426/// getAddrModeImmOpValue - Return encoding info for 'reg +/- imm' operand.
Jim Grosbach2eed7a12010-11-03 23:52:49 +0000427bool ARMMCCodeEmitter::
428EncodeAddrModeOpValues(const MCInst &MI, unsigned OpIdx, unsigned &Reg,
429 unsigned &Imm, SmallVectorImpl<MCFixup> &Fixups) const {
Jim Grosbach1e4d9a12010-10-26 22:37:02 +0000430 const MCOperand &MO = MI.getOperand(OpIdx);
431 const MCOperand &MO1 = MI.getOperand(OpIdx + 1);
Jim Grosbach2ba03aa2010-11-01 23:45:50 +0000432
Bill Wendlinge84eb992010-11-03 01:49:29 +0000433 Reg = getARMRegisterNumbering(MO.getReg());
434
435 int32_t SImm = MO1.getImm();
436 bool isAdd = true;
Bill Wendling603bd8f2010-11-02 22:31:46 +0000437
Jim Grosbach505607e2010-10-28 18:34:10 +0000438 // Special value for #-0
Owen Anderson967674d2011-08-29 19:36:44 +0000439 if (SImm == INT32_MIN) {
Bill Wendlinge84eb992010-11-03 01:49:29 +0000440 SImm = 0;
Owen Anderson967674d2011-08-29 19:36:44 +0000441 isAdd = false;
442 }
Bill Wendling603bd8f2010-11-02 22:31:46 +0000443
Jim Grosbach505607e2010-10-28 18:34:10 +0000444 // Immediate is always encoded as positive. The 'U' bit controls add vs sub.
Bill Wendlinge84eb992010-11-03 01:49:29 +0000445 if (SImm < 0) {
446 SImm = -SImm;
447 isAdd = false;
448 }
Bill Wendling603bd8f2010-11-02 22:31:46 +0000449
Bill Wendlinge84eb992010-11-03 01:49:29 +0000450 Imm = SImm;
451 return isAdd;
452}
453
Bill Wendlinga7d6aa92010-12-08 23:01:43 +0000454/// getBranchTargetOpValue - Helper function to get the branch target operand,
455/// which is either an immediate or requires a fixup.
456static uint32_t getBranchTargetOpValue(const MCInst &MI, unsigned OpIdx,
457 unsigned FixupKind,
458 SmallVectorImpl<MCFixup> &Fixups) {
459 const MCOperand &MO = MI.getOperand(OpIdx);
460
461 // If the destination is an immediate, we have nothing to do.
462 if (MO.isImm()) return MO.getImm();
463 assert(MO.isExpr() && "Unexpected branch target type!");
464 const MCExpr *Expr = MO.getExpr();
465 MCFixupKind Kind = MCFixupKind(FixupKind);
466 Fixups.push_back(MCFixup::Create(0, Expr, Kind));
467
468 // All of the information is in the fixup.
469 return 0;
470}
471
Owen Anderson5c160fd2011-08-31 18:30:20 +0000472// Thumb BL and BLX use a strange offset encoding where bits 22 and 21 are
473// determined by negating them and XOR'ing them with bit 23.
474static int32_t encodeThumbBLOffset(int32_t offset) {
475 offset >>= 1;
476 uint32_t S = (offset & 0x800000) >> 23;
477 uint32_t J1 = (offset & 0x400000) >> 22;
478 uint32_t J2 = (offset & 0x200000) >> 21;
479 J1 = (~J1 & 0x1);
480 J2 = (~J2 & 0x1);
481 J1 ^= S;
482 J2 ^= S;
483
484 offset &= ~0x600000;
485 offset |= J1 << 22;
486 offset |= J2 << 21;
487
488 return offset;
489}
490
Bill Wendlinga7d6aa92010-12-08 23:01:43 +0000491/// getThumbBLTargetOpValue - Return encoding info for immediate branch target.
Jim Grosbach9e199462010-12-06 23:57:07 +0000492uint32_t ARMMCCodeEmitter::
493getThumbBLTargetOpValue(const MCInst &MI, unsigned OpIdx,
494 SmallVectorImpl<MCFixup> &Fixups) const {
Owen Anderson5c160fd2011-08-31 18:30:20 +0000495 const MCOperand MO = MI.getOperand(OpIdx);
496 if (MO.isExpr())
497 return ::getBranchTargetOpValue(MI, OpIdx, ARM::fixup_arm_thumb_bl,
498 Fixups);
499 return encodeThumbBLOffset(MO.getImm());
Jim Grosbach9e199462010-12-06 23:57:07 +0000500}
501
Bill Wendling3392bfc2010-12-09 00:39:08 +0000502/// getThumbBLXTargetOpValue - Return encoding info for Thumb immediate
503/// BLX branch target.
504uint32_t ARMMCCodeEmitter::
505getThumbBLXTargetOpValue(const MCInst &MI, unsigned OpIdx,
506 SmallVectorImpl<MCFixup> &Fixups) const {
Owen Anderson5c160fd2011-08-31 18:30:20 +0000507 const MCOperand MO = MI.getOperand(OpIdx);
508 if (MO.isExpr())
509 return ::getBranchTargetOpValue(MI, OpIdx, ARM::fixup_arm_thumb_blx,
510 Fixups);
511 return encodeThumbBLOffset(MO.getImm());
Bill Wendling3392bfc2010-12-09 00:39:08 +0000512}
513
Jim Grosbache119da12010-12-10 18:21:33 +0000514/// getThumbBRTargetOpValue - Return encoding info for Thumb branch target.
515uint32_t ARMMCCodeEmitter::
516getThumbBRTargetOpValue(const MCInst &MI, unsigned OpIdx,
517 SmallVectorImpl<MCFixup> &Fixups) const {
Owen Anderson543c89f2011-08-30 22:03:20 +0000518 const MCOperand MO = MI.getOperand(OpIdx);
519 if (MO.isExpr())
Owen Anderson5c160fd2011-08-31 18:30:20 +0000520 return ::getBranchTargetOpValue(MI, OpIdx, ARM::fixup_arm_thumb_br,
521 Fixups);
Owen Anderson543c89f2011-08-30 22:03:20 +0000522 return (MO.getImm() >> 1);
Jim Grosbache119da12010-12-10 18:21:33 +0000523}
524
Jim Grosbach78485ad2010-12-10 17:13:40 +0000525/// getThumbBCCTargetOpValue - Return encoding info for Thumb branch target.
526uint32_t ARMMCCodeEmitter::
527getThumbBCCTargetOpValue(const MCInst &MI, unsigned OpIdx,
Jim Grosbache119da12010-12-10 18:21:33 +0000528 SmallVectorImpl<MCFixup> &Fixups) const {
Owen Andersona455a0b2011-08-31 20:26:14 +0000529 const MCOperand MO = MI.getOperand(OpIdx);
530 if (MO.isExpr())
531 return ::getBranchTargetOpValue(MI, OpIdx, ARM::fixup_arm_thumb_bcc,
532 Fixups);
533 return (MO.getImm() >> 1);
Jim Grosbach78485ad2010-12-10 17:13:40 +0000534}
535
Jim Grosbach62b68112010-12-09 19:04:53 +0000536/// getThumbCBTargetOpValue - Return encoding info for Thumb branch target.
Bill Wendlinga7d6aa92010-12-08 23:01:43 +0000537uint32_t ARMMCCodeEmitter::
Jim Grosbach62b68112010-12-09 19:04:53 +0000538getThumbCBTargetOpValue(const MCInst &MI, unsigned OpIdx,
Bill Wendlinga7d6aa92010-12-08 23:01:43 +0000539 SmallVectorImpl<MCFixup> &Fixups) const {
Owen Andersonfdf3cd72011-08-30 22:15:17 +0000540 const MCOperand MO = MI.getOperand(OpIdx);
541 if (MO.isExpr())
542 return ::getBranchTargetOpValue(MI, OpIdx, ARM::fixup_arm_thumb_cb, Fixups);
543 return (MO.getImm() >> 1);
Bill Wendlinga7d6aa92010-12-08 23:01:43 +0000544}
545
Jason W Kimd2e2f562011-02-04 19:47:15 +0000546/// Return true if this branch has a non-always predication
547static bool HasConditionalBranch(const MCInst &MI) {
548 int NumOp = MI.getNumOperands();
549 if (NumOp >= 2) {
550 for (int i = 0; i < NumOp-1; ++i) {
551 const MCOperand &MCOp1 = MI.getOperand(i);
552 const MCOperand &MCOp2 = MI.getOperand(i + 1);
Owen Anderson1732c2e2011-08-30 21:58:18 +0000553 if (MCOp1.isImm() && MCOp2.isReg() &&
Jason W Kimd2e2f562011-02-04 19:47:15 +0000554 (MCOp2.getReg() == 0 || MCOp2.getReg() == ARM::CPSR)) {
Owen Anderson1732c2e2011-08-30 21:58:18 +0000555 if (ARMCC::CondCodes(MCOp1.getImm()) != ARMCC::AL)
Jason W Kimd2e2f562011-02-04 19:47:15 +0000556 return true;
557 }
558 }
559 }
560 return false;
561}
562
Bill Wendlinga7d6aa92010-12-08 23:01:43 +0000563/// getBranchTargetOpValue - Return encoding info for 24-bit immediate branch
564/// target.
Jim Grosbach9d6d77a2010-11-11 18:04:49 +0000565uint32_t ARMMCCodeEmitter::
566getBranchTargetOpValue(const MCInst &MI, unsigned OpIdx,
Bill Wendlinga7d6aa92010-12-08 23:01:43 +0000567 SmallVectorImpl<MCFixup> &Fixups) const {
Jim Grosbachaecdd872010-12-10 23:41:10 +0000568 // FIXME: This really, really shouldn't use TargetMachine. We don't want
569 // coupling between MC and TM anywhere we can help it.
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000570 if (isThumb2())
Owen Anderson578074b2010-12-13 19:31:11 +0000571 return
572 ::getBranchTargetOpValue(MI, OpIdx, ARM::fixup_t2_condbranch, Fixups);
Jason W Kimd2e2f562011-02-04 19:47:15 +0000573 return getARMBranchTargetOpValue(MI, OpIdx, Fixups);
Jim Grosbach9d6d77a2010-11-11 18:04:49 +0000574}
575
Jason W Kimd2e2f562011-02-04 19:47:15 +0000576/// getBranchTargetOpValue - Return encoding info for 24-bit immediate branch
577/// target.
578uint32_t ARMMCCodeEmitter::
579getARMBranchTargetOpValue(const MCInst &MI, unsigned OpIdx,
580 SmallVectorImpl<MCFixup> &Fixups) const {
Owen Anderson6c70e582011-08-26 22:54:51 +0000581 const MCOperand MO = MI.getOperand(OpIdx);
582 if (MO.isExpr()) {
Owen Anderson1732c2e2011-08-30 21:58:18 +0000583 if (HasConditionalBranch(MI))
Owen Anderson6c70e582011-08-26 22:54:51 +0000584 return ::getBranchTargetOpValue(MI, OpIdx,
585 ARM::fixup_arm_condbranch, Fixups);
Owen Anderson1732c2e2011-08-30 21:58:18 +0000586 return ::getBranchTargetOpValue(MI, OpIdx,
Owen Anderson6c70e582011-08-26 22:54:51 +0000587 ARM::fixup_arm_uncondbranch, Fixups);
588 }
589
590 return MO.getImm() >> 2;
Jason W Kimd2e2f562011-02-04 19:47:15 +0000591}
592
Owen Andersonb205c022011-08-26 23:32:08 +0000593uint32_t ARMMCCodeEmitter::
594getARMBLXTargetOpValue(const MCInst &MI, unsigned OpIdx,
595 SmallVectorImpl<MCFixup> &Fixups) const {
596 const MCOperand MO = MI.getOperand(OpIdx);
597 if (MO.isExpr()) {
Owen Anderson1732c2e2011-08-30 21:58:18 +0000598 if (HasConditionalBranch(MI))
Owen Andersonb205c022011-08-26 23:32:08 +0000599 return ::getBranchTargetOpValue(MI, OpIdx,
600 ARM::fixup_arm_condbranch, Fixups);
Owen Anderson1732c2e2011-08-30 21:58:18 +0000601 return ::getBranchTargetOpValue(MI, OpIdx,
Owen Andersonb205c022011-08-26 23:32:08 +0000602 ARM::fixup_arm_uncondbranch, Fixups);
603 }
Jason W Kimd2e2f562011-02-04 19:47:15 +0000604
Owen Andersonb205c022011-08-26 23:32:08 +0000605 return MO.getImm() >> 1;
606}
Jason W Kimd2e2f562011-02-04 19:47:15 +0000607
Owen Anderson578074b2010-12-13 19:31:11 +0000608/// getUnconditionalBranchTargetOpValue - Return encoding info for 24-bit
609/// immediate branch target.
610uint32_t ARMMCCodeEmitter::
611getUnconditionalBranchTargetOpValue(const MCInst &MI, unsigned OpIdx,
612 SmallVectorImpl<MCFixup> &Fixups) const {
613 unsigned Val =
614 ::getBranchTargetOpValue(MI, OpIdx, ARM::fixup_t2_uncondbranch, Fixups);
615 bool I = (Val & 0x800000);
616 bool J1 = (Val & 0x400000);
617 bool J2 = (Val & 0x200000);
618 if (I ^ J1)
619 Val &= ~0x400000;
620 else
621 Val |= 0x400000;
Owen Anderson4ebf4712011-02-08 22:39:40 +0000622
Owen Anderson578074b2010-12-13 19:31:11 +0000623 if (I ^ J2)
624 Val &= ~0x200000;
625 else
626 Val |= 0x200000;
Owen Anderson4ebf4712011-02-08 22:39:40 +0000627
Owen Anderson578074b2010-12-13 19:31:11 +0000628 return Val;
629}
630
Bill Wendlinga7d6aa92010-12-08 23:01:43 +0000631/// getAdrLabelOpValue - Return encoding info for 12-bit immediate ADR label
632/// target.
Jim Grosbachdc35e062010-12-01 19:47:31 +0000633uint32_t ARMMCCodeEmitter::
634getAdrLabelOpValue(const MCInst &MI, unsigned OpIdx,
635 SmallVectorImpl<MCFixup> &Fixups) const {
Owen Andersona01bcbf2011-08-26 18:09:22 +0000636 const MCOperand MO = MI.getOperand(OpIdx);
637 if (MO.isExpr())
638 return ::getBranchTargetOpValue(MI, OpIdx, ARM::fixup_arm_adr_pcrel_12,
639 Fixups);
640 int32_t offset = MO.getImm();
641 uint32_t Val = 0x2000;
642 if (offset < 0) {
643 Val = 0x1000;
644 offset *= -1;
645 }
646 Val |= offset;
647 return Val;
Jim Grosbachdc35e062010-12-01 19:47:31 +0000648}
649
Owen Anderson6d375e52010-12-14 00:36:49 +0000650/// getAdrLabelOpValue - Return encoding info for 12-bit immediate ADR label
651/// target.
652uint32_t ARMMCCodeEmitter::
653getT2AdrLabelOpValue(const MCInst &MI, unsigned OpIdx,
654 SmallVectorImpl<MCFixup> &Fixups) const {
Owen Andersona01bcbf2011-08-26 18:09:22 +0000655 const MCOperand MO = MI.getOperand(OpIdx);
656 if (MO.isExpr())
657 return ::getBranchTargetOpValue(MI, OpIdx, ARM::fixup_t2_adr_pcrel_12,
658 Fixups);
659 return MO.getImm();
Owen Anderson6d375e52010-12-14 00:36:49 +0000660}
661
Jim Grosbach509dc2a2010-12-14 22:28:03 +0000662/// getAdrLabelOpValue - Return encoding info for 8-bit immediate ADR label
663/// target.
664uint32_t ARMMCCodeEmitter::
665getThumbAdrLabelOpValue(const MCInst &MI, unsigned OpIdx,
666 SmallVectorImpl<MCFixup> &Fixups) const {
Owen Andersona01bcbf2011-08-26 18:09:22 +0000667 const MCOperand MO = MI.getOperand(OpIdx);
668 if (MO.isExpr())
669 return ::getBranchTargetOpValue(MI, OpIdx, ARM::fixup_thumb_adr_pcrel_10,
670 Fixups);
671 return MO.getImm();
Jim Grosbach509dc2a2010-12-14 22:28:03 +0000672}
673
Bill Wendling092a7bd2010-12-14 03:36:38 +0000674/// getThumbAddrModeRegRegOpValue - Return encoding info for 'reg + reg'
675/// operand.
Owen Andersonb0fa1272010-12-10 22:11:13 +0000676uint32_t ARMMCCodeEmitter::
Bill Wendling092a7bd2010-12-14 03:36:38 +0000677getThumbAddrModeRegRegOpValue(const MCInst &MI, unsigned OpIdx,
678 SmallVectorImpl<MCFixup> &) const {
679 // [Rn, Rm]
680 // {5-3} = Rm
681 // {2-0} = Rn
Owen Andersonb0fa1272010-12-10 22:11:13 +0000682 const MCOperand &MO1 = MI.getOperand(OpIdx);
Bill Wendling092a7bd2010-12-14 03:36:38 +0000683 const MCOperand &MO2 = MI.getOperand(OpIdx + 1);
Owen Andersonb0fa1272010-12-10 22:11:13 +0000684 unsigned Rn = getARMRegisterNumbering(MO1.getReg());
685 unsigned Rm = getARMRegisterNumbering(MO2.getReg());
686 return (Rm << 3) | Rn;
687}
688
Bill Wendlinge84eb992010-11-03 01:49:29 +0000689/// getAddrModeImm12OpValue - Return encoding info for 'reg +/- imm12' operand.
Jim Grosbach2eed7a12010-11-03 23:52:49 +0000690uint32_t ARMMCCodeEmitter::
691getAddrModeImm12OpValue(const MCInst &MI, unsigned OpIdx,
692 SmallVectorImpl<MCFixup> &Fixups) const {
Bill Wendlinge84eb992010-11-03 01:49:29 +0000693 // {17-13} = reg
694 // {12} = (U)nsigned (add == '1', sub == '0')
695 // {11-0} = imm12
696 unsigned Reg, Imm12;
Jim Grosbach0fb841f2010-11-04 01:12:30 +0000697 bool isAdd = true;
698 // If The first operand isn't a register, we have a label reference.
699 const MCOperand &MO = MI.getOperand(OpIdx);
Owen Anderson4ebf4712011-02-08 22:39:40 +0000700 if (!MO.isReg()) {
Jim Grosbach90987142010-11-09 01:37:15 +0000701 Reg = getARMRegisterNumbering(ARM::PC); // Rn is PC.
Jim Grosbach0fb841f2010-11-04 01:12:30 +0000702 Imm12 = 0;
Jim Grosbach2d3e5c12010-11-30 22:40:36 +0000703 isAdd = false ; // 'U' bit is set as part of the fixup.
Jim Grosbach0fb841f2010-11-04 01:12:30 +0000704
Owen Anderson4ebf4712011-02-08 22:39:40 +0000705 assert(MO.isExpr() && "Unexpected machine operand type!");
706 const MCExpr *Expr = MO.getExpr();
Jim Grosbachc4a0c292010-12-10 21:57:34 +0000707
Owen Anderson3e6ee1d2010-12-09 01:51:07 +0000708 MCFixupKind Kind;
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000709 if (isThumb2())
Owen Anderson3e6ee1d2010-12-09 01:51:07 +0000710 Kind = MCFixupKind(ARM::fixup_t2_ldst_pcrel_12);
711 else
712 Kind = MCFixupKind(ARM::fixup_arm_ldst_pcrel_12);
Jim Grosbach0fb841f2010-11-04 01:12:30 +0000713 Fixups.push_back(MCFixup::Create(0, Expr, Kind));
714
715 ++MCNumCPRelocations;
716 } else
717 isAdd = EncodeAddrModeOpValues(MI, OpIdx, Reg, Imm12, Fixups);
Bill Wendlinge84eb992010-11-03 01:49:29 +0000718
Bill Wendlinge84eb992010-11-03 01:49:29 +0000719 uint32_t Binary = Imm12 & 0xfff;
720 // Immediate is always encoded as positive. The 'U' bit controls add vs sub.
Jim Grosbach505607e2010-10-28 18:34:10 +0000721 if (isAdd)
Bill Wendlinge84eb992010-11-03 01:49:29 +0000722 Binary |= (1 << 12);
723 Binary |= (Reg << 13);
724 return Binary;
725}
726
Jim Grosbach7db8d692011-09-08 22:07:06 +0000727/// getT2Imm8s4OpValue - Return encoding info for
728/// '+/- imm8<<2' operand.
729uint32_t ARMMCCodeEmitter::
730getT2Imm8s4OpValue(const MCInst &MI, unsigned OpIdx,
731 SmallVectorImpl<MCFixup> &Fixups) const {
732 // FIXME: The immediate operand should have already been encoded like this
733 // before ever getting here. The encoder method should just need to combine
734 // the MI operands for the register and the offset into a single
735 // representation for the complex operand in the .td file. This isn't just
736 // style, unfortunately. As-is, we can't represent the distinct encoding
737 // for #-0.
738
739 // {8} = (U)nsigned (add == '1', sub == '0')
740 // {7-0} = imm8
741 int32_t Imm8 = MI.getOperand(OpIdx).getImm();
742 bool isAdd = Imm8 >= 0;
743
744 // Immediate is always encoded as positive. The 'U' bit controls add vs sub.
745 if (Imm8 < 0)
746 Imm8 = -Imm8;
747
748 // Scaled by 4.
749 Imm8 /= 4;
750
751 uint32_t Binary = Imm8 & 0xff;
752 // Immediate is always encoded as positive. The 'U' bit controls add vs sub.
753 if (isAdd)
754 Binary |= (1 << 8);
755 return Binary;
756}
757
Owen Anderson943fb602010-12-01 19:18:46 +0000758/// getT2AddrModeImm8s4OpValue - Return encoding info for
759/// 'reg +/- imm8<<2' operand.
760uint32_t ARMMCCodeEmitter::
761getT2AddrModeImm8s4OpValue(const MCInst &MI, unsigned OpIdx,
762 SmallVectorImpl<MCFixup> &Fixups) const {
Jim Grosbache69f7242010-12-10 21:05:07 +0000763 // {12-9} = reg
764 // {8} = (U)nsigned (add == '1', sub == '0')
765 // {7-0} = imm8
Owen Anderson943fb602010-12-01 19:18:46 +0000766 unsigned Reg, Imm8;
767 bool isAdd = true;
768 // If The first operand isn't a register, we have a label reference.
769 const MCOperand &MO = MI.getOperand(OpIdx);
770 if (!MO.isReg()) {
771 Reg = getARMRegisterNumbering(ARM::PC); // Rn is PC.
772 Imm8 = 0;
773 isAdd = false ; // 'U' bit is set as part of the fixup.
774
775 assert(MO.isExpr() && "Unexpected machine operand type!");
776 const MCExpr *Expr = MO.getExpr();
777 MCFixupKind Kind = MCFixupKind(ARM::fixup_arm_pcrel_10);
778 Fixups.push_back(MCFixup::Create(0, Expr, Kind));
779
780 ++MCNumCPRelocations;
781 } else
782 isAdd = EncodeAddrModeOpValues(MI, OpIdx, Reg, Imm8, Fixups);
783
Jim Grosbach7db8d692011-09-08 22:07:06 +0000784 // FIXME: The immediate operand should have already been encoded like this
785 // before ever getting here. The encoder method should just need to combine
786 // the MI operands for the register and the offset into a single
787 // representation for the complex operand in the .td file. This isn't just
788 // style, unfortunately. As-is, we can't represent the distinct encoding
789 // for #-0.
Owen Anderson943fb602010-12-01 19:18:46 +0000790 uint32_t Binary = (Imm8 >> 2) & 0xff;
791 // Immediate is always encoded as positive. The 'U' bit controls add vs sub.
792 if (isAdd)
Jim Grosbache69f7242010-12-10 21:05:07 +0000793 Binary |= (1 << 8);
Owen Anderson943fb602010-12-01 19:18:46 +0000794 Binary |= (Reg << 9);
795 return Binary;
796}
797
Jason W Kim9c5b65d2011-01-12 00:19:25 +0000798// FIXME: This routine assumes that a binary
799// expression will always result in a PCRel expression
800// In reality, its only true if one or more subexpressions
801// is itself a PCRel (i.e. "." in asm or some other pcrel construct)
802// but this is good enough for now.
803static bool EvaluateAsPCRel(const MCExpr *Expr) {
804 switch (Expr->getKind()) {
Matt Beaumont-Gay3077bb62011-01-12 18:02:55 +0000805 default: assert(0 && "Unexpected expression type");
Jason W Kim9c5b65d2011-01-12 00:19:25 +0000806 case MCExpr::SymbolRef: return false;
807 case MCExpr::Binary: return true;
Jason W Kim9c5b65d2011-01-12 00:19:25 +0000808 }
809}
810
Evan Cheng965b3c72011-01-13 07:58:56 +0000811uint32_t
812ARMMCCodeEmitter::getHiLo16ImmOpValue(const MCInst &MI, unsigned OpIdx,
813 SmallVectorImpl<MCFixup> &Fixups) const {
Jason W Kim5a97bd82010-11-18 23:37:15 +0000814 // {20-16} = imm{15-12}
815 // {11-0} = imm{11-0}
Jim Grosbachc4a0c292010-12-10 21:57:34 +0000816 const MCOperand &MO = MI.getOperand(OpIdx);
Evan Cheng965b3c72011-01-13 07:58:56 +0000817 if (MO.isImm())
818 // Hi / lo 16 bits already extracted during earlier passes.
Jason W Kim5a97bd82010-11-18 23:37:15 +0000819 return static_cast<unsigned>(MO.getImm());
Evan Cheng965b3c72011-01-13 07:58:56 +0000820
821 // Handle :upper16: and :lower16: assembly prefixes.
822 const MCExpr *E = MO.getExpr();
823 if (E->getKind() == MCExpr::Target) {
824 const ARMMCExpr *ARM16Expr = cast<ARMMCExpr>(E);
825 E = ARM16Expr->getSubExpr();
826
Jason W Kim5a97bd82010-11-18 23:37:15 +0000827 MCFixupKind Kind;
Evan Cheng965b3c72011-01-13 07:58:56 +0000828 switch (ARM16Expr->getKind()) {
Matt Beaumont-Gay3077bb62011-01-12 18:02:55 +0000829 default: assert(0 && "Unsupported ARMFixup");
Evan Cheng965b3c72011-01-13 07:58:56 +0000830 case ARMMCExpr::VK_ARM_HI16:
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000831 if (!isTargetDarwin() && EvaluateAsPCRel(E))
832 Kind = MCFixupKind(isThumb2()
Evan Chengd4a5c052011-01-14 02:38:49 +0000833 ? ARM::fixup_t2_movt_hi16_pcrel
834 : ARM::fixup_arm_movt_hi16_pcrel);
835 else
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000836 Kind = MCFixupKind(isThumb2()
Evan Chengd4a5c052011-01-14 02:38:49 +0000837 ? ARM::fixup_t2_movt_hi16
838 : ARM::fixup_arm_movt_hi16);
Jason W Kim5a97bd82010-11-18 23:37:15 +0000839 break;
Evan Cheng965b3c72011-01-13 07:58:56 +0000840 case ARMMCExpr::VK_ARM_LO16:
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000841 if (!isTargetDarwin() && EvaluateAsPCRel(E))
842 Kind = MCFixupKind(isThumb2()
Evan Chengd4a5c052011-01-14 02:38:49 +0000843 ? ARM::fixup_t2_movw_lo16_pcrel
844 : ARM::fixup_arm_movw_lo16_pcrel);
845 else
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000846 Kind = MCFixupKind(isThumb2()
Evan Chengd4a5c052011-01-14 02:38:49 +0000847 ? ARM::fixup_t2_movw_lo16
848 : ARM::fixup_arm_movw_lo16);
Jason W Kim5a97bd82010-11-18 23:37:15 +0000849 break;
Jason W Kim5a97bd82010-11-18 23:37:15 +0000850 }
Evan Cheng965b3c72011-01-13 07:58:56 +0000851 Fixups.push_back(MCFixup::Create(0, E, Kind));
Jason W Kim5a97bd82010-11-18 23:37:15 +0000852 return 0;
Jim Grosbach2aeb8b92010-11-19 00:27:09 +0000853 };
Evan Cheng965b3c72011-01-13 07:58:56 +0000854
Jim Grosbach2aeb8b92010-11-19 00:27:09 +0000855 llvm_unreachable("Unsupported MCExpr type in MCOperand!");
Jason W Kim5a97bd82010-11-18 23:37:15 +0000856 return 0;
857}
858
859uint32_t ARMMCCodeEmitter::
Jim Grosbachdbfb5ed2010-11-09 17:20:53 +0000860getLdStSORegOpValue(const MCInst &MI, unsigned OpIdx,
861 SmallVectorImpl<MCFixup> &Fixups) const {
862 const MCOperand &MO = MI.getOperand(OpIdx);
863 const MCOperand &MO1 = MI.getOperand(OpIdx+1);
864 const MCOperand &MO2 = MI.getOperand(OpIdx+2);
865 unsigned Rn = getARMRegisterNumbering(MO.getReg());
866 unsigned Rm = getARMRegisterNumbering(MO1.getReg());
Jim Grosbachdbfb5ed2010-11-09 17:20:53 +0000867 unsigned ShImm = ARM_AM::getAM2Offset(MO2.getImm());
868 bool isAdd = ARM_AM::getAM2Op(MO2.getImm()) == ARM_AM::add;
Jim Grosbach38b469e2010-11-15 20:47:07 +0000869 ARM_AM::ShiftOpc ShOp = ARM_AM::getAM2ShiftOpc(MO2.getImm());
870 unsigned SBits = getShiftOp(ShOp);
Jim Grosbachdbfb5ed2010-11-09 17:20:53 +0000871
872 // {16-13} = Rn
873 // {12} = isAdd
874 // {11-0} = shifter
875 // {3-0} = Rm
876 // {4} = 0
877 // {6-5} = type
878 // {11-7} = imm
Jim Grosbach607efcb2010-11-11 01:09:40 +0000879 uint32_t Binary = Rm;
Jim Grosbachdbfb5ed2010-11-09 17:20:53 +0000880 Binary |= Rn << 13;
881 Binary |= SBits << 5;
882 Binary |= ShImm << 7;
883 if (isAdd)
884 Binary |= 1 << 12;
885 return Binary;
886}
887
Jim Grosbach607efcb2010-11-11 01:09:40 +0000888uint32_t ARMMCCodeEmitter::
Jim Grosbach38b469e2010-11-15 20:47:07 +0000889getAddrMode2OpValue(const MCInst &MI, unsigned OpIdx,
890 SmallVectorImpl<MCFixup> &Fixups) const {
891 // {17-14} Rn
892 // {13} 1 == imm12, 0 == Rm
893 // {12} isAdd
894 // {11-0} imm12/Rm
895 const MCOperand &MO = MI.getOperand(OpIdx);
896 unsigned Rn = getARMRegisterNumbering(MO.getReg());
897 uint32_t Binary = getAddrMode2OffsetOpValue(MI, OpIdx + 1, Fixups);
898 Binary |= Rn << 14;
899 return Binary;
900}
901
902uint32_t ARMMCCodeEmitter::
903getAddrMode2OffsetOpValue(const MCInst &MI, unsigned OpIdx,
904 SmallVectorImpl<MCFixup> &Fixups) const {
905 // {13} 1 == imm12, 0 == Rm
906 // {12} isAdd
907 // {11-0} imm12/Rm
908 const MCOperand &MO = MI.getOperand(OpIdx);
909 const MCOperand &MO1 = MI.getOperand(OpIdx+1);
910 unsigned Imm = MO1.getImm();
911 bool isAdd = ARM_AM::getAM2Op(Imm) == ARM_AM::add;
912 bool isReg = MO.getReg() != 0;
913 uint32_t Binary = ARM_AM::getAM2Offset(Imm);
914 // if reg +/- reg, Rm will be non-zero. Otherwise, we have reg +/- imm12
915 if (isReg) {
916 ARM_AM::ShiftOpc ShOp = ARM_AM::getAM2ShiftOpc(Imm);
917 Binary <<= 7; // Shift amount is bits [11:7]
918 Binary |= getShiftOp(ShOp) << 5; // Shift type is bits [6:5]
919 Binary |= getARMRegisterNumbering(MO.getReg()); // Rm is bits [3:0]
920 }
921 return Binary | (isAdd << 12) | (isReg << 13);
922}
923
924uint32_t ARMMCCodeEmitter::
Jim Grosbachd3595712011-08-03 23:50:40 +0000925getPostIdxRegOpValue(const MCInst &MI, unsigned OpIdx,
926 SmallVectorImpl<MCFixup> &Fixups) const {
927 // {4} isAdd
928 // {3-0} Rm
929 const MCOperand &MO = MI.getOperand(OpIdx);
930 const MCOperand &MO1 = MI.getOperand(OpIdx+1);
Jim Grosbacha70fbfd52011-08-05 16:11:38 +0000931 bool isAdd = MO1.getImm() != 0;
Jim Grosbachd3595712011-08-03 23:50:40 +0000932 return getARMRegisterNumbering(MO.getReg()) | (isAdd << 4);
933}
934
935uint32_t ARMMCCodeEmitter::
Jim Grosbach68685e62010-11-11 16:55:29 +0000936getAddrMode3OffsetOpValue(const MCInst &MI, unsigned OpIdx,
937 SmallVectorImpl<MCFixup> &Fixups) const {
938 // {9} 1 == imm8, 0 == Rm
939 // {8} isAdd
940 // {7-4} imm7_4/zero
941 // {3-0} imm3_0/Rm
942 const MCOperand &MO = MI.getOperand(OpIdx);
943 const MCOperand &MO1 = MI.getOperand(OpIdx+1);
944 unsigned Imm = MO1.getImm();
945 bool isAdd = ARM_AM::getAM3Op(Imm) == ARM_AM::add;
946 bool isImm = MO.getReg() == 0;
947 uint32_t Imm8 = ARM_AM::getAM3Offset(Imm);
948 // if reg +/- reg, Rm will be non-zero. Otherwise, we have reg +/- imm8
949 if (!isImm)
950 Imm8 = getARMRegisterNumbering(MO.getReg());
951 return Imm8 | (isAdd << 8) | (isImm << 9);
952}
953
954uint32_t ARMMCCodeEmitter::
Jim Grosbach607efcb2010-11-11 01:09:40 +0000955getAddrMode3OpValue(const MCInst &MI, unsigned OpIdx,
956 SmallVectorImpl<MCFixup> &Fixups) const {
957 // {13} 1 == imm8, 0 == Rm
958 // {12-9} Rn
959 // {8} isAdd
960 // {7-4} imm7_4/zero
961 // {3-0} imm3_0/Rm
962 const MCOperand &MO = MI.getOperand(OpIdx);
963 const MCOperand &MO1 = MI.getOperand(OpIdx+1);
964 const MCOperand &MO2 = MI.getOperand(OpIdx+2);
965 unsigned Rn = getARMRegisterNumbering(MO.getReg());
966 unsigned Imm = MO2.getImm();
967 bool isAdd = ARM_AM::getAM3Op(Imm) == ARM_AM::add;
968 bool isImm = MO1.getReg() == 0;
969 uint32_t Imm8 = ARM_AM::getAM3Offset(Imm);
970 // if reg +/- reg, Rm will be non-zero. Otherwise, we have reg +/- imm8
971 if (!isImm)
972 Imm8 = getARMRegisterNumbering(MO1.getReg());
973 return (Rn << 9) | Imm8 | (isAdd << 8) | (isImm << 13);
974}
975
Bill Wendling8a6449c2010-12-08 01:57:09 +0000976/// getAddrModeThumbSPOpValue - Encode the t_addrmode_sp operands.
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000977uint32_t ARMMCCodeEmitter::
978getAddrModeThumbSPOpValue(const MCInst &MI, unsigned OpIdx,
979 SmallVectorImpl<MCFixup> &Fixups) const {
980 // [SP, #imm]
981 // {7-0} = imm8
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000982 const MCOperand &MO1 = MI.getOperand(OpIdx + 1);
Bill Wendling8a6449c2010-12-08 01:57:09 +0000983 assert(MI.getOperand(OpIdx).getReg() == ARM::SP &&
984 "Unexpected base register!");
Bill Wendling7d3bde92010-12-15 23:32:27 +0000985
Jim Grosbach49bcd6f2010-12-07 21:50:47 +0000986 // The immediate is already shifted for the implicit zeroes, so no change
987 // here.
988 return MO1.getImm() & 0xff;
989}
990
Bill Wendling092a7bd2010-12-14 03:36:38 +0000991/// getAddrModeISOpValue - Encode the t_addrmode_is# operands.
Bill Wendling0c4838b2010-12-09 21:49:07 +0000992uint32_t ARMMCCodeEmitter::
Bill Wendling092a7bd2010-12-14 03:36:38 +0000993getAddrModeISOpValue(const MCInst &MI, unsigned OpIdx,
Bill Wendling03e75762010-12-15 08:51:02 +0000994 SmallVectorImpl<MCFixup> &Fixups) const {
Bill Wendling811c9362010-11-30 07:44:32 +0000995 // [Rn, #imm]
996 // {7-3} = imm5
997 // {2-0} = Rn
998 const MCOperand &MO = MI.getOperand(OpIdx);
999 const MCOperand &MO1 = MI.getOperand(OpIdx + 1);
Bill Wendling811c9362010-11-30 07:44:32 +00001000 unsigned Rn = getARMRegisterNumbering(MO.getReg());
Matt Beaumont-Gaye9afc742010-12-16 01:34:26 +00001001 unsigned Imm5 = MO1.getImm();
Bill Wendling0c4838b2010-12-09 21:49:07 +00001002 return ((Imm5 & 0x1f) << 3) | Rn;
Bill Wendlinga9e3df72010-11-30 22:57:21 +00001003}
1004
Bill Wendling8a6449c2010-12-08 01:57:09 +00001005/// getAddrModePCOpValue - Return encoding for t_addrmode_pc operands.
1006uint32_t ARMMCCodeEmitter::
1007getAddrModePCOpValue(const MCInst &MI, unsigned OpIdx,
1008 SmallVectorImpl<MCFixup> &Fixups) const {
Owen Andersond16fb432011-08-30 22:10:03 +00001009 const MCOperand MO = MI.getOperand(OpIdx);
1010 if (MO.isExpr())
1011 return ::getBranchTargetOpValue(MI, OpIdx, ARM::fixup_arm_thumb_cp, Fixups);
1012 return (MO.getImm() >> 2);
Bill Wendling8a6449c2010-12-08 01:57:09 +00001013}
1014
Jim Grosbach30eb6c72010-12-01 21:09:40 +00001015/// getAddrMode5OpValue - Return encoding info for 'reg +/- imm10' operand.
Jim Grosbach2eed7a12010-11-03 23:52:49 +00001016uint32_t ARMMCCodeEmitter::
1017getAddrMode5OpValue(const MCInst &MI, unsigned OpIdx,
1018 SmallVectorImpl<MCFixup> &Fixups) const {
Bill Wendlinge84eb992010-11-03 01:49:29 +00001019 // {12-9} = reg
1020 // {8} = (U)nsigned (add == '1', sub == '0')
1021 // {7-0} = imm8
1022 unsigned Reg, Imm8;
Jim Grosbach2d3e5c12010-11-30 22:40:36 +00001023 bool isAdd;
Jim Grosbach0fb841f2010-11-04 01:12:30 +00001024 // If The first operand isn't a register, we have a label reference.
1025 const MCOperand &MO = MI.getOperand(OpIdx);
1026 if (!MO.isReg()) {
Jim Grosbach90987142010-11-09 01:37:15 +00001027 Reg = getARMRegisterNumbering(ARM::PC); // Rn is PC.
Jim Grosbach0fb841f2010-11-04 01:12:30 +00001028 Imm8 = 0;
Jim Grosbach2d3e5c12010-11-30 22:40:36 +00001029 isAdd = false; // 'U' bit is handled as part of the fixup.
Jim Grosbach0fb841f2010-11-04 01:12:30 +00001030
1031 assert(MO.isExpr() && "Unexpected machine operand type!");
1032 const MCExpr *Expr = MO.getExpr();
Owen Anderson0f7142d2010-12-08 00:18:36 +00001033 MCFixupKind Kind;
Evan Chengc5e6d2f2011-07-11 03:57:24 +00001034 if (isThumb2())
Owen Anderson0f7142d2010-12-08 00:18:36 +00001035 Kind = MCFixupKind(ARM::fixup_t2_pcrel_10);
1036 else
1037 Kind = MCFixupKind(ARM::fixup_arm_pcrel_10);
Jim Grosbach0fb841f2010-11-04 01:12:30 +00001038 Fixups.push_back(MCFixup::Create(0, Expr, Kind));
1039
1040 ++MCNumCPRelocations;
Jim Grosbach2d3e5c12010-11-30 22:40:36 +00001041 } else {
Jim Grosbach0fb841f2010-11-04 01:12:30 +00001042 EncodeAddrModeOpValues(MI, OpIdx, Reg, Imm8, Fixups);
Jim Grosbach2d3e5c12010-11-30 22:40:36 +00001043 isAdd = ARM_AM::getAM5Op(Imm8) == ARM_AM::add;
1044 }
Bill Wendlinge84eb992010-11-03 01:49:29 +00001045
Bill Wendlinge84eb992010-11-03 01:49:29 +00001046 uint32_t Binary = ARM_AM::getAM5Offset(Imm8);
1047 // Immediate is always encoded as positive. The 'U' bit controls add vs sub.
Jim Grosbach2d3e5c12010-11-30 22:40:36 +00001048 if (isAdd)
Bill Wendlinge84eb992010-11-03 01:49:29 +00001049 Binary |= (1 << 8);
1050 Binary |= (Reg << 9);
Jim Grosbach1e4d9a12010-10-26 22:37:02 +00001051 return Binary;
1052}
1053
Jim Grosbach2eed7a12010-11-03 23:52:49 +00001054unsigned ARMMCCodeEmitter::
Owen Anderson04912702011-07-21 23:38:37 +00001055getSORegRegOpValue(const MCInst &MI, unsigned OpIdx,
Jim Grosbach2eed7a12010-11-03 23:52:49 +00001056 SmallVectorImpl<MCFixup> &Fixups) const {
Bill Wendlingf9eebb52010-11-02 22:53:11 +00001057 // Sub-operands are [reg, reg, imm]. The first register is Rm, the reg to be
Owen Anderson7c965e72011-07-28 17:56:55 +00001058 // shifted. The second is Rs, the amount to shift by, and the third specifies
1059 // the type of the shift.
Jim Grosbach49b0c452010-11-03 22:03:20 +00001060 //
Jim Grosbachefd53692010-10-12 23:53:58 +00001061 // {3-0} = Rm.
Owen Anderson7c965e72011-07-28 17:56:55 +00001062 // {4} = 1
Jim Grosbachefd53692010-10-12 23:53:58 +00001063 // {6-5} = type
Owen Anderson7c965e72011-07-28 17:56:55 +00001064 // {11-8} = Rs
1065 // {7} = 0
Jim Grosbachefd53692010-10-12 23:53:58 +00001066
1067 const MCOperand &MO = MI.getOperand(OpIdx);
1068 const MCOperand &MO1 = MI.getOperand(OpIdx + 1);
1069 const MCOperand &MO2 = MI.getOperand(OpIdx + 2);
1070 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(MO2.getImm());
1071
1072 // Encode Rm.
1073 unsigned Binary = getARMRegisterNumbering(MO.getReg());
1074
1075 // Encode the shift opcode.
1076 unsigned SBits = 0;
1077 unsigned Rs = MO1.getReg();
1078 if (Rs) {
1079 // Set shift operand (bit[7:4]).
1080 // LSL - 0001
1081 // LSR - 0011
1082 // ASR - 0101
1083 // ROR - 0111
Jim Grosbachefd53692010-10-12 23:53:58 +00001084 switch (SOpc) {
1085 default: llvm_unreachable("Unknown shift opc!");
1086 case ARM_AM::lsl: SBits = 0x1; break;
1087 case ARM_AM::lsr: SBits = 0x3; break;
1088 case ARM_AM::asr: SBits = 0x5; break;
1089 case ARM_AM::ror: SBits = 0x7; break;
Jim Grosbachefd53692010-10-12 23:53:58 +00001090 }
1091 }
Bill Wendlingf9eebb52010-11-02 22:53:11 +00001092
Jim Grosbachefd53692010-10-12 23:53:58 +00001093 Binary |= SBits << 4;
Jim Grosbachefd53692010-10-12 23:53:58 +00001094
Owen Anderson7c965e72011-07-28 17:56:55 +00001095 // Encode the shift operation Rs.
Owen Anderson04912702011-07-21 23:38:37 +00001096 // Encode Rs bit[11:8].
1097 assert(ARM_AM::getSORegOffset(MO2.getImm()) == 0);
1098 return Binary | (getARMRegisterNumbering(Rs) << ARMII::RegRsShift);
1099}
1100
1101unsigned ARMMCCodeEmitter::
1102getSORegImmOpValue(const MCInst &MI, unsigned OpIdx,
1103 SmallVectorImpl<MCFixup> &Fixups) const {
Owen Anderson7c965e72011-07-28 17:56:55 +00001104 // Sub-operands are [reg, imm]. The first register is Rm, the reg to be
1105 // shifted. The second is the amount to shift by.
Owen Anderson04912702011-07-21 23:38:37 +00001106 //
1107 // {3-0} = Rm.
Owen Anderson7c965e72011-07-28 17:56:55 +00001108 // {4} = 0
Owen Anderson04912702011-07-21 23:38:37 +00001109 // {6-5} = type
Owen Anderson7c965e72011-07-28 17:56:55 +00001110 // {11-7} = imm
Owen Anderson04912702011-07-21 23:38:37 +00001111
1112 const MCOperand &MO = MI.getOperand(OpIdx);
1113 const MCOperand &MO1 = MI.getOperand(OpIdx + 1);
1114 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(MO1.getImm());
1115
1116 // Encode Rm.
1117 unsigned Binary = getARMRegisterNumbering(MO.getReg());
1118
1119 // Encode the shift opcode.
1120 unsigned SBits = 0;
1121
1122 // Set shift operand (bit[6:4]).
1123 // LSL - 000
1124 // LSR - 010
1125 // ASR - 100
1126 // ROR - 110
1127 // RRX - 110 and bit[11:8] clear.
1128 switch (SOpc) {
1129 default: llvm_unreachable("Unknown shift opc!");
1130 case ARM_AM::lsl: SBits = 0x0; break;
1131 case ARM_AM::lsr: SBits = 0x2; break;
1132 case ARM_AM::asr: SBits = 0x4; break;
1133 case ARM_AM::ror: SBits = 0x6; break;
1134 case ARM_AM::rrx:
1135 Binary |= 0x60;
1136 return Binary;
Jim Grosbachefd53692010-10-12 23:53:58 +00001137 }
1138
1139 // Encode shift_imm bit[11:7].
Owen Anderson04912702011-07-21 23:38:37 +00001140 Binary |= SBits << 4;
Owen Andersone33c95d2011-08-11 18:41:59 +00001141 unsigned Offset = ARM_AM::getSORegOffset(MO1.getImm());
1142 assert(Offset && "Offset must be in range 1-32!");
1143 if (Offset == 32) Offset = 0;
1144 return Binary | (Offset << 7);
Jim Grosbachefd53692010-10-12 23:53:58 +00001145}
1146
Owen Anderson04912702011-07-21 23:38:37 +00001147
Jim Grosbach2eed7a12010-11-03 23:52:49 +00001148unsigned ARMMCCodeEmitter::
Owen Anderson50d662b2010-11-29 22:44:32 +00001149getT2AddrModeSORegOpValue(const MCInst &MI, unsigned OpNum,
1150 SmallVectorImpl<MCFixup> &Fixups) const {
1151 const MCOperand &MO1 = MI.getOperand(OpNum);
1152 const MCOperand &MO2 = MI.getOperand(OpNum+1);
Jim Grosbachc4a0c292010-12-10 21:57:34 +00001153 const MCOperand &MO3 = MI.getOperand(OpNum+2);
1154
Owen Anderson50d662b2010-11-29 22:44:32 +00001155 // Encoded as [Rn, Rm, imm].
1156 // FIXME: Needs fixup support.
1157 unsigned Value = getARMRegisterNumbering(MO1.getReg());
1158 Value <<= 4;
1159 Value |= getARMRegisterNumbering(MO2.getReg());
1160 Value <<= 2;
1161 Value |= MO3.getImm();
Jim Grosbachc4a0c292010-12-10 21:57:34 +00001162
Owen Anderson50d662b2010-11-29 22:44:32 +00001163 return Value;
1164}
1165
1166unsigned ARMMCCodeEmitter::
1167getT2AddrModeImm8OpValue(const MCInst &MI, unsigned OpNum,
1168 SmallVectorImpl<MCFixup> &Fixups) const {
1169 const MCOperand &MO1 = MI.getOperand(OpNum);
1170 const MCOperand &MO2 = MI.getOperand(OpNum+1);
1171
1172 // FIXME: Needs fixup support.
1173 unsigned Value = getARMRegisterNumbering(MO1.getReg());
Jim Grosbachc4a0c292010-12-10 21:57:34 +00001174
Owen Anderson50d662b2010-11-29 22:44:32 +00001175 // Even though the immediate is 8 bits long, we need 9 bits in order
1176 // to represent the (inverse of the) sign bit.
1177 Value <<= 9;
Owen Andersone22c7322010-11-30 00:14:31 +00001178 int32_t tmp = (int32_t)MO2.getImm();
1179 if (tmp < 0)
1180 tmp = abs(tmp);
1181 else
1182 Value |= 256; // Set the ADD bit
1183 Value |= tmp & 255;
1184 return Value;
1185}
1186
1187unsigned ARMMCCodeEmitter::
1188getT2AddrModeImm8OffsetOpValue(const MCInst &MI, unsigned OpNum,
1189 SmallVectorImpl<MCFixup> &Fixups) const {
1190 const MCOperand &MO1 = MI.getOperand(OpNum);
1191
1192 // FIXME: Needs fixup support.
1193 unsigned Value = 0;
1194 int32_t tmp = (int32_t)MO1.getImm();
1195 if (tmp < 0)
1196 tmp = abs(tmp);
1197 else
1198 Value |= 256; // Set the ADD bit
1199 Value |= tmp & 255;
Owen Anderson50d662b2010-11-29 22:44:32 +00001200 return Value;
1201}
1202
1203unsigned ARMMCCodeEmitter::
Owen Anderson299382e2010-11-30 19:19:31 +00001204getT2AddrModeImm12OffsetOpValue(const MCInst &MI, unsigned OpNum,
1205 SmallVectorImpl<MCFixup> &Fixups) const {
1206 const MCOperand &MO1 = MI.getOperand(OpNum);
1207
1208 // FIXME: Needs fixup support.
1209 unsigned Value = 0;
1210 int32_t tmp = (int32_t)MO1.getImm();
1211 if (tmp < 0)
1212 tmp = abs(tmp);
1213 else
1214 Value |= 4096; // Set the ADD bit
1215 Value |= tmp & 4095;
1216 return Value;
1217}
1218
1219unsigned ARMMCCodeEmitter::
Owen Anderson8fdd1722010-11-12 21:12:40 +00001220getT2SORegOpValue(const MCInst &MI, unsigned OpIdx,
1221 SmallVectorImpl<MCFixup> &Fixups) const {
1222 // Sub-operands are [reg, imm]. The first register is Rm, the reg to be
1223 // shifted. The second is the amount to shift by.
1224 //
1225 // {3-0} = Rm.
1226 // {4} = 0
1227 // {6-5} = type
1228 // {11-7} = imm
1229
1230 const MCOperand &MO = MI.getOperand(OpIdx);
1231 const MCOperand &MO1 = MI.getOperand(OpIdx + 1);
1232 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(MO1.getImm());
1233
1234 // Encode Rm.
1235 unsigned Binary = getARMRegisterNumbering(MO.getReg());
1236
1237 // Encode the shift opcode.
1238 unsigned SBits = 0;
1239 // Set shift operand (bit[6:4]).
1240 // LSL - 000
1241 // LSR - 010
1242 // ASR - 100
1243 // ROR - 110
1244 switch (SOpc) {
1245 default: llvm_unreachable("Unknown shift opc!");
1246 case ARM_AM::lsl: SBits = 0x0; break;
1247 case ARM_AM::lsr: SBits = 0x2; break;
1248 case ARM_AM::asr: SBits = 0x4; break;
1249 case ARM_AM::ror: SBits = 0x6; break;
1250 }
1251
1252 Binary |= SBits << 4;
1253 if (SOpc == ARM_AM::rrx)
1254 return Binary;
1255
1256 // Encode shift_imm bit[11:7].
1257 return Binary | ARM_AM::getSORegOffset(MO1.getImm()) << 7;
1258}
1259
1260unsigned ARMMCCodeEmitter::
Jim Grosbach2eed7a12010-11-03 23:52:49 +00001261getBitfieldInvertedMaskOpValue(const MCInst &MI, unsigned Op,
1262 SmallVectorImpl<MCFixup> &Fixups) const {
Jim Grosbach5edb03e2010-10-21 22:03:21 +00001263 // 10 bits. lower 5 bits are are the lsb of the mask, high five bits are the
1264 // msb of the mask.
1265 const MCOperand &MO = MI.getOperand(Op);
1266 uint32_t v = ~MO.getImm();
1267 uint32_t lsb = CountTrailingZeros_32(v);
1268 uint32_t msb = (32 - CountLeadingZeros_32 (v)) - 1;
1269 assert (v != 0 && lsb < 32 && msb < 32 && "Illegal bitfield mask!");
1270 return lsb | (msb << 5);
1271}
1272
Jim Grosbach2eed7a12010-11-03 23:52:49 +00001273unsigned ARMMCCodeEmitter::
Bruno Cardoso Lopes7f639c12011-01-18 20:45:56 +00001274getMsbOpValue(const MCInst &MI, unsigned Op,
1275 SmallVectorImpl<MCFixup> &Fixups) const {
1276 // MSB - 5 bits.
1277 uint32_t lsb = MI.getOperand(Op-1).getImm();
1278 uint32_t width = MI.getOperand(Op).getImm();
1279 uint32_t msb = lsb+width-1;
1280 assert (width != 0 && msb < 32 && "Illegal bit width!");
1281 return msb;
1282}
1283
1284unsigned ARMMCCodeEmitter::
Jim Grosbach2eed7a12010-11-03 23:52:49 +00001285getRegisterListOpValue(const MCInst &MI, unsigned Op,
Bill Wendling1b83ed52010-11-09 00:30:18 +00001286 SmallVectorImpl<MCFixup> &Fixups) const {
Bill Wendling345b48f2010-11-17 00:45:23 +00001287 // VLDM/VSTM:
1288 // {12-8} = Vd
1289 // {7-0} = Number of registers
1290 //
1291 // LDM/STM:
1292 // {15-0} = Bitfield of GPRs.
1293 unsigned Reg = MI.getOperand(Op).getReg();
Evan Chengad5f4852011-07-23 00:00:19 +00001294 bool SPRRegs = llvm::ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg);
1295 bool DPRRegs = llvm::ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg);
Bill Wendling345b48f2010-11-17 00:45:23 +00001296
Bill Wendling1b83ed52010-11-09 00:30:18 +00001297 unsigned Binary = 0;
Bill Wendling345b48f2010-11-17 00:45:23 +00001298
1299 if (SPRRegs || DPRRegs) {
1300 // VLDM/VSTM
1301 unsigned RegNo = getARMRegisterNumbering(Reg);
1302 unsigned NumRegs = (MI.getNumOperands() - Op) & 0xff;
1303 Binary |= (RegNo & 0x1f) << 8;
1304 if (SPRRegs)
1305 Binary |= NumRegs;
1306 else
1307 Binary |= NumRegs * 2;
1308 } else {
1309 for (unsigned I = Op, E = MI.getNumOperands(); I < E; ++I) {
1310 unsigned RegNo = getARMRegisterNumbering(MI.getOperand(I).getReg());
1311 Binary |= 1 << RegNo;
1312 }
Bill Wendling1b83ed52010-11-09 00:30:18 +00001313 }
Bill Wendling345b48f2010-11-17 00:45:23 +00001314
Jim Grosbach74ef9e12010-10-30 00:37:59 +00001315 return Binary;
1316}
1317
Bob Wilson318ce7c2010-11-30 00:00:42 +00001318/// getAddrMode6AddressOpValue - Encode an addrmode6 register number along
1319/// with the alignment operand.
Jim Grosbach2eed7a12010-11-03 23:52:49 +00001320unsigned ARMMCCodeEmitter::
1321getAddrMode6AddressOpValue(const MCInst &MI, unsigned Op,
1322 SmallVectorImpl<MCFixup> &Fixups) const {
Owen Andersonad402342010-11-02 00:05:05 +00001323 const MCOperand &Reg = MI.getOperand(Op);
Bill Wendlingf9eebb52010-11-02 22:53:11 +00001324 const MCOperand &Imm = MI.getOperand(Op + 1);
Jim Grosbach49b0c452010-11-03 22:03:20 +00001325
Owen Andersonad402342010-11-02 00:05:05 +00001326 unsigned RegNo = getARMRegisterNumbering(Reg.getReg());
Bill Wendlingf9eebb52010-11-02 22:53:11 +00001327 unsigned Align = 0;
1328
1329 switch (Imm.getImm()) {
1330 default: break;
1331 case 2:
1332 case 4:
1333 case 8: Align = 0x01; break;
1334 case 16: Align = 0x02; break;
1335 case 32: Align = 0x03; break;
Owen Andersonad402342010-11-02 00:05:05 +00001336 }
Bill Wendlingf9eebb52010-11-02 22:53:11 +00001337
Owen Andersonad402342010-11-02 00:05:05 +00001338 return RegNo | (Align << 4);
1339}
1340
Mon P Wang92ff16b2011-05-09 17:47:27 +00001341/// getAddrMode6OneLane32AddressOpValue - Encode an addrmode6 register number
1342/// along with the alignment operand for use in VST1 and VLD1 with size 32.
1343unsigned ARMMCCodeEmitter::
1344getAddrMode6OneLane32AddressOpValue(const MCInst &MI, unsigned Op,
1345 SmallVectorImpl<MCFixup> &Fixups) const {
1346 const MCOperand &Reg = MI.getOperand(Op);
1347 const MCOperand &Imm = MI.getOperand(Op + 1);
1348
1349 unsigned RegNo = getARMRegisterNumbering(Reg.getReg());
1350 unsigned Align = 0;
1351
1352 switch (Imm.getImm()) {
1353 default: break;
1354 case 2:
1355 case 4:
1356 case 8:
1357 case 16: Align = 0x00; break;
1358 case 32: Align = 0x03; break;
1359 }
1360
1361 return RegNo | (Align << 4);
1362}
1363
1364
Bob Wilson318ce7c2010-11-30 00:00:42 +00001365/// getAddrMode6DupAddressOpValue - Encode an addrmode6 register number and
1366/// alignment operand for use in VLD-dup instructions. This is the same as
1367/// getAddrMode6AddressOpValue except for the alignment encoding, which is
1368/// different for VLD4-dup.
1369unsigned ARMMCCodeEmitter::
1370getAddrMode6DupAddressOpValue(const MCInst &MI, unsigned Op,
1371 SmallVectorImpl<MCFixup> &Fixups) const {
1372 const MCOperand &Reg = MI.getOperand(Op);
1373 const MCOperand &Imm = MI.getOperand(Op + 1);
1374
1375 unsigned RegNo = getARMRegisterNumbering(Reg.getReg());
1376 unsigned Align = 0;
1377
1378 switch (Imm.getImm()) {
1379 default: break;
1380 case 2:
1381 case 4:
1382 case 8: Align = 0x01; break;
1383 case 16: Align = 0x03; break;
1384 }
1385
1386 return RegNo | (Align << 4);
1387}
1388
Jim Grosbach2eed7a12010-11-03 23:52:49 +00001389unsigned ARMMCCodeEmitter::
1390getAddrMode6OffsetOpValue(const MCInst &MI, unsigned Op,
1391 SmallVectorImpl<MCFixup> &Fixups) const {
Bill Wendlingf9eebb52010-11-02 22:53:11 +00001392 const MCOperand &MO = MI.getOperand(Op);
1393 if (MO.getReg() == 0) return 0x0D;
1394 return MO.getReg();
Owen Anderson526ffd52010-11-02 01:24:55 +00001395}
1396
Bill Wendling3b1459b2011-03-01 01:00:59 +00001397unsigned ARMMCCodeEmitter::
Bill Wendling77ad1dc2011-03-07 23:38:41 +00001398getShiftRight8Imm(const MCInst &MI, unsigned Op,
1399 SmallVectorImpl<MCFixup> &Fixups) const {
Bill Wendling3b1459b2011-03-01 01:00:59 +00001400 return 8 - MI.getOperand(Op).getImm();
1401}
1402
1403unsigned ARMMCCodeEmitter::
Bill Wendling77ad1dc2011-03-07 23:38:41 +00001404getShiftRight16Imm(const MCInst &MI, unsigned Op,
1405 SmallVectorImpl<MCFixup> &Fixups) const {
Bill Wendling3b1459b2011-03-01 01:00:59 +00001406 return 16 - MI.getOperand(Op).getImm();
1407}
1408
1409unsigned ARMMCCodeEmitter::
Bill Wendling77ad1dc2011-03-07 23:38:41 +00001410getShiftRight32Imm(const MCInst &MI, unsigned Op,
1411 SmallVectorImpl<MCFixup> &Fixups) const {
Bill Wendling3b1459b2011-03-01 01:00:59 +00001412 return 32 - MI.getOperand(Op).getImm();
1413}
1414
Bill Wendling77ad1dc2011-03-07 23:38:41 +00001415unsigned ARMMCCodeEmitter::
1416getShiftRight64Imm(const MCInst &MI, unsigned Op,
1417 SmallVectorImpl<MCFixup> &Fixups) const {
1418 return 64 - MI.getOperand(Op).getImm();
1419}
1420
Jim Grosbach1287f4f2010-09-17 18:46:17 +00001421void ARMMCCodeEmitter::
1422EncodeInstruction(const MCInst &MI, raw_ostream &OS,
Jim Grosbach2eed7a12010-11-03 23:52:49 +00001423 SmallVectorImpl<MCFixup> &Fixups) const {
Jim Grosbach91029092010-10-07 22:12:50 +00001424 // Pseudo instructions don't get encoded.
Evan Chengc5e6d2f2011-07-11 03:57:24 +00001425 const MCInstrDesc &Desc = MCII.get(MI.getOpcode());
Jim Grosbach20b6fd72010-11-11 23:41:09 +00001426 uint64_t TSFlags = Desc.TSFlags;
1427 if ((TSFlags & ARMII::FormMask) == ARMII::Pseudo)
Jim Grosbach91029092010-10-07 22:12:50 +00001428 return;
Owen Anderson651b2302011-07-13 23:22:26 +00001429
Jim Grosbach20b6fd72010-11-11 23:41:09 +00001430 int Size;
Owen Anderson651b2302011-07-13 23:22:26 +00001431 if (Desc.getSize() == 2 || Desc.getSize() == 4)
1432 Size = Desc.getSize();
1433 else
1434 llvm_unreachable("Unexpected instruction size!");
Owen Anderson1732c2e2011-08-30 21:58:18 +00001435
Jim Grosbach567ebd0c2010-12-03 22:31:40 +00001436 uint32_t Binary = getBinaryCodeForInstr(MI, Fixups);
Evan Cheng965b3c72011-01-13 07:58:56 +00001437 // Thumb 32-bit wide instructions need to emit the high order halfword
1438 // first.
Evan Chengc5e6d2f2011-07-11 03:57:24 +00001439 if (isThumb() && Size == 4) {
Jim Grosbach567ebd0c2010-12-03 22:31:40 +00001440 EmitConstant(Binary >> 16, 2, OS);
1441 EmitConstant(Binary & 0xffff, 2, OS);
1442 } else
1443 EmitConstant(Binary, Size, OS);
Bill Wendling91da9ab2010-11-02 22:44:12 +00001444 ++MCNumEmitted; // Keep track of the # of mi's emitted.
Jim Grosbach1287f4f2010-09-17 18:46:17 +00001445}
Jim Grosbach8aed3862010-10-07 21:57:55 +00001446
Jim Grosbach2eed7a12010-11-03 23:52:49 +00001447#include "ARMGenMCCodeEmitter.inc"