695 Commits

Author SHA1 Message Date
Nikita Popov
b492ec5899
[ErrorHandling] Add reportFatalInternalError + reportFatalUsageError (NFC) (#138251)
This implements the result of the discussion at:

https://discourse.llvm.org/t/rfc-report-fatal-error-and-the-default-value-of-gencrashdialog/73587

There are two different use cases for report_fatal_error, so replace it
with two functions reportFatalInternalError() and
reportFatalUsageError(). The former indicates a bug in LLVM and
generates a crash dialog. The latter does not. The names have been
suggested by rnk and people seemed to like them.

This replaces a lot of the usages that passed an explicit value for
GenCrashDiag. I did not bulk replace remaining report_fatal_error usage
-- they probably require case by case review for which function to use.
2025-05-05 12:10:03 +02:00
Kazu Hirata
aa15596b5f
[llvm] Remove unused local variables (NFC) (#138478) 2025-05-04 21:33:54 -07:00
Fangrui Song
4cde986df4 LoongArch: Sink #include llvm/BinaryFormat/ELF.h from LoongArchMCExpr.h. NFC
Remove a fishy `#undef LoongArch` and an unneeded user-provided dtor.
2025-05-03 18:18:37 -07:00
Craig Topper
ca21508080
[Targets] Migrate from atomic_load_8/16/32/64 to atomic_load_nonext_8/16/32/64. NFC (#137428)
This makes them more consistent with the checks performed by regular loads. We can't simply add IsNonExtLoad to the existing atomic_load_8/16/32/64 as that would affect out of tree targets.
2025-04-28 09:26:34 -07:00
tangaac
34845ac35a
[LoongArch] Try to widen shuffle mask (#136081) 2025-04-28 14:25:52 +08:00
Sergei Barannikov
bb1765179e
[TTI] Simplify implementation (NFCI) (#136674)
Replace "concept based polymorphism" with simpler PImpl idiom.

This pursues two goals:
* Enforce static type checking. Previously, target implementations hid
base class methods and type checking was impossible. Now that they
override the methods, the compiler will complain on mismatched
signatures.
* Make the code easier to navigate. Previously, if you asked your
favorite LSP server to show a method (e.g. `getInstructionCost()`), it
would show you methods from `TTI`, `TTI::Concept`, `TTI::Model`,
`TTIImplBase`, and target overrides. Now it is two less :)

There are three commits to hopefully simplify the review.

The first commit removes `TTI::Model`. This is done by deriving
`TargetTransformInfoImplBase` from `TTI::Concept`. This is possible
because they implement the same set of interfaces with identical
signatures.

The first commit makes `TargetTransformImplBase` polymorphic, which
means all derived classes should `override` its methods. This is done in
second commit to make the first one smaller. It appeared infeasible to
extract this into a separate PR because the first commit landed
separately would result in tons of `-Woverloaded-virtual` warnings (and
break `-Werror` builds).

The third commit eliminates `TTI::Concept` by merging it with the only
derived class `TargetTransformImplBase`. This commit could be extracted
into a separate PR, but it touches the same lines in
`TargetTransformInfoImpl.h` (removes `override` added by the second
commit and adds `virtual`), so I thought it may make sense to land these
two commits together.

Pull Request: https://github.com/llvm/llvm-project/pull/136674
2025-04-26 15:25:40 +03:00
Craig Topper
5dc2d668e6
[SelectionDAG][Targets] Replace atomic_load_8/atomic_load_16 with atomic_load_*ext_8/atomic_load_*ext_16 where possible. (#137279)
isAnyExtLoad/isZExtLoad/isSignExtLoad are able to emit predicate checks
from tablegen now so we should use them.

The next step would be to add isNonExtLoad versions and migrate all
remaining uses of atomic_load_8/16/32/64 to that.
2025-04-25 09:01:00 -07:00
Sergei Barannikov
0014b49482
[TTI] Make all interface methods const (NFCI) (#136598)
Making `TargetTransformInfo::Model::Impl` `const` makes sure all
interface methods are `const`, in `BasicTTIImpl`, its bases, and in all
derived classes.

Pull Request: https://github.com/llvm/llvm-project/pull/136598
2025-04-22 06:27:29 +03:00
tangaac
4853bf0956
[LoongArch] Lower build_vector to broadcast load if possible (#135896) 2025-04-21 16:04:28 +08:00
Fangrui Song
c239acb5b6 MCFixup: Make FixupKindInfo smaller and change getFixupKindInfo to return value
We will increase the use of raw relocation types and eliminate fixup
kinds that correspond to relocation types. The getFixupKindInfo
functions will return an rvalue instead. Let's update the return type
from a const reference to a value type.
2025-04-18 20:55:43 -07:00
Fangrui Song
89687e6f38 LoongArch: Remove TLS fixup kinds that map to relocationtypes
Follow-up to 40789ce7f1b7cff6de82b7f93db25a8c54194d46
("MCFixup: Move relocation values before FK_NONE")
2025-04-18 20:19:42 -07:00
Fangrui Song
609586f7f6 LoongArch: Remove fixup kinds that map to relocation types
Follow-up to 40789ce7f1b7cff6de82b7f93db25a8c54194d46
("MCFixup: Move relocation values before FK_NONE")
2025-04-18 20:16:50 -07:00
Fangrui Song
dca0ccff4f LoongArch: Remove unreachable TLS fixup from adjustFixupValue 2025-04-18 20:02:57 -07:00
Fangrui Song
40789ce7f1 MCFixup: Move relocation values before FK_NONE
Simplify the process of encoding a raw relocation type using MCFixupKind.

Currently, FirstRelocationkind is utilized by AArch64, LoongArch, and
RISCV.
2025-04-18 19:51:56 -07:00
Fangrui Song
f336c908cd LoongArch: Use mc::isRelocation. NFC 2025-04-18 19:37:52 -07:00
Fangrui Song
7b0409ad0e MC: Simplify code with isRelocation 2025-04-18 19:09:16 -07:00
tangaac
ebf9883b82
[LoongArch] Lower vector shuffle as byte rotate (if possible) (#135157) 2025-04-17 11:08:18 +08:00
Fangrui Song
507d7dc651 [LoongArch] Simplify getRelocType 2025-04-16 00:09:07 -07:00
Fangrui Song
ac4712482e [LoongArch] Use FirstRelocationKind to remove ELFObjectWriter::recordRelocation special case
The current implementation of R_LARCH_SUB{8,16,32,64} and TLS relocation types relies on fixup kinds FirstLiteralRelocationKind + offset (originally intended for .reloc directives). While this is clever and prevents switch cases like

```
case fixup_...sub8:
  return ELF::R_LARCH_SUB8;
```

it needs revision.

GNU Assembler treats .reloc directives differently from standard relocations, notably by skipping

* Skipping STT_SECTION adjustments (when a referenced symbol is local and satisfies certain conditions, it can be redirected to a section symbol).
* Skipping STT_TLS symbol type setting for TLS relocations.

Encode relocatin type t with FirstRelocationKind+t instead of
FirstLiteralRelocationKind+t. The new value is less than
FirstLiteralRelocationKind and will not be treated as a .reloc
directive.

Close #135521
2025-04-15 23:55:49 -07:00
leecheechen
dfb5b6e27c
[LoongArch] Don't crash on instruction prefetch intrinsics (#135760)
Instead of failing to select during isel, drop the intrinsic in
lowering.

Similar as the X86's PR. Seeing: https://reviews.llvm.org/D151050.

Fixes #134624
2025-04-16 14:12:00 +08:00
tangaac
a024d13f84
[LoongArch] make ABDS/ABDU legal for lsx/lasx (#134190) 2025-04-16 11:33:29 +08:00
tangaac
7818e5ab67
[LoongArch] lower vector shuffle to shift if possible (#132866) 2025-04-10 15:26:00 +08:00
Rahul Joshi
20eb60d3f2
[NFC][LLVM] Cleanup pass initialization for wasm/LoongArch (#134452)
- Remove calls to pass initialization from pass constructors.
- https://github.com/llvm/llvm-project/issues/111767
2025-04-07 18:09:46 -07:00
Fangrui Song
c0b4a8edfe MCValue: Replace getRefKind with getSpecifier 2025-04-06 00:12:45 -07:00
Fangrui Song
d5893fc2a7 MCValue: Replace MCSymbolRefExpr members with MCSymbol
Commit 0999cbd0b9ed8aa893cce10d681dec6d54b200ad (2014) introduced
`MCValue::RefKind` for AArch64 ELF as a clean approach to encode the
relocation specifier.

Following numerous migration commits, direct references to getSymA and
getSymB have been eliminated. This allows us to seamlessly update SymA
and SymB, replacing MCSymbolRefExpr with MCSymbol.

Removeing reliance on a MCAssembler::evaluateFixup hack
(`if (Target.SymSpecifier || SA.isUndefined()) {` (previosuly
`if (A->getKind() != MCSymbolRefExpr::VK_None || SA.isUndefined()) {`))
requires 38c3ad36be1facbe6db2dede7e93c0f12fb4e1dc and 4182d2dcb5ecbfc34d41a6cd11810cd36844eddb

Revert the temporary RISCV/LoongArch workaround
(7e62715e0cd433ed97749549c6582c4e1aa689a3) during migration.

MCAssembler::evaluateFixup needs an extra `!Add->isAbsolute()` case
to support `movq abs@GOTPCREL(%rip), %rax; abs = 42` in llvm/test/MC/ELF/relocation-alias.s
(ELFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl asserts if
called on an absolute symbol).
2025-04-05 21:02:08 -07:00
Fangrui Song
7e62715e0c [RISCV,LoongArch,MC] Replace getSymA()->getSymbol() with getAddSym. NFC
We will replace the MCSymbolRefExpr member in MCValue with MCSymbol.
This change reduces dependence on MCSymbolRefExpr.

Creating a MCSymbolRefExpr in *AsmBackend::handleAddSubRelocations is
not efficient, but it is temporary and will be replaced when MCValue no
longer uses MCSymbolRefExpr.
2025-04-05 13:58:16 -07:00
Fangrui Song
0c84d71eda [MC] Replace getSymA()->getSymbol() with getAddSym. NFC
We will replace the MCSymbolRefExpr member in MCValue with MCSymbol.
This change reduces dependence on MCSymbolRefExpr.
2025-04-05 13:40:04 -07:00
Fangrui Song
b1cd3cb3f4 [MC] Replace getSymA()->getSymbol() with getAddSym. NFC
We will replace the MCSymbolRefExpr member in MCValue with MCSymbol.
This change reduces dependence on MCSymbolRefExpr.
2025-04-05 13:34:24 -07:00
Fangrui Song
f3e6473df4 MCValue: reduce getSymB uses
The MCValue::SymB MCSymbolRefExpr member might be replaced with a
MCSymbol in the future. Reduce direct access.
2025-04-04 22:17:22 -07:00
Fangrui Song
a07b37475c [LoongArch] Simplify evaluateAsRelocatableImpl
Similar to RISCV
2025-04-04 21:15:42 -07:00
Fangrui Song
db603a09da [MC] Move ELF-specific handleAddSubRelocations to ELFObjectWriter::recordRelocation 2025-03-29 19:08:07 -07:00
Fangrui Song
f7228f38b7 MCValue: Simplify code with getSubSym
The MCValue::SymB MCSymbolRefExpr member might be replaced with a
MCSymbol in the future. Reduce direct access.
2025-03-29 18:19:19 -07:00
wanglei
d055e58334
[LoongArch][MC] Add relocation support for fld fst [x]vld [x]vst
This also fixes errors when using Clang with step-by-step compilation.
Because the optimization will pass relocation information to memory
access instructions. For example:
t.c:
```
float f = 0.1;
float foo() { return f;}
```
```
clang --target=loongarch64 -O2 -c t.c --save-temps
```

Reviewed By: tangaac, SixWeining

Pull Request: https://github.com/llvm/llvm-project/pull/133225
2025-03-28 11:20:17 +08:00
WÁNG Xuěruì
99ec6f8aec
[LoongArch][MC] Add support for disassembly option "no-aliases" (#132900)
This parallels the GNU Binutils feature's usage. A hidden command-line
option `--loongarch-no-aliases` is also added, similar to how
`--loongarch-numeric-reg` is for the `numeric` option.
2025-03-27 17:43:46 +08:00
tangaac
88099a7da9
[LoongArch] Custom lower vector trunc to vector shuffle (#130938) 2025-03-27 09:23:05 +08:00
WÁNG Xuěruì
aae37a2968
[LoongArch] Allow recognition of b{lt,gt,le,ge}z in disassembly (#132620)
This behavior is implemented for GNU Binutils since 2.41, and benefits
the readability of the disassembly output. Do the same for LLVM by
removing the zero weight from the alias definitions respectively.
2025-03-26 11:04:11 +08:00
Kazu Hirata
432328e3f4 [LoongArch] Fix a warning
This patch fixes:

  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp:561:7: error:
  unused variable 'ScalarSizeInBits' [-Werror,-Wunused-variable]
2025-03-24 00:10:55 -07:00
tangaac
e3bd1f2b3f
[LoongArch] lower vector shuffle to zero or any extend (#129485) 2025-03-24 14:29:11 +08:00
Fangrui Song
4781a8ebd0 MCValue: add setSpecifier to simplify code
This primarily simplifies backend evaluateAsRelocatableImpl.
2025-03-23 12:36:46 -07:00
Fangrui Song
8ec96cc886 [LoongArch] Move STT_TLS setting from fixELFSymbolsInTLSFixups to getRelocType
The legacy generic code uses `ELFObjectWriter::fixSymbolsInTLSFixups` to
set `STT_TLS` (and use an unnecessary expression walk). The better way
is to do this in `getRelocType`, which I have done for AArch64, PowerPC,
RISC-V, and X86.
2025-03-22 19:55:15 -07:00
ZhaoQi
d6dc74e19f
[LoongArch] Fix the type of tls-le symbols (#132324) 2025-03-21 16:05:45 +08:00
Fangrui Song
058a4e8170 [LoongArch] Rename VariantKind to Specifier
Follow the X86, Mips, and RISCV renaming.

> "Relocation modifier" suggests adjustments happen during the linker's relocation step rather than the assembler's expression evaluation.
> "Relocation specifier" is clear, aligns with Arm and IBM AIX's documentation, and fits the assembler's role seamlessly.

In addition, rename *MCExpr::getKind, which confusingly shadows the base class getKind.

The parseSpecifier name follows Sparc.
2025-03-20 23:59:23 -07:00
hev
2d876ed33e
[llvm][LoongArch] Changing the default code model from small to medium for 64-bit (#132173)
Link: https://discourse.llvm.org/t/rfc-changing-the-default-code-model-for-loongarch
2025-03-21 10:15:31 +08:00
Fangrui Song
2c35cb6f16 [MC] Remove unneeded getNumFixupKinds 2025-03-16 23:50:46 -07:00
Fangrui Song
8a1b4d0ed2 [MC] Rework AVR #121498 to not add extra argument to shouldForceRelocation
This removes the extra argument from commit 814b34f31e163e76b816194004689985f5b9fd7b.

Also remove unneeded `>= FirstLiteralRelocationKind`.
2025-03-16 23:35:01 -07:00
Fangrui Song
de60c0e034 [MC] .reloc: move FirstLiteralRelocationKind check to evaluateFixup
Target shouldForceRelocation checks `FirstLiteralRelocationKind` to
determine whether a relocation is forced due to the .reloc directive. We
should move the code to evaluateFixup so that many targets don't need to
override shouldForceRelocation.
2025-03-16 22:32:18 -07:00
Fangrui Song
7722d7519c [MC] evaluateAsRelocatableImpl: remove the Fixup argument
Follow-up to d6fbffa23c84e622735b3e880fd800985c1c0072 . This commit
updates all call sites and removes the argument from the function.
2025-03-15 16:10:19 -07:00
Lu Weining
bae6644e12
[LoongArch] Relax the restrictions of inlineasm operand modifier 'u' and 'w' (#129864)
- Allow 'u' and 'w' on LASX, LSX or floating point register operands.
- Also add missing description in LangRef.

Fixes #129863.
2025-03-06 16:17:12 +08:00
Fangrui Song
fe56c4c019 [MC] Remove unneeded VK_None argument from MCSymbolRefExpr::create. NFC 2025-03-05 23:14:04 -08:00
tangaac
cb7030dbe7
[LoongArch] use TypeWidenVector for most illegal vector types (#126456)
`TypeWidenVector` makes an illegal vector a larger one
e.g. in lsx
v2i32 -> v4i32
v4i16 -> v8i16
With this we can make good use of `vilvh`, `vilvl` instructions in
vector `sext`, `zext` in later pr.

Previous action is `TypePromoteInteger`, which replaces integer with a
larger one
e.g. in lsx
v2i32 -> v2i64
v4i16 -> v4i32
2025-03-03 10:26:11 +08:00