Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/include/llvm/CodeGen/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,9 @@ namespace llvm {

/// Lowers KCFI operand bundles for indirect calls.
FunctionPass *createKCFIPass();

/// This pass replaces spills to stack with spills to registers.
extern char &Spill2RegID;
} // End llvm namespace

#endif
36 changes: 36 additions & 0 deletions llvm/include/llvm/CodeGen/TargetInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ class TargetInstrInfo : public MCInstrInfo {
return isLoadFromStackSlot(MI, FrameIndex);
}

virtual const MachineOperand *isLoadFromStackSlotMO(const MachineInstr &MI,
int &FrameIndex) const {
llvm_unreachable("target did not implement");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just return nullptr by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reasoning is that if I was implementing this for a new target I would prefer getting a crash telling me that I should override this function, rather than getting it to silently skip spill2reg because some functions are not overridden. Wdyt?

}

/// Check for post-frame ptr elimination stack locations as well.
/// This uses a heuristic so it isn't reliable for correctness.
virtual Register isLoadFromStackSlotPostFE(const MachineInstr &MI,
Expand Down Expand Up @@ -325,6 +330,11 @@ class TargetInstrInfo : public MCInstrInfo {
return 0;
}

virtual const MachineOperand *isStoreToStackSlotMO(const MachineInstr &MI,
int &FrameIndex) const {
llvm_unreachable("target did not implement");
}

/// Optional extension of isStoreToStackSlot that returns the number of
/// bytes stored to the stack. This must be implemented if a backend
/// supports partial stack slot spills/loads to further disambiguate
Expand Down Expand Up @@ -2288,6 +2298,32 @@ class TargetInstrInfo : public MCInstrInfo {
llvm_unreachable("unknown number of operands necessary");
}

/// \Returns true if it is profitable to perform spill2reg on \p MI.
virtual bool isSpill2RegProfitable(const MachineInstr *MI,
const TargetRegisterInfo *TRI,
const MachineRegisterInfo *MRI) const {
llvm_unreachable(
"Target didn't implement TargetInstrInfo::isSpill2RegProfitable!");
}

/// Inserts \p SrcReg into the destination Spill2Reg register \p DstReg.
virtual MachineInstr *spill2RegInsertToS2RReg(
Register S2RReg, Register SrcReg, int OperationBits,
MachineBasicBlock *MBB, MachineBasicBlock::iterator InsertBeforeIt,
const TargetRegisterInfo *TRI, const TargetSubtargetInfo *STI) const {
llvm_unreachable(
"Target didn't implement TargetInstrInfo::spill2RegInsertToS2RReg!");
}

/// Extracts from \p S2RReg into \p DstReg.
virtual MachineInstr *spill2RegExtractFromS2RReg(
Register DstReg, Register S2RReg, int OperationBits,
MachineBasicBlock *InsertMBB, MachineBasicBlock::iterator InsertBeforeIt,
const TargetRegisterInfo *TRI, const TargetSubtargetInfo *STI) const {
llvm_unreachable("Target didn't implement "
"TargetInstrInfo::spill2RegExtractFromS2RReg!");
}

private:
mutable std::unique_ptr<MIRFormatter> Formatter;
unsigned CallFrameSetupOpcode, CallFrameDestroyOpcode;
Expand Down
20 changes: 20 additions & 0 deletions llvm/include/llvm/CodeGen/TargetRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class RegScavenger;
class VirtRegMap;
class LiveIntervals;
class LiveInterval;
class TargetSubtargetInfo;
class TargetRegisterClass {
public:
using iterator = const MCPhysReg *;
Expand Down Expand Up @@ -1233,6 +1234,25 @@ class TargetRegisterInfo : public MCRegisterInfo {
getVRegFlagsOfReg(Register Reg, const MachineFunction &MF) const {
return {};
}

/// \Returns true if a spill/reload of \p Reg can be handled by Spill2Reg.
virtual bool isLegalToSpill2Reg(Register Reg, const TargetRegisterInfo *TRI,
const MachineRegisterInfo *MRI) const {
llvm_unreachable(
"Target didn't implement TargetInstrInfo::isLegalToSpill2Reg!");
}

virtual bool targetSupportsSpill2Reg(const TargetSubtargetInfo *STI) const {
return false;
}

virtual const TargetRegisterClass *
getCandidateRegisterClassForSpill2Reg(const TargetRegisterInfo *TRI,
const TargetSubtargetInfo *STI,
Register SpilledReg) const {
llvm_unreachable("Target didn't implement "
"TargetInstrInfo::getCandidateRegisterClassForSpill2Reg!");
}
};

//===----------------------------------------------------------------------===//
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ void initializeWasmEHPreparePass(PassRegistry &);
void initializeWinEHPreparePass(PassRegistry &);
void initializeWriteBitcodePassPass(PassRegistry &);
void initializeXRayInstrumentationPass(PassRegistry &);
void initializeSpill2RegPass(PassRegistry &);

} // end namespace llvm

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ add_llvm_component_library(LLVMCodeGen
SjLjEHPrepare.cpp
SlotIndexes.cpp
SpillPlacement.cpp
Spill2Reg.cpp
SplitKit.cpp
StackColoring.cpp
StackFrameLayoutAnalysisPass.cpp
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,5 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
initializeWasmEHPreparePass(Registry);
initializeWinEHPreparePass(Registry);
initializeXRayInstrumentationPass(Registry);
initializeSpill2RegPass(Registry);
}
Loading
Loading