OLD | NEW |
---|---|
1 //===- subzero/src/IceAssemblerARM32.cpp - Assembler for ARM32 --*- C++ -*-===// | 1 //===- subzero/src/IceAssemblerARM32.cpp - Assembler for ARM32 --*- C++ -*-===// |
2 // | 2 // |
3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
4 // for details. All rights reserved. Use of this source code is governed by a | 4 // for details. All rights reserved. Use of this source code is governed by a |
5 // BSD-style license that can be found in the LICENSE file. | 5 // BSD-style license that can be found in the LICENSE file. |
6 // | 6 // |
7 // Modified by the Subzero authors. | 7 // Modified by the Subzero authors. |
8 // | 8 // |
9 //===----------------------------------------------------------------------===// | 9 //===----------------------------------------------------------------------===// |
10 // | 10 // |
11 // The Subzero Code Generator | 11 // The Subzero Code Generator |
12 // | 12 // |
13 // This file is distributed under the University of Illinois Open Source | 13 // This file is distributed under the University of Illinois Open Source |
14 // License. See LICENSE.TXT for details. | 14 // License. See LICENSE.TXT for details. |
15 // | 15 // |
16 //===----------------------------------------------------------------------===// | 16 //===----------------------------------------------------------------------===// |
17 /// | 17 /// |
18 /// \file | 18 /// \file |
19 /// This file implements the Assembler class for ARM32. | 19 /// This file implements the Assembler class for ARM32. |
20 /// | 20 /// |
21 //===----------------------------------------------------------------------===// | 21 //===----------------------------------------------------------------------===// |
22 | 22 |
23 #include "IceAssemblerARM32.h" | 23 #include "IceAssemblerARM32.h" |
24 #include "IceCfgNode.h" | |
24 #include "IceUtils.h" | 25 #include "IceUtils.h" |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 using namespace Ice; | 29 using namespace Ice; |
29 | 30 |
30 // The following define individual bits. | 31 // The following define individual bits. |
31 static constexpr uint32_t B0 = 1; | 32 static constexpr uint32_t B0 = 1; |
32 static constexpr uint32_t B1 = 1 << 1; | 33 static constexpr uint32_t B1 = 1 << 1; |
33 static constexpr uint32_t B2 = 1 << 2; | 34 static constexpr uint32_t B2 = 1 << 2; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 OperandARM32Mem::Offset); | 198 OperandARM32Mem::Offset); |
198 return DecodedAsImmRegOffset; | 199 return DecodedAsImmRegOffset; |
199 } | 200 } |
200 return CantDecode; | 201 return CantDecode; |
201 } | 202 } |
202 | 203 |
203 } // end of anonymous namespace | 204 } // end of anonymous namespace |
204 | 205 |
205 namespace Ice { | 206 namespace Ice { |
206 | 207 |
208 void ARM32::AssemblerARM32::bindCfgNodeLabel(const CfgNode *Node) { | |
209 if (BuildDefs::dump() && !Ctx->getFlags().getDisableHybridAssembly()) { | |
210 // Generate label name so that branches can find it. | |
211 emitTextInst(Node->getAsmName() + ":", 0); | |
Jim Stichnoth
2015/10/23 13:54:52
Can you use "constexpr SizeT InstSize = 0;" for th
Karl
2015/10/23 16:20:07
Done.
| |
212 } | |
213 SizeT NodeNumber = Node->getIndex(); | |
214 assert(!getPreliminary()); | |
215 Label *L = getOrCreateCfgNodeLabel(NodeNumber); | |
216 this->bind(L); | |
217 } | |
218 | |
207 Label *ARM32::AssemblerARM32::getOrCreateLabel(SizeT Number, | 219 Label *ARM32::AssemblerARM32::getOrCreateLabel(SizeT Number, |
208 LabelVector &Labels) { | 220 LabelVector &Labels) { |
209 Label *L = nullptr; | 221 Label *L = nullptr; |
210 if (Number == Labels.size()) { | 222 if (Number == Labels.size()) { |
211 L = new (this->allocate<Label>()) Label(); | 223 L = new (this->allocate<Label>()) Label(); |
212 Labels.push_back(L); | 224 Labels.push_back(L); |
213 return L; | 225 return L; |
214 } | 226 } |
215 if (Number > Labels.size()) { | 227 if (Number > Labels.size()) { |
216 Labels.resize(Number + 1); | 228 Labels.resize(Number + 1); |
(...skipping 12 matching lines...) Expand all Loading... | |
229 while (label->isLinked()) { | 241 while (label->isLinked()) { |
230 intptr_t position = label->getLinkPosition(); | 242 intptr_t position = label->getLinkPosition(); |
231 intptr_t next = Buffer.load<int32_t>(position); | 243 intptr_t next = Buffer.load<int32_t>(position); |
232 Buffer.store<int32_t>(position, bound - (position + 4)); | 244 Buffer.store<int32_t>(position, bound - (position + 4)); |
233 label->setPosition(next); | 245 label->setPosition(next); |
234 } | 246 } |
235 // TODO(kschimpf) Decide if we have near jumps. | 247 // TODO(kschimpf) Decide if we have near jumps. |
236 label->bindTo(bound); | 248 label->bindTo(bound); |
237 } | 249 } |
238 | 250 |
239 void ARM32::AssemblerARM32::emitTextInst(const std::string &Text) { | 251 void ARM32::AssemblerARM32::emitTextInst(const std::string &Text, |
240 static constexpr uint32_t Placeholder = 0; | 252 SizeT InstSize) { |
241 AssemblerBuffer::EnsureCapacity ensured(&Buffer); | 253 AssemblerBuffer::EnsureCapacity ensured(&Buffer); |
242 AssemblerFixup *F = createTextFixup(Text, sizeof(Placeholder)); | 254 AssemblerFixup *F = createTextFixup(Text, InstSize); |
243 emitFixup(F); | 255 emitFixup(F); |
244 emitInst(Placeholder); | 256 for (SizeT I = 0; I < InstSize; ++I) |
257 Buffer.emit<char>(0); | |
245 } | 258 } |
246 | 259 |
247 void ARM32::AssemblerARM32::emitType01(CondARM32::Cond Cond, uint32_t Type, | 260 void ARM32::AssemblerARM32::emitType01(CondARM32::Cond Cond, uint32_t Type, |
248 uint32_t Opcode, bool SetCc, uint32_t Rn, | 261 uint32_t Opcode, bool SetCc, uint32_t Rn, |
249 uint32_t Rd, uint32_t Imm12) { | 262 uint32_t Rd, uint32_t Imm12) { |
250 assert(isGPRRegisterDefined(Rd)); | 263 assert(isGPRRegisterDefined(Rd)); |
251 // TODO(kschimpf): Remove void cast when MINIMAL build allows. | 264 // TODO(kschimpf): Remove void cast when MINIMAL build allows. |
252 (void)isGPRRegisterDefined(Rd); | 265 (void)isGPRRegisterDefined(Rd); |
253 assert(Cond != CondARM32::kNone); | 266 assert(Cond != CondARM32::kNone); |
254 AssemblerBuffer::EnsureCapacity ensured(&Buffer); | 267 AssemblerBuffer::EnsureCapacity ensured(&Buffer); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 if (Rd == RegARM32::Encoded_Reg_pc) | 493 if (Rd == RegARM32::Encoded_Reg_pc) |
481 // Conditions of rule violated. | 494 // Conditions of rule violated. |
482 return setNeedsTextFixup(); | 495 return setNeedsTextFixup(); |
483 emitType01(Cond, kInstTypeDataImmediate, Sub, SetFlags, Rn, Rd, Src1Value); | 496 emitType01(Cond, kInstTypeDataImmediate, Sub, SetFlags, Rn, Rd, Src1Value); |
484 return; | 497 return; |
485 } | 498 } |
486 } | 499 } |
487 } | 500 } |
488 | 501 |
489 } // end of namespace Ice | 502 } // end of namespace Ice |
OLD | NEW |