Skip to content

Commit 6e82f23

Browse files
committed
RISCV: the builtins support for MIPS RV64 P8700 execution control instructions
1 parent 2837370 commit 6e82f23

File tree

8 files changed

+131
-1
lines changed

8 files changed

+131
-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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
class RISCVXMIPSBuiltin<string prototype, string features = ""> : TargetBuiltin {
15+
let Spellings = ["__builtin_riscv_" # NAME];
16+
let Prototype = prototype;
17+
let Features = features;
18+
}
19+
20+
//===----------------------------------------------------------------------===//
21+
// MIPS execution control extensions .
22+
//===----------------------------------------------------------------------===//
23+
let Attributes = [NoThrow, Const] in {
24+
def mips_pause : RISCVXMIPSBuiltin<"void()", "xmipsexectl">;
25+
def mips_ehb : RISCVXMIPSBuiltin<"void()", "xmipsexectl">;
26+
def mips_ihb : RISCVXMIPSBuiltin<"void()", "xmipsexectl">;
27+
}
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_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 RISCV32
3+
4+
// CHECK-LABEL: define dso_local void @test_mips_pause(
5+
// CHECK-SAME: ) local_unnamed_addr #[[ATTR0:[0-9]+]] {
6+
// CHECK-NEXT: [[ENTRY:.*:]]
7+
// CHECK-NEXT: tail call void @llvm.riscv.mips.pause()
8+
// CHECK-NEXT: ret void
9+
//
10+
void test_mips_pause()
11+
{
12+
__builtin_riscv_mips_pause();
13+
}
14+
15+
// CHECK-LABEL: define dso_local void @test_mips_ehb(
16+
// CHECK-SAME: ) local_unnamed_addr #[[ATTR0]] {
17+
// CHECK-NEXT: [[ENTRY:.*:]]
18+
// CHECK-NEXT: tail call void @llvm.riscv.mips.ehb()
19+
// CHECK-NEXT: ret void
20+
//
21+
void test_mips_ehb()
22+
{
23+
__builtin_riscv_mips_ehb();
24+
}
25+
26+
// CHECK-LABEL: define dso_local void @test_mips_ihb(
27+
// CHECK-SAME: ) local_unnamed_addr #[[ATTR0]] {
28+
// CHECK-NEXT: [[ENTRY:.*:]]
29+
// CHECK-NEXT: tail call void @llvm.riscv.mips.ihb()
30+
// CHECK-NEXT: ret void
31+
//
32+
void test_mips_ihb()
33+
{
34+
__builtin_riscv_mips_ihb();
35+
}

llvm/include/llvm/IR/IntrinsicsRISCV.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,3 +1949,4 @@ include "llvm/IR/IntrinsicsRISCVXTHead.td"
19491949
include "llvm/IR/IntrinsicsRISCVXsf.td"
19501950
include "llvm/IR/IntrinsicsRISCVXCV.td"
19511951
include "llvm/IR/IntrinsicsRISCVXAndes.td"
1952+
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 - Defines 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 RISCV.
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
@@ -1426,7 +1426,7 @@ def NoVendorXMIPSCBOP : Predicate<"!Subtarget->hasVendorXMIPSCBOP()">;
14261426

14271427
def FeatureVendorXMIPSEXECTL : RISCVExtension<1, 0, "MIPS execution control">;
14281428
def HasVendorXMIPSEXECTL
1429-
: Predicate<"Subtarget->hasVendorXMIPSEXT()">,
1429+
: Predicate<"Subtarget->hasVendorXMIPSEXECTL()">,
14301430
AssemblerPredicate<(all_of FeatureVendorXMIPSEXECTL),
14311431
"'Xmipsexectl' (MIPS execution control)">;
14321432

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: --tool /home/ukalappa/llvm/github/build/bin/llc --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 dso_local void @test_mips_pause() local_unnamed_addr {
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 dso_local void @test_mips_ehb() local_unnamed_addr {
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 dso_local void @test_mips_ihb() local_unnamed_addr {
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)