Skip to content

Commit 2283d50

Browse files
authored
[LoongArch] add la v1.1 features for sys::getHostCPUFeatures (#115832)
Two features (i.e. `frecipe` and `lam-bh`) are added to `sys.getHostCPUFeatures`. More features will be added in future. In addition, this patch adds the features returned by `sys.getHostCPUFeature` when `-march=native`.
1 parent 48cc435 commit 2283d50

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,15 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
135135
Features.push_back("+lsx");
136136

137137
std::string ArchName;
138-
if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
139-
ArchName = A->getValue();
138+
const Arg *MArch = Args.getLastArg(options::OPT_march_EQ);
139+
if (MArch)
140+
ArchName = MArch->getValue();
140141
ArchName = postProcessTargetCPUString(ArchName, Triple);
141142
llvm::LoongArch::getArchFeatures(ArchName, Features);
143+
if (MArch && StringRef(MArch->getValue()) == "native")
144+
for (auto &F : llvm::sys::getHostCPUFeatures())
145+
Features.push_back(
146+
Args.MakeArgString((F.second ? "+" : "-") + F.first()));
142147

143148
// Select floating-point features determined by -mdouble-float,
144149
// -msingle-float, -msoft-float and -mfpu.

llvm/lib/TargetParser/Host.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,15 @@ const StringMap<bool> sys::getHostCPUFeatures() {
20102010
Features["lasx"] = hwcap & (1UL << 5); // HWCAP_LOONGARCH_LASX
20112011
Features["lvz"] = hwcap & (1UL << 9); // HWCAP_LOONGARCH_LVZ
20122012

2013+
Features["frecipe"] = cpucfg2 & (1U << 25); // CPUCFG.2.FRECIPE
2014+
Features["lam-bh"] = cpucfg2 & (1U << 27); // CPUCFG.2.LAM_BH
2015+
2016+
// TODO: Need to complete.
2017+
// Features["div32"] = cpucfg2 & (1U << 26); // CPUCFG.2.DIV32
2018+
// Features["lamcas"] = cpucfg2 & (1U << 28); // CPUCFG.2.LAMCAS
2019+
// Features["llacq-screl"] = cpucfg2 & (1U << 29); // CPUCFG.2.LLACQ_SCREL
2020+
// Features["scq"] = cpucfg2 & (1U << 30); // CPUCFG.2.SCQ
2021+
// Features["ld-seq-sa"] = cpucfg3 & (1U << 23); // CPUCFG.3.LD_SEQ_SA
20132022
return Features;
20142023
}
20152024
#elif defined(__linux__) && defined(__riscv)

0 commit comments

Comments
 (0)