Skip to content

Commit

Permalink
[lldb][RISCV] doubles support in lldb expressions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dlav-sc committed Sep 30, 2024
1 parent d0f0e1c commit 05e62e5
Showing 1 changed file with 52 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/TargetParser/Triple.h"

#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
Expand Down Expand Up @@ -442,24 +443,50 @@ static void SetupDefaultClangDiagnostics(CompilerInstance &compiler) {
/// \return
/// A string representing target ABI for the current architecture.
static std::string GetClangTargetABI(const ArchSpec &target_arch) {
std::string abi;

if (target_arch.IsMIPS()) {
switch (target_arch.GetFlags() & ArchSpec::eMIPSABI_mask) {
case ArchSpec::eMIPSABI_N64:
abi = "n64";
break;
return "n64";
case ArchSpec::eMIPSABI_N32:
abi = "n32";
break;
return "n32";
case ArchSpec::eMIPSABI_O32:
abi = "o32";
break;
return "o32";
default:
break;
return {};
}
}
return abi;

if (target_arch.GetTriple().isRISCV64()) {
switch (target_arch.GetFlags() & ArchSpec::eRISCV_float_abi_mask) {
case ArchSpec::eRISCV_float_abi_soft:
return "lp64";
case ArchSpec::eRISCV_float_abi_single:
return "lp64f";
case ArchSpec::eRISCV_float_abi_double:
return "lp64d";
case ArchSpec::eRISCV_float_abi_quad:
return "lp64q";
default:
return {};
}
}

if (target_arch.GetTriple().isRISCV32()) {
switch (target_arch.GetFlags() & ArchSpec::eRISCV_float_abi_mask) {
case ArchSpec::eRISCV_float_abi_soft:
return "ilp32";
case ArchSpec::eRISCV_float_abi_single:
return "ilp32f";
case ArchSpec::eRISCV_float_abi_double:
return "ilp32d";
case ArchSpec::eRISCV_float_abi_soft | ArchSpec::eRISCV_rve:
return "ilp32e";
default:
return {};
}
}

return {};
}

static void SetupTargetOpts(CompilerInstance &compiler,
Expand Down Expand Up @@ -506,6 +533,18 @@ static void SetupTargetOpts(CompilerInstance &compiler,
// Set the target ABI
if (std::string abi = GetClangTargetABI(target_arch); !abi.empty())
compiler.getTargetOpts().ABI = std::move(abi);

if ((target_machine == llvm::Triple::riscv64 &&
compiler.getTargetOpts().ABI == "lp64f") ||
(target_machine == llvm::Triple::riscv32 &&
compiler.getTargetOpts().ABI == "ilp32f"))
compiler.getTargetOpts().FeaturesAsWritten.emplace_back("+f");

if ((target_machine == llvm::Triple::riscv64 &&
compiler.getTargetOpts().ABI == "lp64d") ||
(target_machine == llvm::Triple::riscv32 &&
compiler.getTargetOpts().ABI == "ilp32d"))
compiler.getTargetOpts().FeaturesAsWritten.emplace_back("+d");
}

static void SetupLangOpts(CompilerInstance &compiler,
Expand Down Expand Up @@ -757,7 +796,7 @@ ClangExpressionParser::ClangExpressionParser(
m_compiler->getCodeGenOpts().EmitDeclMetadata = true;
m_compiler->getCodeGenOpts().InstrumentFunctions = false;
m_compiler->getCodeGenOpts().setFramePointer(
CodeGenOptions::FramePointerKind::All);
CodeGenOptions::FramePointerKind::All);
if (generate_debug_info)
m_compiler->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo);
else
Expand All @@ -771,7 +810,7 @@ ClangExpressionParser::ClangExpressionParser(
// FIXME: We shouldn't need to do this, the target should be immutable once
// created. This complexity should be lifted elsewhere.
m_compiler->getTarget().adjust(m_compiler->getDiagnostics(),
m_compiler->getLangOpts());
m_compiler->getLangOpts());

// 5. Set up the diagnostic buffer for reporting errors
auto diag_mgr = new ClangDiagnosticManagerAdapter(
Expand Down Expand Up @@ -1191,8 +1230,7 @@ ClangExpressionParser::ParseInternal(DiagnosticManager &diagnostic_manager,
if (auto fileEntry = m_compiler->getFileManager().getOptionalFileRef(
result_path)) {
source_mgr.setMainFileID(source_mgr.createFileID(
*fileEntry,
SourceLocation(), SrcMgr::C_User));
*fileEntry, SourceLocation(), SrcMgr::C_User));
created_main_file = true;
}
}
Expand Down

0 comments on commit 05e62e5

Please sign in to comment.