Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,8 @@ RISC-V Support

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

- Add support for the `__builtin_riscv_pause()` intrinsic from the `Zihintpause` extension.

CUDA/HIP Language Changes
^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/Basic/BuiltinsRISCV.td
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ def ntl_load : RISCVBuiltin<"void(...)">;
def ntl_store : RISCVBuiltin<"void(...)">;
} // Features = "zihintntl", Attributes = [CustomTypeChecking]

//===----------------------------------------------------------------------===//
// Zihintpause extension.
//===----------------------------------------------------------------------===//
let Features = "zihintpause", Attributes = [NoThrow] in {
def pause : RISCVBuiltin<"void()">;
} // Features = "zihintpause", Attributes = [NoThrow]

//===----------------------------------------------------------------------===//
// XCV extensions.
//===----------------------------------------------------------------------===//
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/CodeGen/TargetBuiltins/RISCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,

return Store;
}
// Zihintpause
case RISCV::BI__builtin_riscv_pause: {
llvm::Function *Fn = CGM.getIntrinsic(llvm::Intrinsic::riscv_pause);
return Builder.CreateCall(Fn, {});
}

// XCValu
case RISCV::BI__builtin_riscv_cv_alu_addN:
ID = Intrinsic::riscv_cv_alu_addN;
Expand Down
14 changes: 14 additions & 0 deletions clang/test/CodeGen/RISCV/riscv-zihintpause.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang_cc1 -triple riscv32 -target-feature +zihintpause -emit-llvm %s -o - \
// RUN: | FileCheck %s
// RUN: %clang_cc1 -triple riscv64 -target-feature +zihintpause -emit-llvm %s -o - \
// RUN: | FileCheck %s

// CHECK-LABEL: @test_builtin_pause(
// CHECK-NEXT: entry:
// CHECK-NEXT: call void @llvm.riscv.pause()
// CHECK-NEXT: ret void
//
void test_builtin_pause() {
__builtin_riscv_pause();
}
6 changes: 6 additions & 0 deletions llvm/include/llvm/IR/IntrinsicsRISCV.td
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,12 @@ let TargetPrefix = "riscv" in {
def int_riscv_vsm3me : RISCVBinaryAAXUnMasked;
} // TargetPrefix = "riscv"

// Zihintpause extensions
//===----------------------------------------------------------------------===//
let TargetPrefix = "riscv" in {
def int_riscv_pause : DefaultAttrsIntrinsic<[], [], [IntrNoMem, IntrHasSideEffects]>;
} // TargetPrefix = "riscv"

// Vendor extensions
//===----------------------------------------------------------------------===//
include "llvm/IR/IntrinsicsRISCVXTHead.td"
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,15 @@ def : Pat<(binop_allwusers<add> GPR:$rs1, immop_oneuse<AddiPair>:$rs2),
def : Pat<(i64 (add GPR:$rs1, negImm:$rs2)), (SUB GPR:$rs1, negImm:$rs2)>;
}

//===----------------------------------------------------------------------===//
// Zihintpause
//===----------------------------------------------------------------------===//

// Zihintpause
let Predicates = [HasStdExtZihintpause] in {
def : Pat<(int_riscv_pause), (FENCE 0x1, 0x0)>;
}

//===----------------------------------------------------------------------===//
// Standard extensions
//===----------------------------------------------------------------------===//
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/CodeGen/RISCV/riscv-zihintpause.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=riscv64 -mattr=+zihintpause -verify-machineinstrs < %s \
; RUN: | FileCheck %s -check-prefix=RVPAUSE

declare void @llvm.riscv.pause()

define void @test_pause() {
; RVPAUSE-LABEL: test_pause:
; RVPAUSE: # %bb.0:
; RVPAUSE-NEXT: pause
; RVPAUSE-NEXT: ret
call void @llvm.riscv.pause()
ret void
}