Skip to content

Commit 57cf6ee

Browse files
committed
[RISCV] Add Clang frontend support for Bitmanip extension
Summary: This adds the __riscv_bitmanip macro and the 'b' target feature to enable it. Reviewers: asb, simoncook, lewis-revill, PaoloS, lenary Reviewed By: lenary Subscribers: Jim, rbar, johnrusso, sabuasal, niosHD, kito-cheng, shiva0217, jrtc27, MaskRay, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, PkmX, jocewei, psnobl, benna, pzheng, sameer.abuasal, apazos, luismarques, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71553
1 parent fd19ffc commit 57cf6ee

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
125125

126126
if (HasC)
127127
Builder.defineMacro("__riscv_compressed");
128+
129+
if (HasB) {
130+
Builder.defineMacro("__riscv_bitmanip");
131+
}
128132
}
129133

130134
/// Return true if has this feature, need to sync with handleTargetFeatures.
@@ -139,6 +143,7 @@ bool RISCVTargetInfo::hasFeature(StringRef Feature) const {
139143
.Case("f", HasF)
140144
.Case("d", HasD)
141145
.Case("c", HasC)
146+
.Case("b", HasB)
142147
.Default(false);
143148
}
144149

@@ -156,6 +161,8 @@ bool RISCVTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
156161
HasD = true;
157162
else if (Feature == "+c")
158163
HasC = true;
164+
else if (Feature == "+b")
165+
HasB = true;
159166
}
160167

161168
return true;

clang/lib/Basic/Targets/RISCV.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ class RISCVTargetInfo : public TargetInfo {
3030
bool HasF;
3131
bool HasD;
3232
bool HasC;
33+
bool HasB;
3334

3435
public:
3536
RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
3637
: TargetInfo(Triple), HasM(false), HasA(false), HasF(false),
37-
HasD(false), HasC(false) {
38+
HasD(false), HasC(false), HasB(false) {
3839
LongDoubleWidth = 128;
3940
LongDoubleAlign = 128;
4041
LongDoubleFormat = &llvm::APFloat::IEEEquad();

clang/lib/Driver/ToolChains/Arch/RISCV.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ static bool getArchFeatures(const Driver &D, StringRef MArch,
331331
case 'c':
332332
Features.push_back("+c");
333333
break;
334+
case 'b':
335+
Features.push_back("+b");
336+
break;
334337
}
335338
}
336339

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// CHECK-NOT: __riscv_mul
88
// CHECK-NOT: __riscv_muldiv
99
// CHECK-NOT: __riscv_compressed
10+
// CHECK-NOT: __riscv_bitmanip
1011
// CHECK-NOT: __riscv_flen
1112
// CHECK-NOT: __riscv_fdiv
1213
// CHECK-NOT: __riscv_fsqrt
@@ -48,6 +49,12 @@
4849
// RUN: -o - | FileCheck --check-prefix=CHECK-C-EXT %s
4950
// CHECK-C-EXT: __riscv_compressed 1
5051

52+
// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ib -x c -E -dM %s \
53+
// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
54+
// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ib -x c -E -dM %s \
55+
// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
56+
// CHECK-B-EXT: __riscv_bitmanip 1
57+
5158
// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ifd -mabi=ilp32 -x c -E -dM %s \
5259
// RUN: -o - | FileCheck --check-prefix=CHECK-SOFT %s
5360
// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ifd -mabi=lp64 -x c -E -dM %s \

0 commit comments

Comments
 (0)