-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[Sparc] Use helper class for emitting CFI instructions into MIR #136027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Also, guard emission by `needsFrameMoves()` check. There are no changes in tests because cfi directives are currently suppressed by AsmPrinter when don't need to be printed.
@llvm/pr-subscribers-backend-sparc Author: Sergei Barannikov (s-barannikov) ChangesAlso, guard emission by Full diff: https://github.com/llvm/llvm-project/pull/136027.diff 2 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/CFIInstBuilder.h b/llvm/include/llvm/CodeGen/CFIInstBuilder.h
index e799b47a0c974..48e2897747783 100644
--- a/llvm/include/llvm/CodeGen/CFIInstBuilder.h
+++ b/llvm/include/llvm/CodeGen/CFIInstBuilder.h
@@ -72,6 +72,16 @@ class CFIInstBuilder {
nullptr, TRI.getDwarfRegNum(Reg, IsEH), Offset));
}
+ void buildRegister(MCRegister Reg1, MCRegister Reg2) const {
+ insertCFIInst(MCCFIInstruction::createRegister(
+ nullptr, TRI.getDwarfRegNum(Reg1, IsEH),
+ TRI.getDwarfRegNum(Reg2, IsEH)));
+ }
+
+ void buildWindowSave() const {
+ insertCFIInst(MCCFIInstruction::createWindowSave(nullptr));
+ }
+
void buildRestore(MCRegister Reg) const {
insertCFIInst(MCCFIInstruction::createRestore(
nullptr, TRI.getDwarfRegNum(Reg, IsEH)));
diff --git a/llvm/lib/Target/Sparc/SparcFrameLowering.cpp b/llvm/lib/Target/Sparc/SparcFrameLowering.cpp
index 14233a526eec1..2934c88b6bffc 100644
--- a/llvm/lib/Target/Sparc/SparcFrameLowering.cpp
+++ b/llvm/lib/Target/Sparc/SparcFrameLowering.cpp
@@ -14,6 +14,7 @@
#include "SparcInstrInfo.h"
#include "SparcMachineFunctionInfo.h"
#include "SparcSubtarget.h"
+#include "llvm/CodeGen/CFIInstBuilder.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
@@ -88,14 +89,7 @@ void SparcFrameLowering::emitPrologue(MachineFunction &MF,
assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
MachineFrameInfo &MFI = MF.getFrameInfo();
const SparcSubtarget &Subtarget = MF.getSubtarget<SparcSubtarget>();
- const SparcInstrInfo &TII =
- *static_cast<const SparcInstrInfo *>(Subtarget.getInstrInfo());
- const SparcRegisterInfo &RegInfo =
- *static_cast<const SparcRegisterInfo *>(Subtarget.getRegisterInfo());
MachineBasicBlock::iterator MBBI = MBB.begin();
- // Debug location must be unknown since the first debug location is used
- // to determine the end of the prologue.
- DebugLoc dl;
// Get the number of bytes to allocate from the FrameInfo
int NumBytes = (int) MFI.getStackSize();
@@ -141,26 +135,12 @@ void SparcFrameLowering::emitPrologue(MachineFunction &MF,
emitSPAdjustment(MF, MBB, MBBI, -NumBytes, SAVErr, SAVEri);
- unsigned regFP = RegInfo.getDwarfRegNum(SP::I6, true);
-
- // Emit ".cfi_def_cfa_register 30".
- unsigned CFIIndex =
- MF.addFrameInst(MCCFIInstruction::createDefCfaRegister(nullptr, regFP));
- BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
- .addCFIIndex(CFIIndex);
-
- // Emit ".cfi_window_save".
- CFIIndex = MF.addFrameInst(MCCFIInstruction::createWindowSave(nullptr));
- BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
- .addCFIIndex(CFIIndex);
-
- unsigned regInRA = RegInfo.getDwarfRegNum(SP::I7, true);
- unsigned regOutRA = RegInfo.getDwarfRegNum(SP::O7, true);
- // Emit ".cfi_register 15, 31".
- CFIIndex = MF.addFrameInst(
- MCCFIInstruction::createRegister(nullptr, regOutRA, regInRA));
- BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
- .addCFIIndex(CFIIndex);
+ if (MF.needsFrameMoves()) {
+ CFIInstBuilder CFIBuilder(MBB, MBBI, MachineInstr::NoFlags);
+ CFIBuilder.buildDefCFARegister(SP::I6);
+ CFIBuilder.buildWindowSave();
+ CFIBuilder.buildRegister(SP::O7, SP::I7);
+ }
}
MachineBasicBlock::iterator SparcFrameLowering::
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems OK
…o MIR (#136027) Also, guard emission by `needsFrameMoves()` check. There are no changes in tests because cfi instructions are currently ignored by AsmPrinter when they don't need to be printed/encoded. PR: llvm/llvm-project#136027
…#136027) Also, guard emission by `needsFrameMoves()` check. There are no changes in tests because cfi instructions are currently ignored by AsmPrinter when they don't need to be printed/encoded. PR: llvm#136027
Also, guard emission by
needsFrameMoves()
check. There are no changes in tests because cfi directives are currently suppressed by AsmPrinter when don't need to be printed.