| 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 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 this->FrameSizeLocals = NextStackOffset - SpillAreaPaddingBytes; | 872 this->FrameSizeLocals = NextStackOffset - SpillAreaPaddingBytes; |
| 873 this->HasComputedFrame = true; | 873 this->HasComputedFrame = true; |
| 874 | 874 |
| 875 // Assign stack offsets to variables that have been linked to spilled | 875 // Assign stack offsets to variables that have been linked to spilled |
| 876 // variables. | 876 // variables. |
| 877 for (Variable *Var : VariablesLinkedToSpillSlots) { | 877 for (Variable *Var : VariablesLinkedToSpillSlots) { |
| 878 Variable *Linked = (llvm::cast<SpillVariable>(Var))->getLinkedTo(); | 878 Variable *Linked = (llvm::cast<SpillVariable>(Var))->getLinkedTo(); |
| 879 Var->setStackOffset(Linked->getStackOffset()); | 879 Var->setStackOffset(Linked->getStackOffset()); |
| 880 } | 880 } |
| 881 | 881 |
| 882 if (Func->getContext()->isVerbose(IceV_Frame)) { | 882 if (ALLOW_DUMP && Func->getContext()->isVerbose(IceV_Frame)) { |
| 883 Ostream &Str = Func->getContext()->getStrDump(); | 883 Ostream &Str = Func->getContext()->getStrDump(); |
| 884 | 884 |
| 885 Str << "Stack layout:\n"; | 885 Str << "Stack layout:\n"; |
| 886 uint32_t EspAdjustmentPaddingSize = | 886 uint32_t EspAdjustmentPaddingSize = |
| 887 SpillAreaSizeBytes - LocalsSpillAreaSize - | 887 SpillAreaSizeBytes - LocalsSpillAreaSize - |
| 888 GlobalsAndSubsequentPaddingSize - SpillAreaPaddingBytes; | 888 GlobalsAndSubsequentPaddingSize - SpillAreaPaddingBytes; |
| 889 Str << " in-args = " << InArgsSizeBytes << " bytes\n" | 889 Str << " in-args = " << InArgsSizeBytes << " bytes\n" |
| 890 << " return address = " << X86_RET_IP_SIZE_BYTES << " bytes\n" | 890 << " return address = " << X86_RET_IP_SIZE_BYTES << " bytes\n" |
| 891 << " preserved registers = " << PreservedRegsSizeBytes << " bytes\n" | 891 << " preserved registers = " << PreservedRegsSizeBytes << " bytes\n" |
| 892 << " spill area padding = " << SpillAreaPaddingBytes << " bytes\n" | 892 << " spill area padding = " << SpillAreaPaddingBytes << " bytes\n" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 static const Type Ty = IceType_f64; | 970 static const Type Ty = IceType_f64; |
| 971 static const char *TypeName; | 971 static const char *TypeName; |
| 972 static const char *AsmTag; | 972 static const char *AsmTag; |
| 973 static const char *PrintfString; | 973 static const char *PrintfString; |
| 974 }; | 974 }; |
| 975 const char *PoolTypeConverter<double>::TypeName = "double"; | 975 const char *PoolTypeConverter<double>::TypeName = "double"; |
| 976 const char *PoolTypeConverter<double>::AsmTag = ".quad"; | 976 const char *PoolTypeConverter<double>::AsmTag = ".quad"; |
| 977 const char *PoolTypeConverter<double>::PrintfString = "0x%llx"; | 977 const char *PoolTypeConverter<double>::PrintfString = "0x%llx"; |
| 978 | 978 |
| 979 template <typename T> void TargetX8632::emitConstantPool() const { | 979 template <typename T> void TargetX8632::emitConstantPool() const { |
| 980 // Note: Still used by emit IAS. |
| 980 Ostream &Str = Ctx->getStrEmit(); | 981 Ostream &Str = Ctx->getStrEmit(); |
| 981 Type Ty = T::Ty; | 982 Type Ty = T::Ty; |
| 982 SizeT Align = typeAlignInBytes(Ty); | 983 SizeT Align = typeAlignInBytes(Ty); |
| 983 ConstantList Pool = Ctx->getConstantPool(Ty); | 984 ConstantList Pool = Ctx->getConstantPool(Ty); |
| 984 | 985 |
| 985 Str << "\t.section\t.rodata.cst" << Align << ",\"aM\",@progbits," << Align | 986 Str << "\t.section\t.rodata.cst" << Align << ",\"aM\",@progbits," << Align |
| 986 << "\n"; | 987 << "\n"; |
| 987 Str << "\t.align\t" << Align << "\n"; | 988 Str << "\t.align\t" << Align << "\n"; |
| 988 for (Constant *C : Pool) { | 989 for (Constant *C : Pool) { |
| 989 typename T::IceType *Const = llvm::cast<typename T::IceType>(C); | 990 typename T::IceType *Const = llvm::cast<typename T::IceType>(C); |
| 990 typename T::PrimitiveFpType Value = Const->getValue(); | 991 typename T::PrimitiveFpType Value = Const->getValue(); |
| 991 // Use memcpy() to copy bits from Value into RawValue in a way | 992 // Use memcpy() to copy bits from Value into RawValue in a way |
| 992 // that avoids breaking strict-aliasing rules. | 993 // that avoids breaking strict-aliasing rules. |
| 993 typename T::PrimitiveIntType RawValue; | 994 typename T::PrimitiveIntType RawValue; |
| 994 memcpy(&RawValue, &Value, sizeof(Value)); | 995 memcpy(&RawValue, &Value, sizeof(Value)); |
| 995 char buf[30]; | 996 char buf[30]; |
| 996 int CharsPrinted = | 997 int CharsPrinted = |
| 997 snprintf(buf, llvm::array_lengthof(buf), T::PrintfString, RawValue); | 998 snprintf(buf, llvm::array_lengthof(buf), T::PrintfString, RawValue); |
| 998 assert(CharsPrinted >= 0 && | 999 assert(CharsPrinted >= 0 && |
| 999 (size_t)CharsPrinted < llvm::array_lengthof(buf)); | 1000 (size_t)CharsPrinted < llvm::array_lengthof(buf)); |
| 1000 (void)CharsPrinted; // avoid warnings if asserts are disabled | 1001 (void)CharsPrinted; // avoid warnings if asserts are disabled |
| 1001 Str << ".L$" << Ty << "$" << Const->getPoolEntryID() << ":\n"; | 1002 Str << ".L$" << Ty << "$" << Const->getPoolEntryID() << ":\n"; |
| 1002 Str << "\t" << T::AsmTag << "\t" << buf << "\t# " << T::TypeName << " " | 1003 Str << "\t" << T::AsmTag << "\t" << buf << "\t# " << T::TypeName << " " |
| 1003 << Value << "\n"; | 1004 << Value << "\n"; |
| 1004 } | 1005 } |
| 1005 } | 1006 } |
| 1006 | 1007 |
| 1007 void TargetX8632::emitConstants() const { | 1008 void TargetX8632::emitConstants() const { |
| 1009 // Note: Still used by emit IAS. |
| 1008 emitConstantPool<PoolTypeConverter<float> >(); | 1010 emitConstantPool<PoolTypeConverter<float> >(); |
| 1009 emitConstantPool<PoolTypeConverter<double> >(); | 1011 emitConstantPool<PoolTypeConverter<double> >(); |
| 1010 | 1012 |
| 1011 // No need to emit constants from the int pool since (for x86) they | 1013 // No need to emit constants from the int pool since (for x86) they |
| 1012 // are embedded as immediates in the instructions. | 1014 // are embedded as immediates in the instructions. |
| 1013 } | 1015 } |
| 1014 | 1016 |
| 1015 void TargetX8632::split64(Variable *Var) { | 1017 void TargetX8632::split64(Variable *Var) { |
| 1016 switch (Var->getType()) { | 1018 switch (Var->getType()) { |
| 1017 default: | 1019 default: |
| (...skipping 2522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3540 if (const InstArithmetic *Arith = | 3542 if (const InstArithmetic *Arith = |
| 3541 llvm::dyn_cast_or_null<const InstArithmetic>(Inst)) { | 3543 llvm::dyn_cast_or_null<const InstArithmetic>(Inst)) { |
| 3542 return (Arith->getOp() == InstArithmetic::Add); | 3544 return (Arith->getOp() == InstArithmetic::Add); |
| 3543 } | 3545 } |
| 3544 return false; | 3546 return false; |
| 3545 } | 3547 } |
| 3546 | 3548 |
| 3547 void dumpAddressOpt(const Cfg *Func, const Variable *Base, | 3549 void dumpAddressOpt(const Cfg *Func, const Variable *Base, |
| 3548 const Variable *Index, uint16_t Shift, int32_t Offset, | 3550 const Variable *Index, uint16_t Shift, int32_t Offset, |
| 3549 const Inst *Reason) { | 3551 const Inst *Reason) { |
| 3552 if (!ALLOW_DUMP) |
| 3553 return; |
| 3550 if (!Func->getContext()->isVerbose(IceV_AddrOpt)) | 3554 if (!Func->getContext()->isVerbose(IceV_AddrOpt)) |
| 3551 return; | 3555 return; |
| 3552 Ostream &Str = Func->getContext()->getStrDump(); | 3556 Ostream &Str = Func->getContext()->getStrDump(); |
| 3553 Str << "Instruction: "; | 3557 Str << "Instruction: "; |
| 3554 Reason->dumpDecorated(Func); | 3558 Reason->dumpDecorated(Func); |
| 3555 Str << " results in Base="; | 3559 Str << " results in Base="; |
| 3556 if (Base) | 3560 if (Base) |
| 3557 Base->dump(Func); | 3561 Base->dump(Func); |
| 3558 else | 3562 else |
| 3559 Str << "<null>"; | 3563 Str << "<null>"; |
| (...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4605 FreedRegisters[RegNum] = true; | 4609 FreedRegisters[RegNum] = true; |
| 4606 } | 4610 } |
| 4607 } | 4611 } |
| 4608 } | 4612 } |
| 4609 } | 4613 } |
| 4610 AvailableRegisters |= FreedRegisters; | 4614 AvailableRegisters |= FreedRegisters; |
| 4611 } | 4615 } |
| 4612 } | 4616 } |
| 4613 | 4617 |
| 4614 template <> void ConstantInteger32::emit(GlobalContext *Ctx) const { | 4618 template <> void ConstantInteger32::emit(GlobalContext *Ctx) const { |
| 4619 if (!ALLOW_DUMP) |
| 4620 return; |
| 4615 Ostream &Str = Ctx->getStrEmit(); | 4621 Ostream &Str = Ctx->getStrEmit(); |
| 4616 Str << "$" << (int32_t)getValue(); | 4622 Str << "$" << (int32_t)getValue(); |
| 4617 } | 4623 } |
| 4618 | 4624 |
| 4619 template <> void ConstantInteger64::emit(GlobalContext *) const { | 4625 template <> void ConstantInteger64::emit(GlobalContext *) const { |
| 4620 llvm_unreachable("Not expecting to emit 64-bit integers"); | 4626 llvm_unreachable("Not expecting to emit 64-bit integers"); |
| 4621 } | 4627 } |
| 4622 | 4628 |
| 4623 template <> void ConstantFloat::emit(GlobalContext *Ctx) const { | 4629 template <> void ConstantFloat::emit(GlobalContext *Ctx) const { |
| 4630 if (!ALLOW_DUMP) |
| 4631 return; |
| 4624 Ostream &Str = Ctx->getStrEmit(); | 4632 Ostream &Str = Ctx->getStrEmit(); |
| 4625 Str << ".L$" << IceType_f32 << "$" << getPoolEntryID(); | 4633 Str << ".L$" << IceType_f32 << "$" << getPoolEntryID(); |
| 4626 } | 4634 } |
| 4627 | 4635 |
| 4628 template <> void ConstantDouble::emit(GlobalContext *Ctx) const { | 4636 template <> void ConstantDouble::emit(GlobalContext *Ctx) const { |
| 4637 if (!ALLOW_DUMP) |
| 4638 return; |
| 4629 Ostream &Str = Ctx->getStrEmit(); | 4639 Ostream &Str = Ctx->getStrEmit(); |
| 4630 Str << ".L$" << IceType_f64 << "$" << getPoolEntryID(); | 4640 Str << ".L$" << IceType_f64 << "$" << getPoolEntryID(); |
| 4631 } | 4641 } |
| 4632 | 4642 |
| 4633 void ConstantUndef::emit(GlobalContext *) const { | 4643 void ConstantUndef::emit(GlobalContext *) const { |
| 4634 llvm_unreachable("undef value encountered by emitter."); | 4644 llvm_unreachable("undef value encountered by emitter."); |
| 4635 } | 4645 } |
| 4636 | 4646 |
| 4637 TargetGlobalInitX8632::TargetGlobalInitX8632(GlobalContext *Ctx) | 4647 TargetGlobalInitX8632::TargetGlobalInitX8632(GlobalContext *Ctx) |
| 4638 : TargetGlobalInitLowering(Ctx) {} | 4648 : TargetGlobalInitLowering(Ctx) {} |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4724 } else if (IsConstant || IsExternal) | 4734 } else if (IsConstant || IsExternal) |
| 4725 Str << "\t.zero\t" << Size << "\n"; | 4735 Str << "\t.zero\t" << Size << "\n"; |
| 4726 // Size is part of .comm. | 4736 // Size is part of .comm. |
| 4727 | 4737 |
| 4728 if (IsConstant || HasNonzeroInitializer || IsExternal) | 4738 if (IsConstant || HasNonzeroInitializer || IsExternal) |
| 4729 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; | 4739 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; |
| 4730 // Size is part of .comm. | 4740 // Size is part of .comm. |
| 4731 } | 4741 } |
| 4732 | 4742 |
| 4733 } // end of namespace Ice | 4743 } // end of namespace Ice |
| OLD | NEW |