Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,10 @@ def err_drv_loongarch_invalid_simd_option_combination : Error<
"invalid option combination; LASX depends on LSX">;
def err_drv_loongarch_invalid_msimd_EQ : Error<
"invalid argument '%0' to -msimd=; must be one of: none, lsx, lasx">;
// Support for other float specifications for flang in LoongArch64 may be
// added in the future, such as 32-bit fpu or soft fpu.
def err_drv_loongarch_disable_fpu64_for_flang : Error<
"invalid argument '%0'; must support 64-bit fpu for flang in LoongArch64">;

def err_drv_expand_response_file : Error<
"failed to expand response file: %0">;
Expand Down
15 changes: 15 additions & 0 deletions clang/lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ void Flang::AddAArch64TargetArgs(const ArgList &Args,
}
}

void Flang::AddLoongArch64TargetArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
const Driver &D = getToolChain().getDriver();
// Currently, flang only support `-mabi=lp64d` in LoongArch64.
if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
StringRef V = A->getValue();
if (V != "lp64d") {
std::string errMesg = std::string("-mabi=") + std::string(V.data());
D.Diag(diag::err_drv_loongarch_disable_fpu64_for_flang) << errMesg;
}
}
CmdArgs.push_back("-mabi=lp64d");
}

void Flang::AddPPCTargetArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
const Driver &D = getToolChain().getDriver();
Expand Down Expand Up @@ -416,6 +430,7 @@ void Flang::addTargetOptions(const ArgList &Args,
break;
case llvm::Triple::loongarch64:
getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
AddLoongArch64TargetArgs(Args, CmdArgs);
break;
}

Expand Down
7 changes: 7 additions & 0 deletions clang/lib/Driver/ToolChains/Flang.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ class LLVM_LIBRARY_VISIBILITY Flang : public Tool {
void AddAMDGPUTargetArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const;

/// Add specific options for LoongArch64 target.
///
/// \param [in] Args The list of input driver arguments
/// \param [out] CmdArgs The list of output command arguments
void AddLoongArch64TargetArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const;

/// Add specific options for RISC-V target.
///
/// \param [in] Args The list of input driver arguments
Expand Down
13 changes: 13 additions & 0 deletions flang/test/Driver/mabi-loongarch.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
! RUN: not %flang -### -c --target=loongarch64-unknown-linux -mabi=lp64s %s 2>&1 | FileCheck --check-prefix=INVALID1 %s
! RUN: not %flang -### -c --target=loongarch64-unknown-linux -mabi=lp64f %s 2>&1 | FileCheck --check-prefix=INVALID2 %s
! RUN: %flang -### -c --target=loongarch64-unknown-linux -mabi=lp64d %s 2>&1 | FileCheck --check-prefix=ABI %s
! RUN: %flang -### -c --target=loongarch64-unknown-linux %s 2>&1 | FileCheck --check-prefix=ABI %s

! REQUIRES: target=loongarch64{{.*}}

! INVALID1: error: invalid argument '-mabi=lp64s'; must support 64-bit fpu for flang in LoongArch64
! INVALID2: error: invalid argument '-mabi=lp64f'; must support 64-bit fpu for flang in LoongArch64

! ABI: "-target-feature" "+d"
! ABI-SAME: "-mabi=lp64d"

Loading