[llvm-branch-commits] [llvm] [RISCV] Use a fully covered switch in RISCVABI::getStackAlignment. (PR #239053)
Craig Topper via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 4 23:04:55 PST 2026
https://github.com/topperc updated https://github.com/llvm/llvm-project/pull/239053
>From fbdb151c71879eea85bcd53dc198f8d894fcbc7e Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Wed, 4 Nov 2026 17:29:31 -0800
Subject: [PATCH] [RISCV] Use a fully covered switch in
RISCVABI::getStackAlignment.
This makes it more obvious the alignment has been chosen explicitly
for every ABI.
Not quite NFC because we no longer emit the stack align attribute for
an unknown ABI.
---
.../Target/RISCV/MCTargetDesc/RISCVBaseInfo.h | 26 ++++++++++++++++---
.../MCTargetDesc/RISCVTargetStreamer.cpp | 2 +-
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
index 9ab55df9cab6d..f423e2b6075db 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
@@ -813,13 +813,31 @@ inline bool isPurecap(ABI TargetABI) {
}
// Returns the stack alignment required by the ABI.
-// FIXME: Add the purecap variants of the E ABIs?
inline Align getStackAlignment(ABI TargetABI) {
- if (TargetABI == ABI::ILP32E)
+ switch (TargetABI) {
+ case ABI::ILP32E:
return Align(4);
- if (TargetABI == ABI::LP64E)
+ case ABI::LP64E:
return Align(8);
- return Align(16);
+ case ABI::ILP32:
+ case ABI::ILP32F:
+ case ABI::ILP32D:
+ case ABI::IL32PC64:
+ case ABI::IL32PC64F:
+ case ABI::IL32PC64D:
+ case ABI::IL32PC64E:
+ case ABI::LP64:
+ case ABI::LP64F:
+ case ABI::LP64D:
+ case ABI::L64PC128:
+ case ABI::L64PC128F:
+ case ABI::L64PC128D:
+ case ABI::CHERIOT:
+ return Align(16);
+ case ABI::Unknown:
+ llvm_unreachable("Unknown ABI has no stack alignment");
+ }
+ llvm_unreachable("Unhandled ABI");
}
// Returns the target ABI, or else a StringError if the requested ABIName is
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
index a43b6e50b6179..56fb2cc8bfc2b 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
@@ -64,7 +64,7 @@ void RISCVTargetStreamer::setFlagsFromFeatures(const MCSubtargetInfo &STI) {
void RISCVTargetStreamer::emitTargetAttributes(const MCSubtargetInfo &STI,
bool EmitStackAlign) {
- if (EmitStackAlign)
+ if (EmitStackAlign && TargetABI != RISCVABI::ABI::Unknown)
emitAttribute(RISCVAttrs::STACK_ALIGN,
RISCVABI::getStackAlignment(TargetABI).value());
More information about the llvm-branch-commits
mailing list