Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RISCV] Support "call" pseudoinstruction in the MC layer
To do this: 1. Add PseudoCALLIndirct to match indirect function call. 2. Add PseudoCALL to support parsing and print pseudo `call` in assembly 3. Expand PseudoCALL to the following form with R_RISCV_CALL relocation type while encoding: auipc ra, func jalr ra, ra, 0 If we expand PseudoCALL before emitting assembly, we will see auipc and jalr pair when compile with -S. It's hard for assembly parser to parsing this pair and identify it's semantic is function call and then insert R_RISCV_CALL relocation type. Although we could insert R_RISCV_PCREL_HI20 and R_RISCV_PCREL_LO12_I relocation types instead of R_RISCV_CALL. Due to RISCV relocation design, auipc and jalr pair only can relax to jal with R_RISCV_CALL + R_RISCV_RELAX relocation types. We expand PseudoCALL as late as encoding(RISCVMCCodeEmitter) instead of before emitting assembly(RISCVAsmPrinter) because we want to preserve call pseudoinstruction in assembly code. It's more readable and assembly parser could identify call assembly and insert R_RISCV_CALL relocation type. Differential Revision: https://reviews.llvm.org/D45859 llvm-svn: 330826
- Loading branch information
Showing
9 changed files
with
140 additions
and
4 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
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,11 @@ | ||
# RUN: not llvm-mc -triple riscv32 < %s 2>&1 | FileCheck %s | ||
|
||
call 1234 # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name | ||
call %pcrel_hi(1234) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name | ||
call %pcrel_lo(1234) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name | ||
call %pcrel_hi(foo) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name | ||
call %pcrel_lo(foo) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name | ||
call %hi(1234) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name | ||
call %lo(1234) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name | ||
call %hi(foo) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name | ||
call %lo(foo) # CHECK: :[[@LINE]]:6: error: operand must be a bare symbol name |
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,19 @@ | ||
# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \ | ||
# RUN: | llvm-objdump -d - | FileCheck -check-prefix=INSTR %s | ||
# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \ | ||
# RUN: | llvm-readobj -r | FileCheck -check-prefix=RELOC %s | ||
# RUN: llvm-mc -triple riscv32 < %s -show-encoding \ | ||
# RUN: | FileCheck -check-prefix=FIXUP %s | ||
|
||
.long foo | ||
|
||
call foo | ||
# RELOC: R_RISCV_CALL foo 0x0 | ||
# INSTR: auipc ra, 0 | ||
# INSTR: jalr ra | ||
# FIXUP: fixup A - offset: 0, value: foo, kind: | ||
call bar | ||
# RELOC: R_RISCV_CALL bar 0x0 | ||
# INSTR: auipc ra, 0 | ||
# INSTR: jalr ra | ||
# FIXUP: fixup A - offset: 0, value: bar, kind: |