Skip to content

Commit 3f9842c

Browse files
Merge branch 'main' into fix-im2col-linalg
2 parents ebf0a8f + 7d815c7 commit 3f9842c

32 files changed

+1319
-194
lines changed

clang/docs/ThinLTO.rst

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ during the traditional link step.
249249

250250
The implementation is documented here: https://llvm.org/docs/DTLTO.html.
251251

252+
Command-Line Options
253+
^^^^^^^^^^^^^^^^^^^^
254+
252255
DTLTO requires the LLD linker (``-fuse-ld=lld``).
253256

254257
``-fthinlto-distributor=<path>``
@@ -260,17 +263,29 @@ DTLTO requires the LLD linker (``-fuse-ld=lld``).
260263
- Can be specified multiple times to pass multiple options.
261264
- Multiple options can also be specified by separating them with commas.
262265

263-
Examples:
264-
- ``clang -flto=thin -fthinlto-distributor=incredibuild.exe -Xthinlto-distributor=--verbose,--j10 -fuse-ld=lld``
265-
- ``clang -flto=thin -fthinlto-distributor=$(which python) -Xthinlto-distributor=incredibuild.py -fuse-ld=lld``
266-
267266
If ``-fthinlto-distributor=`` is specified, Clang supplies the path to a
268267
compiler to be executed remotely to perform the ThinLTO backend
269268
compilations. Currently, this is Clang itself.
270269

270+
Usage
271+
^^^^^
272+
273+
Compilation is unchanged from ThinLTO. DTLTO options need to supplied for the link step:
274+
275+
.. code-block:: console
276+
277+
% clang -flto=thin -fthinlto-distributor=distribute.sh -Xthinlto-distributor=--verbose,--j10 -fuse-ld=lld file1.o file2.o
278+
% clang -flto=thin -fthinlto-distributor=$(which python) -Xthinlto-distributor=distribute.py -fuse-ld=lld file1.o file2.o
279+
280+
When using lld-link:
281+
282+
.. code-block:: console
283+
284+
% lld-link /out:a.exe file1.obj file2.obj /thinlto-distributor:distribute.exe /thinlto-remote-compiler:${LLVM}\bin\clang.exe /thinlto-distributor-arg:--verbose
285+
271286
Note that currently, DTLTO is only supported in some LLD flavors. Support can
272287
be added to other LLD flavours in the future.
273-
See `DTLTO <https://lld.llvm.org/dtlto.html>`_ for more information.
288+
See `DTLTO <https://lld.llvm.org/DTLTO.html>`_ for more information.
274289

275290
More Information
276291
================

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4801,7 +4801,7 @@ void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
48014801
const FunctionDecl *CalleeDecl) {
48024802
if (!CallOrInvoke)
48034803
return;
4804-
auto *Func = CallOrInvoke->getCalledFunction();
4804+
auto *Func = dyn_cast<llvm::Function>(CallOrInvoke->getCalledOperand());
48054805
if (!Func)
48064806
return;
48074807
if (Func->getSubprogram())
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Test that call site debug info is (un)supported in various configurations.
2+
3+
// Supported: DWARF5, -O1, standalone DI
4+
// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple %s -o - \
5+
// RUN: -O1 -disable-llvm-passes \
6+
// RUN: -debug-info-kind=standalone -dwarf-version=5 \
7+
// RUN: | FileCheck %s -check-prefix=HAS-ATTR \
8+
// RUN: -implicit-check-not=DISubprogram -implicit-check-not=DIFlagAllCallsDescribed
9+
10+
// Supported: DWARF4 + LLDB tuning, -O1, limited DI
11+
// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple %s -o - \
12+
// RUN: -O1 -disable-llvm-passes \
13+
// RUN: -debugger-tuning=lldb \
14+
// RUN: -debug-info-kind=standalone -dwarf-version=4 \
15+
// RUN: | FileCheck %s -check-prefix=HAS-ATTR \
16+
// RUN: -implicit-check-not=DISubprogram -implicit-check-not=DIFlagAllCallsDescribed
17+
18+
// Note: DIFlagAllCallsDescribed may have been enabled prematurely when tuning
19+
// for GDB under -gdwarf-4 in https://reviews.llvm.org/D69743. It's possible
20+
// this should have been 'Unsupported' until entry values emission was enabled
21+
// by default.
22+
//
23+
// Supported: DWARF4 + GDB tuning
24+
// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu \
25+
// RUN: %s -o - -O1 -disable-llvm-passes -debugger-tuning=gdb \
26+
// RUN: -debug-info-kind=standalone -dwarf-version=4 \
27+
// RUN: | FileCheck %s -check-prefix=HAS-ATTR \
28+
// RUN: -implicit-check-not=DIFlagAllCallsDescribed
29+
30+
// Supported: DWARF4 + LLDB, -O1
31+
// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu \
32+
// RUN: %s -o - -O1 -disable-llvm-passes -debugger-tuning=lldb \
33+
// RUN: -debug-info-kind=standalone -dwarf-version=4 \
34+
// RUN: | FileCheck %s -check-prefix=HAS-ATTR \
35+
// RUN: -implicit-check-not=DIFlagAllCallsDescribed
36+
37+
// Unsupported: -O0
38+
// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu \
39+
// RUN: %s -o - -O0 -disable-llvm-passes -debugger-tuning=gdb \
40+
// RUN: -debug-info-kind=standalone -dwarf-version=4 \
41+
// RUN: | FileCheck %s -check-prefix=NO-ATTR
42+
43+
// Supported: DWARF4 + LLDB tuning, -O1, line-tables only DI
44+
// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple %s -o - \
45+
// RUN: -O1 -disable-llvm-passes \
46+
// RUN: -debugger-tuning=lldb \
47+
// RUN: -debug-info-kind=line-tables-only -dwarf-version=4 \
48+
// RUN: | FileCheck %s -check-prefix=LINE-TABLES-ONLY
49+
50+
// Unsupported: -O0
51+
// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple %s -o - \
52+
// RUN: -O0 \
53+
// RUN: -debug-info-kind=standalone -dwarf-version=5 \
54+
// RUN: | FileCheck %s -check-prefix=NO-ATTR
55+
56+
// Unsupported: DWARF4
57+
// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple %s -o - \
58+
// RUN: -O1 -disable-llvm-passes \
59+
// RUN: -debug-info-kind=standalone -dwarf-version=4 \
60+
// RUN: | FileCheck %s -check-prefix=NO-ATTR
61+
62+
// NO-ATTR-NOT: FlagAllCallsDescribed
63+
64+
// HAS-ATTR-DAG: DISubprogram(name: "declaration1", {{.*}}, spFlags: DISPFlagOptimized)
65+
// HAS-ATTR-DAG: DISubprogram(name: "declaration2", {{.*}}, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized
66+
// HAS-ATTR-DAG: DISubprogram(name: "declaration3", {{.*}}, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
67+
// HAS-ATTR-DAG: DISubprogram(name: "declaration4", {{.*}}, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized
68+
69+
// HAS-ATTR-DAG: DISubprogram(name: "force_irgen", {{.*}}, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition
70+
71+
// LINE-TABLES-ONLY: DISubprogram(name: "force_irgen", {{.*}}, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition
72+
73+
void declaration1();
74+
75+
void declaration2();
76+
77+
void declaration2() {}
78+
79+
void declaration3(void);
80+
81+
void declaration4(void);
82+
83+
void declaration4(void) {}
84+
85+
void __attribute__((optnone)) force_irgen(void) {
86+
declaration1();
87+
declaration3();
88+
}

cross-project-tests/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ set(CROSS_PROJECT_TEST_DEPS
1919
FileCheck
2020
check-gdb-llvm-support
2121
count
22-
llvm-dwarfdump
22+
llvm-ar
2323
llvm-config
24+
llvm-dwarfdump
2425
llvm-objdump
25-
split-file
2626
not
27+
split-file
2728
)
2829

2930
if ("clang" IN_LIST LLVM_ENABLE_PROJECTS)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
REQUIRES: ld.lld,llvm-ar
2+
3+
## Test that a DTLTO link succeeds and outputs the expected set of files
4+
## correctly when thin archives are present.
5+
6+
RUN: rm -rf %t && split-file %s %t && cd %t
7+
8+
## Compile bitcode. -O2 is required for cross-module importing.
9+
RUN: %clang -O2 --target=x86_64-linux-gnu -flto=thin -c \
10+
RUN: foo.c bar.c dog.c cat.c start.c
11+
12+
## Generate thin archives.
13+
RUN: llvm-ar rcs foo.a foo.o --thin
14+
## Create this bitcode thin archive in a subdirectory to test the expansion of
15+
## the path to a bitcode file that is referenced using "..", e.g., in this case
16+
## "../bar.o".
17+
RUN: mkdir lib
18+
RUN: llvm-ar rcs lib/bar.a bar.o --thin
19+
## Create this bitcode thin archive with an absolute path entry containing "..".
20+
RUN: llvm-ar rcs dog.a %t/lib/../dog.o --thin
21+
## The bitcode member of cat.a will not be used in the link.
22+
RUN: llvm-ar rcs cat.a cat.o --thin
23+
RUN: llvm-ar rcs start.a start.o --thin
24+
25+
## Link from a different directory to ensure that thin archive member paths are
26+
## resolved correctly relative to the archive locations.
27+
RUN: mkdir %t/out && cd %t/out
28+
29+
RUN: %clang --target=x86_64-linux-gnu -flto=thin -fuse-ld=lld %t/foo.a %t/lib/bar.a ../start.a %t/cat.a \
30+
RUN: -Wl,--whole-archive ../dog.a \
31+
RUN: -fthinlto-distributor=%python \
32+
RUN: -Xthinlto-distributor=%llvm_src_root/utils/dtlto/local.py \
33+
RUN: -Wl,--save-temps -nostdlib -Werror
34+
35+
## Check that the required output files have been created.
36+
RUN: ls | sort | FileCheck %s
37+
38+
## No files are expected before.
39+
CHECK-NOT: {{.}}
40+
41+
## JSON jobs description.
42+
CHECK: {{^}}a.[[PID:[a-zA-Z0-9_]+]].dist-file.json{{$}}
43+
44+
## Native output object files and individual summary index files.
45+
CHECK: {{^}}bar.3.[[PID]].native.o{{$}}
46+
CHECK: {{^}}bar.3.[[PID]].native.o.thinlto.bc{{$}}
47+
CHECK: {{^}}dog.1.[[PID]].native.o{{$}}
48+
CHECK: {{^}}dog.1.[[PID]].native.o.thinlto.bc{{$}}
49+
CHECK: {{^}}foo.2.[[PID]].native.o{{$}}
50+
CHECK: {{^}}foo.2.[[PID]].native.o.thinlto.bc{{$}}
51+
CHECK: {{^}}start.4.[[PID]].native.o{{$}}
52+
CHECK: {{^}}start.4.[[PID]].native.o.thinlto.bc{{$}}
53+
54+
## No files are expected after.
55+
CHECK-NOT: {{.}}
56+
57+
58+
## It is important that cross-module inlining occurs for this test to show that Clang can
59+
## successfully load the bitcode file dependencies recorded in the summary indices.
60+
## Explicitly check that the expected importing has occurred.
61+
62+
RUN: llvm-dis start.4.*.native.o.thinlto.bc -o - | \
63+
RUN: FileCheck %s --check-prefixes=FOO,BAR,START
64+
65+
RUN: llvm-dis dog.1.*.native.o.thinlto.bc -o - | \
66+
RUN: FileCheck %s --check-prefixes=FOO,BAR,DOG,START
67+
68+
RUN: llvm-dis foo.2.*.native.o.thinlto.bc -o - | \
69+
RUN: FileCheck %s --check-prefixes=FOO,BAR,START
70+
71+
RUN: llvm-dis bar.3.*.native.o.thinlto.bc -o - | \
72+
RUN: FileCheck %s --check-prefixes=FOO,BAR,START
73+
74+
FOO-DAG: foo.o
75+
BAR-DAG: bar.o
76+
DOG-DAG: dog.o
77+
START-DAG: start.o
78+
79+
80+
#--- foo.c
81+
extern int bar(int), _start(int);
82+
__attribute__((retain)) int foo(int x) { return x + bar(x) + _start(x); }
83+
84+
#--- bar.c
85+
extern int foo(int), _start(int);
86+
__attribute__((retain)) int bar(int x) { return x + foo(x) + _start(x); }
87+
88+
#--- dog.c
89+
extern int foo(int), bar(int), _start(int);
90+
__attribute__((retain)) int dog(int x) { return x + foo(x) + bar(x) + _start(x); }
91+
92+
#--- cat.c
93+
__attribute__((retain)) void cat(int x) {}
94+
95+
#--- start.c
96+
extern int foo(int), bar(int);
97+
__attribute__((retain)) int _start(int x) { return x + foo(x) + bar(x); }

cross-project-tests/lit.cfg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def get_required_attr(config, attr_name):
107107
if lldb_path is not None:
108108
config.available_features.add("lldb")
109109

110+
if llvm_config.use_llvm_tool("llvm-ar"):
111+
config.available_features.add("llvm-ar")
110112

111113
def configure_dexter_substitutions():
112114
"""Configure substitutions for host platform and return list of dependencies"""

libclc/CMakeLists.txt

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ set( LIBCLC_TARGETS_TO_BUILD "all"
4242

4343
option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal support." OFF )
4444

45+
option(
46+
LIBCLC_USE_SPIRV_BACKEND "Build SPIR-V targets with the SPIR-V backend." OFF
47+
)
48+
4549
# Top level target used to build all Libclc libraries.
4650
add_custom_target( libclc ALL )
4751

@@ -115,14 +119,17 @@ foreach( tool IN ITEMS clang opt llvm-as llvm-link )
115119
endif()
116120
endforeach()
117121

118-
# llvm-spirv is an optional dependency, used to build spirv-* targets.
119-
# It may be provided in-tree or externally.
120-
if( TARGET llvm-spirv )
121-
get_host_tool_path( llvm-spirv LLVM_SPIRV llvm-spirv_exe llvm-spirv_target )
122-
else()
123-
find_program( LLVM_SPIRV llvm-spirv HINTS ${LLVM_TOOLS_BINARY_DIR} )
124-
set( llvm-spirv_exe "${LLVM_SPIRV}" )
125-
set( llvm-spirv_target )
122+
if( NOT LIBCLC_USE_SPIRV_BACKEND )
123+
# llvm-spirv is an optional dependency, used to build spirv-* targets when
124+
# the SPIR-V backend hasn't been requested. It may be provided in-tree or
125+
# externally.
126+
if( TARGET llvm-spirv )
127+
get_host_tool_path( llvm-spirv LLVM_SPIRV llvm-spirv_exe llvm-spirv_target )
128+
else()
129+
find_program( LLVM_SPIRV llvm-spirv HINTS ${LLVM_TOOLS_BINARY_DIR} )
130+
set( llvm-spirv_exe "${LLVM_SPIRV}" )
131+
set( llvm-spirv_target )
132+
endif()
126133
endif()
127134

128135
# List of all targets. Note that some are added dynamically below.
@@ -138,22 +145,24 @@ set( LIBCLC_TARGETS_ALL
138145
nvptx64--nvidiacl
139146
)
140147

141-
# mesa3d environment is only available since LLVM 4.0
148+
# The mesa3d environment is only available since LLVM 4.0
142149
if( LLVM_PACKAGE_VERSION VERSION_GREATER_EQUAL 4.0.0 )
143150
list( APPEND LIBCLC_TARGETS_ALL amdgcn-mesa-mesa3d )
144151
endif()
145152

146-
# spirv-mesa3d and spirv64-mesa3d targets can only be built with the (optional)
147-
# llvm-spirv external tool.
148-
if( llvm-spirv_exe )
149-
list( APPEND LIBCLC_TARGETS_ALL spirv-mesa3d- spirv64-mesa3d- )
153+
# The spirv-mesa3d and spirv64-mesa3d targets are optional and can be built
154+
# with either the LLVM SPIR-V backend or the external llvm-spirv tool.
155+
if( LIBCLC_USE_SPIRV_BACKEND OR llvm-spirv_exe )
156+
list( APPEND LIBCLC_TARGETS_ALL spirv-mesa3d- spirv64-mesa3d- )
150157
endif()
151158

152159
# Verify that the user hasn't requested mesa3d targets without an available
153160
# llvm-spirv tool.
154-
if( "spirv-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD OR "spirv64-mesa3d-" IN_LIST LIBCLC_TARGETS_TO_BUILD )
155-
if( NOT llvm-spirv_exe )
156-
message( FATAL_ERROR "SPIR-V targets requested, but spirv-tools is not installed" )
161+
if( spirv-mesa3d- IN_LIST LIBCLC_TARGETS_TO_BUILD
162+
OR spirv64-mesa3d- IN_LIST LIBCLC_TARGETS_TO_BUILD )
163+
if( NOT LIBCLC_USE_SPIRV_BACKEND AND NOT llvm-spirv_exe )
164+
message( FATAL_ERROR "SPIR-V targets requested, but spirv-tools is not "
165+
"installed and the SPIR-V backend has not been requested." )
157166
endif()
158167
endif()
159168

libclc/cmake/modules/AddLibclc.cmake

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ function(get_libclc_device_info)
164164
list( GET TRIPLE 0 ARCH )
165165

166166
# Some targets don't have a specific device architecture to target
167-
if( ARG_DEVICE STREQUAL none OR ARCH STREQUAL spirv OR ARCH STREQUAL spirv64 )
167+
if( ARG_DEVICE STREQUAL none
168+
OR ((ARCH STREQUAL spirv OR ARCH STREQUAL spirv64)
169+
AND NOT LIBCLC_USE_SPIRV_BACKEND) )
168170
set( cpu )
169171
set( arch_suffix "${ARG_TRIPLE}" )
170172
else()
@@ -182,7 +184,11 @@ function(get_libclc_device_info)
182184

183185
# Some libclc targets are not real clang triples: return their canonical
184186
# triples.
185-
if( ARCH STREQUAL spirv OR ARCH STREQUAL clspv )
187+
if( ARCH STREQUAL spirv AND LIBCLC_USE_SPIRV_BACKEND )
188+
set( ARG_TRIPLE "spirv32--" )
189+
elseif( ARCH STREQUAL spirv64 AND LIBCLC_USE_SPIRV_BACKEND )
190+
set( ARG_TRIPLE "spirv64--" )
191+
elseif( ARCH STREQUAL spirv OR ARCH STREQUAL clspv )
186192
set( ARG_TRIPLE "spir--" )
187193
elseif( ARCH STREQUAL spirv64 OR ARCH STREQUAL clspv64 )
188194
set( ARG_TRIPLE "spir64--" )
@@ -363,10 +369,17 @@ function(add_libclc_builtin_set)
363369
if( ARG_ARCH STREQUAL spirv OR ARG_ARCH STREQUAL spirv64 )
364370
set( obj_suffix ${ARG_ARCH_SUFFIX}.spv )
365371
set( libclc_builtins_lib ${LIBCLC_OUTPUT_LIBRARY_DIR}/${obj_suffix} )
366-
add_custom_command( OUTPUT ${libclc_builtins_lib}
367-
COMMAND ${llvm-spirv_exe} ${spvflags} -o ${libclc_builtins_lib} ${builtins_link_lib}
368-
DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
369-
)
372+
if ( LIBCLC_USE_SPIRV_BACKEND )
373+
add_custom_command( OUTPUT ${libclc_builtins_lib}
374+
COMMAND ${clang_exe} --target=${ARG_TRIPLE} -x ir -o ${libclc_builtins_lib} ${builtins_link_lib}
375+
DEPENDS ${clang_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
376+
)
377+
else()
378+
add_custom_command( OUTPUT ${libclc_builtins_lib}
379+
COMMAND ${llvm-spirv_exe} ${spvflags} -o ${libclc_builtins_lib} ${builtins_link_lib}
380+
DEPENDS ${llvm-spirv_target} ${builtins_link_lib} ${builtins_link_lib_tgt}
381+
)
382+
endif()
370383
else()
371384
# Non-SPIR-V targets add an extra step to optimize the bytecode
372385
set( builtins_opt_lib_tgt builtins.opt.${ARG_ARCH_SUFFIX} )

0 commit comments

Comments
 (0)