Skip to content

Commit 067744c

Browse files
committed
[RISCV] Simplify getStackAdjBase. NFC
Use math instead of a switch.
1 parent bdace10 commit 067744c

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
@@ -592,49 +592,13 @@ inline unsigned encodeRlist(MCRegister EndReg, bool IsRV32E = false) {
592592
inline static unsigned getStackAdjBase(unsigned RlistVal, bool IsRV64) {
593593
assert(RlistVal != RLISTENCODE::INVALID_RLIST &&
594594
"{ra, s0-s10} is not supported, s11 must be included.");
595-
if (!IsRV64) {
596-
switch (RlistVal) {
597-
case RLISTENCODE::RA:
598-
case RLISTENCODE::RA_S0:
599-
case RLISTENCODE::RA_S0_S1:
600-
case RLISTENCODE::RA_S0_S2:
601-
return 16;
602-
case RLISTENCODE::RA_S0_S3:
603-
case RLISTENCODE::RA_S0_S4:
604-
case RLISTENCODE::RA_S0_S5:
605-
case RLISTENCODE::RA_S0_S6:
606-
return 32;
607-
case RLISTENCODE::RA_S0_S7:
608-
case RLISTENCODE::RA_S0_S8:
609-
case RLISTENCODE::RA_S0_S9:
610-
return 48;
611-
case RLISTENCODE::RA_S0_S11:
612-
return 64;
613-
}
614-
} else {
615-
switch (RlistVal) {
616-
case RLISTENCODE::RA:
617-
case RLISTENCODE::RA_S0:
618-
return 16;
619-
case RLISTENCODE::RA_S0_S1:
620-
case RLISTENCODE::RA_S0_S2:
621-
return 32;
622-
case RLISTENCODE::RA_S0_S3:
623-
case RLISTENCODE::RA_S0_S4:
624-
return 48;
625-
case RLISTENCODE::RA_S0_S5:
626-
case RLISTENCODE::RA_S0_S6:
627-
return 64;
628-
case RLISTENCODE::RA_S0_S7:
629-
case RLISTENCODE::RA_S0_S8:
630-
return 80;
631-
case RLISTENCODE::RA_S0_S9:
632-
return 96;
633-
case RLISTENCODE::RA_S0_S11:
634-
return 112;
635-
}
636-
}
637-
llvm_unreachable("Unexpected RlistVal");
595+
unsigned NumRegs = (RlistVal - RLISTENCODE::RA) + 1;
596+
// s10 and s11 are saved together.
597+
if (RlistVal == RLISTENCODE::RA_S0_S11)
598+
++NumRegs;
599+
600+
unsigned RegSize = IsRV64 ? 8 : 4;
601+
return alignTo(NumRegs * RegSize, 16);
638602
}
639603

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

0 commit comments

Comments
 (0)