Skip to content

Commit

Permalink
[RISCV][Clang] Add C API header for elw CORE-V intrinsics.
Browse files Browse the repository at this point in the history
This commit adds the C API header to serve as an interface for
the intrinsic functions provided with the CORE-V xcvelw extension.

The commit includes the addition of the header itself and a clang
CodeGen test that checks the integrity of the call to the wrapper
functions designed in the C API CORE-V elw header.
  • Loading branch information
PaoloS02 committed Dec 15, 2023
1 parent a1b425f commit 1435e2d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions clang/lib/Headers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ set(ppc_htm_files

set(riscv_files
riscv_corev_bitmanip.h
riscv_corev_elw.h
)

set(systemz_files
Expand Down
33 changes: 33 additions & 0 deletions clang/lib/Headers/riscv_corev_elw.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*===---- riscv_corev_elw.h - CORE-V event load 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_COREV_ELW_H
#define __RISCV_COREV_ELW_H

#include <stdint.h>

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

#if defined(__riscv_xcvelw)

#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))

static __inline__ unsigned long __DEFAULT_FN_ATTRS __riscv_cv_elw_elw(void *loc) {
return __builtin_riscv_cv_elw_elw(loc);
}

#endif // defined(__riscv_xcvelw)

#if defined(__cplusplus)
}
#endif

#endif // define __RISCV_COREV_ELW_H
11 changes: 11 additions & 0 deletions clang/test/CodeGen/RISCV/corev-intrinsics/elw-c-api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %clang_cc1 -triple riscv32 -target-feature +xcvelw -emit-llvm %s -o - \
// RUN: | FileCheck %s

#include <stdint.h>
#include <riscv_corev_elw.h>

// CHECK-LABEL: @test_elw
// CHECK: @llvm.riscv.cv.elw.elw
uint32_t test_elw(void *a) {
return __riscv_cv_elw_elw(a);
}

0 comments on commit 1435e2d

Please sign in to comment.