Skip to content

Commit af083d0

Browse files
authored
[RISCV] Add zihintpause LLVM/Clang intrinsic (llvm#139519)
This PR adds the missing intrinsic `__builtin_riscv_pause` for the zihintpause extension. Spec: https://five-embeddev.com/riscv-user-isa-manual/Priv-v1.12/zihintpause.html Fixes llvm#129961
1 parent bcb1227 commit af083d0

File tree

7 files changed

+55
-0
lines changed

7 files changed

+55
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,8 @@ RISC-V Support
830830

831831
- `Zicsr` / `Zifencei` are allowed to be duplicated in the presence of `g` in `-march`.
832832

833+
- Add support for the `__builtin_riscv_pause()` intrinsic from the `Zihintpause` extension.
834+
833835
CUDA/HIP Language Changes
834836
^^^^^^^^^^^^^^^^^^^^^^^^^
835837

clang/include/clang/Basic/BuiltinsRISCV.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ def ntl_load : RISCVBuiltin<"void(...)">;
147147
def ntl_store : RISCVBuiltin<"void(...)">;
148148
} // Features = "zihintntl", Attributes = [CustomTypeChecking]
149149

150+
//===----------------------------------------------------------------------===//
151+
// Zihintpause extension.
152+
//===----------------------------------------------------------------------===//
153+
let Features = "zihintpause", Attributes = [NoThrow] in
154+
def pause : RISCVBuiltin<"void()">;
155+
150156
//===----------------------------------------------------------------------===//
151157
// XCV extensions.
152158
//===----------------------------------------------------------------------===//

clang/lib/CodeGen/TargetBuiltins/RISCV.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
357357

358358
return Store;
359359
}
360+
// Zihintpause
361+
case RISCV::BI__builtin_riscv_pause: {
362+
llvm::Function *Fn = CGM.getIntrinsic(llvm::Intrinsic::riscv_pause);
363+
return Builder.CreateCall(Fn, {});
364+
}
365+
360366
// XCValu
361367
case RISCV::BI__builtin_riscv_cv_alu_addN:
362368
ID = Intrinsic::riscv_cv_alu_addN;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2+
// RUN: %clang_cc1 -triple riscv32 -target-feature +zihintpause -emit-llvm %s -o - \
3+
// RUN: | FileCheck %s
4+
// RUN: %clang_cc1 -triple riscv64 -target-feature +zihintpause -emit-llvm %s -o - \
5+
// RUN: | FileCheck %s
6+
7+
// CHECK-LABEL: @test_builtin_pause(
8+
// CHECK-NEXT: entry:
9+
// CHECK-NEXT: call void @llvm.riscv.pause()
10+
// CHECK-NEXT: ret void
11+
//
12+
void test_builtin_pause() {
13+
__builtin_riscv_pause();
14+
}

llvm/include/llvm/IR/IntrinsicsRISCV.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,11 @@ let TargetPrefix = "riscv" in {
18861886
def int_riscv_vsm3me : RISCVBinaryAAXUnMasked;
18871887
} // TargetPrefix = "riscv"
18881888

1889+
// Zihintpause extensions
1890+
//===----------------------------------------------------------------------===//
1891+
let TargetPrefix = "riscv" in
1892+
def int_riscv_pause : DefaultAttrsIntrinsic<[], [], [IntrNoMem, IntrHasSideEffects]>;
1893+
18891894
// Vendor extensions
18901895
//===----------------------------------------------------------------------===//
18911896
include "llvm/IR/IntrinsicsRISCVXTHead.td"

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,14 @@ def : Pat<(binop_allwusers<add> GPR:$rs1, immop_oneuse<AddiPair>:$rs2),
21982198
def : Pat<(i64 (add GPR:$rs1, negImm:$rs2)), (SUB GPR:$rs1, negImm:$rs2)>;
21992199
}
22002200

2201+
//===----------------------------------------------------------------------===//
2202+
// Zihintpause
2203+
//===----------------------------------------------------------------------===//
2204+
2205+
// Zihintpause
2206+
let Predicates = [HasStdExtZihintpause] in
2207+
def : Pat<(int_riscv_pause), (FENCE 0x1, 0x0)>;
2208+
22012209
//===----------------------------------------------------------------------===//
22022210
// Standard extensions
22032211
//===----------------------------------------------------------------------===//
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=riscv64 -mattr=+zihintpause -verify-machineinstrs < %s \
3+
; RUN: | FileCheck %s -check-prefix=RVPAUSE
4+
5+
declare void @llvm.riscv.pause()
6+
7+
define void @test_pause() {
8+
; RVPAUSE-LABEL: test_pause:
9+
; RVPAUSE: # %bb.0:
10+
; RVPAUSE-NEXT: pause
11+
; RVPAUSE-NEXT: ret
12+
call void @llvm.riscv.pause()
13+
ret void
14+
}

0 commit comments

Comments
 (0)