[clang] 57cf6ee - [RISCV] Add Clang frontend support for Bitmanip extension
Scott Egerton via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 14 09:46:15 PST 2020
Author: Scott Egerton
Date: 2020-01-14T17:45:45Z
New Revision: 57cf6ee9c84434161088c39a6f8dd2aae14eb12d
URL: https://github.com/llvm/llvm-project/commit/57cf6ee9c84434161088c39a6f8dd2aae14eb12d
DIFF: https://github.com/llvm/llvm-project/commit/57cf6ee9c84434161088c39a6f8dd2aae14eb12d.diff
LOG: [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
Added:
Modified:
clang/lib/Basic/Targets/RISCV.cpp
clang/lib/Basic/Targets/RISCV.h
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
clang/test/Preprocessor/riscv-target-features.c
Removed:
################################################################################
diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp
index ab8272c034fd..58285f1d8134 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -125,6 +125,10 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
if (HasC)
Builder.defineMacro("__riscv_compressed");
+
+ if (HasB) {
+ Builder.defineMacro("__riscv_bitmanip");
+ }
}
/// Return true if has this feature, need to sync with handleTargetFeatures.
@@ -139,6 +143,7 @@ bool RISCVTargetInfo::hasFeature(StringRef Feature) const {
.Case("f", HasF)
.Case("d", HasD)
.Case("c", HasC)
+ .Case("b", HasB)
.Default(false);
}
@@ -156,6 +161,8 @@ bool RISCVTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
HasD = true;
else if (Feature == "+c")
HasC = true;
+ else if (Feature == "+b")
+ HasB = true;
}
return true;
diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 9118494a87ab..05da13230bf8 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -30,11 +30,12 @@ class RISCVTargetInfo : public TargetInfo {
bool HasF;
bool HasD;
bool HasC;
+ bool HasB;
public:
RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
: TargetInfo(Triple), HasM(false), HasA(false), HasF(false),
- HasD(false), HasC(false) {
+ HasD(false), HasC(false), HasB(false) {
LongDoubleWidth = 128;
LongDoubleAlign = 128;
LongDoubleFormat = &llvm::APFloat::IEEEquad();
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 8c343b8693f3..85869ae937e5 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -331,6 +331,9 @@ static bool getArchFeatures(const Driver &D, StringRef MArch,
case 'c':
Features.push_back("+c");
break;
+ case 'b':
+ Features.push_back("+b");
+ break;
}
}
diff --git a/clang/test/Preprocessor/riscv-target-features.c b/clang/test/Preprocessor/riscv-target-features.c
index a93d7e6a9a43..1d2fd60847da 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -7,6 +7,7 @@
// CHECK-NOT: __riscv_mul
// CHECK-NOT: __riscv_muldiv
// CHECK-NOT: __riscv_compressed
+// CHECK-NOT: __riscv_bitmanip
// CHECK-NOT: __riscv_flen
// CHECK-NOT: __riscv_fdiv
// CHECK-NOT: __riscv_fsqrt
@@ -48,6 +49,12 @@
// RUN: -o - | FileCheck --check-prefix=CHECK-C-EXT %s
// CHECK-C-EXT: __riscv_compressed 1
+// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ib -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ib -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-B-EXT %s
+// CHECK-B-EXT: __riscv_bitmanip 1
+
// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ifd -mabi=ilp32 -x c -E -dM %s \
// RUN: -o - | FileCheck --check-prefix=CHECK-SOFT %s
// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ifd -mabi=lp64 -x c -E -dM %s \
More information about the cfe-commits
mailing list