44
44
#include " llvm/Support/Error.h"
45
45
#include " llvm/Support/FileSystem.h"
46
46
#include " llvm/Support/TargetSelect.h"
47
+ #include " llvm/TargetParser/Triple.h"
47
48
48
49
#include " llvm/IR/LLVMContext.h"
49
50
#include " llvm/IR/Module.h"
@@ -442,24 +443,50 @@ static void SetupDefaultClangDiagnostics(CompilerInstance &compiler) {
442
443
// / \return
443
444
// / A string representing target ABI for the current architecture.
444
445
static std::string GetClangTargetABI (const ArchSpec &target_arch) {
445
- std::string abi;
446
-
447
446
if (target_arch.IsMIPS ()) {
448
447
switch (target_arch.GetFlags () & ArchSpec::eMIPSABI_mask) {
449
448
case ArchSpec::eMIPSABI_N64:
450
- abi = " n64" ;
451
- break ;
449
+ return " n64" ;
452
450
case ArchSpec::eMIPSABI_N32:
453
- abi = " n32" ;
454
- break ;
451
+ return " n32" ;
455
452
case ArchSpec::eMIPSABI_O32:
456
- abi = " o32" ;
457
- break ;
453
+ return " o32" ;
458
454
default :
459
- break ;
455
+ return {} ;
460
456
}
461
457
}
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 {};
463
490
}
464
491
465
492
static void SetupTargetOpts (CompilerInstance &compiler,
@@ -506,6 +533,18 @@ static void SetupTargetOpts(CompilerInstance &compiler,
506
533
// Set the target ABI
507
534
if (std::string abi = GetClangTargetABI (target_arch); !abi.empty ())
508
535
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" );
509
548
}
510
549
511
550
static void SetupLangOpts (CompilerInstance &compiler,
@@ -757,7 +796,7 @@ ClangExpressionParser::ClangExpressionParser(
757
796
m_compiler->getCodeGenOpts ().EmitDeclMetadata = true ;
758
797
m_compiler->getCodeGenOpts ().InstrumentFunctions = false ;
759
798
m_compiler->getCodeGenOpts ().setFramePointer (
760
- CodeGenOptions::FramePointerKind::All);
799
+ CodeGenOptions::FramePointerKind::All);
761
800
if (generate_debug_info)
762
801
m_compiler->getCodeGenOpts ().setDebugInfo (codegenoptions::FullDebugInfo);
763
802
else
@@ -771,7 +810,7 @@ ClangExpressionParser::ClangExpressionParser(
771
810
// FIXME: We shouldn't need to do this, the target should be immutable once
772
811
// created. This complexity should be lifted elsewhere.
773
812
m_compiler->getTarget ().adjust (m_compiler->getDiagnostics (),
774
- m_compiler->getLangOpts ());
813
+ m_compiler->getLangOpts ());
775
814
776
815
// 5. Set up the diagnostic buffer for reporting errors
777
816
auto diag_mgr = new ClangDiagnosticManagerAdapter (
@@ -1191,8 +1230,7 @@ ClangExpressionParser::ParseInternal(DiagnosticManager &diagnostic_manager,
1191
1230
if (auto fileEntry = m_compiler->getFileManager ().getOptionalFileRef (
1192
1231
result_path)) {
1193
1232
source_mgr.setMainFileID (source_mgr.createFileID (
1194
- *fileEntry,
1195
- SourceLocation (), SrcMgr::C_User));
1233
+ *fileEntry, SourceLocation (), SrcMgr::C_User));
1196
1234
created_main_file = true ;
1197
1235
}
1198
1236
}
0 commit comments