Mips: Don't store MachineFunction in MipsFunctionInfo

It will soon be disallowed to depend on MachineFunction state on
construction.
This commit is contained in:
Matt Arsenault 2020-06-18 10:19:07 -04:00
parent 983a4b520e
commit 669bb3111f
11 changed files with 43 additions and 41 deletions

View File

@ -72,7 +72,7 @@ void Mips16DAGToDAGISel::initGlobalBaseReg(MachineFunction &MF) {
MachineRegisterInfo &RegInfo = MF.getRegInfo(); MachineRegisterInfo &RegInfo = MF.getRegInfo();
const TargetInstrInfo &TII = *Subtarget->getInstrInfo(); const TargetInstrInfo &TII = *Subtarget->getInstrInfo();
DebugLoc DL; DebugLoc DL;
Register V0, V1, V2, GlobalBaseReg = MipsFI->getGlobalBaseReg(); Register V0, V1, V2, GlobalBaseReg = MipsFI->getGlobalBaseReg(MF);
const TargetRegisterClass *RC = &Mips::CPU16RegsRegClass; const TargetRegisterClass *RC = &Mips::CPU16RegsRegClass;
V0 = RegInfo.createVirtualRegister(RC); V0 = RegInfo.createVirtualRegister(RC);

View File

@ -492,7 +492,7 @@ getOpndList(SmallVectorImpl<SDValue> &Ops,
ExternalSymbolSDNode *S = cast<ExternalSymbolSDNode>(JumpTarget); ExternalSymbolSDNode *S = cast<ExternalSymbolSDNode>(JumpTarget);
JumpTarget = getAddrGlobal(S, CLI.DL, JumpTarget.getValueType(), DAG, JumpTarget = getAddrGlobal(S, CLI.DL, JumpTarget.getValueType(), DAG,
MipsII::MO_GOT, Chain, MipsII::MO_GOT, Chain,
FuncInfo->callPtrInfo(S->getSymbol())); FuncInfo->callPtrInfo(MF, S->getSymbol()));
} else } else
RegsToPass.push_front(std::make_pair((unsigned)Mips::T9, Callee)); RegsToPass.push_front(std::make_pair((unsigned)Mips::T9, Callee));
} }

View File

@ -593,7 +593,7 @@ bool MipsCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
if (IsCalleeGlobalPIC) { if (IsCalleeGlobalPIC) {
MIRBuilder.buildCopy( MIRBuilder.buildCopy(
Register(Mips::GP), Register(Mips::GP),
MF.getInfo<MipsFunctionInfo>()->getGlobalBaseRegForGlobalISel()); MF.getInfo<MipsFunctionInfo>()->getGlobalBaseRegForGlobalISel(MF));
MIB.addDef(Mips::GP, RegState::Implicit); MIB.addDef(Mips::GP, RegState::Implicit);
} }
MIRBuilder.insertInstr(MIB); MIRBuilder.insertInstr(MIB);

View File

@ -420,7 +420,7 @@ unsigned MipsFastISel::materializeGV(const GlobalValue *GV, MVT VT) {
if (IsThreadLocal) if (IsThreadLocal)
return 0; return 0;
emitInst(Mips::LW, DestReg) emitInst(Mips::LW, DestReg)
.addReg(MFI->getGlobalBaseReg()) .addReg(MFI->getGlobalBaseReg(*MF))
.addGlobalAddress(GV, 0, MipsII::MO_GOT); .addGlobalAddress(GV, 0, MipsII::MO_GOT);
if ((GV->hasInternalLinkage() || if ((GV->hasInternalLinkage() ||
(GV->hasLocalLinkage() && !isa<Function>(GV)))) { (GV->hasLocalLinkage() && !isa<Function>(GV)))) {
@ -437,7 +437,7 @@ unsigned MipsFastISel::materializeExternalCallSym(MCSymbol *Sym) {
const TargetRegisterClass *RC = &Mips::GPR32RegClass; const TargetRegisterClass *RC = &Mips::GPR32RegClass;
unsigned DestReg = createResultReg(RC); unsigned DestReg = createResultReg(RC);
emitInst(Mips::LW, DestReg) emitInst(Mips::LW, DestReg)
.addReg(MFI->getGlobalBaseReg()) .addReg(MFI->getGlobalBaseReg(*MF))
.addSym(Sym, MipsII::MO_GOT); .addSym(Sym, MipsII::MO_GOT);
return DestReg; return DestReg;
} }

View File

@ -65,7 +65,7 @@ bool MipsDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
/// getGlobalBaseReg - Output the instructions required to put the /// getGlobalBaseReg - Output the instructions required to put the
/// GOT address into a register. /// GOT address into a register.
SDNode *MipsDAGToDAGISel::getGlobalBaseReg() { SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
Register GlobalBaseReg = MF->getInfo<MipsFunctionInfo>()->getGlobalBaseReg(); Register GlobalBaseReg = MF->getInfo<MipsFunctionInfo>()->getGlobalBaseReg(*MF);
return CurDAG->getRegister(GlobalBaseReg, getTargetLowering()->getPointerTy( return CurDAG->getRegister(GlobalBaseReg, getTargetLowering()->getPointerTy(
CurDAG->getDataLayout())) CurDAG->getDataLayout()))
.getNode(); .getNode();

View File

@ -142,8 +142,9 @@ unsigned MipsTargetLowering::getVectorTypeBreakdownForCallingConv(
} }
SDValue MipsTargetLowering::getGlobalReg(SelectionDAG &DAG, EVT Ty) const { SDValue MipsTargetLowering::getGlobalReg(SelectionDAG &DAG, EVT Ty) const {
MipsFunctionInfo *FI = DAG.getMachineFunction().getInfo<MipsFunctionInfo>(); MachineFunction &MF = DAG.getMachineFunction();
return DAG.getRegister(FI->getGlobalBaseReg(), Ty); MipsFunctionInfo *FI = MF.getInfo<MipsFunctionInfo>();
return DAG.getRegister(FI->getGlobalBaseReg(MF), Ty);
} }
SDValue MipsTargetLowering::getTargetNode(GlobalAddressSDNode *N, EVT Ty, SDValue MipsTargetLowering::getTargetNode(GlobalAddressSDNode *N, EVT Ty,
@ -3420,11 +3421,11 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
else if (Subtarget.useXGOT()) { else if (Subtarget.useXGOT()) {
Callee = getAddrGlobalLargeGOT(G, DL, Ty, DAG, MipsII::MO_CALL_HI16, Callee = getAddrGlobalLargeGOT(G, DL, Ty, DAG, MipsII::MO_CALL_HI16,
MipsII::MO_CALL_LO16, Chain, MipsII::MO_CALL_LO16, Chain,
FuncInfo->callPtrInfo(Val)); FuncInfo->callPtrInfo(MF, Val));
IsCallReloc = true; IsCallReloc = true;
} else { } else {
Callee = getAddrGlobal(G, DL, Ty, DAG, MipsII::MO_GOT_CALL, Chain, Callee = getAddrGlobal(G, DL, Ty, DAG, MipsII::MO_GOT_CALL, Chain,
FuncInfo->callPtrInfo(Val)); FuncInfo->callPtrInfo(MF, Val));
IsCallReloc = true; IsCallReloc = true;
} }
} else } else
@ -3442,11 +3443,11 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
else if (Subtarget.useXGOT()) { else if (Subtarget.useXGOT()) {
Callee = getAddrGlobalLargeGOT(S, DL, Ty, DAG, MipsII::MO_CALL_HI16, Callee = getAddrGlobalLargeGOT(S, DL, Ty, DAG, MipsII::MO_CALL_HI16,
MipsII::MO_CALL_LO16, Chain, MipsII::MO_CALL_LO16, Chain,
FuncInfo->callPtrInfo(Sym)); FuncInfo->callPtrInfo(MF, Sym));
IsCallReloc = true; IsCallReloc = true;
} else { // PIC } else { // PIC
Callee = getAddrGlobal(S, DL, Ty, DAG, MipsII::MO_GOT_CALL, Chain, Callee = getAddrGlobal(S, DL, Ty, DAG, MipsII::MO_GOT_CALL, Chain,
FuncInfo->callPtrInfo(Sym)); FuncInfo->callPtrInfo(MF, Sym));
IsCallReloc = true; IsCallReloc = true;
} }

View File

@ -404,7 +404,7 @@ bool MipsInstructionSelector::select(MachineInstr &I) {
.addDef(Dest) .addDef(Dest)
.addUse(DestTmp) .addUse(DestTmp)
.addUse(MF.getInfo<MipsFunctionInfo>() .addUse(MF.getInfo<MipsFunctionInfo>()
->getGlobalBaseRegForGlobalISel()); ->getGlobalBaseRegForGlobalISel(MF));
if (!constrainSelectedInstRegOperands(*ADDu, TII, TRI, RBI)) if (!constrainSelectedInstRegOperands(*ADDu, TII, TRI, RBI))
return false; return false;
} }
@ -669,7 +669,7 @@ bool MipsInstructionSelector::select(MachineInstr &I) {
MachineInstr *LWGOT = BuildMI(MBB, I, I.getDebugLoc(), TII.get(Mips::LW)) MachineInstr *LWGOT = BuildMI(MBB, I, I.getDebugLoc(), TII.get(Mips::LW))
.addDef(I.getOperand(0).getReg()) .addDef(I.getOperand(0).getReg())
.addReg(MF.getInfo<MipsFunctionInfo>() .addReg(MF.getInfo<MipsFunctionInfo>()
->getGlobalBaseRegForGlobalISel()) ->getGlobalBaseRegForGlobalISel(MF))
.addGlobalAddress(GVal); .addGlobalAddress(GVal);
// Global Values that don't have local linkage are handled differently // Global Values that don't have local linkage are handled differently
// when they are part of call sequence. MipsCallLowering::lowerCall // when they are part of call sequence. MipsCallLowering::lowerCall
@ -725,7 +725,7 @@ bool MipsInstructionSelector::select(MachineInstr &I) {
MI = BuildMI(MBB, I, I.getDebugLoc(), TII.get(Mips::LW)) MI = BuildMI(MBB, I, I.getDebugLoc(), TII.get(Mips::LW))
.addDef(I.getOperand(0).getReg()) .addDef(I.getOperand(0).getReg())
.addReg(MF.getInfo<MipsFunctionInfo>() .addReg(MF.getInfo<MipsFunctionInfo>()
->getGlobalBaseRegForGlobalISel()) ->getGlobalBaseRegForGlobalISel(MF))
.addJumpTableIndex(I.getOperand(1).getIndex(), MipsII::MO_GOT) .addJumpTableIndex(I.getOperand(1).getIndex(), MipsII::MO_GOT)
.addMemOperand(MF.getMachineMemOperand( .addMemOperand(MF.getMachineMemOperand(
MachinePointerInfo::getGOT(MF), MachineMemOperand::MOLoad, 4, MachinePointerInfo::getGOT(MF), MachineMemOperand::MOLoad, 4,

View File

@ -44,22 +44,22 @@ static const TargetRegisterClass &getGlobalBaseRegClass(MachineFunction &MF) {
return Mips::GPR32RegClass; return Mips::GPR32RegClass;
} }
Register MipsFunctionInfo::getGlobalBaseReg() { Register MipsFunctionInfo::getGlobalBaseReg(MachineFunction &MF) {
if (!GlobalBaseReg) if (!GlobalBaseReg)
GlobalBaseReg = GlobalBaseReg =
MF.getRegInfo().createVirtualRegister(&getGlobalBaseRegClass(MF)); MF.getRegInfo().createVirtualRegister(&getGlobalBaseRegClass(MF));
return GlobalBaseReg; return GlobalBaseReg;
} }
Register MipsFunctionInfo::getGlobalBaseRegForGlobalISel() { Register MipsFunctionInfo::getGlobalBaseRegForGlobalISel(MachineFunction &MF) {
if (!GlobalBaseReg) { if (!GlobalBaseReg) {
getGlobalBaseReg(); getGlobalBaseReg(MF);
initGlobalBaseReg(); initGlobalBaseReg(MF);
} }
return GlobalBaseReg; return GlobalBaseReg;
} }
void MipsFunctionInfo::initGlobalBaseReg() { void MipsFunctionInfo::initGlobalBaseReg(MachineFunction &MF) {
if (!GlobalBaseReg) if (!GlobalBaseReg)
return; return;
@ -146,7 +146,7 @@ void MipsFunctionInfo::initGlobalBaseReg() {
.addReg(Mips::V0).addReg(Mips::T9); .addReg(Mips::V0).addReg(Mips::T9);
} }
void MipsFunctionInfo::createEhDataRegsFI() { void MipsFunctionInfo::createEhDataRegsFI(MachineFunction &MF) {
const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
for (int I = 0; I < 4; ++I) { for (int I = 0; I < 4; ++I) {
const TargetRegisterClass &RC = const TargetRegisterClass &RC =
@ -159,7 +159,7 @@ void MipsFunctionInfo::createEhDataRegsFI() {
} }
} }
void MipsFunctionInfo::createISRRegFI() { void MipsFunctionInfo::createISRRegFI(MachineFunction &MF) {
// ISRs require spill slots for Status & ErrorPC Coprocessor 0 registers. // ISRs require spill slots for Status & ErrorPC Coprocessor 0 registers.
// The current implementation only supports Mips32r2+ not Mips64rX. Status // The current implementation only supports Mips32r2+ not Mips64rX. Status
// is always 32 bits, ErrorPC is 32 or 64 bits dependent on architecture, // is always 32 bits, ErrorPC is 32 or 64 bits dependent on architecture,
@ -180,15 +180,18 @@ bool MipsFunctionInfo::isEhDataRegFI(int FI) const {
bool MipsFunctionInfo::isISRRegFI(int FI) const { bool MipsFunctionInfo::isISRRegFI(int FI) const {
return IsISR && (FI == ISRDataRegFI[0] || FI == ISRDataRegFI[1]); return IsISR && (FI == ISRDataRegFI[0] || FI == ISRDataRegFI[1]);
} }
MachinePointerInfo MipsFunctionInfo::callPtrInfo(const char *ES) { MachinePointerInfo MipsFunctionInfo::callPtrInfo(MachineFunction &MF,
const char *ES) {
return MachinePointerInfo(MF.getPSVManager().getExternalSymbolCallEntry(ES)); return MachinePointerInfo(MF.getPSVManager().getExternalSymbolCallEntry(ES));
} }
MachinePointerInfo MipsFunctionInfo::callPtrInfo(const GlobalValue *GV) { MachinePointerInfo MipsFunctionInfo::callPtrInfo(MachineFunction &MF,
const GlobalValue *GV) {
return MachinePointerInfo(MF.getPSVManager().getGlobalValueCallEntry(GV)); return MachinePointerInfo(MF.getPSVManager().getGlobalValueCallEntry(GV));
} }
int MipsFunctionInfo::getMoveF64ViaSpillFI(const TargetRegisterClass *RC) { int MipsFunctionInfo::getMoveF64ViaSpillFI(MachineFunction &MF,
const TargetRegisterClass *RC) {
const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
if (MoveF64ViaSpillFI == -1) { if (MoveF64ViaSpillFI == -1) {
MoveF64ViaSpillFI = MF.getFrameInfo().CreateStackObject( MoveF64ViaSpillFI = MF.getFrameInfo().CreateStackObject(

View File

@ -24,7 +24,7 @@ namespace llvm {
/// Mips target-specific information for each MachineFunction. /// Mips target-specific information for each MachineFunction.
class MipsFunctionInfo : public MachineFunctionInfo { class MipsFunctionInfo : public MachineFunctionInfo {
public: public:
MipsFunctionInfo(MachineFunction &MF) : MF(MF) {} MipsFunctionInfo(MachineFunction &MF) {}
~MipsFunctionInfo() override; ~MipsFunctionInfo() override;
@ -32,12 +32,12 @@ public:
void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; } void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
bool globalBaseRegSet() const; bool globalBaseRegSet() const;
Register getGlobalBaseReg(); Register getGlobalBaseReg(MachineFunction &MF);
Register getGlobalBaseRegForGlobalISel(); Register getGlobalBaseRegForGlobalISel(MachineFunction &MF);
// Insert instructions to initialize the global base register in the // Insert instructions to initialize the global base register in the
// first MBB of the function. // first MBB of the function.
void initGlobalBaseReg(); void initGlobalBaseReg(MachineFunction &MF);
int getVarArgsFrameIndex() const { return VarArgsFrameIndex; } int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; } void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
@ -53,30 +53,30 @@ public:
bool callsEhReturn() const { return CallsEhReturn; } bool callsEhReturn() const { return CallsEhReturn; }
void setCallsEhReturn() { CallsEhReturn = true; } void setCallsEhReturn() { CallsEhReturn = true; }
void createEhDataRegsFI(); void createEhDataRegsFI(MachineFunction &MF);
int getEhDataRegFI(unsigned Reg) const { return EhDataRegFI[Reg]; } int getEhDataRegFI(unsigned Reg) const { return EhDataRegFI[Reg]; }
bool isEhDataRegFI(int FI) const; bool isEhDataRegFI(int FI) const;
/// Create a MachinePointerInfo that has an ExternalSymbolPseudoSourceValue /// Create a MachinePointerInfo that has an ExternalSymbolPseudoSourceValue
/// object representing a GOT entry for an external function. /// object representing a GOT entry for an external function.
MachinePointerInfo callPtrInfo(const char *ES); MachinePointerInfo callPtrInfo(MachineFunction &MF, const char *ES);
// Functions with the "interrupt" attribute require special prologues, // Functions with the "interrupt" attribute require special prologues,
// epilogues and additional spill slots. // epilogues and additional spill slots.
bool isISR() const { return IsISR; } bool isISR() const { return IsISR; }
void setISR() { IsISR = true; } void setISR() { IsISR = true; }
void createISRRegFI(); void createISRRegFI(MachineFunction &MF);
int getISRRegFI(Register Reg) const { return ISRDataRegFI[Reg]; } int getISRRegFI(Register Reg) const { return ISRDataRegFI[Reg]; }
bool isISRRegFI(int FI) const; bool isISRRegFI(int FI) const;
/// Create a MachinePointerInfo that has a GlobalValuePseudoSourceValue object /// Create a MachinePointerInfo that has a GlobalValuePseudoSourceValue object
/// representing a GOT entry for a global function. /// representing a GOT entry for a global function.
MachinePointerInfo callPtrInfo(const GlobalValue *GV); MachinePointerInfo callPtrInfo(MachineFunction &MF, const GlobalValue *GV);
void setSaveS2() { SaveS2 = true; } void setSaveS2() { SaveS2 = true; }
bool hasSaveS2() const { return SaveS2; } bool hasSaveS2() const { return SaveS2; }
int getMoveF64ViaSpillFI(const TargetRegisterClass *RC); int getMoveF64ViaSpillFI(MachineFunction &MF, const TargetRegisterClass *RC);
std::map<const char *, const Mips16HardFloatInfo::FuncSignature *> std::map<const char *, const Mips16HardFloatInfo::FuncSignature *>
StubsNeeded; StubsNeeded;
@ -84,8 +84,6 @@ public:
private: private:
virtual void anchor(); virtual void anchor();
MachineFunction& MF;
/// SRetReturnReg - Some subtargets require that sret lowering includes /// SRetReturnReg - Some subtargets require that sret lowering includes
/// returning the value of the returned struct in a register. This field /// returning the value of the returned struct in a register. This field
/// holds the virtual register into which the sret argument is passed. /// holds the virtual register into which the sret argument is passed.

View File

@ -320,7 +320,7 @@ bool ExpandPseudo::expandBuildPairF64(MachineBasicBlock &MBB,
// We re-use the same spill slot each time so that the stack frame doesn't // We re-use the same spill slot each time so that the stack frame doesn't
// grow too much in functions with a large number of moves. // grow too much in functions with a large number of moves.
int FI = MF.getInfo<MipsFunctionInfo>()->getMoveF64ViaSpillFI(RC2); int FI = MF.getInfo<MipsFunctionInfo>()->getMoveF64ViaSpillFI(MF, RC2);
if (!Subtarget.isLittle()) if (!Subtarget.isLittle())
std::swap(LoReg, HiReg); std::swap(LoReg, HiReg);
TII.storeRegToStack(MBB, I, LoReg, I->getOperand(1).isKill(), FI, RC, TII.storeRegToStack(MBB, I, LoReg, I->getOperand(1).isKill(), FI, RC,
@ -386,7 +386,7 @@ bool ExpandPseudo::expandExtractElementF64(MachineBasicBlock &MBB,
// We re-use the same spill slot each time so that the stack frame doesn't // We re-use the same spill slot each time so that the stack frame doesn't
// grow too much in functions with a large number of moves. // grow too much in functions with a large number of moves.
int FI = MF.getInfo<MipsFunctionInfo>()->getMoveF64ViaSpillFI(RC); int FI = MF.getInfo<MipsFunctionInfo>()->getMoveF64ViaSpillFI(MF, RC);
TII.storeRegToStack(MBB, I, SrcReg, Op1.isKill(), FI, RC, &RegInfo, 0); TII.storeRegToStack(MBB, I, SrcReg, Op1.isKill(), FI, RC, &RegInfo, 0);
TII.loadRegFromStack(MBB, I, DstReg, FI, RC2, &RegInfo, Offset); TII.loadRegFromStack(MBB, I, DstReg, FI, RC2, &RegInfo, Offset);
return true; return true;
@ -878,11 +878,11 @@ void MipsSEFrameLowering::determineCalleeSaves(MachineFunction &MF,
// Create spill slots for eh data registers if function calls eh_return. // Create spill slots for eh data registers if function calls eh_return.
if (MipsFI->callsEhReturn()) if (MipsFI->callsEhReturn())
MipsFI->createEhDataRegsFI(); MipsFI->createEhDataRegsFI(MF);
// Create spill slots for Coprocessor 0 registers if function is an ISR. // Create spill slots for Coprocessor 0 registers if function is an ISR.
if (MipsFI->isISR()) if (MipsFI->isISR())
MipsFI->createISRRegFI(); MipsFI->createISRRegFI(MF);
// Expand pseudo instructions which load, store or copy accumulators. // Expand pseudo instructions which load, store or copy accumulators.
// Add an emergency spill slot if a pseudo was expanded. // Add an emergency spill slot if a pseudo was expanded.

View File

@ -153,7 +153,7 @@ void MipsSEDAGToDAGISel::emitMCountABI(MachineInstr &MI, MachineBasicBlock &MBB,
} }
void MipsSEDAGToDAGISel::processFunctionAfterISel(MachineFunction &MF) { void MipsSEDAGToDAGISel::processFunctionAfterISel(MachineFunction &MF) {
MF.getInfo<MipsFunctionInfo>()->initGlobalBaseReg(); MF.getInfo<MipsFunctionInfo>()->initGlobalBaseReg(MF);
MachineRegisterInfo *MRI = &MF.getRegInfo(); MachineRegisterInfo *MRI = &MF.getRegInfo();