Skip to content

Commit 1a60e00

Browse files
committed
[RISCV] Use Triple::isRISCV/isRISCV32/isRISCV64 helps in some places. NFC
Reviewed By: reames Differential Revision: https://reviews.llvm.org/D132197
1 parent a47ec1b commit 1a60e00

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -968,14 +968,9 @@ void CodeGenModule::EmitOpenCLMetadata() {
968968

969969
void CodeGenModule::EmitBackendOptionsMetadata(
970970
const CodeGenOptions CodeGenOpts) {
971-
switch (getTriple().getArch()) {
972-
default:
973-
break;
974-
case llvm::Triple::riscv32:
975-
case llvm::Triple::riscv64:
971+
if (getTriple().isRISCV()) {
976972
getModule().addModuleFlag(llvm::Module::Error, "SmallDataLimit",
977973
CodeGenOpts.SmallDataLimit);
978-
break;
979974
}
980975
}
981976

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void getRISCFeaturesFromMcpu(const Driver &D, const llvm::Triple &Triple,
5252
const llvm::opt::ArgList &Args,
5353
const llvm::opt::Arg *A, StringRef Mcpu,
5454
std::vector<StringRef> &Features) {
55-
bool Is64Bit = (Triple.getArch() == llvm::Triple::riscv64);
55+
bool Is64Bit = Triple.isRISCV64();
5656
llvm::RISCV::CPUKind CPUKind = llvm::RISCV::parseCPUKind(Mcpu);
5757
if (!llvm::RISCV::checkCPUKind(CPUKind, Is64Bit) ||
5858
!llvm::RISCV::getCPUFeaturesExceptStdExt(CPUKind, Features)) {
@@ -163,9 +163,7 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
163163
}
164164

165165
StringRef riscv::getRISCVABI(const ArgList &Args, const llvm::Triple &Triple) {
166-
assert((Triple.getArch() == llvm::Triple::riscv32 ||
167-
Triple.getArch() == llvm::Triple::riscv64) &&
168-
"Unexpected triple");
166+
assert(Triple.isRISCV() && "Unexpected triple");
169167

170168
// GCC's logic around choosing a default `-mabi=` is complex. If GCC is not
171169
// configured using `--with-abi=`, then the logic for the default choice is
@@ -213,7 +211,7 @@ StringRef riscv::getRISCVABI(const ArgList &Args, const llvm::Triple &Triple) {
213211
// We deviate from GCC's defaults here:
214212
// - On `riscv{XLEN}-unknown-elf` we use the integer calling convention only.
215213
// - On all other OSs we use the double floating point calling convention.
216-
if (Triple.getArch() == llvm::Triple::riscv32) {
214+
if (Triple.isRISCV32()) {
217215
if (Triple.getOS() == llvm::Triple::UnknownOS)
218216
return "ilp32";
219217
else
@@ -228,9 +226,7 @@ StringRef riscv::getRISCVABI(const ArgList &Args, const llvm::Triple &Triple) {
228226

229227
StringRef riscv::getRISCVArch(const llvm::opt::ArgList &Args,
230228
const llvm::Triple &Triple) {
231-
assert((Triple.getArch() == llvm::Triple::riscv32 ||
232-
Triple.getArch() == llvm::Triple::riscv64) &&
233-
"Unexpected triple");
229+
assert(Triple.isRISCV() && "Unexpected triple");
234230

235231
// GCC's logic around choosing a default `-march=` is complex. If GCC is not
236232
// configured using `--with-arch=`, then the logic for the default choice is
@@ -291,7 +287,7 @@ StringRef riscv::getRISCVArch(const llvm::opt::ArgList &Args,
291287
// We deviate from GCC's defaults here:
292288
// - On `riscv{XLEN}-unknown-elf` we default to `rv{XLEN}imac`
293289
// - On all other OSs we use `rv{XLEN}imafdc` (equivalent to `rv{XLEN}gc`)
294-
if (Triple.getArch() == llvm::Triple::riscv32) {
290+
if (Triple.isRISCV32()) {
295291
if (Triple.getOS() == llvm::Triple::UnknownOS)
296292
return "rv32imac";
297293
else

clang/lib/Driver/ToolChains/BareMetal.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static bool findRISCVMultilibs(const Driver &D,
3939
StringRef Arch = riscv::getRISCVArch(Args, TargetTriple);
4040
StringRef Abi = tools::riscv::getRISCVABI(Args, TargetTriple);
4141

42-
if (TargetTriple.getArch() == llvm::Triple::riscv64) {
42+
if (TargetTriple.isRISCV64()) {
4343
Multilib Imac = makeMultilib("").flag("+march=rv64imac").flag("+mabi=lp64");
4444
Multilib Imafdc = makeMultilib("/rv64imafdc/lp64d")
4545
.flag("+march=rv64imafdc")
@@ -57,7 +57,7 @@ static bool findRISCVMultilibs(const Driver &D,
5757
Result.Multilibs = MultilibSet().Either(Imac, Imafdc);
5858
return Result.Multilibs.select(Flags, Result.SelectedMultilib);
5959
}
60-
if (TargetTriple.getArch() == llvm::Triple::riscv32) {
60+
if (TargetTriple.isRISCV32()) {
6161
Multilib Imac =
6262
makeMultilib("").flag("+march=rv32imac").flag("+mabi=ilp32");
6363
Multilib I =
@@ -140,8 +140,7 @@ static bool isAArch64BareMetal(const llvm::Triple &Triple) {
140140
}
141141

142142
static bool isRISCVBareMetal(const llvm::Triple &Triple) {
143-
if (Triple.getArch() != llvm::Triple::riscv32 &&
144-
Triple.getArch() != llvm::Triple::riscv64)
143+
if (!Triple.isRISCV())
145144
return false;
146145

147146
if (Triple.getVendor() != llvm::Triple::UnknownVendor)

0 commit comments

Comments
 (0)