Commit Graph

74 Commits

Author SHA1 Message Date
gonglingqin a9d46d9af3 [LoongArch] Add codegen support for fabs
Differential Revision: https://reviews.llvm.org/D131871
2022-08-16 14:41:27 +08:00
Weining Lu d1f36da9e0 [LoongArch] Encode LoongArch specific ELF e_flags to binary by LoongArchTargetStreamer
Reference: https://github.com/loongson/LoongArch-Documentation
The last commit hash (main branch) is:
99016636af64d02dee05e39974d4c1e55875c45b

Note:
There are several PRs [1][2][3] that may affect the e_flags.
After they got closed or merged, we should update the implementation here accordingly.

[1] https://github.com/loongson/LoongArch-Documentation/pull/33
[2] https://github.com/loongson/LoongArch-Documentation/pull/47
[2] https://github.com/loongson/LoongArch-Documentation/pull/61

Differential Revision: https://reviews.llvm.org/D130239
2022-08-16 13:41:50 +08:00
gonglingqin 9e09c3186e [LoongArch] Add codegen support for ISD::CTPOP, ISD::CTTZ and ISD::CTLZ
Differential Revision: https://reviews.llvm.org/D131550
2022-08-12 14:15:30 +08:00
Weining Lu 40f1f9b357 [LoongArch] Return null SDValue by default in LowerOperation. NFC
Differential Revision: https://reviews.llvm.org/D131546
2022-08-12 12:09:08 +08:00
wanglei c437412fbc [LoongArch] Override TargetLowering::isOffsetFoldingLegal()
This patch disable GlobalAddress+Offset folding.

Differential Revision: https://reviews.llvm.org/D131491
2022-08-11 11:26:54 +08:00
WANG Xuerui ed078c48f0 [LoongArch] Add insn aliases `jr` and `ret`
Differential Revision: https://reviews.llvm.org/D131512
2022-08-11 10:02:45 +08:00
WANG Xuerui 326f7aed38 [LoongArch] Add codegen support for bitreverse
Differential Revision: https://reviews.llvm.org/D131378
2022-08-11 08:55:14 +08:00
gonglingqin cf75ef460c [LoongArch] Add codegen support for ISD::ROTL and ISD::ROTR
Differential Revision: https://reviews.llvm.org/D131231
2022-08-09 19:39:17 +08:00
WANG Xuerui 7d48a9e1ae [LoongArch] Support register-register-addressed GPR loads/stores
Differential Revision: https://reviews.llvm.org/D131380
2022-08-09 19:13:36 +08:00
gonglingqin d3580c2eb6 [LoongArch] Add codegen support for not
Differential Revision: https://reviews.llvm.org/D131384
2022-08-09 14:05:09 +08:00
wanglei 8716513e65 [LoongArch] Implement branch analysis
This allows a number of optimisation passes to work.
E.g. BranchFolding and MachineBlockPlacement.

Differential Revision: https://reviews.llvm.org/D131316
2022-08-09 14:03:09 +08:00
WANG Xuerui f35cb7ba34 [LoongArch] Add codegen support for bswap
Differential Revision: https://reviews.llvm.org/D131352
2022-08-09 13:42:03 +08:00
wanglei 0c2b738f8f [LoongArch] Support for varargs
This patch ensures the `$fp` always points to the bottom of the vararg
spill region.
Includes support for expand `ISD::DYNAMIC_STACKALLOC`.

Differential Revision: https://reviews.llvm.org/D130250
2022-08-08 14:01:24 +08:00
wanglei 57eb77d411 [LoongArch] Implement more of the ABI
According to the description of the LoongArch abi documentation,
(https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html)
the calling convention of LoongArch is almost the same as the RISCV's
(except for the vector part), so we borrow the implementation of RISCV.

This patch only guarantees the correctness of lp64d, because only the
part of lp64d is described in detail in the documentation.

Differential Revision: https://reviews.llvm.org/D130249
2022-08-05 15:14:16 +08:00
wanglei 56ab2f4ccd [LoongArch] Offset folding for frameindex
This patch is for frameindex calculations.

Differential Revision: https://reviews.llvm.org/D130248
2022-07-29 17:27:34 +08:00
wanglei fd6545322c [LoongArch] Refactor insertDivByZeroTrap
Ensure non-terminators don't follow terminators.
This patch fixes the `sdiv-udiv-srem-urem.ll` test failure with
expensive check.

Differential Revision: https://reviews.llvm.org/D130247
2022-07-29 17:06:49 +08:00
Weining Lu 904a87ace3 [LoongArch] Use `end namespace xxx` style comment. NFC 2022-07-26 15:01:29 +08:00
Fangrui Song 9742166935 [LoongArch] Support load/store of dso_local PIC global values
lowerGlobalAddress added by D128427 can be used for PIC. The actual condition is
that the global value needs to be dso_local (a dso_preemptable one needs GOT
indirection).

load-store.ll has UB due to out-of-bounds load/store. Fix the UB in the variable
test and add an array test. Note: NOPIC array index is currently wrong.

Reviewed By: wangleiat

Differential Revision: https://reviews.llvm.org/D129977
2022-07-21 19:37:56 -07:00
Fangrui Song 3c849d0aef Modernize Optional::{getValueOr,hasValue} 2022-07-15 01:20:39 -07:00
Weining Lu 9b87ad33c1 [LoongArch] Implement OR combination to generate bstrins.w/d
Differential Revision: https://reviews.llvm.org/D129357
2022-07-14 17:20:43 +08:00
David Green 3e0bf1c7a9 [CodeGen] Move instruction predicate verification to emitInstruction
D25618 added a method to verify the instruction predicates for an
emitted instruction, through verifyInstructionPredicates added into
<Target>MCCodeEmitter::encodeInstruction. This is a very useful idea,
but the implementation inside MCCodeEmitter made it only fire for object
files, not assembly which most of the llvm test suite uses.

This patch moves the code into the <Target>_MC::verifyInstructionPredicates
method, inside the InstrInfo.  The allows it to be called from other
places, such as in this patch where it is called from the
<Target>AsmPrinter::emitInstruction methods which should trigger for
both assembly and object files. It can also be called from other places
such as verifyInstruction, but that is not done here (it tends to catch
errors earlier, but in reality just shows all the mir tests that have
incorrect feature predicates). The interface was also simplified
slightly, moving computeAvailableFeatures into the function so that it
does not need to be called externally.

The ARM, AMDGPU (but not R600), AVR, Mips and X86 backends all currently
show errors in the test-suite, so have been disabled with FIXME
comments.

Recommitted with some fixes for the leftover MCII variables in release
builds.

Differential Revision: https://reviews.llvm.org/D129506
2022-07-14 09:33:28 +01:00
David Green 95252133e1 Revert "Move instruction predicate verification to emitInstruction"
This reverts commit e2fb8c0f4b as it does
not build for Release builds, and some buildbots are giving more warning
than I saw locally. Reverting to fix those issues.
2022-07-13 13:28:11 +01:00
David Green e2fb8c0f4b Move instruction predicate verification to emitInstruction
D25618 added a method to verify the instruction predicates for an
emitted instruction, through verifyInstructionPredicates added into
<Target>MCCodeEmitter::encodeInstruction. This is a very useful idea,
but the implementation inside MCCodeEmitter made it only fire for object
files, not assembly which most of the llvm test suite uses.

This patch moves the code into the <Target>_MC::verifyInstructionPredicates
method, inside the InstrInfo.  The allows it to be called from other
places, such as in this patch where it is called from the
<Target>AsmPrinter::emitInstruction methods which should trigger for
both assembly and object files. It can also be called from other places
such as verifyInstruction, but that is not done here (it tends to catch
errors earlier, but in reality just shows all the mir tests that have
incorrect feature predicates). The interface was also simplified
slightly, moving computeAvailableFeatures into the function so that it
does not need to be called externally.

The ARM, AMDGPU (but not R600), AVR, Mips and X86 backends all currently
show errors in the test-suite, so have been disabled with FIXME
comments.

Differential Revision: https://reviews.llvm.org/D129506
2022-07-13 12:53:32 +01:00
gonglingqin 47f3dc6d49 [LoongArch] Add codegen support for atomic fence, atomic load and atomic store
Differential Revision: https://reviews.llvm.org/D128901
2022-07-13 15:25:45 +08:00
gonglingqin e147a0f65a [LoongArch] Add codegen support for converting between unsigned integer and floating-point
Differential Revision: https://reviews.llvm.org/D128900
2022-07-13 15:25:44 +08:00
gonglingqin 1df96ce518 [LoongArch] Add codegen support for fpround, fpextend and converting between signed integer and floating-point
Differential Revision: https://reviews.llvm.org/D128899
2022-07-13 15:25:43 +08:00
Weining Lu 1d27f26426 [LoongArch] Add codegen support for multiplication operations
Reference:
https://llvm.org/docs/LangRef.html#mul-instruction

Differential Revision: https://reviews.llvm.org/D128194
2022-07-08 17:15:17 +08:00
gonglingqin aeaca854d1 [LoongArch] Add codegen support for handling floating point immediates
Differential Revision: https://reviews.llvm.org/D128898
2022-07-07 08:13:33 +08:00
Weining Lu d29215790f [LoongArch] Add codegen support for division operations
These operations include sdiv/udiv/srem/urem.

As the ISA [https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#_div_wudu_mod_wudu]
described, when the divisor is 0, the result can be any value, but no
exception will be triggered. Unlike gcc, which by default emit code
that checks divide-by-zero after the division or modulus instruction,
we only emit this check when the `-loongarch-check-zero-division`
option is passed.

Differential Revision: https://reviews.llvm.org/D128572
2022-07-06 17:54:57 +08:00
wanglei c2d1d9f942 [LoongArch] Implement prologue/epilogue insertion
Differential Revision: https://reviews.llvm.org/D128432
2022-07-06 15:52:26 +08:00
wanglei 5b1ec70590 [LoongArch] Support lowering FrameIndex
Ensure callee-saved registers are accessed relative to the stackpointer.

Differential Revision: https://reviews.llvm.org/D128430
2022-07-06 15:40:43 +08:00
wanglei 3610d5f5d4 [LoongArch] Add initial support for function calls
Note that this is just enough for simple function call examples to
generate working code.

A good portion of this patch is the extra functions that needed to be
implemented to support the test case. e.g. storeRegToStackSlot,
loadRegFromStackSlot, eliminateFrameIndex.

Differential Revision: https://reviews.llvm.org/D128429
2022-07-05 12:02:14 +08:00
wanglei b940fe6fe2 [LoongArch] Add codegen support for conditional branches
Setting ISD::BR_CC to Expand makes it much easier to deal with
matching the expanded form.

Differential Revision: https://reviews.llvm.org/D128428
2022-07-05 11:59:58 +08:00
wanglei 5b4851ed91 [LoongArch] Add codegen support for load/store operations
This patch also support lowering global addresses.

Differential Revision: https://reviews.llvm.org/D128427
2022-07-05 11:58:20 +08:00
Weining Lu 20e6ada2fb [LoongArch] Combine ((x & shifted_mask) >> shamt) to bstrpick.{w/d}
This is an improvement to LoongArch codegen. In D127206 we combined
((x >> shamt) & shifted_mask) to bstrpick and here we do a similar
combination when certain conditions are met.

Thanks to @xen0n for reminding me.

Differential Revision: https://reviews.llvm.org/D128191
2022-06-23 17:10:06 +08:00
Weining Lu cf71f97bb1 [LoongArch] Add codegen support for part of conversion operations
These operations include `sext`, `zext` and `trunc`.

Reference:
https://llvm.org/docs/LangRef.html#conversion-operations

Differential Revision: https://reviews.llvm.org/D127204
2022-06-20 10:00:20 +08:00
Weining Lu 2ef7c4ce46 [LoongArch] Perform `and` combination with a shifted mask
Differential Revision: https://reviews.llvm.org/D127206
2022-06-20 09:58:17 +08:00
Weining Lu 709e4ad0d9 [LoongArch] Add codegen support for the bitwise binary operations and part of other operations
Reference:
https://llvm.org/docs/LangRef.html#bitwise-binary-operations
https://llvm.org/docs/LangRef.html#other-operations

The reason why other operations are implemented here is that some
bitwise binary operations depend on them. For example, on loongarch32,
`shl` over i64 data requires `select`.

Differential Revision: https://reviews.llvm.org/D127203
2022-06-20 09:54:38 +08:00
Weining Lu efc70058d9 [LoongArch] Add codegen support for fneg
Reference:
https://llvm.org/docs/LangRef.html#fneg-instruction

Differential Revision: https://reviews.llvm.org/D127200
2022-06-20 09:47:23 +08:00
Weining Lu a992115545 [LoongArch] Add codegen support for the binary operations
These binary operations include sub/fadd/fsub/fmul/fdiv. Others ops
like mul/udiv/sdiv/urem/srem would be added later since they depend on
`shift` and `truncate` that have not been supported.

Note `add` has been added in a previous patch.

Reference:
https://llvm.org/docs/LangRef.html#binary-operations

Differential Revision: https://reviews.llvm.org/D127199
2022-06-20 09:43:36 +08:00
Weining Lu 70f2befaf7 [LoongArch] Use register R0 (ZERO) for constant 0
Differential Revision: https://reviews.llvm.org/D127205
2022-06-16 13:43:11 +08:00
Weining Lu 45963ae06d [LoongArch] clang-format some code in LoongArchISelLowering.cpp. NFC 2022-06-12 10:41:56 +08:00
Weining Lu 229e08ce99 [LoongArch] Remove unnecessary `static` keyword as `const` has internal linkage. NFC
See https://reviews.llvm.org/D127199#inline-1222815
2022-06-12 10:05:47 +08:00
Matt Arsenault cc5a1b3dd9 llvm-reduce: Add cloning of target MachineFunctionInfo
MIR support is totally unusable for AMDGPU without this, since the set
of reserved registers is set from fields here.

Add a clone method to MachineFunctionInfo. This is a subtle variant of
the copy constructor that is required if there are any MIR constructs
that use pointers. Specifically, at minimum fields that reference
MachineBasicBlocks or the MachineFunction need to be adjusted to the
values in the new function.
2022-06-07 10:14:48 -04:00
Weining Lu cfeacec833 [LoongArch] Add the missing ld.d instruction definition 2022-06-02 14:57:23 +08:00
Weining Lu 8a1250f958 [LoongArch] Fix register type in FCMP_*_D instructions definition
The correct type is FPR64 but not FPR32.
2022-06-02 14:21:58 +08:00
Sheng c644488a8b Rename `MCFixedLenDisassembler.h` as `MCDecoderOps.h`
The name `MCFixedLenDisassembler.h` is out of date after D120958.

Rename it as `MCDecoderOps.h` to reflect the change.

Reviewed By: myhsu

Differential Revision: https://reviews.llvm.org/D124987
2022-05-15 08:44:58 +08:00
Weining Lu 11ec7307a3 [LoongArch] Add privilege instructions definition
These instructions are added by following the `LoongArch Reference
Manual Volume 1: Basic Architecture Version 1.00`.

Differential Revision: https://reviews.llvm.org/D124826
2022-05-14 17:46:02 +08:00
Weining Lu 24532d05f8 [LoongArch] Check msb is not less than lsb for the bstr{ins/pick}.{w/d} instructions
Differential Revision: https://reviews.llvm.org/D124825
2022-05-12 09:31:44 +08:00
Weining Lu 3a49ad717c [LoongArch] Add basic floating-point instructions definition
These instructions are added by following the `LoongArch Reference
Manual Volume 1: Basic Architecture Version 1.00`.

Differential Revision: https://reviews.llvm.org/D123988
2022-04-21 10:04:20 +08:00