Skip to content

Commit b59d410

Browse files
RISC-V: builtins support for MIPS RV64 P8700 execution control .
the following changes are made a)Typo Fix (with previous PRhttps://github.com//pull/155747) b)builtins support for MIPS P8700 execution control instructions . c)Testcase
1 parent c4617bc commit b59d410

File tree

10 files changed

+162
-1
lines changed

10 files changed

+162
-1
lines changed

clang/include/clang/Basic/BuiltinsRISCV.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,8 @@ include "clang/Basic/BuiltinsRISCVXCV.td"
162162
// XAndes extensions.
163163
//===----------------------------------------------------------------------===//
164164
include "clang/Basic/BuiltinsRISCVXAndes.td"
165+
166+
//===----------------------------------------------------------------------===//
167+
// MIPS extensions.
168+
//===----------------------------------------------------------------------===//
169+
include "clang/Basic/BuiltinsRISCVXMIPS.td"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//==- BuiltinsRISCVXMIPS.td - RISC-V MIPS Builtin database ----*- C++ -*-==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines the MIPS-specific builtin function database. Users of
10+
// this file must define the BUILTIN macro to make use of this information.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
//===----------------------------------------------------------------------===//
15+
// MIPS execution control extensions.
16+
//===----------------------------------------------------------------------===//
17+
let Attributes = [NoThrow, Const] in {
18+
def mips_pause : RISCVBuiltin<"void()", "xmipsexectl">;
19+
def mips_ehb : RISCVBuiltin<"void()", "xmipsexectl">;
20+
def mips_ihb : RISCVBuiltin<"void()", "xmipsexectl">;
21+
}

clang/lib/Headers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ set(riscv_files
131131
riscv_ntlh.h
132132
sifive_vector.h
133133
andes_vector.h
134+
riscv_mips.h
134135
)
135136

136137
set(spirv_files

clang/lib/Headers/riscv_mips.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===----- riscv_mips.h - RISC-V MIPS Intrinsic definitions
2+
//----------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef __RISCV_MIPS_H
11+
#define __RISCV_MIPS_H
12+
13+
#if !defined(__riscv)
14+
#error "This header is only meant to be used on riscv architecture"
15+
#endif
16+
17+
#define __DEFAULT_FN_ATTRS \
18+
__attribute__((__always_inline__, __nodebug__, __target__("xmipsexectl")))
19+
20+
static __inline__ void __DEFAULT_FN_ATTRS __mips_pause() {
21+
__builtin_riscv_mips_pause();
22+
}
23+
24+
static __inline__ void __DEFAULT_FN_ATTRS __mips_ehb() {
25+
__builtin_riscv_mips_ehb();
26+
}
27+
28+
static __inline__ void __DEFAULT_FN_ATTRS __mips_ihb() {
29+
__builtin_riscv_mips_ihb();
30+
}
31+
32+
#undef __DEFAULT_FN_ATTRS
33+
34+
#endif
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 6
2+
// RUN: %clang_cc1 -triple riscv32-linux-elf -O3 -target-feature +xmipsexectl -emit-llvm -o - %s | FileCheck %s
3+
4+
#include<riscv_mips.h>
5+
6+
// CHECK-LABEL: define dso_local void @test_mips_pause(
7+
// CHECK-SAME: ) local_unnamed_addr #[[ATTR0:[0-9]+]] {
8+
// CHECK-NEXT: [[ENTRY:.*:]]
9+
// CHECK-NEXT: tail call void @llvm.riscv.mips.pause()
10+
// CHECK-NEXT: ret void
11+
//
12+
void test_mips_pause()
13+
{
14+
__mips_pause();
15+
}
16+
17+
// CHECK-LABEL: define dso_local void @test_mips_ehb(
18+
// CHECK-SAME: ) local_unnamed_addr #[[ATTR0]] {
19+
// CHECK-NEXT: [[ENTRY:.*:]]
20+
// CHECK-NEXT: tail call void @llvm.riscv.mips.ehb()
21+
// CHECK-NEXT: ret void
22+
//
23+
void test_mips_ehb()
24+
{
25+
__mips_ehb();
26+
}
27+
28+
// CHECK-LABEL: define dso_local void @test_mips_ihb(
29+
// CHECK-SAME: ) local_unnamed_addr #[[ATTR0]] {
30+
// CHECK-NEXT: [[ENTRY:.*:]]
31+
// CHECK-NEXT: tail call void @llvm.riscv.mips.ihb()
32+
// CHECK-NEXT: ret void
33+
//
34+
void test_mips_ihb()
35+
{
36+
__mips_ihb();
37+
}

llvm/include/llvm/IR/IntrinsicsRISCV.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,3 +1964,4 @@ include "llvm/IR/IntrinsicsRISCVXTHead.td"
19641964
include "llvm/IR/IntrinsicsRISCVXsf.td"
19651965
include "llvm/IR/IntrinsicsRISCVXCV.td"
19661966
include "llvm/IR/IntrinsicsRISCVXAndes.td"
1967+
include "llvm/IR/IntrinsicsRISCVXMIPS.td"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===- IntrinsicsRISCVXMIPS.td - MIPS intrinsics -------*- tablegen -*----===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines all of the MIPS specific intrinsics for RISC-V.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
let TargetPrefix = "riscv" in {
14+
def int_riscv_mips_pause : ClangBuiltin<"__builtin_riscv_mips_pause">,
15+
Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects]>;
16+
def int_riscv_mips_ehb : ClangBuiltin<"__builtin_riscv_mips_ehb">,
17+
Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects]>;
18+
def int_riscv_mips_ihb : ClangBuiltin<"__builtin_riscv_mips_ihb">,
19+
Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects]>;
20+
}

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ def NoVendorXMIPSCBOP : Predicate<"!Subtarget->hasVendorXMIPSCBOP()">;
14391439

14401440
def FeatureVendorXMIPSEXECTL : RISCVExtension<1, 0, "MIPS execution control">;
14411441
def HasVendorXMIPSEXECTL
1442-
: Predicate<"Subtarget->hasVendorXMIPSEXT()">,
1442+
: Predicate<"Subtarget->hasVendorXMIPSEXECTL()">,
14431443
AssemblerPredicate<(all_of FeatureVendorXMIPSEXECTL),
14441444
"'Xmipsexectl' (MIPS execution control)">;
14451445

llvm/lib/Target/RISCV/RISCVInstrInfoXMips.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ let Predicates = [HasVendorXMIPSEXECTL], DecoderNamespace = "XMIPS" in {
143143
def MIPS_PAUSE : MIPSExtInst_ri<0b000101, "mips.pause">;
144144
}
145145

146+
let Predicates = [HasVendorXMIPSEXECTL] in {
147+
// Intrinsics
148+
def : Pat<(int_riscv_mips_pause), (MIPS_PAUSE)>;
149+
def : Pat<(int_riscv_mips_ihb), (MIPS_IHB)>;
150+
def : Pat<(int_riscv_mips_ehb), (MIPS_EHB)>;
151+
}
152+
146153
let Predicates = [HasVendorXMIPSCBOP], DecoderNamespace = "XMIPS" in {
147154
def MIPS_PREF : Mips_prefetch_ri<(outs), (ins GPR:$rs1, uimm9:$imm9, uimm5:$hint),
148155
"mips.pref", "$hint, ${imm9}(${rs1})">,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
2+
; RUN: llc -mtriple=riscv64 -mcpu=mips-p8700 -O3 -verify-machineinstrs < %s \
3+
; RUN: | FileCheck -check-prefix=MIPS %s
4+
5+
target datalayout = "e-m:e-p:32:32-i64:64-n32-S128"
6+
7+
define void @test_mips_pause() {
8+
; MIPS-LABEL: test_mips_pause:
9+
; MIPS: # %bb.0: # %entry
10+
; MIPS-NEXT: mips.pause
11+
; MIPS-NEXT: ret
12+
entry:
13+
tail call void @llvm.riscv.mips.pause()
14+
ret void
15+
}
16+
17+
define void @test_mips_ehb() {
18+
; MIPS-LABEL: test_mips_ehb:
19+
; MIPS: # %bb.0: # %entry
20+
; MIPS-NEXT: mips.ehb
21+
; MIPS-NEXT: ret
22+
entry:
23+
tail call void @llvm.riscv.mips.ehb()
24+
ret void
25+
}
26+
27+
define void @test_mips_ihb() {
28+
; MIPS-LABEL: test_mips_ihb:
29+
; MIPS: # %bb.0: # %entry
30+
; MIPS-NEXT: mips.ihb
31+
; MIPS-NEXT: ret
32+
entry:
33+
tail call void @llvm.riscv.mips.ihb()
34+
ret void
35+
}

0 commit comments

Comments
 (0)