32 Commits

Author SHA1 Message Date
Tim Besard
49b57df161
DXIL: Use correct type ID when writing ValueAsMetadata. (#94337)
When emitting references to functions as part of `ValueAsMetadata`,
we currently emit the incorrect (typed) pointer, resulting in
crashes during deserialization. Avoid this by correctly mapping the
type during serialization.
2024-09-11 14:38:56 +02:00
James Y Knight
dfeb3991fb
Remove the x86_mmx IR type. (#98505)
It is now translated to `<1 x i64>`, which allows the removal of a bunch
of special casing.

This _incompatibly_ changes the ABI of any LLVM IR function with
`x86_mmx` arguments or returns: instead of passing in mmx registers,
they will now be passed via integer registers. However, the real-world
incompatibility caused by this is expected to be minimal, because Clang
never uses the x86_mmx type -- it lowers `__m64` to either `<1 x i64>`
or `double`, depending on ABI.

This change does _not_ eliminate the SelectionDAG `MVT::x86mmx` type.
That type simply no longer corresponds to an IR type, and is used only
by MMX intrinsics and inline-asm operands.

Because SelectionDAGBuilder only knows how to generate the
operands/results of intrinsics based on the IR type, it thus now
generates the intrinsics with the type MVT::v1i64, instead of
MVT::x86mmx. We need to fix this before the DAG LegalizeTypes, and thus
have the X86 backend fix them up in DAGCombine. (This may be a
short-lived hack, if all the MMX intrinsics can be removed in upcoming
changes.)

Works towards issue #98272.
2024-07-25 09:19:22 -04:00
Justin Bogner
c6e96a2605 [DirectX] Update for removal of icmp and fcmp constant expressions
The icmp and fcmp constant expressions were removed in deab451e7a7f
"[IR] Remove support for icmp and fcmp constant expressions (#93038)".
Update the DXILBitcodeWriter to stop referencing them.
2024-06-04 12:22:07 -07:00
Fangrui Song
c4dad9a6b6 [DirectX] Fix BitcodeWriter ctor after #92983 2024-05-30 14:22:50 -07:00
Jay Foad
1650f1b3d7
Fix typo "indicies" (#92232) 2024-05-15 13:10:16 +01:00
Kazu Hirata
af8d050286 [Target] Use range-based for loops (NFC) 2023-12-24 23:09:55 -08:00
Justin Bogner
d7f3b238fd [DXILBitcodeWriter] Fix handling of an unspecified lower bound in DISubrange
If the lower bound isn't specified it implies that it's zero.

Differential Revision: https://reviews.llvm.org/D158441
2023-08-21 14:30:45 -07:00
Justin Bogner
48e0a6f902 [DXILBitcodeWriter] Don't create a new abbrev per MDString
We were running out of abbrevs and crashing if there were more than 20
something strings in metadata, which turned out to be a bug where we
created an abbrev every time we emitted a string rather than just one
for the string table.

Differential Revision: https://reviews.llvm.org/D158440
2023-08-21 13:58:38 -07:00
Justin Bogner
245073ac80 [DirectX] Remove uses of isOpaquePointerTy(). NFC
isOpaquePointerTy now returns true for all pointers, so we can replace
these with isPointerTy().
2023-07-19 14:28:05 -07: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
Xiang Li
e3becfacfd [DirectX backend] Remove unused bitcode block for dxil
DXIL doesn't need uselist strtab and symtab blocks which are not supported  by llvm3.7 bitcode.

Differential Revision: https://reviews.llvm.org/D141328
2023-01-09 19:06:33 -05:00
Joshua Cranmer
aa34a9d108 Add TargetExtTyID to switch statements in Hexagon and DXIL backend code. 2022-12-20 11:48:35 -05:00
Alex Richardson
f7ae55f03d [DirectX] Fix shared libraries build
I just tried to build all experimental targets and noticed that DirectX did
not build with -DBUILD_SHARED_LIBS=ON.

Differential Revision: https://reviews.llvm.org/D138431
2022-12-01 16:53:42 +00:00
Xiang Li
ad68c66a38 [DirectX backend] Fix build and test error caused by out of sync with upstream change.
Fix build and test error caused by
a2620e00ff#
and
304f1d59ca

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D137815
2022-11-14 12:50:23 -08:00
Xiang Li
a80a888de5 [DirectX backend] Support global ctor for DXILBitcodeWriter.
1. Save typed pointer type for GlobalVariable/Function instead of the ObjectType.
   This will allow use GlobalVariable/Function as value.
2. Save target type for global ctors for Constant.
3. In DXILBitcodeWriter::getTypeID, check PointerMap first for Constant case.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D133283
2022-09-30 11:27:23 -07:00
Chris Bieneman
5d4dd53570 Revert "[DirectX backend] Support global ctor for DXILBitcodeWriter."
This reverts commit 26129766df701d462ed9a6a9a68a88b3564a70bd.

The reverted commit broke in-tree unit tests for the DirectX backend.
2022-09-29 11:58:27 -05:00
Xiang Li
26129766df [DirectX backend] Support global ctor for DXILBitcodeWriter.
1. Save typed pointer type for GlobalVariable/Function instead of the ObjectType.
   This will allow use GlobalVariable/Function as value.
2. Save target type for global ctors for Constant.
3. In DXILBitcodeWriter::getTypeID, check PointerMap first for Constant case.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D133283
2022-09-28 13:23:56 -07:00
Chris Bieneman
eebf84c5b3 [DirectX] Remove broken assert
This assert always fails. It is unclear to me what it was attempting to
test, but removing it gets our tests passing, so it clearly isn't
checking the right thing.
2022-08-22 17:25:16 -05:00
Chris Bieneman
4579a0224c [NFC] Fix warning in asserts build
When asserts are enabled a warning for implicit conversion from 64-bit to
32-bit integer occurs here.
2022-08-19 17:48:22 -05:00
Xiang Li
dfde731df7 [DirectX] Fix crash on ShuffleVectorInst in DXILBitcodeWriter
Use onstantDataSequential::getElementType to allow vector type.

Use getShuffleMaskForBitcode to get ShuffleMask.

Use old format for alloca Align.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D132102
2022-08-18 23:46:20 -07:00
Joshua Cranmer
2138c90645 [IR] Move support for dxil::TypedPointerType to LLVM core IR.
This allows the construct to be shared between different backends. However, it
still remains illegal to use TypedPointerType in LLVM IR--the type is intended
to remain an auxiliary type, not a real LLVM type. So no support is provided for
LLVM-C, nor bitcode, nor LLVM assembly (besides the bare minimum needed to make
Type->dump() work properly).

Reviewed By: beanz, nikic, aeubanks

Differential Revision: https://reviews.llvm.org/D130592
2022-08-04 10:41:11 -04:00
Dmitri Gribenko
aba43035bd Use llvm::sort instead of std::sort where possible
llvm::sort is beneficial even when we use the iterator-based overload,
since it can optionally shuffle the elements (to detect
non-determinism). However llvm::sort is not usable everywhere, for
example, in compiler-rt.

Reviewed By: nhaehnle

Differential Revision: https://reviews.llvm.org/D130406
2022-07-23 15:19:05 +02:00
Shilei Tian
1023ddaf77 [LLVM] Add the support for fmax and fmin in atomicrmw instruction
This patch adds the support for `fmax` and `fmin` operations in `atomicrmw`
instruction. For now (at least in this patch), the instruction will be expanded
to CAS loop. There are already a couple of targets supporting the feature. I'll
create another patch(es) to enable them accordingly.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D127041
2022-07-06 10:57:53 -04:00
Chris Bieneman
c967c3d39b [DirectX] Properly fix for MaybeAlign API removal
My last attempt caused a test case failure. This resovles the issue.
2022-06-28 21:53:59 -05:00
Chris Bieneman
072288dacd [DirectX] Fix broken build after API removal
This removes the DirectX backend's usage of the MaybeAlign API removed
in 1baf1fc.
2022-06-28 20:16:04 -05:00
Xiang Li
73ebb05e44 [DirectX] Support opaque ptr for ValueAsMetadata in DXILBitcodeWriter
When writeValueAsMetadata for GlobalVariable and Function, write TypedPointerType for ValueType and FunctionType.

Reviewed By: bogner

Differential Revision: https://reviews.llvm.org/D127705
2022-06-22 09:10:42 -07:00
Guillaume Chatelet
93082108b7 [NFC][Alignment] Use getAlign in DXILBitcodeWriter 2022-06-13 13:36:36 +00:00
Chris Bieneman
04d4130a51 Support converting pointers from opaque to typed
Using the pointer type analysis we can re-constitute typed pointers and
populate the correct types in the bitcasts throughout the IR.

This doesn't yet handle all cases, but this should be illustrative as
to the dirction and feasability of
the solution.

Reviewed By: pete

Differential Revision: https://reviews.llvm.org/D122270
2022-06-06 11:36:52 -05:00
Chris Bieneman
11dd508bd4 NFC. Clang-formatting.
Since the rest of the DirectX backend is pretty well clang-format
clean, this file should be too.
2022-05-24 11:51:00 -05:00
Chris Bieneman
05b765ff69 [DXIL] [NFC] Remove dead attribute code paths
DXIL doesn't support attributes added after LLVM 3.7. The DXILPrepare
pass removes those attributes so they should never be present by the
time we reach the DXIL bitcode writer.

In the event that we somehow try to write a newer attribute in the DXIL
writer, we should fail hard (crash), because the output would be
invalid. This case should only be possible if the DXIL writer were
called without DXILPrepare being run first, which shouldn't be possible.

This patch also adds a default case to the switch statement over the
attribute list which covers all the removed cases and any new attribute
kinds that may be added in the future. The default case is handled like
other unsupported cases by a call to llvm_unreachable.
2022-04-27 10:46:59 -05:00
Chris Bieneman
e6f44a3cd2 Add PointerType analysis for DirectX backend
As implemented this patch assumes that Typed pointer support remains in
the llvm::PointerType class, however this could be modified to use a
different subclass of llvm::Type that could be disallowed from use in
other contexts.

This does not rely on inserting typed pointers into the Module, it just
uses the llvm::PointerType class to track and unique types.

Fixes #54918

Reviewed By: kuhar

Differential Revision: https://reviews.llvm.org/D122268
2022-04-25 17:49:43 -05:00
Chris Bieneman
f2526c1a5c Add DXIL Bitcode Writer and DXIL testing
This change is a big blob of code that isn't easy to break up. It
either comes in all together as a blob, works and has tests, or it
doesn't do anything.

Logically you can think of this patch as three things:
(1) Adding virtual interfaces so the bitcode writer can be overridden
(2) Adding a new bitcode writer implementation for DXIL
(3) Adding some (optional) crazy CMake goop to build the
DirectXShaderCompiler's llvm-dis as dxil-dis for testing

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D122082
2022-04-15 18:50:26 -05:00