Skip to content

Commit 134ceb6

Browse files
committed
[lldb][RISCV] Add separate function for register size evaluation
1 parent f395e48 commit 134ceb6

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ const RegisterInfo *ABISysV_riscv::GetRegisterInfoArray(uint32_t &count) {
136136
// Static Functions
137137
//------------------------------------------------------------------
138138

139+
static inline size_t DeriveRegSizeInBytes(bool is_rv64) {
140+
return is_rv64 ? 8 : 4;
141+
}
142+
139143
ABISP
140144
ABISysV_riscv::CreateInstance(ProcessSP process_sp, const ArchSpec &arch) {
141145
llvm::Triple::ArchType machine = arch.GetTriple().getArch();
@@ -151,14 +155,14 @@ ABISysV_riscv::CreateInstance(ProcessSP process_sp, const ArchSpec &arch) {
151155
}
152156

153157
static inline size_t AugmentArgSize(bool is_rv64, size_t size_in_bytes) {
154-
size_t word_size = is_rv64 ? 8 : 4;
158+
size_t word_size = DeriveRegSizeInBytes(is_rv64);
155159
return llvm::alignTo(size_in_bytes, word_size);
156160
}
157161

158162
static size_t
159163
TotalArgsSizeInWords(bool is_rv64,
160164
const llvm::ArrayRef<ABI::CallArgument> &args) {
161-
size_t reg_size = is_rv64 ? 8 : 4;
165+
size_t reg_size = DeriveRegSizeInBytes(is_rv64);
162166
size_t word_size = reg_size;
163167
size_t total_size = 0;
164168
for (const auto &arg : args)
@@ -275,7 +279,7 @@ bool ABISysV_riscv::PrepareTrivialCall(
275279
if (!process)
276280
return false;
277281

278-
size_t reg_size = m_is_rv64 ? 8 : 4;
282+
size_t reg_size = DeriveRegSizeInBytes(m_is_rv64);
279283
size_t word_size = reg_size;
280284
// Push host data onto target.
281285
for (const auto &arg : args) {
@@ -397,7 +401,7 @@ Status ABISysV_riscv::SetReturnValueObject(StackFrameSP &frame_sp,
397401
return result;
398402
}
399403

400-
size_t reg_size = m_is_rv64 ? 8 : 4;
404+
size_t reg_size = DeriveRegSizeInBytes(m_is_rv64);
401405
if (num_bytes <= 2 * reg_size) {
402406
offset_t offset = 0;
403407
uint64_t raw_value = data.GetMaxU64(&offset, num_bytes);
@@ -752,7 +756,7 @@ ABISysV_riscv::GetReturnValueObjectSimple(Thread &thread,
752756
}
753757
// Aggregate return type
754758
if (compiler_type.IsAggregateType()) {
755-
size_t xlen_byte_size = m_is_rv64 ? 8 : 4;
759+
size_t xlen_byte_size = DeriveRegSizeInBytes(m_is_rv64);
756760

757761
return GetAggregateObj(thread, reg_ctx, compiler_type, xlen_byte_size,
758762
byte_size);
@@ -801,9 +805,7 @@ UnwindPlanSP ABISysV_riscv::CreateDefaultUnwindPlan() {
801805
// Define the CFA as the current frame pointer value.
802806
row.GetCFAValue().SetIsRegisterPlusOffset(fp_reg_num, 0);
803807

804-
int reg_size = 4;
805-
if (m_is_rv64)
806-
reg_size = 8;
808+
int reg_size = DeriveRegSizeInBytes(m_is_rv64);
807809

808810
// Assume the ra reg (return pc) and caller's frame pointer
809811
// have been spilled to stack already.

0 commit comments

Comments
 (0)