15867 Commits

Author SHA1 Message Date
Matt Arsenault
057b3c2452 llvm-reduce: Trim unnecessary includes 2025-03-30 14:59:43 +07:00
Matt Arsenault
a03367fd01 llvm-reduce: Remove trailing whitespace 2025-03-30 12:44:14 +07:00
Kazu Hirata
8db434a481
[bugpoint] Avoid repeated hash lookups (NFC) (#133616) 2025-03-29 22:40:05 -07:00
YLChenZ
fea6b38805
[llvm-reduce]: print short form, actionable names in the log (#133561)
Closes #132696

before the patch like this:
```
----------------------------
*** Reducing GlobalObjects...
----------------------------
*** Reducing GV Initializers...
----------------------------
*** Reducing GlobalVariables...
----------------------------
```
after the patch like this:
```
----------------------------
*** Reducing GlobalObjects (global-objects)...
----------------------------
*** Reducing GV Initializers (global-initializers)...
----------------------------
*** Reducing GlobalVariables (global-variables)...
----------------------------
```
2025-03-30 12:37:48 +07:00
Shilei Tian
847cdd46e5 [NFC][llvm-reduce] Fix an used variable warning in ReduceOperandsToArgs.cpp 2025-03-29 11:39:05 -04:00
Tim Gymnich
0bed72160c
Revert "[NFC] LLVM reduce: remove unused variable" (#133586)
Reverts llvm/llvm-project#133584
2025-03-29 14:59:56 +01:00
Tim Gymnich
9451617d56
[NFC] LLVM reduce: fix unused variable (#133584) 2025-03-29 14:50:55 +01:00
Matt Arsenault
d852cc5311
llvm-reduce: Fix losing call metadata in operands-to-args (#133422) 2025-03-29 16:20:49 +07:00
Matt Arsenault
d3d4a242de
llvm-reduce: Fix losing fast math flags in operands-to-args (#133421) 2025-03-29 16:17:43 +07:00
Matt Arsenault
5b5f40283d
llvm-reduce: Fix losing callsite attributes in operand-to-args (#133420) 2025-03-29 16:14:46 +07:00
Matt Arsenault
5b3e152e16
llvm-reduce: Make run-ir-passes error more consistent (#133564)
Avoid capitalized Error. This loses the "Error constructing pass pipeline"
part, and just forwards the error to the default report_fatal_error case. Not
sure if it's worth trying to keep.
2025-03-29 14:14:09 +07:00
Matt Arsenault
e87bec622c
llvm-reduce: Make some error messages more consistent (#133563)
The coding standards states that error messages should start with
a lowercase. Also use WithColor, and add missing test coverage for
the failed to write to output file case.
2025-03-29 14:10:58 +07:00
Kazu Hirata
d4427f308e
[llvm] Use range constructors of *Set (NFC) (#133549) 2025-03-28 19:55:18 -07:00
Matt Arsenault
8c18c25b1b
llvm-reduce: Do not assert if the input is no longer interesting (#133386)
If the interestingness script is flaky, we should not assert. Print
a warning, and continue. This could still happen as a result of an
llvm-reduce bug, so make a note of that.

Add a --skip-verify-interesting-after-counting-chunks option to
avoid the extra run of the reduction script, and to silence the
warning.
2025-03-29 07:44:20 +07:00
Matt Arsenault
84c1afe69e
llvm-reduce: Simplify instruction reduction to avoid worklist (#133391) 2025-03-29 07:43:36 +07:00
Matt Arsenault
27b53e90a5
llvm-reduce: Use takeName instead of setName when cloning functions (#133393) 2025-03-29 06:53:21 +07:00
Matt Arsenault
8dc64e93cb
llvm-reduce: Avoid double map lookup (#133447) 2025-03-29 06:52:11 +07:00
Matt Arsenault
133c1afa8e
llvm-reduce: Filter function based on uses before removing arguments (#133412)
Invokes and others are not handled, so this was leaving broken callsites
behind for anything other than CallInst
2025-03-29 00:01:14 +07:00
Matt Arsenault
44e3735ac1
llvm-reduce: Preserve original callsite calling conv when removing arguments (#133411)
In undefined mismatch cases, this was fixing the callsite to use the calling
convention of the new function. Preserve the original wrong callsite's calling
convention.
2025-03-28 23:51:09 +07:00
Matt Arsenault
6b1acdb818
llvm-reduce: Fix losing operand bundles when removing arguments (#133410) 2025-03-28 23:41:47 +07:00
Matt Arsenault
115a77df9d
llvm-reduce: Fix losing metadata when removing arguments (#133409) 2025-03-28 23:28:03 +07:00
Matt Arsenault
688df34634
llvm-reduce: Fix losing fast math flags when removing arguments (#133408) 2025-03-28 23:24:49 +07:00
Matt Arsenault
1b86867ab3
llvm-reduce: Fix losing callsite attributes when removing arguments (#133407)
The attribute APIs make this cumbersome. There seem to be missing
overloads using AttrBuilder for the function attrs. Plus there doesn't
seem to be a direct way to set the function attrs on the call.
2025-03-28 23:20:56 +07:00
Matt Arsenault
a33d789bb7
llvm-reduce: Avoid invalid reductions on x86_intrcc (#133396)
If there are arguments, the first one must be byval.
2025-03-28 23:11:28 +07:00
Matt Arsenault
2213872002
llvm-reduce: Use isCallee helper (#133419) 2025-03-28 22:24:42 +07:00
Kazu Hirata
0ae9c65d4a
[tools] Use *Set::insert_range (NFC) (#133384)
We can use *Set::insert_range to replace "for" loop-based insertions.
In some cases, we can further fold insert_range into the set
declaration.
2025-03-28 07:53:09 -07:00
Matt Arsenault
0ed8b27890
llvm-reduce: Avoid removing convergent with convergence tokens (#132946)
Check if the intrinsics are declared in the module as an overly
conservative fix.

Fixes #132695
2025-03-28 12:30:35 +07:00
Alan Zhao
50ea777e40
[opt][timers] Fix time-passes.ll test failing on reversed iterators (#131941)
After https://github.com/llvm/llvm-project/pull/131217 was submitted,
time-passes.ll fails because `opt` prints `-time-report` when
`ManagedTimerGlobals` is destroyed. `ManagedTimerGlobals` stores
`TimerGroup`s in an unordered map, so the ordering of the output
`TimerGroup`s depends on the underlying iterator.

To fix this, we do what Clang does and use
`llvm::TimerGroup::printAll(...)`, which *is* deterministic. This is
also what Clang does. This does put move analysis section before the
pass section for `-time-report`, but again, this is also what Clang
currently does.
2025-03-27 15:31:53 -07:00
Vladislav Dzhidzhoev
bcad050106
[llvm-objdump][ARM] Find ELF file PLT entries for arm, thumb (#130764)
This implements arm, armeb, thumb, thumbeb PLT entries parsing support
in ELF for llvm-objdump.

Implementation is similar to AArch64MCInstrAnalysis::findPltEntries. PLT
entry signatures are based on LLD code for PLT generation
(ARM::writePlt).

llvm-objdump tests are produced from lld/test/ELF/arm-plt-reloc.s,
lld/test/ELF/armv8-thumb-plt-reloc.s.
2025-03-26 20:18:23 +01:00
AnastasiyaChernikova
6ecc67fb32
[Exegesis] CPU selection, when native arch and target mismatch (#131014) 2025-03-26 19:00:06 +03:00
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