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 | |
969 if (isKill) | 978 if (isKill) |
970 MBB.addLiveIn(Reg); | 979 MBB.addLiveIn(Reg); |
971 | 980 |
972 // If NoGap is true, push consecutive registers and then leave the rest | 981 // If NoGap is true, push consecutive registers and then leave the rest |
973 // for other instructions. e.g. | 982 // for other instructions. e.g. |
974 // vpush {d8, d10, d11} -> vpush {d8}, vpush {d10, d11} | 983 // vpush {d8, d10, d11} -> vpush {d8}, vpush {d10, d11} |
975 if (NoGap && LastReg && LastReg != Reg-1) | 984 if (NoGap && LastReg && LastReg != Reg-1) |
976 break; | 985 break; |
977 LastReg = Reg; | 986 LastReg = Reg; |
978 Regs.push_back(std::make_pair(Reg, isKill)); | 987 Regs.push_back(std::make_pair(Reg, isKill)); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1018 bool isTailCall = (RetOpcode == ARM::TCRETURNdi || | 1027 bool isTailCall = (RetOpcode == ARM::TCRETURNdi || |
1019 RetOpcode == ARM::TCRETURNri); | 1028 RetOpcode == ARM::TCRETURNri); |
1020 bool isInterrupt = | 1029 bool isInterrupt = |
1021 RetOpcode == ARM::SUBS_PC_LR || RetOpcode == ARM::t2SUBS_PC_LR; | 1030 RetOpcode == ARM::SUBS_PC_LR || RetOpcode == ARM::t2SUBS_PC_LR; |
1022 | 1031 |
1023 SmallVector<unsigned, 4> Regs; | 1032 SmallVector<unsigned, 4> Regs; |
1024 unsigned i = CSI.size(); | 1033 unsigned i = CSI.size(); |
1025 while (i != 0) { | 1034 while (i != 0) { |
1026 unsigned LastReg = 0; | 1035 unsigned LastReg = 0; |
1027 bool DeleteRet = false; | 1036 bool DeleteRet = false; |
1037 unsigned SkippedPop = 0; // @LOCALMOD | |
1028 for (; i != 0; --i) { | 1038 for (; i != 0; --i) { |
1029 unsigned Reg = CSI[i-1].getReg(); | 1039 unsigned Reg = CSI[i-1].getReg(); |
1030 if (!(Func)(Reg, STI.isTargetDarwin())) continue; | 1040 if (!(Func)(Reg, STI.isTargetDarwin())) continue; |
1031 | 1041 |
1032 // The aligned reloads from area DPRCS2 are not inserted here. | 1042 // The aligned reloads from area DPRCS2 are not inserted here. |
1033 if (Reg >= ARM::D8 && Reg < ARM::D8 + NumAlignedDPRCS2Regs) | 1043 if (Reg >= ARM::D8 && Reg < ARM::D8 + NumAlignedDPRCS2Regs) |
1034 continue; | 1044 continue; |
1035 | 1045 |
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 | |
1036 if (Reg == ARM::LR && !isTailCall && !isVarArg && !isInterrupt && | 1059 if (Reg == ARM::LR && !isTailCall && !isVarArg && !isInterrupt && |
1037 STI.hasV5TOps() && | 1060 STI.hasV5TOps() && |
1038 !STI.isTargetNaCl() /* @LOCALMOD */) { | 1061 !STI.isTargetNaCl() /* @LOCALMOD */) { |
1039 Reg = ARM::PC; | 1062 Reg = ARM::PC; |
1040 LdmOpc = AFI->isThumbFunction() ? ARM::t2LDMIA_RET : ARM::LDMIA_RET; | 1063 LdmOpc = AFI->isThumbFunction() ? ARM::t2LDMIA_RET : ARM::LDMIA_RET; |
1041 // Fold the return instruction into the LDM. | 1064 // Fold the return instruction into the LDM. |
1042 DeleteRet = true; | 1065 DeleteRet = true; |
1043 } | 1066 } |
1044 | 1067 |
1045 // If NoGap is true, pop consecutive registers and then leave the rest | 1068 // If NoGap is true, pop consecutive registers and then leave the rest |
1046 // for other instructions. e.g. | 1069 // for other instructions. e.g. |
1047 // vpop {d8, d10, d11} -> vpop {d8}, vpop {d10, d11} | 1070 // vpop {d8, d10, d11} -> vpop {d8}, vpop {d10, d11} |
1048 if (NoGap && LastReg && LastReg != Reg-1) | 1071 if (NoGap && LastReg && LastReg != Reg-1) |
1049 break; | 1072 break; |
1050 | 1073 |
1051 LastReg = Reg; | 1074 LastReg = Reg; |
1052 Regs.push_back(Reg); | 1075 Regs.push_back(Reg); |
1053 } | 1076 } |
1054 | 1077 |
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 restores ; | |
jvoung (off chromium)
2015/06/03 17:19:38
80 col
Derek Schuff
2015/06/03 20:50:57
Done.
| |
1083 // it does this by finding the first instruction that's not a pop. | |
1084 // If we put an add here, the restore would go in between the restore of | |
1085 // the FP registers and the GPRs, instead of before the FP restore. So | |
1086 // 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 | |
1055 if (Regs.empty()) | 1093 if (Regs.empty()) |
1056 continue; | 1094 continue; |
1057 if (Regs.size() > 1 || LdrOpc == 0) { | 1095 if (Regs.size() > 1 || LdrOpc == 0) { |
1058 MachineInstrBuilder MIB = | 1096 MachineInstrBuilder MIB = |
1059 AddDefaultPred(BuildMI(MBB, MI, DL, TII.get(LdmOpc), ARM::SP) | 1097 AddDefaultPred(BuildMI(MBB, MI, DL, TII.get(LdmOpc), ARM::SP) |
1060 .addReg(ARM::SP)); | 1098 .addReg(ARM::SP)); |
jvoung (off chromium)
2015/06/03 17:19:38
revert whitespace change?
Derek Schuff
2015/06/03 20:50:57
Done.
| |
1061 for (unsigned i = 0, e = Regs.size(); i < e; ++i) | 1099 for (unsigned i = 0, e = Regs.size(); i < e; ++i) |
1062 MIB.addReg(Regs[i], getDefRegState(true)); | 1100 MIB.addReg(Regs[i], getDefRegState(true)); |
1063 if (DeleteRet) { | 1101 if (DeleteRet) { |
1064 MIB.copyImplicitOps(&*MI); | 1102 MIB.copyImplicitOps(&*MI); |
1065 MI->eraseFromParent(); | 1103 MI->eraseFromParent(); |
1066 } | 1104 } |
1067 MI = MIB; | 1105 MI = MIB; |
1068 } else if (Regs.size() == 1) { | 1106 } else if (Regs.size() == 1) { |
1069 // If we adjusted the reg to PC from LR above, switch it back here. We | 1107 // If we adjusted the reg to PC from LR above, switch it back here. We |
1070 // only do that for LDM. | 1108 // only do that for LDM. |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2165 GetMBB->addSuccessor(AllocMBB); | 2203 GetMBB->addSuccessor(AllocMBB); |
2166 | 2204 |
2167 McrMBB->addSuccessor(GetMBB); | 2205 McrMBB->addSuccessor(GetMBB); |
2168 | 2206 |
2169 PrevStackMBB->addSuccessor(McrMBB); | 2207 PrevStackMBB->addSuccessor(McrMBB); |
2170 | 2208 |
2171 #ifdef XDEBUG | 2209 #ifdef XDEBUG |
2172 MF.verify(); | 2210 MF.verify(); |
2173 #endif | 2211 #endif |
2174 } | 2212 } |
OLD | NEW |