481 Commits

Author SHA1 Message Date
Patryk Wychowaniec
814b34f31e
[AVR] Force relocations for non-encodable jumps (#121498)
This commit changes the branch emission logic so that instead of
throwing the "branch target out of range" error, we emit a relocation
instead.
2025-01-20 09:23:57 +08:00
quic_hchandel
171d3edd05
[RISCV] Add Qualcomm uC Xqciint (Interrupts) extension (#122256)
This extension adds eleven instructions to accelerate interrupt
servicing.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.

---------

Co-authored-by: Harsh Chandel <hchandel@qti.qualcomm.com>
2025-01-13 16:36:05 +05:30
Sam Elliott
525f5262af
[RISCV] Support Parsing Nonstandard Relocations (#119909)
This allows nonstandard relocation names to be used in `.reloc` assembly
directives (giving the correct relocation number).

No translation is done by the assembler into `R_RISCV_CUSTOM<n>` names,
and the assembler does not automatically add the relevant
`R_RISCV_VENDOR` relocation with the vendor symbol. If we want, we can
have a different directive that does this later.

The first batch of relocations to be added are from [Qualcomm's RISC-V
psABI
extensions](https://github.com/quic/riscv-elf-psabi-quic-extensions/releases/tag/v0.1).
2025-01-07 12:51:04 +00:00
Craig Topper
1401703fe4
[RISCV] Add Enum for CSR encodings. (#121674)
This allows us to use them in C++ code without needing to do a table
lookup.
2025-01-06 10:11:29 -08:00
Craig Topper
a2b9058c39
[RISCV] Reduce size of CSR lookup tables. NFC (#121606)
Instead of storing 3 different names in each row of the table, use a
separate row for each name and use a flag to indicate what type of name
it is. The AltName and DeprecatedName weren't used often enough to
justify storing them as a possibility for every register.

This reduces the .rodata size by 27k and reduces the number of dynamic
relocations since we now only need 1 lookup by name function. The lookup
by name function each contained a ~400 entry table of const char*
pointing to constant strings. Each of those requires a dynamic
relocation.

I also capitalized IsRV32Only in the C++ code to match coding
standards.
2025-01-03 19:04:13 -08:00
quic_hchandel
1557eeda73
[RISCV] Add Qualcomm uC Xqciac (Load-Store Adress calculation) extension (#121037)
This extension adds 3 instructions that perform load-store address
calculation.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.

---------

Co-authored-by: Harsh Chandel <hchandel@qti.qualcomm.com>
Co-authored-by: Sudharsan Veeravalli <quic_svs@quicinc.com>
2024-12-29 11:14:12 +05:30
Sam Elliott
95c5386ddb
[RISCV][NFCI] Rationalize Immediate Definitions (#120718) 2024-12-21 09:47:07 +00:00
Owen Anderson
f06756f50e
Store sysreg names in-line with their descriptors. (#119157)
This wastes some disk space, because we have to size the arrays for
the maximum possible length. However, it eliminates dynamic relocations
from the SysRegsList arrays.
2024-12-21 20:19:56 +13:00
Craig Topper
82459ecf3e
[RISCV] Split OPERAND_SEW operand type for mask only instructions. (#119776)
Mask only instructions like vmand and vmsbf should always have 0 for
their Log2SEW operand.  Non-mask instructions should only have
3, 4, 5, or 6 for their Log2SEW operand.

Split the operand type so we can verify these cases separately.

I had to fix the SEW for whole register move to vmv.v.v copy
optimization and update an mir test. The vmv.v.v change isn't
functional since we have already done vsetvli insertion before and
nothing else uses the field after copy expansion. I can split these
changes off if desired.
2024-12-13 13:14:23 -08:00
Sudharsan Veeravalli
668d9688ac
[RISCV] Add Qualcomm uC Xqcilsm (Load Store Multiple) extension (#119823)
This extension adds 6 instructions that can do multi-word load/store.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.
2024-12-14 00:06:58 +05:30
Sudharsan Veeravalli
6881c6d2a6
[RISCV] Add Qualcomm uC Xqcia (Arithmetic) extension (#118113)
This extension adds 11 instructions that perform integer arithmetic.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.
2024-12-01 17:06:22 +05:30
Mark Goncharov
80df56e03b
Reapply "[RISCV] Implement tail call optimization in machine outliner" (#117700)
This MR fixes failed test `CodeGen/RISCV/compress-opt-select.ll`.

It was failed due to previously merged commit `[TTI][RISCV]
Unconditionally break critical edges to sink ADDI (PR #108889)`.

So, regenerated `compress-opt-select` test.
2024-11-26 23:39:45 +08:00
Mehdi Amini
f94bd3c933
Revert "[RISCV] Implement tail call optimization in machine outliner" (#117710)
Reverts llvm/llvm-project#115297
Bots are broken
2024-11-26 13:45:47 +01:00
Mark Goncharov
29062329f3
[RISCV] Implement tail call optimization in machine outliner (#115297)
Following up issue #89822, this patch adds opportunity to use tail call
in machine outliner pass.
Also it enables outline patterns with X5(T0) register.
2024-11-26 12:30:37 +03:00
Kazu Hirata
82d5dd28b4
[RISCV] Remove unused includes (NFC) (#115814)
Identified with misc-include-cleaner.
2024-11-11 22:54:54 -08:00
Sergei Barannikov
eeb987f6f3
[MC] Make generated MCInstPrinter::getMnemonic const (NFC) (#114682)
The value returned from the function depends only on the instruction opcode.

As a drive-by, change the type of the argument to const-reference.
2024-11-03 20:37:26 +03:00
Craig Topper
c3724ba866
[RISCV] Add OperandType for vector rounding mode operands. (#114179)
Use TSFlags to distinquish which type of rounding mode it is. We use the same tablegen base classes for vxrm and frm sometimes so its hard to have different types for different instructions.
2024-10-30 11:46:15 -07:00
Craig Topper
e7262c15d3
[RISCV] Add OperandType for sew and vecpolicy operands. (#114168) 2024-10-29 22:34:47 -07:00
Craig Topper
f672cc1ee1
[RISCV] Add OperandType for condition code arguments used by select and SFB pseudos. (#114163) 2024-10-29 21:23:31 -07:00
Fangrui Song
facdae62b7 [MCInstPrinter] Make printRegName non-const
Similar to printInst. printRegName may change states (e.g. #113834).
2024-10-29 19:14:54 -07:00
Craig Topper
13a3c4f97c
[RISCV] Add OperandType to frmarg and rtzarg. (#114142)
Teach RISCVInstrInfo::verifyInstruction to validate them.

This is partially extracted from #89047, but that did not include the
verification.
2024-10-29 17:46:52 -07:00
Sam Elliott
b5ea5be2a7
[RISCV][MC] Fix >32bit .insn Directives (#111878)
The original patch had a reasonably significant bug. You could not use
`.insn` to assemble encodings that had any bits set above the low 32
bits. This is due to the fact that `getMachineOpValue` was truncating
the immediate value, and I did not commit enough tests of useful cases.

This changes the result of `getMachineOpValue` to be able to return the
48-bit and 64-bit immediates needed for the wider `.insn` directives.

I took the opportunity to move some of the test cases around in the file
to make looking at the output of `llvm-objdump` a little clearer.
2024-10-11 12:24:54 +01:00
Sam Elliott
f93f925d4f
[RISCV][MC] Support Assembling 48- and 64-bit Instructions (#110022)
This adds `.insn` support for assembling instructions of 48- and
64-bits (only when giving an explicit length). Disassembly already
knows to bunch up the instruction bits for these instructions.

This changes some error messages so they are a little clearer.

Co-authored-by: Sudharsan Veeravalli <quic_svs@quicinc.com>
2024-10-08 14:09:07 +01:00
Craig Topper
c3d3cef8d5
[RISCV] Don't delete all fixups in RISCVMCCodeEmitter::expandLongCondBr. (#109513)
The Fixups vector passed into this function may already have fixups in
it from earlier instructions. We should not erase those. We just want to
erase fixups added by this function.

Fixes #108612.
2024-09-22 22:31:36 -07:00
Fangrui Song
a15f1bfa94 [RISCV] Avoid calling isSymbolRefDifferenceFullyResolvedImpl. NFC
This member function is supposed to be private to MC. Also add an ifunc
test.
2024-09-20 19:41:11 -07:00
Craig Topper
cebc130737 [RISCV] Remove unneeded check for NoRegister from RISCVInstPrinter::printRegReg. NFC
The operand should never be NoRegister.
2024-09-14 20:10:57 -07:00
Craig Topper
57aaf5ec9f [RISCV] Use MCRegister in RISCVMCInstrAnalysis. NFC 2024-09-12 23:35:55 -07:00
Luke Lau
3d729571fd
[RISCV] Model dest EEW and fix peepholes not checking EEW (#105945)
Previously for vector peepholes that fold based on VL, we checked if the
VLMAX is the same as a proxy to check that the EEWs were the same. This
only worked at LMUL >= 1 because the EMULs of the Src output and user's
input had to be the same because the register classes needed to match.

At fractional LMULs we would have incorrectly folded something like
this:

    %x:vr = PseudoVADD_VV_MF4 $noreg, $noreg, $noreg, 4, 4 /* e16 */, 0
    %y:vr = PseudoVMV_V_V_MF8 $noreg, %x, 4, 3 /* e8 */, 0

This models the EEW of the destination operands of vector instructions
with a TSFlag, which is enough to fix the incorrect folding.

There's some overlap with the TargetOverlapConstraintType and
IsRVVWideningReduction. If we model the source operands as well we may
be able to subsume them.
2024-09-05 15:27:48 +08:00
Craig Topper
d0dfcea608 [RISCV][LoongArch] Don't store Dwarf register in MCRegister. 2024-08-30 19:32:21 -07:00
Luke Lau
dbbfc952f0
[RISCV] Separate ActiveElementsAffectResult into VL and Mask flags (#106517)
In #106110 we had to mark v[f]slide1down.vx as
ActiveElementsAffectResult since the elements in the body depend on VL.
However it doesn't depend on the mask, so this was overly conservative
and broke the vmerge peephole.

We can recover this by splitting up ActiveElementsAffectResult into VL
and Mask bits, so we can more accurately model v[f]slide1down.vx and
re-enable the peephole.
2024-08-30 07:46:06 +08:00
Craig Topper
62c5de36e8 [RISCV] Fix a place that convert an immediate to MCRegister and back to immediate.
This dropped the upper 32 bits of the immediate, but I'm not sure
it is ever non-zero.
2024-08-28 22:35:24 -07:00
Rahul Joshi
1753008bbb
[NFC] Eliminate top-level "using namespace" from some headers. (#102751)
- Eliminate top-level "using namespace" from some headers.
2024-08-11 13:10:48 -07:00
Luke Lau
a5b65399a7
[RISCV] Move ActiveElementsAffectResult to TSFlags. NFC (#101123)
As noted in
https://github.com/llvm/llvm-project/pull/100367/files#r1695442138,
RISCVMaskedPseudoInfo currently stores two things, whether or not a
masked pseudo has an unmasked variant, and whether or not it's
element-wise.

These are separate things, so this patch splits the latter out into the
underlying instruction's TSFlags to help make the semantics of #100367
more clear.

To the best of my knowledge the only non-element-wise instructions in V
are:

- vredsum.vs and other reductions
- vcompress.vm
- vms*f.m
- vcpop.m and vfirst.m
- viota.m

In vector crypto the instructions that operate on element groups are
conservatively marked (this might be fine to relax later given since
non-EGS multiple vls are reserved), as well as the SiFive extensions and
XTHeadVdot.
2024-08-05 12:08:03 +08:00
Sergei Barannikov
25bea3eb03
[MC] Forward declare ELFObjectWriter (#100989) 2024-07-30 10:40:40 +03:00
Fangrui Song
f9c349fd4c
[RISCV] Create mapping symbols with non-unique names
Similar to #99836 for AArch64.

Non-unique names save .strtab space and match GNU assembler.

Pull Request: https://github.com/llvm/llvm-project/pull/99903
2024-07-22 23:07:27 -07:00
Fangrui Song
99e6631e30 MCAssembler: Remove getWriterPtr
Commit 8728e097dfbec3630a1dd907431c0f14274a1ae8 (2018) introduced
getWriterPtr, which might be nullptr for MCAsmStreamer. This lured call
sites to use getWriterPtr when it's guaranteed to be non-null for
MCObjectstreamer. Remove this misleading API.
2024-07-22 22:31:08 -07:00
Fangrui Song
c473e75ade MCAssmembler: Move ELFHeaderEFlags to ELFObjectWriter
Now that MCELFStreamer can access ELFObjectWriter (commit
70c52b62c5669993e341664a63bfbe5245e32884), we can move ELFHeaderEFlags
there.
2024-07-22 18:20:18 -07: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
Tristan Ross
810adbaa02
[RISCV] Remove unused include in RISCVMCTargetDesc.h (#98790)
Goes in hand with #97130, split out to figure out CI fails. Should just
build whatever subprojects utilize the `RISCVMCTargetDesc.h` header and
it should build & test just like normal.

Co-authored-by: pca006132 <john.lck40@gmail.com>
2024-07-17 22:57:26 -07:00
Alex Bradbury
8687f7cd66
[RISCV] Support constant hoisting of immediate store values (#96073)
Previously getIntImmInstCost only calculated the cost of materialising
the argument of a store if it was the address. This means
ConstantHoisting's transformation wouldn't kick in for cases like
storing two values that require multiple instructions to materialise but
where one can be cheaply generated from the other (e.g. by an addition).

Two key changes were needed to avoid regressions when enabling this:
* Allowing constant materialisation cost to be calculated assuming
zeroes are free (as might happen if you had a 2*XLEN constant and one
half is zero).
* Avoiding constant hoisting if we have a misaligned store that's going
to be a legalised to a sequence of narrower stores. I'm seeing cases
where hoisting the constant ends up with worse codegen in that case.

Out of caution and so as not to unexpectedly degrade other existing hoisting logic, FreeZeroes is used only for the new cost calculations for the load instruction. It would likely make sense to revisit this later.
2024-07-17 15:19:31 +01:00
Garvit Gupta
062844615d
[RISCV] Enable framework to resolve encoding conflicts among vendor-specific CSRs (#97287)
This PR is a follow-up of PR #96174 which added the framework to resolve
encoding conflicts among vendor specific CSRs. This PR explicitly
enables this only for the RISCV target.
2024-07-11 20:12:17 -07:00
R
3c5f929ad0
[RISCV] Add QingKe "XW" compressed opcode extension (#97925)
This extension consists of 8 additional 16-bit compressed forms for
existing standard load/store opcodes.

These opcodes are found in some RISC-V microcontrollers from WCH /
Nanjing Qinheng Microelectronics.

As discussed in the Discourse forums, this uses incompatible extension
and opcode names vs the vendor binary toolchain. The chosen names
instead follow the conventions for other vendor extensions listed on the
"riscv-non-isa" project.
2024-07-11 11:10:02 +08:00
Yingwei Zheng
2a086dce69
[RISCV][MC] Add support for hardcode encoding of .insn directive (#98030)
This patch adds support for the following two hardcode encodings of
.insn directive:
```
.insn <insn-length>, <value>
.insn <value>
```

See also gas's patch
a262b82fdb
NOTE: This patch doesn't support long instructions. 

Closes https://github.com/llvm/llvm-project/issues/97498.
2024-07-10 00:39:51 +08:00
Paul Kirth
a4fec164bf
Reapply "[llvm][RISCV] Enable trailing fences for seq-cst stores by default (#87376)" (#90267)
With the tag merging in place, we can safely change the default for
+seq-cst-trailing-fence to the default, according to the recommendation
in
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-atomic.adoc

This patch changes the default for the feature flag, and moves to more
consistent naming with respect to existing features.

This was reverted with https://github.com/llvm/llvm-project/pull/84597,
because ld.bfd would segfault with unknown riscv attributes. Now that
attributes emission is guarded with a backend flag,
`--riscv-abi-attributes`, this should be safe to reland, since it won't 
introduce abi tags unless the user opts into them.
2024-07-08 13:35:36 -07:00
Paul Kirth
b146a57f67
Reapply "[RISCV] Support RISCV Atomics ABI attributes (#84597)"
This patch adds support for the atomic_abi attribute, specifid in
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#tag_riscv_atomic_abi-14-uleb128version.

This was previously reverted due to ld.bfd segfaulting w/ unknown riscv
attributes. Attribute emission is now guarded by a backend flag
`--riscv-abi-attributes`, which is off by default. Linker support in
LLD for attribute merging is now in a standalone patch.

Reviewers: kito-cheng, MaskRay, asb

Reviewed By: MaskRay

Pull Request: https://github.com/llvm/llvm-project/pull/90266
2024-07-02 08:23:03 -07:00
Fangrui Song
057f28be3e [MC] Remove unused MCAsmLayout declarations and includes 2024-07-01 17:47:13 -07:00
Fangrui Song
bd3215149a MCExpr::evaluateKnownAbsolute: replace the MCAsmLayout parameter with MCAssembler
and add a comment.
2024-07-01 16:45:57 -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
78804f891c [MC] Remove the evaluateAsAbsolute overload that takes a MCAsmLayout parameter
Continue the MCAsmLayout removal work started by 67957a45ee1ec42ae1671cdbfa0d73127346cc95.
2024-07-01 15:38:18 -07:00
Fangrui Song
8f7887ad53 [MC] Remove the MCAsmLayout parameter from MCAsmBackend::relax*
finishLayout is now the only member function that has a MCAsmLayout
parameter.
2024-07-01 14:36:25 -07:00