Skip to content

Commit 22965dc

Browse files
authored
[RISCV] Simplify getStackAdjBase. NFC (#129281)
Use math instead of a switch.
1 parent a19e685 commit 22965dc

File tree

1 file changed

+7
-43
lines changed

1 file changed

+7
-43
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -629,49 +629,13 @@ inline unsigned encodeRlist(MCRegister EndReg, bool IsRV32E = false) {
629629
inline static unsigned getStackAdjBase(unsigned RlistVal, bool IsRV64) {
630630
assert(RlistVal != RLISTENCODE::INVALID_RLIST &&
631631
"{ra, s0-s10} is not supported, s11 must be included.");
632-
if (!IsRV64) {
633-
switch (RlistVal) {
634-
case RLISTENCODE::RA:
635-
case RLISTENCODE::RA_S0:
636-
case RLISTENCODE::RA_S0_S1:
637-
case RLISTENCODE::RA_S0_S2:
638-
return 16;
639-
case RLISTENCODE::RA_S0_S3:
640-
case RLISTENCODE::RA_S0_S4:
641-
case RLISTENCODE::RA_S0_S5:
642-
case RLISTENCODE::RA_S0_S6:
643-
return 32;
644-
case RLISTENCODE::RA_S0_S7:
645-
case RLISTENCODE::RA_S0_S8:
646-
case RLISTENCODE::RA_S0_S9:
647-
return 48;
648-
case RLISTENCODE::RA_S0_S11:
649-
return 64;
650-
}
651-
} else {
652-
switch (RlistVal) {
653-
case RLISTENCODE::RA:
654-
case RLISTENCODE::RA_S0:
655-
return 16;
656-
case RLISTENCODE::RA_S0_S1:
657-
case RLISTENCODE::RA_S0_S2:
658-
return 32;
659-
case RLISTENCODE::RA_S0_S3:
660-
case RLISTENCODE::RA_S0_S4:
661-
return 48;
662-
case RLISTENCODE::RA_S0_S5:
663-
case RLISTENCODE::RA_S0_S6:
664-
return 64;
665-
case RLISTENCODE::RA_S0_S7:
666-
case RLISTENCODE::RA_S0_S8:
667-
return 80;
668-
case RLISTENCODE::RA_S0_S9:
669-
return 96;
670-
case RLISTENCODE::RA_S0_S11:
671-
return 112;
672-
}
673-
}
674-
llvm_unreachable("Unexpected RlistVal");
632+
unsigned NumRegs = (RlistVal - RLISTENCODE::RA) + 1;
633+
// s10 and s11 are saved together.
634+
if (RlistVal == RLISTENCODE::RA_S0_S11)
635+
++NumRegs;
636+
637+
unsigned RegSize = IsRV64 ? 8 : 4;
638+
return alignTo(NumRegs * RegSize, 16);
675639
}
676640

677641
void printRlist(unsigned SlistEncode, raw_ostream &OS);

0 commit comments

Comments
 (0)