-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[RISCV] Support .option {no}exact #122483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
8d8ed46
eba37b2
f6b0186
546f52c
3d9113d
dece4a6
c70f679
4e2aaee
b832095
32f3944
8133e9d
3fc5749
c8bf695
7dc2322
61bdfeb
2c62a5b
318afee
58a0f1b
a764474
859b430
6c10814
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -344,6 +344,10 @@ std::pair<bool, bool> RISCVAsmBackend::relaxLEB128(const MCAssembler &Asm, | |
| // Given a compressed control flow instruction this function returns | ||
| // the expanded instruction. | ||
| unsigned RISCVAsmBackend::getRelaxedOpcode(unsigned Op) const { | ||
| // Disable relaxation if FeatureExactAssembly | ||
| if (STI.hasFeature(RISCV::FeatureExactAssembly)) | ||
|
||
| return Op; | ||
|
|
||
| switch (Op) { | ||
| default: | ||
| return Op; | ||
|
|
@@ -371,6 +375,12 @@ unsigned RISCVAsmBackend::getRelaxedOpcode(unsigned Op) const { | |
|
|
||
| bool RISCVAsmBackend::mayNeedRelaxation(const MCInst &Inst, | ||
| const MCSubtargetInfo &STI) const { | ||
| // This function has access to two STIs, the member of the AsmBackend, and the | ||
| // one passed as an argument. The latter is more specific, so we query it for | ||
| // specific features. | ||
| if (STI.hasFeature(RISCV::FeatureExactAssembly)) | ||
| return false; | ||
|
|
||
| return getRelaxedOpcode(Inst.getOpcode()) != Inst.getOpcode(); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -254,7 +254,9 @@ void RISCVAsmPrinter::LowerSTATEPOINT(MCStreamer &OutStreamer, StackMaps &SM, | |
| bool RISCVAsmPrinter::EmitToStreamer(MCStreamer &S, const MCInst &Inst, | ||
| const MCSubtargetInfo &SubtargetInfo) { | ||
| MCInst CInst; | ||
| bool Res = RISCVRVC::compress(CInst, Inst, SubtargetInfo); | ||
| bool Res = false; | ||
| if (!SubtargetInfo.hasFeature(RISCV::FeatureExactAssembly)) | ||
|
||
| Res = RISCVRVC::compress(CInst, Inst, SubtargetInfo); | ||
| if (Res) | ||
| ++RISCVNumInstrsCompressed; | ||
| S.emitInstruction(Res ? CInst : Inst, SubtargetInfo); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # RUN: llvm-mc -triple riscv32 -show-encoding -mattr=+c %s \ | ||
| # RUN: | FileCheck -check-prefixes=CHECK,CHECK-ALIAS %s | ||
| # RUN: llvm-mc -triple riscv32 -show-encoding -mattr=+c \ | ||
| # RUN: -M no-aliases %s | FileCheck -check-prefixes=CHECK,CHECK-INST %s | ||
| # RUN: llvm-mc -triple riscv32 -filetype=obj -mattr=+c %s \ | ||
| # RUN: | llvm-objdump --triple=riscv32 --mattr=+c --no-print-imm-hex -d - \ | ||
| # RUN: | FileCheck -check-prefixes=CHECK-BYTES,CHECK-ALIAS %s | ||
| # RUN: llvm-mc -triple riscv32 -filetype=obj -mattr=+c %s \ | ||
| # RUN: | llvm-objdump --triple=riscv32 --mattr=+c --no-print-imm-hex -d -M no-aliases - \ | ||
|
||
| # RUN: | FileCheck -check-prefixes=CHECK-BYTES,CHECK-INST %s | ||
|
|
||
| # RUN: llvm-mc -triple riscv64 -show-encoding -mattr=+c %s \ | ||
| # RUN: | FileCheck -check-prefixes=CHECK-ALIAS %s | ||
| # RUN: llvm-mc -triple riscv64 -show-encoding -mattr=+c \ | ||
| # RUN: -M no-aliases %s | FileCheck -check-prefixes=CHECK-INST %s | ||
| # RUN: llvm-mc -triple riscv64 -filetype=obj -mattr=+c %s \ | ||
| # RUN: | llvm-objdump --triple=riscv64 --mattr=+c --no-print-imm-hex -d - \ | ||
| # RUN: | FileCheck -check-prefixes=CHECK-BYTES,CHECK-ALIAS %s | ||
| # RUN: llvm-mc -triple riscv64 -filetype=obj -mattr=+c %s \ | ||
| # RUN: | llvm-objdump --triple=riscv64 --mattr=+c --no-print-imm-hex -d -M no-aliases - \ | ||
| # RUN: | FileCheck -check-prefixes=CHECK-BYTES,CHECK-INST %s | ||
|
|
||
|
|
||
| ## `.option exact` disables a variety of assembler behaviour: | ||
| ## - automatic compression | ||
| ## - branch relaxation (of short branches to longer equivalent sequences) | ||
| ## - linker relaxation (emitting R_RISCV_RELAX) | ||
| ## `.option noexact` enables these behaviours again. It is also the default. | ||
|
|
||
| ## This test only checks the automatic compression part of this behaviour. | ||
|
|
||
| # CHECK-BYTES: 4108 | ||
| # CHECK-INST: c.lw a0, 0(a0) | ||
| # CHECK-ALIAS: lw a0, 0(a0) | ||
| # CHECK: # encoding: [0x08,0x41] | ||
| lw a0, 0(a0) | ||
|
|
||
| # CHECK-BYTES: 4108 | ||
| # CHECK-INST: c.lw a0, 0(a0) | ||
| # CHECK-ALIAS: lw a0, 0(a0) | ||
| # CHECK: # encoding: [0x08,0x41] | ||
| c.lw a0, 0(a0) | ||
|
|
||
| # CHECK: .option exact | ||
| .option exact | ||
|
|
||
| # CHECK-BYTES: 00052503 | ||
| # CHECK-INST: lw a0, 0(a0) | ||
| # CHECK-ALIAS: lw a0, 0(a0) | ||
| # CHECK: # encoding: [0x03,0x25,0x05,0x00] | ||
| lw a0, 0(a0) | ||
|
|
||
| # CHECK-BYTES: 4108 | ||
| # CHECK-INST: c.lw a0, 0(a0) | ||
| # CHECK-ALIAS: lw a0, 0(a0) | ||
| # CHECK: # encoding: [0x08,0x41] | ||
| c.lw a0, 0(a0) | ||
|
|
||
| # CHECK: .option noexact | ||
| .option noexact | ||
|
|
||
| # CHECK-BYTES: 4108 | ||
| # CHECK-INST: c.lw a0, 0(a0) | ||
| # CHECK-ALIAS: lw a0, 0(a0) | ||
| # CHECK: # encoding: [0x08,0x41] | ||
| lw a0, 0(a0) | ||
|
|
||
| # CHECK-BYTES: 4108 | ||
| # CHECK-INST: c.lw a0, 0(a0) | ||
| # CHECK-ALIAS: lw a0, 0(a0) | ||
| # CHECK: # encoding: [0x08,0x41] | ||
| c.lw a0, 0(a0) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # RUN: llvm-mc -triple riscv32 -show-encoding -mattr=+relax %s \ | ||
| # RUN: | FileCheck -check-prefixes=CHECK-ASM %s | ||
| # RUN: llvm-mc -triple riscv32 -filetype=obj -mattr=+relax %s \ | ||
| # RUN: | llvm-objdump --triple=riscv32 --no-show-raw-insn -dr - \ | ||
| # RUN: | FileCheck -check-prefixes=CHECK-OBJDUMP %s | ||
|
|
||
| # RUN: llvm-mc -triple riscv64 -show-encoding -mattr=+relax %s \ | ||
| # RUN: | FileCheck -check-prefixes=CHECK-ASM %s | ||
| # RUN: llvm-mc -triple riscv64 -filetype=obj -mattr=+relax %s \ | ||
| # RUN: | llvm-objdump --triple=riscv64 --no-show-raw-insn -dr - \ | ||
| # RUN: | FileCheck -check-prefixes=CHECK-OBJDUMP %s | ||
|
|
||
| ## `.option exact` disables a variety of assembler behaviour: | ||
| ## - automatic compression | ||
| ## - branch relaxation (of short branches to longer equivalent sequences) | ||
| ## - linker relaxation (emitting R_RISCV_RELAX) | ||
| ## `.option noexact` enables these behaviours again. It is also the default. | ||
|
|
||
| ## This test only checks the branch and linker relaxation part of this behaviour. | ||
|
|
||
|
|
||
|
|
||
| # CHECK-ASM: call undefined | ||
| # CHECK-ASM-NEXT: fixup A - offset: 0, value: undefined, kind: fixup_riscv_call_plt | ||
| # CHECK-ASM-NEXT: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax | ||
| # CHECK-OBJDUMP: auipc ra, 0x0 | ||
| # CHECK-OBJDUMP-NEXT: R_RISCV_CALL_PLT undefined | ||
| # CHECK-OBJDUMP-NEXT: R_RISCV_RELAX *ABS* | ||
| # CHECK-OBJDUMP-NEXT: jalr ra | ||
| call undefined@plt | ||
|
|
||
| # CHECK-ASM: beq a0, a1, undefined | ||
| # CHECK-ASM-NEXT: fixup A - offset: 0, value: undefined, kind: fixup_riscv_branch | ||
| # CHECK-OBJDUMP: bne a0, a1, 0x10 | ||
| # CHECK-OBJDUMP-NEXT: j 0xc | ||
| # CHECK-OBJDUMP-NEXT: R_RISCV_JAL undefined | ||
| beq a0, a1, undefined | ||
|
|
||
| # CHECK-ASM: .option exact | ||
| .option exact | ||
|
|
||
| # CHECK-ASM: call undefined | ||
| # CHECK-ASM-NEXT: fixup A - offset: 0, value: undefined, kind: fixup_riscv_call_plt | ||
| # CHECK-ASM-NOT: fixup_riscv_relax | ||
| # CHECK-OBJDUMP: auipc ra, 0x0 | ||
| # CHECK-OBJDUMP-NEXT: R_RISCV_CALL_PLT undefined | ||
| # CHECK-OBJDUMP-NOT: R_RISCV_RELAX | ||
| # CHECK-OBJDUMP-NEXT: jalr ra | ||
| call undefined@plt | ||
|
|
||
| # CHECK-ASM: beq a0, a1, undefined | ||
| # CHECK-ASM-NEXT: fixup A - offset: 0, value: undefined, kind: fixup_riscv_branch | ||
| # CHECK-OBJDUMP: beq a0, a1, 0x18 | ||
| # CHECK-OBJDUMP-NEXT: R_RISCV_BRANCH undefined | ||
| beq a0, a1, undefined | ||
|
|
||
| # CHECK-ASM: .option noexact | ||
| .option noexact | ||
|
|
||
| # CHECK-ASM: call undefined | ||
| # CHECK-ASM-NEXT: fixup A - offset: 0, value: undefined, kind: fixup_riscv_call_plt | ||
| # CHECK-ASM-NEXT: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax | ||
| # CHECK-OBJDUMP: auipc ra, 0x0 | ||
| # CHECK-OBJDUMP-NEXT: R_RISCV_CALL_PLT undefined | ||
| # CHECK-OBJDUMP-NEXT: R_RISCV_RELAX *ABS* | ||
| # CHECK-OBJDUMP-NEXT: jalr ra | ||
| call undefined@plt | ||
|
|
||
| # CHECK-ASM: beq a0, a1, undefined | ||
| # CHECK-ASM-NEXT: fixup A - offset: 0, value: undefined, kind: fixup_riscv_branch | ||
| # CHECK-OBJDUMP: bne a0, a1, 0x2c | ||
| # CHECK-OBJDUMP-NEXT: j 0x28 | ||
| # CHECK-OBJDUMP-NEXT: R_RISCV_JAL undefined | ||
| beq a0, a1, undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while you're here. oxford comma
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Learnt, the community is a good place to learn new English phrases. :-)