-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[RISCV] Use vsetvli instead of vlenb in Prologue/Epilogue #113756
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7149518
[RISCV] Use vsetvli instead of vlenb in Prologue/Epilogue
kito-cheng 1573c2b
Apply Craig's suggestion
kito-cheng 0b1e453
Address Luke's comment
kito-cheng bbd5b17
Apply Craig's comment
kito-cheng 091fe30
fixup Rename PseudoReadMulVLENB to PseudoReadVLENBViaVSETVLIX0
kito-cheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1534,6 +1534,12 @@ def TuneVentanaVeyron : SubtargetFeature<"ventana-veyron", "RISCVProcFamily", "V | |
def TuneVXRMPipelineFlush : SubtargetFeature<"vxrm-pipeline-flush", "HasVXRMPipelineFlush", | ||
"true", "VXRM writes causes pipeline flush">; | ||
|
||
def TunePreferVsetvliOverReadVLENB | ||
: SubtargetFeature<"prefer-vsetvli-over-read-vlenb", | ||
"PreferVsetvliOverReadVLENB", | ||
"true", | ||
"Prefer vsetvli over read vlenb CSR when calculate VLEN">; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// Assume that lock-free native-width atomics are available, even if the target | ||
// and operating system combination would not usually provide them. The user | ||
// is responsible for providing any necessary __sync implementations. Code | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -669,7 +669,8 @@ void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB, | |
// Simply allocate the stack if it's not big enough to require a probe. | ||
if (!NeedProbe || Offset <= ProbeSize) { | ||
RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg, StackOffset::getFixed(-Offset), | ||
MachineInstr::FrameSetup, getStackAlign()); | ||
MachineInstr::FrameSetup, getStackAlign(), | ||
/*IsPrologueOrEpilogue*/ true); | ||
|
||
if (EmitCFI) { | ||
// Emit ".cfi_def_cfa_offset RealStackSize" | ||
|
@@ -698,7 +699,7 @@ void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB, | |
while (CurrentOffset + ProbeSize <= Offset) { | ||
RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg, | ||
StackOffset::getFixed(-ProbeSize), MachineInstr::FrameSetup, | ||
getStackAlign()); | ||
getStackAlign(), /*IsPrologueOrEpilogue*/ true); | ||
// s[d|w] zero, 0(sp) | ||
BuildMI(MBB, MBBI, DL, TII->get(IsRV64 ? RISCV::SD : RISCV::SW)) | ||
.addReg(RISCV::X0) | ||
|
@@ -721,7 +722,7 @@ void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB, | |
if (Residual) { | ||
RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg, | ||
StackOffset::getFixed(-Residual), MachineInstr::FrameSetup, | ||
getStackAlign()); | ||
getStackAlign(), /*IsPrologueOrEpilogue*/ true); | ||
if (EmitCFI) { | ||
// Emit ".cfi_def_cfa_offset Offset" | ||
unsigned CFIIndex = | ||
|
@@ -752,7 +753,7 @@ void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB, | |
// SUB TargetReg, SP, RoundedSize | ||
RI->adjustReg(MBB, MBBI, DL, TargetReg, SPReg, | ||
StackOffset::getFixed(-RoundedSize), MachineInstr::FrameSetup, | ||
getStackAlign()); | ||
getStackAlign(), /*IsPrologueOrEpilogue*/ true); | ||
|
||
if (EmitCFI) { | ||
// Set the CFA register to TargetReg. | ||
|
@@ -781,7 +782,8 @@ void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB, | |
|
||
if (Residual) { | ||
RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg, StackOffset::getFixed(-Residual), | ||
MachineInstr::FrameSetup, getStackAlign()); | ||
MachineInstr::FrameSetup, getStackAlign(), | ||
/*IsPrologueOrEpilogue*/ true); | ||
if (DynAllocation) { | ||
// s[d|w] zero, 0(sp) | ||
BuildMI(MBB, MBBI, DL, TII->get(IsRV64 ? RISCV::SD : RISCV::SW)) | ||
|
@@ -1014,7 +1016,8 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF, | |
RI->adjustReg( | ||
MBB, MBBI, DL, FPReg, SPReg, | ||
StackOffset::getFixed(RealStackSize - RVFI->getVarArgsSaveSize()), | ||
MachineInstr::FrameSetup, getStackAlign()); | ||
MachineInstr::FrameSetup, getStackAlign(), | ||
/*IsPrologueOrEpilogue*/ true); | ||
} | ||
|
||
// Emit ".cfi_def_cfa $fp, RVFI->getVarArgsSaveSize()" | ||
|
@@ -1047,7 +1050,8 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF, | |
// updates. | ||
RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg, | ||
StackOffset::getScalable(-RVVStackSize), | ||
MachineInstr::FrameSetup, getStackAlign()); | ||
MachineInstr::FrameSetup, getStackAlign(), | ||
/*IsPrologueOrEpilogue*/ true); | ||
} | ||
|
||
if (!hasFP(MF)) { | ||
|
@@ -1125,7 +1129,8 @@ void RISCVFrameLowering::deallocateStack(MachineFunction &MF, | |
const RISCVInstrInfo *TII = STI.getInstrInfo(); | ||
|
||
RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg, StackOffset::getFixed(StackSize), | ||
MachineInstr::FrameDestroy, getStackAlign()); | ||
MachineInstr::FrameDestroy, getStackAlign(), | ||
/*IsPrologueOrEpilogue*/ true); | ||
StackSize = 0; | ||
|
||
unsigned CFIIndex = | ||
|
@@ -1189,7 +1194,8 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF, | |
if (!RestoreSPFromFP) | ||
RI->adjustReg(MBB, FirstScalarCSRRestoreInsn, DL, SPReg, SPReg, | ||
StackOffset::getScalable(RVVStackSize), | ||
MachineInstr::FrameDestroy, getStackAlign()); | ||
MachineInstr::FrameDestroy, getStackAlign(), | ||
/*IsPrologueOrEpilogue*/ true); | ||
|
||
if (!hasFP(MF)) { | ||
unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfa( | ||
|
@@ -1214,7 +1220,8 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF, | |
if (!RestoreSPFromFP) | ||
RI->adjustReg(MBB, FirstScalarCSRRestoreInsn, DL, SPReg, SPReg, | ||
StackOffset::getFixed(SecondSPAdjustAmount), | ||
MachineInstr::FrameDestroy, getStackAlign()); | ||
MachineInstr::FrameDestroy, getStackAlign(), | ||
/*IsPrologueOrEpilogue*/ true); | ||
|
||
if (!hasFP(MF)) { | ||
unsigned CFIIndex = MF.addFrameInst( | ||
|
@@ -1240,7 +1247,7 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF, | |
assert(hasFP(MF) && "frame pointer should not have been eliminated"); | ||
RI->adjustReg(MBB, FirstScalarCSRRestoreInsn, DL, SPReg, FPReg, | ||
StackOffset::getFixed(-FPOffset), MachineInstr::FrameDestroy, | ||
getStackAlign()); | ||
getStackAlign(), /*IsPrologueOrEpilogue*/ true); | ||
} | ||
|
||
if (hasFP(MF)) { | ||
|
@@ -1771,7 +1778,8 @@ MachineBasicBlock::iterator RISCVFrameLowering::eliminateCallFramePseudoInstr( | |
|
||
const RISCVRegisterInfo &RI = *STI.getRegisterInfo(); | ||
RI.adjustReg(MBB, MI, DL, SPReg, SPReg, StackOffset::getFixed(Amount), | ||
MachineInstr::NoFlags, getStackAlign()); | ||
MachineInstr::NoFlags, getStackAlign(), | ||
/*IsPrologueOrEpilogue*/ true); | ||
} | ||
} | ||
|
||
|
@@ -2195,6 +2203,17 @@ bool RISCVFrameLowering::canUseAsPrologue(const MachineBasicBlock &MBB) const { | |
const MachineFunction *MF = MBB.getParent(); | ||
const auto *RVFI = MF->getInfo<RISCVMachineFunctionInfo>(); | ||
|
||
// Make sure VTYPE and VL are not live-in since we will use vsetvli in the | ||
// prologue to get the VLEN, and that will clobber these registers. | ||
// | ||
// We may do also check the stack has contain for the object with the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "has contain for the object with the " -> "contains objects with" |
||
// scalable vector type, but this will require iterating over all the stack | ||
// objects, but this may not worth since the situation is rare, we could do | ||
// further check in future if we find it is necessary. | ||
if (STI.preferVsetvliOverReadVLENB() && | ||
(MBB.isLiveIn(RISCV::VTYPE) || MBB.isLiveIn(RISCV::VL))) | ||
return false; | ||
|
||
if (!RVFI->useSaveRestoreLibCalls(*MF)) | ||
return true; | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.