Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions clang/include/clang/Basic/BuiltinsRISCV.td
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ def ntl_store : RISCVBuiltin<"void(...)">;
let Features = "zihintpause", Attributes = [NoThrow] in
def pause : RISCVBuiltin<"void()">;

//===----------------------------------------------------------------------===//
// Zicboz extension.
//===----------------------------------------------------------------------===//
let Features = "zicboz" in {
def cbo_zero : RISCVBuiltin<"void(void *)">;
} // Features = "zicboz"

//===----------------------------------------------------------------------===//
// 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 @@ -1296,6 +1296,12 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
return Builder.CreateCall(Fn, {});
}

// Zicboz
case RISCV::BI__builtin_riscv_cbo_zero:
ID = Intrinsic::riscv_cbo_zero;
IntrinsicTypes = {Int8PtrTy};
break;

// XCValu
case RISCV::BI__builtin_riscv_cv_alu_addN:
ID = Intrinsic::riscv_cv_alu_addN;
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Headers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ set(ppc_htm_files

set(riscv_files
riscv_bitmanip.h
riscv_cmo.h
riscv_corev_alu.h
riscv_crypto.h
riscv_nds.h
Expand Down
28 changes: 28 additions & 0 deletions clang/lib/Headers/riscv_cmo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*===---- riscv_cmo.h - RISC-V CMO intrinsics ----------------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

#ifndef __RISCV_CMO_H
#define __RISCV_CMO_H

#if defined(__cplusplus)
extern "C" {
#endif

#if defined(__riscv_zicboz)
static __inline__ void __attribute__((__always_inline__, __nodebug__))
__riscv_cbo_zero(void *__x) {
return __builtin_riscv_cbo_zero(__x);
}
#endif // defined(__riscv_zicboz)

#if defined(__cplusplus)
}
#endif

#endif // define __RISCV_CMO_H
12 changes: 12 additions & 0 deletions clang/test/CodeGen/RISCV/riscv-zicbo-intrinsics/cbo-zero-invalid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// REQUIRES: riscv-registered-target
// RUN: %clang_cc1 -triple riscv64 -target-feature +zicboz \
// RUN: -Wall -Wno-unused -Werror -fsyntax-only -verify %s

#include <riscv_cmo.h>

void test(void *x) {
__riscv_cbo_zero(x, 0); // expected-error{{too many arguments to function call, expected single argument '__x', have 2 arguments}} expected-note@riscv_cmo.h:* {{'__riscv_cbo_zero' declared here}}
int res = __riscv_cbo_zero(x); // expected-error{{initializing 'int' with an expression of incompatible type 'void'}}
__riscv_cbo_zero(42); // expected-error{{incompatible integer to pointer conversion passing 'int' to parameter of type 'void *'}} expected-note@riscv_cmo.h:* {{passing argument to parameter '__x' here}}
}

13 changes: 13 additions & 0 deletions clang/test/CodeGen/RISCV/riscv-zicbo-intrinsics/cbo-zero-valid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

// REQUIRES: riscv-registered-target
// RUN: %clang_cc1 -triple riscv64 -target-feature +zicboz -O2 -S -o - %s | FileCheck %s

#include <riscv_cmo.h>

void test(void *x) {
// CHECK-LABEL: test:
// CHECK: cbo.zero (a0)
// CHECK: ret
__riscv_cbo_zero(x);
}

11 changes: 9 additions & 2 deletions llvm/include/llvm/IR/IntrinsicsRISCV.td
Original file line number Diff line number Diff line change
Expand Up @@ -1953,13 +1953,20 @@ let TargetPrefix = "riscv" in {
} // TargetPrefix = "riscv"


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

// Vendor extensions
//===----------------------------------------------------------------------===//
// Cache Management
let TargetPrefix = "riscv" in {
// Zicboz
def int_riscv_cbo_zero : Intrinsic<[], [llvm_anyptr_ty], [IntrWriteMem]>;
} // TargetPrefix = "riscv"

//===----------------------------------------------------------------------===//
// Vendor extensions
include "llvm/IR/IntrinsicsRISCVXTHead.td"
include "llvm/IR/IntrinsicsRISCVXsf.td"
include "llvm/IR/IntrinsicsRISCVXCV.td"
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfoZicbo.td
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def CBO_INVAL : CBO_r<0b000000000000, "cbo.inval">, Sched<[]>;

let Predicates = [HasStdExtZicboz] in {
def CBO_ZERO : CBO_r<0b000000000100, "cbo.zero">, Sched<[]>;
def : Pat<(int_riscv_cbo_zero GPR:$rs1), (CBO_ZERO GPR:$rs1)>;
} // Predicates = [HasStdExtZicboz]

let Predicates = [HasStdExtZicbop, NoVendorXMIPSCBOP] in {
Expand Down