OLD | NEW |
1 //===- subzero/src/IceInstX8632.cpp - X86-32 instruction implementation ---===// | 1 //===- subzero/src/IceInstX8632.cpp - X86-32 instruction implementation ---===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file implements the InstX8632 and OperandX8632 classes, | 10 // This file implements the InstX8632 and OperandX8632 classes, |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 Str << "\n"; | 961 Str << "\n"; |
962 } | 962 } |
963 | 963 |
964 template <> void InstX8632Mov::emit(const Cfg *Func) const { | 964 template <> void InstX8632Mov::emit(const Cfg *Func) const { |
965 Ostream &Str = Func->getContext()->getStrEmit(); | 965 Ostream &Str = Func->getContext()->getStrEmit(); |
966 assert(getSrcSize() == 1); | 966 assert(getSrcSize() == 1); |
967 Operand *Src = getSrc(0); | 967 Operand *Src = getSrc(0); |
968 // The llvm-mc assembler using Intel syntax has a bug in which "mov | 968 // The llvm-mc assembler using Intel syntax has a bug in which "mov |
969 // reg, RelocatableConstant" does not generate the right instruction | 969 // reg, RelocatableConstant" does not generate the right instruction |
970 // with a relocation. To work around, we emit "lea reg, | 970 // with a relocation. To work around, we emit "lea reg, |
971 // [RelocatableConstant]". Also, the lowering and legalization is | 971 // RelocatableConstant". Also, the lowering and legalization is |
972 // changed to allow relocatable constants only in Assign and Call | 972 // changed to allow relocatable constants only in Assign and Call |
973 // instructions or in Mem operands. TODO(stichnot): remove LEAHACK | 973 // instructions or in Mem operands. TODO(stichnot): remove LEAHACK |
974 // once a proper emitter is used. | 974 // once a proper emitter is used. |
| 975 // |
| 976 // In addition, llvm-mc doesn't like "lea eax, bp" or "lea eax, Sp" |
| 977 // or "lea eax, flags" etc., when the relocatable constant name is a |
| 978 // reserved word. The hack-on-top-of-hack is to temporarily drop |
| 979 // into AT&T syntax for this lea instruction. |
975 bool UseLeaHack = llvm::isa<ConstantRelocatable>(Src); | 980 bool UseLeaHack = llvm::isa<ConstantRelocatable>(Src); |
976 Str << "\t"; | 981 if (UseLeaHack) { |
977 if (UseLeaHack) | 982 Str << ".att_syntax\n"; |
978 Str << "lea"; | 983 Str << "\tleal"; |
979 else | 984 } else { |
980 Str << "mov" << TypeX8632Attributes[getDest()->getType()].SdSsString; | 985 Str << "\tmov" << TypeX8632Attributes[getDest()->getType()].SdSsString; |
| 986 } |
981 Str << "\t"; | 987 Str << "\t"; |
982 // For an integer truncation operation, src is wider than dest. | 988 // For an integer truncation operation, src is wider than dest. |
983 // Ideally, we use a mov instruction whose data width matches the | 989 // Ideally, we use a mov instruction whose data width matches the |
984 // narrower dest. This is a problem if e.g. src is a register like | 990 // narrower dest. This is a problem if e.g. src is a register like |
985 // esi or si where there is no 8-bit version of the register. To be | 991 // esi or si where there is no 8-bit version of the register. To be |
986 // safe, we instead widen the dest to match src. This works even | 992 // safe, we instead widen the dest to match src. This works even |
987 // for stack-allocated dest variables because typeWidthOnStack() | 993 // for stack-allocated dest variables because typeWidthOnStack() |
988 // pads to a 4-byte boundary even if only a lower portion is used. | 994 // pads to a 4-byte boundary even if only a lower portion is used. |
989 // TODO: This assert disallows usages such as copying a floating point | 995 // TODO: This assert disallows usages such as copying a floating point |
990 // value between a vector and a scalar (which movss is used for). | 996 // value between a vector and a scalar (which movss is used for). |
991 // Clean this up. | 997 // Clean this up. |
992 assert(Func->getTarget()->typeWidthInBytesOnStack(getDest()->getType()) == | 998 assert(Func->getTarget()->typeWidthInBytesOnStack(getDest()->getType()) == |
993 Func->getTarget()->typeWidthInBytesOnStack(Src->getType())); | 999 Func->getTarget()->typeWidthInBytesOnStack(Src->getType())); |
994 getDest()->asType(Src->getType()).emit(Func); | 1000 if (UseLeaHack) { |
995 Str << ", "; | 1001 Src->emit(Func); |
996 Src->emit(Func); | 1002 Str << ", %"; |
997 Str << "\n"; | 1003 getDest()->emit(Func); |
| 1004 Str << "\n"; |
| 1005 Str << ".intel_syntax\n"; |
| 1006 } else { |
| 1007 getDest()->asType(Src->getType()).emit(Func); |
| 1008 Str << ", "; |
| 1009 Src->emit(Func); |
| 1010 Str << "\n"; |
| 1011 } |
998 } | 1012 } |
999 | 1013 |
1000 template <> void InstX8632Movp::emit(const Cfg *Func) const { | 1014 template <> void InstX8632Movp::emit(const Cfg *Func) const { |
1001 // TODO(wala,stichnot): movups works with all vector operands, but | 1015 // TODO(wala,stichnot): movups works with all vector operands, but |
1002 // there exist other instructions (movaps, movdqa, movdqu) that may | 1016 // there exist other instructions (movaps, movdqa, movdqu) that may |
1003 // perform better, depending on the data type and alignment of the | 1017 // perform better, depending on the data type and alignment of the |
1004 // operands. | 1018 // operands. |
1005 Ostream &Str = Func->getContext()->getStrEmit(); | 1019 Ostream &Str = Func->getContext()->getStrEmit(); |
1006 assert(getSrcSize() == 1); | 1020 assert(getSrcSize() == 1); |
1007 Str << "\tmovups\t"; | 1021 Str << "\tmovups\t"; |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 default: | 1473 default: |
1460 Str << "???"; | 1474 Str << "???"; |
1461 break; | 1475 break; |
1462 } | 1476 } |
1463 Str << "("; | 1477 Str << "("; |
1464 Var->dump(Func); | 1478 Var->dump(Func); |
1465 Str << ")"; | 1479 Str << ")"; |
1466 } | 1480 } |
1467 | 1481 |
1468 } // end of namespace Ice | 1482 } // end of namespace Ice |
OLD | NEW |