Skip to content

Commit fff026c

Browse files
committed
rustc_llvm: expose FloatABIType target machine parameter
1 parent f95c996 commit fff026c

File tree

4 files changed

+39
-14
lines changed

4 files changed

+39
-14
lines changed

compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl OwnedTargetMachine {
2525
model: llvm::CodeModel,
2626
reloc: llvm::RelocModel,
2727
level: llvm::CodeGenOptLevel,
28-
use_soft_fp: bool,
28+
float_abi: llvm::FloatAbi,
2929
function_sections: bool,
3030
data_sections: bool,
3131
unique_section_names: bool,
@@ -57,7 +57,7 @@ impl OwnedTargetMachine {
5757
model,
5858
reloc,
5959
level,
60-
use_soft_fp,
60+
float_abi,
6161
function_sections,
6262
data_sections,
6363
unique_section_names,

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use crate::errors::{
4040
WithLlvmError, WriteBytecode,
4141
};
4242
use crate::llvm::diagnostic::OptimizationDiagnosticKind::*;
43-
use crate::llvm::{self, DiagnosticInfo, PassManager};
43+
use crate::llvm::{self, DiagnosticInfo, FloatAbi, PassManager};
4444
use crate::type_::Type;
4545
use crate::{LlvmCodegenBackend, ModuleLlvm, base, common, llvm_util};
4646

@@ -189,12 +189,12 @@ pub(crate) fn target_machine_factory(
189189
let reloc_model = to_llvm_relocation_model(sess.relocation_model());
190190

191191
let (opt_level, _) = to_llvm_opt_settings(optlvl);
192-
let use_softfp = if sess.target.arch == "arm" {
193-
sess.opts.cg.soft_float
192+
let float_abi = if sess.target.arch == "arm" && sess.opts.cg.soft_float {
193+
FloatAbi::Soft
194194
} else {
195195
// `validate_commandline_args_with_session_available` has already warned about this being
196196
// ignored. Let's make sure LLVM doesn't suddenly start using this flag on more targets.
197-
false
197+
FloatAbi::Default
198198
};
199199

200200
let ffunction_sections =
@@ -290,7 +290,7 @@ pub(crate) fn target_machine_factory(
290290
code_model,
291291
reloc_model,
292292
opt_level,
293-
use_softfp,
293+
float_abi,
294294
ffunction_sections,
295295
fdata_sections,
296296
funique_section_names,

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ pub struct SanitizerOptions {
526526
pub sanitize_kernel_address_recover: bool,
527527
}
528528

529-
/// LLVMRelocMode
529+
/// LLVMRustRelocModel
530530
#[derive(Copy, Clone, PartialEq)]
531531
#[repr(C)]
532532
pub enum RelocModel {
@@ -538,6 +538,15 @@ pub enum RelocModel {
538538
ROPI_RWPI,
539539
}
540540

541+
/// LLVMRustFloatABI
542+
#[derive(Copy, Clone, PartialEq)]
543+
#[repr(C)]
544+
pub enum FloatAbi {
545+
Default,
546+
Soft,
547+
Hard,
548+
}
549+
541550
/// LLVMRustCodeModel
542551
#[derive(Copy, Clone)]
543552
#[repr(C)]
@@ -2192,7 +2201,7 @@ unsafe extern "C" {
21922201
Model: CodeModel,
21932202
Reloc: RelocModel,
21942203
Level: CodeGenOptLevel,
2195-
UseSoftFP: bool,
2204+
FloatABIType: FloatAbi,
21962205
FunctionSections: bool,
21972206
DataSections: bool,
21982207
UniqueSectionNames: bool,

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,24 @@ static Reloc::Model fromRust(LLVMRustRelocModel RustReloc) {
308308
report_fatal_error("Bad RelocModel.");
309309
}
310310

311+
enum class LLVMRustFloatABI {
312+
Default,
313+
Soft,
314+
Hard,
315+
};
316+
317+
static FloatABI::ABIType fromRust(LLVMRustFloatABI RustFloatAbi) {
318+
switch (RustFloatAbi) {
319+
case LLVMRustFloatABI::Default:
320+
return FloatABI::Default;
321+
case LLVMRustFloatABI::Soft:
322+
return FloatABI::Soft;
323+
case LLVMRustFloatABI::Hard:
324+
return FloatABI::Hard;
325+
}
326+
report_fatal_error("Bad FloatABI.");
327+
}
328+
311329
/// getLongestEntryLength - Return the length of the longest entry in the table.
312330
template <typename KV> static size_t getLongestEntryLength(ArrayRef<KV> Table) {
313331
size_t MaxLen = 0;
@@ -358,7 +376,7 @@ extern "C" const char *LLVMRustGetHostCPUName(size_t *OutLen) {
358376
extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
359377
const char *TripleStr, const char *CPU, const char *Feature,
360378
const char *ABIStr, LLVMRustCodeModel RustCM, LLVMRustRelocModel RustReloc,
361-
LLVMRustCodeGenOptLevel RustOptLevel, bool UseSoftFloat,
379+
LLVMRustCodeGenOptLevel RustOptLevel, LLVMRustFloatABI RustFloatABIType,
362380
bool FunctionSections, bool DataSections, bool UniqueSectionNames,
363381
bool TrapUnreachable, bool Singlethread, bool VerboseAsm,
364382
bool EmitStackSizeSection, bool RelaxELFRelocations, bool UseInitArray,
@@ -369,6 +387,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
369387
auto OptLevel = fromRust(RustOptLevel);
370388
auto RM = fromRust(RustReloc);
371389
auto CM = fromRust(RustCM);
390+
auto FloatABIType = fromRust(RustFloatABIType);
372391

373392
std::string Error;
374393
auto Trip = Triple(Triple::normalize(TripleStr));
@@ -381,10 +400,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
381400

382401
TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(Trip);
383402

384-
Options.FloatABIType = FloatABI::Default;
385-
if (UseSoftFloat) {
386-
Options.FloatABIType = FloatABI::Soft;
387-
}
403+
Options.FloatABIType = FloatABIType;
388404
Options.DataSections = DataSections;
389405
Options.FunctionSections = FunctionSections;
390406
Options.UniqueSectionNames = UniqueSectionNames;

0 commit comments

Comments
 (0)