Skip to content

Commit 23c0850

Browse files
authored
[RISCV][VCIX] Add vcix_state to GNU inline assembly register set (#106914)
riscv-non-isa/riscv-toolchain-conventions#56 Resolved #106700. This enables inline asm to have vcix_state to be a clobbered register thus disable reordering between VCIX intrinsics and inline asm.
1 parent b609163 commit 23c0850

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ArrayRef<const char *> RISCVTargetInfo::getGCCRegNames() const {
4444
"v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
4545

4646
// CSRs
47-
"fflags", "frm", "vtype", "vl", "vxsat", "vxrm"
47+
"fflags", "frm", "vtype", "vl", "vxsat", "vxrm", "sf.vcix_state"
4848
};
4949
// clang-format on
5050
return llvm::ArrayRef(GCCRegNames);

llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,12 @@ Register RISCVRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
715715
return TFI->hasFP(MF) ? RISCV::X8 : RISCV::X2;
716716
}
717717

718+
StringRef RISCVRegisterInfo::getRegAsmName(MCRegister Reg) const {
719+
if (Reg == RISCV::SF_VCIX_STATE)
720+
return "sf.vcix_state";
721+
return TargetRegisterInfo::getRegAsmName(Reg);
722+
}
723+
718724
const uint32_t *
719725
RISCVRegisterInfo::getCallPreservedMask(const MachineFunction & MF,
720726
CallingConv::ID CC) const {

llvm/lib/Target/RISCV/RISCVRegisterInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ struct RISCVRegisterInfo : public RISCVGenRegisterInfo {
102102

103103
Register getFrameRegister(const MachineFunction &MF) const override;
104104

105+
StringRef getRegAsmName(MCRegister Reg) const override;
106+
105107
bool requiresRegisterScavenging(const MachineFunction &MF) const override {
106108
return true;
107109
}

llvm/lib/Target/RISCV/RISCVRegisterInfo.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,3 +717,7 @@ def SSP : RISCVReg<0, "ssp">;
717717

718718
// Dummy SiFive VCIX state register
719719
def SF_VCIX_STATE : RISCVReg<0, "sf.vcix_state">;
720+
def : RISCVRegisterClass<[XLenVT], 32, (add SF_VCIX_STATE)> {
721+
let RegInfos = XLenRI;
722+
let isAllocatable = 0;
723+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: sed 's/iXLen/i32/g' %s | llc -mtriple=riscv32 -mattr=+v,+xsfvcp \
3+
; RUN: -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK
4+
; RUN: sed 's/iXLen/i64/g' %s | llc -mtriple=riscv64 -mattr=+v,+xsfvcp \
5+
; RUN: -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK
6+
7+
; VCIX instructions can not reorder between each other.
8+
define void @test_reorder(<vscale x 1 x i64> %vreg) {
9+
; CHECK-LABEL: test_reorder:
10+
; CHECK: # %bb.0: # %entry
11+
; CHECK-NEXT: vsetivli zero, 0, e64, m1, ta, ma
12+
; CHECK-NEXT: sf.vc.iv 0, 0, v8, 0
13+
; CHECK-NEXT: #APP
14+
; CHECK-NEXT: sf.vc.vv 3, 0, v8, v8
15+
; CHECK-EMPTY:
16+
; CHECK-NEXT: #NO_APP
17+
; CHECK-NEXT: ret
18+
entry:
19+
call void @llvm.riscv.sf.vc.iv.se.iXLen.nxv1i64.iXLen.iXLen(iXLen 0, iXLen 0, <vscale x 1 x i64> %vreg, iXLen 0, iXLen 0)
20+
call iXLen asm sideeffect "sf.vc.vv 0x3, 0x0, $1, $1;", "=r,^vr,~{memory},~{vl},~{sf.vcix_state}"(<vscale x 1 x i64> %vreg)
21+
ret void
22+
}

0 commit comments

Comments
 (0)