Skip to content

Commit

Permalink
[RISCV] Remove duplicated logic when determining the target ABI
Browse files Browse the repository at this point in the history
We were calculating twice ilp32/lp64. Do this in one place instead.

Differential Revision: https://reviews.llvm.org/D48357

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368128 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rofirrim committed Aug 7, 2019
1 parent c3583ea commit 8198a54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
8 changes: 7 additions & 1 deletion lib/Driver/ToolChains/Arch/RISCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,14 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const ArgList &Args,
}

StringRef riscv::getRISCVABI(const ArgList &Args, const llvm::Triple &Triple) {
if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
assert((Triple.getArch() == llvm::Triple::riscv32 ||
Triple.getArch() == llvm::Triple::riscv64) &&
"Unexpected triple");

if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
return A->getValue();

// FIXME: currently defaults to the soft-float ABIs. Will need to be
// expanded to select ilp32f, ilp32d, lp64f, lp64d when appropriate.
return Triple.getArch() == llvm::Triple::riscv32 ? "ilp32" : "lp64";
}
14 changes: 2 additions & 12 deletions lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1848,21 +1848,11 @@ void Clang::AddPPCTargetArgs(const ArgList &Args,

void Clang::AddRISCVTargetArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
// FIXME: currently defaults to the soft-float ABIs. Will need to be
// expanded to select ilp32f, ilp32d, lp64f, lp64d when appropriate.
const char *ABIName = nullptr;
const llvm::Triple &Triple = getToolChain().getTriple();
if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
ABIName = A->getValue();
else if (Triple.getArch() == llvm::Triple::riscv32)
ABIName = "ilp32";
else if (Triple.getArch() == llvm::Triple::riscv64)
ABIName = "lp64";
else
llvm_unreachable("Unexpected triple!");
StringRef ABIName = riscv::getRISCVABI(Args, Triple);

CmdArgs.push_back("-target-abi");
CmdArgs.push_back(ABIName);
CmdArgs.push_back(ABIName.data());
}

void Clang::AddSparcTargetArgs(const ArgList &Args,
Expand Down

0 comments on commit 8198a54

Please sign in to comment.