| OLD | NEW |
| 1 //===-- ARMFrameLowering.cpp - ARM Frame Information ----------------------===// | 1 //===-- ARMFrameLowering.cpp - ARM Frame Information ----------------------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 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 contains the ARM implementation of TargetFrameLowering class. | 10 // This file contains the ARM implementation of TargetFrameLowering class. |
| (...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 // @llvm.returnaddress is called. If LR is returned for | 959 // @llvm.returnaddress is called. If LR is returned for |
| 960 // @llvm.returnaddress then it's already added to the function and | 960 // @llvm.returnaddress then it's already added to the function and |
| 961 // entry block live-in sets. | 961 // entry block live-in sets. |
| 962 bool isKill = true; | 962 bool isKill = true; |
| 963 if (Reg == ARM::LR) { | 963 if (Reg == ARM::LR) { |
| 964 if (MF.getFrameInfo()->isReturnAddressTaken() && | 964 if (MF.getFrameInfo()->isReturnAddressTaken() && |
| 965 MF.getRegInfo().isLiveIn(Reg)) | 965 MF.getRegInfo().isLiveIn(Reg)) |
| 966 isKill = false; | 966 isKill = false; |
| 967 } | 967 } |
| 968 | 968 |
| 969 // @LOCALMOD-START | |
| 970 // Functions which call EHReturn spill all CSRs plus R0/R1 | |
| 971 if ((Reg == ARM::R0 || Reg == ARM::R1) && | |
| 972 MF.getRegInfo().isLiveIn(Reg)) { | |
| 973 assert(MF.getMMI().callsEHReturn()); | |
| 974 isKill = false; | |
| 975 } | |
| 976 // @LOCALMOD-END | |
| 977 | |
| 978 if (isKill) | 969 if (isKill) |
| 979 MBB.addLiveIn(Reg); | 970 MBB.addLiveIn(Reg); |
| 980 | 971 |
| 981 // If NoGap is true, push consecutive registers and then leave the rest | 972 // If NoGap is true, push consecutive registers and then leave the rest |
| 982 // for other instructions. e.g. | 973 // for other instructions. e.g. |
| 983 // vpush {d8, d10, d11} -> vpush {d8}, vpush {d10, d11} | 974 // vpush {d8, d10, d11} -> vpush {d8}, vpush {d10, d11} |
| 984 if (NoGap && LastReg && LastReg != Reg-1) | 975 if (NoGap && LastReg && LastReg != Reg-1) |
| 985 break; | 976 break; |
| 986 LastReg = Reg; | 977 LastReg = Reg; |
| 987 Regs.push_back(std::make_pair(Reg, isKill)); | 978 Regs.push_back(std::make_pair(Reg, isKill)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 bool isTailCall = (RetOpcode == ARM::TCRETURNdi || | 1018 bool isTailCall = (RetOpcode == ARM::TCRETURNdi || |
| 1028 RetOpcode == ARM::TCRETURNri); | 1019 RetOpcode == ARM::TCRETURNri); |
| 1029 bool isInterrupt = | 1020 bool isInterrupt = |
| 1030 RetOpcode == ARM::SUBS_PC_LR || RetOpcode == ARM::t2SUBS_PC_LR; | 1021 RetOpcode == ARM::SUBS_PC_LR || RetOpcode == ARM::t2SUBS_PC_LR; |
| 1031 | 1022 |
| 1032 SmallVector<unsigned, 4> Regs; | 1023 SmallVector<unsigned, 4> Regs; |
| 1033 unsigned i = CSI.size(); | 1024 unsigned i = CSI.size(); |
| 1034 while (i != 0) { | 1025 while (i != 0) { |
| 1035 unsigned LastReg = 0; | 1026 unsigned LastReg = 0; |
| 1036 bool DeleteRet = false; | 1027 bool DeleteRet = false; |
| 1037 unsigned SkippedPop = 0; // @LOCALMOD | |
| 1038 for (; i != 0; --i) { | 1028 for (; i != 0; --i) { |
| 1039 unsigned Reg = CSI[i-1].getReg(); | 1029 unsigned Reg = CSI[i-1].getReg(); |
| 1040 if (!(Func)(Reg, STI.isTargetDarwin())) continue; | 1030 if (!(Func)(Reg, STI.isTargetDarwin())) continue; |
| 1041 | 1031 |
| 1042 // The aligned reloads from area DPRCS2 are not inserted here. | 1032 // The aligned reloads from area DPRCS2 are not inserted here. |
| 1043 if (Reg >= ARM::D8 && Reg < ARM::D8 + NumAlignedDPRCS2Regs) | 1033 if (Reg >= ARM::D8 && Reg < ARM::D8 + NumAlignedDPRCS2Regs) |
| 1044 continue; | 1034 continue; |
| 1045 | 1035 |
| 1046 // @LOCALMOD-START | |
| 1047 // Functions which call EHReturn spill all of their CSRs plus R0 and R1, | |
| 1048 // (the EHReturn return value registers). Epilogs which return via | |
| 1049 // EHreturn pop all of them, but epilogs which return via normal return | |
| 1050 // must not restore R0 and R1, as that would clobber the return value. | |
| 1051 if (MF.getMMI().callsEHReturn() && | |
| 1052 RetOpcode != ARM::ARMeh_return && | |
| 1053 (Reg == ARM::R0 || Reg == ARM::R1)) { | |
| 1054 SkippedPop++; | |
| 1055 continue; | |
| 1056 } | |
| 1057 // @LOCALMOD-END | |
| 1058 | |
| 1059 if (Reg == ARM::LR && !isTailCall && !isVarArg && !isInterrupt && | 1036 if (Reg == ARM::LR && !isTailCall && !isVarArg && !isInterrupt && |
| 1060 STI.hasV5TOps() && | 1037 STI.hasV5TOps() && |
| 1061 !STI.isTargetNaCl() /* @LOCALMOD */) { | 1038 !STI.isTargetNaCl() /* @LOCALMOD */) { |
| 1062 Reg = ARM::PC; | 1039 Reg = ARM::PC; |
| 1063 LdmOpc = AFI->isThumbFunction() ? ARM::t2LDMIA_RET : ARM::LDMIA_RET; | 1040 LdmOpc = AFI->isThumbFunction() ? ARM::t2LDMIA_RET : ARM::LDMIA_RET; |
| 1064 // Fold the return instruction into the LDM. | 1041 // Fold the return instruction into the LDM. |
| 1065 DeleteRet = true; | 1042 DeleteRet = true; |
| 1066 } | 1043 } |
| 1067 | 1044 |
| 1068 // If NoGap is true, pop consecutive registers and then leave the rest | 1045 // If NoGap is true, pop consecutive registers and then leave the rest |
| 1069 // for other instructions. e.g. | 1046 // for other instructions. e.g. |
| 1070 // vpop {d8, d10, d11} -> vpop {d8}, vpop {d10, d11} | 1047 // vpop {d8, d10, d11} -> vpop {d8}, vpop {d10, d11} |
| 1071 if (NoGap && LastReg && LastReg != Reg-1) | 1048 if (NoGap && LastReg && LastReg != Reg-1) |
| 1072 break; | 1049 break; |
| 1073 | 1050 |
| 1074 LastReg = Reg; | 1051 LastReg = Reg; |
| 1075 Regs.push_back(Reg); | 1052 Regs.push_back(Reg); |
| 1076 } | 1053 } |
| 1077 | 1054 |
| 1078 // @LOCALMOD-START | |
| 1079 if (SkippedPop) { | |
| 1080 // We need to increment the stack pointer to compensate for the skipped | |
| 1081 // pops. However we cannot directly increment it because the epilog | |
| 1082 // insertion code places the stack pointer restore before the CSR | |
| 1083 // restores; it does this by finding the first instruction that's not a | |
| 1084 // pop. If we put an add here, the restore would go in between the | |
| 1085 // restore of the FP registers and the GPRs, instead of before the FP | |
| 1086 // restore. So use a pop into R12 to adjust SP. | |
| 1087 while(SkippedPop--) | |
| 1088 AddDefaultPred(BuildMI(MBB, MI, DL, TII.get(LdmOpc), ARM::SP) | |
| 1089 .addReg(ARM::SP)).addReg(ARM::R12); | |
| 1090 } | |
| 1091 // @LOCALMOD-END | |
| 1092 | |
| 1093 if (Regs.empty()) | 1055 if (Regs.empty()) |
| 1094 continue; | 1056 continue; |
| 1095 if (Regs.size() > 1 || LdrOpc == 0) { | 1057 if (Regs.size() > 1 || LdrOpc == 0) { |
| 1096 MachineInstrBuilder MIB = | 1058 MachineInstrBuilder MIB = |
| 1097 AddDefaultPred(BuildMI(MBB, MI, DL, TII.get(LdmOpc), ARM::SP) | 1059 AddDefaultPred(BuildMI(MBB, MI, DL, TII.get(LdmOpc), ARM::SP) |
| 1098 .addReg(ARM::SP)); | 1060 .addReg(ARM::SP)); |
| 1099 for (unsigned i = 0, e = Regs.size(); i < e; ++i) | 1061 for (unsigned i = 0, e = Regs.size(); i < e; ++i) |
| 1100 MIB.addReg(Regs[i], getDefRegState(true)); | 1062 MIB.addReg(Regs[i], getDefRegState(true)); |
| 1101 if (DeleteRet) { | 1063 if (DeleteRet) { |
| 1102 MIB.copyImplicitOps(&*MI); | 1064 MIB.copyImplicitOps(&*MI); |
| (...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2203 GetMBB->addSuccessor(AllocMBB); | 2165 GetMBB->addSuccessor(AllocMBB); |
| 2204 | 2166 |
| 2205 McrMBB->addSuccessor(GetMBB); | 2167 McrMBB->addSuccessor(GetMBB); |
| 2206 | 2168 |
| 2207 PrevStackMBB->addSuccessor(McrMBB); | 2169 PrevStackMBB->addSuccessor(McrMBB); |
| 2208 | 2170 |
| 2209 #ifdef XDEBUG | 2171 #ifdef XDEBUG |
| 2210 MF.verify(); | 2172 MF.verify(); |
| 2211 #endif | 2173 #endif |
| 2212 } | 2174 } |
| OLD | NEW |