43
43
#include " llvm/Support/Error.h"
44
44
#include " llvm/Support/FileSystem.h"
45
45
#include " llvm/Support/TargetSelect.h"
46
+ #include " llvm/TargetParser/Triple.h"
46
47
47
48
#include " llvm/IR/LLVMContext.h"
48
49
#include " llvm/IR/Module.h"
@@ -407,24 +408,50 @@ static void SetupDefaultClangDiagnostics(CompilerInstance &compiler) {
407
408
// / \return
408
409
// / A string representing target ABI for the current architecture.
409
410
static std::string GetClangTargetABI (const ArchSpec &target_arch) {
410
- std::string abi;
411
-
412
411
if (target_arch.IsMIPS ()) {
413
412
switch (target_arch.GetFlags () & ArchSpec::eMIPSABI_mask) {
414
413
case ArchSpec::eMIPSABI_N64:
415
- abi = " n64" ;
416
- break ;
414
+ return " n64" ;
417
415
case ArchSpec::eMIPSABI_N32:
418
- abi = " n32" ;
419
- break ;
416
+ return " n32" ;
420
417
case ArchSpec::eMIPSABI_O32:
421
- abi = " o32" ;
422
- break ;
418
+ return " o32" ;
423
419
default :
424
- break ;
420
+ return {} ;
425
421
}
426
422
}
427
- return abi;
423
+
424
+ if (target_arch.GetTriple ().isRISCV64 ()) {
425
+ switch (target_arch.GetFlags () & ArchSpec::eRISCV_float_abi_mask) {
426
+ case ArchSpec::eRISCV_float_abi_soft:
427
+ return " lp64" ;
428
+ case ArchSpec::eRISCV_float_abi_single:
429
+ return " lp64f" ;
430
+ case ArchSpec::eRISCV_float_abi_double:
431
+ return " lp64d" ;
432
+ case ArchSpec::eRISCV_float_abi_quad:
433
+ return " lp64q" ;
434
+ default :
435
+ return {};
436
+ }
437
+ }
438
+
439
+ if (target_arch.GetTriple ().isRISCV32 ()) {
440
+ switch (target_arch.GetFlags () & ArchSpec::eRISCV_float_abi_mask) {
441
+ case ArchSpec::eRISCV_float_abi_soft:
442
+ return " ilp32" ;
443
+ case ArchSpec::eRISCV_float_abi_single:
444
+ return " ilp32f" ;
445
+ case ArchSpec::eRISCV_float_abi_double:
446
+ return " ilp32d" ;
447
+ case ArchSpec::eRISCV_float_abi_soft | ArchSpec::eRISCV_rve:
448
+ return " ilp32e" ;
449
+ default :
450
+ return {};
451
+ }
452
+ }
453
+
454
+ return {};
428
455
}
429
456
430
457
static void SetupTargetOpts (CompilerInstance &compiler,
@@ -471,6 +498,18 @@ static void SetupTargetOpts(CompilerInstance &compiler,
471
498
// Set the target ABI
472
499
if (std::string abi = GetClangTargetABI (target_arch); !abi.empty ())
473
500
compiler.getTargetOpts ().ABI = std::move (abi);
501
+
502
+ if ((target_machine == llvm::Triple::riscv64 &&
503
+ compiler.getTargetOpts ().ABI == " lp64f" ) ||
504
+ (target_machine == llvm::Triple::riscv32 &&
505
+ compiler.getTargetOpts ().ABI == " ilp32f" ))
506
+ compiler.getTargetOpts ().FeaturesAsWritten .emplace_back (" +f" );
507
+
508
+ if ((target_machine == llvm::Triple::riscv64 &&
509
+ compiler.getTargetOpts ().ABI == " lp64d" ) ||
510
+ (target_machine == llvm::Triple::riscv32 &&
511
+ compiler.getTargetOpts ().ABI == " ilp32d" ))
512
+ compiler.getTargetOpts ().FeaturesAsWritten .emplace_back (" +d" );
474
513
}
475
514
476
515
static void SetupLangOpts (CompilerInstance &compiler,
@@ -722,7 +761,7 @@ ClangExpressionParser::ClangExpressionParser(
722
761
m_compiler->getCodeGenOpts ().EmitDeclMetadata = true ;
723
762
m_compiler->getCodeGenOpts ().InstrumentFunctions = false ;
724
763
m_compiler->getCodeGenOpts ().setFramePointer (
725
- CodeGenOptions::FramePointerKind::All);
764
+ CodeGenOptions::FramePointerKind::All);
726
765
if (generate_debug_info)
727
766
m_compiler->getCodeGenOpts ().setDebugInfo (codegenoptions::FullDebugInfo);
728
767
else
@@ -736,7 +775,7 @@ ClangExpressionParser::ClangExpressionParser(
736
775
// FIXME: We shouldn't need to do this, the target should be immutable once
737
776
// created. This complexity should be lifted elsewhere.
738
777
m_compiler->getTarget ().adjust (m_compiler->getDiagnostics (),
739
- m_compiler->getLangOpts ());
778
+ m_compiler->getLangOpts ());
740
779
741
780
// 5. Set up the diagnostic buffer for reporting errors
742
781
@@ -1156,8 +1195,7 @@ ClangExpressionParser::ParseInternal(DiagnosticManager &diagnostic_manager,
1156
1195
if (auto fileEntry = m_compiler->getFileManager ().getOptionalFileRef (
1157
1196
result_path)) {
1158
1197
source_mgr.setMainFileID (source_mgr.createFileID (
1159
- *fileEntry,
1160
- SourceLocation (), SrcMgr::C_User));
1198
+ *fileEntry, SourceLocation (), SrcMgr::C_User));
1161
1199
created_main_file = true ;
1162
1200
}
1163
1201
}
@@ -1504,7 +1542,8 @@ lldb_private::Status ClangExpressionParser::DoPrepareForExecution(
1504
1542
1505
1543
DiagnosticManager install_diags;
1506
1544
if (Error Err = dynamic_checkers->Install (install_diags, exe_ctx)) {
1507
- std::string ErrMsg = " couldn't install checkers: " + toString (std::move (Err));
1545
+ std::string ErrMsg =
1546
+ " couldn't install checkers: " + toString (std::move (Err));
1508
1547
if (install_diags.Diagnostics ().size ())
1509
1548
ErrMsg = ErrMsg + " \n " + install_diags.GetString ().c_str ();
1510
1549
err = Status (ErrMsg);
0 commit comments