| OLD | NEW |
| 1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// | 1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// |
| 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 TargetLoweringX8632 class, which | 10 // This file implements the TargetLoweringX8632 class, which |
| (...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 this->FrameSizeLocals = NextStackOffset - SpillAreaPaddingBytes; | 891 this->FrameSizeLocals = NextStackOffset - SpillAreaPaddingBytes; |
| 892 this->HasComputedFrame = true; | 892 this->HasComputedFrame = true; |
| 893 | 893 |
| 894 // Assign stack offsets to variables that have been linked to spilled | 894 // Assign stack offsets to variables that have been linked to spilled |
| 895 // variables. | 895 // variables. |
| 896 for (Variable *Var : VariablesLinkedToSpillSlots) { | 896 for (Variable *Var : VariablesLinkedToSpillSlots) { |
| 897 Variable *Linked = (llvm::cast<SpillVariable>(Var))->getLinkedTo(); | 897 Variable *Linked = (llvm::cast<SpillVariable>(Var))->getLinkedTo(); |
| 898 Var->setStackOffset(Linked->getStackOffset()); | 898 Var->setStackOffset(Linked->getStackOffset()); |
| 899 } | 899 } |
| 900 | 900 |
| 901 if (Func->getContext()->isVerbose(IceV_Frame)) { | 901 if (ALLOW_DUMP && Func->getContext()->isVerbose(IceV_Frame)) { |
| 902 Ostream &Str = Func->getContext()->getStrDump(); | 902 Ostream &Str = Func->getContext()->getStrDump(); |
| 903 | 903 |
| 904 Str << "Stack layout:\n"; | 904 Str << "Stack layout:\n"; |
| 905 uint32_t EspAdjustmentPaddingSize = | 905 uint32_t EspAdjustmentPaddingSize = |
| 906 SpillAreaSizeBytes - LocalsSpillAreaSize - | 906 SpillAreaSizeBytes - LocalsSpillAreaSize - |
| 907 GlobalsAndSubsequentPaddingSize - SpillAreaPaddingBytes; | 907 GlobalsAndSubsequentPaddingSize - SpillAreaPaddingBytes; |
| 908 Str << " in-args = " << InArgsSizeBytes << " bytes\n" | 908 Str << " in-args = " << InArgsSizeBytes << " bytes\n" |
| 909 << " return address = " << X86_RET_IP_SIZE_BYTES << " bytes\n" | 909 << " return address = " << X86_RET_IP_SIZE_BYTES << " bytes\n" |
| 910 << " preserved registers = " << PreservedRegsSizeBytes << " bytes\n" | 910 << " preserved registers = " << PreservedRegsSizeBytes << " bytes\n" |
| 911 << " spill area padding = " << SpillAreaPaddingBytes << " bytes\n" | 911 << " spill area padding = " << SpillAreaPaddingBytes << " bytes\n" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 static const Type Ty = IceType_f64; | 989 static const Type Ty = IceType_f64; |
| 990 static const char *TypeName; | 990 static const char *TypeName; |
| 991 static const char *AsmTag; | 991 static const char *AsmTag; |
| 992 static const char *PrintfString; | 992 static const char *PrintfString; |
| 993 }; | 993 }; |
| 994 const char *PoolTypeConverter<double>::TypeName = "double"; | 994 const char *PoolTypeConverter<double>::TypeName = "double"; |
| 995 const char *PoolTypeConverter<double>::AsmTag = ".quad"; | 995 const char *PoolTypeConverter<double>::AsmTag = ".quad"; |
| 996 const char *PoolTypeConverter<double>::PrintfString = "0x%llx"; | 996 const char *PoolTypeConverter<double>::PrintfString = "0x%llx"; |
| 997 | 997 |
| 998 template <typename T> void TargetX8632::emitConstantPool() const { | 998 template <typename T> void TargetX8632::emitConstantPool() const { |
| 999 // Note: Still used by emit IAS. |
| 999 Ostream &Str = Ctx->getStrEmit(); | 1000 Ostream &Str = Ctx->getStrEmit(); |
| 1000 Type Ty = T::Ty; | 1001 Type Ty = T::Ty; |
| 1001 SizeT Align = typeAlignInBytes(Ty); | 1002 SizeT Align = typeAlignInBytes(Ty); |
| 1002 ConstantList Pool = Ctx->getConstantPool(Ty); | 1003 ConstantList Pool = Ctx->getConstantPool(Ty); |
| 1003 | 1004 |
| 1004 Str << "\t.section\t.rodata.cst" << Align << ",\"aM\",@progbits," << Align | 1005 Str << "\t.section\t.rodata.cst" << Align << ",\"aM\",@progbits," << Align |
| 1005 << "\n"; | 1006 << "\n"; |
| 1006 Str << "\t.align\t" << Align << "\n"; | 1007 Str << "\t.align\t" << Align << "\n"; |
| 1007 for (Constant *C : Pool) { | 1008 for (Constant *C : Pool) { |
| 1008 typename T::IceType *Const = llvm::cast<typename T::IceType>(C); | 1009 typename T::IceType *Const = llvm::cast<typename T::IceType>(C); |
| 1009 typename T::PrimitiveFpType Value = Const->getValue(); | 1010 typename T::PrimitiveFpType Value = Const->getValue(); |
| 1010 // Use memcpy() to copy bits from Value into RawValue in a way | 1011 // Use memcpy() to copy bits from Value into RawValue in a way |
| 1011 // that avoids breaking strict-aliasing rules. | 1012 // that avoids breaking strict-aliasing rules. |
| 1012 typename T::PrimitiveIntType RawValue; | 1013 typename T::PrimitiveIntType RawValue; |
| 1013 memcpy(&RawValue, &Value, sizeof(Value)); | 1014 memcpy(&RawValue, &Value, sizeof(Value)); |
| 1014 char buf[30]; | 1015 char buf[30]; |
| 1015 int CharsPrinted = | 1016 int CharsPrinted = |
| 1016 snprintf(buf, llvm::array_lengthof(buf), T::PrintfString, RawValue); | 1017 snprintf(buf, llvm::array_lengthof(buf), T::PrintfString, RawValue); |
| 1017 assert(CharsPrinted >= 0 && | 1018 assert(CharsPrinted >= 0 && |
| 1018 (size_t)CharsPrinted < llvm::array_lengthof(buf)); | 1019 (size_t)CharsPrinted < llvm::array_lengthof(buf)); |
| 1019 (void)CharsPrinted; // avoid warnings if asserts are disabled | 1020 (void)CharsPrinted; // avoid warnings if asserts are disabled |
| 1020 Str << ".L$" << Ty << "$" << Const->getPoolEntryID() << ":\n"; | 1021 Str << ".L$" << Ty << "$" << Const->getPoolEntryID() << ":\n"; |
| 1021 Str << "\t" << T::AsmTag << "\t" << buf << "\t# " << T::TypeName << " " | 1022 Str << "\t" << T::AsmTag << "\t" << buf << "\t# " << T::TypeName << " " |
| 1022 << Value << "\n"; | 1023 << Value << "\n"; |
| 1023 } | 1024 } |
| 1024 } | 1025 } |
| 1025 | 1026 |
| 1026 void TargetX8632::emitConstants() const { | 1027 void TargetX8632::emitConstants() const { |
| 1028 // Note: Still used by emit IAS. |
| 1027 emitConstantPool<PoolTypeConverter<float> >(); | 1029 emitConstantPool<PoolTypeConverter<float> >(); |
| 1028 emitConstantPool<PoolTypeConverter<double> >(); | 1030 emitConstantPool<PoolTypeConverter<double> >(); |
| 1029 | 1031 |
| 1030 // No need to emit constants from the int pool since (for x86) they | 1032 // No need to emit constants from the int pool since (for x86) they |
| 1031 // are embedded as immediates in the instructions. | 1033 // are embedded as immediates in the instructions. |
| 1032 } | 1034 } |
| 1033 | 1035 |
| 1034 void TargetX8632::split64(Variable *Var) { | 1036 void TargetX8632::split64(Variable *Var) { |
| 1035 switch (Var->getType()) { | 1037 switch (Var->getType()) { |
| 1036 default: | 1038 default: |
| (...skipping 2517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3554 if (const InstArithmetic *Arith = | 3556 if (const InstArithmetic *Arith = |
| 3555 llvm::dyn_cast_or_null<const InstArithmetic>(Inst)) { | 3557 llvm::dyn_cast_or_null<const InstArithmetic>(Inst)) { |
| 3556 return (Arith->getOp() == InstArithmetic::Add); | 3558 return (Arith->getOp() == InstArithmetic::Add); |
| 3557 } | 3559 } |
| 3558 return false; | 3560 return false; |
| 3559 } | 3561 } |
| 3560 | 3562 |
| 3561 void dumpAddressOpt(const Cfg *Func, const Variable *Base, | 3563 void dumpAddressOpt(const Cfg *Func, const Variable *Base, |
| 3562 const Variable *Index, uint16_t Shift, int32_t Offset, | 3564 const Variable *Index, uint16_t Shift, int32_t Offset, |
| 3563 const Inst *Reason) { | 3565 const Inst *Reason) { |
| 3566 if (!ALLOW_DUMP) |
| 3567 return; |
| 3564 if (!Func->getContext()->isVerbose(IceV_AddrOpt)) | 3568 if (!Func->getContext()->isVerbose(IceV_AddrOpt)) |
| 3565 return; | 3569 return; |
| 3566 Ostream &Str = Func->getContext()->getStrDump(); | 3570 Ostream &Str = Func->getContext()->getStrDump(); |
| 3567 Str << "Instruction: "; | 3571 Str << "Instruction: "; |
| 3568 Reason->dumpDecorated(Func); | 3572 Reason->dumpDecorated(Func); |
| 3569 Str << " results in Base="; | 3573 Str << " results in Base="; |
| 3570 if (Base) | 3574 if (Base) |
| 3571 Base->dump(Func); | 3575 Base->dump(Func); |
| 3572 else | 3576 else |
| 3573 Str << "<null>"; | 3577 Str << "<null>"; |
| (...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4521 // TODO(stichnot): We may need to consider all source | 4525 // TODO(stichnot): We may need to consider all source |
| 4522 // operands, not just the first one, if using 3-address | 4526 // operands, not just the first one, if using 3-address |
| 4523 // instructions. | 4527 // instructions. |
| 4524 if (Inst->getSrcSize() > 0 && Inst->getSrc(0) == Dest) | 4528 if (Inst->getSrcSize() > 0 && Inst->getSrc(0) == Dest) |
| 4525 Inst->setDestNonKillable(); | 4529 Inst->setDestNonKillable(); |
| 4526 } | 4530 } |
| 4527 } | 4531 } |
| 4528 } | 4532 } |
| 4529 | 4533 |
| 4530 template <> void ConstantInteger32::emit(GlobalContext *Ctx) const { | 4534 template <> void ConstantInteger32::emit(GlobalContext *Ctx) const { |
| 4535 if (!ALLOW_DUMP) |
| 4536 return; |
| 4531 Ostream &Str = Ctx->getStrEmit(); | 4537 Ostream &Str = Ctx->getStrEmit(); |
| 4532 Str << "$" << (int32_t)getValue(); | 4538 Str << "$" << (int32_t)getValue(); |
| 4533 } | 4539 } |
| 4534 | 4540 |
| 4535 template <> void ConstantInteger64::emit(GlobalContext *) const { | 4541 template <> void ConstantInteger64::emit(GlobalContext *) const { |
| 4536 llvm_unreachable("Not expecting to emit 64-bit integers"); | 4542 llvm_unreachable("Not expecting to emit 64-bit integers"); |
| 4537 } | 4543 } |
| 4538 | 4544 |
| 4539 template <> void ConstantFloat::emit(GlobalContext *Ctx) const { | 4545 template <> void ConstantFloat::emit(GlobalContext *Ctx) const { |
| 4546 if (!ALLOW_DUMP) |
| 4547 return; |
| 4540 Ostream &Str = Ctx->getStrEmit(); | 4548 Ostream &Str = Ctx->getStrEmit(); |
| 4541 Str << ".L$" << IceType_f32 << "$" << getPoolEntryID(); | 4549 Str << ".L$" << IceType_f32 << "$" << getPoolEntryID(); |
| 4542 } | 4550 } |
| 4543 | 4551 |
| 4544 template <> void ConstantDouble::emit(GlobalContext *Ctx) const { | 4552 template <> void ConstantDouble::emit(GlobalContext *Ctx) const { |
| 4553 if (!ALLOW_DUMP) |
| 4554 return; |
| 4545 Ostream &Str = Ctx->getStrEmit(); | 4555 Ostream &Str = Ctx->getStrEmit(); |
| 4546 Str << ".L$" << IceType_f64 << "$" << getPoolEntryID(); | 4556 Str << ".L$" << IceType_f64 << "$" << getPoolEntryID(); |
| 4547 } | 4557 } |
| 4548 | 4558 |
| 4549 void ConstantUndef::emit(GlobalContext *) const { | 4559 void ConstantUndef::emit(GlobalContext *) const { |
| 4550 llvm_unreachable("undef value encountered by emitter."); | 4560 llvm_unreachable("undef value encountered by emitter."); |
| 4551 } | 4561 } |
| 4552 | 4562 |
| 4553 TargetGlobalInitX8632::TargetGlobalInitX8632(GlobalContext *Ctx) | 4563 TargetGlobalInitX8632::TargetGlobalInitX8632(GlobalContext *Ctx) |
| 4554 : TargetGlobalInitLowering(Ctx) {} | 4564 : TargetGlobalInitLowering(Ctx) {} |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4640 } else if (IsConstant || IsExternal) | 4650 } else if (IsConstant || IsExternal) |
| 4641 Str << "\t.zero\t" << Size << "\n"; | 4651 Str << "\t.zero\t" << Size << "\n"; |
| 4642 // Size is part of .comm. | 4652 // Size is part of .comm. |
| 4643 | 4653 |
| 4644 if (IsConstant || HasNonzeroInitializer || IsExternal) | 4654 if (IsConstant || HasNonzeroInitializer || IsExternal) |
| 4645 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; | 4655 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; |
| 4646 // Size is part of .comm. | 4656 // Size is part of .comm. |
| 4647 } | 4657 } |
| 4648 | 4658 |
| 4649 } // end of namespace Ice | 4659 } // end of namespace Ice |
| OLD | NEW |