mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-05 09:31:03 +03:00
Predefine version D_HardFloat instead of D_SoftFloat for -float-abi=softfp (#2678)
Matching the D_HardFloat semantics: 'the target hardware has a floating point unit'.
This commit is contained in:
parent
7464d8449f
commit
0cd14bf80e
5 changed files with 59 additions and 21 deletions
|
@ -618,21 +618,22 @@ void fixupUClibcEnv()
|
||||||
/// Also defines D_HardFloat or D_SoftFloat depending if FPU should be used
|
/// Also defines D_HardFloat or D_SoftFloat depending if FPU should be used
|
||||||
void registerPredefinedFloatABI(const char *soft, const char *hard,
|
void registerPredefinedFloatABI(const char *soft, const char *hard,
|
||||||
const char *softfp = nullptr) {
|
const char *softfp = nullptr) {
|
||||||
// Use target floating point unit instead of s/w float routines
|
switch (floatABI) {
|
||||||
// FIXME: This is a semantic change!
|
case FloatABI::Soft:
|
||||||
bool useFPU = gTargetMachine->Options.FloatABIType == llvm::FloatABI::Hard;
|
VersionCondition::addPredefinedGlobalIdent(soft);
|
||||||
VersionCondition::addPredefinedGlobalIdent(useFPU ? "D_HardFloat"
|
break;
|
||||||
: "D_SoftFloat");
|
case FloatABI::SoftFP:
|
||||||
|
VersionCondition::addPredefinedGlobalIdent(softfp ? softfp : soft);
|
||||||
if (gTargetMachine->Options.FloatABIType == llvm::FloatABI::Soft) {
|
break;
|
||||||
VersionCondition::addPredefinedGlobalIdent(useFPU && softfp ? softfp
|
case FloatABI::Hard:
|
||||||
: soft);
|
|
||||||
} else if (gTargetMachine->Options.FloatABIType == llvm::FloatABI::Hard) {
|
|
||||||
assert(useFPU && "Should be using the FPU if using float-abi=hard");
|
|
||||||
VersionCondition::addPredefinedGlobalIdent(hard);
|
VersionCondition::addPredefinedGlobalIdent(hard);
|
||||||
} else {
|
break;
|
||||||
assert(0 && "FloatABIType neither Soft or Hard");
|
default:
|
||||||
|
llvm_unreachable("Unknown float ABI");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VersionCondition::addPredefinedGlobalIdent(
|
||||||
|
floatABI == FloatABI::Soft ? "D_SoftFloat" : "D_HardFloat");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Registers the predefined versions specific to the current target triple
|
/// Registers the predefined versions specific to the current target triple
|
||||||
|
@ -997,6 +998,7 @@ int cppmain(int argc, char **argv) {
|
||||||
// check and fix environment for uClibc
|
// check and fix environment for uClibc
|
||||||
fixupUClibcEnv();
|
fixupUClibcEnv();
|
||||||
|
|
||||||
|
// create target machine and finalize floatABI
|
||||||
gTargetMachine = createTargetMachine(
|
gTargetMachine = createTargetMachine(
|
||||||
mTargetTriple, arch, opts::getCPUStr(), opts::getFeaturesStr(), bitness,
|
mTargetTriple, arch, opts::getCPUStr(), opts::getFeaturesStr(), bitness,
|
||||||
floatABI, relocModel, opts::getCodeModel(), codeGenOptLevel(),
|
floatABI, relocModel, opts::getCodeModel(), codeGenOptLevel(),
|
||||||
|
|
|
@ -345,7 +345,7 @@ llvm::TargetMachine *
|
||||||
createTargetMachine(const std::string targetTriple, const std::string arch,
|
createTargetMachine(const std::string targetTriple, const std::string arch,
|
||||||
std::string cpu, const std::string featuresString,
|
std::string cpu, const std::string featuresString,
|
||||||
const ExplicitBitness::Type bitness,
|
const ExplicitBitness::Type bitness,
|
||||||
FloatABI::Type floatABI,
|
FloatABI::Type &floatABI,
|
||||||
#if LDC_LLVM_VER >= 309
|
#if LDC_LLVM_VER >= 309
|
||||||
llvm::Optional<llvm::Reloc::Model> relocModel,
|
llvm::Optional<llvm::Reloc::Model> relocModel,
|
||||||
#else
|
#else
|
||||||
|
@ -468,20 +468,19 @@ createTargetMachine(const std::string targetTriple, const std::string arch,
|
||||||
targetOptions.MCOptions.DwarfVersion = 3;
|
targetOptions.MCOptions.DwarfVersion = 3;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto ldcFloatABI = floatABI;
|
if (floatABI == FloatABI::Default) {
|
||||||
if (ldcFloatABI == FloatABI::Default) {
|
|
||||||
switch (triple.getArch()) {
|
switch (triple.getArch()) {
|
||||||
default: // X86, ...
|
default: // X86, ...
|
||||||
ldcFloatABI = FloatABI::Hard;
|
floatABI = FloatABI::Hard;
|
||||||
break;
|
break;
|
||||||
case llvm::Triple::arm:
|
case llvm::Triple::arm:
|
||||||
case llvm::Triple::thumb:
|
case llvm::Triple::thumb:
|
||||||
ldcFloatABI = getARMFloatABI(triple, getLLVMArchSuffixForARM(cpu));
|
floatABI = getARMFloatABI(triple, getLLVMArchSuffixForARM(cpu));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ldcFloatABI) {
|
switch (floatABI) {
|
||||||
default:
|
default:
|
||||||
llvm_unreachable("Floating point ABI type unknown.");
|
llvm_unreachable("Floating point ABI type unknown.");
|
||||||
case FloatABI::Soft:
|
case FloatABI::Soft:
|
||||||
|
|
|
@ -50,13 +50,14 @@ ComputeBackend::Type getComputeTargetType(llvm::Module*);
|
||||||
/**
|
/**
|
||||||
* Creates an LLVM TargetMachine suitable for the given (usually command-line)
|
* Creates an LLVM TargetMachine suitable for the given (usually command-line)
|
||||||
* parameters and the host platform defaults.
|
* parameters and the host platform defaults.
|
||||||
|
* Also finalizes floatABI if it's set to FloatABI::Default.
|
||||||
*
|
*
|
||||||
* Does not depend on any global state.
|
* Does not depend on any global state.
|
||||||
*/
|
*/
|
||||||
llvm::TargetMachine *
|
llvm::TargetMachine *
|
||||||
createTargetMachine(std::string targetTriple, std::string arch, std::string cpu,
|
createTargetMachine(std::string targetTriple, std::string arch, std::string cpu,
|
||||||
std::string featuresString, ExplicitBitness::Type bitness,
|
std::string featuresString, ExplicitBitness::Type bitness,
|
||||||
FloatABI::Type floatABI,
|
FloatABI::Type &floatABI,
|
||||||
#if LDC_LLVM_VER >= 309
|
#if LDC_LLVM_VER >= 309
|
||||||
llvm::Optional<llvm::Reloc::Model> relocModel,
|
llvm::Optional<llvm::Reloc::Model> relocModel,
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -35,10 +35,11 @@ public:
|
||||||
const bool is64 = global.params.is64bit;
|
const bool is64 = global.params.is64bit;
|
||||||
auto tripleString = is64 ? "nvptx64-nvidia-cuda" : "nvptx-nvidia-cuda";
|
auto tripleString = is64 ? "nvptx64-nvidia-cuda" : "nvptx-nvidia-cuda";
|
||||||
|
|
||||||
|
auto floatABI = ::FloatABI::Hard;
|
||||||
targetMachine = createTargetMachine(
|
targetMachine = createTargetMachine(
|
||||||
tripleString, is64 ? "nvptx64" : "nvptx",
|
tripleString, is64 ? "nvptx64" : "nvptx",
|
||||||
"sm_" + ldc::to_string(tversion / 10), {},
|
"sm_" + ldc::to_string(tversion / 10), {},
|
||||||
is64 ? ExplicitBitness::M64 : ExplicitBitness::M32, ::FloatABI::Hard,
|
is64 ? ExplicitBitness::M64 : ExplicitBitness::M32, floatABI,
|
||||||
llvm::Reloc::Static, llvm::CodeModel::Medium, codeGenOptLevel(), false);
|
llvm::Reloc::Static, llvm::CodeModel::Medium, codeGenOptLevel(), false);
|
||||||
|
|
||||||
_ir = new IRState("dcomputeTargetCUDA", ctx);
|
_ir = new IRState("dcomputeTargetCUDA", ctx);
|
||||||
|
|
35
tests/driver/float_abi.d
Normal file
35
tests/driver/float_abi.d
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
// REQUIRES: target_ARM
|
||||||
|
|
||||||
|
// RUN: %ldc -c -o- %s -mtriple=armv7-linux-android -float-abi=soft -d-version=SOFT
|
||||||
|
// RUN: %ldc -c -o- %s -mtriple=armv7-linux-android -float-abi=softfp -d-version=SOFTFP
|
||||||
|
// RUN: %ldc -c -o- %s -mtriple=armv7-linux-gnueabihf -d-version=HARD
|
||||||
|
|
||||||
|
version (SOFT)
|
||||||
|
{
|
||||||
|
version (ARM_SoftFloat) {} else static assert(0);
|
||||||
|
version (ARM_SoftFP) static assert(0);
|
||||||
|
version (ARM_HardFloat) static assert(0);
|
||||||
|
|
||||||
|
version (D_SoftFloat) {} else static assert(0);
|
||||||
|
version (D_HardFloat) static assert(0);
|
||||||
|
}
|
||||||
|
else version (SOFTFP)
|
||||||
|
{
|
||||||
|
version (ARM_SoftFloat) static assert(0);
|
||||||
|
version (ARM_SoftFP) {} else static assert(0);
|
||||||
|
version (ARM_HardFloat) static assert(0);
|
||||||
|
|
||||||
|
version (D_SoftFloat) static assert(0);
|
||||||
|
version (D_HardFloat) {} else static assert(0);
|
||||||
|
}
|
||||||
|
else version (HARD)
|
||||||
|
{
|
||||||
|
version (ARM_SoftFloat) static assert(0);
|
||||||
|
version (ARM_SoftFP) static assert(0);
|
||||||
|
version (ARM_HardFloat) {} else static assert(0);
|
||||||
|
|
||||||
|
version (D_SoftFloat) static assert(0);
|
||||||
|
version (D_HardFloat) {} else static assert(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
static assert(0);
|
Loading…
Add table
Add a link
Reference in a new issue