Skip to content

Commit 6bcead8

Browse files
committed
[RISCV] Intrinsic Support for XCVelw
Add intrinsic support for XCVelw extension. Documentation: https://docs.openhwgroup.org/projects/cv32e40p-user-manual/en/latest/instruction_set_extensions.html#event-load-instruction
1 parent 63ecb01 commit 6bcead8

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

llvm/include/llvm/IR/IntrinsicsRISCVXCV.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,7 @@ let TargetPrefix = "riscv" in {
9090
def int_riscv_cv_mac_machhuRN : ScalarCoreVMacGprGprGprImmIntrinsic;
9191
def int_riscv_cv_mac_macsRN : ScalarCoreVMacGprGprGprImmIntrinsic;
9292
def int_riscv_cv_mac_machhsRN : ScalarCoreVMacGprGprGprImmIntrinsic;
93+
94+
def int_riscv_cv_elw_elw
95+
: Intrinsic<[llvm_i32_ty], [llvm_ptr_ty], [IntrReadMem, IntrArgMemOnly]>;
9396
} // TargetPrefix = "riscv"

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3919,6 +3919,9 @@ bool RISCVAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
39193919

39203920
return false;
39213921
}
3922+
case RISCV::PseudoCV_ELW:
3923+
emitLoadStoreSymbol(Inst, RISCV::CV_ELW, IDLoc, Out, /*HasTmpReg=*/false);
3924+
return false;
39223925
}
39233926

39243927
emitToStreamer(Out, Inst);

llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ class CVLoad_ri<bits<3> funct3, string opcodestr>
662662

663663
let Predicates = [HasVendorXCVelw, IsRV32], hasSideEffects = 0,
664664
mayLoad = 1, mayStore = 0 in {
665+
def PseudoCV_ELW : PseudoLoad<"cv.elw">;
665666
// Event load
666667
def CV_ELW : CVLoad_ri<0b011, "cv.elw">;
667668
}
@@ -707,6 +708,12 @@ let Predicates = [HasVendorXCVmem, IsRV32], AddedComplexity = 1 in {
707708
def : CVStrrPat<store, CV_SW_rr>;
708709
}
709710

711+
let Predicates = [HasVendorXCVelw, IsRV32] in {
712+
def : Pat<(int_riscv_cv_elw_elw (XLenVT GPR:$rs1)), (PseudoCV_ELW GPR:$rs1)>;
713+
def : Pat<(int_riscv_cv_elw_elw (AddrRegImm (XLenVT GPR:$rs1), simm12:$imm12)),
714+
(CV_ELW GPR:$rs1, simm12:$imm12)>;
715+
}
716+
710717
def cv_tuimm2 : TImmLeaf<XLenVT, [{return isUInt<2>(Imm);}]>;
711718
def cv_tuimm5 : TImmLeaf<XLenVT, [{return isUInt<5>(Imm);}]>;
712719
def cv_uimm10 : ImmLeaf<XLenVT, [{return isUInt<10>(Imm);}]>;

llvm/test/CodeGen/RISCV/xcvelw.ll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -O0 -mtriple=riscv32 -mattr=+xcvelw -verify-machineinstrs < %s \
3+
; RUN: | FileCheck %s
4+
5+
declare i32 @llvm.riscv.cv.elw.elw(i8*)
6+
7+
define i32 @test.cv.elw.elw(i8* %a) {
8+
; CHECK-LABEL: test.cv.elw.elw:
9+
; CHECK: # %bb.0:
10+
; CHECK-NEXT: cv.elw a0, 0(a0)
11+
; CHECK-NEXT: ret
12+
%1 = call i32 @llvm.riscv.cv.elw.elw(i8* %a)
13+
ret i32 %1
14+
}
15+
16+
define i32 @test.cv.elw.elw2(i8* %a, i32 %b) {
17+
; CHECK-LABEL: test.cv.elw.elw2:
18+
; CHECK: # %bb.0:
19+
; CHECK-NEXT: add a0, a1, a0
20+
; CHECK-NEXT: cv.elw a0, 7(a0)
21+
; CHECK-NEXT: ret
22+
%c = add i32 %b, 4
23+
%d = add i32 %c, 3
24+
%e = getelementptr i8, i8* %a, i32 %d
25+
%1 = call i32 @llvm.riscv.cv.elw.elw(i8* %e)
26+
ret i32 %1
27+
}

0 commit comments

Comments
 (0)