Skip to content

Commit 05e62e5

Browse files
committed
[lldb][RISCV] doubles support in lldb expressions
Function calls support in LLDB expressions for RISCV: 4 of 4 This patch adds desired feature flags in MCJIT compiler to enable hard-float instructions if target supports them and allows to use floats and doubles in lldb expressions.
1 parent d0f0e1c commit 05e62e5

File tree

1 file changed

+52
-14
lines changed

1 file changed

+52
-14
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "llvm/Support/Error.h"
4545
#include "llvm/Support/FileSystem.h"
4646
#include "llvm/Support/TargetSelect.h"
47+
#include "llvm/TargetParser/Triple.h"
4748

4849
#include "llvm/IR/LLVMContext.h"
4950
#include "llvm/IR/Module.h"
@@ -442,24 +443,50 @@ static void SetupDefaultClangDiagnostics(CompilerInstance &compiler) {
442443
/// \return
443444
/// A string representing target ABI for the current architecture.
444445
static std::string GetClangTargetABI(const ArchSpec &target_arch) {
445-
std::string abi;
446-
447446
if (target_arch.IsMIPS()) {
448447
switch (target_arch.GetFlags() & ArchSpec::eMIPSABI_mask) {
449448
case ArchSpec::eMIPSABI_N64:
450-
abi = "n64";
451-
break;
449+
return "n64";
452450
case ArchSpec::eMIPSABI_N32:
453-
abi = "n32";
454-
break;
451+
return "n32";
455452
case ArchSpec::eMIPSABI_O32:
456-
abi = "o32";
457-
break;
453+
return "o32";
458454
default:
459-
break;
455+
return {};
460456
}
461457
}
462-
return abi;
458+
459+
if (target_arch.GetTriple().isRISCV64()) {
460+
switch (target_arch.GetFlags() & ArchSpec::eRISCV_float_abi_mask) {
461+
case ArchSpec::eRISCV_float_abi_soft:
462+
return "lp64";
463+
case ArchSpec::eRISCV_float_abi_single:
464+
return "lp64f";
465+
case ArchSpec::eRISCV_float_abi_double:
466+
return "lp64d";
467+
case ArchSpec::eRISCV_float_abi_quad:
468+
return "lp64q";
469+
default:
470+
return {};
471+
}
472+
}
473+
474+
if (target_arch.GetTriple().isRISCV32()) {
475+
switch (target_arch.GetFlags() & ArchSpec::eRISCV_float_abi_mask) {
476+
case ArchSpec::eRISCV_float_abi_soft:
477+
return "ilp32";
478+
case ArchSpec::eRISCV_float_abi_single:
479+
return "ilp32f";
480+
case ArchSpec::eRISCV_float_abi_double:
481+
return "ilp32d";
482+
case ArchSpec::eRISCV_float_abi_soft | ArchSpec::eRISCV_rve:
483+
return "ilp32e";
484+
default:
485+
return {};
486+
}
487+
}
488+
489+
return {};
463490
}
464491

465492
static void SetupTargetOpts(CompilerInstance &compiler,
@@ -506,6 +533,18 @@ static void SetupTargetOpts(CompilerInstance &compiler,
506533
// Set the target ABI
507534
if (std::string abi = GetClangTargetABI(target_arch); !abi.empty())
508535
compiler.getTargetOpts().ABI = std::move(abi);
536+
537+
if ((target_machine == llvm::Triple::riscv64 &&
538+
compiler.getTargetOpts().ABI == "lp64f") ||
539+
(target_machine == llvm::Triple::riscv32 &&
540+
compiler.getTargetOpts().ABI == "ilp32f"))
541+
compiler.getTargetOpts().FeaturesAsWritten.emplace_back("+f");
542+
543+
if ((target_machine == llvm::Triple::riscv64 &&
544+
compiler.getTargetOpts().ABI == "lp64d") ||
545+
(target_machine == llvm::Triple::riscv32 &&
546+
compiler.getTargetOpts().ABI == "ilp32d"))
547+
compiler.getTargetOpts().FeaturesAsWritten.emplace_back("+d");
509548
}
510549

511550
static void SetupLangOpts(CompilerInstance &compiler,
@@ -757,7 +796,7 @@ ClangExpressionParser::ClangExpressionParser(
757796
m_compiler->getCodeGenOpts().EmitDeclMetadata = true;
758797
m_compiler->getCodeGenOpts().InstrumentFunctions = false;
759798
m_compiler->getCodeGenOpts().setFramePointer(
760-
CodeGenOptions::FramePointerKind::All);
799+
CodeGenOptions::FramePointerKind::All);
761800
if (generate_debug_info)
762801
m_compiler->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo);
763802
else
@@ -771,7 +810,7 @@ ClangExpressionParser::ClangExpressionParser(
771810
// FIXME: We shouldn't need to do this, the target should be immutable once
772811
// created. This complexity should be lifted elsewhere.
773812
m_compiler->getTarget().adjust(m_compiler->getDiagnostics(),
774-
m_compiler->getLangOpts());
813+
m_compiler->getLangOpts());
775814

776815
// 5. Set up the diagnostic buffer for reporting errors
777816
auto diag_mgr = new ClangDiagnosticManagerAdapter(
@@ -1191,8 +1230,7 @@ ClangExpressionParser::ParseInternal(DiagnosticManager &diagnostic_manager,
11911230
if (auto fileEntry = m_compiler->getFileManager().getOptionalFileRef(
11921231
result_path)) {
11931232
source_mgr.setMainFileID(source_mgr.createFileID(
1194-
*fileEntry,
1195-
SourceLocation(), SrcMgr::C_User));
1233+
*fileEntry, SourceLocation(), SrcMgr::C_User));
11961234
created_main_file = true;
11971235
}
11981236
}

0 commit comments

Comments
 (0)