diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp index 2a42bd5af90227470d06bd7a3903ba3822875a13..ac36757bb03dab7f3848e45afe3f38b7f7400919 100644 --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -611,6 +611,10 @@ void PEI::RecordCalleeSaveRegisterAndOffset(MachineFunction &MF, std::vectorgetDwarfRegNum(Reg, true); std::string key = std::string("DwarfReg") + std::to_string(DwarfRegNum); std::string value = std::to_string(Offset); + LLVM_DEBUG(dbgs() << "RecordCalleeSaveRegisterAndOffset DwarfRegNum:" + << DwarfRegNum << " key:" << key + << " value:" << value + << "]\n"); Attribute attr = Attribute::get(func.getContext(), key.c_str(), value.c_str()); func.addAttribute(AttributeList::FunctionIndex, attr); } @@ -834,7 +838,6 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &MF) { // Skew to be applied to alignment. unsigned Skew = TFI.getStackAlignmentSkew(MF); - #ifdef EXPENSIVE_CHECKS for (unsigned i = 0, e = MFI.getObjectIndexEnd(); i != e; ++i) if (!MFI.isDeadObjectIndex(i) && @@ -911,7 +914,7 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &MF) { #ifdef ARK_GC_SUPPORT int CalleeSavedFrameSize = 0; Triple::ArchType archType = TFI.GetArkSupportTarget(); - if (archType != Triple::UnknownArch && TFI.hasFP(MF)) { + if (archType == Triple::aarch64 && TFI.hasFP(MF)) { int fpPosition = TFI.GetFixedFpPosition(); int slotSize = sizeof(uint64_t); int fpToCallerSpDelta = 0; @@ -962,6 +965,32 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &MF) { CalleeSavedFrameSize = TFI.GetFrameReserveSize(MF); Offset += CalleeSavedFrameSize; } + + if ((archType == Triple::x86_64) && TFI.hasFP(MF)) { + // Determine which of the registers in the callee save list should be saved. + int fpPosition = TFI.GetFixedFpPosition(); + int fpToCallerSpDelta = 0; + int slotSize = sizeof(uint64_t); + if (fpPosition >= 0) { + fpToCallerSpDelta = fpPosition * slotSize; + } else { + fpToCallerSpDelta = FixedCSEnd + (fpPosition + 1) * slotSize; + } + Function &func = const_cast(MF.getFunction()); + Attribute attr = Attribute::get(func.getContext(), "fpToCallerSpDelta", std::to_string(fpToCallerSpDelta).c_str()); + func.addAttribute(AttributeList::FunctionIndex, attr); + + CalleeSavedFrameSize = TFI.GetFrameReserveSize(MF); + std::vector &CSI = MFI.getCalleeSavedInfo(); + LLVM_DEBUG(dbgs() << " CSI size: " << CSI.size() << " CalleeSavedFrameSize " << CalleeSavedFrameSize << "\n"); + // if callee-saved is empty, the reserved-size can't be passed to the computation of local zone + // because the assignCalleeSavedSpillSlots() directly return. + // Otherwise, the reserved-size don't need to add to the computation of local zone because it has been considered + // while computing the offsets of callee-saved-zone that will be passed to the computation of local-zone + if (CSI.empty()) { + Offset += CalleeSavedFrameSize; + } + } #endif // Make sure the special register scavenging spill slot is closest to the diff --git a/llvm/lib/Target/X86/X86FrameLowering.cpp b/llvm/lib/Target/X86/X86FrameLowering.cpp index 4ca41ece19f3f95edee635ecd7310509590b49a0..7451b6a65ed565734332b2d3608c025074870bc7 100644 --- a/llvm/lib/Target/X86/X86FrameLowering.cpp +++ b/llvm/lib/Target/X86/X86FrameLowering.cpp @@ -2007,12 +2007,13 @@ void X86FrameLowering::emitEpilogue(MachineFunction &MF, #ifdef ARK_GC_SUPPORT if (MF.getFunction().hasFnAttribute("frame-reserved-slots")) { + + int reserveSize = GetFrameReserveSize(MF); int slotSize = sizeof(uint32_t); if (Is64Bit) { slotSize = sizeof(uint64_t); } - int reserveSize = GetFrameReserveSize(MF); - for (unsigned i = 0; i < reserveSize / slotSize; i++) { + for (int i = 0; i < reserveSize / slotSize; i++) { BuildMI(MBB, MBBI, DL, TII.get(Is64Bit ? X86::POP64r : X86::POP32r), MachineFramePtr) .setMIFlag(MachineInstr::FrameDestroy); @@ -2414,7 +2415,11 @@ bool X86FrameLowering::assignCalleeSavedSpillSlots( } } } - +#ifdef ARK_GC_SUPPORT + int reserveSize = GetFrameReserveSize(MF); + SpillSlotOffset -= reserveSize; // skip frame reserved + CalleeSavedFrameSize += reserveSize; +#endif // Assign slots for GPRs. It increases frame size. for (unsigned i = CSI.size(); i != 0; --i) { unsigned Reg = CSI[i - 1].getReg();