This finishes the work of replacing OperandMatchResultTy with
ParseStatus, started in D154101.
As a drive-by change, rename some RegNo variables to just Reg
(a leftover from the days when RegNo had 'unsigned' type).
This patch defines the `LVZ` and `LBT` extension instructions, which
provide enough definitions for llvm-mc and llvm-objdump to correctly
handle these instructions.
It also defines the `SCR` (Scratchpad Register) register class, which
are used by the `LBT` extension instructions.
Reviewed By: SixWeining, xen0n
Differential Revision: https://reviews.llvm.org/D155917
This patch adds the definition for the `LSX` registers and instructions.
It also adds handling for new immediate operands in the AsmParser. This
patch ensures that llvm-mc and llvm-objdump correctly handle the `LSX`
instructions.
We expand those pseudo-instructions `vrepli.{b,h,w,d}` in the
MCCodeEmitter. This increases the readability of the output when
generating assembly files.
Reviewed By: SixWeining
Differential Revision: https://reviews.llvm.org/D154183
Remove overrides of parseDirective that unconditionally return NoMatch.
This is what the base implementation does.
This is a follow-up to D154101 based on post-commit review feedback.
ParseStatus is slightly more convenient to use due to implicit
conversion from bool, which allows to do something like:
```
return Error(L, "msg");
```
when with MatchOperandResultTy it had to be:
```
Error(L, "msg");
return MatchOperand_ParseFail;
```
It also has more appropriate name since parse* methods are not only for
parsing operands.
Reviewed By: xen0n
Differential Revision: https://reviews.llvm.org/D154318
Conventionally, parsing methods return false on success and true on
error. However, directive parsing methods need a third state: the
directive is not target specific. AsmParser::parseStatement detected
this case by using a fragile heuristic: if the target parser did not
consume any tokens, the directive is assumed to be not target-specific.
Some targets fail to follow the convention: they return success after
emitting an error or do not consume the entire line and return failure
on successful parsing. This was partially worked around by checking for
pending errors in parseStatement.
This patch tries to improve the situation by introducing parseDirective
method that returns ParseStatus -- three-state class. The new method
should eventually replace the old one returning bool.
ParseStatus is intentionally implicitly constructible from bool to allow
uses like `return Error(Loc, "message")`. It also has a potential to
replace OperandMatchResulTy as it is more convenient to use due to the
implicit construction from bool and more type safe.
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D154101
With this fix, when encountering an out-of-range uimm8 operand, the code
now triggers an appropriate error message, clearly indicating that the
immediate value must be an integer within the range of 0 to 255.
Currently, gcc-13 will generate such assembly when `-mcmodel=medium`,
which is ostensibly a dirty hack to allow bigger offsets for extern
function calls without having to add more reloc types. This is not the
best way to accomplish the original goal, but such usages will appear
soon and we have to support it anyway.
Example:
```c
extern int foo(int);
int bar(int x) {
return foo(x + 123);
}
```
will produce the following (simplified) assembly when compiled with
`-O2 -mcmodel=medium`:
```
.globl bar
.type bar, @function
bar:
.cfi_startproc
addi.w $r4,$r4,123
pcalau12i $r12,%pc_hi20(foo)
jirl $r0,$r12,%pc_lo12(foo)
.cfi_endproc
```
Reviewed By: SixWeining, wangleiat, MaskRay, xry111
Differential Revision: https://reviews.llvm.org/D142278
In order to be compatible with the form of the atomic instruction in
GAS that accepts the fourth operand as 0 (i.e. `am* $rd, $rk, $rj, 0`),
we need to treat `$rj, 0` as one operand, but only print `$rj`.
For this, the number of result operands of inline assembly memory
operand `ZB` constraint is modified to 2 (reg + 0).
Restrictions on register usage in `am*` instructions have also been
adjusted. When `$rd` is equal to `$r0`, the instruction must be
considered legal, because of some special usage like `PseudoUNIMP`.
Reviewed By: SixWeining, xen0n
Differential Revision: https://reviews.llvm.org/D139303
The `li.[wd]` pseudo instructions are used to load an immediate value
into a GPR. These expand directly during asm parsing. As the result,
only real MC instructions are emitted to the MCStreamer. The actual
expansion to real instructions is similar to the expansion performed by
the GAS.
Note: The `li.w` always treats the imm operand as a 32-bit signed value.
Reviewed By: SixWeining
Differential Revision: https://reviews.llvm.org/D138086
This patch makes `IAS` compatible with `GAS`. It accepts `la*` pseudo
instructions, and expands `la{,.local,.global}` into different
instructions according to different features.
```
Default:
la = la.global = la.got
la.local = la.pcrel
With feature "+la-global-with-pcrel":
la = la.global = la.pcrel
With feature "+la-global-with-abs":
la = la.global = la.abs
With feature "+la-local-with-abs":
la.local = la.abs
With features "+la-global-with-pcrel,+la-global-with-abs"(disorder):
la = la.global = la.pcrel
```
Note: To keep consistent with `GAS` behavior, the "la" can only have
one register operand.
Reviewed By: SixWeining
Differential Revision: https://reviews.llvm.org/D138021
Do this check because the ISA manual says (edited from the original translation):
> If the AM* instruction has its rd == rj, an Instruction Non-defined Exception will be triggered when the instruction is executed.
>
> If the AM* instruction has its rd == rk, the execution result is unpredictable. It is software's responsibility to avoid this situation.
Note that binutils does the same check except when rd == r0 but this
is undocumented.
Differential Revision: https://reviews.llvm.org/D136076
This patch makes the assembler support all modifiers defined in gnu-as.
Also changes some diagnostic information.
Differential Revision: https://reviews.llvm.org/D132633
This patch only add %pc_hi20/%pc_lo12/%plt relocations in order
to be able to generate gnu ld linkable relocation file for the
`hello world` IR :
```
@.str = private unnamed_addr constant [14 x i8] c"Hello world!\0A\00", align 1
define dso_local signext i32 @main() nounwind {
entry:
%call = call signext i32 (ptr, ...) @printf(ptr noundef @.str)
ret i32 0
}
declare dso_local signext i32 @printf(ptr noundef, ...)
```
This patch also updates some test cases due to new modifiers introduced.
New test: test/MC/LoongArch/Relocations/relocations.s
Differential Revision: https://reviews.llvm.org/D132108
These instructions are added by following the `LoongArch Reference
Manual Volume 1: Basic Architecture Version 1.00`.
Differential Revision: https://reviews.llvm.org/D124826
These instructions are added by following the `LoongArch Reference
Manual Volume 1: Basic Architecture Version 1.00`.
Differential Revision: https://reviews.llvm.org/D123988
This patch adds basic support to AsmParser which can handle basic
instructions with register or immediate operands. With the addition of
the parser, now it's possible to test instructions encoding with `llvm-mc`.
Disassembler will be added later and then we can do `round-trip` test.
Reviewed By: xen0n, MaskRay, myhsu
Differential Revision: https://reviews.llvm.org/D120476