Skip to content

Commit 5e953a2

Browse files
committed
[RISCV] Define preprocessor definitions for 'V' extension.
Differential Revision: https://reviews.llvm.org/D92650
1 parent db226cd commit 5e953a2

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
136136
if (HasB)
137137
Builder.defineMacro("__riscv_bitmanip");
138138

139+
if (HasV)
140+
Builder.defineMacro("__riscv_vector");
141+
139142
if (HasZfh)
140143
Builder.defineMacro("__riscv_zfh");
141144
}
@@ -153,6 +156,7 @@ bool RISCVTargetInfo::hasFeature(StringRef Feature) const {
153156
.Case("d", HasD)
154157
.Case("c", HasC)
155158
.Case("experimental-b", HasB)
159+
.Case("experimental-v", HasV)
156160
.Case("experimental-zfh", HasZfh)
157161
.Default(false);
158162
}
@@ -173,6 +177,8 @@ bool RISCVTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
173177
HasC = true;
174178
else if (Feature == "+experimental-b")
175179
HasB = true;
180+
else if (Feature == "+experimental-v")
181+
HasV = true;
176182
else if (Feature == "+experimental-zfh")
177183
HasZfh = true;
178184
}

clang/lib/Basic/Targets/RISCV.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ class RISCVTargetInfo : public TargetInfo {
3131
bool HasD;
3232
bool HasC;
3333
bool HasB;
34+
bool HasV;
3435
bool HasZfh;
3536

3637
public:
3738
RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
3839
: TargetInfo(Triple), HasM(false), HasA(false), HasF(false), HasD(false),
39-
HasC(false), HasB(false), HasZfh(false) {
40+
HasC(false), HasB(false), HasV(false), HasZfh(false) {
4041
LongDoubleWidth = 128;
4142
LongDoubleAlign = 128;
4243
LongDoubleFormat = &llvm::APFloat::IEEEquad();

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@
7979
// CHECK-DOUBLE-NOT: __riscv_float_abi_soft
8080
// CHECK-DOUBLE-NOT: __riscv_float_abi_single
8181

82+
// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions \
83+
// RUN: -march=rv32iv0p9 -x c -E -dM %s \
84+
// RUN: -o - | FileCheck --check-prefix=CHECK-V-EXT %s
85+
// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions \
86+
// RUN: -march=rv64iv0p9 -x c -E -dM %s \
87+
// RUN: -o - | FileCheck --check-prefix=CHECK-V-EXT %s
88+
// CHECK-V-EXT: __riscv_vector 1
89+
//
8290
// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32izfh0p1 -x c -E -dM %s \
8391
// RUN: -o - | FileCheck --check-prefix=CHECK-ZFH-EXT %s
8492
// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv64izfh0p1 -x c -E -dM %s \

0 commit comments

Comments
 (0)