Skip to content

Commit

Permalink
[RISCV][Driver] Refactor riscv::getRISCVArch to return `std::string…
Browse files Browse the repository at this point in the history
…`. NFC.
  • Loading branch information
dtcxzyw committed Jul 7, 2024
1 parent 902fb1b commit 21a8c00
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
if (Target.isRISCV()) {
if (Args.hasArg(options::OPT_march_EQ) ||
Args.hasArg(options::OPT_mcpu_EQ)) {
StringRef ArchName = tools::riscv::getRISCVArch(Args, Target);
std::string ArchName = tools::riscv::getRISCVArch(Args, Target);
auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
ArchName, /*EnableExperimentalExtensions=*/true);
if (!llvm::errorToBool(ISAInfo.takeError())) {
Expand Down
10 changes: 5 additions & 5 deletions clang/lib/Driver/ToolChains/Arch/RISCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static void getRISCFeaturesFromMcpu(const Driver &D, const Arg *A,
void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args,
std::vector<StringRef> &Features) {
StringRef MArch = getRISCVArch(Args, Triple);
std::string MArch = getRISCVArch(Args, Triple);

if (!getArchFeatures(D, MArch, Features, Args))
return;
Expand Down Expand Up @@ -227,7 +227,7 @@ StringRef riscv::getRISCVABI(const ArgList &Args, const llvm::Triple &Triple) {
// rv64g | rv64*d -> lp64d
// rv64e -> lp64e
// rv64* -> lp64
StringRef Arch = getRISCVArch(Args, Triple);
std::string Arch = getRISCVArch(Args, Triple);

auto ParseResult = llvm::RISCVISAInfo::parseArchString(
Arch, /* EnableExperimentalExtension */ true);
Expand All @@ -253,8 +253,8 @@ StringRef riscv::getRISCVABI(const ArgList &Args, const llvm::Triple &Triple) {
}
}

StringRef riscv::getRISCVArch(const llvm::opt::ArgList &Args,
const llvm::Triple &Triple) {
std::string riscv::getRISCVArch(const llvm::opt::ArgList &Args,
const llvm::Triple &Triple) {
assert(Triple.isRISCV() && "Unexpected triple");

// GCC's logic around choosing a default `-march=` is complex. If GCC is not
Expand Down Expand Up @@ -295,7 +295,7 @@ StringRef riscv::getRISCVArch(const llvm::opt::ArgList &Args,
StringRef MArch = llvm::RISCV::getMArchFromMcpu(CPU);
// Bypass if target cpu's default march is empty.
if (MArch != "")
return MArch;
return MArch.str();
}

// 3. Choose a default based on `-mabi=`
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Driver/ToolChains/Arch/RISCV.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
std::vector<llvm::StringRef> &Features);
StringRef getRISCVABI(const llvm::opt::ArgList &Args,
const llvm::Triple &Triple);
StringRef getRISCVArch(const llvm::opt::ArgList &Args,
const llvm::Triple &Triple);
std::string getRISCVArch(const llvm::opt::ArgList &Args,
const llvm::Triple &Triple);
std::string getRISCVTargetCPU(const llvm::opt::ArgList &Args,
const llvm::Triple &Triple);
} // end namespace riscv
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/BareMetal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static bool findRISCVMultilibs(const Driver &D,
const llvm::Triple &TargetTriple,
const ArgList &Args, DetectedMultilibs &Result) {
Multilib::flags_list Flags;
StringRef Arch = riscv::getRISCVArch(Args, TargetTriple);
std::string Arch = riscv::getRISCVArch(Args, TargetTriple);
StringRef Abi = tools::riscv::getRISCVABI(Args, TargetTriple);

if (TargetTriple.isRISCV64()) {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,7 @@ void Clang::AddRISCVTargetArgs(const ArgList &Args,

// Get minimum VLen from march.
unsigned MinVLen = 0;
StringRef Arch = riscv::getRISCVArch(Args, Triple);
std::string Arch = riscv::getRISCVArch(Args, Triple);
auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
Arch, /*EnableExperimentalExtensions*/ true);
// Ignore parsing error.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void Flang::AddRISCVTargetArgs(const ArgList &Args,

// Get minimum VLen from march.
unsigned MinVLen = 0;
StringRef Arch = riscv::getRISCVArch(Args, Triple);
std::string Arch = riscv::getRISCVArch(Args, Triple);
auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
Arch, /*EnableExperimentalExtensions*/ true);
// Ignore parsing error.
Expand Down
7 changes: 4 additions & 3 deletions clang/lib/Driver/ToolChains/Gnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,9 +769,10 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,
StringRef ABIName = riscv::getRISCVABI(Args, getToolChain().getTriple());
CmdArgs.push_back("-mabi");
CmdArgs.push_back(ABIName.data());
StringRef MArchName = riscv::getRISCVArch(Args, getToolChain().getTriple());
std::string MArchName =
riscv::getRISCVArch(Args, getToolChain().getTriple());
CmdArgs.push_back("-march");
CmdArgs.push_back(MArchName.data());
CmdArgs.push_back(Args.MakeArgString(MArchName));
if (!Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))
Args.addOptOutFlag(CmdArgs, options::OPT_mrelax, options::OPT_mno_relax);
break;
Expand Down Expand Up @@ -1882,7 +1883,7 @@ static void findRISCVBareMetalMultilibs(const Driver &D,
Multilib::flags_list Flags;
llvm::StringSet<> Added_ABIs;
StringRef ABIName = tools::riscv::getRISCVABI(Args, TargetTriple);
StringRef MArch = tools::riscv::getRISCVArch(Args, TargetTriple);
std::string MArch = tools::riscv::getRISCVArch(Args, TargetTriple);
for (auto Element : RISCVMultilibSet) {
addMultilibFlag(MArch == Element.march,
Twine("-march=", Element.march).str().c_str(), Flags);
Expand Down

0 comments on commit 21a8c00

Please sign in to comment.