-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RISCV] Support .option rvc and norvc assembler directives
These directives allow the 'C' (compressed) extension to be enabled/disabled within a single file. Differential Revision: https://reviews.llvm.org/D45864 Patch by Kito Cheng git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332107 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
10 changed files
with
260 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; RUN: llc -mtriple=riscv32 -mattr=+c -filetype=obj < %s\ | ||
; RUN: | llvm-objdump -triple=riscv32 -mattr=+c -d -riscv-no-aliases -\ | ||
; RUN: | FileCheck -check-prefix=CHECK %s | ||
|
||
; This test demonstrates that .option norvc has no effect on codegen when | ||
; emitting an ELF directly. | ||
|
||
define i32 @add(i32 %a, i32 %b) nounwind { | ||
; CHECK-LABEL: add: | ||
; CHECK: c.add a0, a1 | ||
; CHECK-NEXT: c.jr ra | ||
tail call void asm sideeffect ".option norvc", ""() | ||
%add = add nsw i32 %b, %a | ||
ret i32 %add | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; RUN: llc -mtriple=riscv32 -filetype=obj < %s\ | ||
; RUN: | llvm-objdump -triple=riscv32 -mattr=+c -d -riscv-no-aliases -\ | ||
; RUN: | FileCheck -check-prefix=CHECK %s | ||
|
||
; This test demonstrates that .option norvc has no effect on codegen when | ||
; emitting an ELF directly. | ||
|
||
define i32 @add(i32 %a, i32 %b) nounwind { | ||
; CHECK-LABEL: add: | ||
; CHECK: add a0, a1, a0 | ||
; CHECK-NEXT: jalr zero, ra, 0 | ||
tail call void asm sideeffect ".option rvc", ""() | ||
%add = add nsw i32 %b, %a | ||
ret i32 %add | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# RUN: not llvm-mc -triple riscv32 < %s 2>&1 \ | ||
# RUN: | FileCheck -check-prefixes=CHECK %s | ||
|
||
# CHECK: error: unexpected token, expected identifier | ||
.option | ||
|
||
# CHECK: error: unexpected token, expected identifier | ||
.option 123 | ||
|
||
# CHECK: error: unexpected token, expected identifier | ||
.option "str" | ||
|
||
# CHECK: error: unexpected token, expected end of statement | ||
.option rvc foo | ||
|
||
# CHECK: warning: unknown option, expected 'rvc' or 'norvc' | ||
.option bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# RUN: llvm-mc -triple riscv32 -show-encoding < %s \ | ||
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-ALIAS %s | ||
# RUN: llvm-mc -triple riscv32 -show-encoding \ | ||
# RUN: -riscv-no-aliases <%s | FileCheck -check-prefixes=CHECK,CHECK-INST %s | ||
# RUN: llvm-mc -triple riscv32 -filetype=obj < %s \ | ||
# RUN: | llvm-objdump -triple riscv32 -mattr=+c -d - \ | ||
# RUN: | FileCheck -check-prefixes=CHECK-BYTES,CHECK-ALIAS %s | ||
# RUN: llvm-mc -triple riscv32 -filetype=obj < %s \ | ||
# RUN: | llvm-objdump -triple riscv32 -mattr=+c -d -riscv-no-aliases - \ | ||
# RUN: | FileCheck -check-prefixes=CHECK-BYTES,CHECK-INST %s | ||
|
||
# RUN: llvm-mc -triple riscv64 -show-encoding < %s \ | ||
# RUN: | FileCheck -check-prefixes=CHECK-ALIAS %s | ||
# RUN: llvm-mc -triple riscv64 -show-encoding \ | ||
# RUN: -riscv-no-aliases <%s | FileCheck -check-prefixes=CHECK-INST %s | ||
# RUN: llvm-mc -triple riscv64 -filetype=obj < %s \ | ||
# RUN: | llvm-objdump -triple riscv64 -mattr=+c -d - \ | ||
# RUN: | FileCheck -check-prefixes=CHECK-BYTES,CHECK-ALIAS %s | ||
# RUN: llvm-mc -triple riscv64 -filetype=obj < %s \ | ||
# RUN: | llvm-objdump -triple riscv64 -mattr=+c -d -riscv-no-aliases - \ | ||
# RUN: | FileCheck -check-prefixes=CHECK-BYTES,CHECK-INST %s | ||
|
||
# CHECK-BYTES: 13 85 05 00 | ||
# CHECK-ALIAS: mv a0, a1 | ||
# CHECK-INST: addi a0, a1, 0 | ||
# CHECK: # encoding: [0x13,0x85,0x05,0x00] | ||
addi a0, a1, 0 | ||
|
||
# CHECK-BYTES: 13 04 c1 3f | ||
# CHECK-ALIAS: addi s0, sp, 1020 | ||
# CHECK-INST: addi s0, sp, 1020 | ||
# CHECK: # encoding: [0x13,0x04,0xc1,0x3f] | ||
addi s0, sp, 1020 | ||
|
||
|
||
# CHECK: .option rvc | ||
.option rvc | ||
# CHECK-BYTES: 2e 85 | ||
# CHECK-ALIAS: add a0, zero, a1 | ||
# CHECK-INST: c.mv a0, a1 | ||
# CHECK: # encoding: [0x2e,0x85] | ||
addi a0, a1, 0 | ||
|
||
# CHECK-BYTES: e0 1f | ||
# CHECK-ALIAS: addi s0, sp, 1020 | ||
# CHECK-INST: c.addi4spn s0, sp, 1020 | ||
# CHECK: # encoding: [0xe0,0x1f] | ||
addi s0, sp, 1020 | ||
|
||
# CHECK: .option norvc | ||
.option norvc | ||
# CHECK-BYTES: 13 85 05 00 | ||
# CHECK-ALIAS: mv a0, a1 | ||
# CHECK-INST: addi a0, a1, 0 | ||
# CHECK: # encoding: [0x13,0x85,0x05,0x00] | ||
addi a0, a1, 0 | ||
|
||
# CHECK-BYTES: 13 04 c1 3f | ||
# CHECK-ALIAS: addi s0, sp, 1020 | ||
# CHECK-INST: addi s0, sp, 1020 | ||
# CHECK: # encoding: [0x13,0x04,0xc1,0x3f] | ||
addi s0, sp, 1020 | ||
|
||
# CHECK: .option rvc | ||
.option rvc | ||
# CHECK-BYTES: 2e 85 | ||
# CHECK-ALIAS: add a0, zero, a1 | ||
# CHECK-INST: c.mv a0, a1 | ||
# CHECK: # encoding: [0x2e,0x85] | ||
addi a0, a1, 0 | ||
|
||
# CHECK-BYTES: e0 1f | ||
# CHECK-ALIAS: addi s0, sp, 1020 | ||
# CHECK-INST: c.addi4spn s0, sp, 1020 | ||
# CHECK: # encoding: [0xe0,0x1f] | ||
addi s0, sp, 1020 | ||
|
||
# CHECK: .option norvc | ||
.option norvc | ||
# CHECK-BYTES: 13 85 05 00 | ||
# CHECK-ALIAS: mv a0, a1 | ||
# CHECK-INST: addi a0, a1, 0 | ||
# CHECK: # encoding: [0x13,0x85,0x05,0x00] | ||
addi a0, a1, 0 | ||
|
||
# CHECK-BYTES: 13 04 c1 3f | ||
# CHECK-ALIAS: addi s0, sp, 1020 | ||
# CHECK-INST: addi s0, sp, 1020 | ||
# CHECK: # encoding: [0x13,0x04,0xc1,0x3f] | ||
addi s0, sp, 1020 |