Skip to content

Commit 818e76d

Browse files
author
Yeting Kuo
committed
[RISCV] Add MC layer support for Zicfilp.
This adds extension Zicfilp and support pseudo instruction lpad. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D157362
1 parent 30c1866 commit 818e76d

File tree

10 files changed

+79
-4
lines changed

10 files changed

+79
-4
lines changed

clang/test/Preprocessor/riscv-target-features.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
// CHECK-NOT: __riscv_zvfbfmin {{.*$}}
7272
// CHECK-NOT: __riscv_zvfbfwma {{.*$}}
7373
// CHECK-NOT: __riscv_zacas {{.*$}}
74+
// CHECK-NOT: __riscv_zicfilp {{.*$}}
7475

7576
// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32i -x c -E -dM %s \
7677
// RUN: -o - | FileCheck %s
@@ -774,3 +775,11 @@
774775
// RUN: -march=rv64i_zacas1p0 -x c -E -dM %s \
775776
// RUN: -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
776777
// CHECK-ZACAS-EXT: __riscv_zacas 1000000{{$}}
778+
779+
// RUN: %clang -target riscv32 -menable-experimental-extensions \
780+
// RUN: -march=rv32i_zicfilp0p2 -x c -E -dM %s \
781+
// RUN: -o - | FileCheck --check-prefix=CHECK-ZICFILP-EXT %s
782+
// RUN: %clang -target riscv64 -menable-experimental-extensions \
783+
// RUN: -march=rv64i_zicfilp0p2 -x c -E -dM %s \
784+
// RUN: -o - | FileCheck --check-prefix=CHECK-ZICFILP-EXT %s
785+
// CHECK-ZICFILP-EXT: __riscv_zicfilp 2000{{$}}

llvm/docs/RISCVUsage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ The primary goal of experimental support is to assist in the process of ratifica
202202
``experimental-zfbfmin``, ``experimental-zvfbfmin``, ``experimental-zvfbfwma``
203203
LLVM implements assembler support for the `0.8.0 draft specification <https://github.com/riscv/riscv-bfloat16/releases/tag/20230629>`_.
204204

205+
``experimental-zicfilp``
206+
LLVM implements the `0.2 draft specification <https://github.com/riscv/riscv-cfi/releases/tag/v0.2.0>`__.
207+
205208
``experimental-zicond``
206209
LLVM implements the `1.0-rc1 draft specification <https://github.com/riscv/riscv-zicond/releases/tag/v1.0-rc1>`__.
207210

llvm/lib/Support/RISCVISAInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
168168
{"zfa", RISCVExtensionVersion{0, 2}},
169169
{"zfbfmin", RISCVExtensionVersion{0, 8}},
170170

171+
{"zicfilp", RISCVExtensionVersion{0, 2}},
171172
{"zicond", RISCVExtensionVersion{1, 0}},
172173

173174
{"ztso", RISCVExtensionVersion{0, 1}},

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
660660
bool isUImm6() const { return IsUImm<6>(); }
661661
bool isUImm7() const { return IsUImm<7>(); }
662662
bool isUImm8() const { return IsUImm<8>(); }
663+
bool isUImm20() const { return IsUImm<20>(); }
663664

664665
bool isUImm8GE32() const {
665666
int64_t Imm;
@@ -1478,6 +1479,8 @@ bool RISCVAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
14781479
"operand must be a symbol with "
14791480
"%hi/%tprel_hi modifier or an integer in "
14801481
"the range");
1482+
case Match_InvalidUImm20:
1483+
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 20) - 1);
14811484
case Match_InvalidUImm20AUIPC:
14821485
return generateImmOutOfRangeError(
14831486
Operands, ErrorInfo, 0, (1 << 20) - 1,

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,13 @@ def FeatureStdExtZvksg
648648
"other extensions: Zvks and Zvkg.",
649649
[FeatureStdExtZvks, FeatureStdExtZvkg]>;
650650

651+
def FeatureStdExtZicfilp
652+
: SubtargetFeature<"experimental-zicfilp", "HasStdExtZicfilp", "true",
653+
"'Zicfilp' (Landing pad)">;
654+
def HasStdExtZicfilp : Predicate<"Subtarget->hasStdExtZicfilp()">,
655+
AssemblerPredicate<(all_of FeatureStdExtZicfilp),
656+
"'Zicfilp' (Landing pad)">;
657+
651658
def FeatureStdExtZicond
652659
: SubtargetFeature<"experimental-zicond", "HasStdExtZicond", "true",
653660
"'Zicond' (Integer Conditional Operations)">;

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,23 +302,36 @@ def simm13_lsb0 : Operand<OtherVT> {
302302
class UImm20Operand : Operand<XLenVT> {
303303
let EncoderMethod = "getImmOpValue";
304304
let DecoderMethod = "decodeUImmOperand<20>";
305+
let OperandType = "OPERAND_UIMM20";
306+
let OperandNamespace = "RISCVOp";
307+
}
308+
309+
class UImm20OperandMaybeSym : UImm20Operand {
305310
let MCOperandPredicate = [{
306311
int64_t Imm;
307312
if (MCOp.evaluateAsConstantImm(Imm))
308313
return isUInt<20>(Imm);
309314
return MCOp.isBareSymbolRef();
310315
}];
311-
let OperandType = "OPERAND_UIMM20";
312-
let OperandNamespace = "RISCVOp";
313316
}
314317

315-
def uimm20_lui : UImm20Operand {
318+
def uimm20_lui : UImm20OperandMaybeSym {
316319
let ParserMatchClass = UImmAsmOperand<20, "LUI">;
317320
}
318-
def uimm20_auipc : UImm20Operand {
321+
def uimm20_auipc : UImm20OperandMaybeSym {
319322
let ParserMatchClass = UImmAsmOperand<20, "AUIPC">;
320323
}
321324

325+
def uimm20 : UImm20Operand {
326+
let ParserMatchClass = UImmAsmOperand<20>;
327+
let MCOperandPredicate = [{
328+
int64_t Imm;
329+
if (!MCOp.evaluateAsConstantImm(Imm))
330+
return false;
331+
return isUInt<20>(Imm);
332+
}];
333+
}
334+
322335
def Simm21Lsb0JALAsmOperand : SImmAsmOperand<21, "Lsb0JAL"> {
323336
let ParserMethod = "parseJALOffset";
324337
}
@@ -1105,6 +1118,10 @@ def : MnemonicAlias<"sbreak", "ebreak">;
11051118
// that don't support this alias.
11061119
def : InstAlias<"zext.b $rd, $rs", (ANDI GPR:$rd, GPR:$rs, 0xFF), 0>;
11071120

1121+
let Predicates = [HasStdExtZicfilp] in {
1122+
def : InstAlias<"lpad $imm20", (AUIPC X0, uimm20:$imm20)>;
1123+
}
1124+
11081125
//===----------------------------------------------------------------------===//
11091126
// .insn directive instructions
11101127
//===----------------------------------------------------------------------===//

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zvfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV32ZVFBFMIN %s
8787
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zvfbfwma %s -o - | FileCheck --check-prefixes=CHECK,RV32ZVFBFWMA %s
8888
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zacas %s -o - | FileCheck --check-prefix=RV32ZACAS %s
89+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicfilp %s -o - | FileCheck --check-prefix=RV32ZICFILP %s
8990

9091
; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s
9192
; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefixes=CHECK,RV64M %s
@@ -174,6 +175,7 @@
174175
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zvfbfmin %s -o - | FileCheck --check-prefixes=CHECK,RV64ZVFBFMIN %s
175176
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zvfbfwma %s -o - | FileCheck --check-prefixes=CHECK,RV64ZVFBFWMA %s
176177
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zacas %s -o - | FileCheck --check-prefix=RV64ZACAS %s
178+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-zicfilp %s -o - | FileCheck --check-prefix=RV64ZICFILP %s
177179

178180
; CHECK: .attribute 4, 16
179181

@@ -262,6 +264,7 @@
262264
; RV32ZVFBFMIN: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin0p8_zve32f1p0_zve32x1p0_zvfbfmin0p8_zvl32b1p0"
263265
; RV32ZVFBFWMA: .attribute 5, "rv32i2p1_f2p2_zicsr2p0_zfbfmin0p8_zve32f1p0_zve32x1p0_zvfbfmin0p8_zvfbfwma0p8_zvl32b1p0"
264266
; RV32ZACAS: .attribute 5, "rv32i2p1_a2p1_zacas1p0"
267+
; RV32ZICFILP: .attribute 5, "rv32i2p1_zicfilp0p2"
265268

266269
; RV64M: .attribute 5, "rv64i2p1_m2p0"
267270
; RV64ZMMUL: .attribute 5, "rv64i2p1_zmmul1p0"
@@ -349,6 +352,7 @@
349352
; RV64ZVFBFMIN: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zfbfmin0p8_zve32f1p0_zve32x1p0_zvfbfmin0p8_zvl32b1p0"
350353
; RV64ZVFBFWMA: .attribute 5, "rv64i2p1_f2p2_zicsr2p0_zfbfmin0p8_zve32f1p0_zve32x1p0_zvfbfmin0p8_zvfbfwma0p8_zvl32b1p0"
351354
; RV64ZACAS: .attribute 5, "rv64i2p1_a2p1_zacas1p0"
355+
; RV64ZICFILP: .attribute 5, "rv64i2p1_zicfilp0p2"
352356

353357
define i32 @addi(i32 %a) {
354358
%1 = add i32 %a, 1

llvm/test/MC/RISCV/attribute-arch.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,6 @@
299299

300300
.attribute arch, "rv32i_xcvbi"
301301
# CHECK: attribute 5, "rv32i2p1_xcvbi1p0"
302+
303+
.attribute arch, "rv32i_zicfilp0p2"
304+
# CHECK: attribute 5, "rv32i2p1_zicfilp0p2"

llvm/test/MC/RISCV/zicfilp-invalid.s

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# RUN: not llvm-mc -triple riscv32 -mattr=+experimental-zicfilp -riscv-no-aliases -show-encoding < %s 2>&1 \
2+
# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
3+
# RUN: not llvm-mc -triple riscv64 -mattr=+experimental-zicfilp -riscv-no-aliases -show-encoding < %s 2>&1 \
4+
# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
5+
6+
# CHECK-NO-EXT: immediate must be an integer in the range [0, 1048575]
7+
lpad 1048576

llvm/test/MC/RISCV/zicfilp-valid.s

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zicfilp -riscv-no-aliases -show-encoding \
2+
# RUN: | FileCheck -check-prefixes=CHECK-ASM %s
3+
# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zicfilp -riscv-no-aliases -show-encoding \
4+
# RUN: | FileCheck -check-prefixes=CHECK-ASM %s
5+
# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zicfilp < %s \
6+
# RUN: | llvm-objdump --mattr=+experimental-zicfilp -d -r - \
7+
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
8+
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zicfilp < %s \
9+
# RUN: | llvm-objdump --mattr=+experimental-zicfilp -d -r - \
10+
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s
11+
#
12+
# RUN: not llvm-mc -triple riscv32 -riscv-no-aliases -show-encoding < %s 2>&1 \
13+
# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
14+
# RUN: not llvm-mc -triple riscv64 -riscv-no-aliases -show-encoding < %s 2>&1 \
15+
# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s
16+
17+
# CHECK-ASM-AND-OBJ: lpad 22
18+
# CHECK-ASM: auipc zero, 22
19+
# CHECK-ASM: encoding: [0x17,0x60,0x01,0x00]
20+
# CHECK-NO-EXT: instruction requires the following: 'Zicfilp' (Landing pad)
21+
lpad 22

0 commit comments

Comments
 (0)