[clang] [RISCV] Simplify reserse fixed regs (PR #104736)
Pengcheng Wang via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 18 23:02:41 PDT 2024
https://github.com/wangpc-pp updated https://github.com/llvm/llvm-project/pull/104736
>From d45743a893a44dbb5da75d3dbe40dfbd34c14e71 Mon Sep 17 00:00:00 2001
From: Wang Pengcheng <wangpengcheng.pp at bytedance.com>
Date: Mon, 19 Aug 2024 12:07:00 +0800
Subject: [PATCH 1/2] [RISCV] Simplify reserse fixed regs
Add a macro to simplify some codes.
---
clang/lib/Driver/ToolChains/Arch/RISCV.cpp | 98 ++++++++--------------
1 file changed, 35 insertions(+), 63 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 149a31f58e75d2..914b9ae4bebe3d 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -95,69 +95,41 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
CPUFastVectorUnaligned = true;
}
- // Handle features corresponding to "-ffixed-X" options
- if (Args.hasArg(options::OPT_ffixed_x1))
- Features.push_back("+reserve-x1");
- if (Args.hasArg(options::OPT_ffixed_x2))
- Features.push_back("+reserve-x2");
- if (Args.hasArg(options::OPT_ffixed_x3))
- Features.push_back("+reserve-x3");
- if (Args.hasArg(options::OPT_ffixed_x4))
- Features.push_back("+reserve-x4");
- if (Args.hasArg(options::OPT_ffixed_x5))
- Features.push_back("+reserve-x5");
- if (Args.hasArg(options::OPT_ffixed_x6))
- Features.push_back("+reserve-x6");
- if (Args.hasArg(options::OPT_ffixed_x7))
- Features.push_back("+reserve-x7");
- if (Args.hasArg(options::OPT_ffixed_x8))
- Features.push_back("+reserve-x8");
- if (Args.hasArg(options::OPT_ffixed_x9))
- Features.push_back("+reserve-x9");
- if (Args.hasArg(options::OPT_ffixed_x10))
- Features.push_back("+reserve-x10");
- if (Args.hasArg(options::OPT_ffixed_x11))
- Features.push_back("+reserve-x11");
- if (Args.hasArg(options::OPT_ffixed_x12))
- Features.push_back("+reserve-x12");
- if (Args.hasArg(options::OPT_ffixed_x13))
- Features.push_back("+reserve-x13");
- if (Args.hasArg(options::OPT_ffixed_x14))
- Features.push_back("+reserve-x14");
- if (Args.hasArg(options::OPT_ffixed_x15))
- Features.push_back("+reserve-x15");
- if (Args.hasArg(options::OPT_ffixed_x16))
- Features.push_back("+reserve-x16");
- if (Args.hasArg(options::OPT_ffixed_x17))
- Features.push_back("+reserve-x17");
- if (Args.hasArg(options::OPT_ffixed_x18))
- Features.push_back("+reserve-x18");
- if (Args.hasArg(options::OPT_ffixed_x19))
- Features.push_back("+reserve-x19");
- if (Args.hasArg(options::OPT_ffixed_x20))
- Features.push_back("+reserve-x20");
- if (Args.hasArg(options::OPT_ffixed_x21))
- Features.push_back("+reserve-x21");
- if (Args.hasArg(options::OPT_ffixed_x22))
- Features.push_back("+reserve-x22");
- if (Args.hasArg(options::OPT_ffixed_x23))
- Features.push_back("+reserve-x23");
- if (Args.hasArg(options::OPT_ffixed_x24))
- Features.push_back("+reserve-x24");
- if (Args.hasArg(options::OPT_ffixed_x25))
- Features.push_back("+reserve-x25");
- if (Args.hasArg(options::OPT_ffixed_x26))
- Features.push_back("+reserve-x26");
- if (Args.hasArg(options::OPT_ffixed_x27))
- Features.push_back("+reserve-x27");
- if (Args.hasArg(options::OPT_ffixed_x28))
- Features.push_back("+reserve-x28");
- if (Args.hasArg(options::OPT_ffixed_x29))
- Features.push_back("+reserve-x29");
- if (Args.hasArg(options::OPT_ffixed_x30))
- Features.push_back("+reserve-x30");
- if (Args.hasArg(options::OPT_ffixed_x31))
- Features.push_back("+reserve-x31");
+// Handle features corresponding to "-ffixed-X" options
+#define RESERVE_REG(REG) \
+ if (Args.hasArg(options::OPT_ffixed_##REG)) \
+ Features.push_back("+reserve-" #REG);
+ RESERVE_REG(x1)
+ RESERVE_REG(x2)
+ RESERVE_REG(x3)
+ RESERVE_REG(x4)
+ RESERVE_REG(x5)
+ RESERVE_REG(x6)
+ RESERVE_REG(x7)
+ RESERVE_REG(x8)
+ RESERVE_REG(x9)
+ RESERVE_REG(x10)
+ RESERVE_REG(x11)
+ RESERVE_REG(x12)
+ RESERVE_REG(x13)
+ RESERVE_REG(x14)
+ RESERVE_REG(x15)
+ RESERVE_REG(x16)
+ RESERVE_REG(x17)
+ RESERVE_REG(x18)
+ RESERVE_REG(x19)
+ RESERVE_REG(x20)
+ RESERVE_REG(x21)
+ RESERVE_REG(x22)
+ RESERVE_REG(x23)
+ RESERVE_REG(x24)
+ RESERVE_REG(x25)
+ RESERVE_REG(x26)
+ RESERVE_REG(x27)
+ RESERVE_REG(x28)
+ RESERVE_REG(x29)
+ RESERVE_REG(x30)
+ RESERVE_REG(x31)
// -mrelax is default, unless -mno-relax is specified.
if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true)) {
>From 14120fecdd921972502a826b9b7c9d44968b50ec Mon Sep 17 00:00:00 2001
From: Wang Pengcheng <wangpengcheng.pp at bytedance.com>
Date: Mon, 19 Aug 2024 14:02:13 +0800
Subject: [PATCH 2/2] Undef RESERVE_REG
---
clang/lib/Driver/ToolChains/Arch/RISCV.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 914b9ae4bebe3d..6935904a24edbf 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -130,6 +130,7 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
RESERVE_REG(x29)
RESERVE_REG(x30)
RESERVE_REG(x31)
+#undef RESERVE_REG
// -mrelax is default, unless -mno-relax is specified.
if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true)) {
More information about the cfe-commits
mailing list