| OLD | NEW |
| 1 //===- subzero/src/IceAssemblerX8664.h - Assembler for x86-64 -*- C++ -*---===// | 1 //===- subzero/src/IceAssemblerX8664.h - Assembler for x86-64 ---*- C++ -*-===// |
| 2 // | 2 // |
| 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 |
| 5 // BSD-style license that can be found in the LICENSE file. |
| 6 // |
| 7 // Modified by the Subzero authors. |
| 8 // |
| 9 //===----------------------------------------------------------------------===// |
| 10 // |
| 3 // The Subzero Code Generator | 11 // The Subzero Code Generator |
| 4 // | 12 // |
| 5 // This file is distributed under the University of Illinois Open Source | 13 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 14 // License. See LICENSE.TXT for details. |
| 7 // | 15 // |
| 8 //===----------------------------------------------------------------------===// | 16 //===----------------------------------------------------------------------===// |
| 9 /// | 17 /// |
| 10 /// \file | 18 /// \file |
| 11 /// This file implements the Assembler class for x86-64. | 19 /// This file implements the Assembler class for x86-64. |
| 12 /// | 20 /// |
| 13 //===----------------------------------------------------------------------===// | 21 //===----------------------------------------------------------------------===// |
| 14 | 22 |
| 15 #ifndef SUBZERO_SRC_ICEASSEMBLERX8664_H | 23 #ifndef SUBZERO_SRC_ICEASSEMBLERX8664_H |
| 16 #define SUBZERO_SRC_ICEASSEMBLERX8664_H | 24 #define SUBZERO_SRC_ICEASSEMBLERX8664_H |
| 17 | 25 |
| 18 #include "IceAssembler.h" | 26 #include "IceAssembler.h" |
| 27 #include "IceAssemblerX86Base.h" |
| 19 #include "IceDefs.h" | 28 #include "IceDefs.h" |
| 29 #include "IceOperand.h" |
| 30 #include "IceTargetLoweringX8664Traits.h" |
| 31 #include "IceTypes.h" |
| 32 #include "IceUtils.h" |
| 33 |
| 34 #include <type_traits> |
| 20 | 35 |
| 21 namespace Ice { | 36 namespace Ice { |
| 37 |
| 38 class TargetX8664; |
| 39 |
| 22 namespace X8664 { | 40 namespace X8664 { |
| 23 | 41 |
| 24 class AssemblerX8664 final : public Assembler { | 42 using Immediate = ::Ice::X86Internal::Immediate; |
| 43 using Label = ::Ice::X86Internal::Label; |
| 44 |
| 45 class AssemblerX8664 : public X86Internal::AssemblerX86Base<TargetX8664> { |
| 25 AssemblerX8664(const AssemblerX8664 &) = delete; | 46 AssemblerX8664(const AssemblerX8664 &) = delete; |
| 26 AssemblerX8664 &operator=(const AssemblerX8664 &) = delete; | 47 AssemblerX8664 &operator=(const AssemblerX8664 &) = delete; |
| 27 | 48 |
| 28 public: | 49 public: |
| 29 explicit AssemblerX8664(bool use_far_branches = false) | 50 explicit AssemblerX8664(bool use_far_branches = false) |
| 30 : Assembler(Asm_X8664) { | 51 : X86Internal::AssemblerX86Base<TargetX8664>(Asm_X8664, |
| 31 assert(!use_far_branches); | 52 use_far_branches) {} |
| 32 (void)use_far_branches; | |
| 33 llvm::report_fatal_error("Not yet implemented"); | |
| 34 } | |
| 35 | |
| 36 ~AssemblerX8664() override = default; | 53 ~AssemblerX8664() override = default; |
| 37 | 54 |
| 38 void alignFunction() override; | |
| 39 void padWithNop(intptr_t Padding) override; | |
| 40 SizeT getBundleAlignLog2Bytes() const override; | |
| 41 const char *getNonExecPadDirective() const override; | |
| 42 llvm::ArrayRef<uint8_t> getNonExecBundlePadding() const override; | |
| 43 void bindCfgNodeLabel(SizeT NodeNumber) override; | |
| 44 bool fixupIsPCRel(FixupKind Kind) const override; | |
| 45 | |
| 46 static bool classof(const Assembler *Asm) { | 55 static bool classof(const Assembler *Asm) { |
| 47 return Asm->getKind() == Asm_X8664; | 56 return Asm->getKind() == Asm_X8664; |
| 48 } | 57 } |
| 58 |
| 59 private: |
| 60 friend class X86Internal::AssemblerX86Base<TargetX8664>; |
| 61 |
| 62 template <typename RegType> |
| 63 Traits::GPRRegister gprEncoding(const RegType Reg) { |
| 64 return static_cast<Traits::GPRRegister>(static_cast<uint8_t>(Reg) & ~0x08); |
| 65 } |
| 66 |
| 67 template <typename RegType> struct IsGPR { |
| 68 static constexpr bool value = |
| 69 std::is_same<typename std::decay<RegType>::type, |
| 70 Traits::ByteRegister>::value || |
| 71 std::is_same<typename std::decay<RegType>::type, |
| 72 Traits::GPRRegister>::value; |
| 73 }; |
| 74 |
| 75 template <typename RegType, typename RmType> |
| 76 void emitRexRB(const Type Ty, const RegType Reg, const RmType Rm) { |
| 77 uint8_t W = |
| 78 (Ty == IceType_i64) ? Traits::Operand::RexW : Traits::Operand::RexNone; |
| 79 uint8_t R = (Reg & 0x08) ? Traits::Operand::RexR : Traits::Operand::RexNone; |
| 80 uint8_t B = (Rm & 0x08) ? Traits::Operand::RexB : Traits::Operand::RexNone; |
| 81 static constexpr bool RegIsGPR = IsGPR<RegType>::value; |
| 82 static constexpr bool RmIsGPR = IsGPR<RmType>::value; |
| 83 bool AccessesNewByteRegister = |
| 84 (RegIsGPR || RmIsGPR) && isByteSizedType(Ty) && |
| 85 ((((Reg & 0x04) != 0) && ((Reg & 0x08) == 0)) || |
| 86 ((Rm & 0x04) && !(Rm & 0x08))); |
| 87 uint8_t Rex = AccessesNewByteRegister ? Traits::Operand::RexBase |
| 88 : Traits::Operand::RexNone; |
| 89 uint8_t Prefix = Rex | W | R | B; |
| 90 if (Prefix != Traits::Operand::RexNone) { |
| 91 emitUint8(Prefix); |
| 92 } |
| 93 } |
| 94 |
| 95 template <typename RegType> void emitRexB(const Type Ty, const RegType Reg) { |
| 96 uint8_t W = |
| 97 (Ty == IceType_i64) ? Traits::Operand::RexW : Traits::Operand::RexNone; |
| 98 uint8_t B = (Reg & 0x08) ? Traits::Operand::RexB : Traits::Operand::RexNone; |
| 99 static constexpr bool RegIsGPR = IsGPR<RegType>::value; |
| 100 bool AccessesNewByteRegister = RegIsGPR && isByteSizedType(Ty) && |
| 101 ((Reg & 0x04) != 0) && ((Reg & 0x08) == 0); |
| 102 uint8_t Rex = AccessesNewByteRegister ? Traits::Operand::RexBase |
| 103 : Traits::Operand::RexNone; |
| 104 uint8_t Prefix = Rex | W | B; |
| 105 if (Prefix != Traits::Operand::RexNone) { |
| 106 emitUint8(Prefix); |
| 107 } |
| 108 } |
| 109 |
| 110 template <typename RegType> |
| 111 void emitRex(const Type Ty, const Traits::Address &Addr, const RegType Reg) { |
| 112 uint8_t W = |
| 113 (Ty == IceType_i64) ? Traits::Operand::RexW : Traits::Operand::RexNone; |
| 114 uint8_t R = (Reg & 0x08) ? Traits::Operand::RexR : Traits::Operand::RexNone; |
| 115 uint8_t X = Addr.rexX(); |
| 116 uint8_t B = Addr.rexB(); |
| 117 static constexpr bool RegIsGPR = IsGPR<RegType>::value; |
| 118 bool AccessesNewByteRegister = RegIsGPR && isByteSizedType(Ty) && |
| 119 ((Reg & 0x04) != 0) && ((Reg & 0x08) == 0); |
| 120 uint8_t Rex = AccessesNewByteRegister ? Traits::Operand::RexBase |
| 121 : Traits::Operand::RexNone; |
| 122 uint8_t Prefix = Rex | W | R | X | B; |
| 123 if (Prefix != Traits::Operand::RexNone) { |
| 124 emitUint8(Prefix); |
| 125 } |
| 126 } |
| 49 }; | 127 }; |
| 50 | 128 |
| 51 } // end of namespace X8664 | 129 } // end of namespace X8664 |
| 52 } // end of namespace Ice | 130 } // end of namespace Ice |
| 53 | 131 |
| 54 #endif // SUBZERO_SRC_ICEASSEMBLERX8664_H | 132 #endif // SUBZERO_SRC_ICEASSEMBLERX8664_H |
| OLD | NEW |