Skip to content

Commit d92613e

Browse files
cachemeifyoucantru
authored andcommitted
Revert "Reland "[LoongArch] Support -march=native and -mtune=""
This reverts commit c56514f. This commit adds global state that is shared between clang driver and clang cc1, which is not correct when clang is used with `-fno-integrated-cc1` option (no integrated cc1). The -march and -mtune option needs to be properly passed through cc1 command-line and stored in TargetInfo. (cherry picked from commit 42c9354)
1 parent d93ba81 commit d92613e

File tree

12 files changed

+13
-168
lines changed

12 files changed

+13
-168
lines changed

clang/lib/Basic/Targets/LoongArch.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "clang/Basic/MacroBuilder.h"
1616
#include "clang/Basic/TargetBuiltins.h"
1717
#include "llvm/Support/raw_ostream.h"
18-
#include "llvm/TargetParser/LoongArchTargetParser.h"
18+
#include "llvm/TargetParser/TargetParser.h"
1919

2020
using namespace clang;
2121
using namespace clang::targets;
@@ -198,19 +198,7 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts,
198198
else
199199
Builder.defineMacro("__loongarch_frlen", "0");
200200

201-
// Define __loongarch_arch.
202-
StringRef Arch = llvm::LoongArch::getArch();
203-
if (Arch.empty())
204-
Arch = llvm::LoongArch::getDefaultArch(GRLen == 64);
205-
if (!Arch.empty())
206-
Builder.defineMacro("__loongarch_arch", Arch);
207-
208-
// Define __loongarch_tune.
209-
StringRef TuneCPU = llvm::LoongArch::getTuneCPU();
210-
if (TuneCPU.empty())
211-
TuneCPU = Arch;
212-
if (!TuneCPU.empty())
213-
Builder.defineMacro("__loongarch_tune", TuneCPU);
201+
// TODO: define __loongarch_arch and __loongarch_tune.
214202

215203
StringRef ABI = getABI();
216204
if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s")
@@ -282,12 +270,3 @@ bool LoongArchTargetInfo::handleTargetFeatures(
282270
}
283271
return true;
284272
}
285-
286-
bool LoongArchTargetInfo::isValidTuneCPUName(StringRef Name) const {
287-
return llvm::LoongArch::isValidTuneCPUName(Name);
288-
}
289-
290-
void LoongArchTargetInfo::fillValidTuneCPUList(
291-
SmallVectorImpl<StringRef> &Values) const {
292-
llvm::LoongArch::fillValidTuneCPUList(Values);
293-
}

clang/lib/Basic/Targets/LoongArch.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
8080
const std::vector<std::string> &FeaturesVec) const override;
8181

8282
bool hasFeature(StringRef Feature) const override;
83-
84-
bool isValidTuneCPUName(StringRef Name) const override;
85-
void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override;
8683
};
8784

8885
class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "clang/Driver/Driver.h"
1313
#include "clang/Driver/DriverDiagnostic.h"
1414
#include "clang/Driver/Options.h"
15-
#include "llvm/TargetParser/Host.h"
1615
#include "llvm/TargetParser/LoongArchTargetParser.h"
1716

1817
using namespace clang::driver;
@@ -129,29 +128,21 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
129128
std::vector<StringRef> &Features) {
130129
StringRef ArchName;
131130
if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
132-
ArchName = A->getValue();
133-
134-
// Handle -march=native.
135-
if (ArchName == "native") {
136-
ArchName = llvm::sys::getHostCPUName();
137-
if (ArchName == "generic")
138-
ArchName = llvm::LoongArch::getDefaultArch(Triple.isLoongArch64());
139-
}
140-
141-
if (!llvm::LoongArch::isValidArchName(ArchName)) {
131+
if (!llvm::LoongArch::isValidArchName(A->getValue())) {
142132
D.Diag(clang::diag::err_drv_invalid_arch_name) << A->getAsString(Args);
143133
return;
144134
}
135+
ArchName = A->getValue();
145136
}
146137

138+
// TODO: handle -march=native and -mtune=xx.
139+
147140
// Select a default arch name.
148-
if (ArchName.empty())
149-
ArchName = llvm::LoongArch::getDefaultArch(Triple.isLoongArch64());
141+
if (ArchName.empty() && Triple.isLoongArch64())
142+
ArchName = "loongarch64";
150143

151-
if (!ArchName.empty()) {
144+
if (!ArchName.empty())
152145
llvm::LoongArch::getArchFeatures(ArchName, Features);
153-
llvm::LoongArch::setArch(ArchName);
154-
}
155146

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

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
#include "llvm/Support/YAMLParser.h"
5757
#include "llvm/TargetParser/ARMTargetParserCommon.h"
5858
#include "llvm/TargetParser/Host.h"
59-
#include "llvm/TargetParser/LoongArchTargetParser.h"
6059
#include "llvm/TargetParser/RISCVTargetParser.h"
6160
#include <cctype>
6261

@@ -1854,25 +1853,10 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args,
18541853

18551854
void Clang::AddLoongArchTargetArgs(const ArgList &Args,
18561855
ArgStringList &CmdArgs) const {
1857-
const llvm::Triple &Triple = getToolChain().getTriple();
1858-
18591856
CmdArgs.push_back("-target-abi");
1860-
CmdArgs.push_back(
1861-
loongarch::getLoongArchABI(getToolChain().getDriver(), Args, Triple)
1862-
.data());
1863-
1864-
// Handle -mtune.
1865-
if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
1866-
StringRef TuneCPU = A->getValue();
1867-
if (TuneCPU == "native") {
1868-
TuneCPU = llvm::sys::getHostCPUName();
1869-
if (TuneCPU == "generic")
1870-
TuneCPU = llvm::LoongArch::getDefaultArch(Triple.isLoongArch64());
1871-
}
1872-
CmdArgs.push_back("-tune-cpu");
1873-
CmdArgs.push_back(Args.MakeArgString(TuneCPU));
1874-
llvm::LoongArch::setTuneCPU(TuneCPU);
1875-
}
1857+
CmdArgs.push_back(loongarch::getLoongArchABI(getToolChain().getDriver(), Args,
1858+
getToolChain().getTriple())
1859+
.data());
18761860
}
18771861

18781862
void Clang::AddMIPSTargetArgs(const ArgList &Args,

clang/test/Driver/loongarch-mtune-error.c

Lines changed: 0 additions & 6 deletions
This file was deleted.

clang/test/Driver/loongarch-mtune.c

Lines changed: 0 additions & 16 deletions
This file was deleted.

clang/test/Preprocessor/init-loongarch.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -787,23 +787,3 @@
787787
// LA64-FPU0-LP64S: #define __loongarch_lp64 1
788788
// LA64-FPU0-LP64S-NOT: #define __loongarch_single_float
789789
// LA64-FPU0-LP64S: #define __loongarch_soft_float 1
790-
791-
/// Check __loongarch_arch and __loongarch_tune.
792-
793-
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - | \
794-
// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=loongarch64 %s
795-
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 | \
796-
// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=loongarch64 %s
797-
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la464 | \
798-
// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=la464 -DTUNE=la464 %s
799-
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -mtune=loongarch64 | \
800-
// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=loongarch64 %s
801-
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -mtune=la464 | \
802-
// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=la464 %s
803-
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=loongarch64 -mtune=la464 | \
804-
// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=loongarch64 -DTUNE=la464 %s
805-
// RUN: %clang --target=loongarch64 -x c -E -dM %s -o - -march=la464 -mtune=loongarch64 | \
806-
// RUN: FileCheck --match-full-lines --check-prefix=ARCH-TUNE -DARCH=la464 -DTUNE=loongarch64 %s
807-
808-
// ARCH-TUNE: #define __loongarch_arch [[ARCH]]
809-
// ARCH-TUNE: #define __loongarch_tune [[TUNE]]

llvm/include/llvm/TargetParser/LoongArchTargetParser.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,9 @@ struct ArchInfo {
6666

6767
bool isValidArchName(StringRef Arch);
6868
bool getArchFeatures(StringRef Arch, std::vector<StringRef> &Features);
69-
bool isValidTuneCPUName(StringRef TuneCPU);
70-
void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values);
71-
StringRef getDefaultArch(bool Is64Bit);
72-
void setArch(StringRef Arch);
73-
StringRef getArch();
74-
void setTuneCPU(StringRef TuneCPU);
75-
StringRef getTuneCPU();
7669

7770
} // namespace LoongArch
7871

7972
} // namespace llvm
8073

81-
#endif // LLVM_TARGETPARSER_LOONGARCHTARGETPARSER_H
74+
#endif // LLVM_SUPPORT_LOONGARCHTARGETPARSER_H

llvm/lib/Target/LoongArch/LoongArch.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ include "LoongArchInstrInfo.td"
117117
def : ProcessorModel<"generic-la32", NoSchedModel, [Feature32Bit]>;
118118
def : ProcessorModel<"generic-la64", NoSchedModel, [Feature64Bit, FeatureUAL]>;
119119

120-
// Generic 64-bit processor with double-precision floating-point support.
121-
def : ProcessorModel<"loongarch64", NoSchedModel, [Feature64Bit,
122-
FeatureUAL,
123-
FeatureBasicD]>;
124-
125120
// Support generic for compatibility with other targets. The triple will be used
126121
// to change to the appropriate la32/la64 version.
127122
def : ProcessorModel<"generic", NoSchedModel, []>;

llvm/lib/TargetParser/LoongArchTargetParser.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
using namespace llvm;
1717
using namespace llvm::LoongArch;
1818

19-
StringRef Arch;
20-
StringRef TuneCPU;
21-
2219
const FeatureInfo AllFeatures[] = {
2320
#define LOONGARCH_FEATURE(NAME, KIND) {NAME, KIND},
2421
#include "llvm/TargetParser/LoongArchTargetParser.def"
@@ -49,25 +46,3 @@ bool LoongArch::getArchFeatures(StringRef Arch,
4946
}
5047
return false;
5148
}
52-
53-
bool LoongArch::isValidTuneCPUName(StringRef TuneCPU) {
54-
return isValidArchName(TuneCPU);
55-
}
56-
57-
void LoongArch::fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) {
58-
for (const auto A : AllArchs)
59-
Values.emplace_back(A.Name);
60-
}
61-
62-
StringRef LoongArch::getDefaultArch(bool Is64Bit) {
63-
// TODO: use a real 32-bit arch name.
64-
return Is64Bit ? "loongarch64" : "";
65-
}
66-
67-
void LoongArch::setArch(StringRef Name) { Arch = Name; }
68-
69-
StringRef LoongArch::getArch() { return Arch; }
70-
71-
void LoongArch::setTuneCPU(StringRef Name) { TuneCPU = Name; }
72-
73-
StringRef LoongArch::getTuneCPU() { return TuneCPU; }

llvm/test/CodeGen/LoongArch/cpus-invalid.ll

Lines changed: 0 additions & 7 deletions
This file was deleted.

llvm/test/CodeGen/LoongArch/cpus.ll

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)