15837 Commits

Author SHA1 Message Date
Kazu Hirata
40d251db4a
[llvm] Use *Set::insert_range (NFC) (#133041)
We can use *Set::insert_range to collapse:

  for (auto Elem : Range)
    Set.insert(E);

down to:

  Set.insert_range(Range);

In some cases, we can further fold that into the set declaration.
2025-03-26 07:46:24 -07:00
Julien Villette
f4bb9b53ad
[MCA] Extend -instruction-tables option with verbosity levels (#130574)
Option becomes: -instruction-tables=`<level>`
 
The choice of `<level>` controls number of printed information.
`<level>` may be `none` (default), `normal`, `full`.
Note: If the option is used without `<label>`, default is `normal`
(legacy).

When `<level>` is `full`, additional information are:
- `<Bypass Latency>`: Latency when a bypass is implemented between
operands
  in pipelines (see SchedReadAdvance).
  - `<LLVM Opcode Name>`: mnemonic plus operands identifier.
  - `<Resources units>`: Used resources associated with LLVM Opcode.
- `<instruction comment>`: reports comment if any from source assembly.

Level `full` can be used to better check scheduling info when TableGen
is modified.
LLVM Opcode name help to find right instruction regexp to fix TableGen
Scheduling Info.

-instruction-tables=full option is validated on
AArch64/Neoverse/V1-sve-instructions.s

Follow up of MR #126703

---------

Co-authored-by: Julien Villette <julien.villette@sipearl.com>
2025-03-25 09:19:57 -07:00
Matt Arsenault
37b5f77f8b
llvm-reduce: Fix asserting on TargetExtTypes that do not support zeroinit (#132733)
So far I've been unsuccessful in finding an example where the used constant
value is directly observed in the output. This avoids an assert in an intermediate
step of value replacement.
2025-03-25 11:40:55 +07:00
Matt Arsenault
bfb549ff33
llvm-reduce: Fix operand reduction asserting on target ext types (#132732)
Not all TargetExtTypes support zeroinit, so use poison as a substitute
if unavailable.
2025-03-25 11:38:04 +07:00
Rahul Joshi
eeb4132b8d
[NFC] Fix macro redefinition warning in NewPMDriver.cpp (#132854) 2025-03-24 20:16:48 -07:00
Kazu Hirata
41b76119ec
[llvm] Use range constructors for *Set (NFC) (#132636) 2025-03-23 15:50:34 -07:00
Matt Arsenault
896df5c4bf
llvm-reduce: Fix assert if call type mismatches function type (#131981) 2025-03-22 04:19:25 +07:00
Joseph Huber
bd6df0fe21
Reapply "[LLVM] Make the GPU loader utilities an LLVM tool (#132096)" (#132277)
Summary:
There were a few issues with the first one, leading to some errors and
warnings. Most importantly, this was building on MSVC which isn't
supported.
2025-03-21 11:05:32 -05:00
Kazu Hirata
29e1a7673c
[llvm-exegesis] Avoid repeated hash lookups (NFC) (#132331) 2025-03-21 01:06:25 -07:00
Kazu Hirata
599005686a
[llvm] Use *Set::insert_range (NFC) (#132325)
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently
gained C++23-style insert_range.  This patch replaces:

  Dest.insert(Src.begin(), Src.end());

with:

  Dest.insert_range(Src);

This patch does not touch custom begin like succ_begin for now.
2025-03-20 22:24:06 -07:00
Joseph Huber
df2a56767d Revert "[LLVM] Make the GPU loader utilities an LLVM tool (#132096)"
This reverts commit 221b0117fd21d45098ead779a040a4b939a5c84f.

Some build failures requiring TargetParser and some warnings to clean
up.
2025-03-20 14:26:59 -05:00
Joseph Huber
221b0117fd
[LLVM] Make the GPU loader utilities an LLVM tool (#132096)
Summary:
These tools `amdhsa-loader` and `nvptx-loader` are used to execute unit
tests directly on the GPU. We use this for `libc` and `libcxx` unit
tests as well as general GPU experimentation. It looks like this.

```console
> clang++ main.cpp --target=amdgcn-amd-amdhsa -mcpu=native -flto -lc ./lib/amdgcn-amd-amdhsa/crt1.o
> llvm-gpu-loader a.out
Hello World!
```

Currently these are a part of the `libc` project, but this creates
issues as `libc` itself depends on them to run tests. Right now we get
around this by force-including the `libc` project prior to running the
runtimes build so that this dependency can be built first. We should
instead just make this a simple LLVM tool so it's always available.

This has the effect of installing these by default now instead of just
when `libc` was enabled, but they should be relatively small. Right now
this only supports a 'static' configuration. That is, we locate the CUDA
and HSA dependencies at LLVM compile time. In the future we should be
able to provide this by default using `dlopen` and some API.

I don't know if it's required to reformat all of these names since they
used the `libc` naming convention so I just left it for now.
2025-03-20 14:17:41 -05:00
Akshat Oke
4254f2777c
[CodeGen][NPM] Parse MachineFunctions in NPM driver (#128467)
MachineFunctions were not being parsed when target is allowed to build
the pipeline.

This will allow us to use `-start-before` and other options.
2025-03-20 12:21:43 +05:30
Mingming Liu
d99033e4b4
[LTO][WPD] Suppress WPD on a class if the LTO unit doesn't have the prevailing definition of this class (#131721)
Before this patch, whole program devirtualization is suppressed on a
class if any superclass is visible to regular object files, by recording
the class GUID in `VisibleToRegularObjSymbols`.

This patch suppresses whole program devirtualization on a class if the
LTO unit doesn't have the prevailing definition of this class (e.g., the
prevailing definition is in a shared library)

Implementation summaries:
1. In llvm/lib/LTO/LTO.cpp, `IsVisibleToRegularObj` is updated to look
at the global resolution's `IsPrevailing` bit for ThinLTO and
regularLTO.
2. In llvm/tools/llvm-lto2/llvm-lto2.cpp, 
- three command line options are added so `llvm-lto2` can override
`Conf.HasWholeProgramVisibility`, `Conf.ValidateAllVtablesHaveTypeInfos`
and `Conf.AllVtablesHaveTypeInfos`.
    
The test case is reduced from a small C++ program (main.cc, lib.cc/h
pasted below in [1]). To reproduce the program failure without this
patch, compile lib.cc into a shared library, and provide it to a ThinLTO
build of main.cc (commands are pasted in [2]).

[1]

* lib.h

```
#include <cstdio>

class Derived {
 public:
  void dispatch();
  virtual void print();
  virtual void sum();
};

void Derived::dispatch() {
  static_cast<Derived*>(this)->print();
  static_cast<Derived*>(this)->sum();
}

void Derived::sum() {
  printf("Derived::sum\n");
}

__attribute__((noinline)) void* create(int i);
__attribute__((noinline)) void* getPtr(int i);

```

* lib.cc

```
#include "lib.h"
#include <cstdio>
#include <iostream>

class Derived2 : public Derived {
public:
  void print() override {
    printf("DerivedSharedLib\n");
  }
  void sum() override {
    printf("DerivedSharedLib::sum\n");
  }
};


void Derived::print() {
  printf("Derived\n");
}

__attribute__((noinline)) void* create(int i) {
  if (i & 1)
    return new Derived2();
  return new Derived();
}

```

* main.cc

```
cat main.cc
#include "lib.h"

class DerivedN : public Derived {
 public:
};

__attribute__((noinline)) void* getPtr(int x) {
  return new DerivedN();
}


int main() {
  Derived*b = static_cast<Derived*>(create(201));
  b->dispatch();
  delete b;

  Derived* a = static_cast<Derived*>(getPtr(202));
  a->dispatch();
  delete a;
  return 0;
}

```

[2]
```
# compile lib.o in a shared library.
$ ./bin/clang++ -O2 -fPIC -c lib.cc -o lib.o
$ ./bin/clang++ -shared -o libdata.so lib.o

# Provide the shared library in `-ldata`
$ ./bin/clang++ -v -g -ldata --save-temps -fno-discard-value-names -Wl,-mllvm,-print-before=wholeprogramdevirt -Wl,-mllvm,-wholeprogramdevirt-check=trap -Rpass=wholeprogramdevirt -Wl,--lto-whole-program-visibility -Wl,--lto-validate-all-vtables-have-type-infos -mllvm -disable-icp=true -Wl,-mllvm,-disable-icp=false -flto=thin -fwhole-program-vtables  -fno-split-lto-unit -fuse-ld=lld   main.cc  -L . -o main >/tmp/wholeprogramdevirt.ir 2>&1

# Run the program hits a segmentation fault with  `-Wl,-mllvm,-wholeprogramdevirt-check=trap`

$ LD_LIBRARY_PATH=. ./main
DerivedSharedLib
Trace/breakpoint trap (core dumped)

```
2025-03-19 22:10:57 -07:00
Eric Astor
3c657ceef9
[ms] [llvm-ml] Add llvm-ml64 alias (#131854)
Rather than requiring users to pass `-m64` to the `llvm-ml` driver to
get 64-bit behavior, we add the `llvm-ml64` alias, matching the behavior
of `ML.EXE` and `ML64.EXE`.

The original flavor/bitness flags still work, but the alias should make
some workflows easier.

NOTE: The logic for this already existed in the code; we're just finally
adding the build/install instructions to match.
2025-03-19 15:02:17 -04:00
Matt Arsenault
8249492374 llvm-reduce: Remove redundant casts to InvokeInst 2025-03-19 14:32:28 +07:00
Fangrui Song
b5ef33b3b9 [llvm-objdump] Delete unused variables after #128434 2025-03-18 23:48:55 -07:00
Cyndy Ishida
4e4e4a190f
[TextAPI] Track RPaths in the order its provided via command line. (#131665)
RPaths are basically search paths for how to load dependent libraries.
The order they appear is the order the linker will search, we should
preserve that order in tbd files.

* Additionally add this level of detection to llvm-readtapi.

resolves: rdar://145603347
2025-03-18 22:12:45 -07:00
Matt Arsenault
d43b4ede66
llvm-reduce: Do not remove appending linkage from intrinsic globals (#131713) 2025-03-18 23:51:36 +07:00
Vladislav Dzhidzhoev
84e44ae6b7
[llvm-objdump] Pass MCSubtargetInfo to findPltEntries (NFC) (#131773)
It allows access to subtarget features, collected in llvm-objdump.cpp,
from findPltEntries, which will be used in
https://github.com/llvm/llvm-project/pull/130764.
2025-03-18 14:00:34 +01:00
Zequan Wu
6dbe82f061
[NFC][DebugInfo] Wrap DILineInfo return type with std::optional to handle missing debug info. (#129792)
Currently, `DIContext::getLineInfoForAddress` and
`DIContext::getLineInfoForDataAddress` returns empty DILineInfo when the
debug info is missing for the given address. This is not differentiable
with the case when debug info is found for the given address but the
debug info is default value (filename:linenum is <invalid>:0).

This change wraps the return types of `DIContext::getLineInfoForAddress`
and `DIContext::getLineInfoForDataAddress` with `std::optional`.
2025-03-17 17:01:06 -04:00
Craig Topper
b00ad36632
[RISCV] Use hasFeature instead of checkFeature in llvm-exegesis. NFC (#131401)
Until recently checkFeature was quite slow. #130936

I was curious where we use checkFeature and noticed these. I thought we
could use hasFeature instead of going through strings.
2025-03-17 09:05:09 -07:00
Akshat Oke
baab447aad
[llc] Report error in lieu of warning for invalid cl option (#128846) 2025-03-17 11:24:54 +05:30
Jeremy Morse
792a6f8119
[RemoveDIs] Remove "try-debuginfo-iterators..." test flags (#130298)
These date back to when the non-intrinsic format of variable locations
was still being tested and was behind a compile-time flag, so not all
builds / bots would correctly run them. The solution at the time, to get
at least some test coverage, was to have tests opt-in to non-intrinsic
debug-info if it was built into LLVM.

Nowadays, non-intrinsic format is the default and has been on for more
than a year, there's no need for this flag to exist.

(I've downgraded the flag from "try" to explicitly requesting
non-intrinsic format in some places, so that we can deal with tests that
are explicitly about non-intrinsic format in their own commit).
2025-03-14 15:50:49 +00:00
Kazu Hirata
19b25a4524
[dsymutil] Avoid repeated hash lookups (NFC) (#131268) 2025-03-14 07:22:44 -07:00
Frederik Harwath
6962cf1700
Rename ExpandLargeFpConvertPass to ExpandFpPass (#131128)
This is meant as a preparation for PR #130988 "[AMDGPU] Implement IR
expansion for frem instruction" which implements the expansion of
another instruction in this pass. The more general name seems more
appropriate given this change and quite reasonable even without it.
2025-03-14 13:11:45 +01:00
Bertik23
b67379c35b
[llvm-diff] Add colorful output to diff (#131012)
Adds colorful output when when possible to the diff. Adds a use to the
`--color` option llvm-diff has.
2025-03-13 14:26:42 +01:00
Nikita Popov
f137c3d592
[TargetRegistry] Accept Triple in createTargetMachine() (NFC) (#130940)
This avoids doing a Triple -> std::string -> Triple round trip in lots
of places, now that the Module stores a Triple.
2025-03-12 17:35:09 +01:00
Lang Hames
76d5a79bed
[ORC] Drop EHFrameRegistrar, register eh-frames with AllocActions (#130719)
This simplifies resource management, and should improve performance for most use
cases.
2025-03-12 10:02:30 +11:00
Kazu Hirata
f33dca41a3
[llvm-rtdyld] Avoid repeated hash lookups (NFC) (#130711) 2025-03-11 07:34:27 -07:00
lakshayk-nv
9cc477be6e
[llvm-exegesis][AArch64] Handle register classes FPR8/16/32 and FPCR (#130595)
Current implementation (for AArch64) only supports the GRP32, GPR64,
FPR64/128, PPR16 and ZPR128 register classes. This adds support for
the other floating point register classes to initialize registers and avoid
the "setReg is not implemented" warning for these cases.
2025-03-11 13:47:16 +00:00
Joseph Huber
e3bef37971 Revert "[offload][SYCL] Add SYCL Module splitting (#119713)"
This reverts commit bfeea10460d155d9b3484bed25b5dc60a9755c90.
2025-03-11 08:40:01 -05:00
Maksim Sabianin
bfeea10460
[offload][SYCL] Add SYCL Module splitting (#119713)
This patch adds SYCL Module splitting - the necessary step in the SYCL
compilation pipeline. Only 2 splitting modes are being added in this
patch: by kernel and by source.
2025-03-11 08:36:37 -05:00
SivanShani-Arm
b1ebfac185
[readobj][Arm][AArch64] Refactor Build Attributes parsing under ELFAtributeParser and add support for AArch64 Build Attributes (#128727)
Refactor readobj to integrate AArch64 Build Attributes under
ELFAttributeParser. ELFAttributeParser now serves as a base class for:
- ELFCompactAttrParser, handling Arm-style attributes with a single
build attribute subsection.
- ELFExtendedAttrParser, handling AArch64-style attributes with multiple
build attribute subsections. This improves code organization and better
aligns with the attribute parsing model.

Add support for parsing AArch64 Build Attributes.
2025-03-10 09:48:40 +00:00
Ruoyu Qiu
82f2b66110
[llvm-objdump][ELF]Fix crash when reading strings from .dynstr (#125679)
This change introduces a check for the strtab offset to prevent
llvm-objdump from crashing when processing malformed ELF files.
It provide a minimal reproduce test for
https://github.com/llvm/llvm-project/issues/86612#issuecomment-2035694455.
Additionally, it modifies how llvm-objdump handles and outputs malformed
ELF files with invalid string offsets.(More info:
https://discourse.llvm.org/t/should-llvm-objdump-objdump-display-actual-corrupted-values-in-malformed-elf-files/84391)

Fixes: #86612

Co-authored-by: James Henderson <James.Henderson@sony.com>
2025-03-09 19:39:58 -07:00
Kazu Hirata
99d2b3b0aa
[llvm-profgen] Avoid repeated hash lookups (NFC) (#130466) 2025-03-09 00:49:37 -08:00
Kazu Hirata
573df34ea0
[llvm-jitlink] Avoid repeated hash lookups (NFC) (#130465) 2025-03-09 00:49:13 -08:00
Douglas Yung
1d763f3833 Revert "Modify the localCache API to require an explicit commit on CachedFile… (#115331)"
This reverts commit ce9e1d3c15ed6290f1cb07b482939976fa8115cd.

The unittest added in this commit seems to be flaky causing random failure on buildbots:
 - https://lab.llvm.org/buildbot/#/builders/46/builds/13235
 - https://lab.llvm.org/buildbot/#/builders/46/builds/13232
 - https://lab.llvm.org/buildbot/#/builders/46/builds/13228
 - https://lab.llvm.org/buildbot/#/builders/46/builds/13224
 - https://lab.llvm.org/buildbot/#/builders/46/builds/13220
 - https://lab.llvm.org/buildbot/#/builders/46/builds/13210
 - https://lab.llvm.org/buildbot/#/builders/46/builds/13208
 - https://lab.llvm.org/buildbot/#/builders/46/builds/13207
 - https://lab.llvm.org/buildbot/#/builders/46/builds/13202
 - https://lab.llvm.org/buildbot/#/builders/46/builds/13196
and
 - https://lab.llvm.org/buildbot/#/builders/180/builds/14266
 - https://lab.llvm.org/buildbot/#/builders/180/builds/14254
 - https://lab.llvm.org/buildbot/#/builders/180/builds/14250
 - https://lab.llvm.org/buildbot/#/builders/180/builds/14245
 - https://lab.llvm.org/buildbot/#/builders/180/builds/14244
 - https://lab.llvm.org/buildbot/#/builders/180/builds/14226
2025-03-08 23:54:57 +00:00
Douglas Yung
49e585f4c4 Revert "[gold] Fix compilation (#130334)"
This reverts commit b0baa1d8bd68a2ce2f7c5f2b62333e410e9122a1.

Reverting follow-up commit to ce9e1d3c15ed6290f1cb07b482939976fa8115cd since the original commit test is flaky.
2025-03-08 23:53:38 +00:00
Peter Jung
3ac24236aa
[llvm-profdata] Fix typo in llvm-profdata (#114675)
Signed-off-by: Peter Jung <admin@ptr1337.dev>
2025-03-08 18:52:24 +00:00
Vitaly Buka
b0baa1d8bd
[gold] Fix compilation (#130334)
After #115331.
2025-03-07 12:06:03 -08:00
anjenner
ce9e1d3c15
Modify the localCache API to require an explicit commit on CachedFile… (#115331)
…Stream.

CachedFileStream has previously performed the commit step in its
destructor, but this means its only recourse for error handling is
report_fatal_error. Modify this to add an explicit commit() method, and
call this in the appropriate places with appropriate error handling for
the location.

Currently the destructor of CacheStream gives an assert failure in Debug
builds if commit() was not called. This will help track down any
remaining uses of the API that assume the old destructior behaviour. In
Release builds we fall back to the previous behaviour and call
report_fatal_error if the commit fails.
2025-03-07 17:58:36 +00:00
Zentrik
d7f409d39a
[JITListener] Fix build after Module::getTargetTriple() change (#130152)
Adjust for #129868.
2025-03-07 09:37:19 +01:00
Tejas Vipin
bd5f29c008
[llvm-strip] Let llvm-strip continue on encountering an error (#129531)
This change means that llvm-strip no longer exits immediately upon
encountering an error when modifying a file and will instead continue
modifying the other inputs. Fixes #129412
2025-03-07 08:34:29 +00:00
Daniel Paoliello
16e051f0b9
[win] NFC: Rename EHCatchret to EHCont to allow for EH Continuation targets that aren't catchret instructions (#129953)
This change splits out the renaming and comment updates from #129612 as a non-functional change.
2025-03-06 09:28:44 -08:00
Kazu Hirata
92dfc0ffc3
[llvm-jitlink] Avoid repeated hash lookups (NFC) (#129993) 2025-03-06 08:50:21 -08:00
Kazu Hirata
abcab4f7ba
[llvm-dwarfdump] Avoid repeated hash lookups (NFC) (#129991) 2025-03-06 08:50:00 -08:00
Nikita Popov
f7c0f33d6f [lto] Add TargetParser dependency
To fix the shared libs build after #129868.
2025-03-06 11:01:17 +01:00
Nikita Popov
979c275097
[IR] Store Triple in Module (NFC) (#129868)
The module currently stores the target triple as a string. This means
that any code that wants to actually use the triple first has to
instantiate a Triple, which is somewhat expensive. The change in #121652
caused a moderate compile-time regression due to this. While it would be
easy enough to work around, I think that architecturally, it makes more
sense to store the parsed Triple in the module, so that it can always be
directly queried.

For this change, I've opted not to add any magic conversions between
std::string and Triple for backwards-compatibilty purses, and instead
write out needed Triple()s or str()s explicitly. This is because I think
a decent number of them should be changed to work on Triple as well, to
avoid unnecessary conversions back and forth.

The only interesting part in this patch is that the default triple is
Triple("") instead of Triple() to preserve existing behavior. The former
defaults to using the ELF object format instead of unknown object
format. We should fix that as well.
2025-03-06 10:27:47 +01:00
lakshayk-nv
d61d219739
Adding support in llvm-exegesis for Aarch64 for handling FPR64/128, PPR16 and ZPR128 reg class. (#127564)
Current implementation (for Aarch64) in llvm-exegesis only supports
GRP32 and GPR64 bit register class, thus for opcodes variants which used
FPR64/128, PPR16 and ZPR128, llvm-exegesis throws warning "setReg is not
implemented". This code will handle the above register class and
initialize the registers using appropriate base instruction class.
2025-03-06 09:02:54 +00:00