-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RISCV] Support constraint "s" (#80201)
GCC has supported a generic constraint "s" for a long time (since at least 1992), which references a symbol or label with an optional constant offset. "i" is a superset that also supports a constant integer. GCC's RISC-V port also supports a machine-specific constraint "S", which cannot be used with a preemptible symbol. (We don't bother to check preemptibility.) In PIC code, an external symbol is preemptible by default, making "S" less useful if you want to create an artificial reference for linker garbage collection, or define sections to hold symbol addresses: ``` void fun(); // error: impossible constraint in ‘asm’ for riscv64-linux-gnu-gcc -fpie/-fpic void foo() { asm(".reloc ., BFD_RELOC_NONE, %0" :: "S"(fun)); } // good even if -fpie/-fpic void foo() { asm(".reloc ., BFD_RELOC_NONE, %0" :: "s"(fun)); } ``` This patch adds support for "s". Modify https://reviews.llvm.org/D105254 ("S") to handle multi-depth GEPs (https://reviews.llvm.org/D61560).
- Loading branch information
Showing
8 changed files
with
110 additions
and
67 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 was deleted.
Oops, something went wrong.
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,14 @@ | ||
; RUN: not llc -mtriple=riscv64 < %s 2>&1 | FileCheck %s | ||
|
||
@a = external global [4 x i32], align 16 | ||
|
||
; CHECK-COUNT-2: error: invalid operand for inline asm constraint 's' | ||
; CHECK-NOT: error: | ||
define void @test(i64 %i) { | ||
entry: | ||
%x = alloca i32, align 4 | ||
%ai = getelementptr inbounds [4 x i32], ptr @a, i64 0, i64 %i | ||
call void asm sideeffect "", "s,~{dirflag},~{fpsr},~{flags}"(ptr %x) | ||
call void asm sideeffect "", "s,~{dirflag},~{fpsr},~{flags}"(ptr %ai) | ||
ret void | ||
} |
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,70 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; RUN: llc -mtriple=riscv32 -relocation-model=static < %s | FileCheck %s --check-prefix=RV32 | ||
; RUN: llc -mtriple=riscv64 -relocation-model=pic < %s | FileCheck %s --check-prefix=RV64 | ||
|
||
@var = external dso_local global i32, align 4 | ||
@a = external global [2 x [2 x i32]], align 4 | ||
|
||
define dso_local void @test() { | ||
; RV32-LABEL: test: | ||
; RV32: # %bb.0: # %entry | ||
; RV32-NEXT: #APP | ||
; RV32-NEXT: # var a+12 test | ||
; RV32-NEXT: #NO_APP | ||
; RV32-NEXT: #APP | ||
; RV32-NEXT: # var a+12 test | ||
; RV32-NEXT: #NO_APP | ||
; RV32-NEXT: ret | ||
; | ||
; RV64-LABEL: test: | ||
; RV64: # %bb.0: # %entry | ||
; RV64-NEXT: #APP | ||
; RV64-NEXT: # var a+12 .Ltest$local | ||
; RV64-NEXT: #NO_APP | ||
; RV64-NEXT: #APP | ||
; RV64-NEXT: # var a+12 .Ltest$local | ||
; RV64-NEXT: #NO_APP | ||
; RV64-NEXT: ret | ||
entry: | ||
call void asm sideeffect "// $0 $1 $2", "s,s,s,~{dirflag},~{fpsr},~{flags}"(ptr @var, ptr getelementptr inbounds ([2 x [2 x i32]], ptr @a, i64 0, i64 1, i64 1), ptr @test) | ||
|
||
;; Implement "S" as an alias for "s". | ||
call void asm sideeffect "// $0 $1 $2", "S,S,S,~{dirflag},~{fpsr},~{flags}"(ptr @var, ptr getelementptr inbounds ([2 x [2 x i32]], ptr @a, i64 0, i64 1, i64 1), ptr @test) | ||
ret void | ||
} | ||
|
||
; Function Attrs: nofree nosync nounwind readnone | ||
define dso_local ptr @test_label() { | ||
; RV32-LABEL: test_label: | ||
; RV32: # %bb.0: # %entry | ||
; RV32-NEXT: .Ltmp0: # Block address taken | ||
; RV32-NEXT: # %bb.1: # %L1 | ||
; RV32-NEXT: #APP | ||
; RV32-NEXT: # .Ltmp0 | ||
; RV32-NEXT: #NO_APP | ||
; RV32-NEXT: #APP | ||
; RV32-NEXT: lui a0, %hi(.Ltmp0) | ||
; RV32-NEXT: addi a0, a0, %lo(.Ltmp0) | ||
; RV32-NEXT: #NO_APP | ||
; RV32-NEXT: ret | ||
; | ||
; RV64-LABEL: test_label: | ||
; RV64: # %bb.0: # %entry | ||
; RV64-NEXT: .Ltmp0: # Block address taken | ||
; RV64-NEXT: # %bb.1: # %L1 | ||
; RV64-NEXT: #APP | ||
; RV64-NEXT: # .Ltmp0 | ||
; RV64-NEXT: #NO_APP | ||
; RV64-NEXT: #APP | ||
; RV64-NEXT: lui a0, %hi(.Ltmp0) | ||
; RV64-NEXT: addi a0, a0, %lo(.Ltmp0) | ||
; RV64-NEXT: #NO_APP | ||
; RV64-NEXT: ret | ||
entry: | ||
br label %L1 | ||
|
||
L1: | ||
call void asm sideeffect "// $0", "s,~{dirflag},~{fpsr},~{flags}"(ptr blockaddress(@test_label, %L1)) | ||
%ret = tail call ptr asm "lui $0, %hi($1)\0Aaddi $0, $0, %lo($1)", "=r,S"(ptr blockaddress(@test_label, %L1)) | ||
ret ptr %ret | ||
} |