Skip to content

Commit 20624cc

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:73e0aa58666f235bef091735a5f189882acc1148 into amd-gfx:e64f6fcf29c6
Local branch amd-gfx e64f6fc Merged main:fee48365b44d161575314c67328fa21104c4537d into amd-gfx:0447d312fac8 Remote branch main 73e0aa5 [CodeGen] Create IFUNCs in the program address space, not hard-coded 0 (llvm#105726)
2 parents e64f6fc + 73e0aa5 commit 20624cc

File tree

28 files changed

+668
-66
lines changed

28 files changed

+668
-66
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4455,12 +4455,13 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
44554455
if (getTarget().supportsIFunc()) {
44564456
llvm::GlobalValue::LinkageTypes Linkage = getMultiversionLinkage(*this, GD);
44574457
auto *IFunc = cast<llvm::GlobalValue>(GetOrCreateMultiVersionResolver(GD));
4458+
unsigned AS = IFunc->getType()->getPointerAddressSpace();
44584459

44594460
// Fix up function declarations that were created for cpu_specific before
44604461
// cpu_dispatch was known
44614462
if (!isa<llvm::GlobalIFunc>(IFunc)) {
4462-
auto *GI = llvm::GlobalIFunc::create(DeclTy, 0, Linkage, "", ResolverFunc,
4463-
&getModule());
4463+
auto *GI = llvm::GlobalIFunc::create(DeclTy, AS, Linkage, "",
4464+
ResolverFunc, &getModule());
44644465
replaceDeclarationWith(IFunc, GI);
44654466
IFunc = GI;
44664467
}
@@ -4469,8 +4470,8 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
44694470
*this, GD, FD, /*OmitMultiVersionMangling=*/true);
44704471
llvm::Constant *AliasFunc = GetGlobalValue(AliasName);
44714472
if (!AliasFunc) {
4472-
auto *GA = llvm::GlobalAlias::create(DeclTy, 0, Linkage, AliasName, IFunc,
4473-
&getModule());
4473+
auto *GA = llvm::GlobalAlias::create(DeclTy, AS, Linkage, AliasName,
4474+
IFunc, &getModule());
44744475
SetCommonAttributes(GD, GA);
44754476
}
44764477
}
@@ -4542,15 +4543,14 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
45424543
// For cpu_specific, don't create an ifunc yet because we don't know if the
45434544
// cpu_dispatch will be emitted in this translation unit.
45444545
if (getTarget().supportsIFunc() && !FD->isCPUSpecificMultiVersion()) {
4545-
llvm::Type *ResolverType = llvm::FunctionType::get(
4546-
llvm::PointerType::get(DeclTy,
4547-
getTypes().getTargetAddressSpace(FD->getType())),
4548-
false);
4546+
unsigned AS = getTypes().getTargetAddressSpace(FD->getType());
4547+
llvm::Type *ResolverType =
4548+
llvm::FunctionType::get(llvm::PointerType::get(DeclTy, AS), false);
45494549
llvm::Constant *Resolver = GetOrCreateLLVMFunction(
45504550
MangledName + ".resolver", ResolverType, GlobalDecl{},
45514551
/*ForVTable=*/false);
45524552
llvm::GlobalIFunc *GIF =
4553-
llvm::GlobalIFunc::create(DeclTy, 0, getMultiversionLinkage(*this, GD),
4553+
llvm::GlobalIFunc::create(DeclTy, AS, getMultiversionLinkage(*this, GD),
45544554
"", Resolver, &getModule());
45554555
GIF->setName(ResolverName);
45564556
SetCommonAttributes(FD, GIF);
@@ -6160,9 +6160,9 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
61606160
GetOrCreateLLVMFunction(IFA->getResolver(), VoidTy, {},
61616161
/*ForVTable=*/false);
61626162
llvm::Type *DeclTy = getTypes().ConvertTypeForMem(D->getType());
6163-
llvm::GlobalIFunc *GIF =
6164-
llvm::GlobalIFunc::create(DeclTy, 0, llvm::Function::ExternalLinkage,
6165-
"", Resolver, &getModule());
6163+
unsigned AS = getTypes().getTargetAddressSpace(D->getType());
6164+
llvm::GlobalIFunc *GIF = llvm::GlobalIFunc::create(
6165+
DeclTy, AS, llvm::Function::ExternalLinkage, "", Resolver, &getModule());
61666166
if (Entry) {
61676167
if (GIF->getResolver() == Entry) {
61686168
Diags.Report(IFA->getLocation(), diag::err_cyclic_alias) << 1;

clang/test/CodeGen/ifunc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// RUN: %clang_cc1 -triple x86_64-apple-macosx -fsanitize=thread -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
1212
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsanitize=address -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
1313
// RUN: %clang_cc1 -triple x86_64-apple-macosx -fsanitize=address -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
14+
// RUN: %clang_cc1 -triple avr-unknown-unknown -emit-llvm -o - %s | FileCheck %s --check-prefix=AVR
1415

1516
/// The ifunc is emitted before its resolver.
1617
int foo(int) __attribute__ ((ifunc("foo_ifunc")));
@@ -55,6 +56,10 @@ extern void hoo(int) __attribute__ ((ifunc("hoo_ifunc")));
5556
// CHECK: @goo = ifunc void (), ptr @goo_ifunc
5657
// CHECK: @hoo = ifunc void (i32), ptr @hoo_ifunc
5758

59+
// AVR: @foo = ifunc i16 (i16), ptr addrspace(1) @foo_ifunc
60+
// AVR: @goo = ifunc void (), ptr addrspace(1) @goo_ifunc
61+
// AVR: @hoo = ifunc void (i16), ptr addrspace(1) @hoo_ifunc
62+
5863
// CHECK: call i32 @foo(i32
5964
// CHECK: call void @goo()
6065

flang/include/flang/Tools/TargetSetup.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "flang/Evaluate/target.h"
1313
#include "llvm/Target/TargetMachine.h"
14+
#include <cfloat>
1415

1516
namespace Fortran::tools {
1617

@@ -21,9 +22,25 @@ namespace Fortran::tools {
2122

2223
const llvm::Triple &targetTriple{targetMachine.getTargetTriple()};
2324
// FIXME: Handle real(3) ?
24-
if (targetTriple.getArch() != llvm::Triple::ArchType::x86_64)
25+
if (targetTriple.getArch() != llvm::Triple::ArchType::x86_64) {
2526
targetCharacteristics.DisableType(
2627
Fortran::common::TypeCategory::Real, /*kind=*/10);
28+
}
29+
30+
// Figure out if we can support F128: see
31+
// flang/runtime/Float128Math/math-entries.h
32+
#ifdef FLANG_RUNTIME_F128_MATH_LIB
33+
// we can use libquadmath wrappers
34+
constexpr bool f128Support = true;
35+
#elif LDBL_MANT_DIG == 113
36+
// we can use libm wrappers
37+
constexpr bool f128Support = true;
38+
#else
39+
constexpr bool f128Support = false;
40+
#endif
41+
42+
if constexpr (!f128Support)
43+
targetCharacteristics.DisableType(Fortran::common::TypeCategory::Real, 16);
2744

2845
targetCharacteristics.set_compilerOptionsString(compilerOptions)
2946
.set_compilerVersionString(compilerVersion);

flang/module/ieee_arithmetic.f90

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,33 @@ end function ieee_round_ne
161161
G(1) G(2) G(4) G(8) G(16)
162162
#define SPECIFICS_L(G) \
163163
G(1) G(2) G(4) G(8)
164+
165+
#if FLANG_SUPPORT_R16
164166
#if __x86_64__
165167
#define SPECIFICS_R(G) \
166168
G(2) G(3) G(4) G(8) G(10) G(16)
167169
#else
168170
#define SPECIFICS_R(G) \
169171
G(2) G(3) G(4) G(8) G(16)
170172
#endif
173+
#else
174+
#if __x86_64__
175+
#define SPECIFICS_R(G) \
176+
G(2) G(3) G(4) G(8) G(10)
177+
#else
178+
#define SPECIFICS_R(G) \
179+
G(2) G(3) G(4) G(8)
180+
#endif
181+
#endif
182+
171183
#define SPECIFICS_II(G) \
172184
G(1,1) G(1,2) G(1,4) G(1,8) G(1,16) \
173185
G(2,1) G(2,2) G(2,4) G(2,8) G(2,16) \
174186
G(4,1) G(4,2) G(4,4) G(4,8) G(4,16) \
175187
G(8,1) G(8,2) G(8,4) G(8,8) G(8,16) \
176188
G(16,1) G(16,2) G(16,4) G(16,8) G(16,16)
189+
190+
#if FLANG_SUPPORT_R16
177191
#if __x86_64__
178192
#define SPECIFICS_RI(G) \
179193
G(2,1) G(2,2) G(2,4) G(2,8) G(2,16) \
@@ -190,7 +204,24 @@ end function ieee_round_ne
190204
G(8,1) G(8,2) G(8,4) G(8,8) G(8,16) \
191205
G(16,1) G(16,2) G(16,4) G(16,8) G(16,16)
192206
#endif
207+
#else
208+
#if __x86_64__
209+
#define SPECIFICS_RI(G) \
210+
G(2,1) G(2,2) G(2,4) G(2,8) \
211+
G(3,1) G(3,2) G(3,4) G(3,8) \
212+
G(4,1) G(4,2) G(4,4) G(4,8) \
213+
G(8,1) G(8,2) G(8,4) G(8,8) \
214+
G(10,1) G(10,2) G(10,4) G(10,8)
215+
#else
216+
#define SPECIFICS_RI(G) \
217+
G(2,1) G(2,2) G(2,4) G(2,8) \
218+
G(3,1) G(3,2) G(3,4) G(3,8) \
219+
G(4,1) G(4,2) G(4,4) G(4,8) \
220+
G(8,1) G(8,2) G(8,4) G(8,8)
221+
#endif
222+
#endif
193223

224+
#if FLANG_SUPPORT_R16
194225
#if __x86_64__
195226
#define SPECIFICS_RR(G) \
196227
G(2,2) G(2,3) G(2,4) G(2,8) G(2,10) G(2,16) \
@@ -207,6 +238,22 @@ end function ieee_round_ne
207238
G(8,2) G(8,3) G(8,4) G(8,8) G(8,16) \
208239
G(16,2) G(16,3) G(16,4) G(16,8) G(16,16)
209240
#endif
241+
#else
242+
#if __x86_64__
243+
#define SPECIFICS_RR(G) \
244+
G(2,2) G(2,3) G(2,4) G(2,8) G(2,10) \
245+
G(3,2) G(3,3) G(3,4) G(3,8) G(3,10) \
246+
G(4,2) G(4,3) G(4,4) G(4,8) G(4,10) \
247+
G(8,2) G(8,3) G(8,4) G(8,8) G(8,10) \
248+
G(10,2) G(10,3) G(10,4) G(10,8) G(10,10)
249+
#else
250+
#define SPECIFICS_RR(G) \
251+
G(2,2) G(2,3) G(2,4) G(2,8) \
252+
G(3,2) G(3,3) G(3,4) G(3,8) \
253+
G(4,2) G(4,3) G(4,4) G(4,8) \
254+
G(8,2) G(8,3) G(8,4) G(8,8)
255+
#endif
256+
#endif
210257

211258
#define IEEE_CLASS_R(XKIND) \
212259
elemental type(ieee_class_type) function ieee_class_a##XKIND(x); \
@@ -462,8 +509,10 @@ end function ieee_real_a##AKIND##_i##KKIND;
462509
interface ieee_real
463510
SPECIFICS_I(IEEE_REAL_I)
464511
SPECIFICS_R(IEEE_REAL_R)
512+
#if FLANG_SUPPORT_R16
465513
SPECIFICS_II(IEEE_REAL_II)
466514
SPECIFICS_RI(IEEE_REAL_RI)
515+
#endif
467516
end interface ieee_real
468517
public :: ieee_real
469518
#undef IEEE_REAL_I

flang/test/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ llvm_canonicalize_cmake_booleans(
1111

1212
set(FLANG_TOOLS_DIR ${FLANG_BINARY_DIR}/bin)
1313

14+
# Check if 128-bit float computations can be done via long double
15+
check_cxx_source_compiles(
16+
"#include <cfloat>
17+
#if LDBL_MANT_DIG != 113
18+
#error LDBL_MANT_DIG != 113
19+
#endif
20+
int main() { return 0; }
21+
"
22+
HAVE_LDBL_MANT_DIG_113)
23+
1424
# FIXME In out-of-tree builds, "SHLIBDIR" is undefined and passing it to
1525
# `configure_lit_site_cfg` leads to a configuration error. This is currently
1626
# only required by plugins/examples, which are not supported in out-of-tree

flang/test/Evaluate/fold-out_of_range.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
! RUN: %python %S/test_folding.py %s %flang_fc1 -pedantic -triple x86_64-unknown-linux-gnu
22
! UNSUPPORTED: system-windows
33
! REQUIRES: target=x86_64{{.*}}
4+
! REQUIRES: flang-supports-f128-math
45
! Tests folding of OUT_OF_RANGE().
56
module m
67
integer(1), parameter :: i1v(*) = [ -huge(1_1) - 1_1, huge(1_1) ]

flang/test/Evaluate/folding07.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
! REQUIRES: flang-supports-f128-math
12
! RUN: %python %S/test_folding.py %s %flang_fc1
23
! Test numeric model inquiry intrinsics
34

flang/test/Lower/Intrinsics/ieee_class_queries.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
! REQUIRES: flang-supports-f128-math
12
! RUN: bbc -emit-fir -o - %s | FileCheck %s
23

34
! CHECK-LABEL: func @_QQmain

flang/test/Lower/Intrinsics/ieee_unordered.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
! REQUIRES: flang-supports-f128-math
12
! RUN: bbc -emit-fir -hlfir=false -o - %s | FileCheck %s
23

34
! CHECK-LABEL: func @_QQmain

flang/test/Lower/common-block.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
! REQUIRES: flang-supports-f128-math
12
! RUN: bbc %s -o - | tco | FileCheck %s
23
! RUN: %flang -emit-llvm -S -mmlir -disable-external-name-interop %s -o - | FileCheck %s
34

@@ -78,4 +79,3 @@ subroutine s7()
7879
real(16) r16
7980
common /co1/ r16
8081
end subroutine
81-

flang/test/Semantics/kinds03.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
! REQUIRES: flang-supports-f128-math
12
! RUN: %python %S/test_symbols.py %s %flang_fc1
23
!DEF: /MainProgram1/ipdt DerivedType
34
!DEF: /MainProgram1/ipdt/k TypeParam INTEGER(4)

flang/test/Semantics/modfile26.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
! REQUIRES: flang-supports-f128-math
12
! RUN: %python %S/test_modfile.py %s %flang_fc1
23
! Intrinsics SELECTED_INT_KIND, SELECTED_REAL_KIND, PRECISION, RANGE,
34
! RADIX, DIGITS

flang/test/Semantics/realkinds-aarch64-01.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
! REQUIRES: aarch64-registered-target
2+
! REQUIRES: flang-supports-f128-math
23
! RUN: %python %S/test_modfile.py %s %flang_fc1 -triple aarch64-unknown-linux-gnu
34

45
module m1

flang/test/lit.cfg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,9 @@
216216
# Add features and substitutions to test F128 math support.
217217
# %f128-lib substitution may be used to generate check prefixes
218218
# for LIT tests checking for F128 library support.
219-
if config.flang_runtime_f128_math_lib:
219+
if config.flang_runtime_f128_math_lib or config.have_ldbl_mant_dig_113:
220220
config.available_features.add("flang-supports-f128-math")
221+
if config.flang_runtime_f128_math_lib:
221222
config.available_features.add(
222223
"flang-f128-math-lib-" + config.flang_runtime_f128_math_lib
223224
)

flang/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ if "openmp" in "@LLVM_ENABLE_RUNTIMES@".lower().split(";"):
3131
else:
3232
config.openmp_module_dir = None
3333
config.flang_runtime_f128_math_lib = "@FLANG_RUNTIME_F128_MATH_LIB@"
34+
config.have_ldbl_mant_dig_113 = "@HAVE_LDBL_MANT_DIG_113@"
3435

3536
import lit.llvm
3637
lit.llvm.initialize(lit_config, config)

flang/tools/f18/CMakeLists.txt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ set(MODULES_WITHOUT_IMPLEMENTATION
3131

3232
set(MODULES ${MODULES_WITH_IMPLEMENTATION} ${MODULES_WITHOUT_IMPLEMENTATION})
3333

34+
# Check if 128-bit float computations can be done via long double.
35+
check_cxx_source_compiles(
36+
"#include <cfloat>
37+
#if LDBL_MANT_DIG != 113
38+
#error LDBL_MANT_DIG != 113
39+
#endif
40+
int main() { return 0; }
41+
"
42+
HAVE_LDBL_MANT_DIG_113)
43+
44+
# Figure out whether we can support REAL(KIND=16)
45+
if (FLANG_RUNTIME_F128_MATH_LIB)
46+
set(FLANG_SUPPORT_R16 "1")
47+
elseif (HAVE_LDBL_MANT_DIG_113)
48+
set(FLANG_SUPPORT_R16 "1")
49+
else()
50+
set(FLANG_SUPPORT_R16 "0")
51+
endif()
52+
3453
# Init variable to hold extra object files coming from the Fortran modules;
3554
# these module files will be contributed from the CMakeLists in flang/tools/f18.
3655
set(module_objects "")
@@ -76,6 +95,10 @@ if (NOT CMAKE_CROSSCOMPILING)
7695
endif()
7796
endif()
7897

98+
set(decls "")
99+
if (FLANG_SUPPORT_R16)
100+
set(decls "-DFLANG_SUPPORT_R16")
101+
endif()
79102

80103
# Some modules have an implementation part that needs to be added to the
81104
# FortranRuntime library.
@@ -92,7 +115,7 @@ if (NOT CMAKE_CROSSCOMPILING)
92115
# TODO: We may need to flag this with conditional, in case Flang is built w/o OpenMP support
93116
add_custom_command(OUTPUT ${base}.mod ${object_output}
94117
COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
95-
COMMAND flang-new ${opts} -cpp ${compile_with} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
118+
COMMAND flang-new ${opts} ${decls} -cpp ${compile_with} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
96119
${FLANG_SOURCE_DIR}/module/${filename}.f90
97120
DEPENDS flang-new ${FLANG_SOURCE_DIR}/module/${filename}.f90 ${FLANG_SOURCE_DIR}/module/__fortran_builtins.f90 ${depends}
98121
)

lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,19 @@ def do_test_scopes_variables_setVariable_evaluate(
200200
verify_locals["pt"]["$__lldb_extensions"] = {
201201
"equals": {"autoSummary": "{x:11, y:22}"}
202202
}
203+
203204
verify_globals = {
204205
"s_local": {"equals": {"type": "float", "value": "2.25"}},
205-
"::g_global": {"equals": {"type": "int", "value": "123"}},
206-
"s_global": {"equals": {"type": "int", "value": "234"}},
207206
}
207+
s_global = {"equals": {"type": "int", "value": "234"}}
208+
g_global = {"equals": {"type": "int", "value": "123"}}
209+
if lldbplatformutil.getHostPlatform() == "windows":
210+
verify_globals["::s_global"] = s_global
211+
verify_globals["g_global"] = g_global
212+
else:
213+
verify_globals["s_global"] = s_global
214+
verify_globals["::g_global"] = g_global
215+
208216
varref_dict = {}
209217
self.verify_variables(verify_locals, locals, varref_dict)
210218
self.verify_variables(verify_globals, globals, varref_dict)
@@ -393,13 +401,11 @@ def do_test_scopes_variables_setVariable_evaluate(
393401

394402
self.verify_variables(verify_locals, locals)
395403

396-
@skipIfWindows
397404
def test_scopes_variables_setVariable_evaluate(self):
398405
self.do_test_scopes_variables_setVariable_evaluate(
399406
enableAutoVariableSummaries=False
400407
)
401408

402-
@skipIfWindows
403409
def test_scopes_variables_setVariable_evaluate_with_descriptive_summaries(self):
404410
self.do_test_scopes_variables_setVariable_evaluate(
405411
enableAutoVariableSummaries=True
@@ -600,11 +606,9 @@ def do_test_scopes_and_evaluate_expansion(self, enableAutoVariableSummaries: boo
600606
if scope["name"] == "Registers":
601607
self.assertEqual(scope.get("presentationHint"), "registers")
602608

603-
@skipIfWindows
604609
def test_scopes_and_evaluate_expansion(self):
605610
self.do_test_scopes_and_evaluate_expansion(enableAutoVariableSummaries=False)
606611

607-
@skipIfWindows
608612
def test_scopes_and_evaluate_expansion_with_descriptive_summaries(self):
609613
self.do_test_scopes_and_evaluate_expansion(enableAutoVariableSummaries=True)
610614

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 509912
19+
#define LLVM_MAIN_REVISION 509920
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

0 commit comments

Comments
 (0)