| OLD | NEW |
| 1 //===- subzero/src/assembler_ia32.cpp - Assembler for x86-32 -------------===// | 1 //===- subzero/src/assembler_ia32.cpp - Assembler for x86-32 -------------===// |
| 2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 // | 5 // |
| 6 // Modified by the Subzero authors. | 6 // Modified by the Subzero authors. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // The Subzero Code Generator | 10 // The Subzero Code Generator |
| 11 // | 11 // |
| 12 // This file is distributed under the University of Illinois Open Source | 12 // This file is distributed under the University of Illinois Open Source |
| 13 // License. See LICENSE.TXT for details. | 13 // License. See LICENSE.TXT for details. |
| 14 // | 14 // |
| 15 //===----------------------------------------------------------------------===// | 15 //===----------------------------------------------------------------------===// |
| 16 // | 16 // |
| 17 // This file implements the Assembler class for x86-32. | 17 // This file implements the Assembler class for x86-32. |
| 18 // | 18 // |
| 19 //===----------------------------------------------------------------------===// | 19 //===----------------------------------------------------------------------===// |
| 20 | 20 |
| 21 #include "assembler_ia32.h" | 21 #include "assembler_ia32.h" |
| 22 #include "IceCfg.h" | 22 #include "IceCfg.h" |
| 23 #include "IceMemoryRegion.h" | |
| 24 #include "IceOperand.h" | 23 #include "IceOperand.h" |
| 25 | 24 |
| 26 namespace Ice { | 25 namespace Ice { |
| 27 namespace x86 { | 26 namespace x86 { |
| 28 | 27 |
| 29 class DirectCallRelocation : public AssemblerFixup { | 28 class DirectCallRelocation : public AssemblerFixup { |
| 30 DirectCallRelocation(const DirectCallRelocation &) = delete; | 29 DirectCallRelocation(const DirectCallRelocation &) = delete; |
| 31 DirectCallRelocation &operator=(const DirectCallRelocation &) = delete; | 30 DirectCallRelocation &operator=(const DirectCallRelocation &) = delete; |
| 32 | 31 |
| 33 public: | 32 public: |
| 34 static DirectCallRelocation *create(Assembler *Asm, FixupKind Kind, | 33 static DirectCallRelocation *create(Assembler *Asm, FixupKind Kind, |
| 35 const ConstantRelocatable *Sym) { | 34 const ConstantRelocatable *Sym) { |
| 36 return new (Asm->Allocate<DirectCallRelocation>()) | 35 return new (Asm->Allocate<DirectCallRelocation>()) |
| 37 DirectCallRelocation(Kind, Sym); | 36 DirectCallRelocation(Kind, Sym); |
| 38 } | 37 } |
| 39 | 38 |
| 40 void Process(const MemoryRegion ®ion, intptr_t position) override { | |
| 41 // Direct calls are relative to the following instruction on x86. | |
| 42 int32_t pointer = region.Load<int32_t>(position); | |
| 43 int32_t delta = region.start() + position + sizeof(int32_t); | |
| 44 region.Store<int32_t>(position, pointer - delta); | |
| 45 } | |
| 46 | |
| 47 private: | 39 private: |
| 48 DirectCallRelocation(FixupKind Kind, const ConstantRelocatable *Sym) | 40 DirectCallRelocation(FixupKind Kind, const ConstantRelocatable *Sym) |
| 49 : AssemblerFixup(Kind, Sym) {} | 41 : AssemblerFixup(Kind, Sym) {} |
| 50 }; | 42 }; |
| 51 | 43 |
| 52 Address Address::ofConstPool(GlobalContext *Ctx, Assembler *Asm, | 44 Address Address::ofConstPool(GlobalContext *Ctx, Assembler *Asm, |
| 53 const Constant *Imm) { | 45 const Constant *Imm) { |
| 54 // We should make this much lighter-weight. E.g., just record the const pool | 46 // We should make this much lighter-weight. E.g., just record the const pool |
| 55 // entry ID. | 47 // entry ID. |
| 56 std::string Buffer; | 48 std::string Buffer; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 70 #ifndef NDEBUG | 62 #ifndef NDEBUG |
| 71 for (const Label *Label : CfgNodeLabels) { | 63 for (const Label *Label : CfgNodeLabels) { |
| 72 Label->FinalCheck(); | 64 Label->FinalCheck(); |
| 73 } | 65 } |
| 74 for (const Label *Label : LocalLabels) { | 66 for (const Label *Label : LocalLabels) { |
| 75 Label->FinalCheck(); | 67 Label->FinalCheck(); |
| 76 } | 68 } |
| 77 #endif | 69 #endif |
| 78 } | 70 } |
| 79 | 71 |
| 72 void AssemblerX86::alignFunction() { |
| 73 intptr_t Pos = buffer_.GetPosition(); |
| 74 SizeT Align = 1 << getBundleAlignLog2Bytes(); |
| 75 intptr_t Mod = Pos & (Align - 1); |
| 76 if (Mod == 0) { |
| 77 return; |
| 78 } |
| 79 SizeT BytesNeeded = Align - Mod; |
| 80 const SizeT HltSize = 1; |
| 81 while (BytesNeeded > 0) { |
| 82 hlt(); |
| 83 BytesNeeded -= HltSize; |
| 84 } |
| 85 assert((buffer_.GetPosition() & (Align - 1)) == 0); |
| 86 } |
| 87 |
| 80 Label *AssemblerX86::GetOrCreateLabel(SizeT Number, LabelVector &Labels) { | 88 Label *AssemblerX86::GetOrCreateLabel(SizeT Number, LabelVector &Labels) { |
| 81 Label *L = nullptr; | 89 Label *L = nullptr; |
| 82 if (Number == Labels.size()) { | 90 if (Number == Labels.size()) { |
| 83 L = new (this->Allocate<Label>()) Label(); | 91 L = new (this->Allocate<Label>()) Label(); |
| 84 Labels.push_back(L); | 92 Labels.push_back(L); |
| 85 return L; | 93 return L; |
| 86 } | 94 } |
| 87 if (Number > Labels.size()) { | 95 if (Number > Labels.size()) { |
| 88 Labels.resize(Number + 1); | 96 Labels.resize(Number + 1); |
| 89 } | 97 } |
| (...skipping 2430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2520 assert(shifter == RegX8632::Encoded_Reg_ecx); | 2528 assert(shifter == RegX8632::Encoded_Reg_ecx); |
| 2521 (void)shifter; | 2529 (void)shifter; |
| 2522 if (Ty == IceType_i16) | 2530 if (Ty == IceType_i16) |
| 2523 EmitOperandSizeOverride(); | 2531 EmitOperandSizeOverride(); |
| 2524 EmitUint8(isByteSizedArithType(Ty) ? 0xD2 : 0xD3); | 2532 EmitUint8(isByteSizedArithType(Ty) ? 0xD2 : 0xD3); |
| 2525 EmitOperand(rm, operand); | 2533 EmitOperand(rm, operand); |
| 2526 } | 2534 } |
| 2527 | 2535 |
| 2528 } // end of namespace x86 | 2536 } // end of namespace x86 |
| 2529 } // end of namespace Ice | 2537 } // end of namespace Ice |
| OLD | NEW |