[llvm] r337647 - [mips] Factor out register class selection for global base register. NFC
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 21 09:16:08 PDT 2018
Author: atanasyan
Date: Sat Jul 21 09:16:08 2018
New Revision: 337647
URL: http://llvm.org/viewvc/llvm-project?rev=337647&view=rev
Log:
[mips] Factor out register class selection for global base register. NFC
Factor out register class selection for global base register into a
separate function to escape long chain of ternary operators.
Modified:
llvm/trunk/lib/Target/Mips/MipsMachineFunction.cpp
Modified: llvm/trunk/lib/Target/Mips/MipsMachineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsMachineFunction.cpp?rev=337647&r1=337646&r2=337647&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsMachineFunction.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsMachineFunction.cpp Sat Jul 21 09:16:08 2018
@@ -29,25 +29,27 @@ bool MipsFunctionInfo::globalBaseRegSet(
return GlobalBaseReg;
}
+static const TargetRegisterClass &getGlobalBaseRegClass(MachineFunction &MF) {
+ auto &STI = static_cast<const MipsSubtarget &>(MF.getSubtarget());
+ auto &TM = static_cast<const MipsTargetMachine &>(MF.getTarget());
+
+ if (STI.inMips16Mode())
+ return Mips::CPU16RegsRegClass;
+
+ if (STI.inMicroMipsMode())
+ return Mips::GPRMM16RegClass;
+
+ if (TM.getABI().IsN64())
+ return Mips::GPR64RegClass;
+
+ return Mips::GPR32RegClass;
+}
+
unsigned MipsFunctionInfo::getGlobalBaseReg() {
- // Return if it has already been initialized.
- if (GlobalBaseReg)
- return GlobalBaseReg;
-
- MipsSubtarget const &STI =
- static_cast<const MipsSubtarget &>(MF.getSubtarget());
-
- const TargetRegisterClass *RC =
- STI.inMips16Mode()
- ? &Mips::CPU16RegsRegClass
- : STI.inMicroMipsMode()
- ? &Mips::GPRMM16RegClass
- : static_cast<const MipsTargetMachine &>(MF.getTarget())
- .getABI()
- .IsN64()
- ? &Mips::GPR64RegClass
- : &Mips::GPR32RegClass;
- return GlobalBaseReg = MF.getRegInfo().createVirtualRegister(RC);
+ if (!GlobalBaseReg)
+ GlobalBaseReg =
+ MF.getRegInfo().createVirtualRegister(&getGlobalBaseRegClass(MF));
+ return GlobalBaseReg;
}
void MipsFunctionInfo::createEhDataRegsFI() {
More information about the llvm-commits
mailing list