2323 Commits

Author SHA1 Message Date
Koakuma
7955760bc8
[SPARC][IAS] Add illtrap alias for unimp (#105928)
This follows Solaris behavior of allowing both mnemonics all the time.

Fixes https://github.com/llvm/llvm-project/issues/105639.
2024-08-29 19:28:38 +07:00
Piyou Chen
b01c006f73
[TII][RISCV] Add renamable bit to copyPhysReg (#91179)
The renamable flag is useful during MachineCopyPropagation but renamable
flag will be dropped after lowerCopy in some case.

This patch introduces extra arguments to pass the renamable flag to
copyPhysReg.
2024-08-27 10:08:43 +08:00
Koakuma
576b7a781a
[SPARC] Remove assertions in printOperand for inline asm operands (#104692)
Inline asm operands could contain any kind of relocation, so remove the
checks.

Fixes https://github.com/llvm/llvm-project/issues/103493
2024-08-20 20:05:06 +07:00
Daniel Cederman
7faf1a0868
[Sparc] Add errata workaround pass for GR712RC and UT700 (#103843)
This patch adds a pass that provides workarounds for the errata
described in GRLIB-TN-0009, GRLIB-TN-0010, GRLIB-TN-0011, GRLIB-TN-0012,
and GRLIB-TN-0013, that are applicable to the GR712RC and UT700. The
documents are available for download from here:

https://www.gaisler.com/index.php/information/app-tech-notes

The pass will detect certain sensitive instruction sequences and prevent
them from occurring by inserting NOP instruction. Below is an overview
of each of the workarounds. A similar implementation is available in
GCC.

GRLIB-TN-0009:

* Insert NOPs to prevent the sequence (stb/sth/st/stf) -> (single
non-store/load instruction) -> (any store)

* Insert NOPs to prevent the sequence (std/stdf) -> (any store)

GRLIB-TN-0010:

* Insert a NOP between load instruction and atomic instruction (swap and
casa).

* Insert a NOP at branch target if load in delay slot and atomic
instruction at branch target.

* Do not allow functions to begin with atomic instruction.

GRLIB-TN-0011:

* Insert .p2align 4 before atomic instructions (swap and casa).

GRLIB-TN-0012:

* Place a NOP at the branch target of an integer branch if it is a
floating-point operation or a floating-point branch.

GRLIB-TN-0013:

* Prevent (div/sqrt) instructions in the delay slot.

* Insert NOPs to prevent the sequence (div/sqrt) -> (two or three
floating point operations or loads) -> (div/sqrt).

* Do not insert NOPs if any of the floating point operations have a
dependency on the destination register of the first (div/sqrt).

* Do not insert NOPs if one of the floating point operations is a
(div/sqrt).

* Insert NOPs to prevent (div/sqrt) followed by a branch.
2024-08-19 07:59:58 +02:00
Sergei Barannikov
293aa56ebc
[Sparc] Remove dead code (NFC) (#104264) 2024-08-16 04:28:11 +03:00
Koakuma
aca971d336
[SPARC][IAS] Add v8plus feature bit (#101367)
Implement handling for `v8plus` feature bit to allow the user to switch
between V8 and V8+ mode with 32-bit code.
Currently this only sets the appropriate ELF machine type and flags;
codegen changes will be done in future patches.

This is done as a prerequisite for `-mv8plus` flag on clang (#98713).
2024-08-02 10:30:36 +07:00
Sergei Barannikov
991192b211
[Sparc] Remove custom lowering for ADD[CE] / SUB[CE] (#100861)
The default lowering produces fewer instructions.
2024-07-28 18:22:40 +03:00
Sergei Barannikov
77f89f1f54
[Sparc] Remove custom lowering for SMULO / UMULO (#100858)
The underlying issue was fixed by 7c4fe0e9. The lowering is tested by
[us]mulo-128-legalisation-lowering.ll and there are no changes.
2024-07-28 18:15:23 +03:00
Fangrui Song
8f14e39e59 [MC] Remove unnecessary isVerboseAsm from Target::AsmTargetStreamerCtorTy
The parameter is confusing as it duplicates MCStreamer::isVeboseAsm
(initialized from MCTargetOptions::AsmVerbose). After
233cca169237b91d16092c82bd55ee6a283afe98, no in-tree target uses the
parameter.
2024-07-21 10:19:17 -07:00
Amara Emerson
f270a4dd66
[AArch64] Don't tail call memset if it would convert to a bzero. (#98969)
Well, not quite that simple. We can tc memset since it returns the first
argument but bzero doesn't do that and therefore we can end up
miscompiling.

This patch also refactors the logic out of isInTailCallPosition() into the callers.
As a result memcpy and memmove are also modified to do the same thing
for consistency.

rdar://131419786
2024-07-17 01:31:52 -07:00
Kazu Hirata
5e22a53698
[Target] Use range-based for loops (NFC) (#98705) 2024-07-13 17:40:51 -07:00
Joseph Huber
3f1a767572
[LLVM] Factor disabled Libcalls into the initializer (#98421)
Summary:
These Libcalls represent which functions are available to the backend.
If a runtime call is not available, the target sets the the name to
`nullptr`. Currently, this logic is spread around the various targets.
This patch pulls all of the locations that disable libcalls into the
intializer. This patch is effectively NFC.

The motivation behind this patch is that currently the LTO handling uses
the list of all runtime calls to determine which functions cannot be
internalized and must be extracted from static libraries. We do not want
this to happen for libcalls that are not emitted by the backend. A
follow-up patch will move out this logic so the LTO pass can know which
rtlib calls are actually used by the backend.
2024-07-11 12:59:25 -05:00
Koakuma
a92bcb20b8
[SPARC][IAS] Reject unknown/unavailable mnemonics early in ParseInstruction
Validate and reject any unknown or unavailable instruction mnemonics early
in ParseInstruction, before any operand parsing is performed. Some operands
(mainly memory ones) can be parsed slightly differently in V8 and V9
assembly language, so by rejecting unknown or unavailable instructions early
we can prevent the error message from being shadowed by the one raised during
operand parsing.

As a side effect this also allows us to tell unknown and unavailable
mnemonics apart, and issue a suggestion in appropriate cases.

This is based on the approach taken by the MIPS backend.

Reviewers: brad0, rorth, s-barannikov, jrtc27

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/96021
2024-07-11 11:33:19 +07:00
Koakuma
fb7f65ba46
[SPARC][IAS] Emit the correct ELF machine type (#96583)
Emit the correct machine type when writing out ELF objects.
This patch is modeled on GCC's behavior:
- `-m32` emits an object of type EM_SPARC;
- `-m32 -mcpu=v9` emits EM_SPARC32PLUS (however, see below); and
- `-m64` emits EM_SPARCV9.

Note that GCC does not guarantee emission of EM_SPARC32PLUS objects,
since GNU as doesn't support user control of emitted machine type.
It will always autodetect the type based on the instruction mix:
- If there's a V9 instruction inside, then emit EM_SPARC32PLUS; and
- Emit EM_SPARC otherwise.

For LLVM we choose deterministic behavior instead for simplicity.
2024-07-03 19:14:39 +07:00
Fangrui Song
e25e8003ca MCExpr::evaluateAsRelocatable: replace the MCAsmLayout parameter with MCAssembler
Continue the MCAsmLayout removal work started by 67957a45ee1ec42ae1671cdbfa0d73127346cc95.
2024-07-01 16:23:43 -07:00
Fangrui Song
6e93e37fe9 [MC] Remove unneeded MC*AsmBackend::fixupNeedsRelaxation overrides
Follow-up to 88c0a8258800bbc72e7c0b0586436d4a1c62a260
("[MC] Make MCAsmBackend::fixupNeedsRelaxation not pure virtual").
2024-07-01 13:54:08 -07:00
Koakuma
e9b8cd0c80
[SPARC][IAS] Rework ASI/Prefetch tag matching in prep for ParseForAllFeatures
Unify parts of ASI and Prefetch tag matching at `parseASITag`
and `parsePrefetchTag` to use a common function to parse any immediate
expressions. This introduces a slight regression to error messages,
but is needed so we can enable `ParseForAllFeatures`
in `MatchOperandParserImpl` in a future patch.

Reviewers: jrtc27, brad0, rorth, s-barannikov

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/96020
2024-06-27 19:45:53 +07:00
Koakuma
edd2d7c558
[NFC][SPARC] Fix typos and style mismatches
Fix style errors accidentally introduced in PRs #87259 and #94245.

Reviewers: rorth, jrtc27, brad0, s-barannikov

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/96019
2024-06-19 21:44:48 +07:00
Matt Arsenault
5c9352eb02
DAG: Replace bitwidth with type in suffix in atomic tablegen ops (#94845) 2024-06-13 11:52:22 +02:00
Koakuma
e0b9cce4c7
[SPARC][IAS] Add movr(n)e alias for movr(n)z
This adds the alternate mnemonics for movrz and movrnz.

Reviewers: s-barannikov, jrtc27, brad0, rorth

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/94252
2024-06-09 22:16:34 +07:00
Koakuma
2bc36afcdb
[SPARC][IAS] Handle the case of non-4-byte aligned writeNopData
If the Count passed into writeNopData is not a multiple of four,
add a little amount of zeros before writing the NOP stream.
This makes it match the behavior of GNU binutils.

Reviewers: brad0, rorth, s-barannikov, jrtc27

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/94251
2024-06-09 22:15:15 +07:00
Koakuma
41f2ea0b0f
[SPARC][IAS] Add support for prefetcha instruction
This adds support for `prefetcha` instruction for prefetching from
alternate address spaces.

Reviewers: jrtc27, brad0, rorth, s-barannikov

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/94250
2024-06-09 22:13:31 +07:00
Koakuma
2388129d48
[SPARC][IAS] Add named prefetch tag constants
This adds named tag constants (such as `#one_write` and `#one_read`)
for the prefetch instruction.

Reviewers: jrtc27, rorth, brad0, s-barannikov

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/94249
2024-06-09 22:09:14 +07:00
Koakuma
715a5d8d93
[SPARC][IAS] Add aliases for %asr20-21 as defined in JPS1
This adds %set_softint and %clear_softint alias for %asr20 and %asr21
as defined in JPS1.

Reviewers: jrtc27, brad0, s-barannikov, rorth

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/94247
2024-06-09 10:14:50 +07:00
Koakuma
44f93578d2
[SPARC][IAS] Add support for %uhi and %ulo extensions
This adds support for GNU %uhi and %ulo extensions.
Those resolve to the same relocations as %hh and %hm.

Reviewers:
cyndyishida, dcci, brad0, jrtc27, aaupov, Endilll, rorth, maksfb, #reviewers-libcxxabi, s-barannikov, rafaelauler, ayermolo, #reviewers-libunwind, #reviewers-libcxx, daniel-grumberg, tbaederr

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/94246
2024-06-09 10:09:51 +07:00
Koakuma
f20d8b9dcb
[SPARC][IAS] Add GNU extension for addc
Transform `addc imm, %rs, %rd` into `addc %rs, imm, %rd`.
This is used in some GNU and Linux code.

Reviewers: s-barannikov, rorth, jrtc27, brad0

Reviewed By: s-barannikov

Pull Request: https://github.com/llvm/llvm-project/pull/94245
2024-06-09 09:58:46 +07:00
paperchalice
7652a59407
Reland "[NewPM][CodeGen] Port selection dag isel to new pass manager" (#94149)
- Fix build with `EXPENSIVE_CHECKS`
- Remove unused `PassName::ID` to resolve warning
- Mark `~SelectionDAGISel` virtual so AArch64 backend can work properly
2024-06-04 08:10:58 +08:00
paperchalice
8917afaf0e
Revert "[NewPM][CodeGen] Port selection dag isel to new pass manager" (#94146)
This reverts commit de37c06f01772e02465ccc9f538894c76d89a7a1 to
de37c06f01772e02465ccc9f538894c76d89a7a1

It still breaks EXPENSIVE_CHECKS build. Sorry.
2024-06-02 14:31:52 +08:00
paperchalice
d2cdc8ab45
[NewPM][CodeGen] Port selection dag isel to new pass manager (#83567)
Port selection dag isel to new pass manager.
Only `AMDGPU` and `X86` support new pass version. `-verify-machineinstrs` in new pass manager belongs to verify instrumentation, it is enabled by default.
2024-06-02 09:12:33 +08:00
Kazu Hirata
c18bcd0a57
[Target] Use StringRef::operator== instead of StringRef::equals (NFC) (#91072) (#91138)
I'm planning to remove StringRef::equals in favor of
StringRef::operator==.

- StringRef::operator==/!= outnumber StringRef::equals by a factor of
  38 under llvm/ in terms of their usage.

- The elimination of StringRef::equals brings StringRef closer to
  std::string_view, which has operator== but not equals.

- S == "foo" is more readable than S.equals("foo"), especially for
  !Long.Expression.equals("str") vs Long.Expression != "str".
2024-05-05 13:43:10 -07:00
Michael Liao
7c26889775 [Sparc] Fix instr desc of special register stores
- Those special register stores are STORE and their memory operands are
  input operands instead of output ones.

Reviewers:
JDevlieghere, arsenm, yinying-lisa-li, koachan, PeimingLiu, jyknight, aartbik, matthias-springer

Reviewed By: arsenm

Pull Request: https://github.com/llvm/llvm-project/pull/88971
2024-04-16 20:32:00 -04:00
Koakuma
697dd93ae3
[SPARC] Implement L and H inline asm argument modifiers (#87259)
This adds support for using the L and H argument modifiers for twinword
operands in inline asm code, such as in:

```
%1 = tail call i64 asm sideeffect "rd %pc, ${0:L} ; srlx ${0:L}, 32, ${0:H}", "={o4}"()
```

This is needed by the Linux kernel.
2024-04-05 04:34:07 +07:00
Sergei Barannikov
5e5b656102
[MC] Make MCParsedAsmOperand::getReg() return MCRegister (#86444) 2024-03-25 05:13:48 +03:00
Sergei Barannikov
057e725260
[Sparc] Use generated MatchRegisterName (NFCI) (#82165) 2024-03-02 05:17:41 +03:00
Rishabh Bali
fe42e72db2
[CodeGen] Port AtomicExpand to new Pass Manager (#71220)
Port the `atomicexpand` pass to the new Pass Manager. 
Fixes #64559
2024-02-25 18:42:22 +05:30
James Y Knight
c1a99b2c77
[Sparc] limit MaxAtomicSizeInBitsSupported to 32 for 32-bit Sparc. (#81655)
When in 32-bit mode, the backend doesn't currently implement 64-bit
atomics, even though the hardware is capable if you have specified a V9
CPU. Thus, limit the width to 32-bit, for now, leaving behind a TODO.

This fixes a regression triggered by PR #73176.
2024-02-13 15:40:51 -05:00
Koakuma
c2f9885a8a
[SPARC] Support reserving arbitrary general purpose registers (#74927)
This adds support for marking arbitrary general purpose registers -
except for those with special purpose (G0, I6-I7, O6-O7) - as reserved,
as needed by some software like the Linux kernel.
2024-02-11 02:04:18 -05:00
Philip Reames
3ff7caea33
[TTI] Use Register in isLoadFromStackSlot and isStoreToStackSlot [nfc] (#80339) 2024-02-01 17:52:35 -08:00
Kazu Hirata
81218356fd [Sparc] Use StringRef::starts_with_insensitive (NFC) 2024-01-20 14:30:32 -08:00
Koakuma
118d4234ac
[SPARC] Prefer RDPC over CALL to implement GETPCX for 64-bit target
On 64-bit target, prefer using RDPC over CALL to get the value of %pc.
This is faster on modern processors (Niagara T1 and newer) and avoids
polluting the processor's predictor state.

The old behavior of using a fake CALL is still done when tuning for
classic UltraSPARC processors, since RDPC is much slower there.

A quick pgbench test on a SPARC T4 shows about 2% speedup on SELECT
loads, and about 7% speedup on INSERT/UPDATE loads.

Reviewed By: @s-barannikov

Github PR: https://github.com/llvm/llvm-project/pull/78280
2024-01-16 22:46:39 +07:00
Koakuma
5fa4b1d83c
[SPARC] Consume tune-cpu directive in the backend (#77195)
This lets the backend read the `tune-cpu` directive that is emitted by the frontend.

No changes are needed for clang as it is already emits it.
2024-01-12 21:21:32 -05:00
Alex Bradbury
80aeb62211
[llvm][NFC] Use SDValue::getConstantOperandVal(i) where possible (#76708)
This helper function shortens examples like
`cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue();` to
`Node->getConstantOperandVal(1);`.

Implemented with:
`git grep -l
"cast<ConstantSDNode>\(.*->getOperand\(.*\)\)->getZExtValue\(\)" | xargs
sed -E -i

's/cast<ConstantSDNode>\((.*)->getOperand\((.*)\)\)->getZExtValue\(\)/\1->getConstantOperandVal(\2)/`
and `git grep -l
"cast<ConstantSDNode>\(.*\.getOperand\(.*\)\)->getZExtValue\(\)" | xargs
sed -E -i

's/cast<ConstantSDNode>\((.*)\.getOperand\((.*)\)\)->getZExtValue\(\)/\1.getConstantOperandVal(\2)/'`.
With a couple of simple manual fixes needed. Result then processed by
`git clang-format`.
2024-01-02 13:14:28 +00:00
Craig Topper
e87f33d9ce
[RISCV][MC] Pass MCSubtargetInfo down to shouldForceRelocation and evaluateTargetFixup. (#73721)
Instead of using the STI stored in RISCVAsmBackend, try to get it from
the MCFragment.

This addresses the issue raised here
https://discourse.llvm.org/t/possible-problem-related-to-subtarget-usage/75283
2023-12-07 13:17:58 -08:00
Kazu Hirata
ab6d5fa3d0 [Sparc] Use isNullConstant (NFC) 2023-10-14 21:00:59 -07:00
Kazu Hirata
4a0ccfa865 Use llvm::endianness::{big,little,native} (NFC)
Note that llvm::support::endianness has been renamed to
llvm::endianness while becoming an enum class as opposed to an
enum. This patch replaces support::{big,little,native} with
llvm::endianness::{big,little,native}.
2023-10-12 21:21:45 -07:00
Sergei Barannikov
b9208aca9b
[Sparc] Remove duplicate ALU and SETHI instructions (NFCI) (#66851)
There are no 64-bit variants of these ALU / SETHI instructions in V9.
Remove these instruction definitions and add patterns to match DAG nodes
to the generic instructions defined in SparcInstrInfo.td.

This is not strictly NFC because of the changes in
`2011-01-11-FrameAddr.ll` test. The reason is that Sparc delay slot
filler pass handled ADDrr but not ADDXrr, which are now the same
instruction.
2023-10-10 20:34:20 +03:00
Sergei Barannikov
c98bf1e45e
[Sparc] Replace CMP instructions with InstAlias (NFCI) (#66859)
According to the manual `cmp` is a synthetic instruction that maps to
`subcc` with %g0 output operand. Make it so.

The change required some changes to instruction selection process. The
reason is that the old CMP did not have an output operand, while setcc
does have one. We want that operand to be %g0. The easiest way to
achieve this seems to be to mark SUBCC with hasPostISelHook and replace
the output operand with %g0 in the corresponding TargetLowering method.
2023-10-09 09:40:44 +03:00
Nick Desaulniers
330fa7d2a4
[TargetLowering] Deduplicate choosing InlineAsm constraint between ISels (#67057)
Given a list of constraints for InlineAsm (ex. "imr") I'm looking to
modify the order in which they are chosen. Before doing so, I noticed a
fair
amount of logic is duplicated between SelectionDAGISel and GlobalISel
for this.

That is because SelectionDAGISel is also trying to lower immediates
during selection. If we detangle these concerns into:
1. choose the preferred constraint
2. attempt to lower that constraint

Then we can slide down the list of constraints until we find one that
can be lowered. That allows the implementation to be shared between
instruction selection frameworks.

This makes it so that later I might only need to adjust the priority of
constraints in one place, and have both selectors behave the same.
2023-09-25 08:53:03 -07:00
Sergei Barannikov
2f23666ae7
[Sparc] Remove Subtarget member of SparcTargetMachine (#66876)
It was already removed once in D19265, but was reintroduced in D20353.
2023-09-25 18:31:54 +03:00
Sergei Barannikov
dd477ebd23
[Sparc] Remove LEA instructions (NFCI) (#65850)
LEA_ADDri and LEAX_ADDri are printed / encoded the same way as ADDri. I
had to change the type of simm13Op so that it can be used in both 32-
and 64-bit modes. This required the changes in operands of some
InstAliases.
2023-09-20 03:34:39 +03:00