-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RISCV] Generate address sequences suitable for mcmodel=medium
This patch adds an implementation of a PC-relative addressing sequence to be used when -mcmodel=medium is specified. With absolute addressing, a 'medium' codemodel may cause addresses to be out of range. This is because while 'medium' implies a 2 GiB addressing range, this 2 GiB can be at any offset as opposed to 'small', which implies the first 2 GiB only. Note that LLVM/Clang currently specifies code models differently to GCC, where small and medium imply the same functionality as GCC's medlow and medany respectively. Differential Revision: https://reviews.llvm.org/D54143 Patch by Lewis Revill. llvm-svn: 357393
- Loading branch information
Showing
9 changed files
with
205 additions
and
36 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 |
---|---|---|
|
@@ -50,6 +50,7 @@ enum { | |
MO_None, | ||
MO_LO, | ||
MO_HI, | ||
MO_PCREL_LO, | ||
MO_PCREL_HI, | ||
}; | ||
} // namespace RISCVII | ||
|
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,80 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; RUN: llc -mtriple=riscv32 -mattr=+f -code-model=small -verify-machineinstrs < %s \ | ||
; RUN: | FileCheck %s -check-prefix=RV32I-SMALL | ||
; RUN: llc -mtriple=riscv32 -mattr=+f -code-model=medium -verify-machineinstrs < %s \ | ||
; RUN: | FileCheck %s -check-prefix=RV32I-MEDIUM | ||
|
||
; Check lowering of globals | ||
@G = global i32 0 | ||
|
||
define i32 @lower_global(i32 %a) nounwind { | ||
; RV32I-SMALL-LABEL: lower_global: | ||
; RV32I-SMALL: # %bb.0: | ||
; RV32I-SMALL-NEXT: lui a0, %hi(G) | ||
; RV32I-SMALL-NEXT: lw a0, %lo(G)(a0) | ||
; RV32I-SMALL-NEXT: ret | ||
; | ||
; RV32I-MEDIUM-LABEL: lower_global: | ||
; RV32I-MEDIUM: # %bb.0: | ||
; RV32I-MEDIUM-NEXT: .LBB0_1: # Label of block must be emitted | ||
; RV32I-MEDIUM-NEXT: auipc a0, %pcrel_hi(G) | ||
; RV32I-MEDIUM-NEXT: addi a0, a0, %pcrel_lo(.LBB0_1) | ||
; RV32I-MEDIUM-NEXT: lw a0, 0(a0) | ||
; RV32I-MEDIUM-NEXT: ret | ||
%1 = load volatile i32, i32* @G | ||
ret i32 %1 | ||
} | ||
|
||
; Check lowering of blockaddresses | ||
|
||
@addr = global i8* null | ||
|
||
define void @lower_blockaddress() nounwind { | ||
; RV32I-SMALL-LABEL: lower_blockaddress: | ||
; RV32I-SMALL: # %bb.0: | ||
; RV32I-SMALL-NEXT: lui a0, %hi(addr) | ||
; RV32I-SMALL-NEXT: addi a1, zero, 1 | ||
; RV32I-SMALL-NEXT: sw a1, %lo(addr)(a0) | ||
; RV32I-SMALL-NEXT: ret | ||
; | ||
; RV32I-MEDIUM-LABEL: lower_blockaddress: | ||
; RV32I-MEDIUM: # %bb.0: | ||
; RV32I-MEDIUM-NEXT: .LBB1_1: # Label of block must be emitted | ||
; RV32I-MEDIUM-NEXT: auipc a0, %pcrel_hi(addr) | ||
; RV32I-MEDIUM-NEXT: addi a0, a0, %pcrel_lo(.LBB1_1) | ||
; RV32I-MEDIUM-NEXT: addi a1, zero, 1 | ||
; RV32I-MEDIUM-NEXT: sw a1, 0(a0) | ||
; RV32I-MEDIUM-NEXT: ret | ||
store volatile i8* blockaddress(@lower_blockaddress, %block), i8** @addr | ||
ret void | ||
|
||
block: | ||
unreachable | ||
} | ||
|
||
; Check lowering of constantpools | ||
|
||
define float @lower_constantpool(float %a) nounwind { | ||
; RV32I-SMALL-LABEL: lower_constantpool: | ||
; RV32I-SMALL: # %bb.0: | ||
; RV32I-SMALL-NEXT: fmv.w.x ft0, a0 | ||
; RV32I-SMALL-NEXT: lui a0, %hi(.LCPI2_0) | ||
; RV32I-SMALL-NEXT: addi a0, a0, %lo(.LCPI2_0) | ||
; RV32I-SMALL-NEXT: flw ft1, 0(a0) | ||
; RV32I-SMALL-NEXT: fadd.s ft0, ft0, ft1 | ||
; RV32I-SMALL-NEXT: fmv.x.w a0, ft0 | ||
; RV32I-SMALL-NEXT: ret | ||
; | ||
; RV32I-MEDIUM-LABEL: lower_constantpool: | ||
; RV32I-MEDIUM: # %bb.0: | ||
; RV32I-MEDIUM-NEXT: .LBB2_1: # Label of block must be emitted | ||
; RV32I-MEDIUM-NEXT: auipc a1, %pcrel_hi(.LCPI2_0) | ||
; RV32I-MEDIUM-NEXT: addi a1, a1, %pcrel_lo(.LBB2_1) | ||
; RV32I-MEDIUM-NEXT: flw ft0, 0(a1) | ||
; RV32I-MEDIUM-NEXT: fmv.w.x ft1, a0 | ||
; RV32I-MEDIUM-NEXT: fadd.s ft0, ft1, ft0 | ||
; RV32I-MEDIUM-NEXT: fmv.x.w a0, ft0 | ||
; RV32I-MEDIUM-NEXT: ret | ||
%1 = fadd float %a, 1.0 | ||
ret float %1 | ||
} |