Skip to content

Commit 7c0c32e

Browse files
committed
Move changes away from f128 libcalls to an adjust function
Move to a module flag Add new musl variants for f128 availability cleanup
1 parent 655f5c8 commit 7c0c32e

File tree

13 files changed

+217
-140
lines changed

13 files changed

+217
-140
lines changed

clang/lib/Basic/Targets.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
124124
return std::make_unique<XCoreTargetInfo>(Triple, Opts);
125125

126126
case llvm::Triple::hexagon:
127-
if (os == llvm::Triple::Linux &&
128-
Triple.getEnvironment() == llvm::Triple::Musl)
127+
if (os == llvm::Triple::Linux && Triple.isMusl())
129128
return std::make_unique<LinuxTargetInfo<HexagonTargetInfo>>(Triple, Opts);
130129
return std::make_unique<HexagonTargetInfo>(Triple, Opts);
131130

clang/lib/Driver/Driver.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
797797
Target.getEnvironment() == llvm::Triple::GNUT64 ||
798798
Target.getEnvironment() == llvm::Triple::GNUABI64)
799799
Target.setEnvironment(llvm::Triple::GNUABIN32);
800-
else if (Target.getEnvironment() == llvm::Triple::Musl ||
801-
Target.getEnvironment() == llvm::Triple::MuslABI64)
800+
else if (Target.isMusl())
802801
Target.setEnvironment(llvm::Triple::MuslABIN32);
803802
} else if (ABIName == "64") {
804803
Target = Target.get64BitArchVariant();
@@ -809,6 +808,9 @@ static llvm::Triple computeTargetTriple(const Driver &D,
809808
else if (Target.getEnvironment() == llvm::Triple::Musl ||
810809
Target.getEnvironment() == llvm::Triple::MuslABIN32)
811810
Target.setEnvironment(llvm::Triple::MuslABI64);
811+
else if (Target.getEnvironment() == llvm::Triple::MuslF128 ||
812+
Target.getEnvironment() == llvm::Triple::MuslABIN3F128)
813+
Target.setEnvironment(llvm::Triple::MuslABI64F128);
812814
}
813815
}
814816
}

clang/lib/Driver/ToolChains/Arch/LoongArch.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ StringRef loongarch::getLoongArchABI(const Driver &D, const ArgList &Args,
105105
switch (Triple.getEnvironment()) {
106106
case llvm::Triple::GNUSF:
107107
case llvm::Triple::MuslSF:
108+
case llvm::Triple::MuslSFF128:
108109
return IsLA32 ? "ilp32s" : "lp64s";
109110
case llvm::Triple::GNUF32:
110111
case llvm::Triple::MuslF32:
112+
case llvm::Triple::MuslF32F128:
111113
return IsLA32 ? "ilp32f" : "lp64f";
112114
case llvm::Triple::GNUF64:
113115
// This was originally permitted (and indeed the canonical way) to

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,18 @@ std::string Linux::getMultiarchTriple(const Driver &D,
110110
return TargetTriple.str();
111111
case llvm::Triple::GNUSF:
112112
case llvm::Triple::MuslSF:
113+
case llvm::Triple::MuslSFF128:
113114
FPFlavor = "sf";
114115
break;
115116
case llvm::Triple::GNUF32:
116117
case llvm::Triple::MuslF32:
118+
case llvm::Triple::MuslF32F128:
117119
FPFlavor = "f32";
118120
break;
119121
case llvm::Triple::GNU:
120122
case llvm::Triple::GNUF64:
121123
case llvm::Triple::Musl:
124+
case llvm::Triple::MuslF128:
122125
// This was going to be "f64" in an earlier Toolchain Conventions
123126
// revision, but starting from Feb 2023 the F64 ABI variants are
124127
// unmarked in their canonical forms.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 -triple x86_64-linux-android -emit-llvm -o - %s \
2+
// RUN: | FileCheck %s --check-prefix=A64
3+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s \
4+
// RUN: | FileCheck %s --check-prefix=G64
5+
// RUN: %clang_cc1 -triple powerpc64-linux-gnu -emit-llvm -o - %s \
6+
// RUN: | FileCheck %s --check-prefix=P64
7+
// RUN: %clang_cc1 -triple i686-linux-android -emit-llvm -o - %s \
8+
// RUN: | FileCheck %s --check-prefix=A32
9+
// RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm -o - %s \
10+
// RUN: | FileCheck %s --check-prefix=G32
11+
// RUN: %clang_cc1 -triple powerpc-linux-gnu -emit-llvm -o - %s \
12+
// RUN: | FileCheck %s --check-prefix=P32
13+
// RUN: %clang_cc1 -triple x86_64-nacl -emit-llvm -o - %s \
14+
// RUN: | FileCheck %s --check-prefix=N64
15+

llvm/include/llvm/IR/RuntimeLibcalls.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ HANDLE_LIBCALL(CTPOP_I32, "__popcountsi2")
8989
HANDLE_LIBCALL(CTPOP_I64, "__popcountdi2")
9090
HANDLE_LIBCALL(CTPOP_I128, "__popcountti2")
9191

92-
// Floating-point
92+
// Floating-point. Note that new fp128 math routines should also be added to
93+
// setF128LibcallFormat in RuntimeLibcalls.cpp.
9394
HANDLE_LIBCALL(ADD_F32, "__addsf3")
9495
HANDLE_LIBCALL(ADD_F64, "__adddf3")
9596
HANDLE_LIBCALL(ADD_F80, "__addxf3")

llvm/include/llvm/IR/RuntimeLibcalls.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,25 @@
1414
#ifndef LLVM_IR_RUNTIME_LIBCALLS_H
1515
#define LLVM_IR_RUNTIME_LIBCALLS_H
1616

17+
#include "llvm/ADT/APFloat.h"
1718
#include "llvm/ADT/ArrayRef.h"
1819
#include "llvm/IR/CallingConv.h"
1920
#include "llvm/Support/AtomicOrdering.h"
21+
#include "llvm/Target/TargetMachine.h"
2022
#include "llvm/TargetParser/Triple.h"
2123

2224
namespace llvm {
25+
26+
/// Library names to use for `fp128` libcalls.
27+
// If needed, this could be extended with a `Quadmath` option for `q`-suffixed
28+
// `libquadmath` symbols.
29+
enum class F128LibcallFormat {
30+
/// C23 `*f128` lowering, e.g. `sinf128`
31+
Default = 0,
32+
/// `long double` *l` lowering, e.g. `sinl`.
33+
LongDouble = 1,
34+
};
35+
2336
namespace RTLIB {
2437

2538
/// RTLIB::Libcall enum - This enum defines all of the runtime library calls
@@ -38,9 +51,9 @@ enum Libcall {
3851

3952
/// A simple container for information about the supported runtime calls.
4053
struct RuntimeLibcallsInfo {
41-
explicit RuntimeLibcallsInfo(const Triple &TT) {
42-
initLibcalls(TT);
43-
}
54+
/// Default libcalls for the triple. Note that `fixupLibcalls` should also be
55+
/// called in order to apply machine-specific and configurable behavior.
56+
explicit RuntimeLibcallsInfo(const Triple &TT) { initLibcalls(TT); }
4457

4558
/// Rename the default libcall routine name for the specified libcall.
4659
void setLibcallName(RTLIB::Libcall Call, const char *Name) {
@@ -72,6 +85,14 @@ struct RuntimeLibcallsInfo {
7285
LibcallRoutineNames + RTLIB::UNKNOWN_LIBCALL);
7386
}
7487

88+
/// Set a specific lowering convention for `fp128` math libcalls.
89+
///
90+
/// By default, `fp128` math functions get lowered to the C23 `sinf128`-
91+
/// style symbols. This allows overriding with `sinl`-style symbols on
92+
/// platforms where `long double` is known to be identical to _Float128.
93+
/// versions, e.g. `sinf128`.
94+
void setF128LibcallFormat(F128LibcallFormat Format);
95+
7596
private:
7697
/// Stores the name each libcall.
7798
const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL + 1];

llvm/include/llvm/TargetParser/Triple.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,21 @@ class Triple {
262262
EABIHF,
263263
Android,
264264
Musl,
265-
MuslABIN32,
266-
MuslABI64,
267-
MuslEABI,
268-
MuslEABIHF,
269-
MuslF32,
270-
MuslSF,
271-
MuslX32,
265+
MuslABIN32, // MIPS N32 ABI
266+
MuslABI64, // MIPS N64 ABI
267+
MuslEABI, // Arm32 EABI
268+
MuslEABIHF, // Arm32 EABI + HF
269+
MuslF32, // LoongArch ILP32F/LP64F
270+
MuslSF, // LoongArch ILP32S/LP64S
271+
MuslX32, // Musl using 32-bit ABI on x86_64
272+
// Musl with `*f128` math symbols available (e.g. `sqrtf128` rather than
273+
// only `sqrtl`). 32-bit musl variants are excluded sin e `*f128` symbols
274+
// are required to use `fp128` at all.
275+
MuslF128,
276+
MuslABI64F128,
277+
MuslF32F128,
278+
MuslSFF128,
279+
272280
LLVM,
273281

274282
MSVC,
@@ -827,6 +835,10 @@ class Triple {
827835
getEnvironment() == Triple::MuslF32 ||
828836
getEnvironment() == Triple::MuslSF ||
829837
getEnvironment() == Triple::MuslX32 ||
838+
getEnvironment() == Triple::MuslF128 ||
839+
getEnvironment() == Triple::MuslABI64F128 ||
840+
getEnvironment() == Triple::MuslF32F128 ||
841+
getEnvironment() == Triple::MuslSFF128 ||
830842
getEnvironment() == Triple::OpenHOS || isOSLiteOS();
831843
}
832844

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/IR/RuntimeLibcalls.h"
10+
#include "llvm/Target/TargetMachine.h"
1011

1112
using namespace llvm;
1213
using namespace RTLIB;
@@ -25,55 +26,6 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
2526
for (int LC = 0; LC < RTLIB::UNKNOWN_LIBCALL; ++LC)
2627
setLibcallCallingConv((RTLIB::Libcall)LC, CallingConv::C);
2728

28-
// The long double version of library functions is more common than the
29-
// f128-specific version. Use these if that is the long double type on the
30-
// platform, or if the frontend specifies.
31-
if (TT.isLongDoubleF128("")) {
32-
setLibcallName(RTLIB::ACOS_F128, "acosl");
33-
setLibcallName(RTLIB::ASIN_F128, "asinl");
34-
setLibcallName(RTLIB::ATAN2_F128,"atan2l");
35-
setLibcallName(RTLIB::ATAN_F128,"atanl");
36-
setLibcallName(RTLIB::CBRT_F128, "cbrtl");
37-
setLibcallName(RTLIB::CEIL_F128, "ceill");
38-
setLibcallName(RTLIB::COPYSIGN_F128, "copysignl");
39-
setLibcallName(RTLIB::COSH_F128, "coshl");
40-
setLibcallName(RTLIB::COS_F128, "cosl");
41-
setLibcallName(RTLIB::EXP10_F128, "exp10l");
42-
setLibcallName(RTLIB::EXP2_F128, "exp2l");
43-
setLibcallName(RTLIB::EXP_F128, "expl");
44-
setLibcallName(RTLIB::FLOOR_F128, "floorl");
45-
setLibcallName(RTLIB::FMAXIMUMNUM_F128, "fmaximum_numl");
46-
setLibcallName(RTLIB::FMAXIMUM_F128, "fmaximuml");
47-
setLibcallName(RTLIB::FMAX_F128, "fmaxl");
48-
setLibcallName(RTLIB::FMA_F128, "fmal");
49-
setLibcallName(RTLIB::FMINIMUMNUM_F128, "fminimum_numl");
50-
setLibcallName(RTLIB::FMINIMUM_F128, "fminimuml");
51-
setLibcallName(RTLIB::FMIN_F128, "fminl");
52-
setLibcallName(RTLIB::FREXP_F128, "frexpl");
53-
setLibcallName(RTLIB::LDEXP_F128, "ldexpl");
54-
setLibcallName(RTLIB::LLRINT_F128, "llrintl");
55-
setLibcallName(RTLIB::LLROUND_F128, "llroundl");
56-
setLibcallName(RTLIB::LOG10_F128, "log10l");
57-
setLibcallName(RTLIB::LOG2_F128, "log2l");
58-
setLibcallName(RTLIB::LOG_F128, "logl");
59-
setLibcallName(RTLIB::LRINT_F128, "lrintl");
60-
setLibcallName(RTLIB::LROUND_F128, "lroundl");
61-
setLibcallName(RTLIB::MODF_F128, "modfl");
62-
setLibcallName(RTLIB::NEARBYINT_F128, "nearbyintl");
63-
setLibcallName(RTLIB::POW_F128, "powl");
64-
setLibcallName(RTLIB::REM_F128, "fmodl");
65-
setLibcallName(RTLIB::RINT_F128, "rintl");
66-
setLibcallName(RTLIB::ROUNDEVEN_F128, "roundevenl");
67-
setLibcallName(RTLIB::ROUND_F128, "roundl");
68-
setLibcallName(RTLIB::SINCOSPI_F128, "sincospil");
69-
setLibcallName(RTLIB::SINH_F128, "sinhl");
70-
setLibcallName(RTLIB::SIN_F128, "sinl");
71-
setLibcallName(RTLIB::SQRT_F128, "sqrtl");
72-
setLibcallName(RTLIB::TANH_F128,"tanhl");
73-
setLibcallName(RTLIB::TAN_F128,"tanl");
74-
setLibcallName(RTLIB::TRUNC_F128, "truncl");
75-
}
76-
7729
// For IEEE quad-precision libcall names, PPC uses "kf" instead of "tf".
7830
if (TT.isPPC()) {
7931
setLibcallName(RTLIB::ADD_F128, "__addkf3");
@@ -254,3 +206,51 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
254206
setLibcallName(RTLIB::MULO_I128, nullptr);
255207
}
256208
}
209+
210+
void RuntimeLibcallsInfo::setF128LibcallFormat(F128LibcallFormat Format) {
211+
bool UseLD = Format == F128LibcallFormat::LongDouble;
212+
213+
setLibcallName(RTLIB::ACOS_F128, UseLD ? "acosl" : "acosf128");
214+
setLibcallName(RTLIB::ASIN_F128, UseLD ? "asinl" : "asinf128");
215+
setLibcallName(RTLIB::ATAN2_F128, UseLD ? "atan2l" : "atan2f128");
216+
setLibcallName(RTLIB::ATAN_F128, UseLD ? "atanl" : "atanf128");
217+
setLibcallName(RTLIB::CBRT_F128, UseLD ? "cbrtl" : "cbrtf128");
218+
setLibcallName(RTLIB::CEIL_F128, UseLD ? "ceill" : "ceilf128");
219+
setLibcallName(RTLIB::COPYSIGN_F128, UseLD ? "copysignl" : "copysignf128");
220+
setLibcallName(RTLIB::COSH_F128, UseLD ? "coshl" : "coshf128");
221+
setLibcallName(RTLIB::COS_F128, UseLD ? "cosl" : "cosf128");
222+
setLibcallName(RTLIB::EXP10_F128, UseLD ? "exp10l" : "exp10f128");
223+
setLibcallName(RTLIB::EXP2_F128, UseLD ? "exp2l" : "exp2f128");
224+
setLibcallName(RTLIB::EXP_F128, UseLD ? "expl" : "expf128");
225+
setLibcallName(RTLIB::FLOOR_F128, UseLD ? "floorl" : "floorf128");
226+
setLibcallName(RTLIB::FMAXIMUMNUM_F128, UseLD ? "fmaximum_numl" : "fmaximum_numf128");
227+
setLibcallName(RTLIB::FMAXIMUM_F128, UseLD ? "fmaximuml" : "fmaximumf128");
228+
setLibcallName(RTLIB::FMAX_F128, UseLD ? "fmaxl" : "fmaxf128");
229+
setLibcallName(RTLIB::FMA_F128, UseLD ? "fmal" : "fmaf128");
230+
setLibcallName(RTLIB::FMINIMUMNUM_F128, UseLD ? "fminimum_numl" : "fminimum_numf128");
231+
setLibcallName(RTLIB::FMINIMUM_F128, UseLD ? "fminimuml" : "fminimumf128");
232+
setLibcallName(RTLIB::FMIN_F128, UseLD ? "fminl" : "fminf128");
233+
setLibcallName(RTLIB::FREXP_F128, UseLD ? "frexpl" : "frexpf128");
234+
setLibcallName(RTLIB::LDEXP_F128, UseLD ? "ldexpl" : "ldexpf128");
235+
setLibcallName(RTLIB::LLRINT_F128, UseLD ? "llrintl" : "llrintf128");
236+
setLibcallName(RTLIB::LLROUND_F128, UseLD ? "llroundl" : "llroundf128");
237+
setLibcallName(RTLIB::LOG10_F128, UseLD ? "log10l" : "log10f128");
238+
setLibcallName(RTLIB::LOG2_F128, UseLD ? "log2l" : "log2f128");
239+
setLibcallName(RTLIB::LOG_F128, UseLD ? "logl" : "logf128");
240+
setLibcallName(RTLIB::LRINT_F128, UseLD ? "lrintl" : "lrintf128");
241+
setLibcallName(RTLIB::LROUND_F128, UseLD ? "lroundl" : "lroundf128");
242+
setLibcallName(RTLIB::MODF_F128, UseLD ? "modfl" : "modff128");
243+
setLibcallName(RTLIB::NEARBYINT_F128, UseLD ? "nearbyintl" : "nearbyintf128");
244+
setLibcallName(RTLIB::POW_F128, UseLD ? "powl" : "powf128");
245+
setLibcallName(RTLIB::REM_F128, UseLD ? "fmodl" : "fmodf128");
246+
setLibcallName(RTLIB::RINT_F128, UseLD ? "rintl" : "rintf128");
247+
setLibcallName(RTLIB::ROUNDEVEN_F128, UseLD ? "roundevenl" : "roundevenf128");
248+
setLibcallName(RTLIB::ROUND_F128, UseLD ? "roundl" : "roundf128");
249+
setLibcallName(RTLIB::SINCOSPI_F128, UseLD ? "sincospil" : "sincospif128");
250+
setLibcallName(RTLIB::SINH_F128, UseLD ? "sinhl" : "sinhf128");
251+
setLibcallName(RTLIB::SIN_F128, UseLD ? "sinl" : "sinf128");
252+
setLibcallName(RTLIB::SQRT_F128, UseLD ? "sqrtl" : "sqrtf128");
253+
setLibcallName(RTLIB::TANH_F128, UseLD ? "tanhl" : "tanhf128");
254+
setLibcallName(RTLIB::TAN_F128, UseLD ? "tanl" : "tanf128");
255+
setLibcallName(RTLIB::TRUNC_F128, UseLD ? "truncl" : "truncf128");
256+
}

llvm/lib/Target/Hexagon/HexagonSubtarget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class HexagonSubtarget : public HexagonGenSubtargetInfo {
113113

114114
const Triple &getTargetTriple() const { return TargetTriple; }
115115
bool isEnvironmentMusl() const {
116-
return TargetTriple.getEnvironment() == Triple::Musl;
116+
return TargetTriple.isMusl();
117117
}
118118

119119
/// getInstrItins - Return the instruction itineraries based on subtarget

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ static ABI getTripleABI(const Triple &TT) {
5454
switch (TT.getEnvironment()) {
5555
case llvm::Triple::EnvironmentType::GNUSF:
5656
case llvm::Triple::EnvironmentType::MuslSF:
57+
case llvm::Triple::EnvironmentType::MuslSFF128:
5758
TripleABI = Is64Bit ? ABI_LP64S : ABI_ILP32S;
5859
break;
5960
case llvm::Triple::EnvironmentType::GNUF32:
6061
case llvm::Triple::EnvironmentType::MuslF32:
62+
case llvm::Triple::EnvironmentType::MuslF32F128:
6163
TripleABI = Is64Bit ? ABI_LP64F : ABI_ILP32F;
6264
break;
6365
// Let the fallback case behave like {ILP32,LP64}D.

llvm/lib/TargetParser/Triple.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
361361
case MuslSF:
362362
return "muslsf";
363363
case MuslX32: return "muslx32";
364+
case MuslF128: return "musl_f128";
365+
case MuslABI64F128: return "muslabi64_f128";
366+
case MuslF32F128: return "muslf32_f128";
367+
case MuslSFF128: return "muslsf_f128";
364368
case Simulator: return "simulator";
365369
case Pixel: return "pixel";
366370
case Vertex: return "vertex";
@@ -733,6 +737,10 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
733737
.StartsWith("gnut64", Triple::GNUT64)
734738
.StartsWith("gnu", Triple::GNU)
735739
.StartsWith("android", Triple::Android)
740+
.StartsWith("muslabi64_f128", Triple::MuslABI64F128)
741+
.StartsWith("muslf32_f128", Triple::MuslF32F128)
742+
.StartsWith("muslsf_f128", Triple::MuslSFF128)
743+
.StartsWith("musl_f128", Triple::MuslF128)
736744
.StartsWith("muslabin32", Triple::MuslABIN32)
737745
.StartsWith("muslabi64", Triple::MuslABI64)
738746
.StartsWith("musleabihf", Triple::MuslEABIHF)

0 commit comments

Comments
 (0)