-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[RISCV] Implement Clang Builtins for XAndesPerf Extension #147018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tclin914
wants to merge
2
commits into
llvm:main
Choose a base branch
from
tclin914:andes-xandesperf-intrinsic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+347
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//==- BuiltinsRISCVXAndes.td - RISC-V Andes Builtin database -----*- C++ -*-==// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines the Andes-specific builtin function database. Users of | ||
// this file must define the BUILTIN macro to make use of this information. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
class RISCVXAndesBuiltin<string prototype, string features = ""> : TargetBuiltin { | ||
let Spellings = ["__builtin_riscv_nds_" # NAME]; | ||
let Prototype = prototype; | ||
let Features = features; | ||
} | ||
|
||
let Attributes = [NoThrow, Const] in { | ||
//===----------------------------------------------------------------------===// | ||
// XAndesPerf extension. | ||
//===----------------------------------------------------------------------===// | ||
|
||
def ffb : RISCVXAndesBuiltin<"long int(unsigned long int, unsigned long int)", "xandesperf">; | ||
def ffzmism : RISCVXAndesBuiltin<"long int(unsigned long int, unsigned long int)", "xandesperf">; | ||
def ffmism : RISCVXAndesBuiltin<"long int(unsigned long int, unsigned long int)", "xandesperf">; | ||
def flmism : RISCVXAndesBuiltin<"long int(unsigned long int, unsigned long int)", "xandesperf">; | ||
} // Attributes = [NoThrow, Const] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*===---- riscv_nds.h - Andes 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_NDS_H | ||
#define __RISCV_NDS_H | ||
|
||
#if defined(__cplusplus) | ||
extern "C" { | ||
#endif | ||
|
||
#if defined(__riscv_xandesperf) | ||
|
||
#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_nds_ffb(unsigned long a, | ||
unsigned long b) { | ||
return __builtin_riscv_nds_ffb(a, b); | ||
} | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_nds_ffzmism(unsigned long a, | ||
unsigned long b) { | ||
return __builtin_riscv_nds_ffzmism(a, b); | ||
} | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_nds_ffmism(unsigned long a, | ||
unsigned long b) { | ||
return __builtin_riscv_nds_ffmism(a, b); | ||
} | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_nds_flmism(unsigned long a, | ||
unsigned long b) { | ||
return __builtin_riscv_nds_flmism(a, b); | ||
} | ||
|
||
#endif // defined(__riscv_nds) | ||
|
||
#if defined(__cplusplus) | ||
} | ||
#endif | ||
|
||
#endif // define __RISCV_NDS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py | ||
// RUN: %clang_cc1 -triple riscv32 -target-feature +xandesperf -emit-llvm %s -o - \ | ||
tclin914 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// RUN: -disable-O0-optnone | opt -S -passes=mem2reg \ | ||
// RUN: | FileCheck %s --check-prefix=CHECK-RV32 | ||
// RUN: %clang_cc1 -triple riscv64 -target-feature +xandesperf -emit-llvm %s -o - \ | ||
// RUN: -disable-O0-optnone | opt -S -passes=mem2reg \ | ||
// RUN: | FileCheck %s --check-prefix=CHECK-RV64 | ||
|
||
#include <riscv_nds.h> | ||
|
||
// CHECK-RV32-LABEL: @test_ffb( | ||
// CHECK-RV32-NEXT: entry: | ||
// CHECK-RV32-NEXT: [[TMP0:%.*]] = call i32 @llvm.riscv.nds.ffb.i32(i32 [[A:%.*]], i32 [[B:%.*]]) | ||
// CHECK-RV32-NEXT: ret i32 [[TMP0]] | ||
// | ||
// CHECK-RV64-LABEL: @test_ffb( | ||
// CHECK-RV64-NEXT: entry: | ||
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call i64 @llvm.riscv.nds.ffb.i64(i64 [[A:%.*]], i64 [[B:%.*]]) | ||
// CHECK-RV64-NEXT: ret i64 [[TMP0]] | ||
// | ||
long test_ffb(unsigned long a, unsigned long b) { | ||
return __riscv_nds_ffb(a, b); | ||
} | ||
|
||
// CHECK-RV32-LABEL: @test_ffzmism( | ||
// CHECK-RV32-NEXT: entry: | ||
// CHECK-RV32-NEXT: [[TMP0:%.*]] = call i32 @llvm.riscv.nds.ffzmism.i32(i32 [[A:%.*]], i32 [[B:%.*]]) | ||
// CHECK-RV32-NEXT: ret i32 [[TMP0]] | ||
// | ||
// CHECK-RV64-LABEL: @test_ffzmism( | ||
// CHECK-RV64-NEXT: entry: | ||
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call i64 @llvm.riscv.nds.ffzmism.i64(i64 [[A:%.*]], i64 [[B:%.*]]) | ||
// CHECK-RV64-NEXT: ret i64 [[TMP0]] | ||
// | ||
long test_ffzmism(unsigned long a, unsigned long b) { | ||
return __riscv_nds_ffzmism(a, b); | ||
} | ||
|
||
// CHECK-RV32-LABEL: @test_ffmism( | ||
// CHECK-RV32-NEXT: entry: | ||
// CHECK-RV32-NEXT: [[TMP0:%.*]] = call i32 @llvm.riscv.nds.ffmism.i32(i32 [[A:%.*]], i32 [[B:%.*]]) | ||
// CHECK-RV32-NEXT: ret i32 [[TMP0]] | ||
// | ||
// CHECK-RV64-LABEL: @test_ffmism( | ||
// CHECK-RV64-NEXT: entry: | ||
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call i64 @llvm.riscv.nds.ffmism.i64(i64 [[A:%.*]], i64 [[B:%.*]]) | ||
// CHECK-RV64-NEXT: ret i64 [[TMP0]] | ||
// | ||
long test_ffmism(unsigned long a, unsigned long b) { | ||
return __riscv_nds_ffmism(a, b); | ||
} | ||
|
||
// CHECK-RV32-LABEL: @test_flmism( | ||
// CHECK-RV32-NEXT: entry: | ||
// CHECK-RV32-NEXT: [[TMP0:%.*]] = call i32 @llvm.riscv.nds.flmism.i32(i32 [[A:%.*]], i32 [[B:%.*]]) | ||
// CHECK-RV32-NEXT: ret i32 [[TMP0]] | ||
// | ||
// CHECK-RV64-LABEL: @test_flmism( | ||
// CHECK-RV64-NEXT: entry: | ||
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call i64 @llvm.riscv.nds.flmism.i64(i64 [[A:%.*]], i64 [[B:%.*]]) | ||
// CHECK-RV64-NEXT: ret i64 [[TMP0]] | ||
// | ||
long test_flmism(unsigned long a, unsigned long b) { | ||
return __riscv_nds_flmism(a, b); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py | ||
// RUN: %clang_cc1 -triple riscv32 -target-feature +xandesperf -emit-llvm %s -o - \ | ||
// RUN: -disable-O0-optnone | opt -S -passes=mem2reg \ | ||
// RUN: | FileCheck %s --check-prefix=CHECK-RV32 | ||
// RUN: %clang_cc1 -triple riscv64 -target-feature +xandesperf -emit-llvm %s -o - \ | ||
// RUN: -disable-O0-optnone | opt -S -passes=mem2reg \ | ||
// RUN: | FileCheck %s --check-prefix=CHECK-RV64 | ||
|
||
// CHECK-RV32-LABEL: @test_ffb( | ||
// CHECK-RV32-NEXT: entry: | ||
// CHECK-RV32-NEXT: [[TMP0:%.*]] = call i32 @llvm.riscv.nds.ffb.i32(i32 [[A:%.*]], i32 [[B:%.*]]) | ||
// CHECK-RV32-NEXT: ret i32 [[TMP0]] | ||
// | ||
// CHECK-RV64-LABEL: @test_ffb( | ||
// CHECK-RV64-NEXT: entry: | ||
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call i64 @llvm.riscv.nds.ffb.i64(i64 [[A:%.*]], i64 [[B:%.*]]) | ||
// CHECK-RV64-NEXT: ret i64 [[TMP0]] | ||
// | ||
long test_ffb(unsigned long a, unsigned long b) { | ||
return __builtin_riscv_nds_ffb(a, b); | ||
} | ||
|
||
// CHECK-RV32-LABEL: @test_ffzmism( | ||
// CHECK-RV32-NEXT: entry: | ||
// CHECK-RV32-NEXT: [[TMP0:%.*]] = call i32 @llvm.riscv.nds.ffzmism.i32(i32 [[A:%.*]], i32 [[B:%.*]]) | ||
// CHECK-RV32-NEXT: ret i32 [[TMP0]] | ||
// | ||
// CHECK-RV64-LABEL: @test_ffzmism( | ||
// CHECK-RV64-NEXT: entry: | ||
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call i64 @llvm.riscv.nds.ffzmism.i64(i64 [[A:%.*]], i64 [[B:%.*]]) | ||
// CHECK-RV64-NEXT: ret i64 [[TMP0]] | ||
// | ||
long test_ffzmism(unsigned long a, unsigned long b) { | ||
return __builtin_riscv_nds_ffzmism(a, b); | ||
} | ||
|
||
// CHECK-RV32-LABEL: @test_ffmism( | ||
// CHECK-RV32-NEXT: entry: | ||
// CHECK-RV32-NEXT: [[TMP0:%.*]] = call i32 @llvm.riscv.nds.ffmism.i32(i32 [[A:%.*]], i32 [[B:%.*]]) | ||
// CHECK-RV32-NEXT: ret i32 [[TMP0]] | ||
// | ||
// CHECK-RV64-LABEL: @test_ffmism( | ||
// CHECK-RV64-NEXT: entry: | ||
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call i64 @llvm.riscv.nds.ffmism.i64(i64 [[A:%.*]], i64 [[B:%.*]]) | ||
// CHECK-RV64-NEXT: ret i64 [[TMP0]] | ||
// | ||
long test_ffmism(unsigned long a, unsigned long b) { | ||
return __builtin_riscv_nds_ffmism(a, b); | ||
} | ||
|
||
// CHECK-RV32-LABEL: @test_flmism( | ||
// CHECK-RV32-NEXT: entry: | ||
// CHECK-RV32-NEXT: [[TMP0:%.*]] = call i32 @llvm.riscv.nds.flmism.i32(i32 [[A:%.*]], i32 [[B:%.*]]) | ||
// CHECK-RV32-NEXT: ret i32 [[TMP0]] | ||
// | ||
// CHECK-RV64-LABEL: @test_flmism( | ||
// CHECK-RV64-NEXT: entry: | ||
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call i64 @llvm.riscv.nds.flmism.i64(i64 [[A:%.*]], i64 [[B:%.*]]) | ||
// CHECK-RV64-NEXT: ret i64 [[TMP0]] | ||
// | ||
long test_flmism(unsigned long a, unsigned long b) { | ||
return __builtin_riscv_nds_flmism(a, b); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have 32/64 versions just like
clz
,orc.b
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, we did not plan to provide both 32-bit and 64-bit versions for RV64. The 32-bit version would be only for RV32, and the 64-bit version is for RV64.