68 Commits

Author SHA1 Message Date
Matt Arsenault
3a8081cedc
AMDGPU: Stop checking for r600 in printf pass (#183536)
Avoid adding the pass to the pipeline in the first place.
2026-02-26 17:18:36 +01:00
Steffen Larsen
6cbefe0016
[AMDGPU] Skip printf runtime binding if function signature is unexpected (#177573)
When creating the binding for OpenCL printf calls, we expect the
signature of the function to match the OpenCL specification. If the
signature is unexpected, this patch makes the pass skip creating the
binding to avoid incorrect behavior and crashes.

---------

Signed-off-by: Steffen Holst Larsen <HolstLarsen.Steffen@amd.com>
Co-authored-by: Steffen Holst Larsen <HolstLarsen.Steffen@amd.com>
2026-01-28 10:22:32 +00:00
Steffen Larsen
7e25a3132f
[AMDGPU] Fix use-after-erase in OpenCL printf runtime binding (#177356)
When handling OpenCL printf calls, the AMDGPU backend replaces the
actual function call with a runtime binding. However, this replacement
currently assumes that there are no uses of the original call value
result. If there are uses, the erasure of the function call leads to
errors.
This patch replaces all uses of the original printf call with a 0 value
constant, signalling success of the printf operation.

---------

Signed-off-by: Steffen Holst Larsen <HolstLarsen.Steffen@amd.com>
Co-authored-by: Steffen Holst Larsen <HolstLarsen.Steffen@amd.com>
2026-01-23 09:02:56 +01:00
Jay Foad
72c69aefba
[AMDGPU] Make use of getFunction and getMF. NFC. (#167872) 2025-11-14 11:00:57 +00:00
Vikram Hegde
de551c6403
[AMDGPU] Support 'F' and 'A' conversion specifiers with ocl printf (#148784)
Runtime support in progress downstream..
2025-07-15 13:24:08 +05:30
Justin Bogner
b7bb256703
Warn on misuse of DiagnosticInfo classes that hold Twines (#137397)
This annotates the `Twine` passed to the constructors of the various
DiagnosticInfo subclasses with `[[clang::lifetimebound]]`, which causes
us to warn when we would try to print the twine after it had already
been destructed.

We also update `DiagnosticInfoUnsupported` to hold a `const Twine &`
like all of the other DiagnosticInfo classes, since this warning allows
us to clean up all of the places where it was being used incorrectly.
2025-05-28 12:26:39 -07:00
Rahul Joshi
a3754ade63
[NFC][LLVM][AMDGPU] Cleanup pass initialization for AMDGPU (#134410)
- Remove calls to pass initialization from pass constructors.
- https://github.com/llvm/llvm-project/issues/111767
2025-04-07 17:27:50 -07:00
Mats Jun Larsen
416f1c465d
[IR] Replace of PointerType::get(Type) with opaque version (NFC) (#123617)
In accordance with https://github.com/llvm/llvm-project/issues/123569

In order to keep the patch at reasonable size, this PR only covers for
the llvm subproject, unittests excluded.
2025-01-21 00:32:56 +09:00
Jay Foad
8d13e7b8c3
[AMDGPU] Qualify auto. NFC. (#110878)
Generated automatically with:
$ clang-tidy -fix -checks=-*,llvm-qualified-auto $(find
lib/Target/AMDGPU/ -type f)
2024-10-03 13:07:54 +01:00
Joseph Huber
dbb8b7a0f4 Reapply "[OpenMP][libc] Remove special handling for OpenMP printf (#98940)"
This reverts commit fea5914c926e2f013a8b5e27eaa74c7047fb2c71.
2024-07-26 17:21:56 -05:00
Joseph Huber
fea5914c92 Revert "[OpenMP][libc] Remove special handling for OpenMP printf (#98940)"
This reverts commit 069e8bcd82c4420239f95c7e6a09e1f756317cfc.

Summary:
Some tests failing, revert this for now.
2024-07-26 16:39:12 -05:00
Joseph Huber
069e8bcd82
[OpenMP][libc] Remove special handling for OpenMP printf (#98940)
Summary:
Currently there are several layers to handle `printf`. Since we now have
varargs and an implementation of `printf` this can be heavily
simplified.

1. The frontend renames `printf` into `omp_vprintf` and gives it an
   argument buffer.

Removing 1. triggered some code in the AMDGPU backend menat for HIP /
OpenCL, so I hadded an exception to it.

2. Forward this to CUDA vprintf or ignore it.

We no longer need special handling for it since we have varargs. So now
we just forward this to CUDA vprintf if we have libc, otherwise just
leave `printf` as an external function and expect that `libc` will be
linked in.
2024-07-26 16:03:36 -05:00
Jay Foad
0b43d573f5 [AMDGPU] clang-tidy: replace macro with enum. NFC. 2024-07-16 16:37:34 +01:00
Jay Foad
63a1242ae3 [AMDGPU] clang-tidy: define trivial constructors with = default. NFC. 2024-07-16 15:41:54 +01:00
Nikita Popov
74deadf196
[IRBuilder] Don't include Module.h (NFC) (#97159)
This used to be necessary to fetch the DataLayout, but isn't anymore.
2024-06-29 15:05:04 +02:00
Jeremy Morse
b9d83eff25
[NFC][RemoveDIs] Use iterators for insertion at various call-sites (#84736)
These are the last remaining "trivial" changes to passes that use
Instruction pointers for insertion. All of this should be NFC, it's just
changing the spelling of how we identify a position.

In one or two locations, I'm also switching uses of getNextNode etc to
using std::next with iterators. This too should be NFC.

---------

Merged by: Stephen Tozer <stephen.tozer@sony.com>
2024-03-19 16:36:29 +00:00
serge-sans-paille
33b51588c5
Replace usage of StringRef::find_last_of with a string literal of size one by the equivalent char literal 2023-11-15 15:01:36 +01:00
Joseph Huber
8a20612467 [AMDGPU] Respect nobuiltin when converting printf
The AMDGPU backend uses a pass to transform calls to the `printf`
function to a built-in verision for either HIP or OpenCL. Currently this
does not respect `-fno-builtin` and is always emitted. This allows the
user to turn off this functionality as is standard for these types of
built-in transformations. The motivation behind this change is to allow
the `libc` project to provide a linkable version of the `printf`
function in the future.

Reviewed By: sameerds

Differential Revision: https://reviews.llvm.org/D158477
2023-08-22 12:48:16 -05:00
Matt Arsenault
94e24624c2 AMDGPU: Remove attempt at simplifying the format string in printf lowering
This avoids computing the dominator tree by removing the
simplifyInstruction use.

This was applying simplification with some kind of questionable
load-store forwarding and looking for the global. This had to have
been an ancient hack copied from previous backends. In the OpenCL
case, this is always emitted as required the direct global reference
anyway.
2023-07-07 09:26:07 -04:00
Elliot Goodrich
b0abd4893f [llvm] Add missing StringExtras.h includes
In preparation for removing the `#include "llvm/ADT/StringExtras.h"`
from the header to source file of `llvm/Support/Error.h`, first add in
all the missing includes that were previously included transitively
through this header.
2023-06-25 15:42:22 +01:00
Archibald Elliott
62c7f035b4 [NFC][TargetParser] Remove llvm/ADT/Triple.h
I also ran `git clang-format` to get the headers in the right order for
the new location, which has changed the order of other headers in two
files.
2023-02-07 12:39:46 +00:00
Matt Arsenault
68d4656722 AMDGPU: Don't insert pointer bitcasts for printf lowering
Cleanup leftover typed pointer handling.
2023-01-28 21:49:10 -04:00
Matt Arsenault
0d87732a1f AMDGPU: Use getConstantStringInfo for printf format strings
Tolerated printf format strings that are indexed globals and fixes
asserting on non-null terminated strings.
2023-01-13 14:11:37 -05:00
Matt Arsenault
39af5cec8b AMDGPU: Fix format string indexes for existing llvm.printf.fmts
The index stored to the buffer is just an index into this named
metadata. It would more robust to produce a private constant table,
and use a constant expression to index into it.
2023-01-13 13:18:27 -05:00
Matt Arsenault
0e7a83f502 AMDGPU: Don't expand printf users if printf is defined 2023-01-13 12:32:04 -05:00
Nemanja Ivanovic
356c71830c [AMDGPU] Fix big endian bots after 7c327c2
The pass that this test case is testing has host-endianness
dependencies. This fixes the pertinent one causing failures
on BE bots.
2023-01-10 13:15:37 -06:00
Matt Arsenault
4682039db0 AMDGPU: Don't assert on printf of half
The comment says fields should be 4-byte aligned, so just pass through
after conversion to integer. The conformance test lacks any testing of
half.
2023-01-10 14:13:23 -05:00
Matt Arsenault
fdda800ba3 AMDGPU: Fix opaque pointer and other bugs in printf of constant strings
Strip pointer casts to get to the global. Fixes not respecting indexed
constant strings. Tolerate non-null terminated and empty strings.
2023-01-10 13:39:44 -05:00
Matt Arsenault
d8534e4e98 AMDGPU: Don't insert ptrtoint for printf lowering 2023-01-10 13:07:01 -05:00
Matt Arsenault
777b905bae AMDGPU: Stop trying to specially handle vector stores in printf lowering
This was broken for 1 element vectors and trying to create invalid
casts. We can directly store any type just fine, so don't bother with
this buggy conversion logic.
2023-01-10 13:07:01 -05:00
Matt Arsenault
925aa514ed AMDGPU: Use DataExtractor for printf string extraction
Attempt 2 to fix big endian bot failures.
2023-01-09 14:03:42 -05:00
Matt Arsenault
68b6cabd9e AMDGPU: Use getTypeAllocSize 2023-01-06 21:33:19 -05:00
Matt Arsenault
0995a31e5d AMDGPU: Try to fix 32-bit build bot 2023-01-06 17:34:25 -05:00
Matt Arsenault
40078a6b71 AMDGPU: Use BinaryByteStream in printf expansion
Attempt to fix test failures on big endian bots. This pass definitely
needs more test coverage.
2023-01-06 17:22:13 -05:00
Matt Arsenault
7c327c2fbb AMDGPU: Fix broken opaque pointer handling in printf pass
This was directly considering the pointee type, and also applying
special semantics to constant address space.
2023-01-05 13:48:32 -05:00
Matt Arsenault
7b922fc0c3 AMDGPU: Fix broken and permissive handling of printf format strings
This was completely broken with opaque pointers because it was
specifically looking for a constant expression with the global
variable as the first operand. Strip casts like normal, and properly
validate all of the restrictions rather than silently ignoring any
unhandled cases. Also be stricter that we aren't calling into some
unresolved or non-constant format string.

Also converts the test to opaque pointers and generated tests. There's
more broken initializer handling for strings inside the format string
processing too, but there's just no test coverage for this at all.
2023-01-05 09:18:00 -05:00
Ron Lieberman
750e1c8dbd Revert "[libomptarget][plugin-nextgen] fix for [TypePromotion] NewPM support."
This reverts commit 135f6a1ee8b20bb392ebad2fa5aef78e3a30ddb4.
2023-01-03 12:26:39 -06:00
Ron Lieberman
135f6a1ee8 [libomptarget][plugin-nextgen] fix for [TypePromotion] NewPM support. 2023-01-03 11:04:13 -06:00
Matt Arsenault
888228f2b0 AMDGPU: Use early continue to reduce indentation 2022-12-22 12:38:59 -05:00
Kazu Hirata
9861a68a7c [Target] Qualify auto in range-based for loops (NFC) 2022-08-28 10:41:50 -07:00
Simon Moll
b8c2781ff6 [NFC] format InstructionSimplify & lowerCaseFunctionNames
Clang-format InstructionSimplify and convert all "FunctionName"s to
"functionName".  This patch does touch a lot of files but gets done with
the cleanup of InstructionSimplify in one commit.

This is the alternative to the less invasive clang-format only patch: D126783

Reviewed By: spatel, rengolin

Differential Revision: https://reviews.llvm.org/D126889
2022-06-09 16:10:08 +02:00
Scott Linder
09f33a430b [AMDGPU][OpenCL] Remove "printf and hostcall" diagnostic
The diagnostic is unreliable, and triggers even for dead uses of
hostcall that may exist when linking the device-libs at lower
optimization levels.

Eliminate the diagnostic, and directly document the limitation for
OpenCL before code object V5.

Make some NFC changes to clarify the related code in the
MetadataStreamer.

Add a clang test to tie OCL sources containing printf to the backend IR
tests for this situation.

Reviewed By: sameerds, arsenm, yaxunl

Differential Revision: https://reviews.llvm.org/D121951
2022-04-05 19:10:23 +00:00
serge-sans-paille
ffe8720aa0 Reduce dependencies on llvm/BinaryFormat/Dwarf.h
This header is very large (3M Lines once expended) and was included in location
where dwarf-specific information were not needed.

More specifically, this commit suppresses the dependencies on
llvm/BinaryFormat/Dwarf.h in two headers: llvm/IR/IRBuilder.h and
llvm/IR/DebugInfoMetadata.h. As these headers (esp. the former) are widely used,
this has a decent impact on number of preprocessed lines generated during
compilation of LLVM, as showcased below.

This is achieved by moving some definitions back to the .cpp file, no
performance impact implied[0].

As a consequence of that patch, downstream user may need to manually some extra
files:

llvm/IR/IRBuilder.h no longer includes llvm/BinaryFormat/Dwarf.h
llvm/IR/DebugInfoMetadata.h no longer includes llvm/BinaryFormat/Dwarf.h

In some situations, codes maybe relying on the fact that
llvm/BinaryFormat/Dwarf.h was including llvm/ADT/Triple.h, this hidden
dependency now needs to be explicit.

$ clang++ -E  -Iinclude -I../llvm/include ../llvm/lib/Transforms/Scalar/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l
after:   10978519
before:  11245451

Related Discourse thread: https://llvm.discourse.group/t/include-what-you-use-include-cleanup
[0] https://llvm-compile-time-tracker.com/compare.php?from=fa7145dfbf94cb93b1c3e610582c495cb806569b&to=995d3e326ee1d9489145e20762c65465a9caeab4&stat=instructions

Differential Revision: https://reviews.llvm.org/D118781
2022-02-04 11:44:03 +01:00
Kazu Hirata
5a667c0e74 [llvm] Use nullptr instead of 0 (NFC)
Identified with modernize-use-nullptr.
2021-12-28 08:52:25 -08:00
Kazu Hirata
262dd1e42d [llvm] Use range-based for loops (NFC) 2021-12-02 09:27:47 -08:00
Kazu Hirata
c1e32b3fc0 [Target] Migrate from getNumArgOperands to arg_size (NFC)
Note that getNumArgOperands is considered a legacy name.  See
llvm/include/llvm/IR/InstrTypes.h for details.
2021-10-02 12:06:29 -07:00
Jacob Lambert
dc6e8dfdfe [AMDGPU][NFC] Correct typos in lib/Target/AMDGPU/AMDGPU*.cpp files. Test commit for new contributor. 2021-09-20 14:48:50 -07:00
Kazu Hirata
c50faffb4e [llvm] Remove redundant calls to str() and c_str() (NFC)
Identified with readability-redundant-string-cstr.
2021-08-30 09:05:05 -07:00
Nikita Popov
9e225a2a71 [AMDGPU] Simplify GEP construction (NFC)
Noticed while making a related change. This code was doing
something really peculiar: Creating an APInt by parsing a string.
And then creating a SmallVector with one element to create the
GEP.

Instead create the APInt from integers and directly pass the single
index to GetElementPtrInst::Create().
2021-07-08 21:21:43 +02:00
Nikita Popov
cfb94212d4 [AMDGPU] Pass explicit GEP type in printf transform (NFC)
This code is working on an i8*. Avoid nullptr element type in
preparation for removing support.
2021-07-08 21:21:43 +02:00