Simon Pilgrim [Thu, 25 Aug 2022 11:23:26 +0000 (12:23 +0100)]
[CostModel][X86] Support cost kind specific look up tables
Most of our cost model tables have been created assuming cost kind == recip-throughput. But we're starting to see passes wanting to get accurate costs for the other kinds as well. Some of these can be determined procedurally (e.g. codesize by default could just be the split count after type legalization), but others are going to need to be handled in cost tables - this is especially true for x86 which has so many ISA combinations.
I've created a 'CostKindCosts' struct which can hold cost values for the 4 cost kinds, defaulting to -1U for unknown cost, this can be used with the existing CostTblEntryT/CostTableLookup template code. I've also added a [TargetCostKind] accessor to make it much easier to look up individual <Optional> costs.
This just changes the ISD::SELECT costs to check the effect (and also to check that the ISD::SETCC are correctly handled for default/None cost kinds) - the plan would be to slowly extend this and move the CostKindTblEntry type somewhere generic to allow other targets to use it once its matured.
I'm also going to resurrect D103695 so that it can help with latency/codesize/sizelatency coverage testing.
For sizelatency - IIRC the definition was vague to let it be target specific - I've tried to use typical uop counts so they're comparable to MicroOpBufferSize etc.
Differential Revision: https://reviews.llvm.org/D132216
zhongyunde [Thu, 25 Aug 2022 11:14:58 +0000 (19:14 +0800)]
[AArch64] Fix sched model for tsv110
Update three changes:
1.Split the Load/Store resources into two, Ld0St and Ld1,
since only one of them is capable of stores.
2.Integer ADD and SUB instructions have different latencies
and processor resource usage (pipeline) when they have a shift of
zero vs. non-zero, refer to D8043
3.The throughout of scalar DIV instruction.
Reviewed By: dmgreen, bryanpkc
Differential Revision: https://reviews.llvm.org/D132529
Max Kazantsev [Thu, 25 Aug 2022 10:48:50 +0000 (17:48 +0700)]
[IRCE] Drop SCEV of a Phi after adding a new input. PR57335
Since SCEV learned to look through single value phis with
20d798bd47ec5191de1b2a8a031da06a04e612e1, whenever we add
a new input to a Phi, we should make sure that the old cached
value is dropped. Otherwise, it may lead to various miscompiles,
such as breach of dominance as shown in the bug
https://github.com/llvm/llvm-project/issues/57335
Nico Weber [Thu, 25 Aug 2022 11:08:44 +0000 (07:08 -0400)]
Revert "[gn build] port
bc39d7bdd497 (libclang.map -> libclang.exports)"
This reverts commit
94c00c10e837aded6a6b15fe84c12f1ced4d856d.
bc39d7bdd497 was reverted in
0f28d4856630.
Sockke [Thu, 25 Aug 2022 10:23:57 +0000 (18:23 +0800)]
[clang-tidy] Ignore other members in a union if any member of it is initialized in cppcoreguidelines-pro-type-member-init
If a union member is initialized, the other members of the union are still suggested to be initialized in this check. This patch fixes this behavior.
Reference issue: https://github.com/llvm/llvm-project/issues/54748
Reviewed By: njames93
Differential Revision: https://reviews.llvm.org/D127293
Felipe de Azevedo Piovezan [Wed, 24 Aug 2022 20:03:29 +0000 (16:03 -0400)]
[lldb] Add more dylib paths for exception breakpoints
When setting a breakpoint upon throwing exceptions, LLDB only
searches for the libc++abi code inside dylibs named:
1. libc++abi.dylib
2. libSystem.B.dylib
However, this fails to account for libs with a version number. For
example, when building the libcxx and libcxxabi runtimes, the following
dylibs are generated:
build/lib/libc++abi.1.0.dylib
build/lib/libc++abi.1.dylib -> libc++abi.1.0.dylib
build/lib/libc++abi.dylib -> libc++abi.1.dylib
If we are debugging a program linked against any of the "versioned"
libs, the breakpoint doesn't work. This commit adds these names to the
search list.
Differential Revision: https://reviews.llvm.org/D132598
isuckatcs [Mon, 22 Aug 2022 12:43:54 +0000 (14:43 +0200)]
[analyzer] Fix for incorrect handling of 0 length non-POD array construction
Prior to this patch when the analyzer encountered a non-POD 0 length array,
it still invoked the constructor for 1 element, which lead to false positives.
This patch makes sure that we no longer construct any elements when we see a
0 length array.
Differential Revision: https://reviews.llvm.org/D131501
Felipe de Azevedo Piovezan [Wed, 24 Aug 2022 19:30:31 +0000 (15:30 -0400)]
[lldb][nfc] Remove unused makefile test variables
The variables LLDB_USING_LIBCPP and LLDB_USING_LIBSTDCPP are no longer
used anywhere.
Differential Revision: https://reviews.llvm.org/D132596
Dmitry Preobrazhensky [Thu, 25 Aug 2022 10:16:21 +0000 (13:16 +0300)]
[AMDGPU][MC][GFX11][NFC] Add missing tests for SOP instructions
Differential Revision: https://reviews.llvm.org/D132549
Dmitry Preobrazhensky [Thu, 25 Aug 2022 09:48:13 +0000 (12:48 +0300)]
[AMDGPU][MC][GFX11][NFC] Update tests for FLAT instructions
Update assembler tests for FLAT instructions; remove redundant gfx11_asm_flat_mnemonic.s.
Differential Revision: https://reviews.llvm.org/D132556
ZHU Zijia [Thu, 25 Aug 2022 08:59:34 +0000 (16:59 +0800)]
[RISCV][test] Update branch-relaxation.ll with update_llc_test_checks.py [NFC]
Update `llvm/test/CodeGen/RISCV/branch-relaxation.ll` with
`update_llc_test_checks.py`, according to
https://reviews.llvm.org/D130560#3746417:
>>! In D130560#3746417, @luismarques wrote:
>>>! In D130560#3746379, @luismarques wrote:
>> The tests don't seem to have been properly updated with
>> `update_llc_test_checks.py`.
>> `llvm/test/CodeGen/RISCV/branch-relaxation.ll` contains RV64 RUN
>> lines but the corresponding CHECK lines are missing in
>> some functions.
>
> Looking more closely at this, I guess you tried to only include the
> `CHECK-RV64` and `CHECK-RV32` checks when relevant. That's a good
> instinct but I guess it goes a bit against how we normally use
> `update_llc_test_checks.py`. My understanding of the trade-off of
> using that tool is that the test updates are much easier, even if
> sometimes the CHECKs aren't as tight as something more tailormade.
Reviewed By: luismarques
Differential Revision: https://reviews.llvm.org/D132625
ZHU Zijia [Thu, 25 Aug 2022 08:59:08 +0000 (16:59 +0800)]
Revert "[RISCV][test] Update branch-relaxation.ll with update_llc_test_checks.py [NFC]"
This reverts commit
c374789fba484af62a327a9337c7c9107461ee51.
Martin Storsjö [Mon, 22 Aug 2022 08:48:08 +0000 (11:48 +0300)]
[LLD] [COFF] Fix export directives in object files from -includeoptional
When an object file contains an export directive, we normally do some
amount of deferred processing of them at the end of the linking
process. The -includeoptional option was handled after this, and
any object files (defining new exports) weren't handled.
Move the handling of the -includeoptional into the same late loop
which does the fixups for e.g. export directives.
Ideally, this would also be done for object files that are pulled
in by the wrap options, and for mingw autoimports, but those changes
require more modifications, to make them safe for potentially
being executed multiple times.
This fixes https://github.com/llvm/llvm-project/issues/57243.
Differential Revision: https://reviews.llvm.org/D132361
Martin Storsjö [Tue, 23 Aug 2022 13:14:42 +0000 (16:14 +0300)]
[flang] [runtime] Fix build warnings if built with mingw
Check whether `F_OK` et al are defined before redefining them; mingw
headers do define them, so check before providing the windows fallback
defines.
Also check `_WIN32` instead of `WIN32`; this is how it's consistently
done in the rest of llvm. (The former is a compiler builtin define,
while the latter isn't, but it's commonly set by e.g. build systems.)
Differential Revision: https://reviews.llvm.org/D132481
ZHU Zijia [Thu, 25 Aug 2022 08:52:20 +0000 (16:52 +0800)]
[RISCV][test] Update branch-relaxation.ll with update_llc_test_checks.py [NFC]
Update `llvm/test/CodeGen/RISCV/branch-relaxation.ll` with
`update_llc_test_checks.py`, according to
https://reviews.llvm.org/D130560#3746417:
>>! In D130560#3746417, @luismarques wrote:
>>>! In D130560#3746379, @luismarques wrote:
>> The tests don't seem to have been properly updated with
>> `update_llc_test_checks.py`.
>> `llvm/test/CodeGen/RISCV/branch-relaxation.ll` contains RV64 RUN
>> lines but the corresponding CHECK lines are missing in
>> some functions.
>
> Looking more closely at this, I guess you tried to only include the
> `CHECK-RV64` and `CHECK-RV32` checks when relevant. That's a good
> instinct but I guess it goes a bit against how we normally use
> `update_llc_test_checks.py`. My understanding of the trade-off of
> using that tool is that the test updates are much easier, even if
> sometimes the CHECKs aren't as tight as something more tailormade.
Alexander Potapenko [Wed, 24 Aug 2022 09:49:52 +0000 (11:49 +0200)]
[compiler-rt][hwasan] Factor out CanUseTaggingAbi() and EnableTaggingAbi()
Simplify InitializeOsSupport() by separating code for detecting and
enabling the tagged address ABI.
Also drop the unnecessary errno checks (regardless of errno value, we
cannot assume that tagging works if the system call failed) and ensure
prctl(PR_SET_TAGGED_ADDR_CTRL) is only called on Android, not on x86
(where arch_prctl(ARCH_ENABLE_TAGGED_ADDR, kTagBits) is used).
Depends on D132544
Differential Revision: https://reviews.llvm.org/D132545
Denis Revunov [Thu, 25 Aug 2022 08:27:42 +0000 (04:27 -0400)]
[BOLT][AArch64] Handle references to the middle of Constant Islands
Fix BinaryContext::handleAddressRef to properly detect references to
other function's Constant islands.
Revieved By: rafauler, yota9
Differential Revision: https://reviews.llvm.org/D132376
Alexander Potapenko [Wed, 24 Aug 2022 09:20:23 +0000 (11:20 +0200)]
[compiler-rt][hwasan] Introduce MaybeDieIfNoTaggingAbi()
Use a helper function to print an error message and die in the case
flags()->fail_without_syscall_abi is set.
Because x86 doesn't have `sysctl abi.tagged_addr_disabled`, do not
mention it in the error message for non-Android runtime.
Depends on D132543
Differential Revision: https://reviews.llvm.org/D132544
Matthias Springer [Thu, 25 Aug 2022 08:12:50 +0000 (10:12 +0200)]
[mlir][tensor] Add getMixedSizes helper
This helper function computes the dimensions of a tensor value as OpFoldResults.
Differential Revision: https://reviews.llvm.org/D132475
Guillaume Chatelet [Thu, 25 Aug 2022 08:19:59 +0000 (10:19 +0200)]
[NFC][libc] Fix unused variable in string_writer_test test
Guillaume Chatelet [Thu, 25 Aug 2022 08:17:12 +0000 (10:17 +0200)]
[NFC][libc] Remove double semicolon
Balázs Kéri [Thu, 25 Aug 2022 06:38:55 +0000 (08:38 +0200)]
[clang-tidy] Add test to cert-dcl58-cpp (NFC).
Add a test to cert-dcl58-cpp.cpp to verify that crash in github
issue #56902 does not happen.
Reviewed By: njames93
Differential Revision: https://reviews.llvm.org/D131686
Alexander Potapenko [Wed, 24 Aug 2022 08:56:59 +0000 (10:56 +0200)]
[compiler-rt][hwasan] Massage prctl/arch_prctl API constants.
Move the definitions outside InitializeOsSupport(). Also remove the
undefs, as these constants won't be visible outside the .cpp file anyway.
Differential Revision: https://reviews.llvm.org/D132543
Alexander Batashev [Mon, 22 Aug 2022 10:12:31 +0000 (13:12 +0300)]
[mlir][LLVMIR] Parse some type attributes for LLVM function parameters
With the transition to opaque pointers, type information has been
transferred to function parameter attributes. This patch adds correct
parsing for some of those arguments and fixes some tests, that
previously used UnitAttr for those.
Differential Revision: https://reviews.llvm.org/D132366
Tobias Hieta [Thu, 25 Aug 2022 07:55:52 +0000 (09:55 +0200)]
[NFC] Fix a misleading comment CLANG_FORCE_MATCHING_LIBCLANG_SOVERSION
Pavel Samolysov [Thu, 25 Aug 2022 07:55:06 +0000 (10:55 +0300)]
[Pipelines] Introduce DAE after ArgumentPromotion
The ArgumentPromotion pass uses Mem2Reg promotion at the end to cutting
down generated `alloca` instructions as well as meaningless `store`s and
this behavior can leave unused (dead) arguments. To eliminate the dead
arguments and therefore let the DeadCodeElimination remove becoming dead
inserted `GEP`s as well as `load`s and `cast`s in the callers, the
DeadArgumentElimination pass should be run after the ArgumentPromotion
one.
Differential Revision: https://reviews.llvm.org/D128830
Michael Buch [Thu, 25 Aug 2022 07:42:33 +0000 (08:42 +0100)]
[lldb][Test] Prevent generating DW_AT_location for unused argument
This test simply checks whether we can print an optimized
function argument. With recent changes to Clang the assumption
that we don't generate a `DW_AT_location` attribute for the
unused funciton parameter breaks.
This patch tries harder to get Clang to drop the location
from DWARF by making it generate an `undef` for `unused1`.
Drop the check for `unused2` since it adds no benefit.
Differential Revision: https://reviews.llvm.org/D132635
H. Vetinari [Thu, 25 Aug 2022 06:35:46 +0000 (08:35 +0200)]
SONAME introduce option CLANG_FORCE_MATCHING_LIBCLANG_SOVERSION
This reverts commit
bc39d7bdd4977a953b2e102f8f7eb479ad78984e.
rename CLANG_SONAME to LIBCLANG_SOVERSION
[clang][cmake] introduce option CLANG_FORCE_MATCHING_LIBCLANG_SOVERSION
Differential Revision: https://reviews.llvm.org/D132486
Roy Jacobson [Thu, 25 Aug 2022 06:11:06 +0000 (09:11 +0300)]
Revert "[Clang] Implement P0848 (Conditionally Trivial Special Member Functions)"
See bug report here: https://github.com/llvm/llvm-project/issues/57351
This reverts commit
7171615099142ed49042c0f27af437b05150dd9b.
Dan McGregor [Thu, 25 Aug 2022 04:43:40 +0000 (21:43 -0700)]
[MCContext] Reverse order of DebugPrefixMap sort for generated assembly debug info
Match Clang's sorting, so that longer (more specific) prefix paths will match
before less specific paths.
Reviewed By: MaskRay, raj.khem, #debug-info
Differential Revision: https://reviews.llvm.org/D132390
wanglian [Wed, 24 Aug 2022 11:04:08 +0000 (19:04 +0800)]
[DAGCombiner] Use FoldConstantArithmetic instead of dyn_cast in visitFP_ROUND.
Reviewed By: RKSimon
Differential Revision: https://reviews.llvm.org/D132439
Ben Langmuir [Wed, 24 Aug 2022 21:54:13 +0000 (14:54 -0700)]
[clang][deps] Remove CompilerInvocation from ModuleDeps
The invocation is only ever used to serialize cc1 arguments from, so
instead serialize the arguments inside the dep scanner to simplify the
interface.
Differential Revision: https://reviews.llvm.org/D132616
Ben Langmuir [Wed, 24 Aug 2022 21:38:50 +0000 (14:38 -0700)]
[clang][tooling] Allow -cc1 arguments in ToolInvocation
ToolInvocation is useful even if you already have a -cc1 invocation,
since it provides a standard way to setup diagnostics, parse arguments,
and handoff to a ToolAction. So teach it to support -cc1 commands by
skipping the driver bits.
Differential Revision: https://reviews.llvm.org/D132615
Chenbing Zheng [Thu, 25 Aug 2022 02:41:47 +0000 (10:41 +0800)]
[InstCombine] recognize bitreverse disguised as shufflevector
This patch complete TODO left in D66965, and achieve
related pattern for bitreverse.
Reviewed By: RKSimon
Differential Revision: https://reviews.llvm.org/D132431
Chenbing Zheng [Thu, 25 Aug 2022 02:38:48 +0000 (10:38 +0800)]
[InstCombine] Add undef elements support for shrinkFPConstantVector
Reviewed By: RKSimon, spatel
Differential Revision: https://reviews.llvm.org/D132343
LLVM GN Syncbot [Thu, 25 Aug 2022 01:34:14 +0000 (01:34 +0000)]
[gn build] Port
5ce4c9aa0405
Nico Weber [Thu, 25 Aug 2022 01:33:56 +0000 (21:33 -0400)]
[gn build] port
5ce4c9aa0405
Matthias Braun [Wed, 24 Aug 2022 20:34:20 +0000 (13:34 -0700)]
Fix CSR update check
D132080 introduced a bug leading to `RegisterClassInfo` caches not
getting invalidated when there was exactly one more CSR register added.
Differential Revision: https://reviews.llvm.org/D132606
Fabian Parzefall [Thu, 25 Aug 2022 01:07:06 +0000 (18:07 -0700)]
[BOLT] Track fragment info for all split fragments
To generate all symbols correctly, it is necessary to record the address
of each fragment. This patch moves the address info for the main and
cold fragments from BinaryFunction to FunctionFragment, where this data
is recorded for all fragments.
Reviewed By: rafauler
Differential Revision: https://reviews.llvm.org/D132051
Fabian Parzefall [Thu, 25 Aug 2022 00:47:01 +0000 (17:47 -0700)]
[BOLT] Allocate FunctionFragment on heap
This changes `FunctionFragment` from being used as a temporary proxy
object to access basic block ranges to a heap-allocated object that can
store fragment-specific information.
Reviewed By: rafauler
Differential Revision: https://reviews.llvm.org/D132050
Matthias Braun [Thu, 25 Aug 2022 00:55:12 +0000 (17:55 -0700)]
Revert "MC: make section classification a bit more thorough"
This reverts commit
73a9dfcee24df959b59a46d75dcbdc0bcfb50fe6.
We started to hit assertions when compiling & assembling separately.
See comments in https://reviews.llvm.org/D131270
Mircea Trofin [Thu, 25 Aug 2022 00:30:54 +0000 (17:30 -0700)]
[mlgo] Fix tests
Missed a few tests in D119507
Valery N Dmitriev [Wed, 24 Aug 2022 19:57:56 +0000 (12:57 -0700)]
[SLP][NFC] Refactor SLPVectorizerPass::vectorizeRootInstruction method.
The goal is to separate collecting items for post-processing
and processing them. Post processing also outlined as
dedicated method.
Differential Revision: https://reviews.llvm.org/D132603
Jeff Niu [Wed, 24 Aug 2022 06:17:19 +0000 (23:17 -0700)]
[mlir] Remove the element type enum from DenseArrayAttr
The element type enum is not needed to differentiate dense array kinds
because the element type of the shaped type can be used instead.
Reviewed By: mehdi_amini, rriddle
Differential Revision: https://reviews.llvm.org/D132535
Fabian Parzefall [Wed, 24 Aug 2022 22:56:02 +0000 (15:56 -0700)]
[BOLT] Towards FunctionLayout const-correctness
A const-qualified reference to function layout allows accessing
non-const qualified basic blocks on a const-qualified function. This
patch adds or removes const-qualifiers where necessary to indicate where
basic blocks are used in a non-const manner.
Reviewed By: rafauler
Differential Revision: https://reviews.llvm.org/D132049
Usman Nadeem [Wed, 24 Aug 2022 23:23:19 +0000 (16:23 -0700)]
[AArch64][DAGCombine] Fix a bug in performBuildVectorCombine where it could produce an invalid EXTRACT_SUBVECTOR
EXTRACT_SUBVECTOR requires that Idx be a constant multiple of ResultType's
known minimum vector length.
Something like this will produce an invalid extract_subvector:
t1: v4i16 = .....
t2: i32 = extract_vector_elt t1, Constant:i64<1>
t3: i32 = extract_vector_elt t1, Constant:i64<2>
t4: v2i32 = BUILD_VECTOR t2, t3
// produces
t5: v2i32 = extract_subvector t...., Constant:i64<1>
Differential Revision: https://reviews.llvm.org/D132517
Change-Id: I7a5acf054edee3e89c0f85a28d8869256403ce08
Mircea Trofin [Sat, 6 Aug 2022 03:28:49 +0000 (20:28 -0700)]
[mlgo] Use TFLite for 'development' mode.
TLite is a lightweight, statically linkable[1], model evaluator, supporting a
subset of what the full tensorflow library does, sufficient for the
types of scenarios we envision having. It is also faster.
We still use saved models as "source of truth" - 'release' mode's AOT
starts from a saved model; and the ML training side operates in terms of
saved models.
Using TFLite solves the following problems compared to using the full TF
C API:
- a compiler-friendly implementation for runtime-loadable (as opposed
to AOT-embedded) models: it's statically linked; it can be built via
cmake;
- solves an issue we had when building the compiler with both AOT and
full TF C API support, whereby, due to a packaging issue on the TF
side, we needed to have the pip package and the TF C API library at
the same version. We have no such constraints now.
The main liability is it supporting a subset of what the full TF
framework does. We do not expect that to cause an issue, but should that
be the case, we can always revert back to using the full framework
(after also figuring out a way to address the problems that motivated
the move to TFLite).
Details:
This change switches the development mode to TFLite. Models are still
expected to be placed in a directory - i.e. the parameters to clang
don't change; what changes is the directory content: we still need
an `output_spec.json` file; but instead of the saved_model protobuf and
the `variables` directory, we now just have one file, `model.tflite`.
The change includes a utility showing how to take a saved model and
convert it to TFLite, which it uses for testing.
The full TF implementation can still be built (not side-by-side). We
intend to remove it shortly, after patching downstream dependencies. The
build behavior, however, prioritizes TFLite - i.e. trying to enable both
full TF C API and TFLite will just pick TFLite.
[1] thanks to @petrhosek's changes to TFLite's cmake support and its deps!
Zequan Wu [Mon, 22 Aug 2022 17:26:00 +0000 (10:26 -0700)]
[LLDB] Clean up after command fails
`CommandObject::CheckRequirements()` requires m_exe_ctx being cleaned up.
Differential Revision: https://reviews.llvm.org/D132397
Philip Reames [Wed, 24 Aug 2022 22:48:25 +0000 (15:48 -0700)]
[RISCV] Remove cttz/ctlz cost model coverage for the moment
I'd used the wrong signatures for these as I had not remembered we'd added the second boolean argument. We appear to still parse the old form just fine, but we should use the two argument form in test since that's what the LangRef actually describes.
Akira Hatanaka [Mon, 22 Aug 2022 23:25:59 +0000 (16:25 -0700)]
[compiler-rt][builtins] Add compiler flags to catch potential errors
that can lead to security vulnerabilities
Also, fix a few places that were causing -Wshadow and
-Wformat-nonliteral warnings to be emitted.
This reapplies the patch that was reverted in
0d66dc57e8c7 because it
broke a few bots.
I made changes so that cmake checks whether some of the flags are
supported by the compiler that is used before adding them to the list.
Also, I moved function add_security_warnings to CompilerRTUtils.cmake so
that it is defined before it's used.
Differential Revision: https://reviews.llvm.org/D131714
Sami Tolvanen [Tue, 15 Feb 2022 22:32:08 +0000 (14:32 -0800)]
KCFI sanitizer
The KCFI sanitizer, enabled with `-fsanitize=kcfi`, implements a
forward-edge control flow integrity scheme for indirect calls. It
uses a !kcfi_type metadata node to attach a type identifier for each
function and injects verification code before indirect calls.
Unlike the current CFI schemes implemented in LLVM, KCFI does not
require LTO, does not alter function references to point to a jump
table, and never breaks function address equality. KCFI is intended
to be used in low-level code, such as operating system kernels,
where the existing schemes can cause undue complications because
of the aforementioned properties. However, unlike the existing
schemes, KCFI is limited to validating only function pointers and is
not compatible with executable-only memory.
KCFI does not provide runtime support, but always traps when a
type mismatch is encountered. Users of the scheme are expected
to handle the trap. With `-fsanitize=kcfi`, Clang emits a `kcfi`
operand bundle to indirect calls, and LLVM lowers this to a
known architecture-specific sequence of instructions for each
callsite to make runtime patching easier for users who require this
functionality.
A KCFI type identifier is a 32-bit constant produced by taking the
lower half of xxHash64 from a C++ mangled typename. If a program
contains indirect calls to assembly functions, they must be
manually annotated with the expected type identifiers to prevent
errors. To make this easier, Clang generates a weak SHN_ABS
`__kcfi_typeid_<function>` symbol for each address-taken function
declaration, which can be used to annotate functions in assembly
as long as at least one C translation unit linked into the program
takes the function address. For example on AArch64, we might have
the following code:
```
.c:
int f(void);
int (*p)(void) = f;
p();
.s:
.4byte __kcfi_typeid_f
.global f
f:
...
```
Note that X86 uses a different preamble format for compatibility
with Linux kernel tooling. See the comments in
`X86AsmPrinter::emitKCFITypeId` for details.
As users of KCFI may need to locate trap locations for binary
validation and error handling, LLVM can additionally emit the
locations of traps to a `.kcfi_traps` section.
Similarly to other sanitizers, KCFI checking can be disabled for a
function with a `no_sanitize("kcfi")` function attribute.
Relands
67504c95494ff05be2a613129110c9bcf17f6c13 with a fix for
32-bit builds.
Reviewed By: nickdesaulniers, kees, joaomoreira, MaskRay
Differential Revision: https://reviews.llvm.org/D119296
Philip Reames [Wed, 24 Aug 2022 22:36:17 +0000 (15:36 -0700)]
{RISCV] Backout cttz/ctlz instruction costs
Craig points out correctly in post-commit review that these depend on the availability of floating point extensions.
Rob Suderman [Wed, 24 Aug 2022 22:19:15 +0000 (15:19 -0700)]
[mlir][tosa] Add constant folding for tosa.slice
If the input to a tosa.slice operation is a splat we can just replace with
another splat. If the result is a single element, replacing with a splat
is universally useful.
Reviewed By: NatashaKnk
Differential Revision: https://reviews.llvm.org/D132499
Craig Topper [Wed, 24 Aug 2022 22:31:17 +0000 (15:31 -0700)]
[RISCV] Pre-commit tests for D132614. NFC
Jonathon Penix [Thu, 11 Aug 2022 23:10:52 +0000 (16:10 -0700)]
[Flang] Enable lowering of CONVERT specifier in OPEN statements
The runtime function was implemented and tested and the
specifier was handled, but it seems lowering was never
specifically added.
Differential Revision: https://reviews.llvm.org/D131814
Rob Suderman [Wed, 24 Aug 2022 21:48:05 +0000 (14:48 -0700)]
[mlir][tosa] Added folders for tosa.add
Added folders for tosa.add that handles bypassing add-zero,
fold additions of two splat tensors, and additions between
two tensors with small values.
Reviewed By: jpienaar
Differential Revision: https://reviews.llvm.org/D132272
Philip Reames [Wed, 24 Aug 2022 22:02:18 +0000 (15:02 -0700)]
[RISCV] Add empirical costs for bswap/bitreverse/ctpop/ctlz/cttz
If anyone is looking for a source of ideas on vector codegen improvements, the lowerings for several of these seem to include pretty obvious fixits.
Philip Reames [Wed, 24 Aug 2022 21:41:07 +0000 (14:41 -0700)]
[RISCV] Add cost model coverage for integer bitmanip intrinsics
Benjamin Kramer [Wed, 24 Aug 2022 22:03:08 +0000 (00:03 +0200)]
[AST] Use std::apply to pop front of tuples. NFCI.
Sanjay Patel [Wed, 24 Aug 2022 21:57:40 +0000 (17:57 -0400)]
[InstCombine] use isa instead of dyn_cast for unused value; NFC
Daniel Bertalan [Mon, 22 Aug 2022 10:32:31 +0000 (12:32 +0200)]
[lld-macho][test] Check addresses in flat-namespace-interposable.s
This test helped me catch an issue in my implementation of chained
fixups (D132560). This commit makes the test more robust by checking if
the bind opcodes are emitted for the correct address.
Differential Revision: https://reviews.llvm.org/D132367
Michael Kruse [Wed, 24 Aug 2022 20:52:06 +0000 (15:52 -0500)]
[flang] Fix msvc 17.3 build.
Compile fix for Microsoft Visual Studio 17.3 (msvc 14.33.31629) which regressed from 17.1.
The compile error is:
```
llvm-project\flang\lib\Evaluate\fold-integer.cpp(802,41): error C2672: 'invoke': no matching overloaded function found
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\type_traits(1552,19): message : could be 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 &&...) noexcept(<expr>)'
llvm-project\flang\lib\Evaluate\fold-integer.cpp(802,41): message : Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 &&...) noexcept(<expr>)'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\type_traits(1552): message : see declaration of 'std::invoke'
llvm-project\flang\lib\Evaluate\fold-integer.cpp(490,1): message : With the following template arguments:
llvm-project\flang\lib\Evaluate\fold-integer.cpp(490,1): message : '_Callable=int (__cdecl Fortran::evaluate::value::Integer<16,true,16,unsigned short,unsigned int>::* &)(void) const'
llvm-project\flang\lib\Evaluate\fold-integer.cpp(490,1): message : '_Ty1=const Fortran::evaluate::value::Integer<8,true,8,unsigned char,unsigned short> &'
llvm-project\flang\lib\Evaluate\fold-integer.cpp(490,1): message : '_Types2={}'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\type_traits(1546,19): message : or 'unknown-type std::invoke(_Callable &&) noexcept(<expr>)'
C:\Users\meinersbur\src\llvm-project\flang\lib\Evaluate\fold-integer.cpp(802,41): message : 'unknown-type std::invoke(_Callable &&) noexcept(<expr>)': expects 1 arguments - 2 provided
```
For some reason, msvc thinks that the lambda argument is `Scalar<T>` instead of `Scalar<TI>` as declared. This only happens in nested closures, using a lambda without `[]` arguments makes the problem disappear. Using `auto` instead to automatically derive the type fixes the problem.
I recently updated the version of Visual Studio on [[ https://lab.llvm.org/buildbot/#/builders/172 | flang-x86_64-windows buildbot ]] which since then fails because of this problem. It occasionally failed with 'fatal error C1001: Internal compiler error." internal error which I hoped to fix with an update.
Reviewed By: klausler
Differential Revision: https://reviews.llvm.org/D132594
Pirama Arumuga Nainar [Wed, 24 Aug 2022 21:24:13 +0000 (21:24 +0000)]
[lldb] Remove obsolete Android-specific definitions
Bionic's <sys/procfs.h> defines the necessary symbols. Remove the
specialization for Android and the now-unnecessary include of
<sys/ptrace.h>. This also helps resolve issues when building the
x86/x86_64 lldb-server for Android.
Curiously, the default branch to include <sys/procfs.h> doesn't seem
necessary on Linux. I'll remove it and add it back if it breaks other
builders.
Differential Revision: https://reviews.llvm.org/D132514
LLVM GN Syncbot [Wed, 24 Aug 2022 21:45:56 +0000 (21:45 +0000)]
[gn build] Port
91389000abe8
Adrian Vogelsgesang [Sun, 21 Aug 2022 17:50:52 +0000 (10:50 -0700)]
[LLDB] Add data formatter for std::coroutine_handle
This patch adds a formatter for `std::coroutine_handle`, both for libc++
and libstdc++. For the type-erased `coroutine_handle<>`, it shows the
`resume` and `destroy` function pointers. For a non-type-erased
`coroutine_handle<promise_type>` it also shows the `promise` value.
With this change, executing the `v t` command on the example from
https://clang.llvm.org/docs/DebuggingCoroutines.html now outputs
```
(task) t = {
handle = coro frame = 0x55555555b2a0 {
resume = 0x0000555555555a10 (a.out`coro_task(int, int) at llvm-example.cpp:36)
destroy = 0x0000555555556090 (a.out`coro_task(int, int) at llvm-example.cpp:36)
}
}
```
instead of just
```
(task) t = {
handle = {
__handle_ = 0x55555555b2a0
}
}
```
Note, how the symbols for the `resume` and `destroy` function pointer
reveal which coroutine is stored inside the `std::coroutine_handle`.
A follow-up commit will use this fact to infer the coroutine's promise
type and the representation of its internal coroutine state based on
the `resume` and `destroy` pointers.
The same formatter is used for both libc++ and libstdc++. It would
also work for MSVC's standard library, however it is not registered
for MSVC, given that lldb does not provide pretty printers for other
MSVC types, either.
The formatter is in a newly added `Coroutines.{h,cpp}` file because there
does not seem to be an already existing place where we could share
formatters across libc++ and libstdc++. Also, I expect this code to grow
as we improve debugging experience for coroutines further.
**Testing**
* Added API test
Differential Revision: https://reviews.llvm.org/D132415
Jan Svoboda [Tue, 16 Aug 2022 00:27:43 +0000 (17:27 -0700)]
[clang][modules] Consider M affecting after mapping M.Private to M_Private
When Clang encounters `@import M.Private` during implicit build, it precompiles module `M` and looks through its submodules. If the `Private` submodule is not found, Clang assumes `@import M_Private`. In the dependency scanner, we don't capture the dependency on `M`, since it's not imported. It's an affecting module, though: compilation of the import statement will fail when implicit modules are disabled and `M` is not precompiled and explicitly provided. This patch fixes that.
Depends on D132430.
Reviewed By: benlangmuir
Differential Revision: https://reviews.llvm.org/D132502
Philip Reames [Wed, 24 Aug 2022 21:21:43 +0000 (14:21 -0700)]
[RISCV] Add empirically measured vector sqrt intrinsic costs
Philip Reames [Wed, 24 Aug 2022 21:16:48 +0000 (14:16 -0700)]
[RISCV] Add cost model coverage for floating point sqrt intrinsic
Uday Bondhugula [Wed, 24 Aug 2022 20:36:47 +0000 (02:06 +0530)]
[MLIR] Generalize/complete getEnclosingAffineForIfOps utility
Rename/generalize getEnclosingAffineForIfOps -> getEnclosingAffineOps.
The utility was originally written only for affine.for ops and then
extended for affine.if as well. It wasn't however updated when
affine.parallel was introduced -- in most cases, analysis has been used
in the presence of affine.for/if but not post parallelization. Extend
utility to also support affine.parallel ops; this allows future changes
to enable affine analysis and opts in the presence of affine.parallel
ops. Fix related stale comments.
This is NFC for all use cases in tree.
Change an associated assert to a utility failure.
Reviewed By: ftynse
Differential Revision: https://reviews.llvm.org/D132326
Jonas Devlieghere [Wed, 24 Aug 2022 19:46:12 +0000 (12:46 -0700)]
[lldb] Remove unused functions in ObjectContainer (NFC)
Philip Reames [Wed, 24 Aug 2022 21:08:56 +0000 (14:08 -0700)]
[RISCV] Add vector fabs intrinsic costs
We have a fabs vector instruction, and are using it for current lowering.
V Donaldson [Wed, 24 Aug 2022 17:22:42 +0000 (10:22 -0700)]
[flang] Noncontiguous formats
Add the remaining pieces to support IO for noncontigous formats.
This is done by passing an array descriptor to IO calls. Scalar
formats continue to pass string and length arguments. IO calls
with formats are modified to place the new format descriptor
argument directly after the original string and length arguments.
Ilia Diachkov [Tue, 23 Aug 2022 23:13:19 +0000 (02:13 +0300)]
[SPIRV] support builtin functions
The patch adds support for OpenCL and SPIR-V built-in functions.
Their detection and properties are implemented using TableGen.
Five tests are added to demonstrate the improvement.
Differential Revision: https://reviews.llvm.org/D132024
Co-authored-by: Aleksandr Bezzubikov <zuban32s@gmail.com>
Co-authored-by: Michal Paszkowski <michal.paszkowski@outlook.com>
Co-authored-by: Andrey Tretyakov <andrey1.tretyakov@intel.com>
Co-authored-by: Konrad Trifunovic <konrad.trifunovic@intel.com>
Peter Cooper [Wed, 24 Aug 2022 16:53:15 +0000 (09:53 -0700)]
Add MachO MH_FILESET support to objdump
https://reviews.llvm.org/D131909
Saleem Abdulrasool [Tue, 23 Aug 2022 15:58:36 +0000 (15:58 +0000)]
RISCV: permit unaligned nop-slide padding emission
We may be requested to emit an unaligned nop sequence (e.g. 7-bytes or
3-bytes). These should be 0-filled even though that is not a valid
instruction. This matches the behaviour on other architectures like
ARM, X86, and MIPS. When a custom section is emitted, it may be
classified as text even though it may be a data section or we may be
emitting data into a text segment (e.g. a literal pool). In such cases,
we should be resilient to the emission request.
This was originally identified by the Linux kernel build and reported on
D131270 by Nathan Chancellor.
Differential Revision: https://reviews.llvm.org/D132482
Reviewed By: luismarques
Tested By: Nathan Chancellor
Cameron McInally [Wed, 24 Aug 2022 14:57:38 +0000 (07:57 -0700)]
[GlobalOpt] Bail out of GlobalOpt SROA if a Scalable Vector is seen
The SROA algorithm won't work for Scalable Vectors, since we don't
know how many bytes are loaded/stored. Bail out if a Scalable
Vector is seen.
Differential Revision: https://reviews.llvm.org/D132417
Sanjay Patel [Wed, 24 Aug 2022 18:59:15 +0000 (14:59 -0400)]
[InstCombine] reduce disguised mul+add factorization
~(A * C1) + A --> (A * (1 - C1)) - 1
This is a non-obvious mix of bitwise logic and math:
https://alive2.llvm.org/ce/z/U7ACVT
The pattern may be produced by Negator from the more typical
code seen in issue #57255.
Sanjay Patel [Wed, 24 Aug 2022 18:23:51 +0000 (14:23 -0400)]
[InstCombine] add tests for add with not-of-mul common operand; NFC
Negator can create non-obvious math while trying hard to avoid subtraction.
issue #57255
Eli Friedman [Wed, 24 Aug 2022 19:52:17 +0000 (12:52 -0700)]
Exclude check-polly-unittests and check-polly-isl from check-all
The unittests are already included in check-polly, so check-all was
running them twice. Running them twice causes a race on the output
files, which led to intermittent failures on the reverse-iteration
buildbot.
Chris Bieneman [Wed, 24 Aug 2022 19:34:46 +0000 (14:34 -0500)]
[HLSL] Entry functions require param annotation
HLSL entry function parameters must have parameter annotations. This
allows appropriate intrinsic values to be populated into parameters
during code generation.
This does not handle entry function return values, which will be
handled in a subsequent commit because we don't currently support any
annotations that are valid for function returns.
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D131625
Ye Luo [Wed, 24 Aug 2022 18:50:42 +0000 (13:50 -0500)]
[libomptarget][amdgpu] enable tests whenever possible.
if(TARGET amdgpu-arch) doesn't work when ENABLE_LLVM_PROJECTS=openmp because openmp subdirectory is processed before clang subdirectory. Adopt the same logic of enabling tests like the CUDA plugin.
Differential Revision: https://reviews.llvm.org/D132579
Sami Tolvanen [Wed, 24 Aug 2022 19:26:05 +0000 (19:26 +0000)]
Revert "KCFI sanitizer"
This reverts commit
67504c95494ff05be2a613129110c9bcf17f6c13 as using
PointerEmbeddedInt to store 32 bits breaks 32-bit arm builds.
Michael Liao [Wed, 24 Aug 2022 19:14:39 +0000 (15:14 -0400)]
[LoongArch] Fix build due to TLI interface changes. NFC.
- isCheapToSpeculateCttz/isCheapToSpeculateCtlz have one type operand
after https://reviews.llvm.org/D132520
Prabhdeep Singh Soni [Wed, 24 Aug 2022 17:18:31 +0000 (13:18 -0400)]
[Flang][OpenMP] Add support for safelen clause
This supports lowering from parse-tree to MLIR for OpenMP safelen clause
in SIMD construct.
Reviewed By: kiranchandramohan
Differential Revision: https://reviews.llvm.org/D132574
Sami Tolvanen [Tue, 15 Feb 2022 22:32:08 +0000 (14:32 -0800)]
KCFI sanitizer
The KCFI sanitizer, enabled with `-fsanitize=kcfi`, implements a
forward-edge control flow integrity scheme for indirect calls. It
uses a !kcfi_type metadata node to attach a type identifier for each
function and injects verification code before indirect calls.
Unlike the current CFI schemes implemented in LLVM, KCFI does not
require LTO, does not alter function references to point to a jump
table, and never breaks function address equality. KCFI is intended
to be used in low-level code, such as operating system kernels,
where the existing schemes can cause undue complications because
of the aforementioned properties. However, unlike the existing
schemes, KCFI is limited to validating only function pointers and is
not compatible with executable-only memory.
KCFI does not provide runtime support, but always traps when a
type mismatch is encountered. Users of the scheme are expected
to handle the trap. With `-fsanitize=kcfi`, Clang emits a `kcfi`
operand bundle to indirect calls, and LLVM lowers this to a
known architecture-specific sequence of instructions for each
callsite to make runtime patching easier for users who require this
functionality.
A KCFI type identifier is a 32-bit constant produced by taking the
lower half of xxHash64 from a C++ mangled typename. If a program
contains indirect calls to assembly functions, they must be
manually annotated with the expected type identifiers to prevent
errors. To make this easier, Clang generates a weak SHN_ABS
`__kcfi_typeid_<function>` symbol for each address-taken function
declaration, which can be used to annotate functions in assembly
as long as at least one C translation unit linked into the program
takes the function address. For example on AArch64, we might have
the following code:
```
.c:
int f(void);
int (*p)(void) = f;
p();
.s:
.4byte __kcfi_typeid_f
.global f
f:
...
```
Note that X86 uses a different preamble format for compatibility
with Linux kernel tooling. See the comments in
`X86AsmPrinter::emitKCFITypeId` for details.
As users of KCFI may need to locate trap locations for binary
validation and error handling, LLVM can additionally emit the
locations of traps to a `.kcfi_traps` section.
Similarly to other sanitizers, KCFI checking can be disabled for a
function with a `no_sanitize("kcfi")` function attribute.
Reviewed By: nickdesaulniers, kees, joaomoreira, MaskRay
Differential Revision: https://reviews.llvm.org/D119296
Siva Chandra Reddy [Wed, 24 Aug 2022 18:24:57 +0000 (18:24 +0000)]
[libc] Add linux implementation of POSIX fchmodat function.
Reviewed By: michaelrj
Differential Revision: https://reviews.llvm.org/D132533
Philip Reames [Wed, 24 Aug 2022 18:42:10 +0000 (11:42 -0700)]
[LV] Simplify code given isPredicatedInst doesn't dependent on VF any more [nfc]
Philip Reames [Wed, 24 Aug 2022 18:19:55 +0000 (11:19 -0700)]
[RISCV][LV] Add predicated div/rem test for fixed length vectorization
Valery N Dmitriev [Tue, 23 Aug 2022 17:36:24 +0000 (10:36 -0700)]
[SLP][NFC] Add test case exposing deficiency in finding reductions that feed buildvector sequence.
Differential Revision: https://reviews.llvm.org/D132506
Jan Svoboda [Wed, 24 Aug 2022 18:07:24 +0000 (11:07 -0700)]
[clang][modules] Track affecting modules
When compiling a module, its semantics and Clang's behavior are affected by other modules. These modules are typically the **imported** ones. However, during implicit build, some modules end up being compiled and read without being actually imported. This patch starts tracking such modules and serializing them into `.pcm` files. This enables the dependency scanner to construct explicit compilations that mimic implicit build.
Reviewed By: benlangmuir
Differential Revision: https://reviews.llvm.org/D132430
Philip Reames [Wed, 24 Aug 2022 18:05:13 +0000 (11:05 -0700)]
[LV] Update a test which appears to have been editted without regen [nfc]
Fabian Parzefall [Wed, 24 Aug 2022 17:47:57 +0000 (10:47 -0700)]
Revert "[BOLT] Towards FunctionLayout const-correctness"
This reverts commit
587d2653420d75ef10f30bd612d86f1e08fe9ea7.
Fabian Parzefall [Wed, 24 Aug 2022 17:47:48 +0000 (10:47 -0700)]
Revert "[BOLT] Allocate FunctionFragment on heap"
This reverts commit
101344af1af82d1633c773b718788eaa813d7f79.
Fabian Parzefall [Wed, 24 Aug 2022 17:47:35 +0000 (10:47 -0700)]
Revert "[BOLT] Track fragment info for all split fragments"
This reverts commit
7e254818e49454a53bd00e3737007025b62d0f79.
Philip Reames [Wed, 24 Aug 2022 17:36:06 +0000 (10:36 -0700)]
[LV] Adjust code added in
f79214d1 for
531dd3634 [nfc]
When rebasing the review which became
f79214d1, I forgot to adjust for the changed semantics introduced by
531dd3634. Functionally, this had no impact, but semantically it resulted in an incorrect result for isPredicatedInst. I noticed this while doing a follow up change.
Petr Hosek [Tue, 23 Aug 2022 07:26:37 +0000 (07:26 +0000)]
[Clang] Avoid using unwind library in the MSVC environment
We're seeing the following warnings with --rtlib=compiler-rt:
lld-link: warning: ignoring unknown argument '--as-needed'
lld-link: warning: ignoring unknown argument '-lunwind'
lld-link: warning: ignoring unknown argument '--no-as-needed'
MSVC doesn't use the unwind library, so just omit it.
Differential Revision: https://reviews.llvm.org/D132440
Daniel Bertalan [Tue, 16 Aug 2022 15:14:27 +0000 (17:14 +0200)]
[llvm-objdump] Complete -chained_fixups support
This commit adds definitions for the `dyld_chained_import*` structs.
The imports array is now printed with `llvm-otool -chained_fixups`. This
completes this option's implementation.
A slight difference from cctools otool is that we don't yet dump the
raw bytes of the imports entries.
When Apple's effort to upstream their chained fixups code continues,
we'll replace this code with the then-upstreamed code. But we need
something in the meantime for testing ld64.lld's chained fixups code.
Differential Revision: https://reviews.llvm.org/D131982
Michael Jones [Tue, 16 Aug 2022 21:02:34 +0000 (14:02 -0700)]
[libc] move printf to use StringViews
The FormatSection and the writer functions both previously took a char*
and a length to represent a string. Now they use the StringView class to
represent that more succinctly. This change also required fixing
everywhere these were used, so it touches a lot of files.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D131994
Mark de Wever [Wed, 24 Aug 2022 05:49:43 +0000 (07:49 +0200)]
[libc++] Tests transitive includes for all C++ versions.
D132284 has an approach to reduce the number of transitive includes
based on the language version used. This requires to be able to validate
changes in transitive includes in all language versions.
Due to issues in the experimental library c++03 will be done separately.
Reviewed By: #libc, ldionne
Differential Revision: https://reviews.llvm.org/D132534
Fabian Parzefall [Wed, 24 Aug 2022 17:03:01 +0000 (10:03 -0700)]
[BOLT] Track fragment info for all split fragments
To generate all symbols correctly, it is necessary to record the address
of each fragment. This patch moves the address info for the main and
cold fragments from BinaryFunction to FunctionFragment, where this data
is recorded for all fragments.
Reviewed By: rafauler
Differential Revision: https://reviews.llvm.org/D132051